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
import 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_copy_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 24
    xnumel = 4
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    y0 = yindex % 6
    x2 = xindex
    y1 = yindex // 6
    tmp0 = y0
    tmp1 = tl.full([1, 1], 5, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.broadcast_to(-4 + y0, [XBLOCK, YBLOCK])
    tmp4 = tl.full([1, 1], 1, tl.int64)
    tmp5 = tmp3 < tmp4
    tmp6 = tmp5 & tmp2
    tmp7 = tl.broadcast_to(y0, [XBLOCK, YBLOCK])
    tmp8 = tmp7 >= tmp4
    tmp9 = tmp7 < tmp1
    tmp10 = tmp8 & tmp9
    tmp11 = tmp10 & tmp6
    tmp12 = tl.load(in_ptr0 + (-4 + x2 + 4 * y0 + 16 * y1), tmp11 & xmask &
        ymask, eviction_policy='evict_last', other=0.0)
    tmp13 = float('nan')
    tmp14 = tl.where(tmp10, tmp12, tmp13)
    tmp15 = tl.full(tmp14.shape, 0.0, tmp14.dtype)
    tmp16 = tl.where(tmp6, tmp14, tmp15)
    tmp17 = tmp3 >= tmp4
    tmp18 = tmp3 < tmp1
    tmp19 = tmp17 & tmp18
    tmp20 = tmp19 & tmp2
    tmp21 = tl.load(in_ptr0 + (-20 + x2 + 4 * y0 + 16 * y1), tmp20 & xmask &
        ymask, eviction_policy='evict_last', other=0.0)
    tmp22 = tl.where(tmp19, tmp21, tmp13)
    tmp23 = tl.where(tmp5, tmp16, tmp22)
    tmp24 = tl.full(tmp23.shape, 0.0, tmp23.dtype)
    tmp25 = tl.where(tmp2, tmp23, tmp24)
    tmp26 = tmp0 < tmp4
    tmp27 = tl.broadcast_to(4 + y0, [XBLOCK, YBLOCK])
    tmp28 = tmp27 >= tmp4
    tmp29 = tmp27 < tmp1
    tmp30 = tmp28 & tmp29
    tmp31 = tmp30 & tmp26
    tmp32 = tl.load(in_ptr0 + (12 + x2 + 4 * y0 + 16 * y1), tmp31 & xmask &
        ymask, eviction_policy='evict_last', other=0.0)
    tmp33 = tl.where(tmp30, tmp32, tmp13)
    tmp34 = tl.full(tmp33.shape, 0.0, tmp33.dtype)
    tmp35 = tl.where(tmp26, tmp33, tmp34)
    tmp36 = tmp0 >= tmp4
    tmp37 = tmp0 < tmp1
    tmp38 = tmp36 & tmp37
    tmp39 = tl.load(in_ptr0 + (-4 + x2 + 4 * y0 + 16 * y1), tmp38 & xmask &
        ymask, eviction_policy='evict_last', other=0.0)
    tmp40 = tl.where(tmp38, tmp39, tmp13)
    tmp41 = tl.where(tmp26, tmp35, tmp40)
    tmp42 = tl.where(tmp2, tmp25, tmp41)
    tl.store(out_ptr0 + (y0 + 6 * x2 + 24 * y1), tmp42, xmask & ymask)


@triton.jit
def triton_poi_fused_add_embedding_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, in_ptr4, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 4
    x2 = xindex // 16
    x1 = xindex // 4 % 4
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + (3 + 4 * x0 + 16 * x2), xmask, eviction_policy
        ='evict_last')
    tmp9 = tl.load(in_ptr0 + (2 + 4 * x0 + 16 * x2), xmask, eviction_policy
        ='evict_last')
    tmp18 = tl.load(in_ptr0 + (1 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp27 = tl.load(in_ptr0 + (4 * x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tmp1.to(tl.int64)
    tmp3 = tl.full([XBLOCK], 24, tl.int32)
    tmp4 = tmp2 + tmp3
    tmp5 = tmp2 < 0
    tmp6 = tl.where(tmp5, tmp4, tmp2)
    tl.device_assert((0 <= tmp6) & (tmp6 < 24) | ~xmask,
        'index out of bounds: 0 <= tmp6 < 24')
    tmp8 = tl.load(in_ptr1 + (x1 + 4 * tmp6), xmask, eviction_policy=
        'evict_last')
    tmp10 = tmp9.to(tl.int64)
    tmp11 = tl.full([XBLOCK], 7, tl.int32)
    tmp12 = tmp10 + tmp11
    tmp13 = tmp10 < 0
    tmp14 = tl.where(tmp13, tmp12, tmp10)
    tl.device_assert((0 <= tmp14) & (tmp14 < 7) | ~xmask,
        'index out of bounds: 0 <= tmp14 < 7')
    tmp16 = tl.load(in_ptr2 + (x1 + 4 * tmp14), xmask, eviction_policy=
        'evict_last')
    tmp17 = tmp8 + tmp16
    tmp19 = tmp18.to(tl.int64)
    tmp20 = tl.full([XBLOCK], 32, tl.int32)
    tmp21 = tmp19 + tmp20
    tmp22 = tmp19 < 0
    tmp23 = tl.where(tmp22, tmp21, tmp19)
    tl.device_assert((0 <= tmp23) & (tmp23 < 32) | ~xmask,
        'index out of bounds: 0 <= tmp23 < 32')
    tmp25 = tl.load(in_ptr3 + (x1 + 4 * tmp23), xmask, eviction_policy=
        'evict_last')
    tmp26 = tmp17 + tmp25
    tmp28 = tmp27.to(tl.int64)
    tmp29 = tl.full([XBLOCK], 13, tl.int32)
    tmp30 = tmp28 + tmp29
    tmp31 = tmp28 < 0
    tmp32 = tl.where(tmp31, tmp30, tmp28)
    tl.device_assert((0 <= tmp32) & (tmp32 < 13) | ~xmask,
        'index out of bounds: 0 <= tmp32 < 13')
    tmp34 = tl.load(in_ptr4 + (x1 + 4 * tmp32), xmask, eviction_policy=
        'evict_last')
    tmp35 = tmp26 + tmp34
    tmp36 = 0.0
    tmp37 = tmp35 + tmp36
    tmp38 = tmp0 + tmp37
    tl.store(in_out_ptr0 + x3, tmp38, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 3), (12, 3, 1))
    assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_4, (24, 4), (4, 1))
    assert_size_stride(primals_5, (7, 4), (4, 1))
    assert_size_stride(primals_6, (32, 4), (4, 1))
    assert_size_stride(primals_7, (13, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf1 = empty_strided_cuda((4, 4, 6), (24, 6, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_copy_0[grid(24, 4)](primals_1, buf1, 24, 4, XBLOCK
            =4, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_1
        buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1,),
            padding=(0,), dilation=(1,), transposed=False, output_padding=(
            0,), groups=1, bias=None)
        assert_size_stride(buf2, (4, 4, 4), (16, 4, 1))
        buf3 = reinterpret_tensor(buf2, (4, 4, 4), (16, 1, 4), 0)
        del buf2
        triton_poi_fused_add_embedding_1[grid(64)](buf3, primals_3,
            primals_4, primals_5, primals_6, primals_7, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        del primals_3
        del primals_4
        del primals_5
        del primals_6
        del primals_7
    return buf3, primals_2, buf1


class PositionalEmbedding(nn.Module):

    def __init__(self, d_model, max_len=5000):
        super(PositionalEmbedding, self).__init__()
        pe = torch.zeros(max_len, d_model).float()
        pe.require_grad = False
        position = torch.arange(0, max_len).float().unsqueeze(1)
        div_term = (torch.arange(0, d_model, 2).float() * -(math.log(
            10000.0) / d_model)).exp()
        pe[:, 0::2] = torch.sin(position * div_term)
        pe[:, 1::2] = torch.cos(position * div_term)
        pe = pe.unsqueeze(0)
        self.register_buffer('pe', pe)

    def forward(self, x):
        return self.pe[:, :x.size(1)]


class TokenEmbedding(nn.Module):

    def __init__(self, c_in, d_model):
        super(TokenEmbedding, self).__init__()
        padding = 1 if torch.__version__ >= '1.5.0' else 2
        self.tokenConv = nn.Conv1d(in_channels=c_in, out_channels=d_model,
            kernel_size=3, padding=padding, padding_mode='circular', bias=False
            )
        for m in self.modules():
            if isinstance(m, nn.Conv1d):
                nn.init.kaiming_normal_(m.weight, mode='fan_in',
                    nonlinearity='leaky_relu')

    def forward(self, x):
        x = self.tokenConv(x.permute(0, 2, 1)).transpose(1, 2)
        return x


class FixedEmbedding(nn.Module):

    def __init__(self, c_in, d_model):
        super(FixedEmbedding, self).__init__()
        w = torch.zeros(c_in, d_model).float()
        w.require_grad = False
        position = torch.arange(0, c_in).float().unsqueeze(1)
        div_term = (torch.arange(0, d_model, 2).float() * -(math.log(
            10000.0) / d_model)).exp()
        w[:, 0::2] = torch.sin(position * div_term)
        w[:, 1::2] = torch.cos(position * div_term)
        self.emb = nn.Embedding(c_in, d_model)
        self.emb.weight = nn.Parameter(w, requires_grad=False)

    def forward(self, x):
        return self.emb(x).detach()


class TemporalEmbedding(nn.Module):

    def __init__(self, d_model, embed_type='fixed', freq='h'):
        super(TemporalEmbedding, self).__init__()
        minute_size = 4
        hour_size = 24
        weekday_size = 7
        day_size = 32
        month_size = 13
        Embed = FixedEmbedding if embed_type == 'fixed' else nn.Embedding
        if freq == 't':
            self.minute_embed = Embed(minute_size, d_model)
        self.hour_embed = Embed(hour_size, d_model)
        self.weekday_embed = Embed(weekday_size, d_model)
        self.day_embed = Embed(day_size, d_model)
        self.month_embed = Embed(month_size, d_model)

    def forward(self, x):
        x = x.long()
        minute_x = self.minute_embed(x[:, :, 4]) if hasattr(self,
            'minute_embed') else 0.0
        hour_x = self.hour_embed(x[:, :, 3])
        weekday_x = self.weekday_embed(x[:, :, 2])
        day_x = self.day_embed(x[:, :, 1])
        month_x = self.month_embed(x[:, :, 0])
        return hour_x + weekday_x + day_x + month_x + minute_x


class TimeFeatureEmbedding(nn.Module):

    def __init__(self, d_model, embed_type='timeF', freq='h'):
        super(TimeFeatureEmbedding, self).__init__()
        freq_map = {'h': 4, 't': 5, 's': 6, 'm': 1, 'a': 1, 'w': 2, 'd': 3,
            'b': 3}
        d_inp = freq_map[freq]
        self.embed = nn.Linear(d_inp, d_model, bias=False)

    def forward(self, x):
        return self.embed(x)


class DataEmbedding_wo_posNew(nn.Module):

    def __init__(self, c_in, d_model, embed_type='fixed', freq='h', dropout=0.1
        ):
        super(DataEmbedding_wo_posNew, self).__init__()
        self.value_embedding = TokenEmbedding(c_in=c_in, d_model=d_model)
        self.position_embedding = PositionalEmbedding(d_model=d_model)
        self.temporal_embedding = TemporalEmbedding(d_model=d_model,
            embed_type=embed_type, freq=freq
            ) if embed_type != 'timeF' else TimeFeatureEmbedding(d_model=
            d_model, embed_type=embed_type, freq=freq)
        self.dropout = nn.Dropout(p=dropout)

    def forward(self, input_0, input_1):
        primals_2 = self.value_embedding.tokenConv.weight
        primals_4 = self.temporal_embedding.hour_embed.emb.weight
        primals_5 = self.temporal_embedding.weekday_embed.emb.weight
        primals_6 = self.temporal_embedding.day_embed.emb.weight
        primals_7 = self.temporal_embedding.month_embed.emb.weight
        primals_1 = input_0
        primals_3 = input_1
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7])
        return output[0]


Measured latency_ms: 0.026993