spark_model/layers/ops/
ple.rs1use anyhow::Result;
7use spark_runtime::gpu::{DevicePtr, GpuBackend, KernelHandle};
8use spark_runtime::kernel_args::KernelLaunch;
9
10#[allow(clippy::too_many_arguments)]
18pub fn ple_gate(
19 gpu: &dyn GpuBackend,
20 kernel: KernelHandle,
21 hidden: DevicePtr,
22 key: DevicePtr,
23 value: DevicePtr,
24 norm_query_w: DevicePtr,
25 norm_key_w: DevicePtr,
26 norm_conv_w: DevicePtr,
27 gated_out: DevicePtr,
28 gated_normed: DevicePtr,
29 num_tokens: u32,
30 hidden_size: u32,
31 hc_mult: u32,
32 norm_eps: f32,
33 stream: u64,
34) -> Result<()> {
35 KernelLaunch::new(gpu, kernel)
36 .grid([num_tokens, 1, 1])
37 .block([256, 1, 1])
38 .arg_ptr(hidden)
39 .arg_ptr(key)
40 .arg_ptr(value)
41 .arg_ptr(norm_query_w)
42 .arg_ptr(norm_key_w)
43 .arg_ptr(norm_conv_w)
44 .arg_ptr(gated_out)
45 .arg_ptr(gated_normed)
46 .arg_u32(hidden_size)
47 .arg_u32(hc_mult)
48 .arg_f32(norm_eps)
49 .launch(stream)
50}
51
52#[allow(clippy::too_many_arguments)]
60pub fn ple_conv(
61 gpu: &dyn GpuBackend,
62 kernel: KernelHandle,
63 x: DevicePtr,
64 gated: DevicePtr,
65 weight: DevicePtr,
66 state: DevicePtr,
67 out: DevicePtr,
68 num_tokens: u32,
69 channels: u32,
70 k_size: u32,
71 dilation: u32,
72 stream: u64,
73) -> Result<()> {
74 let threads = 256u32;
75 KernelLaunch::new(gpu, kernel)
76 .grid([channels.div_ceil(threads), 1, 1])
77 .block([threads, 1, 1])
78 .arg_ptr(x)
79 .arg_ptr(gated)
80 .arg_ptr(weight)
81 .arg_ptr(state)
82 .arg_ptr(out)
83 .arg_u32(num_tokens)
84 .arg_u32(channels)
85 .arg_u32(k_size)
86 .arg_u32(dilation)
87 .launch(stream)
88}
89
90pub fn ple_add_highway(
93 gpu: &dyn GpuBackend,
94 kernel: KernelHandle,
95 ple_out: DevicePtr,
96 hidden: DevicePtr,
97 n: u32,
98 stream: u64,
99) -> Result<()> {
100 let threads = 256u32;
101 KernelLaunch::new(gpu, kernel)
102 .grid([n.div_ceil(threads), 1, 1])
103 .block([threads, 1, 1])
104 .arg_ptr(ple_out)
105 .arg_ptr(hidden)
106 .arg_u32(n)
107 .launch(stream)
108}