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.utils.data
import torch
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_red_fused_abs_mean_sub_0(in_ptr0, in_ptr1, out_ptr0, xnumel,
    rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
    xnumel = 8
    rnumel = 8192
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rbase = tl.arange(0, RBLOCK)[None, :]
    x0 = xindex
    _tmp5 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
    for roffset in range(0, rnumel, RBLOCK):
        rindex = roffset + rbase
        rmask = rindex < rnumel
        r1 = rindex
        tmp0 = tl.load(in_ptr0 + (r1 + 8192 * x0), rmask & xmask,
            eviction_policy='evict_last', other=0.0)
        tmp1 = tl.load(in_ptr1 + (r1 + 8192 * x0), rmask & xmask,
            eviction_policy='evict_last', other=0.0)
        tmp2 = tmp0 - tmp1
        tmp3 = tl_math.abs(tmp2)
        tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
        tmp6 = _tmp5 + tmp4
        _tmp5 = tl.where(rmask & xmask, tmp6, _tmp5)
    tmp5 = tl.sum(_tmp5, 1)[:, None]
    tl.store(out_ptr0 + x0, tmp5, xmask)


@triton.jit
def triton_per_fused_abs_mean_sub_1(in_ptr0, out_ptr0, xnumel, rnumel,
    XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 8
    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 + r0, None)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.sum(tmp1, 1)[:, None]
    tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp3, None)


@triton.jit
def triton_red_fused_abs_avg_pool2d_mean_sub_2(in_ptr0, in_ptr1, out_ptr0,
    out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.
    constexpr):
    xnumel = 2
    rnumel = 8192
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rbase = tl.arange(0, RBLOCK)[None, :]
    x0 = xindex
    _tmp20 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
    for roffset in range(0, rnumel, RBLOCK):
        rindex = roffset + rbase
        rmask = rindex < rnumel
        r1 = rindex % 32
        r2 = rindex // 32
        r3 = rindex
        tmp0 = tl.load(in_ptr0 + (2 * r1 + 128 * r2 + 32768 * x0), rmask &
            xmask, eviction_policy='evict_last', other=0.0)
        tmp1 = tl.load(in_ptr0 + (1 + 2 * r1 + 128 * r2 + 32768 * x0), 
            rmask & xmask, eviction_policy='evict_last', other=0.0)
        tmp3 = tl.load(in_ptr0 + (64 + 2 * r1 + 128 * r2 + 32768 * x0), 
            rmask & xmask, eviction_policy='evict_last', other=0.0)
        tmp5 = tl.load(in_ptr0 + (65 + 2 * r1 + 128 * r2 + 32768 * x0), 
            rmask & xmask, eviction_policy='evict_last', other=0.0)
        tmp9 = tl.load(in_ptr1 + (2 * r1 + 128 * r2 + 32768 * x0), rmask &
            xmask, eviction_policy='evict_last', other=0.0)
        tmp10 = tl.load(in_ptr1 + (1 + 2 * r1 + 128 * r2 + 32768 * x0), 
            rmask & xmask, eviction_policy='evict_last', other=0.0)
        tmp12 = tl.load(in_ptr1 + (64 + 2 * r1 + 128 * r2 + 32768 * x0), 
            rmask & xmask, eviction_policy='evict_last', other=0.0)
        tmp14 = tl.load(in_ptr1 + (65 + 2 * r1 + 128 * r2 + 32768 * x0), 
            rmask & xmask, eviction_policy='evict_last', other=0.0)
        tmp2 = tmp1 + tmp0
        tmp4 = tmp3 + tmp2
        tmp6 = tmp5 + tmp4
        tmp7 = 0.25
        tmp8 = tmp6 * tmp7
        tmp11 = tmp10 + tmp9
        tmp13 = tmp12 + tmp11
        tmp15 = tmp14 + tmp13
        tmp16 = tmp15 * tmp7
        tmp17 = tmp8 - tmp16
        tmp18 = tl_math.abs(tmp17)
        tmp19 = tl.broadcast_to(tmp18, [XBLOCK, RBLOCK])
        tmp21 = _tmp20 + tmp19
        _tmp20 = tl.where(rmask & xmask, tmp21, _tmp20)
        tl.store(out_ptr0 + (r3 + 8192 * x0), tmp8, rmask & xmask)
        tl.store(out_ptr1 + (r3 + 8192 * x0), tmp16, rmask & xmask)
    tmp20 = tl.sum(_tmp20, 1)[:, None]
    tl.store(out_ptr2 + x0, tmp20, xmask)


