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 import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
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
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused_stack_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 24
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 8
    x1 = xindex // 8
    x2 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (12 + 8 * x1 + x0), tmp4 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp6 = tl.load(in_ptr0 + (4 + 8 * x1 + x0), tmp4 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp7 = -tmp6
    tmp8 = tmp5 + tmp7
    tmp9 = tl.load(in_ptr0 + (8 + 8 * x1 + x0), tmp4 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp10 = tl.load(in_ptr0 + (8 * x1 + x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp11 = -tmp10
    tmp12 = tmp9 + tmp11
    tmp13 = libdevice.atan2(tmp8, tmp12)
    tmp14 = 1.5707963
    tmp15 = libdevice.fmod(tmp13, tmp14)
    tmp16 = tl_math.abs(tmp15)
    tmp17 = tl_math.cos(tmp16)
    tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype)
    tmp19 = tl.where(tmp4, tmp17, tmp18)
    tmp20 = tmp0 >= tmp3
    tl.full([1], 8, tl.int64)
    tmp23 = tl.load(in_ptr0 + (12 + 8 * x1 + (-4 + x0)), tmp20 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp24 = tl.load(in_ptr0 + (4 + 8 * x1 + (-4 + x0)), tmp20 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp25 = -tmp24
    tmp26 = tmp23 + tmp25
    tmp27 = tl.load(in_ptr0 + (8 + 8 * x1 + (-4 + x0)), tmp20 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp28 = tl.load(in_ptr0 + (8 * x1 + (-4 + x0)), tmp20 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp29 = -tmp28
    tmp30 = tmp27 + tmp29
    tmp31 = libdevice.atan2(tmp26, tmp30)
    tmp32 = libdevice.fmod(tmp31, tmp14)
    tmp33 = tl_math.abs(tmp32)
    tmp34 = tmp33 - tmp14
    tmp35 = tl_math.cos(tmp34)
    tmp36 = tl.full(tmp35.shape, 0.0, tmp35.dtype)
    tmp37 = tl.where(tmp20, tmp35, tmp36)
    tmp38 = tl.where(tmp4, tmp19, tmp37)
    tmp39 = tmp16 + tmp14
    tmp40 = tl_math.cos(tmp39)
    tmp41 = tl.full(tmp40.shape, 0.0, tmp40.dtype)
    tmp42 = tl.where(tmp4, tmp40, tmp41)
    tmp43 = tl_math.cos(tmp33)
    tmp44 = tl.full(tmp43.shape, 0.0, tmp43.dtype)
    tmp45 = tl.where(tmp20, tmp43, tmp44)
    tmp46 = tl.where(tmp4, tmp42, tmp45)
    tl.store(out_ptr0 + x2, tmp38, xmask)
    tl.store(out_ptr1 + x2, tmp46, xmask)


@triton.jit
def triton_poi_fused_cat_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 48
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 8 % 2
    x0 = xindex % 8
    x2 = xindex // 16
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 8 * x2), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 2, tl.int64)
    tmp9 = tl.load(in_ptr1 + (x0 + 8 * x2), tmp6 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp10 = tl.where(tmp4, tmp5, tmp9)
    tl.store(out_ptr0 + x3, tmp10, xmask)


@triton.jit
def triton_poi_fused_clone_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 96
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = xindex // 4 % 4
    x2 = xindex // 16 % 2
    x4 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 8 * x1), xmask, eviction_policy
        ='evict_last')
    tl.store(out_ptr0 + x4, tmp0, xmask)


@triton.jit
def triton_per_fused_min_mul_sub_3(in_ptr0, out_ptr0, xnumel, rnumel,
    XBLOCK: tl.constexpr):
    rnumel = 12
    RBLOCK: tl.constexpr = 16
    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, :]
    rmask = rindex < rnumel
    r0 = rindex % 4
    r1 = rindex // 4
    tmp0 = tl.load(in_ptr0 + (r0 + 16 * r1), rmask, other=0.0)
    tmp1 = tl.load(in_ptr0 + (4 + r0 + 16 * r1), rmask, other=0.0)
    tmp5 = tl.load(in_ptr0 + (8 + r0 + 16 * r1), rmask, other=0.0)
    tmp6 = tl.load(in_ptr0 + (12 + r0 + 16 * r1), rmask, other=0.0)
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp3 = triton_helpers.minimum(tmp0, tmp1)
    tmp4 = tmp2 - tmp3
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = triton_helpers.minimum(tmp5, tmp6)
    tmp9 = tmp7 - tmp8
    tmp10 = tmp4 * tmp9
    tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK])
    tmp13 = tl.where(rmask, tmp11, float('inf'))
    tmp14 = triton_helpers.min2(tmp13, 1)[:, None]
    tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp14, None)


def call(args):
    arg0_1, = args
    args.clear()
    assert_size_stride(arg0_1, (4, 2, 4), (8, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((3, 8), (8, 1), torch.float32)
        buf1 = empty_strided_cuda((3, 8), (8, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_stack_0[grid(24)](arg0_1, buf0, buf1, 24, XBLOCK=
            32, num_warps=1, num_stages=1)
        buf2 = empty_strided_cuda((3, 2, 2, 4), (16, 8, 4, 1), torch.float32)
        triton_poi_fused_cat_1[grid(48)](buf0, buf1, buf2, 48, XBLOCK=64,
            num_warps=1, num_stages=1)
        del buf0
        del buf1
        buf3 = empty_strided_cuda((3, 2, 4, 4), (32, 16, 4, 1), torch.float32)
        triton_poi_fused_clone_2[grid(96)](arg0_1, buf3, 96, XBLOCK=128,
            num_warps=4, num_stages=1)
        del arg0_1
        buf4 = empty_strided_cuda((6, 2, 4), (8, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf2, (6, 2, 4), (8, 4, 1), 0
            ), reinterpret_tensor(buf3, (6, 4, 4), (16, 4, 1), 0), out=buf4)
        del buf2
        del buf3
        buf5 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_min_mul_sub_3[grid(1)](buf4, buf5, 1, 12, XBLOCK=1,
            num_warps=2, num_stages=1)
        del buf4
    return buf5,


class mbr_convex_hullNew(nn.Module):

    def _init_(self, hull_points_2d):
        super(mbr_convex_hullNew, self)._init_()
        self.hull_points_2d = hull_points_2d
        return

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


Measured latency_ms: 0.038618