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 math
import torch.nn.functional as F
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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    xnumel = 9
    yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)
        ) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    tl.full([XBLOCK, YBLOCK], True, tl.int1)
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y3 = yindex
    y0 = yindex % 256
    y1 = yindex // 256
    tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last'
        )
    tl.store(out_ptr0 + (y0 + 256 * x2 + 2304 * y1), tmp0, xmask)


@triton.jit
def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    xnumel = 4
    yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)
        ) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    tl.full([XBLOCK, YBLOCK], True, tl.int1)
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y3 = yindex
    y0 = yindex % 256
    y1 = yindex // 256
    tmp0 = tl.load(in_ptr0 + (x2 + 4 * y3), xmask, eviction_policy='evict_last'
        )
    tl.store(out_ptr0 + (y0 + 256 * x2 + 1024 * y1), tmp0, xmask)


@triton.jit
def triton_poi_fused_constant_pad_nd_2(in_ptr0, out_ptr0, ynumel, xnumel,
    YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
    xnumel = 36
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    tl.full([XBLOCK, YBLOCK], True, tl.int1)
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x3 = xindex // 6
    x2 = xindex % 6
    y4 = yindex
    x5 = xindex
    y0 = yindex % 256
    y1 = yindex // 256
    tmp0 = -1 + x3
    tmp1 = tl.full([1, 1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1, 1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = -1 + x2
    tmp6 = tmp5 >= tmp1
    tmp7 = tmp5 < tmp3
    tmp8 = tmp2 & tmp4
    tmp9 = tmp8 & tmp6
    tmp10 = tmp9 & tmp7
    tmp11 = tl.load(in_ptr0 + (-5 + x2 + 4 * x3 + 16 * y4), tmp10 & xmask,
        eviction_policy='evict_last', other=0.0)
    tl.store(out_ptr0 + (y0 + 256 * x5 + 9216 * y1), tmp11, xmask)


@triton.jit
def triton_poi_fused_constant_pad_nd_convolution_relu_3(in_ptr0, in_ptr1,
    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 // 1536 % 6
    x1 = xindex // 256 % 6
    x3 = xindex // 9216
    x4 = xindex % 1536
    x0 = xindex % 256
    x6 = xindex
    tmp0 = -1 + x2
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = -1 + x1
    tmp6 = tmp5 >= tmp1
    tmp7 = tmp5 < tmp3
    tmp8 = tmp2 & tmp4
    tmp9 = tmp8 & tmp6
    tmp10 = tmp9 & tmp7
    tmp11 = tl.load(in_ptr0 + (-1280 + x4 + 1024 * x2 + 4096 * x3), tmp10,
        other=0.0)
    tmp12 = tl.load(in_ptr1 + x0, tmp10, eviction_policy='evict_last',
        other=0.0)
    tmp13 = tmp11 + tmp12
    tmp14 = tl.full([1], 0, tl.int32)
    tmp15 = triton_helpers.maximum(tmp14, tmp13)
    tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype)
    tmp17 = tl.where(tmp10, tmp15, tmp16)
    tl.store(out_ptr0 + x6, tmp17, None)


@triton.jit
def triton_poi_fused_convolution_relu_4(in_out_ptr0, in_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
    x0 = xindex % 256
    tmp0 = tl.load(in_out_ptr0 + x2, None)
    tmp1 = tl.load(in_ptr0 + x0, None, 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 + x2, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_relu_5(in_out_ptr0, in_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
    x0 = xindex % 256
    tmp0 = tl.load(in_out_ptr0 + x2, None)
    tmp1 = tl.load(in_ptr0 + x0, None, 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 + x2, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_sigmoid_6(in_ptr0, in_ptr1, out_ptr0,
    ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
    ynumel = 84
    xnumel = 64
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y0 = yindex % 21
    y1 = yindex // 21
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 21 * x2 + 1344 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.sigmoid(tmp2)
    tl.store(out_ptr0 + (x2 + 64 * y3), tmp3, xmask & ymask)


@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_7(in_ptr0, in_ptr1,
    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
    x0 = xindex % 256
    tmp0 = tl.load(in_ptr0 + x2, None)
    tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tl.store(out_ptr0 + x2, tmp6, None)


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) = args
    args.clear()
    assert_size_stride(primals_1, (4, 256, 4, 4), (4096, 16, 4, 1))
    assert_size_stride(primals_2, (256, 256, 3, 3), (2304, 9, 3, 1))
    assert_size_stride(primals_3, (256,), (1,))
    assert_size_stride(primals_4, (256, 256, 3, 3), (2304, 9, 3, 1))
    assert_size_stride(primals_5, (256,), (1,))
    assert_size_stride(primals_6, (256, 256, 3, 3), (2304, 9, 3, 1))
    assert_size_stride(primals_7, (256,), (1,))
    assert_size_stride(primals_8, (256, 256, 3, 3), (2304, 9, 3, 1))
    assert_size_stride(primals_9, (256,), (1,))
    assert_size_stride(primals_10, (256, 256, 2, 2), (1024, 4, 2, 1))
    assert_size_stride(primals_11, (256,), (1,))
    assert_size_stride(primals_12, (21, 256, 1, 1), (256, 1, 1, 1))
    assert_size_stride(primals_13, (21,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
            torch.float32)
        get_raw_stream(0)
        triton_poi_fused_0[grid(65536, 9)](primals_2, buf0, 65536, 9,
            XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
        del primals_2
        buf1 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
            torch.float32)
        triton_poi_fused_0[grid(65536, 9)](primals_4, buf1, 65536, 9,
            XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
        del primals_4
        buf2 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
            torch.float32)
        triton_poi_fused_0[grid(65536, 9)](primals_6, buf2, 65536, 9,
            XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
        del primals_6
        buf3 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
            torch.float32)
        triton_poi_fused_0[grid(65536, 9)](primals_8, buf3, 65536, 9,
            XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
        del primals_8
        buf4 = empty_strided_cuda((256, 256, 2, 2), (1024, 1, 512, 256),
            torch.float32)
        triton_poi_fused_1[grid(65536, 4)](primals_10, buf4, 65536, 4,
            XBLOCK=4, YBLOCK=256, num_warps=4, num_stages=1)
        del primals_10
        buf5 = empty_strided_cuda((4, 256, 6, 6), (9216, 1, 1536, 256),
            torch.float32)
        triton_poi_fused_constant_pad_nd_2[grid(1024, 36)](primals_1, buf5,
            1024, 36, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_1
        buf6 = extern_kernels.convolution(buf5, buf0, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf6, (4, 256, 4, 4), (4096, 1, 1024, 256))
        buf7 = empty_strided_cuda((4, 256, 6, 6), (9216, 1, 1536, 256),
            torch.float32)
        triton_poi_fused_constant_pad_nd_convolution_relu_3[grid(36864)](buf6,
            primals_3, buf7, 36864, XBLOCK=256, num_warps=4, num_stages=1)
        buf8 = extern_kernels.convolution(buf7, buf1, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf8, (4, 256, 4, 4), (4096, 1, 1024, 256))
        buf9 = empty_strided_cuda((4, 256, 6, 6), (9216, 1, 1536, 256),
            torch.float32)
        triton_poi_fused_constant_pad_nd_convolution_relu_3[grid(36864)](buf8,
            primals_5, buf9, 36864, XBLOCK=256, num_warps=4, num_stages=1)
        buf10 = extern_kernels.convolution(buf9, buf2, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf10, (4, 256, 4, 4), (4096, 1, 1024, 256))
        buf11 = empty_strided_cuda((4, 256, 6, 6), (9216, 1, 1536, 256),
            torch.float32)
        triton_poi_fused_constant_pad_nd_convolution_relu_3[grid(36864)](buf10,
            primals_7, buf11, 36864, XBLOCK=256, num_warps=4, num_stages=1)
        buf12 = extern_kernels.convolution(buf11, buf3, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf12, (4, 256, 4, 4), (4096, 1, 1024, 256))
        buf13 = buf12
        del buf12
        triton_poi_fused_convolution_relu_4[grid(16384)](buf13, primals_9, 
            16384, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_9
        buf14 = extern_kernels.convolution(buf13, buf4, stride=(2, 2),
            padding=(0, 0), dilation=(1, 1), transposed=True,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf14, (4, 256, 8, 8), (16384, 1, 2048, 256))
        buf15 = buf14
        del buf14
        triton_poi_fused_convolution_relu_5[grid(65536)](buf15, primals_11,
            65536, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_11
        buf16 = extern_kernels.convolution(buf15, primals_12, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf16, (4, 21, 8, 8), (1344, 1, 168, 21))
        buf17 = empty_strided_cuda((4, 21, 8, 8), (1344, 64, 8, 1), torch.
            float32)
        triton_poi_fused_convolution_sigmoid_6[grid(84, 64)](buf16,
            primals_13, buf17, 84, 64, XBLOCK=64, YBLOCK=4, num_warps=4,
            num_stages=1)
        del buf16
        del primals_13
        buf18 = empty_strided_cuda((4, 256, 4, 4), (4096, 1, 1024, 256),
            torch.bool)
        triton_poi_fused_convolution_relu_threshold_backward_7[grid(16384)](
            buf10, primals_7, buf18, 16384, XBLOCK=256, num_warps=4,
            num_stages=1)
        del buf10
        del primals_7
        buf19 = empty_strided_cuda((4, 256, 4, 4), (4096, 1, 1024, 256),
            torch.bool)
        triton_poi_fused_convolution_relu_threshold_backward_7[grid(16384)](
            buf8, primals_5, buf19, 16384, XBLOCK=256, num_warps=4,
            num_stages=1)
        del buf8
        del primals_5
        buf20 = empty_strided_cuda((4, 256, 4, 4), (4096, 1, 1024, 256),
            torch.bool)
        triton_poi_fused_convolution_relu_threshold_backward_7[grid(16384)](
            buf6, primals_3, buf20, 16384, XBLOCK=256, num_warps=4,
            num_stages=1)
        del buf6
        del primals_3
    return (buf17, buf0, buf1, buf2, buf3, buf4, primals_12, buf5, buf7,
        buf9, buf11, buf13, buf15, buf17, buf18, buf19, buf20)


class SamePad2dStrong(nn.Module):
    """Mimics tensorflow's 'SAME' padding.
    """

    def __init__(self, kernel_size, stride):
        super(SamePad2dStrong, self).__init__()
        self.kernel_size = torch.nn.modules.utils._pair(kernel_size)
        self.stride = torch.nn.modules.utils._pair(stride)

    def forward(self, input):
        in_width = input.size()[2]
        in_height = input.size()[3]
        out_width = math.ceil(float(in_width) / float(self.stride[0]))
        out_height = math.ceil(float(in_height) / float(self.stride[1]))
        pad_along_width = (out_width - 1) * self.stride[0] + self.kernel_size[0
            ] - in_width
        pad_along_height = (out_height - 1) * self.stride[1
            ] + self.kernel_size[1] - in_height
        pad_left = math.floor(pad_along_width / 2)
        pad_top = math.floor(pad_along_height / 2)
        pad_right = pad_along_width - pad_left
        pad_bottom = pad_along_height - pad_top
        return F.pad(input, (pad_left, pad_right, pad_top, pad_bottom),
            'constant', 0)

    def __repr__(self):
        return self.__class__.__name__


class StrongMaskNew(nn.Module):

    def __init__(self, depth=256, pool_size=14, num_classes=21):
        super(StrongMaskNew, self).__init__()
        self.depth = depth
        self.pool_size = pool_size
        self.num_classes = num_classes
        self.padding = SamePad2dStrong(kernel_size=3, stride=1)
        self.conv1 = nn.Conv2d(self.depth, 256, kernel_size=3, stride=1)
        self.conv2 = nn.Conv2d(256, 256, kernel_size=3, stride=1)
        self.conv3 = nn.Conv2d(256, 256, kernel_size=3, stride=1)
        self.conv4 = nn.Conv2d(256, 256, kernel_size=3, stride=1)
        self.deconv = nn.ConvTranspose2d(256, 256, kernel_size=2, stride=2)
        self.conv5 = nn.Conv2d(256, num_classes, kernel_size=1, stride=1)
        self.sigmoid = nn.Sigmoid()
        self.relu = nn.ReLU(inplace=True)

    def forward(self, input_0):
        primals_2 = self.conv1.weight
        primals_3 = self.conv1.bias
        primals_4 = self.conv2.weight
        primals_5 = self.conv2.bias
        primals_6 = self.conv3.weight
        primals_7 = self.conv3.bias
        primals_8 = self.conv4.weight
        primals_9 = self.conv4.bias
        primals_10 = self.deconv.weight
        primals_11 = self.deconv.bias
        primals_12 = self.conv5.weight
        primals_13 = self.conv5.bias
        primals_1 = 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])
        return output[0]


Measured latency_ms: 0.30476