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
from torch import 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_convolution_leaky_relu_0(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)
    x3 = xindex
    x1 = xindex // 1024 % 64
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tmp5 = 0.2
    tmp6 = tmp2 * tmp5
    tmp7 = tl.where(tmp4, tmp2, tmp6)
    tl.store(in_out_ptr0 + x3, tmp7, None)


@triton.jit
def triton_per_fused__native_batch_norm_legit_convolution_leaky_relu_1(
    in_out_ptr0, in_ptr0, out_ptr0, out_ptr2, out_ptr3, xnumel, rnumel):
    XBLOCK: tl.constexpr = 1
    RBLOCK: tl.constexpr = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = tl.full([1], xoffset, tl.int32)
    tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    tl.full([RBLOCK], True, tl.int1)
    r2 = rindex
    x3 = xindex
    x0 = xindex % 128
    tmp0 = tl.load(in_out_ptr0 + (r2 + 256 * x3), None)
    tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.broadcast_to(tmp2, [RBLOCK])
    tmp5 = tl.broadcast_to(tmp3, [RBLOCK])
    tmp7 = triton_helpers.promote_to_tensor(tl.sum(tmp5, 0))
    tmp8 = tl.full([1], 256, tl.int32)
    tmp9 = tmp8.to(tl.float32)
    tmp10 = tmp7 / tmp9
    tmp11 = tmp3 - tmp10
    tmp12 = tmp11 * tmp11
    tmp13 = tl.broadcast_to(tmp12, [RBLOCK])
    tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0))
    tmp16 = tmp2 - tmp10
    tmp17 = 256.0
    tmp18 = tmp15 / tmp17
    tmp19 = 1e-05
    tmp20 = tmp18 + tmp19
    tmp21 = libdevice.rsqrt(tmp20)
    tmp22 = tmp16 * tmp21
    tmp23 = 0.0
    tmp24 = tmp22 > tmp23
    tmp25 = 0.2
    tmp26 = tmp22 * tmp25
    tmp27 = tl.where(tmp24, tmp22, tmp26)
    tl.store(in_out_ptr0 + (r2 + 256 * x3), tmp2, None)
    tl.store(out_ptr2 + (r2 + 256 * x3), tmp27, None)
    tl.store(out_ptr3 + x3, tmp21, None)
    tl.store(out_ptr0 + x3, tmp10, None)


@triton.jit
def triton_per_fused__native_batch_norm_legit_convolution_leaky_relu_2(
    in_out_ptr0, in_ptr0, out_ptr0, out_ptr2, out_ptr3, xnumel, rnumel,
    XBLOCK: tl.constexpr):
    xnumel = 1024
    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)
    r2 = rindex
    x3 = xindex
    x0 = xindex % 256
    tmp0 = tl.load(in_out_ptr0 + (r2 + 64 * x3), xmask, other=0.0)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tl.where(xmask, tmp3, 0)
    tmp6 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp8 = tl.where(xmask, tmp6, 0)
    tmp9 = tl.sum(tmp8, 1)[:, None]
    tmp10 = tl.full([XBLOCK, 1], 64, tl.int32)
    tmp11 = tmp10.to(tl.float32)
    tmp12 = tmp9 / tmp11
    tmp13 = tmp3 - tmp12
    tmp14 = tmp13 * tmp13
    tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
    tmp17 = tl.where(xmask, tmp15, 0)
    tmp18 = tl.sum(tmp17, 1)[:, None]
    tmp19 = tmp2 - tmp12
    tmp20 = 64.0
    tmp21 = tmp18 / tmp20
    tmp22 = 1e-05
    tmp23 = tmp21 + tmp22
    tmp24 = libdevice.rsqrt(tmp23)
    tmp25 = tmp19 * tmp24
    tmp26 = 0.0
    tmp27 = tmp25 > tmp26
    tmp28 = 0.2
    tmp29 = tmp25 * tmp28
    tmp30 = tl.where(tmp27, tmp25, tmp29)
    tl.store(in_out_ptr0 + (r2 + 64 * x3), tmp2, xmask)
    tl.store(out_ptr2 + (r2 + 64 * x3), tmp30, xmask)
    tl.store(out_ptr3 + x3, tmp24, xmask)
    tl.store(out_ptr0 + x3, tmp12, xmask)


