import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_per_fused_dist_0(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel,
    rnumel):
    XBLOCK: tl.constexpr = 1
    RBLOCK: tl.constexpr = 256
    xoffset = tl.program_id(0) * XBLOCK
    tl.full([1], xoffset, tl.int32)
    tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    tl.full([RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp1 = tl.load(in_ptr1 + r0, None)
    tmp2 = tmp0 - tmp1
    tmp3 = tmp2 * tmp2
    tmp4 = tl.broadcast_to(tmp3, [RBLOCK])
    tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0))
    tmp7 = libdevice.sqrt(tmp6)
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp7, None)
    tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp7, None)


@triton.jit
def triton_poi_fused_tanh_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    tmp0 = tl.load(in_out_ptr0 + 0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
    tmp2 = tl.load(in_ptr0 + 0)
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK])
    tmp4 = tmp1 + tmp3
    tmp5 = libdevice.tanh(tmp4)
    tl.store(in_out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp5, None)


@triton.jit
def triton_poi_fused_sigmoid_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    tmp0 = tl.load(in_out_ptr0 + 0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
    tmp2 = tl.load(in_ptr0 + 0)
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK])
    tmp4 = tmp1 + tmp3
    tmp5 = tl.sigmoid(tmp4)
    tl.store(in_out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp5, None)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_3, (1, 1), (1, 1))
    assert_size_stride(primals_4, (1,), (1,))
    assert_size_stride(primals_5, (1, 1), (1, 1))
    assert_size_stride(primals_6, (1,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((), (), torch.float32)
        buf1 = buf0
        del buf0
        buf2 = empty_strided_cuda((1, 1), (1, 1), torch.float32)
        get_raw_stream(0)
        triton_per_fused_dist_0[grid(1)](buf1, primals_2, primals_1, buf2, 
            1, 256, num_warps=2, num_stages=1)
        del primals_1
        del primals_2
        buf3 = empty_strided_cuda((1, 1), (1, 1), torch.float32)
        extern_kernels.mm(buf2, primals_3, out=buf3)
        del primals_3
        buf4 = buf3
        del buf3
        triton_poi_fused_tanh_1[grid(1)](buf4, primals_4, 1, XBLOCK=1,
            num_warps=1, num_stages=1)
        del primals_4
        buf5 = buf2
        del buf2
        extern_kernels.mm(buf4, primals_5, out=buf5)
        buf6 = buf5
        del buf5
        triton_poi_fused_sigmoid_2[grid(1)](buf6, primals_6, 1, XBLOCK=1,
            num_warps=1, num_stages=1)
        del primals_6
    return buf6, reinterpret_tensor(buf1, (1, 1), (1, 1), 0
        ), buf4, primals_5, buf6


class learned_similarity_8New(nn.Module):

    def __init__(self, in_size=1024):
        super(learned_similarity_8New, self).__init__()
        self.lin = nn.Linear(1, 1)
        self.lin2 = nn.Linear(1, 1)
        self.tanh = nn.Tanh()
        self.sigmoid = nn.Sigmoid()

    def forward(self, input_0, input_1):
        primals_3 = self.lin.weight
        primals_4 = self.lin.bias
        primals_5 = self.lin2.weight
        primals_6 = self.lin2.bias
        primals_1 = input_0
        primals_2 = input_1
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6])
        return output[0]


Measured latency_ms: 0.051931