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
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, in_ptr2, 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], 3, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tl.load(in_ptr1 + (x0 + 16 * x1 + 48 * x2), tmp4 & xmask, other=0.0)
    tmp7 = tmp5 * tmp6
    tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype)
    tmp9 = tl.where(tmp4, tmp7, tmp8)
    tmp10 = tmp0 >= tmp3
    tl.full([1], 4, tl.int64)
    tmp13 = tl.load(in_ptr2 + (x0 + 16 * x2), tmp10 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp14 = tl.where(tmp4, tmp9, tmp13)
    tl.store(out_ptr0 + x3, tmp14, xmask)


def call(args):
    arg0_1, arg1_1, arg2_1, arg3_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(arg1_1, (4, 3, 16), (48, 16, 1))
    assert_size_stride(arg2_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(arg3_1, (4, 1, 16), (16, 16, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 3, 16), (48, 16, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 3, 3), (16, 4, 1),
            0), arg1_1, out=buf0)
        del arg0_1
        del arg1_1
        buf1 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(256)](arg2_1, buf0, arg3_1, buf1, 256,
            XBLOCK=256, num_warps=4, num_stages=1)
        del arg2_1
        del arg3_1
        del buf0
    return buf1,


class BackprojectionNew(nn.Module):

    def __init__(self, batch_size, height, width):
        super(BackprojectionNew, self).__init__()
        self.N, self.H, self.W = batch_size, height, width
        yy, xx = torch.meshgrid([torch.arange(0.0, float(self.H)), torch.
            arange(0.0, float(self.W))])
        yy = yy.contiguous().view(-1)
        xx = xx.contiguous().view(-1)
        self.ones = nn.Parameter(torch.ones(self.N, 1, self.H * self.W),
            requires_grad=False)
        self.coord = torch.unsqueeze(torch.stack([xx, yy], 0), 0).repeat(self
            .N, 1, 1)
        self.coord = nn.Parameter(torch.cat([self.coord, self.ones], 1),
            requires_grad=False)

    def forward(self, input_0, input_1):
        arg3_1 = self.ones
        arg1_1 = self.coord
        arg0_1 = input_0
        arg2_1 = input_1
        output = call([arg0_1, arg1_1, arg2_1, arg3_1])
        return output[0]


Measured latency_ms: 0.033714