import torch
from torch._inductor.select_algorithm import extern_kernels
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
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
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 16 % 4
    x0 = xindex % 16
    x2 = xindex // 64
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 4, tl.int64)
    tmp9 = tl.load(in_ptr1 + (x0 + 16 * (-1 + x1) + 48 * x2), tmp6 & xmask,
        other=0.0)
    tmp10 = tl.where(tmp4, tmp5, tmp9)
    tl.store(out_ptr0 + x3, tmp10, xmask)


@triton.jit
def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 16 % 4
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x3, tmp2, xmask)


@triton.jit
def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 16 % 4
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x3, tmp4, xmask)


@triton.jit
def triton_poi_fused_add_convolution_relu_threshold_backward_3(in_ptr0,
    in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 16 % 4
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr1 + x3, xmask)
    tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp4 = tl.full([1], 0, tl.int32)
    tmp5 = triton_helpers.maximum(tmp4, tmp3)
    tmp6 = tmp0 + tmp5
    tmp7 = 0.0
    tmp8 = tmp5 <= tmp7
    tl.store(out_ptr0 + x3, tmp6, xmask)
    tl.store(out_ptr1 + x3, tmp8, xmask)


@triton.jit
def triton_poi_fused_convolution_sigmoid_4(in_out_ptr0, in_ptr0, 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_out_ptr0 + x0, xmask)
    tmp1 = tl.load(in_ptr0 + 0)
    tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
    tmp3 = tmp0 + tmp2
    tmp4 = tl.sigmoid(tmp3)
    tl.store(in_out_ptr0 + x0, tmp3, xmask)
    tl.store(out_ptr0 + x0, tmp4, xmask)


