import torch
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 math as tl_math
import torch.utils
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


@triton.jit
def triton_per_fused_max_0(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.
    constexpr):
    xnumel = 4
    RBLOCK: tl.constexpr = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0)
    tmp1 = tl.full([1, 1], 0, tl.int32)
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.where(xmask, tmp3, float('-inf'))
    tmp6 = triton_helpers.max2(tmp5, 1)[:, None]
    tl.store(out_ptr0 + x0, tmp6, xmask)


@triton.jit
def triton_poi_fused_constant_pad_nd_div_exp_relu_1(in_ptr0, in_ptr1,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 576
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 6 % 6
    x0 = xindex % 6
    x4 = xindex // 36
    x3 = xindex // 144
    x6 = xindex
    tmp0 = -1 + x1
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = -1 + x0
    tmp6 = tmp5 >= tmp1
    tmp7 = tmp5 < tmp3
    tmp8 = tmp2 & tmp4
    tmp9 = tmp8 & tmp6
    tmp10 = tmp9 & tmp7
    tmp11 = tl.load(in_ptr0 + (-5 + x0 + 4 * x1 + 16 * x4), tmp10 & xmask,
        other=0.0)
    tmp12 = tl.full([1], 0, tl.int32)
    tmp13 = triton_helpers.maximum(tmp12, tmp11)
    tmp14 = tl.load(in_ptr1 + x3, tmp10 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp15 = tmp13 / tmp14
    tmp16 = tl_math.exp(tmp15)
    tmp17 = tl.full(tmp16.shape, 1.0, tmp16.dtype)
    tmp18 = tl.where(tmp10, tmp16, tmp17)
    tl.store(out_ptr0 + x6, tmp18, xmask)


@triton.jit
def triton_poi_fused_avg_pool2d_constant_pad_nd_div_exp_relu_2(in_ptr0,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = xindex // 4 % 4
    x2 = xindex // 16
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 6 * x1 + 36 * x2), xmask)
    tmp1 = tl.load(in_ptr0 + (1 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp3 = tl.load(in_ptr0 + (2 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp5 = tl.load(in_ptr0 + (6 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp7 = tl.load(in_ptr0 + (7 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp9 = tl.load(in_ptr0 + (8 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp11 = tl.load(in_ptr0 + (12 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp13 = tl.load(in_ptr0 + (13 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp15 = tl.load(in_ptr0 + (14 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp2 = tmp1 + tmp0
    tmp4 = tmp3 + tmp2
    tmp6 = tmp5 + tmp4
    tmp8 = tmp7 + tmp6
    tmp10 = tmp9 + tmp8
    tmp12 = tmp11 + tmp10
    tmp14 = tmp13 + tmp12
    tmp16 = tmp15 + tmp14
    tmp17 = 0.1111111111111111
    tmp18 = tmp16 * tmp17
    tl.store(out_ptr0 + x3, tmp18, xmask)


@triton.jit
def triton_per_fused_div_exp_max_mul_relu_sum_3(in_ptr0, in_ptr1, in_ptr2,
    out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0)
    tmp3 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr2 + (r1 + 64 * x0), xmask, other=0.0)
    tmp10 = tl.load(in_ptr0 + (16 + r1 + 64 * x0), xmask, other=0.0)
    tmp13 = tl.load(in_ptr0 + (32 + r1 + 64 * x0), xmask, other=0.0)
    tmp16 = tl.load(in_ptr0 + (48 + r1 + 64 * x0), xmask, other=0.0)
    tmp23 = tl.load(in_ptr2 + (16 + r1 + 64 * x0), xmask, other=0.0)
    tmp31 = tl.load(in_ptr2 + (32 + r1 + 64 * x0), xmask, other=0.0)
    tmp39 = tl.load(in_ptr2 + (48 + r1 + 64 * x0), xmask, other=0.0)
    tmp1 = tl.full([1, 1], 0, tl.int32)
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tmp4 = tmp2 / tmp3
    tmp5 = tl_math.exp(tmp4)
    tmp7 = 9.0
    tmp8 = tmp6 * tmp7
    tmp9 = tmp5 / tmp8
    tmp11 = triton_helpers.maximum(tmp1, tmp10)
    tmp12 = triton_helpers.maximum(tmp2, tmp11)
    tmp14 = triton_helpers.maximum(tmp1, tmp13)
    tmp15 = triton_helpers.maximum(tmp12, tmp14)
    tmp17 = triton_helpers.maximum(tmp1, tmp16)
    tmp18 = triton_helpers.maximum(tmp15, tmp17)
    tmp19 = tmp2 / tmp18
    tmp20 = tmp9 * tmp19
    tmp21 = tmp11 / tmp3
    tmp22 = tl_math.exp(tmp21)
    tmp24 = tmp23 * tmp7
    tmp25 = tmp22 / tmp24
    tmp26 = tmp11 / tmp18
    tmp27 = tmp25 * tmp26
    tmp28 = triton_helpers.maximum(tmp20, tmp27)
    tmp29 = tmp14 / tmp3
    tmp30 = tl_math.exp(tmp29)
    tmp32 = tmp31 * tmp7
    tmp33 = tmp30 / tmp32
    tmp34 = tmp14 / tmp18
    tmp35 = tmp33 * tmp34
    tmp36 = triton_helpers.maximum(tmp28, tmp35)
    tmp37 = tmp17 / tmp3
    tmp38 = tl_math.exp(tmp37)
    tmp40 = tmp39 * tmp7
    tmp41 = tmp38 / tmp40
    tmp42 = tmp17 / tmp18
    tmp43 = tmp41 * tmp42
    tmp44 = triton_helpers.maximum(tmp36, tmp43)
    tmp45 = tl.broadcast_to(tmp44, [XBLOCK, RBLOCK])
    tmp47 = tl.where(xmask, tmp45, 0)
    tmp48 = tl.sum(tmp47, 1)[:, None]
    tmp49 = tmp44 / tmp48
    tl.store(out_ptr2 + (r1 + 16 * x0), tmp49, xmask)


def call(args):
    arg0_1, = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4,), (1,), torch.float32)
        get_raw_stream(0)
        triton_per_fused_max_0[grid(4)](arg0_1, buf0, 4, 64, XBLOCK=1,
            num_warps=2, num_stages=1)
        buf2 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32)
        triton_poi_fused_constant_pad_nd_div_exp_relu_1[grid(576)](arg0_1,
            buf0, buf2, 576, XBLOCK=256, num_warps=4, num_stages=1)
        buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_avg_pool2d_constant_pad_nd_div_exp_relu_2[grid(256)](
            buf2, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1)
        del buf2
        buf6 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_per_fused_div_exp_max_mul_relu_sum_3[grid(4)](arg0_1, buf0,
            buf3, buf6, 4, 16, XBLOCK=1, num_warps=2, num_stages=1)
        del arg0_1
        del buf0
        del buf3
    return buf6,


class SoftDetectionModuleNew(nn.Module):

    def __init__(self, soft_local_max_size=3):
        super(SoftDetectionModuleNew, self).__init__()
        self.soft_local_max_size = soft_local_max_size
        self.pad = self.soft_local_max_size // 2
        self.scale = 1000

    def forward(self, input_0):
        arg0_1 = input_0
        output = call([arg0_1])
        return output[0]


Measured latency_ms: 0.053491