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
from torch import 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_smooth_l1_loss_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')
    tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp12 = 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'
        )
    tmp23 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp24 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp34 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp35 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp2 = tmp0 - tmp1
    tmp3 = tl_math.abs(tmp2)
    tmp4 = 1.0
    tmp5 = tmp3 < tmp4
    tmp6 = tmp3 * tmp3
    tmp7 = 0.5
    tmp8 = tmp6 * tmp7
    tmp9 = tmp8 * tmp4
    tmp10 = tmp3 - tmp7
    tmp11 = tl.where(tmp5, tmp9, tmp10)
    tmp14 = tmp12 - tmp13
    tmp15 = tl_math.abs(tmp14)
    tmp16 = tmp15 < tmp4
    tmp17 = tmp15 * tmp15
    tmp18 = tmp17 * tmp7
    tmp19 = tmp18 * tmp4
    tmp20 = tmp15 - tmp7
    tmp21 = tl.where(tmp16, tmp19, tmp20)
    tmp22 = tmp11 + tmp21
    tmp25 = tmp23 - tmp24
    tmp26 = tl_math.abs(tmp25)
    tmp27 = tmp26 < tmp4
    tmp28 = tmp26 * tmp26
    tmp29 = tmp28 * tmp7
    tmp30 = tmp29 * tmp4
    tmp31 = tmp26 - tmp7
    tmp32 = tl.where(tmp27, tmp30, tmp31)
    tmp33 = tmp22 + tmp32
    tmp36 = tmp34 - tmp35
    tmp37 = tl_math.abs(tmp36)
    tmp38 = tmp37 < tmp4
    tmp39 = tmp37 * tmp37
    tmp40 = tmp39 * tmp7
    tmp41 = tmp40 * tmp4
    tmp42 = tmp37 - tmp7
    tmp43 = tl.where(tmp38, tmp41, tmp42)
    tmp44 = tmp33 + tmp43
    tl.store(out_ptr0 + x0, tmp44, xmask)


@triton.jit
def triton_per_fused_mul_sum_1(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel):
    XBLOCK: tl.constexpr = 1
    RBLOCK: tl.constexpr = 256
    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
    tmp0 = tl.load(in_ptr0 + r0, None, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + r2, None)
    tmp2 = tmp0 * tmp1
    tmp3 = tl.broadcast_to(tmp2, [RBLOCK])
    tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0))
    tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp5, None)


def call(args):
    arg0_1, arg1_1, arg2_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))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_smooth_l1_loss_sum_0[grid(64)](arg0_1, arg1_1,
            buf0, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del arg0_1
        del arg1_1
        buf1 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_mul_sum_1[grid(1)](buf0, arg2_1, buf1, 1, 256,
            num_warps=2, num_stages=1)
        del arg2_1
        del buf0
    return buf1,


class SmoothL1loss_with_weightNew(nn.Module):

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

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


Measured latency_ms: 0.033291