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
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
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, in_ptr3, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 512
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 16 % 8
    x0 = xindex % 16
    x2 = xindex // 128
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 6, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 96 * x2), tmp4 & xmask, other=0.0)
    tmp6 = tl.load(in_ptr1 + x1, tmp4 & xmask, eviction_policy='evict_last',
        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], 8, tl.int64)
    tmp13 = tl.load(in_ptr2 + (x0 + 16 * (-6 + x1) + 32 * x2), tmp10 &
        xmask, other=0.0)
    tmp14 = tl.load(in_ptr3 + (-6 + x1), tmp10 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp15 = tmp13 + tmp14
    tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype)
    tmp17 = tl.where(tmp10, tmp15, tmp16)
    tmp18 = tl.where(tmp4, tmp9, tmp17)
    tl.store(out_ptr0 + x3, tmp18, xmask)


@triton.jit
def triton_per_fused__native_batch_norm_legit_1(in_ptr0, out_ptr0, out_ptr1,
    out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 8
    RBLOCK: tl.constexpr = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex % 16
    r2 = rindex // 16
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0 + 128 * r2), xmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tl.where(xmask, tmp1, 0)
    tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
    tmp6 = tl.where(xmask, tmp4, 0)
    tmp7 = tl.sum(tmp6, 1)[:, None]
    tmp8 = tl.full([XBLOCK, 1], 64, tl.int32)
    tmp9 = tmp8.to(tl.float32)
    tmp10 = tmp7 / tmp9
    tmp11 = tmp1 - tmp10
    tmp12 = tmp11 * tmp11
    tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK])
    tmp15 = tl.where(xmask, tmp13, 0)
    tmp16 = tl.sum(tmp15, 1)[:, None]
    tmp17 = 64.0
    tmp18 = tmp16 / tmp17
    tmp19 = 1e-05
    tmp20 = tmp18 + tmp19
    tmp21 = libdevice.rsqrt(tmp20)
    tl.store(out_ptr2 + x0, tmp21, xmask)
    tl.store(out_ptr0 + x0, tmp10, xmask)
    tl.store(out_ptr1 + x0, tmp16, xmask)


@triton.jit
def triton_poi_fused__native_batch_norm_legit_relu_2(in_ptr0, in_ptr1,
    in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 512
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 16 % 8
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 - tmp1
    tmp4 = 64.0
    tmp5 = tmp3 / tmp4
    tmp6 = 1e-05
    tmp7 = tmp5 + tmp6
    tmp8 = libdevice.rsqrt(tmp7)
    tmp9 = tmp2 * tmp8
    tmp11 = tmp9 * tmp10
    tmp13 = tmp11 + tmp12
    tmp14 = tl.full([1], 0, tl.int32)
    tmp15 = triton_helpers.maximum(tmp14, tmp13)
    tl.store(out_ptr0 + x3, tmp15, xmask)


@triton.jit
def triton_poi_fused_cat_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 512
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 16 % 8
    x0 = xindex % 16
    x2 = xindex // 128
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0)
    tmp6 = tl.load(in_ptr1 + x1, tmp4 & xmask, eviction_policy='evict_last',
        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], 8, tl.int64)
    tmp13 = tl.load(in_ptr2 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp10 &
        xmask, other=0.0)
    tmp14 = tl.load(in_ptr3 + (-4 + x1), tmp10 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp15 = tmp13 + tmp14
    tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype)
    tmp17 = tl.where(tmp10, tmp15, tmp16)
    tmp18 = tl.where(tmp4, tmp9, tmp17)
    tl.store(out_ptr0 + x3, tmp18, xmask)


