File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # RUN: %PYTHON %S/kernel_bench.py --input %s --dump-kernel xegpu-wg | FileCheck %s --implicit-check-not=memref.alloc --implicit-check-not=memref.copy --implicit-check-not=gpu.alloc
2+ # REQUIRES: torch, torch_mlir
3+
4+ """Llama 3.2 1B bias-free SwiGLU FFN, without normalization or residual.
5+
6+ The three GEMM kernels materialize activated gate and gated activations.
7+ SiLU is fused into gate projection; the multiply into up projection's
8+ epilogue. Down projection consumes the gated tensor without recomputing it.
9+ """
10+
11+ import torch
12+ import torch .nn as nn
13+ import torch .nn .functional as F
14+
15+
16+ batch_size = 4
17+ n_ctx = 512
18+ dim = 2048
19+ hidden_dim = 8192
20+
21+
22+ class Model (nn .Module ):
23+ def __init__ (self ):
24+ super ().__init__ ()
25+ self .gate_proj = nn .Linear (dim , hidden_dim , bias = False )
26+ self .up_proj = nn .Linear (dim , hidden_dim , bias = False )
27+ self .down_proj = nn .Linear (hidden_dim , dim , bias = False )
28+
29+ def forward (self , x : torch .Tensor ) -> torch .Tensor :
30+ return self .down_proj (F .silu (self .gate_proj (x )) * self .up_proj (x ))
31+
32+
33+ def get_inputs ():
34+ return [torch .randn (batch_size , n_ctx , dim )]
35+
36+
37+ def get_init_inputs ():
38+ return []
39+
40+
41+ # CHECK-COUNT-2: gpu.alloc
42+ # CHECK-NOT: gpu.alloc
43+ # CHECK: gpu.func @main_kernel
44+ # CHECK: xegpu.dpas
45+ # CHECK: math.exp
46+ # CHECK: xegpu.store_nd
47+ # CHECK: gpu.func @main_kernel
48+ # CHECK: xegpu.dpas
49+ # CHECK: arith.mulf
50+ # CHECK: xegpu.store_nd
51+ # CHECK: gpu.func @main_kernel
52+ # CHECK: xegpu.dpas
53+ # CHECK: xegpu.store_nd
54+ # CHECK-NOT: gpu.func
You can’t perform that action at this time.
0 commit comments