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 libdevice, math as tl_math
import torch.utils.data.distributed
import torch.nn as nn
import torch.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_red_fused__to_copy__unsafe_index_add_arange_clamp_log_mean_mul_pow_sqrt_sub_var_0(
    in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.
    constexpr, RBLOCK: tl.constexpr):
    rnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rbase = tl.arange(0, RBLOCK)[None, :]
    tmp44_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
    tmp44_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
    tmp44_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
    _tmp47 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
    for roffset in range(0, rnumel, RBLOCK):
        rindex = roffset + rbase
        rmask = rindex < rnumel
        r1 = rindex // 4 % 4
        r0 = rindex % 4
        r2 = rindex // 16
        r3 = rindex
        tmp40 = tl.load(in_ptr1 + r3, rmask, eviction_policy='evict_first',
            other=0.0)
        tmp0 = r1
        tmp1 = tmp0.to(tl.float32)
        tmp2 = 1.0
        tmp3 = tmp1 * tmp2
        tmp4 = 0.0
        tmp5 = triton_helpers.maximum(tmp3, tmp4)
        tmp6 = tmp5.to(tl.int32)
        tmp7 = tl.full([1, 1], 1, tl.int64)
        tmp8 = tmp6 + tmp7
        tmp9 = tl.full([1, 1], 3, tl.int64)
        tmp10 = triton_helpers.minimum(tmp8, tmp9)
        tmp11 = r0
        tmp12 = tmp11.to(tl.float32)
        tmp13 = tmp12 * tmp2
        tmp14 = triton_helpers.maximum(tmp13, tmp4)
        tmp15 = tmp14.to(tl.int32)
        tmp16 = tl.load(in_ptr0 + (tmp15 + 4 * tmp10 + 16 * r2), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp17 = tmp15 + tmp7
        tmp18 = triton_helpers.minimum(tmp17, tmp9)
        tmp19 = tl.load(in_ptr0 + (tmp18 + 4 * tmp10 + 16 * r2), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp20 = tmp19 - tmp16
        tmp21 = tmp15.to(tl.float32)
        tmp22 = tmp14 - tmp21
        tmp23 = triton_helpers.maximum(tmp22, tmp4)
        tmp24 = triton_helpers.minimum(tmp23, tmp2)
        tmp25 = tmp20 * tmp24
        tmp26 = tmp16 + tmp25
        tmp27 = tl.load(in_ptr0 + (tmp15 + 4 * tmp6 + 16 * r2), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp28 = tl.load(in_ptr0 + (tmp18 + 4 * tmp6 + 16 * r2), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp29 = tmp28 - tmp27
        tmp30 = tmp29 * tmp24
        tmp31 = tmp27 + tmp30
        tmp32 = tmp26 - tmp31
        tmp33 = tmp6.to(tl.float32)
        tmp34 = tmp5 - tmp33
        tmp35 = triton_helpers.maximum(tmp34, tmp4)
        tmp36 = triton_helpers.minimum(tmp35, tmp2)
        tmp37 = tmp32 * tmp36
        tmp38 = tmp31 + tmp37
        tmp39 = tl_math.log(tmp38)
        tmp41 = tl_math.log(tmp40)
        tmp42 = tmp39 - tmp41
        tmp43 = tl.broadcast_to(tmp42, [XBLOCK, RBLOCK])
        tmp44_mean_next, tmp44_m2_next, tmp44_weight_next = (triton_helpers
            .welford_reduce(tmp43, tmp44_mean, tmp44_m2, tmp44_weight, 
            roffset == 0))
        tmp44_mean = tl.where(rmask, tmp44_mean_next, tmp44_mean)
        tmp44_m2 = tl.where(rmask, tmp44_m2_next, tmp44_m2)
        tmp44_weight = tl.where(rmask, tmp44_weight_next, tmp44_weight)
        tmp48 = _tmp47 + tmp43
        _tmp47 = tl.where(rmask, tmp48, _tmp47)
        tl.store(in_out_ptr0 + tl.broadcast_to(r3, [XBLOCK, RBLOCK]), tmp38,
            rmask)
    tmp44_tmp, tmp45_tmp, tmp46_tmp = triton_helpers.welford(tmp44_mean,
        tmp44_m2, tmp44_weight, 1)
    tmp44_tmp[:, None]
    tmp45 = tmp45_tmp[:, None]
    tmp46_tmp[:, None]
    tmp47 = tl.sum(_tmp47, 1)[:, None]
    tmp49 = 255.0
    tmp50 = tmp45 / tmp49
    tmp51 = 256.0
    tmp52 = tmp47 / tmp51
    tmp53 = tmp52 * tmp52
    tmp54 = 0.15
    tmp55 = tmp53 * tmp54
    tmp56 = tmp50 + tmp55
    tmp57 = libdevice.sqrt(tmp56)
    tmp58 = 10.0
    tmp59 = tmp57 * tmp58
    tl.debug_barrier()
    tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp59, 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)
        buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf1 = buf0
        del buf0
        buf3 = empty_strided_cuda((), (), torch.float32)
        buf6 = buf3
        del buf3
        get_raw_stream(0)
        triton_red_fused__to_copy__unsafe_index_add_arange_clamp_log_mean_mul_pow_sqrt_sub_var_0[
            grid(1)](buf1, buf6, arg1_1, arg0_1, 1, 256, XBLOCK=1, RBLOCK=
            256, num_warps=8, num_stages=1)
        del arg0_1
        del arg1_1
        del buf1
    return buf6,


class SILogLossNew(nn.Module):

    def __init__(self):
        super(SILogLossNew, self).__init__()
        self.name = 'SILog'

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