@triton.jit
def triton_poi_fused__log_softmax_convolution_4(in_ptr0, in_ptr1, out_ptr0,
    out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 16
    x1 = xindex // 16
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
    tmp1 = tl.load(in_ptr1 + 0)
    tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
    tmp4 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
    tmp5 = tl.load(in_ptr1 + 1)
    tmp6 = tl.broadcast_to(tmp5, [XBLOCK])
    tmp9 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
    tmp10 = tl.load(in_ptr1 + 2)
    tmp11 = tl.broadcast_to(tmp10, [XBLOCK])
    tmp14 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
    tmp15 = tl.load(in_ptr1 + 3)
    tmp16 = tl.broadcast_to(tmp15, [XBLOCK])
    tmp3 = tmp0 + tmp2
    tmp7 = tmp4 + tmp6
    tmp8 = triton_helpers.maximum(tmp3, tmp7)
    tmp12 = tmp9 + tmp11
    tmp13 = triton_helpers.maximum(tmp8, tmp12)
    tmp17 = tmp14 + tmp16
    tmp18 = triton_helpers.maximum(tmp13, tmp17)
    tmp19 = tmp3 - tmp18
    tmp20 = tl_math.exp(tmp19)
    tmp21 = tmp7 - tmp18
    tmp22 = tl_math.exp(tmp21)
    tmp23 = tmp20 + tmp22
    tmp24 = tmp12 - tmp18
    tmp25 = tl_math.exp(tmp24)
    tmp26 = tmp23 + tmp25
    tmp27 = tmp17 - tmp18
    tmp28 = tl_math.exp(tmp27)
    tmp29 = tmp26 + tmp28
    tl.store(out_ptr0 + x2, tmp18, xmask)
    tl.store(out_ptr1 + x2, tmp29, xmask)


@triton.jit
def triton_poi_fused__log_softmax_convolution_5(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
    x3 = xindex
    x1 = xindex // 16 % 4
    x0 = xindex % 16
    x2 = xindex // 64
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp5 = tl.load(in_ptr2 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 - tmp3
    tmp6 = tl_math.log(tmp5)
    tmp7 = tmp4 - tmp6
    tl.store(in_out_ptr0 + x3, tmp7, 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, primals_15, primals_16, primals_17,
        primals_18, primals_19, primals_20, primals_21) = args
    args.clear()
    assert_size_stride(primals_1, (6, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_2, (6,), (1,))
    assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_4, (2, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_5, (2,), (1,))
    assert_size_stride(primals_6, (8,), (1,))
    assert_size_stride(primals_7, (8,), (1,))
    assert_size_stride(primals_8, (4, 8, 3, 3), (72, 9, 3, 1))
    assert_size_stride(primals_9, (4,), (1,))
    assert_size_stride(primals_10, (4, 8, 3, 3), (72, 9, 3, 1))
    assert_size_stride(primals_11, (4,), (1,))
    assert_size_stride(primals_12, (8,), (1,))
    assert_size_stride(primals_13, (8,), (1,))
    assert_size_stride(primals_14, (4, 8, 3, 3), (72, 9, 3, 1))
    assert_size_stride(primals_15, (4,), (1,))
    assert_size_stride(primals_16, (4, 8, 3, 3), (72, 9, 3, 1))
    assert_size_stride(primals_17, (4,), (1,))
    assert_size_stride(primals_18, (8,), (1,))
    assert_size_stride(primals_19, (8,), (1,))
    assert_size_stride(primals_20, (4, 8, 3, 3), (72, 9, 3, 1))
    assert_size_stride(primals_21, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 
            1), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 6, 4, 4), (96, 16, 4, 1))
        buf1 = extern_kernels.convolution(primals_3, primals_4, stride=(1, 
            1), padding=(101, 101), dilation=(101, 101), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf1, (4, 2, 4, 4), (32, 16, 4, 1))
        buf2 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(512)](buf0, primals_2, buf1, primals_5,
            buf2, 512, XBLOCK=256, num_warps=4, num_stages=1)
        del buf0
        del buf1
        del primals_2
        del primals_5
        buf3 = empty_strided_cuda((1, 8, 1, 1), (8, 1, 8, 8), torch.float32)
        buf4 = empty_strided_cuda((1, 8, 1, 1), (8, 1, 8, 8), torch.float32)
        buf6 = empty_strided_cuda((1, 8, 1, 1), (8, 1, 8, 8), torch.float32)
        triton_per_fused__native_batch_norm_legit_1[grid(8)](buf2, buf3,
            buf4, buf6, 8, 64, XBLOCK=8, num_warps=4, num_stages=1)
        buf7 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32)
        triton_poi_fused__native_batch_norm_legit_relu_2[grid(512)](buf2,
            buf3, buf4, primals_6, primals_7, buf7, 512, XBLOCK=256,
            num_warps=4, num_stages=1)
        del primals_7
        buf8 = extern_kernels.convolution(buf7, primals_8, stride=(1, 1),
            padding=(2, 2), dilation=(2, 2), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf8, (4, 4, 4, 4), (64, 16, 4, 1))
        buf9 = extern_kernels.convolution(buf7, primals_10, stride=(1, 1),
            padding=(6, 6), dilation=(6, 6), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf9, (4, 4, 4, 4), (64, 16, 4, 1))
        buf10 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32
            )
        triton_poi_fused_cat_3[grid(512)](buf8, primals_9, buf9, primals_11,
            buf10, 512, XBLOCK=256, num_warps=4, num_stages=1)
        del buf8
        del buf9
        del primals_11
        del primals_9
        buf11 = buf4
        del buf4
        buf12 = empty_strided_cuda((1, 8, 1, 1), (8, 1, 8, 8), torch.float32)
        buf14 = empty_strided_cuda((1, 8, 1, 1), (8, 1, 8, 8), torch.float32)
        triton_per_fused__native_batch_norm_legit_1[grid(8)](buf10, buf11,
            buf12, buf14, 8, 64, XBLOCK=8, num_warps=4, num_stages=1)
        buf15 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32
            )
        triton_poi_fused__native_batch_norm_legit_relu_2[grid(512)](buf10,
            buf11, buf12, primals_12, primals_13, buf15, 512, XBLOCK=256,
            num_warps=4, num_stages=1)
        del primals_13
        buf16 = extern_kernels.convolution(buf15, primals_14, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf16, (4, 4, 4, 4), (64, 16, 4, 1))
        buf17 = extern_kernels.convolution(buf15, primals_16, stride=(1, 1),
            padding=(4, 4), dilation=(4, 4), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf17, (4, 4, 4, 4), (64, 16, 4, 1))
        buf18 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32
            )
        triton_poi_fused_cat_3[grid(512)](buf16, primals_15, buf17,
            primals_17, buf18, 512, XBLOCK=256, num_warps=4, num_stages=1)
        del buf16
        del buf17
        del primals_15
        del primals_17
        buf19 = buf12
        del buf12
        buf20 = empty_strided_cuda((1, 8, 1, 1), (8, 1, 8, 8), torch.float32)
        buf22 = empty_strided_cuda((1, 8, 1, 1), (8, 1, 8, 8), torch.float32)
        triton_per_fused__native_batch_norm_legit_1[grid(8)](buf18, buf19,
            buf20, buf22, 8, 64, XBLOCK=8, num_warps=4, num_stages=1)
        buf23 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32
            )
        triton_poi_fused__native_batch_norm_legit_relu_2[grid(512)](buf18,
            buf19, buf20, primals_18, primals_19, buf23, 512, XBLOCK=256,
            num_warps=4, num_stages=1)
        del buf20
        del primals_19
        buf24 = extern_kernels.convolution(buf23, primals_20, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf24, (4, 4, 4, 4), (64, 16, 4, 1))
        buf25 = empty_strided_cuda((4, 1, 4, 4), (16, 64, 4, 1), torch.float32)
        buf26 = empty_strided_cuda((4, 1, 4, 4), (16, 64, 4, 1), torch.float32)
        triton_poi_fused__log_softmax_convolution_4[grid(64)](buf24,
            primals_21, buf25, buf26, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf27 = buf24
        del buf24
        triton_poi_fused__log_softmax_convolution_5[grid(256)](buf27,
            primals_21, buf25, buf26, 256, XBLOCK=256, num_warps=4,
            num_stages=1)
        del buf25
        del buf26
        del primals_21
    return (buf27, primals_1, primals_3, primals_4, primals_6, primals_8,
        primals_10, primals_12, primals_14, primals_16, primals_18,
        primals_20, buf2, reinterpret_tensor(buf6, (8,), (1,), 0), buf7,
        buf10, reinterpret_tensor(buf14, (8,), (1,), 0), buf15, buf18,
        reinterpret_tensor(buf22, (8,), (1,), 0), buf23, buf27,
        reinterpret_tensor(buf19, (1, 8, 1, 1), (8, 1, 1, 1), 0),
        reinterpret_tensor(buf11, (1, 8, 1, 1), (8, 1, 1, 1), 0),
        reinterpret_tensor(buf3, (1, 8, 1, 1), (8, 1, 1, 1), 0))


class FourLayerSemSegNetWideViewNew(nn.Module):

    def __init__(self, in_channel, out_channel):
        super().__init__()
        self.conv1 = torch.nn.Conv2d(in_channel, 6, kernel_size=3, padding=
            1, stride=1)
        self.conv1d100 = torch.nn.Conv2d(in_channel, 2, kernel_size=3,
            padding=101, stride=1, dilation=101)
        self.conv2d1 = torch.nn.Conv2d(8, 4, kernel_size=3, padding=2,
            stride=1, dilation=2)
        self.conv2d5 = torch.nn.Conv2d(8, 4, kernel_size=3, padding=6,
            stride=1, dilation=6)
        self.conv3d0 = torch.nn.Conv2d(8, 4, kernel_size=3, padding=1, stride=1
            )
        self.conv3d3 = torch.nn.Conv2d(8, 4, kernel_size=3, padding=4,
            stride=1, dilation=4)
        self.conv4 = torch.nn.Conv2d(8, out_channel, kernel_size=3, padding
            =1, stride=1)
        self.ReLU1 = torch.nn.ReLU()
        self.ReLU2 = torch.nn.ReLU()
        self.ReLU3 = torch.nn.ReLU()
        self.softmax = torch.nn.LogSoftmax(dim=1)
        self.batchnorm1 = torch.nn.BatchNorm2d(8, track_running_stats=False,
            momentum=1.0)
        self.batchnorm2 = torch.nn.BatchNorm2d(8, track_running_stats=False,
            momentum=1.0)
        self.batchnorm3 = torch.nn.BatchNorm2d(8, track_running_stats=False,
            momentum=1.0)

    def forward(self, input_0):
        primals_1 = self.conv1.weight
        primals_2 = self.conv1.bias
        primals_4 = self.conv1d100.weight
        primals_5 = self.conv1d100.bias
        primals_8 = self.conv2d1.weight
        primals_9 = self.conv2d1.bias
        primals_10 = self.conv2d5.weight
        primals_11 = self.conv2d5.bias
        primals_14 = self.conv3d0.weight
        primals_15 = self.conv3d0.bias
        primals_16 = self.conv3d3.weight
        primals_17 = self.conv3d3.bias
        primals_20 = self.conv4.weight
        primals_21 = self.conv4.bias
        primals_6 = self.batchnorm1.weight
        primals_7 = self.batchnorm1.bias
        primals_12 = self.batchnorm2.weight
        primals_13 = self.batchnorm2.bias
        primals_18 = self.batchnorm3.weight
        primals_19 = self.batchnorm3.bias
        primals_3 = input_0
        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,
            primals_15, primals_16, primals_17, primals_18, primals_19,
            primals_20, primals_21])
        return output[0]


Measured latency_ms: 0.041019