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 as nn
from torch.nn.parameter import Parameter
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 192
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 16 % 3
    x0 = xindex % 16
    x2 = xindex // 48
    x3 = xindex
    tmp6 = tl.load(in_ptr1 + 0)
    tmp7 = tl.broadcast_to(tmp6, [XBLOCK])
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 64 * x2), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp8 = tmp5 / tmp7
    tmp9 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), tmp4 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp10 = tmp9 / tmp7
    tmp11 = tmp8 * tmp10
    tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype)
    tmp13 = tl.where(tmp4, tmp11, tmp12)
    tmp14 = tmp0 >= tmp3
    tmp15 = tl.full([1], 2, tl.int64)
    tmp16 = tmp0 < tmp15
    tmp17 = tmp14 & tmp16
    tmp18 = tl.load(in_ptr0 + (16 + x0 + 16 * (-1 + x1) + 64 * x2), tmp17 &
        xmask, other=0.0)
    tmp19 = tmp18 / tmp7
    tmp20 = tl.load(in_ptr0 + (32 + x0 + 16 * (-1 + x1) + 64 * x2), tmp17 &
        xmask, other=0.0)
    tmp21 = tmp20 / tmp7
    tmp22 = tmp19 * tmp21
    tmp23 = tl.full(tmp22.shape, 0.0, tmp22.dtype)
    tmp24 = tl.where(tmp17, tmp22, tmp23)
    tmp25 = tmp0 >= tmp15
    tl.full([1], 3, tl.int64)
    tmp28 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), tmp25 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp29 = tmp28 / tmp7
    tmp30 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), tmp25 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp31 = tmp30 / tmp7
    tmp32 = tmp29 * tmp31
    tmp33 = tl.full(tmp32.shape, 0.0, tmp32.dtype)
    tmp34 = tl.where(tmp25, tmp32, tmp33)
    tmp35 = tl.where(tmp17, tmp24, tmp34)
    tmp36 = tl.where(tmp4, tmp13, tmp35)
    tl.store(out_ptr0 + x3, tmp36, xmask)


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, (), ())
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 3, 4, 4), (48, 16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(192)](arg0_1, arg1_1, buf0, 192, XBLOCK
            =256, num_warps=4, num_stages=1)
        del arg0_1
        del arg1_1
    return buf0,


class EnergyEstimateWidthRescaleNew(nn.Module):

    def __init__(self, scales):
        super(EnergyEstimateWidthRescaleNew, self).__init__()
        self.scales = Parameter(torch.tensor(scales, dtype=torch.float32),
            requires_grad=False)

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


Measured latency_ms: 0.01507