ggml: add SWIGLU_CLAMP (#27930)

* ggml: add SWIGLU_CLAMP

* add vulkan shader
This commit is contained in:
Aman Gupta
2026-08-30 23:00:02 +08:00
committed by GitHub
parent 2578138397
commit 0190529ec4
40 changed files with 768 additions and 35 deletions
+26
View File
@@ -317,6 +317,32 @@ typedef decltype(kernel_swiglu_oai<float>) kernel_swiglu_oai_t;
template [[host_name("kernel_swiglu_oai_f32")]] kernel kernel_swiglu_oai_t kernel_swiglu_oai<float>;
template [[host_name("kernel_swiglu_oai_f16")]] kernel kernel_swiglu_oai_t kernel_swiglu_oai<half>;
template<typename T>
kernel void kernel_swiglu_clamp(
constant ggml_metal_kargs_glu & args,
device const char * src0,
device const char * src1,
device char * dst,
uint tgpig[[threadgroup_position_in_grid]],
uint tpitg[[thread_position_in_threadgroup]],
uint ntg[[threads_per_threadgroup]]) {
device const T * src0_row = (device const T *) ((device const char *) src0 + tgpig*args.nb01) + args.i00;
device const T * src1_row = (device const T *) ((device const char *) src1 + tgpig*args.nb11) + args.i10;
device T * dst_row = (device T *) ((device char *) dst + tgpig*args.nb1);
for (int i0 = tpitg; i0 < args.ne0; i0 += ntg) {
const float gate = min((float) src0_row[i0], args.limit);
const float up = clamp((float) src1_row[i0], -args.limit, args.limit);
dst_row[i0] = (T)(gate / (1.0f + exp(-gate)) * up);
}
}
typedef decltype(kernel_swiglu_clamp<float>) kernel_swiglu_clamp_t;
template [[host_name("kernel_swiglu_clamp_f32")]] kernel kernel_swiglu_clamp_t kernel_swiglu_clamp<float>;
template [[host_name("kernel_swiglu_clamp_f16")]] kernel kernel_swiglu_clamp_t kernel_swiglu_clamp<half>;
template<typename T>
kernel void kernel_geglu_erf(
constant ggml_metal_kargs_glu & args,