@triton.jit
def triton_per_fused_abs_mean_sub_3(in_ptr0, out_ptr0, xnumel, rnumel,
    XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 2
    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 + r0, None)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.sum(tmp1, 1)[:, None]
    tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp3, None)


@triton.jit
def triton_red_fused_abs_avg_pool2d_mean_sub_4(in_ptr0, in_ptr1, out_ptr0,
    out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.
    constexpr):
    rnumel = 4096
    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, :]
    _tmp20 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
    for roffset in range(0, rnumel, RBLOCK):
        rindex = roffset + rbase
        rmask = rindex < rnumel
        r0 = rindex % 16
        r1 = rindex // 16
        r2 = rindex
        tmp0 = tl.load(in_ptr0 + (2 * r0 + 64 * r1), rmask, eviction_policy
            ='evict_last', other=0.0)
        tmp1 = tl.load(in_ptr0 + (1 + 2 * r0 + 64 * r1), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp3 = tl.load(in_ptr0 + (32 + 2 * r0 + 64 * r1), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp5 = tl.load(in_ptr0 + (33 + 2 * r0 + 64 * r1), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp9 = tl.load(in_ptr1 + (2 * r0 + 64 * r1), rmask, eviction_policy
            ='evict_last', other=0.0)
        tmp10 = tl.load(in_ptr1 + (1 + 2 * r0 + 64 * r1), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp12 = tl.load(in_ptr1 + (32 + 2 * r0 + 64 * r1), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp14 = tl.load(in_ptr1 + (33 + 2 * r0 + 64 * r1), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp2 = tmp1 + tmp0
        tmp4 = tmp3 + tmp2
        tmp6 = tmp5 + tmp4
        tmp7 = 0.25
        tmp8 = tmp6 * tmp7
        tmp11 = tmp10 + tmp9
        tmp13 = tmp12 + tmp11
        tmp15 = tmp14 + tmp13
        tmp16 = tmp15 * tmp7
        tmp17 = tmp8 - tmp16
        tmp18 = tl_math.abs(tmp17)
        tmp19 = tl.broadcast_to(tmp18, [XBLOCK, RBLOCK])
        tmp21 = _tmp20 + tmp19
        _tmp20 = tl.where(rmask, tmp21, _tmp20)
        tl.store(out_ptr0 + tl.broadcast_to(r2, [XBLOCK, RBLOCK]), tmp8, rmask)
        tl.store(out_ptr1 + tl.broadcast_to(r2, [XBLOCK, RBLOCK]), tmp16, rmask
            )
    tmp20 = tl.sum(_tmp20, 1)[:, None]
    tl.store(out_ptr2 + tl.full([XBLOCK, 1], 0, tl.int32), tmp20, None)


@triton.jit
def triton_red_fused_abs_avg_pool2d_mean_sub_5(in_ptr0, in_ptr1, out_ptr0,
    out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.
    constexpr):
    rnumel = 1024
    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, :]
    _tmp20 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
    for roffset in range(0, rnumel, RBLOCK):
        rindex = roffset + rbase
        rmask = rindex < rnumel
        r0 = rindex % 8
        r1 = rindex // 8
        r2 = rindex
        tmp0 = tl.load(in_ptr0 + (2 * r0 + 32 * r1), rmask, eviction_policy
            ='evict_last', other=0.0)
        tmp1 = tl.load(in_ptr0 + (1 + 2 * r0 + 32 * r1), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp3 = tl.load(in_ptr0 + (16 + 2 * r0 + 32 * r1), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp5 = tl.load(in_ptr0 + (17 + 2 * r0 + 32 * r1), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp9 = tl.load(in_ptr1 + (2 * r0 + 32 * r1), rmask, eviction_policy
            ='evict_last', other=0.0)
        tmp10 = tl.load(in_ptr1 + (1 + 2 * r0 + 32 * r1), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp12 = tl.load(in_ptr1 + (16 + 2 * r0 + 32 * r1), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp14 = tl.load(in_ptr1 + (17 + 2 * r0 + 32 * r1), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp2 = tmp1 + tmp0
        tmp4 = tmp3 + tmp2
        tmp6 = tmp5 + tmp4
        tmp7 = 0.25
        tmp8 = tmp6 * tmp7
        tmp11 = tmp10 + tmp9
        tmp13 = tmp12 + tmp11
        tmp15 = tmp14 + tmp13
        tmp16 = tmp15 * tmp7
        tmp17 = tmp8 - tmp16
        tmp18 = tl_math.abs(tmp17)
        tmp19 = tl.broadcast_to(tmp18, [XBLOCK, RBLOCK])
        tmp21 = _tmp20 + tmp19
        _tmp20 = tl.where(rmask, tmp21, _tmp20)
        tl.store(out_ptr0 + tl.broadcast_to(r2, [XBLOCK, RBLOCK]), tmp8, rmask)
        tl.store(out_ptr1 + tl.broadcast_to(r2, [XBLOCK, RBLOCK]), tmp16, rmask
            )
    tmp20 = tl.sum(_tmp20, 1)[:, None]
    tl.store(out_ptr2 + tl.full([XBLOCK, 1], 0, tl.int32), tmp20, None)


@triton.jit
def triton_per_fused_abs_add_avg_pool2d_mean_mul_sub_6(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, 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 % 4
    r1 = rindex // 4
    tmp0 = tl.load(in_ptr0 + (2 * r0 + 16 * r1), None, eviction_policy=
        'evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 2 * r0 + 16 * r1), None, eviction_policy=
        'evict_last')
    tmp3 = tl.load(in_ptr0 + (8 + 2 * r0 + 16 * r1), None, eviction_policy=
        'evict_last')
    tmp5 = tl.load(in_ptr0 + (9 + 2 * r0 + 16 * r1), None, eviction_policy=
        'evict_last')
    tmp9 = tl.load(in_ptr1 + (2 * r0 + 16 * r1), None, eviction_policy=
        'evict_last')
    tmp10 = tl.load(in_ptr1 + (1 + 2 * r0 + 16 * r1), None, eviction_policy
        ='evict_last')
    tmp12 = tl.load(in_ptr1 + (8 + 2 * r0 + 16 * r1), None, eviction_policy
        ='evict_last')
    tmp14 = tl.load(in_ptr1 + (9 + 2 * r0 + 16 * r1), None, eviction_policy
        ='evict_last')
    tmp22 = tl.load(in_out_ptr0 + 0)
    tmp23 = tl.broadcast_to(tmp22, [1])
    tmp30 = tl.load(in_ptr2 + 0)
    tmp31 = tl.broadcast_to(tmp30, [1])
    tmp37 = tl.load(in_ptr3 + 0)
    tmp38 = tl.broadcast_to(tmp37, [1])
    tmp43 = tl.load(in_ptr4 + 0)
    tmp44 = tl.broadcast_to(tmp43, [1])
    tmp2 = tmp1 + tmp0
    tmp4 = tmp3 + tmp2
    tmp6 = tmp5 + tmp4
    tmp7 = 0.25
    tmp8 = tmp6 * tmp7
    tmp11 = tmp10 + tmp9
    tmp13 = tmp12 + tmp11
    tmp15 = tmp14 + tmp13
    tmp16 = tmp15 * tmp7
    tmp17 = tmp8 - tmp16
    tmp18 = tl_math.abs(tmp17)
    tmp19 = tl.broadcast_to(tmp18, [RBLOCK])
    tmp21 = triton_helpers.promote_to_tensor(tl.sum(tmp19, 0))
    tmp24 = 65536.0
    tmp25 = tmp23 / tmp24
    tmp26 = 1.0
    tmp27 = tmp25 * tmp26
    tmp28 = 0.0
    tmp29 = tmp27 + tmp28
    tmp32 = 16384.0
    tmp33 = tmp31 / tmp32
    tmp34 = 0.5
    tmp35 = tmp33 * tmp34
    tmp36 = tmp29 + tmp35
    tmp39 = 4096.0
    tmp40 = tmp38 / tmp39
    tmp41 = tmp40 * tmp7
    tmp42 = tmp36 + tmp41
    tmp45 = 1024.0
    tmp46 = tmp44 / tmp45
    tmp47 = 0.125
    tmp48 = tmp46 * tmp47
    tmp49 = tmp42 + tmp48
    tmp50 = 256.0
    tmp51 = tmp21 / tmp50
    tmp52 = tmp51 * tmp47
    tmp53 = tmp49 + tmp52
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp53, None)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 64, 64), (16384, 4096, 64, 1))
    assert_size_stride(arg1_1, (4, 4, 64, 64), (16384, 4096, 64, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((8,), (1,), torch.float32)
        get_raw_stream(0)
        triton_red_fused_abs_mean_sub_0[grid(8)](arg1_1, arg0_1, buf0, 8, 
            8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1)
        buf1 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_abs_mean_sub_1[grid(1)](buf0, buf1, 1, 8, XBLOCK=1,
            num_warps=2, num_stages=1)
        del buf0
        buf2 = empty_strided_cuda((4, 4, 32, 32), (4096, 1024, 32, 1),
            torch.float32)
        buf3 = empty_strided_cuda((4, 4, 32, 32), (4096, 1024, 32, 1),
            torch.float32)
        buf4 = empty_strided_cuda((2,), (1,), torch.float32)
        triton_red_fused_abs_avg_pool2d_mean_sub_2[grid(2)](arg1_1, arg0_1,
            buf2, buf3, buf4, 2, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16,
            num_stages=1)
        del arg0_1
        del arg1_1
        buf5 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_abs_mean_sub_3[grid(1)](buf4, buf5, 1, 2, XBLOCK=1,
            num_warps=2, num_stages=1)
        del buf4
        buf6 = empty_strided_cuda((4, 4, 16, 16), (1024, 256, 16, 1), torch
            .float32)
        buf7 = empty_strided_cuda((4, 4, 16, 16), (1024, 256, 16, 1), torch
            .float32)
        buf8 = empty_strided_cuda((), (), torch.float32)
        triton_red_fused_abs_avg_pool2d_mean_sub_4[grid(1)](buf2, buf3,
            buf6, buf7, buf8, 1, 4096, XBLOCK=1, RBLOCK=4096, num_warps=16,
            num_stages=1)
        del buf2
        del buf3
        buf9 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32)
        buf10 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32
            )
        buf11 = empty_strided_cuda((), (), torch.float32)
        triton_red_fused_abs_avg_pool2d_mean_sub_5[grid(1)](buf6, buf7,
            buf9, buf10, buf11, 1, 1024, XBLOCK=1, RBLOCK=1024, num_warps=8,
            num_stages=1)
        del buf6
        del buf7
        buf13 = buf1
        del buf1
        triton_per_fused_abs_add_avg_pool2d_mean_mul_sub_6[grid(1)](buf13,
            buf9, buf10, buf5, buf8, buf11, 1, 256, num_warps=2, num_stages=1)
        del buf10
        del buf11
        del buf5
        del buf8
        del buf9
    return buf13,


class MultiscaleL1LossNew(nn.Module):

    def __init__(self, scale=5):
        super(MultiscaleL1LossNew, self).__init__()
        self.criterion = nn.L1Loss()
        self.downsample = nn.AvgPool2d(2, stride=2, count_include_pad=False)
        self.weights = [1, 0.5, 0.25, 0.125, 0.125]
        self.weights = self.weights[:scale]

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