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.utils.data
from torch import nn
import torch.nn.functional as F
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_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = 0.5
    tmp2 = tmp0 * tmp1
    tl.store(out_ptr0 + x0, tmp2, xmask)


@triton.jit
def triton_poi_fused_add_mul_1(in_ptr0, in_ptr1, in_ptr2, out_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 // 16 % 4
    x2 = xindex // 64
    tmp0 = tl.load(in_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr1 + (x1 + 8 * x2 + 32 * (x2 % 4 // 4) + 128 * ((4 *
        (x2 // 4 % 4) + x2 % 4) // 16)), None, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr1 + (4 + x1 + 8 * x2 + 32 * (x2 % 4 // 4) + 128 *
        ((4 * (x2 // 4 % 4) + x2 % 4) // 16)), None, eviction_policy=
        'evict_last')
    tmp14 = tl.load(in_ptr2 + (4 + x1), None, eviction_policy='evict_last')
    tmp3 = 1.0
    tmp4 = tmp2 * tmp3
    tmp5 = tmp1 + tmp4
    tmp6 = 0.0
    tmp7 = tmp5 > tmp6
    tmp8 = 0.2
    tmp9 = tmp5 * tmp8
    tmp10 = tl.where(tmp7, tmp5, tmp9)
    tmp11 = tmp10 + tmp3
    tmp12 = tmp0 * tmp11
    tmp15 = tmp14 * tmp3
    tmp16 = tmp13 + tmp15
    tmp17 = tmp16 > tmp6
    tmp18 = tmp16 * tmp8
    tmp19 = tl.where(tmp17, tmp16, tmp18)
    tmp20 = tmp12 + tmp19
    tl.store(out_ptr0 + x3, tmp20, None)


@triton.jit
def triton_poi_fused_leaky_relu_backward_2(in_ptr0, in_ptr1, 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
    x0 = xindex % 8
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = 1.0
    tmp3 = tmp1 * tmp2
    tmp4 = tmp0 + tmp3
    tmp5 = 0.0
    tmp6 = tmp4 > tmp5
    tmp7 = 0.2
    tmp8 = tmp4 * tmp7
    tmp9 = tl.where(tmp6, tmp4, tmp8)
    tmp10 = tmp9 > tmp5
    tl.store(out_ptr0 + x3, tmp10, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4 = args
    args.clear()
    assert_size_stride(primals_1, (8,), (1,))
    assert_size_stride(primals_2, (8, 4), (4, 1))
    assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_4, (64, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((8, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_mul_0[grid(32)](primals_2, buf0, 32, XBLOCK=32,
            num_warps=1, num_stages=1)
        del primals_2
        buf1 = empty_strided_cuda((64, 8), (8, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
            reinterpret_tensor(buf0, (4, 8), (1, 4), 0), out=buf1)
        del buf0
        buf2 = empty_strided_cuda((64, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_add_mul_1[grid(4096)](primals_4, buf1, primals_1,
            buf2, 4096, XBLOCK=256, num_warps=4, num_stages=1)
        buf3 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.bool)
        triton_poi_fused_leaky_relu_backward_2[grid(512)](buf1, primals_1,
            buf3, 512, XBLOCK=256, num_warps=4, num_stages=1)
        del buf1
        del primals_1
    return buf2, primals_4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
        ), buf3


class FC(nn.Module):

    def __init__(self, in_channels, out_channels, gain=2 ** 0.5, use_wscale
        =False, lrmul=1.0, bias=True):
        super(FC, self).__init__()
        he_std = gain * in_channels ** -0.5
        if use_wscale:
            init_std = 1.0 / lrmul
            self.w_lrmul = he_std * lrmul
        else:
            init_std = he_std / lrmul
            self.w_lrmul = lrmul
        self.weight = torch.nn.Parameter(torch.randn(out_channels,
            in_channels) * init_std)
        if bias:
            self.bias = torch.nn.Parameter(torch.zeros(out_channels))
            self.b_lrmul = lrmul
        else:
            self.bias = None

    def forward(self, x):
        if self.bias is not None:
            out = F.linear(x, self.weight * self.w_lrmul, self.bias * self.
                b_lrmul)
        else:
            out = F.linear(x, self.weight * self.w_lrmul)
        out = F.leaky_relu(out, 0.2, inplace=True)
        return out


class ApplyStyleNew(nn.Module):

    def __init__(self, latent_size, channels, use_wscale):
        super(ApplyStyleNew, self).__init__()
        self.linear = FC(latent_size, channels * 2, gain=1.0, use_wscale=
            use_wscale)

    def forward(self, input_0, input_1):
        primals_2 = self.linear.weight
        primals_1 = self.linear.bias
        primals_4 = input_0
        primals_3 = input_1
        output = call([primals_1, primals_2, primals_3, primals_4])
        return output[0]


Measured latency_ms: 0.014032