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._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
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_acos_add_div_mean_mul_sqrt_sum_0(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 % 16
    r1 = rindex // 16
    tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None)
    tmp4 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None)
    tmp8 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None)
    tmp12 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None)
    tmp16 = tl.load(in_ptr1 + (r0 + 64 * r1), None)
    tmp19 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None)
    tmp23 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None)
    tmp27 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None)
    tmp1 = 1e-08
    tmp2 = tmp0 + tmp1
    tmp3 = tmp2 * tmp2
    tmp5 = tmp4 + tmp1
    tmp6 = tmp5 * tmp5
    tmp7 = tmp3 + tmp6
    tmp9 = tmp8 + tmp1
    tmp10 = tmp9 * tmp9
    tmp11 = tmp7 + tmp10
    tmp13 = tmp12 + tmp1
    tmp14 = tmp13 * tmp13
    tmp15 = tmp11 + tmp14
    tmp17 = tmp16 + tmp1
    tmp18 = tmp17 * tmp17
    tmp20 = tmp19 + tmp1
    tmp21 = tmp20 * tmp20
    tmp22 = tmp18 + tmp21
    tmp24 = tmp23 + tmp1
    tmp25 = tmp24 * tmp24
    tmp26 = tmp22 + tmp25
    tmp28 = tmp27 + tmp1
    tmp29 = tmp28 * tmp28
    tmp30 = tmp26 + tmp29
    tmp31 = tmp15 * tmp30
    tmp32 = tmp2 * tmp17
    tmp33 = tmp5 * tmp20
    tmp34 = tmp32 + tmp33
    tmp35 = tmp9 * tmp24
    tmp36 = tmp34 + tmp35
    tmp37 = tmp13 * tmp28
    tmp38 = tmp36 + tmp37
    tmp39 = libdevice.sqrt(tmp31)
    tmp40 = tmp38 / tmp39
    tmp41 = libdevice.acos(tmp40)
    tmp42 = tl.broadcast_to(tmp41, [XBLOCK, RBLOCK])
    tmp44 = tl.sum(tmp42, 1)[:, None]
    tmp45 = 64.0
    tmp46 = tmp44 / tmp45
    tl.debug_barrier()
    tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp46, 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)
        buf2 = empty_strided_cuda((), (), torch.float32)
        buf3 = buf2
        del buf2
        get_raw_stream(0)
        triton_per_fused_acos_add_div_mean_mul_sqrt_sum_0[grid(1)](buf3,
            arg0_1, arg1_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
    return buf3,


class SAM_LossNew(nn.Module):

    def __init__(self):
        super(SAM_LossNew, self).__init__()

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


Measured latency_ms: 0.015287