import torch


def square(x):
    return x * x


class Net2(torch.nn.Module):

    def __init__(self, act=square, output=10):
        super().__init__()
        self.act = act
        self.conv1 = torch.nn.Conv2d(1, 8, kernel_size=5, stride=2, padding=0)
        self.conv2 = torch.nn.Conv2d(8, 64, kernel_size=3, stride=2, padding=0)
        self.conv3 = torch.nn.Conv2d(64, 4, kernel_size=3, stride=1, padding=0)
        self.fc = torch.nn.Linear(4 * 3 * 3, output)

    def forward(self, x):
        x = self.conv1(x)
        x = self.act(x)
        x = self.conv2(x)
        x = self.act(x)
        x = self.conv3(x)
        x = self.act(x)
        x = x.view(-1, 36)
        x = self.fc(x)
        return x

    def mid_layer(self):
        return ['o1', 'o1a', 'o2', 'o2a', 'o3', 'o3a', 'o4']

    def forward_analyze(self, x):
        o1 = self.conv1(x)
        o1a = self.act(o1)
        o2 = self.conv2(o1a)
        o2a = self.act(o2)
        o3 = self.conv3(o2a)
        o3a = self.act(o3)
        o3a = x.view(-1, 36)
        o4 = self.fc(o3a)
        return o1, o1a, o2, o2a, o3, o3a, o4


def get_inputs():
    return [torch.rand([4, 1, 64, 64])]


def get_init_inputs():
    return [[], {}]

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_convolution_mul_0(in_out_ptr0, in_ptr0, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 28800
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 900 % 8
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tmp2 * tmp2
    tl.store(in_out_ptr0 + x3, tmp2, xmask)
    tl.store(out_ptr0 + x3, tmp3, xmask)


@triton.jit
def triton_poi_fused_convolution_mul_1(in_out_ptr0, in_ptr0, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 50176
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 196 % 64
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tmp2 * tmp2
    tl.store(in_out_ptr0 + x3, tmp2, xmask)
    tl.store(out_ptr0 + x3, tmp3, xmask)


@triton.jit
def triton_poi_fused_convolution_mul_2(in_out_ptr0, in_ptr0, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 2304
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 144 % 4
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tmp2 * tmp2
    tl.store(in_out_ptr0 + x3, tmp2, xmask)
    tl.store(out_ptr0 + x3, tmp3, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9) = args
    args.clear()
    assert_size_stride(primals_1, (8, 1, 5, 5), (25, 25, 5, 1))
    assert_size_stride(primals_2, (8,), (1,))
    assert_size_stride(primals_3, (4, 1, 64, 64), (4096, 4096, 64, 1))
    assert_size_stride(primals_4, (64, 8, 3, 3), (72, 9, 3, 1))
    assert_size_stride(primals_5, (64,), (1,))
    assert_size_stride(primals_6, (4, 64, 3, 3), (576, 9, 3, 1))
    assert_size_stride(primals_7, (4,), (1,))
    assert_size_stride(primals_8, (10, 36), (36, 1))
    assert_size_stride(primals_9, (10,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(2, 
            2), padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 8, 30, 30), (7200, 900, 30, 1))
        buf1 = buf0
        del buf0
        buf2 = empty_strided_cuda((4, 8, 30, 30), (7200, 900, 30, 1), torch
            .float32)
        get_raw_stream(0)
        triton_poi_fused_convolution_mul_0[grid(28800)](buf1, primals_2,
            buf2, 28800, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_2
        buf3 = extern_kernels.convolution(buf2, primals_4, stride=(2, 2),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf3, (4, 64, 14, 14), (12544, 196, 14, 1))
        buf4 = buf3
        del buf3
        buf5 = empty_strided_cuda((4, 64, 14, 14), (12544, 196, 14, 1),
            torch.float32)
        triton_poi_fused_convolution_mul_1[grid(50176)](buf4, primals_5,
            buf5, 50176, XBLOCK=512, num_warps=4, num_stages=1)
        del primals_5
        buf6 = extern_kernels.convolution(buf5, primals_6, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf6, (4, 4, 12, 12), (576, 144, 12, 1))
        buf7 = buf6
        del buf6
        buf8 = empty_strided_cuda((4, 4, 12, 12), (576, 144, 12, 1), torch.
            float32)
        triton_poi_fused_convolution_mul_2[grid(2304)](buf7, primals_7,
            buf8, 2304, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_7
        buf9 = empty_strided_cuda((64, 10), (10, 1), torch.float32)
        extern_kernels.addmm(primals_9, reinterpret_tensor(buf8, (64, 36),
            (36, 1), 0), reinterpret_tensor(primals_8, (36, 10), (1, 36), 0
            ), alpha=1, beta=1, out=buf9)
        del primals_9
    return (buf9, primals_1, primals_3, primals_4, primals_6, buf1, buf2,
        buf4, buf5, buf7, reinterpret_tensor(buf8, (64, 36), (36, 1), 0),
        primals_8)


def square(x):
    return x * x


class Net2New(torch.nn.Module):

    def __init__(self, act=square, output=10):
        super().__init__()
        self.act = act
        self.conv1 = torch.nn.Conv2d(1, 8, kernel_size=5, stride=2, padding=0)
        self.conv2 = torch.nn.Conv2d(8, 64, kernel_size=3, stride=2, padding=0)
        self.conv3 = torch.nn.Conv2d(64, 4, kernel_size=3, stride=1, padding=0)
        self.fc = torch.nn.Linear(4 * 3 * 3, output)

    def mid_layer(self):
        return ['o1', 'o1a', 'o2', 'o2a', 'o3', 'o3a', 'o4']

    def forward_analyze(self, x):
        o1 = self.conv1(x)
        o1a = self.act(o1)
        o2 = self.conv2(o1a)
        o2a = self.act(o2)
        o3 = self.conv3(o2a)
        o3a = self.act(o3)
        o3a = x.view(-1, 36)
        o4 = self.fc(o3a)
        return o1, o1a, o2, o2a, o3, o3a, o4

    def forward(self, input_0):
        primals_1 = self.conv1.weight
        primals_2 = 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.fc.weight
        primals_9 = self.fc.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])
        return output[0]
