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.triton_helpers import libdevice
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_poi_fused_add_div_mul_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x4 = xindex // 4
    x0 = xindex % 4
    x2 = xindex // 16
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + 4 * x4, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (1 + 4 * x4), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (2 + 4 * x4), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr0 + (3 + 4 * x4), xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr1 + (4 * x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp17 = tl.load(in_ptr1 + (1 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr1 + (2 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr1 + (3 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp2 = tmp1 * tmp1
    tmp4 = tmp3 * tmp3
    tmp5 = tmp2 + tmp4
    tmp7 = tmp6 * tmp6
    tmp8 = tmp5 + tmp7
    tmp10 = tmp9 * tmp9
    tmp11 = tmp8 + tmp10
    tmp12 = libdevice.sqrt(tmp11)
    tmp13 = 1e-09
    tmp14 = tmp12 + tmp13
    tmp16 = tmp15 * tmp15
    tmp18 = tmp17 * tmp17
    tmp19 = tmp16 + tmp18
    tmp21 = tmp20 * tmp20
    tmp22 = tmp19 + tmp21
    tmp24 = tmp23 * tmp23
    tmp25 = tmp22 + tmp24
    tmp26 = libdevice.sqrt(tmp25)
    tmp27 = tmp26 + tmp13
    tmp28 = tmp14 * tmp27
    tmp29 = tmp0 / tmp28
    tl.store(in_out_ptr0 + x3, tmp29, xmask)


@triton.jit
def triton_poi_fused_add_div_mul_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x4 = xindex // 4
    x0 = xindex % 4
    x2 = xindex // 16
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + (64 + 4 * x4), xmask, eviction_policy='evict_last'
        )
    tmp3 = tl.load(in_ptr0 + (65 + 4 * x4), xmask, eviction_policy='evict_last'
        )
    tmp6 = tl.load(in_ptr0 + (66 + 4 * x4), xmask, eviction_policy='evict_last'
        )
    tmp9 = tl.load(in_ptr0 + (67 + 4 * x4), xmask, eviction_policy='evict_last'
        )
    tmp15 = tl.load(in_ptr1 + (64 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp17 = tl.load(in_ptr1 + (65 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr1 + (66 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr1 + (67 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp2 = tmp1 * tmp1
    tmp4 = tmp3 * tmp3
    tmp5 = tmp2 + tmp4
    tmp7 = tmp6 * tmp6
    tmp8 = tmp5 + tmp7
    tmp10 = tmp9 * tmp9
    tmp11 = tmp8 + tmp10
    tmp12 = libdevice.sqrt(tmp11)
    tmp13 = 1e-09
    tmp14 = tmp12 + tmp13
    tmp16 = tmp15 * tmp15
    tmp18 = tmp17 * tmp17
    tmp19 = tmp16 + tmp18
    tmp21 = tmp20 * tmp20
    tmp22 = tmp19 + tmp21
    tmp24 = tmp23 * tmp23
    tmp25 = tmp22 + tmp24
    tmp26 = libdevice.sqrt(tmp25)
    tmp27 = tmp26 + tmp13
    tmp28 = tmp14 * tmp27
    tmp29 = tmp0 / tmp28
    tl.store(in_out_ptr0 + x3, tmp29, xmask)


@triton.jit
def triton_poi_fused_add_div_mul_2(in_out_ptr0, in_ptr0, in_ptr1, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x4 = xindex // 4
    x0 = xindex % 4
    x2 = xindex // 16
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + (128 + 4 * x4), xmask, eviction_policy=
        'evict_last')
    tmp3 = tl.load(in_ptr0 + (129 + 4 * x4), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (130 + 4 * x4), xmask, eviction_policy=
        'evict_last')
    tmp9 = tl.load(in_ptr0 + (131 + 4 * x4), xmask, eviction_policy=
        'evict_last')
    tmp15 = tl.load(in_ptr1 + (128 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp17 = tl.load(in_ptr1 + (129 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr1 + (130 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr1 + (131 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp2 = tmp1 * tmp1
    tmp4 = tmp3 * tmp3
    tmp5 = tmp2 + tmp4
    tmp7 = tmp6 * tmp6
    tmp8 = tmp5 + tmp7
    tmp10 = tmp9 * tmp9
    tmp11 = tmp8 + tmp10
    tmp12 = libdevice.sqrt(tmp11)
    tmp13 = 1e-09
    tmp14 = tmp12 + tmp13
    tmp16 = tmp15 * tmp15
    tmp18 = tmp17 * tmp17
    tmp19 = tmp16 + tmp18
    tmp21 = tmp20 * tmp20
    tmp22 = tmp19 + tmp21
    tmp24 = tmp23 * tmp23
    tmp25 = tmp22 + tmp24
    tmp26 = libdevice.sqrt(tmp25)
    tmp27 = tmp26 + tmp13
    tmp28 = tmp14 * tmp27
    tmp29 = tmp0 / tmp28
    tl.store(in_out_ptr0 + x3, tmp29, xmask)


@triton.jit
def triton_poi_fused_add_div_mul_3(in_out_ptr0, in_ptr0, in_ptr1, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x4 = xindex // 4
    x0 = xindex % 4
    x2 = xindex // 16
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + (192 + 4 * x4), xmask, eviction_policy=
        'evict_last')
    tmp3 = tl.load(in_ptr0 + (193 + 4 * x4), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (194 + 4 * x4), xmask, eviction_policy=
        'evict_last')
    tmp9 = tl.load(in_ptr0 + (195 + 4 * x4), xmask, eviction_policy=
        'evict_last')
    tmp15 = tl.load(in_ptr1 + (192 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp17 = tl.load(in_ptr1 + (193 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr1 + (194 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr1 + (195 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp2 = tmp1 * tmp1
    tmp4 = tmp3 * tmp3
    tmp5 = tmp2 + tmp4
    tmp7 = tmp6 * tmp6
    tmp8 = tmp5 + tmp7
    tmp10 = tmp9 * tmp9
    tmp11 = tmp8 + tmp10
    tmp12 = libdevice.sqrt(tmp11)
    tmp13 = 1e-09
    tmp14 = tmp12 + tmp13
    tmp16 = tmp15 * tmp15
    tmp18 = tmp17 * tmp17
    tmp19 = tmp16 + tmp18
    tmp21 = tmp20 * tmp20
    tmp22 = tmp19 + tmp21
    tmp24 = tmp23 * tmp23
    tmp25 = tmp22 + tmp24
    tmp26 = libdevice.sqrt(tmp25)
    tmp27 = tmp26 + tmp13
    tmp28 = tmp14 * tmp27
    tmp29 = tmp0 / tmp28
    tl.store(in_out_ptr0 + x3, tmp29, xmask)


@triton.jit
def triton_poi_fused_stack_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
    in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4 % 16
    x0 = xindex % 4
    x2 = xindex // 64
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = -1.0
    tmp7 = tmp5 == tmp6
    tmp8 = tl.load(in_ptr1 + (4 * x2 + x1), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp9 = tmp8 == tmp6
    tmp10 = tl.load(in_ptr2 + (x0 + 4 * x1 + 16 * x2), tmp4 & xmask, other=0.0)
    tmp11 = 0.0
    tmp12 = tl.where(tmp9, tmp11, tmp10)
    tmp13 = tl.where(tmp7, tmp11, tmp12)
    tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype)
    tmp15 = tl.where(tmp4, tmp13, tmp14)
    tmp16 = tmp0 >= tmp3
    tmp17 = tl.full([1], 8, tl.int64)
    tmp18 = tmp0 < tmp17
    tmp19 = tmp16 & tmp18
    tmp20 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp19 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp21 = tmp20 == tmp6
    tmp22 = tl.load(in_ptr1 + (4 * x2 + (-4 + x1)), tmp19 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp23 = tmp22 == tmp6
    tmp24 = tl.load(in_ptr3 + (x0 + 4 * (-4 + x1) + 16 * x2), tmp19 & xmask,
        other=0.0)
    tmp25 = tl.where(tmp23, tmp11, tmp24)
    tmp26 = tl.where(tmp21, tmp11, tmp25)
    tmp27 = tl.full(tmp26.shape, 0.0, tmp26.dtype)
    tmp28 = tl.where(tmp19, tmp26, tmp27)
    tmp29 = tmp0 >= tmp17
    tmp30 = tl.full([1], 12, tl.int64)
    tmp31 = tmp0 < tmp30
    tmp32 = tmp29 & tmp31
    tmp33 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp32 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp34 = tmp33 == tmp6
    tmp35 = tl.load(in_ptr1 + (4 * x2 + (-8 + x1)), tmp32 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp36 = tmp35 == tmp6
    tmp37 = tl.load(in_ptr4 + (x0 + 4 * (-8 + x1) + 16 * x2), tmp32 & xmask,
        other=0.0)
    tmp38 = tl.where(tmp36, tmp11, tmp37)
    tmp39 = tl.where(tmp34, tmp11, tmp38)
    tmp40 = tl.full(tmp39.shape, 0.0, tmp39.dtype)
    tmp41 = tl.where(tmp32, tmp39, tmp40)
    tmp42 = tmp0 >= tmp30
    tl.full([1], 16, tl.int64)
    tmp45 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp42 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp46 = tmp45 == tmp6
    tmp47 = tl.load(in_ptr1 + (4 * x2 + (-12 + x1)), tmp42 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp48 = tmp47 == tmp6
    tmp49 = tl.load(in_ptr5 + (x0 + 4 * (-12 + x1) + 16 * x2), tmp42 &
        xmask, other=0.0)
    tmp50 = tl.where(tmp48, tmp11, tmp49)
    tmp51 = tl.where(tmp46, tmp11, tmp50)
    tmp52 = tl.full(tmp51.shape, 0.0, tmp51.dtype)
    tmp53 = tl.where(tmp42, tmp51, tmp52)
    tmp54 = tl.where(tmp32, tmp41, tmp53)
    tmp55 = tl.where(tmp19, tmp28, tmp54)
    tmp56 = tl.where(tmp4, tmp15, tmp55)
    tl.store(out_ptr0 + x3, tmp56, xmask)


def call(args):
    arg0_1, arg1_1, arg2_1, arg3_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg2_1, (4, 4, 1), (4, 1, 1))
    assert_size_stride(arg3_1, (4, 1, 4), (4, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 4), (16, 4, 1),
            0), reinterpret_tensor(arg1_1, (4, 4, 4), (16, 1, 4), 0), out=buf0)
        buf1 = buf0
        del buf0
        get_raw_stream(0)
        triton_poi_fused_add_div_mul_0[grid(64)](buf1, arg0_1, arg1_1, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 4), (16, 4, 1),
            64), reinterpret_tensor(arg1_1, (4, 4, 4), (16, 1, 4), 64), out
            =buf2)
        buf3 = buf2
        del buf2
        triton_poi_fused_add_div_mul_1[grid(64)](buf3, arg0_1, arg1_1, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 4), (16, 4, 1),
            128), reinterpret_tensor(arg1_1, (4, 4, 4), (16, 1, 4), 128),
            out=buf4)
        buf5 = buf4
        del buf4
        triton_poi_fused_add_div_mul_2[grid(64)](buf5, arg0_1, arg1_1, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        buf6 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 4), (16, 4, 1),
            192), reinterpret_tensor(arg1_1, (4, 4, 4), (16, 1, 4), 192),
            out=buf6)
        buf7 = buf6
        del buf6
        triton_poi_fused_add_div_mul_3[grid(64)](buf7, arg0_1, arg1_1, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del arg0_1
        del arg1_1
        buf8 = empty_strided_cuda((4, 16, 4), (64, 4, 1), torch.float32)
        triton_poi_fused_stack_4[grid(256)](arg3_1, arg2_1, buf1, buf3,
            buf5, buf7, buf8, 256, XBLOCK=128, num_warps=4, num_stages=1)
        del arg2_1
        del arg3_1
        del buf1
        del buf3
        del buf5
        del buf7
    return reinterpret_tensor(buf8, (4, 4, 4, 4), (64, 16, 4, 1), 0),


class SimmatModuleNew(torch.nn.Module):

    def __init__(self, padding=-1):
        super().__init__()
        self.padding = padding
        self._hamming_index_loaded = None
        self._hamming_index = None

    def forward(self, input_0, input_1, input_2, input_3):
        arg0_1 = input_0
        arg1_1 = input_1
        arg2_1 = input_2
        arg3_1 = input_3
        output = call([arg0_1, arg1_1, arg2_1, arg3_1])
        return output[0]


Measured latency_ms: 0.065331