char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
e94722822
char/aliceai-t5-moe
1#include "softcap.cuh" 2 3static __global__ void softcap_f32(const float * x, float * dst, const float scale, const float softcap, const int k) { 4 ggml_cuda_pdl_lc(); 5 const int i = blockDim.x*blockIdx.x + threadIdx.x; 6 7 if (i >= k) { 8 return; 9 } 10 11 ggml_cuda_pdl_sync(); 12 dst[i] = tanhf(scale * x[i]) * softcap; 13} 14 15static void softcap_f32_cuda(const float * x, float * dst, const float scale, const float softcap, const int k, cudaStream_t stream) { 16 const int num_blocks = (k + CUDA_SOFTCAP_BLOCK_SIZE - 1) / CUDA_SOFTCAP_BLOCK_SIZE; 17 const ggml_cuda_kernel_launch_params launch_params = ggml_cuda_kernel_launch_params(num_blocks, CUDA_SOFTCAP_BLOCK_SIZE, 0, stream); 18 ggml_cuda_kernel_launch(softcap_f32, launch_params, x, dst, scale, softcap, k); 19} 20 21// fused GGML_OP_SCALE + GGML_UNARY_OP_TANH + GGML_OP_SCALE 22void ggml_cuda_op_softcap(ggml_backend_cuda_context & ctx, ggml_tensor * dst, ggml_tensor * src) { 23 const ggml_tensor * src0 = src->src[0]; 24 const float * src0_d = (const float *)src0->data; 25 float * dst_d = (float *)dst->data; 26 cudaStream_t stream = ctx.stream(); 27 28 GGML_ASSERT(src0->type == GGML_TYPE_F32); 29 GGML_ASSERT( dst->type == GGML_TYPE_F32); 30 31 float scale; 32 float softcap; 33 memcpy(&scale, (float *) src->op_params + 0, sizeof(float)); 34 memcpy(&softcap, (float *) dst->op_params + 0, sizeof(float)); 35 36 softcap_f32_cuda(src0_d, dst_d, scale, softcap, ggml_nelements(src0), stream); 37}