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.triton_helpers import libdevice
import torch.nn as nn
import torch.fft
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_copy_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 576
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 6
    x1 = xindex // 6 % 6
    x2 = xindex // 36
    x4 = xindex
    tmp0 = x0
    tmp1 = tl.full([1], 5, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = -4 + x0
    tmp4 = tl.full([1], 1, tl.int64)
    tmp5 = tmp3 < tmp4
    tmp6 = tmp5 & tmp2
    tmp7 = tmp0 >= tmp4
    tmp8 = tmp0 < tmp1
    tmp9 = tmp7 & tmp8
    tmp10 = tmp9 & tmp6
    tmp11 = x1
    tmp12 = tmp11 >= tmp4
    tmp13 = tmp11 < tmp1
    tmp14 = tmp12 & tmp13
    tmp15 = tmp14 & tmp10
    tmp16 = tl.load(in_ptr0 + (-5 + x0 + 4 * x1 + 16 * x2), tmp15 & xmask,
        other=0.0)
    tmp17 = tl.load(in_ptr1 + x4, tmp10 & xmask, other=0.0)
    tmp18 = tl.where(tmp14, tmp16, tmp17)
    tmp19 = tl.full(tmp18.shape, 0.0, tmp18.dtype)
    tmp20 = tl.where(tmp10, tmp18, tmp19)
    tmp21 = float('nan')
    tmp22 = tl.where(tmp9, tmp20, tmp21)
    tmp23 = tl.full(tmp22.shape, 0.0, tmp22.dtype)
    tmp24 = tl.where(tmp6, tmp22, tmp23)
    tmp25 = tmp3 >= tmp4
    tmp26 = tmp3 < tmp1
    tmp27 = tmp25 & tmp26
    tmp28 = tmp27 & tmp2
    tmp29 = tmp14 & tmp28
    tmp30 = tl.load(in_ptr0 + (-9 + x0 + 4 * x1 + 16 * x2), tmp29 & xmask,
        other=0.0)
    tmp31 = tl.load(in_ptr1 + (-4 + x4), tmp28 & xmask, other=0.0)
    tmp32 = tl.where(tmp14, tmp30, tmp31)
    tmp33 = tl.full(tmp32.shape, 0.0, tmp32.dtype)
    tmp34 = tl.where(tmp28, tmp32, tmp33)
    tmp35 = tl.where(tmp27, tmp34, tmp21)
    tmp36 = tl.where(tmp5, tmp24, tmp35)
    tmp37 = tl.full(tmp36.shape, 0.0, tmp36.dtype)
    tmp38 = tl.where(tmp2, tmp36, tmp37)
    tmp39 = tmp0 < tmp4
    tmp40 = 4 + x0
    tmp41 = tmp40 >= tmp4
    tmp42 = tmp40 < tmp1
    tmp43 = tmp41 & tmp42
    tmp44 = tmp43 & tmp39
    tmp45 = tmp14 & tmp44
    tmp46 = tl.load(in_ptr0 + (-1 + x0 + 4 * x1 + 16 * x2), tmp45 & xmask,
        other=0.0)
    tmp47 = tl.load(in_ptr1 + (4 + x4), tmp44 & xmask, other=0.0)
    tmp48 = tl.where(tmp14, tmp46, tmp47)
    tmp49 = tl.full(tmp48.shape, 0.0, tmp48.dtype)
    tmp50 = tl.where(tmp44, tmp48, tmp49)
    tmp51 = tl.where(tmp43, tmp50, tmp21)
    tmp52 = tl.full(tmp51.shape, 0.0, tmp51.dtype)
    tmp53 = tl.where(tmp39, tmp51, tmp52)
    tmp54 = tmp14 & tmp9
    tmp55 = tl.load(in_ptr0 + (-5 + x0 + 4 * x1 + 16 * x2), tmp54 & xmask,
        other=0.0)
    tmp56 = tl.load(in_ptr1 + x4, tmp9 & xmask, other=0.0)
    tmp57 = tl.where(tmp14, tmp55, tmp56)
    tmp58 = tl.full(tmp57.shape, 0.0, tmp57.dtype)
    tmp59 = tl.where(tmp9, tmp57, tmp58)
    tmp60 = tl.where(tmp9, tmp59, tmp21)
    tmp61 = tl.where(tmp39, tmp53, tmp60)
    tmp62 = tl.where(tmp2, tmp38, tmp61)
    tl.store(out_ptr0 + x4, tmp62, xmask)


@triton.jit
def triton_poi_fused_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 576
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 6 % 6
    x0 = xindex % 6
    x2 = xindex // 36
    x3 = xindex
    tmp14 = tl.load(in_ptr0 + x3, xmask)
    tmp0 = x1
    tmp1 = tl.full([1], 5, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = -4 + x1
    tmp4 = tl.full([1], 1, tl.int64)
    tmp5 = tmp3 < tmp4
    tmp6 = tmp5 & tmp2
    tmp7 = tl.load(in_ptr0 + (24 + x0 + 36 * x2), tmp6 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp8 = tl.load(in_ptr0 + (-24 + x3), tmp2 & xmask, other=0.0)
    tmp9 = tl.where(tmp5, tmp7, tmp8)
    tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype)
    tmp11 = tl.where(tmp2, tmp9, tmp10)
    tmp12 = tmp0 < tmp4
    tmp13 = tl.load(in_ptr0 + (24 + x0 + 36 * x2), tmp12 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp15 = tl.where(tmp12, tmp13, tmp14)
    tmp16 = tl.where(tmp2, tmp11, tmp15)
    tl.store(out_ptr0 + x3, tmp16, xmask)


@triton.jit
def triton_per_fused__native_batch_norm_legit_add_convolution_leaky_relu_mul_2(
    in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr3, out_ptr4,
    out_ptr5, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    RBLOCK: tl.constexpr = 16
    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 % 4
    tmp0 = tl.load(in_out_ptr0 + (r2 + 16 * x3), xmask, other=0.0)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp26 = tl.load(in_ptr1 + (r2 + 16 * x3), xmask, other=0.0)
    tmp28 = tl.load(in_ptr2 + (r2 + 16 * x3), xmask, other=0.0)
    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], 16, 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 = 16.0
    tmp21 = tmp18 / tmp20
    tmp22 = 1e-05
    tmp23 = tmp21 + tmp22
    tmp24 = libdevice.rsqrt(tmp23)
    tmp25 = tmp19 * tmp24
    tmp27 = tmp25 * tmp26
    tmp29 = tmp27 + tmp28
    tmp30 = 0.0
    tmp31 = tmp29 > tmp30
    tmp32 = 0.01
    tmp33 = tmp29 * tmp32
    tmp34 = tl.where(tmp31, tmp29, tmp33)
    tl.store(in_out_ptr0 + (r2 + 16 * x3), tmp2, xmask)
    tl.store(out_ptr3 + (r2 + 16 * x3), tmp31, xmask)
    tl.store(out_ptr4 + (r2 + 16 * x3), tmp34, xmask)
    tl.store(out_ptr5 + x3, tmp24, xmask)
    tl.store(out_ptr0 + x3, tmp12, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_2, (4,), (1,))
    assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_5, (4, 4, 4, 4), (64, 16, 4, 1))
    buf0 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32)
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf1 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_copy_0[grid(576)](primals_3, buf0, buf1, 576,
            XBLOCK=128, num_warps=4, num_stages=1)
        del primals_3
        buf2 = buf0
        del buf0
        triton_poi_fused_1[grid(576)](buf1, buf2, 576, XBLOCK=128,
            num_warps=4, num_stages=1)
        del buf1
        buf3 = extern_kernels.convolution(buf2, primals_1, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1))
        buf4 = buf3
        del buf3
        buf5 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32
            )
        buf10 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        buf11 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf8 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32
            )
        triton_per_fused__native_batch_norm_legit_add_convolution_leaky_relu_mul_2[
            grid(16)](buf4, primals_2, primals_4, primals_5, buf5, buf10,
            buf11, buf8, 16, 16, XBLOCK=1, num_warps=2, num_stages=1)
        del primals_2
        del primals_5
    return buf11, primals_1, primals_4, buf2, buf4, reinterpret_tensor(buf8,
        (16,), (1,), 0), buf10, reinterpret_tensor(buf5, (1, 16, 1, 1), (16,
        1, 1, 1), 0)


class AdaptiveInstanceNormalization(nn.Module):

    def and__init__(self):
        super(AdaptiveInstanceNormalization, self).__init__()

    def forward(self, x, mean, std):
        whitened_x = torch.nn.functional.instance_norm(x)
        return whitened_x * std + mean


class StyleBlockNew(nn.Module):

    def __init__(self, in_f, out_f):
        super().__init__()
        self.conv = nn.Conv2d(in_f, out_f, 3, 1, 1, padding_mode='circular')
        self.adain = AdaptiveInstanceNormalization()
        self.lrelu = nn.LeakyReLU()

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


Measured latency_ms: 0.065179