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
import torch.utils.data
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_poi_fused_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    tmp0 = tl.load(in_ptr0 + 2)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
    tmp2 = tl.load(in_ptr0 + 0)
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK])
    tmp4 = tmp1 - tmp3
    tl.store(out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp4, None)


@triton.jit
def triton_poi_fused_div_sub_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 16 % 4
    x0 = xindex % 16
    x2 = xindex // 64
    x3 = xindex
    tmp4 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp5 = tl.load(in_ptr1 + 0)
    tmp6 = tl.broadcast_to(tmp5, [XBLOCK])
    tmp10 = tl.load(in_ptr2 + 0)
    tmp11 = tl.broadcast_to(tmp10, [XBLOCK])
    tmp14 = tl.load(in_ptr0 + x3, xmask)
    tmp0 = x1
    tmp1 = tl.full([1], 0, tl.int32)
    tmp2 = tmp0 == tmp1
    tmp3 = tmp1 == tmp1
    tmp7 = tmp4 - tmp6
    tmp8 = tl.where(tmp3, tmp7, tmp4)
    tmp9 = tl.where(tmp3, tmp8, tmp8)
    tmp12 = tmp9 / tmp11
    tmp13 = tl.where(tmp3, tmp12, tmp9)
    tmp15 = tl.where(tmp2, tmp7, tmp14)
    tmp16 = tl.where(tmp2, tmp8, tmp15)
    tmp17 = tl.where(tmp2, tmp12, tmp16)
    tmp18 = tl.where(tmp2, tmp13, tmp17)
    tl.store(out_ptr0 + x3, tmp18, xmask)


@triton.jit
def triton_poi_fused_clone_div_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 16
    x1 = xindex // 16
    x2 = xindex
    tmp2 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
    tmp3 = tl.load(in_ptr1 + 0)
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK])
    tmp8 = tl.load(in_ptr2 + 0)
    tmp9 = tl.broadcast_to(tmp8, [XBLOCK])
    tmp0 = tl.full([1], 0, tl.int32)
    tmp1 = tmp0 == tmp0
    tmp5 = tmp2 - tmp4
    tmp6 = tl.where(tmp1, tmp5, tmp2)
    tmp7 = tl.where(tmp1, tmp6, tmp6)
    tmp10 = tmp7 / tmp9
    tmp11 = tmp10 / tmp9
    tl.store(out_ptr0 + x2, tmp11, xmask)


def call(args):
    primals_1, primals_2 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((), (), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_sub_0[grid(1)](primals_2, buf0, 1, XBLOCK=1,
            num_warps=1, num_stages=1)
        buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_div_sub_1[grid(256)](primals_1, primals_2, buf0,
            buf1, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_clone_div_2[grid(64)](primals_1, primals_2, buf0,
            buf2, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del primals_1
        del primals_2
    return buf1, buf0, buf2


class LinearScalerModelNew(nn.Module):

    def __init__(self, load_from: 'dict'=None):
        super().__init__()
        initial = torch.zeros(4)
        initial[2] = 1
        initial[3] = 10
        self.params = nn.Parameter(initial, requires_grad=False)
        self.param_names = ['Min dose', 'Min density', 'Max dose',
            'Max density']
        if load_from is None:
            self.params.requires_grad = True
        else:
            self.params[0] = load_from['min_dose']
            self.params[1] = load_from['min_density']
            self.params[2] = load_from['max_dose']
            self.params[3] = load_from['max_density']

    def forward(self, input_0):
        primals_2 = self.params
        primals_1 = input_0
        output = call([primals_1, primals_2])
        return output[0]


Measured latency_ms: 0.040742