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.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_poi_fused_add_log_mul_rsub_sum_0(in_ptr0, in_ptr1, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp17 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp21 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp25 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp29 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp1 = 1.0
    tmp2 = tmp1 - tmp0
    tmp3 = 1e-16
    tmp4 = tmp2 + tmp3
    tmp5 = tl_math.log(tmp4)
    tmp7 = tmp1 - tmp6
    tmp8 = tmp5 * tmp7
    tmp10 = tmp1 - tmp9
    tmp11 = tmp10 + tmp3
    tmp12 = tl_math.log(tmp11)
    tmp14 = tmp1 - tmp13
    tmp15 = tmp12 * tmp14
    tmp16 = tmp8 + tmp15
    tmp18 = tmp1 - tmp17
    tmp19 = tmp18 + tmp3
    tmp20 = tl_math.log(tmp19)
    tmp22 = tmp1 - tmp21
    tmp23 = tmp20 * tmp22
    tmp24 = tmp16 + tmp23
    tmp26 = tmp1 - tmp25
    tmp27 = tmp26 + tmp3
    tmp28 = tl_math.log(tmp27)
    tmp30 = tmp1 - tmp29
    tmp31 = tmp28 * tmp30
    tmp32 = tmp24 + tmp31
    tl.store(out_ptr0 + x0, tmp32, xmask)


@triton.jit
def triton_per_fused_add_div_log_mean_mul_rsub_sum_1(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + 16 * r0, None, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + 16 * r0, None, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (1 + 16 * r0), None, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr1 + (1 + 16 * r0), None, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr0 + (2 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp15 = tl.load(in_ptr1 + (2 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp18 = tl.load(in_ptr0 + (3 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp21 = tl.load(in_ptr1 + (3 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp24 = tl.load(in_ptr0 + (4 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp27 = tl.load(in_ptr1 + (4 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp29 = tl.load(in_ptr0 + (5 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp32 = tl.load(in_ptr1 + (5 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp35 = tl.load(in_ptr0 + (6 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp38 = tl.load(in_ptr1 + (6 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp41 = tl.load(in_ptr0 + (7 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp44 = tl.load(in_ptr1 + (7 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp48 = tl.load(in_ptr0 + (8 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp51 = tl.load(in_ptr1 + (8 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp53 = tl.load(in_ptr0 + (9 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp56 = tl.load(in_ptr1 + (9 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp59 = tl.load(in_ptr0 + (10 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp62 = tl.load(in_ptr1 + (10 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp65 = tl.load(in_ptr0 + (11 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp68 = tl.load(in_ptr1 + (11 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp72 = tl.load(in_ptr0 + (12 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp75 = tl.load(in_ptr1 + (12 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp77 = tl.load(in_ptr0 + (13 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp80 = tl.load(in_ptr1 + (13 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp83 = tl.load(in_ptr0 + (14 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp86 = tl.load(in_ptr1 + (14 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp89 = tl.load(in_ptr0 + (15 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp92 = tl.load(in_ptr1 + (15 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp146 = tl.load(in_ptr2 + 4 * r0, None, eviction_policy='evict_last')
    tmp147 = tl.load(in_ptr2 + (1 + 4 * r0), None, eviction_policy='evict_last'
        )
    tmp149 = tl.load(in_ptr2 + (2 + 4 * r0), None, eviction_policy='evict_last'
        )
    tmp151 = tl.load(in_ptr2 + (3 + 4 * r0), None, eviction_policy='evict_last'
        )
    tmp1 = 1e-16
    tmp2 = tmp0 + tmp1
    tmp3 = tl_math.log(tmp2)
    tmp5 = tmp3 * tmp4
    tmp7 = tmp6 + tmp1
    tmp8 = tl_math.log(tmp7)
    tmp10 = tmp8 * tmp9
    tmp11 = tmp5 + tmp10
    tmp13 = tmp12 + tmp1
    tmp14 = tl_math.log(tmp13)
    tmp16 = tmp14 * tmp15
    tmp17 = tmp11 + tmp16
    tmp19 = tmp18 + tmp1
    tmp20 = tl_math.log(tmp19)
    tmp22 = tmp20 * tmp21
    tmp23 = tmp17 + tmp22
    tmp25 = tmp24 + tmp1
    tmp26 = tl_math.log(tmp25)
    tmp28 = tmp26 * tmp27
    tmp30 = tmp29 + tmp1
    tmp31 = tl_math.log(tmp30)
    tmp33 = tmp31 * tmp32
    tmp34 = tmp28 + tmp33
    tmp36 = tmp35 + tmp1
    tmp37 = tl_math.log(tmp36)
    tmp39 = tmp37 * tmp38
    tmp40 = tmp34 + tmp39
    tmp42 = tmp41 + tmp1
    tmp43 = tl_math.log(tmp42)
    tmp45 = tmp43 * tmp44
    tmp46 = tmp40 + tmp45
    tmp47 = tmp23 + tmp46
    tmp49 = tmp48 + tmp1
    tmp50 = tl_math.log(tmp49)
    tmp52 = tmp50 * tmp51
    tmp54 = tmp53 + tmp1
    tmp55 = tl_math.log(tmp54)
    tmp57 = tmp55 * tmp56
    tmp58 = tmp52 + tmp57
    tmp60 = tmp59 + tmp1
    tmp61 = tl_math.log(tmp60)
    tmp63 = tmp61 * tmp62
    tmp64 = tmp58 + tmp63
    tmp66 = tmp65 + tmp1
    tmp67 = tl_math.log(tmp66)
    tmp69 = tmp67 * tmp68
    tmp70 = tmp64 + tmp69
    tmp71 = tmp47 + tmp70
    tmp73 = tmp72 + tmp1
    tmp74 = tl_math.log(tmp73)
    tmp76 = tmp74 * tmp75
    tmp78 = tmp77 + tmp1
    tmp79 = tl_math.log(tmp78)
    tmp81 = tmp79 * tmp80
    tmp82 = tmp76 + tmp81
    tmp84 = tmp83 + tmp1
    tmp85 = tl_math.log(tmp84)
    tmp87 = tmp85 * tmp86
    tmp88 = tmp82 + tmp87
    tmp90 = tmp89 + tmp1
    tmp91 = tl_math.log(tmp90)
    tmp93 = tmp91 * tmp92
    tmp94 = tmp88 + tmp93
    tmp95 = tmp71 + tmp94
    tmp96 = tmp4 + tmp9
    tmp97 = tmp96 + tmp15
    tmp98 = tmp97 + tmp21
    tmp99 = tmp27 + tmp32
    tmp100 = tmp99 + tmp38
    tmp101 = tmp100 + tmp44
    tmp102 = tmp98 + tmp101
    tmp103 = tmp51 + tmp56
    tmp104 = tmp103 + tmp62
    tmp105 = tmp104 + tmp68
    tmp106 = tmp102 + tmp105
    tmp107 = tmp75 + tmp80
    tmp108 = tmp107 + tmp86
    tmp109 = tmp108 + tmp92
    tmp110 = tmp106 + tmp109
    tmp111 = 1.0
    tmp112 = tmp111 - tmp4
    tmp113 = tmp111 - tmp9
    tmp114 = tmp112 + tmp113
    tmp115 = tmp111 - tmp15
    tmp116 = tmp114 + tmp115
    tmp117 = tmp111 - tmp21
    tmp118 = tmp116 + tmp117
    tmp119 = tmp111 - tmp27
    tmp120 = tmp111 - tmp32
    tmp121 = tmp119 + tmp120
    tmp122 = tmp111 - tmp38
    tmp123 = tmp121 + tmp122
    tmp124 = tmp111 - tmp44
    tmp125 = tmp123 + tmp124
    tmp126 = tmp118 + tmp125
    tmp127 = tmp111 - tmp51
    tmp128 = tmp111 - tmp56
    tmp129 = tmp127 + tmp128
    tmp130 = tmp111 - tmp62
    tmp131 = tmp129 + tmp130
    tmp132 = tmp111 - tmp68
    tmp133 = tmp131 + tmp132
    tmp134 = tmp126 + tmp133
    tmp135 = tmp111 - tmp75
    tmp136 = tmp111 - tmp80
    tmp137 = tmp135 + tmp136
    tmp138 = tmp111 - tmp86
    tmp139 = tmp137 + tmp138
    tmp140 = tmp111 - tmp92
    tmp141 = tmp139 + tmp140
    tmp142 = tmp134 + tmp141
    tmp143 = -1.0
    tmp144 = tmp95 * tmp143
    tmp145 = tmp144 / tmp110
    tmp148 = tmp146 + tmp147
    tmp150 = tmp148 + tmp149
    tmp152 = tmp150 + tmp151
    tmp153 = tmp152 * tmp143
    tmp154 = tmp153 / tmp142
    tmp155 = tmp145 + tmp154
    tmp156 = tl.broadcast_to(tmp155, [XBLOCK, RBLOCK])
    tmp158 = tl.sum(tmp156, 1)[:, None]
    tmp159 = 16.0
    tmp160 = tmp158 / tmp159
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp160, None)


def call(args):
    arg0_1, arg1_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))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_add_log_mul_rsub_sum_0[grid(64)](arg1_1, arg0_1,
            buf2, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf4 = empty_strided_cuda((), (), torch.float32)
        buf5 = buf4
        del buf4
        triton_per_fused_add_div_log_mean_mul_rsub_sum_1[grid(1)](buf5,
            arg1_1, arg0_1, buf2, 1, 16, XBLOCK=1, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
        del buf2
    return buf5,


class WCE_lossNew(nn.Module):

    def __init__(self):
        super(WCE_lossNew, self).__init__()

    def sum_ij(self, x):
        return torch.sum(torch.sum(x, dim=3), dim=2)

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


Measured latency_ms: 0.028913