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
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_add_div_mean_pow_sub_sum_0(in_out_ptr0, in_ptr0,
    xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    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 + 16 * x0), xmask, other=0.0)
    tmp5 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last'
        )
    tmp8 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last'
        )
    tmp10 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp12 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp13 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp15 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp17 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp20 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp21 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp23 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp25 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp28 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp29 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp31 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp33 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.where(xmask, tmp1, 0)
    tmp4 = tl.sum(tmp3, 1)[:, None]
    tmp7 = tmp5 + tmp6
    tmp9 = tmp7 + tmp8
    tmp11 = tmp9 + tmp10
    tmp14 = tmp12 + tmp13
    tmp16 = tmp14 + tmp15
    tmp18 = tmp16 + tmp17
    tmp19 = tmp11 + tmp18
    tmp22 = tmp20 + tmp21
    tmp24 = tmp22 + tmp23
    tmp26 = tmp24 + tmp25
    tmp27 = tmp19 + tmp26
    tmp30 = tmp28 + tmp29
    tmp32 = tmp30 + tmp31
    tmp34 = tmp32 + tmp33
    tmp35 = tmp27 + tmp34
    tmp36 = 0.0625
    tmp37 = tmp35 * tmp36
    tmp38 = tmp5 - tmp37
    tmp39 = tmp38 * tmp38
    tmp40 = tmp6 - tmp37
    tmp41 = tmp40 * tmp40
    tmp42 = tmp39 + tmp41
    tmp43 = tmp8 - tmp37
    tmp44 = tmp43 * tmp43
    tmp45 = tmp42 + tmp44
    tmp46 = tmp10 - tmp37
    tmp47 = tmp46 * tmp46
    tmp48 = tmp45 + tmp47
    tmp49 = tmp12 - tmp37
    tmp50 = tmp49 * tmp49
    tmp51 = tmp13 - tmp37
    tmp52 = tmp51 * tmp51
    tmp53 = tmp50 + tmp52
    tmp54 = tmp15 - tmp37
    tmp55 = tmp54 * tmp54
    tmp56 = tmp53 + tmp55
    tmp57 = tmp17 - tmp37
    tmp58 = tmp57 * tmp57
    tmp59 = tmp56 + tmp58
    tmp60 = tmp48 + tmp59
    tmp61 = tmp20 - tmp37
    tmp62 = tmp61 * tmp61
    tmp63 = tmp21 - tmp37
    tmp64 = tmp63 * tmp63
    tmp65 = tmp62 + tmp64
    tmp66 = tmp23 - tmp37
    tmp67 = tmp66 * tmp66
    tmp68 = tmp65 + tmp67
    tmp69 = tmp25 - tmp37
    tmp70 = tmp69 * tmp69
    tmp71 = tmp68 + tmp70
    tmp72 = tmp60 + tmp71
    tmp73 = tmp28 - tmp37
    tmp74 = tmp73 * tmp73
    tmp75 = tmp29 - tmp37
    tmp76 = tmp75 * tmp75
    tmp77 = tmp74 + tmp76
    tmp78 = tmp31 - tmp37
    tmp79 = tmp78 * tmp78
    tmp80 = tmp77 + tmp79
    tmp81 = tmp33 - tmp37
    tmp82 = tmp81 * tmp81
    tmp83 = tmp80 + tmp82
    tmp84 = tmp72 + tmp83
    tmp85 = tmp84 * tmp36
    tmp86 = libdevice.sqrt(tmp85)
    tmp87 = 16.0
    tmp88 = tmp4 / tmp87
    tmp89 = tmp86 + tmp88
    tl.debug_barrier()
    tl.store(in_out_ptr0 + x0, tmp89, xmask)


@triton.jit
def triton_poi_fused_sigmoid_1(in_out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_out_ptr0 + x0, xmask)
    tmp1 = tl.sigmoid(tmp0)
    tl.store(in_out_ptr0 + x0, tmp1, xmask)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (1, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_3, (4, 1, 3, 3), (9, 9, 3, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
        buf1 = buf0
        del buf0
        buf3 = reinterpret_tensor(buf1, (4, 4, 1, 1), (4, 1, 1, 1), 0)
        del buf1
        get_raw_stream(0)
        triton_per_fused_add_div_mean_pow_sub_sum_0[grid(16)](buf3,
            primals_1, 16, 16, XBLOCK=1, num_warps=2, num_stages=1)
        del primals_1
        buf4 = extern_kernels.convolution(buf3, primals_2, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf4, (4, 1, 1, 1), (1, 1, 1, 1))
        buf5 = extern_kernels.convolution(buf4, primals_3, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf5, (4, 4, 1, 1), (4, 1, 1, 1))
        buf6 = buf5
        del buf5
        triton_poi_fused_sigmoid_1[grid(16)](buf6, 16, XBLOCK=16, num_warps
            =1, num_stages=1)
    return buf6, primals_2, primals_3, buf3, buf4, buf6


def mean_channels(F):
    assert F.dim() == 4
    spatial_sum = F.sum(3, keepdim=True).sum(2, keepdim=True)
    return spatial_sum / (F.size(2) * F.size(3))


def stdv_channels(F):
    assert F.dim() == 4
    F_mean = mean_channels(F)
    F_variance = (F - F_mean).pow(2).sum(3, keepdim=True).sum(2, keepdim=True
        ) / (F.size(2) * F.size(3))
    return F_variance.pow(0.5)


def activation(act_type, inplace=False, neg_slope=0.05, n_prelu=1):
    act_type = act_type.lower()
    if act_type == 'relu':
        layer = nn.ReLU(inplace)
    elif act_type == 'lrelu':
        layer = nn.LeakyReLU(neg_slope, inplace)
    elif act_type == 'prelu':
        layer = nn.PReLU(num_parameters=n_prelu, init=neg_slope)
    else:
        raise NotImplementedError('activation layer [{:s}] is not found'.
            format(act_type))
    return layer


class LCCALayerNew(nn.Module):

    def __init__(self, channel):
        super(LCCALayerNew, self).__init__()
        self.contrast = stdv_channels
        self.avg_pool = nn.AdaptiveAvgPool2d(1)
        self.c3 = nn.Conv2d(channel, channel // 4, kernel_size=3, padding=(
            3 - 1) // 2, bias=False)
        self.c32 = nn.Conv2d(channel // 4, channel, kernel_size=3, padding=
            (3 - 1) // 2, bias=False)
        self.act = activation('relu')
        self.sigmoid = nn.Sigmoid()

    def forward(self, input_0):
        primals_2 = self.c3.weight
        primals_3 = self.c32.weight
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3])
        return output[0]


Measured latency_ms: 0.043262