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.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_add_div_exp_log_mul_pow_sub_sum_0(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, xnumel, rnumel):
    XBLOCK: tl.constexpr = 1
    RBLOCK: tl.constexpr = 1024
    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 % 64
    r2 = rindex // 256
    r3 = rindex % 256
    tmp0 = tl.load(in_ptr0 + (r0 + 64 * r2), None, eviction_policy='evict_last'
        )
    tmp3 = tl.load(in_ptr0 + r3, None, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr1 + (r0 + 64 * r2), None, eviction_policy='evict_last'
        )
    tmp11 = tl.load(in_ptr1 + r3, None, eviction_policy='evict_last')
    tmp25 = tl.load(in_ptr2 + (r0 + 64 * r2), None, eviction_policy=
        'evict_last')
    tmp27 = tl.load(in_ptr2 + r3, None, eviction_policy='evict_last')
    tmp31 = tl.load(in_ptr3 + (r0 + 64 * r2), None, eviction_policy=
        'evict_last')
    tmp35 = tl.load(in_ptr3 + r3, None, eviction_policy='evict_last')
    tmp1 = 1.0
    tmp2 = tmp0 * tmp1
    tmp4 = tmp3 * tmp1
    tmp5 = tmp2 - tmp4
    tmp6 = tmp5 * tmp5
    tmp8 = tl_math.exp(tmp7)
    tmp9 = tmp8 * tmp1
    tmp10 = tmp9 * tmp1
    tmp12 = tl_math.exp(tmp11)
    tmp13 = tmp12 * tmp1
    tmp14 = tmp13 * tmp1
    tmp15 = tmp10 + tmp14
    tmp16 = tmp6 / tmp15
    tmp17 = tl_math.log(tmp15)
    tmp18 = tmp16 + tmp17
    tmp19 = -0.5
    tmp20 = tmp18 * tmp19
    tmp21 = tl_math.exp(tmp20)
    tmp22 = tl.broadcast_to(tmp21, [RBLOCK])
    tmp24 = triton_helpers.promote_to_tensor(tl.sum(tmp22, 0))
    tmp26 = tmp25 * tmp1
    tmp28 = tmp27 * tmp1
    tmp29 = tmp26 - tmp28
    tmp30 = tmp29 * tmp29
    tmp32 = tl_math.exp(tmp31)
    tmp33 = tmp32 * tmp1
    tmp34 = tmp33 * tmp1
    tmp36 = tl_math.exp(tmp35)
    tmp37 = tmp36 * tmp1
    tmp38 = tmp37 * tmp1
    tmp39 = tmp34 + tmp38
    tmp40 = tmp30 / tmp39
    tmp41 = tl_math.log(tmp39)
    tmp42 = tmp40 + tmp41
    tmp43 = tmp42 * tmp19
    tmp44 = tl_math.exp(tmp43)
    tmp45 = tl.broadcast_to(tmp44, [RBLOCK])
    tmp47 = triton_helpers.promote_to_tensor(tl.sum(tmp45, 0))
    tmp48 = tmp2 - tmp28
    tmp49 = tmp48 * tmp48
    tmp50 = tmp10 + tmp38
    tmp51 = tmp49 / tmp50
    tmp52 = tl_math.log(tmp50)
    tmp53 = tmp51 + tmp52
    tmp54 = tmp53 * tmp19
    tmp55 = tl_math.exp(tmp54)
    tmp56 = tl.broadcast_to(tmp55, [RBLOCK])
    tmp58 = triton_helpers.promote_to_tensor(tl.sum(tmp56, 0))
    tmp59 = tmp24 + tmp47
    tmp60 = 2.0
    tmp61 = tmp58 * tmp60
    tmp62 = tmp59 - tmp61
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp62, None)


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, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg3_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((), (), torch.float32)
        buf3 = buf0
        del buf0
        get_raw_stream(0)
        triton_per_fused_add_div_exp_log_mul_pow_sub_sum_0[grid(1)](buf3,
            arg0_1, arg2_1, arg1_1, arg3_1, 1, 1024, num_warps=8, num_stages=1)
        del arg0_1
        del arg1_1
        del arg2_1
        del arg3_1
    return buf3,


class Gaussian_DistanceNew(nn.Module):

    def __init__(self, kern=1):
        super(Gaussian_DistanceNew, self).__init__()
        self.kern = kern
        self.avgpool = nn.AvgPool2d(kernel_size=kern, stride=kern)

    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.015372