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
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_roll_0(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = (2 + x0) % 4
    tl.store(out_ptr0 + x0, tmp0, xmask)


@triton.jit
def triton_poi_fused_roll_1(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = (1 + x0) % 4
    tl.store(out_ptr0 + x0, tmp0, xmask)


@triton.jit
def triton_poi_fused_cat_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x2 = xindex // 16 % 64
    x3 = xindex // 1024
    x4 = xindex % 16
    x0 = xindex % 4
    x1 = xindex // 4 % 4
    x5 = xindex
    tmp0 = x2
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 16, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x4 + 16 * (x2 % 16) + 256 * x3), tmp4, other=0.0)
    tmp6 = tmp0 >= tmp3
    tmp7 = tl.full([1], 32, tl.int64)
    tmp8 = tmp0 < tmp7
    tmp9 = tmp6 & tmp8
    tmp10 = tl.load(in_ptr0 + (3 + -1 * x1 + 4 * x0 + 16 * ((3 + (-16 + x2) %
        4) % 4) + 64 * ((-16 + x2) // 4 % 4) + 256 * x3), tmp9,
        eviction_policy='evict_last', other=0.0)
    tmp11 = tmp0 >= tmp7
    tmp12 = tl.full([1], 48, tl.int64)
    tmp13 = tmp0 < tmp12
    tmp14 = tmp11 & tmp13
    tmp15 = tl.load(in_ptr0 + (15 + -1 * x4 + 16 * tl.where((2 + (-32 + x2) %
        4) % 4 < 0, 4 + (2 + (-32 + x2) % 4) % 4, (2 + (-32 + x2) % 4) % 4) +
        64 * ((-32 + x2) // 4 % 4) + 256 * x3), tmp14, eviction_policy=
        'evict_last', other=0.0)
    tmp16 = tmp0 >= tmp12
    tl.full([1], 64, tl.int64)
    tmp19 = tl.load(in_ptr0 + (12 + x1 + -4 * x0 + 16 * tl.where((1 + (-48 +
        x2) % 4) % 4 < 0, 4 + (1 + (-48 + x2) % 4) % 4, (1 + (-48 + x2) % 4
        ) % 4) + 64 * ((-48 + x2) // 4 % 4) + 256 * x3), tmp16,
        eviction_policy='evict_last', other=0.0)
    tmp20 = tl.where(tmp14, tmp15, tmp19)
    tmp21 = tl.where(tmp9, tmp10, tmp20)
    tmp22 = tl.where(tmp4, tmp5, tmp21)
    tl.store(out_ptr0 + x5, tmp22, None)


@triton.jit
def triton_poi_fused_add_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 576
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 36 % 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)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1))
    assert_size_stride(primals_3, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4,), (1,), torch.int64)
        get_raw_stream(0)
        triton_poi_fused_roll_0[grid(4)](buf0, 4, XBLOCK=4, num_warps=1,
            num_stages=1)
        buf1 = empty_strided_cuda((4,), (1,), torch.int64)
        triton_poi_fused_roll_1[grid(4)](buf1, 4, XBLOCK=4, num_warps=1,
            num_stages=1)
        buf2 = empty_strided_cuda((4, 64, 4, 4), (1024, 16, 4, 1), torch.
            float32)
        triton_poi_fused_cat_2[grid(4096)](primals_2, buf2, 4096, XBLOCK=
            256, num_warps=4, num_stages=1)
        del primals_2
        buf3 = extern_kernels.convolution(reinterpret_tensor(primals_1, (4,
            16, 4, 4), (256, 16, 4, 1), 0), reinterpret_tensor(buf2, (16, 
            16, 4, 4), (256, 16, 4, 1), 0), stride=(1, 1), padding=(1, 1),
            dilation=(1, 1), transposed=False, output_padding=(0, 0),
            groups=1, bias=None)
        assert_size_stride(buf3, (4, 16, 3, 3), (144, 9, 3, 1))
        buf4 = reinterpret_tensor(buf3, (4, 4, 4, 3, 3), (144, 36, 9, 3, 1), 0)
        del buf3
        triton_poi_fused_add_3[grid(576)](buf4, primals_3, 576, XBLOCK=128,
            num_warps=4, num_stages=1)
        del primals_3
    return buf4, reinterpret_tensor(primals_1, (4, 16, 4, 4), (256, 16, 4, 
        1), 0), buf0, buf1, reinterpret_tensor(buf2, (16, 16, 4, 4), (256, 
        16, 4, 1), 0)


def _grot90(x, k):
    return torch.rot90(x.roll(k, 2), k, (3, 4))


class ConvP4New(torch.nn.Module):

    def __init__(self, in_channels, out_channels, kernel_size, bias=True,
        stride=1, padding=1):
        super().__init__()
        w = torch.empty(out_channels, in_channels, 4, kernel_size, kernel_size)
        self.weight = torch.nn.Parameter(w)
        torch.nn.init.kaiming_uniform_(self.weight, a=5 ** 0.5)
        if bias:
            self.bias = torch.nn.Parameter(torch.zeros(out_channels))
        else:
            self.bias = None
        self.stride = stride
        self.padding = padding

    def _rotated(self, w):
        ws = [_grot90(w, k).view(w.size(0), -1, w.size(3), w.size(4)) for k in
            range(4)]
        return torch.cat(ws, 1).view(4 * w.size(0), 4 * w.size(1), w.size(3
            ), w.size(4))

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


Measured latency_ms: 0.03587