@triton.jit
def triton_poi_fused__unsafe_index_max_pool2d_with_indices_5(in_ptr0,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4 % 4
    x0 = xindex % 4
    x2 = xindex // 16
    x4 = xindex
    tmp0 = x1
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.5
    tmp3 = tmp1 * tmp2
    tmp4 = tmp3.to(tl.int32)
    tmp5 = x0
    tmp6 = tmp5.to(tl.float32)
    tmp7 = tmp6 * tmp2
    tmp8 = tmp7.to(tl.int32)
    tmp9 = tl.load(in_ptr0 + (2 * tmp8 + 8 * tmp4 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr0 + (1 + 2 * tmp8 + 8 * tmp4 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp11 = triton_helpers.maximum(tmp10, tmp9)
    tmp12 = tl.load(in_ptr0 + (4 + 2 * tmp8 + 8 * tmp4 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp13 = triton_helpers.maximum(tmp12, tmp11)
    tmp14 = tl.load(in_ptr0 + (5 + 2 * tmp8 + 8 * tmp4 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp15 = triton_helpers.maximum(tmp14, tmp13)
    tl.store(out_ptr0 + x4, tmp15, xmask)


@triton.jit
def triton_poi_fused_clone_6(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 192
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 16
    x2 = xindex // 48
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tl.store(out_ptr0 + x3, tmp0, xmask)


@triton.jit
def triton_poi_fused_add_sub_7(in_out_ptr0, in_ptr0, in_ptr1, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 192
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 16
    x2 = xindex // 48
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp1 = tl.load(in_ptr1 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp3 = tl.load(in_out_ptr0 + x3, xmask)
    tmp2 = tmp0 - tmp1
    tmp4 = tmp2 + tmp3
    tl.store(in_out_ptr0 + x3, tmp4, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
        primals_13, primals_14) = args
    args.clear()
    assert_size_stride(primals_1, (4, 1, 4, 4), (16, 16, 4, 1))
    assert_size_stride(primals_2, (4, 3, 4, 4), (48, 16, 4, 1))
    assert_size_stride(primals_3, (4, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_4, (4,), (1,))
    assert_size_stride(primals_5, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_6, (4,), (1,))
    assert_size_stride(primals_7, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_8, (4,), (1,))
    assert_size_stride(primals_9, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_10, (4,), (1,))
    assert_size_stride(primals_11, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_12, (4,), (1,))
    assert_size_stride(primals_13, (1, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_14, (1,), (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)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(256)](primals_1, primals_2, buf0, 256,
            XBLOCK=256, num_warps=4, num_stages=1)
        buf1 = extern_kernels.convolution(buf0, primals_3, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1))
        buf2 = buf1
        del buf1
        triton_poi_fused_convolution_1[grid(256)](buf2, primals_4, 256,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_4
        buf3 = extern_kernels.convolution(buf2, primals_5, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1))
        buf4 = buf3
        del buf3
        triton_poi_fused_convolution_relu_2[grid(256)](buf4, primals_6, 256,
            XBLOCK=128, num_warps=4, num_stages=1)
        del primals_6
        buf5 = extern_kernels.convolution(buf4, primals_7, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf5, (4, 4, 4, 4), (64, 16, 4, 1))
        buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf20 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        triton_poi_fused_add_convolution_relu_threshold_backward_3[grid(256)](
            buf2, buf5, primals_8, buf6, buf20, 256, XBLOCK=128, num_warps=
            4, num_stages=1)
        del primals_8
        buf7 = extern_kernels.convolution(buf6, primals_9, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf7, (4, 4, 4, 4), (64, 16, 4, 1))
        buf8 = buf7
        del buf7
        triton_poi_fused_convolution_relu_2[grid(256)](buf8, primals_10, 
            256, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_10
        buf9 = extern_kernels.convolution(buf8, primals_11, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf9, (4, 4, 4, 4), (64, 16, 4, 1))
        buf10 = buf5
        del buf5
        buf19 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        triton_poi_fused_add_convolution_relu_threshold_backward_3[grid(256)](
            buf6, buf9, primals_12, buf10, buf19, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        del buf9
        del primals_12
        buf11 = extern_kernels.convolution(buf10, primals_13, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf11, (4, 1, 4, 4), (16, 16, 4, 1))
        buf12 = buf11
        del buf11
        buf14 = empty_strided_cuda((4, 1, 4, 4), (16, 1, 4, 1), torch.float32)
        triton_poi_fused_convolution_sigmoid_4[grid(64)](buf12, primals_14,
            buf14, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del primals_14
        buf13 = empty_strided_cuda((4, 1, 4, 4), (16, 1, 4, 1), torch.float32)
        triton_poi_fused__unsafe_index_max_pool2d_with_indices_5[grid(64)](
            primals_1, buf13, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf15 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf14, (4, 4, 4), (16, 4, 1),
            0), reinterpret_tensor(buf13, (4, 4, 4), (16, 4, 1), 0), out=buf15)
        buf16 = empty_strided_cuda((4, 3, 4, 4), (48, 16, 4, 1), torch.float32)
        triton_poi_fused_clone_6[grid(192)](buf14, buf16, 192, XBLOCK=256,
            num_warps=4, num_stages=1)
        del buf14
        buf17 = empty_strided_cuda((12, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf16, (12, 4, 4), (16, 4, 1),
            0), reinterpret_tensor(primals_2, (12, 4, 4), (16, 4, 1), 0),
            out=buf17)
        del buf16
        buf18 = reinterpret_tensor(buf17, (4, 3, 4, 4), (48, 16, 4, 1), 0)
        del buf17
        triton_poi_fused_add_sub_7[grid(192)](buf18, primals_1, buf15, 192,
            XBLOCK=256, num_warps=4, num_stages=1)
        del buf15
        del primals_1
    return (buf18, primals_3, primals_5, primals_7, primals_9, primals_11,
        primals_13, buf0, buf2, buf4, buf6, buf8, buf10, buf12,
        reinterpret_tensor(primals_2, (12, 4, 4), (16, 1, 4), 0),
        reinterpret_tensor(buf13, (4, 4, 4), (16, 1, 4), 0), buf19, buf20)


class ResBlock(nn.Module):

    def __init__(self, in_ch, hid_ch):
        super(ResBlock, self).__init__()
        self.act = nn.ReLU()
        self.conv1 = nn.Conv2d(in_ch, hid_ch, kernel_size=3, padding=1)
        self.conv2 = nn.Conv2d(hid_ch, hid_ch, kernel_size=3, padding=1)

    def forward(self, x):
        return x + self.act(self.conv2(self.act(self.conv1(x))))


class scaleCompositorNew(nn.Module):

    def __init__(self, in_ch, hid_ch):
        super(scaleCompositorNew, self).__init__()
        self.conv1 = nn.Conv2d(in_ch, hid_ch, kernel_size=1)
        self.conv2 = nn.Conv2d(hid_ch, 1, kernel_size=1)
        self.resblock1 = ResBlock(hid_ch, hid_ch)
        self.resblock2 = ResBlock(hid_ch, hid_ch)
        self.act = nn.Sigmoid()
        self.downsample = nn.MaxPool2d(2)
        self.upsample = nn.Upsample(scale_factor=2, mode='nearest')

    def forward(self, input_0, input_1):
        primals_3 = self.conv1.weight
        primals_4 = self.conv1.bias
        primals_13 = self.conv2.weight
        primals_14 = self.conv2.bias
        primals_5 = self.resblock1.conv1.weight
        primals_6 = self.resblock1.conv1.bias
        primals_7 = self.resblock1.conv2.weight
        primals_8 = self.resblock1.conv2.bias
        primals_9 = self.resblock2.conv1.weight
        primals_10 = self.resblock2.conv1.bias
        primals_11 = self.resblock2.conv2.weight
        primals_12 = self.resblock2.conv2.bias
        primals_1 = input_0
        primals_2 = input_1
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9,
            primals_10, primals_11, primals_12, primals_13, primals_14])
        return output[0]


Measured latency_ms: 0.014996