@triton.jit
def triton_per_fused__native_batch_norm_legit_convolution_leaky_relu_3(
    in_out_ptr0, in_ptr0, out_ptr0, out_ptr2, out_ptr3, xnumel, rnumel,
    XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r2 = rindex
    x3 = xindex
    x0 = xindex % 512
    tmp0 = tl.load(in_out_ptr0 + (r2 + 16 * x3), None)
    tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp7 = tl.sum(tmp5, 1)[:, None]
    tmp8 = tl.full([XBLOCK, 1], 16, tl.int32)
    tmp9 = tmp8.to(tl.float32)
    tmp10 = tmp7 / tmp9
    tmp11 = tmp3 - tmp10
    tmp12 = tmp11 * tmp11
    tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK])
    tmp15 = tl.sum(tmp13, 1)[:, None]
    tmp16 = tmp2 - tmp10
    tmp17 = 16.0
    tmp18 = tmp15 / tmp17
    tmp19 = 1e-05
    tmp20 = tmp18 + tmp19
    tmp21 = libdevice.rsqrt(tmp20)
    tmp22 = tmp16 * tmp21
    tmp23 = 0.0
    tmp24 = tmp22 > tmp23
    tmp25 = 0.2
    tmp26 = tmp22 * tmp25
    tmp27 = tl.where(tmp24, tmp22, tmp26)
    tl.store(in_out_ptr0 + (r2 + 16 * x3), tmp2, None)
    tl.store(out_ptr2 + (r2 + 16 * x3), tmp27, None)
    tl.store(out_ptr3 + x3, tmp21, None)
    tl.store(out_ptr0 + x3, tmp10, None)


