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
from functools import *
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_mul_reflection_pad2d_0(in_ptr0, in_ptr1, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 576
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 6
    x1 = xindex // 6 % 6
    x2 = xindex // 36
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
        x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2),
        xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
        x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2),
        xmask, eviction_policy='evict_last')
    tmp2 = tmp0 * tmp1
    tl.store(out_ptr0 + x3, tmp2, xmask)


@triton.jit
def triton_poi_fused_add_avg_pool2d_clamp_div_mul_pow_reflection_pad2d_rsub_sub_1(
    in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = xindex // 4 % 4
    x2 = xindex // 16
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 6 * x1 + 36 * x2), xmask)
    tmp1 = tl.load(in_ptr0 + (1 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp3 = tl.load(in_ptr0 + (2 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp5 = tl.load(in_ptr0 + (6 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp7 = tl.load(in_ptr0 + (7 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp9 = tl.load(in_ptr0 + (8 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp11 = tl.load(in_ptr0 + (12 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp13 = tl.load(in_ptr0 + (13 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp15 = tl.load(in_ptr0 + (14 + x0 + 6 * x1 + 36 * x2), xmask)
    tmp19 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
        x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2),
        xmask, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + x0) + -4 *
        tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2), xmask)
    tmp22 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-2 + x0) + -4 *
        tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2), xmask)
    tmp24 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
        x0)) + -4 * tl_math.abs(-3 + x1) + 16 * x2), xmask, eviction_policy
        ='evict_last')
    tmp26 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + x0) + -4 *
        tl_math.abs(-3 + x1) + 16 * x2), xmask)
    tmp28 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-2 + x0) + -4 *
        tl_math.abs(-3 + x1) + 16 * x2), xmask)
    tmp30 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
        x0)) + -4 * tl_math.abs(-2 + x1) + 16 * x2), xmask, eviction_policy
        ='evict_last')
    tmp32 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + x0) + -4 *
        tl_math.abs(-2 + x1) + 16 * x2), xmask)
    tmp34 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-2 + x0) + -4 *
        tl_math.abs(-2 + x1) + 16 * x2), xmask)
    tmp55 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
        x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2),
        xmask, eviction_policy='evict_last')
    tmp56 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-3 + x0) + -4 *
        tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2), xmask)
    tmp58 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-2 + x0) + -4 *
        tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2), xmask)
    tmp60 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
        x0)) + -4 * tl_math.abs(-3 + x1) + 16 * x2), xmask, eviction_policy
        ='evict_last')
    tmp62 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-3 + x0) + -4 *
        tl_math.abs(-3 + x1) + 16 * x2), xmask)
    tmp64 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-2 + x0) + -4 *
        tl_math.abs(-3 + x1) + 16 * x2), xmask)
    tmp66 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
        x0)) + -4 * tl_math.abs(-2 + x1) + 16 * x2), xmask, eviction_policy
        ='evict_last')
    tmp68 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-3 + x0) + -4 *
        tl_math.abs(-2 + x1) + 16 * x2), xmask)
    tmp70 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-2 + x0) + -4 *
        tl_math.abs(-2 + x1) + 16 * x2), xmask)
    tmp2 = tmp1 + tmp0
    tmp4 = tmp3 + tmp2
    tmp6 = tmp5 + tmp4
    tmp8 = tmp7 + tmp6
    tmp10 = tmp9 + tmp8
    tmp12 = tmp11 + tmp10
    tmp14 = tmp13 + tmp12
    tmp16 = tmp15 + tmp14
    tmp17 = 0.1111111111111111
    tmp18 = tmp16 * tmp17
    tmp21 = tmp20 + tmp19
    tmp23 = tmp22 + tmp21
    tmp25 = tmp24 + tmp23
    tmp27 = tmp26 + tmp25
    tmp29 = tmp28 + tmp27
    tmp31 = tmp30 + tmp29
    tmp33 = tmp32 + tmp31
    tmp35 = tmp34 + tmp33
    tmp36 = tmp35 * tmp17
    tmp37 = tmp19 * tmp19
    tmp38 = tmp20 * tmp20
    tmp39 = tmp38 + tmp37
    tmp40 = tmp22 * tmp22
    tmp41 = tmp40 + tmp39
    tmp42 = tmp24 * tmp24
    tmp43 = tmp42 + tmp41
    tmp44 = tmp26 * tmp26
    tmp45 = tmp44 + tmp43
    tmp46 = tmp28 * tmp28
    tmp47 = tmp46 + tmp45
    tmp48 = tmp30 * tmp30
    tmp49 = tmp48 + tmp47
    tmp50 = tmp32 * tmp32
    tmp51 = tmp50 + tmp49
    tmp52 = tmp34 * tmp34
    tmp53 = tmp52 + tmp51
    tmp54 = tmp53 * tmp17
    tmp57 = tmp56 + tmp55
    tmp59 = tmp58 + tmp57
    tmp61 = tmp60 + tmp59
    tmp63 = tmp62 + tmp61
    tmp65 = tmp64 + tmp63
    tmp67 = tmp66 + tmp65
    tmp69 = tmp68 + tmp67
    tmp71 = tmp70 + tmp69
    tmp72 = tmp71 * tmp17
    tmp73 = tmp55 * tmp55
    tmp74 = tmp56 * tmp56
    tmp75 = tmp74 + tmp73
    tmp76 = tmp58 * tmp58
    tmp77 = tmp76 + tmp75
    tmp78 = tmp60 * tmp60
    tmp79 = tmp78 + tmp77
    tmp80 = tmp62 * tmp62
    tmp81 = tmp80 + tmp79
    tmp82 = tmp64 * tmp64
    tmp83 = tmp82 + tmp81
    tmp84 = tmp66 * tmp66
    tmp85 = tmp84 + tmp83
    tmp86 = tmp68 * tmp68
    tmp87 = tmp86 + tmp85
    tmp88 = tmp70 * tmp70
    tmp89 = tmp88 + tmp87
    tmp90 = tmp89 * tmp17
    tmp91 = 2.0
    tmp92 = tmp36 * tmp91
    tmp93 = tmp92 * tmp72
    tmp94 = 0.0001
    tmp95 = tmp93 + tmp94
    tmp96 = tmp36 * tmp72
    tmp97 = tmp18 - tmp96
    tmp98 = tmp97 * tmp91
    tmp99 = 0.0009
    tmp100 = tmp98 + tmp99
    tmp101 = tmp95 * tmp100
    tmp102 = tmp36 * tmp36
    tmp103 = tmp72 * tmp72
    tmp104 = tmp102 + tmp103
    tmp105 = tmp104 + tmp94
    tmp106 = tmp54 - tmp102
    tmp107 = tmp90 - tmp103
    tmp108 = tmp106 + tmp107
    tmp109 = tmp108 + tmp99
    tmp110 = tmp105 * tmp109
    tmp111 = tmp101 / tmp110
    tmp112 = 1.0
    tmp113 = tmp112 - tmp111
    tmp114 = 0.5
    tmp115 = tmp113 * tmp114
    tmp116 = 0.0
    tmp117 = triton_helpers.maximum(tmp115, tmp116)
    tmp118 = triton_helpers.minimum(tmp117, tmp112)
    tl.store(in_out_ptr0 + x3, tmp118, xmask)


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, 6, 6), (144, 36, 6, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_mul_reflection_pad2d_0[grid(576)](arg0_1, arg1_1,
            buf2, 576, XBLOCK=256, num_warps=4, num_stages=1)
        buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf6 = buf0
        del buf0
        buf7 = buf6
        del buf6
        triton_poi_fused_add_avg_pool2d_clamp_div_mul_pow_reflection_pad2d_rsub_sub_1[
            grid(256)](buf7, buf2, arg0_1, arg1_1, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        del arg0_1
        del arg1_1
        del buf2
    return buf7,


class SSIMNew(nn.Module):
    """Layer to compute the SSIM loss between a pair of images
    """

    def __init__(self):
        super(SSIMNew, self).__init__()
        self.mu_x_pool = nn.AvgPool2d(3, 1)
        self.mu_y_pool = nn.AvgPool2d(3, 1)
        self.sig_x_pool = nn.AvgPool2d(3, 1)
        self.sig_y_pool = nn.AvgPool2d(3, 1)
        self.sig_xy_pool = nn.AvgPool2d(3, 1)
        self.refl = nn.ReflectionPad2d(1)
        self.C1 = 0.01 ** 2
        self.C2 = 0.03 ** 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.016022