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


@triton.jit
def triton_poi_fused_copy_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
    x4 = xindex
    tmp0 = x0
    tmp1 = tl.full([1], 5, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = -4 + x0
    tmp4 = tl.full([1], 1, tl.int64)
    tmp5 = tmp3 < tmp4
    tmp6 = tmp5 & tmp2
    tmp7 = tmp0 >= tmp4
    tmp8 = tmp0 < tmp1
    tmp9 = tmp7 & tmp8
    tmp10 = tmp9 & tmp6
    tmp11 = x1
    tmp12 = tmp11 >= tmp4
    tmp13 = tmp11 < tmp1
    tmp14 = tmp12 & tmp13
    tmp15 = tmp14 & tmp10
    tmp16 = tl.load(in_ptr0 + (-5 + x0 + 4 * x1 + 16 * x2), tmp15 & xmask,
        other=0.0)
    tmp17 = tl.load(in_ptr1 + x4, tmp10 & xmask, other=0.0)
    tmp18 = tl.where(tmp14, tmp16, tmp17)
    tmp19 = tl.full(tmp18.shape, 0.0, tmp18.dtype)
    tmp20 = tl.where(tmp10, tmp18, tmp19)
    tmp21 = float('nan')
    tmp22 = tl.where(tmp9, tmp20, tmp21)
    tmp23 = tl.full(tmp22.shape, 0.0, tmp22.dtype)
    tmp24 = tl.where(tmp6, tmp22, tmp23)
    tmp25 = tmp3 >= tmp4
    tmp26 = tmp3 < tmp1
    tmp27 = tmp25 & tmp26
    tmp28 = tmp27 & tmp2
    tmp29 = tmp14 & tmp28
    tmp30 = tl.load(in_ptr0 + (-9 + x0 + 4 * x1 + 16 * x2), tmp29 & xmask,
        other=0.0)
    tmp31 = tl.load(in_ptr1 + (-4 + x4), tmp28 & xmask, other=0.0)
    tmp32 = tl.where(tmp14, tmp30, tmp31)
    tmp33 = tl.full(tmp32.shape, 0.0, tmp32.dtype)
    tmp34 = tl.where(tmp28, tmp32, tmp33)
    tmp35 = tl.where(tmp27, tmp34, tmp21)
    tmp36 = tl.where(tmp5, tmp24, tmp35)
    tmp37 = tl.full(tmp36.shape, 0.0, tmp36.dtype)
    tmp38 = tl.where(tmp2, tmp36, tmp37)
    tmp39 = tmp0 < tmp4
    tmp40 = 4 + x0
    tmp41 = tmp40 >= tmp4
    tmp42 = tmp40 < tmp1
    tmp43 = tmp41 & tmp42
    tmp44 = tmp43 & tmp39
    tmp45 = tmp14 & tmp44
    tmp46 = tl.load(in_ptr0 + (-1 + x0 + 4 * x1 + 16 * x2), tmp45 & xmask,
        other=0.0)
    tmp47 = tl.load(in_ptr1 + (4 + x4), tmp44 & xmask, other=0.0)
    tmp48 = tl.where(tmp14, tmp46, tmp47)
    tmp49 = tl.full(tmp48.shape, 0.0, tmp48.dtype)
    tmp50 = tl.where(tmp44, tmp48, tmp49)
    tmp51 = tl.where(tmp43, tmp50, tmp21)
    tmp52 = tl.full(tmp51.shape, 0.0, tmp51.dtype)
    tmp53 = tl.where(tmp39, tmp51, tmp52)
    tmp54 = tmp14 & tmp9
    tmp55 = tl.load(in_ptr0 + (-5 + x0 + 4 * x1 + 16 * x2), tmp54 & xmask,
        other=0.0)
    tmp56 = tl.load(in_ptr1 + x4, tmp9 & xmask, other=0.0)
    tmp57 = tl.where(tmp14, tmp55, tmp56)
    tmp58 = tl.full(tmp57.shape, 0.0, tmp57.dtype)
    tmp59 = tl.where(tmp9, tmp57, tmp58)
    tmp60 = tl.where(tmp9, tmp59, tmp21)
    tmp61 = tl.where(tmp39, tmp53, tmp60)
    tmp62 = tl.where(tmp2, tmp38, tmp61)
    tl.store(out_ptr0 + x4, tmp62, xmask)


@triton.jit
def triton_poi_fused_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 576
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 6 % 6
    x0 = xindex % 6
    x2 = xindex // 36
    x3 = xindex
    tmp14 = tl.load(in_ptr0 + x3, xmask)
    tmp0 = x1
    tmp1 = tl.full([1], 5, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = -4 + x1
    tmp4 = tl.full([1], 1, tl.int64)
    tmp5 = tmp3 < tmp4
    tmp6 = tmp5 & tmp2
    tmp7 = tl.load(in_ptr0 + (24 + x0 + 36 * x2), tmp6 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp8 = tl.load(in_ptr0 + (-24 + x3), tmp2 & xmask, other=0.0)
    tmp9 = tl.where(tmp5, tmp7, tmp8)
    tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype)
    tmp11 = tl.where(tmp2, tmp9, tmp10)
    tmp12 = tmp0 < tmp4
    tmp13 = tl.load(in_ptr0 + (24 + x0 + 36 * x2), tmp12 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp15 = tl.where(tmp12, tmp13, tmp14)
    tmp16 = tl.where(tmp2, tmp11, tmp15)
    tl.store(out_ptr0 + x3, tmp16, xmask)


@triton.jit
def triton_poi_fused_relu_threshold_backward_2(in_out_ptr0, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    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.full([1], 0, tl.int32)
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tmp3 = 0.0
    tmp4 = tmp2 <= tmp3
    tl.store(in_out_ptr0 + x0, tmp2, xmask)
    tl.store(out_ptr0 + x0, tmp4, xmask)


def call(args):
    primals_1, primals_2 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
    buf0 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32)
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf1 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_copy_0[grid(576)](primals_2, buf0, buf1, 576,
            XBLOCK=128, num_warps=4, num_stages=1)
        del primals_2
        buf2 = buf0
        del buf0
        triton_poi_fused_1[grid(576)](buf1, buf2, 576, XBLOCK=256,
            num_warps=4, num_stages=1)
        del buf1
        buf3 = extern_kernels.convolution(buf2, primals_1, stride=(1, 1),
            padding=(0, 0), 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
        buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        triton_poi_fused_relu_threshold_backward_2[grid(256)](buf4, buf5, 
            256, XBLOCK=128, num_warps=4, num_stages=1)
    return buf4, primals_1, buf2, buf5


class ConvNew(nn.Module):

    def __init__(self, chn_in, chn_out, ker_sz=3):
        super().__init__()
        self.c = nn.Conv2d(chn_in, chn_out, ker_sz, padding=ker_sz // 2,
            padding_mode='circular', bias=False)
        self.a = nn.ReLU()

    def forward(self, input_0):
        primals_1 = self.c.weight
        primals_2 = input_0
        output = call([primals_1, primals_2])
        return output[0]


Measured latency_ms: 0.04798