@triton.jit
def triton_poi_fused_convolution_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 36
    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.load(in_ptr0 + 0)
    tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
    tmp3 = tmp0 + tmp2
    tl.store(in_out_ptr0 + x0, tmp3, 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) = args
    args.clear()
    assert_size_stride(primals_1, (64, 3, 4, 4), (48, 16, 4, 1))
    assert_size_stride(primals_2, (64,), (1,))
    assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1))
    assert_size_stride(primals_4, (128, 64, 4, 4), (1024, 16, 4, 1))
    assert_size_stride(primals_5, (128,), (1,))
    assert_size_stride(primals_6, (256, 128, 4, 4), (2048, 16, 4, 1))
    assert_size_stride(primals_7, (256,), (1,))
    assert_size_stride(primals_8, (512, 256, 4, 4), (4096, 16, 4, 1))
    assert_size_stride(primals_9, (512,), (1,))
    assert_size_stride(primals_10, (1, 512, 4, 4), (8192, 16, 4, 1))
    assert_size_stride(primals_11, (1,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(2, 
            2), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 64, 32, 32), (65536, 1024, 32, 1))
        buf1 = buf0
        del buf0
        get_raw_stream(0)
        triton_poi_fused_convolution_leaky_relu_0[grid(262144)](buf1,
            primals_2, 262144, XBLOCK=512, num_warps=8, num_stages=1)
        del primals_2
        buf2 = extern_kernels.convolution(buf1, primals_4, stride=(2, 2),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf2, (4, 128, 16, 16), (32768, 256, 16, 1))
        buf3 = buf2
        del buf2
        buf4 = empty_strided_cuda((1, 512, 1, 1), (512, 1, 512, 512), torch
            .float32)
        buf8 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1),
            torch.float32)
        buf7 = empty_strided_cuda((1, 512, 1, 1), (512, 1, 512, 512), torch
            .float32)
        triton_per_fused__native_batch_norm_legit_convolution_leaky_relu_1[grid
            (512)](buf3, primals_5, buf4, buf8, buf7, 512, 256, num_warps=2,
            num_stages=1)
        del primals_5
        buf9 = extern_kernels.convolution(buf8, primals_6, stride=(2, 2),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf9, (4, 256, 8, 8), (16384, 64, 8, 1))
        buf10 = buf9
        del buf9
        buf11 = empty_strided_cuda((1, 1024, 1, 1), (1024, 1, 1024, 1024),
            torch.float32)
        buf15 = empty_strided_cuda((4, 256, 8, 8), (16384, 64, 8, 1), torch
            .float32)
        buf14 = empty_strided_cuda((1, 1024, 1, 1), (1024, 1, 1024, 1024),
            torch.float32)
        triton_per_fused__native_batch_norm_legit_convolution_leaky_relu_2[grid
            (1024)](buf10, primals_7, buf11, buf15, buf14, 1024, 64, XBLOCK
            =8, num_warps=4, num_stages=1)
        del primals_7
        buf16 = extern_kernels.convolution(buf15, primals_8, stride=(2, 2),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf16, (4, 512, 4, 4), (8192, 16, 4, 1))
        buf17 = buf16
        del buf16
        buf18 = empty_strided_cuda((1, 2048, 1, 1), (2048, 1, 2048, 2048),
            torch.float32)
        buf22 = empty_strided_cuda((4, 512, 4, 4), (8192, 16, 4, 1), torch.
            float32)
        buf21 = empty_strided_cuda((1, 2048, 1, 1), (2048, 1, 2048, 2048),
            torch.float32)
        triton_per_fused__native_batch_norm_legit_convolution_leaky_relu_3[grid
            (2048)](buf17, primals_9, buf18, buf22, buf21, 2048, 16, XBLOCK
            =32, num_warps=4, num_stages=1)
        del primals_9
        buf23 = extern_kernels.convolution(buf22, primals_10, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf23, (4, 1, 3, 3), (9, 9, 3, 1))
        buf24 = buf23
        del buf23
        triton_poi_fused_convolution_4[grid(36)](buf24, primals_11, 36,
            XBLOCK=64, num_warps=1, num_stages=1)
        del primals_11
    return (buf24, primals_1, primals_3, primals_4, primals_6, primals_8,
        primals_10, buf1, buf3, reinterpret_tensor(buf7, (512,), (1,), 0),
        buf8, buf10, reinterpret_tensor(buf14, (1024,), (1,), 0), buf15,
        buf17, reinterpret_tensor(buf21, (2048,), (1,), 0), buf22,
        reinterpret_tensor(buf18, (1, 2048, 1, 1), (2048, 1, 1, 1), 0),
        reinterpret_tensor(buf11, (1, 1024, 1, 1), (1024, 1, 1, 1), 0),
        reinterpret_tensor(buf4, (1, 512, 1, 1), (512, 1, 1, 1), 0))


class BasicBlock(nn.Module):
    """Basic block"""

    def __init__(self, inplanes, outplanes, kernel_size=4, stride=2,
        padding=1, norm=True):
        super().__init__()
        self.conv = nn.Conv2d(inplanes, outplanes, kernel_size, stride, padding
            )
        self.isn = None
        if norm:
            self.isn = nn.InstanceNorm2d(outplanes)
        self.lrelu = nn.LeakyReLU(0.2, inplace=True)

    def forward(self, x):
        fx = self.conv(x)
        if self.isn is not None:
            fx = self.isn(fx)
        fx = self.lrelu(fx)
        return fx


class DiscriminatorNew(nn.Module):
    """Basic Discriminator"""

    def __init__(self):
        super().__init__()
        self.block1 = BasicBlock(3, 64, norm=False)
        self.block2 = BasicBlock(64, 128)
        self.block3 = BasicBlock(128, 256)
        self.block4 = BasicBlock(256, 512)
        self.block5 = nn.Conv2d(512, 1, kernel_size=4, stride=1, padding=1)

    def forward(self, input_0):
        primals_1 = self.block1.conv.weight
        primals_2 = self.block1.conv.bias
        primals_4 = self.block2.conv.weight
        primals_5 = self.block2.conv.bias
        primals_6 = self.block3.conv.weight
        primals_7 = self.block3.conv.bias
        primals_8 = self.block4.conv.weight
        primals_9 = self.block4.conv.bias
        primals_10 = self.block5.weight
        primals_11 = self.block5.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])
        return output[0]


Measured latency_ms: 0.065526