Spaces:
Runtime error
Runtime error
Upload llama.cpp/ggml/src/ggml-cuda/scale.cu with huggingface_hub
Browse files
llama.cpp/ggml/src/ggml-cuda/scale.cu
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "scale.cuh"
|
| 2 |
+
|
| 3 |
+
static __global__ void scale_f32(const float * x, float * dst, const float scale, const int k) {
|
| 4 |
+
const int i = blockDim.x*blockIdx.x + threadIdx.x;
|
| 5 |
+
|
| 6 |
+
if (i >= k) {
|
| 7 |
+
return;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
dst[i] = scale * x[i];
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
static void scale_f32_cuda(const float * x, float * dst, const float scale, const int k, cudaStream_t stream) {
|
| 14 |
+
const int num_blocks = (k + CUDA_SCALE_BLOCK_SIZE - 1) / CUDA_SCALE_BLOCK_SIZE;
|
| 15 |
+
scale_f32<<<num_blocks, CUDA_SCALE_BLOCK_SIZE, 0, stream>>>(x, dst, scale, k);
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
void ggml_cuda_op_scale(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
| 19 |
+
const ggml_tensor * src0 = dst->src[0];
|
| 20 |
+
const float * src0_d = (const float *)src0->data;
|
| 21 |
+
float * dst_d = (float *)dst->data;
|
| 22 |
+
cudaStream_t stream = ctx.stream();
|
| 23 |
+
|
| 24 |
+
GGML_ASSERT(src0->type == GGML_TYPE_F32);
|
| 25 |
+
GGML_ASSERT( dst->type == GGML_TYPE_F32);
|
| 26 |
+
|
| 27 |
+
float scale;
|
| 28 |
+
memcpy(&scale, dst->op_params, sizeof(float));
|
| 29 |
+
|
| 30 |
+
scale_f32_cuda(src0_d, dst_d, scale, ggml_nelements(src0), stream);
|
| 31 |
+
}
|