import torch
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 import nn
import torch.optim
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_per_fused_add_mean_mul_ones_like_pow_sub_0(in_out_ptr0,
    in_out_ptr1, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 64
    xoffset = tl.program_id(0) * XBLOCK
    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)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp11 = tl.load(in_ptr1 + r0, None)
    tmp17 = tl.load(in_ptr0 + (64 + r0), None)
    tmp27 = tl.load(in_ptr1 + (64 + r0), None)
    tmp33 = tl.load(in_ptr0 + (128 + r0), None)
    tmp43 = tl.load(in_ptr1 + (128 + r0), None)
    tmp1 = 1.0
    tmp2 = tmp0 - tmp1
    tmp3 = tmp2 * tmp2
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp6 = tl.sum(tmp4, 1)[:, None]
    tmp7 = tmp0 * tmp0
    tmp8 = tl.broadcast_to(tmp7, [XBLOCK, RBLOCK])
    tmp10 = tl.sum(tmp8, 1)[:, None]
    tmp12 = tmp11 - tmp1
    tmp13 = tmp12 * tmp12
    tmp14 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK])
    tmp16 = tl.sum(tmp14, 1)[:, None]
    tmp18 = tmp17 - tmp1
    tmp19 = tmp18 * tmp18
    tmp20 = tl.broadcast_to(tmp19, [XBLOCK, RBLOCK])
    tmp22 = tl.sum(tmp20, 1)[:, None]
    tmp23 = tmp17 * tmp17
    tmp24 = tl.broadcast_to(tmp23, [XBLOCK, RBLOCK])
    tmp26 = tl.sum(tmp24, 1)[:, None]
    tmp28 = tmp27 - tmp1
    tmp29 = tmp28 * tmp28
    tmp30 = tl.broadcast_to(tmp29, [XBLOCK, RBLOCK])
    tmp32 = tl.sum(tmp30, 1)[:, None]
    tmp34 = tmp33 - tmp1
    tmp35 = tmp34 * tmp34
    tmp36 = tl.broadcast_to(tmp35, [XBLOCK, RBLOCK])
    tmp38 = tl.sum(tmp36, 1)[:, None]
    tmp39 = tmp33 * tmp33
    tmp40 = tl.broadcast_to(tmp39, [XBLOCK, RBLOCK])
    tmp42 = tl.sum(tmp40, 1)[:, None]
    tmp44 = tmp43 - tmp1
    tmp45 = tmp44 * tmp44
    tmp46 = tl.broadcast_to(tmp45, [XBLOCK, RBLOCK])
    tmp48 = tl.sum(tmp46, 1)[:, None]
    tmp49 = 64.0
    tmp50 = tmp10 / tmp49
    tmp51 = tmp16 / tmp49
    tmp52 = tmp50 + tmp51
    tmp53 = 0.5
    tmp54 = tmp52 * tmp53
    tmp55 = 0.0
    tmp56 = tmp54 + tmp55
    tmp57 = tmp26 / tmp49
    tmp58 = tmp32 / tmp49
    tmp59 = tmp57 + tmp58
    tmp60 = tmp59 * tmp53
    tmp61 = tmp56 + tmp60
    tmp62 = tmp42 / tmp49
    tmp63 = tmp48 / tmp49
    tmp64 = tmp62 + tmp63
    tmp65 = tmp64 * tmp53
    tmp66 = tmp61 + tmp65
    tmp67 = tmp6 / tmp49
    tmp68 = tmp67 + tmp55
    tmp69 = tmp22 / tmp49
    tmp70 = tmp68 + tmp69
    tmp71 = tmp38 / tmp49
    tmp72 = tmp70 + tmp71
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp66, None)
    tl.debug_barrier()
    tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp72, None)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((), (), torch.float32)
        buf3 = empty_strided_cuda((), (), torch.float32)
        buf10 = buf3
        del buf3
        buf9 = buf0
        del buf0
        get_raw_stream(0)
        triton_per_fused_add_mean_mul_ones_like_pow_sub_0[grid(1)](buf10,
            buf9, arg0_1, arg1_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
    return buf9, buf10


class LSGanLossNew(nn.Module):

    def __init__(self, layer=3):
        super(LSGanLossNew, self).__init__()
        self.layer = layer

    def forward(self, input_0, input_1):
        arg0_1 = input_0
        arg1_1 = input_1
        output = call([arg0_1, arg1_1])
        return output[0], output[1]


Measured latency_ms: 0.016507