MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / ggml_compute_forward_scale_f32

Function ggml_compute_forward_scale_f32

ggml.c:10094–10135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10092// ggml_compute_forward_scale
10093
10094static void ggml_compute_forward_scale_f32(
10095 const struct ggml_compute_params * params,
10096 const struct ggml_tensor * src0,
10097 const struct ggml_tensor * src1,
10098 struct ggml_tensor * dst) {
10099 GGML_ASSERT(ggml_is_contiguous(src0));
10100 GGML_ASSERT(ggml_is_contiguous(dst));
10101 GGML_ASSERT(ggml_are_same_shape(src0, dst));
10102 GGML_ASSERT(ggml_is_scalar(src1));
10103
10104 if (params->type == GGML_TASK_INIT || params->type == GGML_TASK_FINALIZE) {
10105 return;
10106 }
10107
10108 // scale factor
10109 const float v = *(float *) src1->data;
10110
10111 const int ith = params->ith;
10112 const int nth = params->nth;
10113
10114 const int nc = src0->ne[0];
10115 const int nr = ggml_nrows(src0);
10116
10117 // rows per thread
10118 const int dr = (nr + nth - 1)/nth;
10119
10120 // row range for this thread
10121 const int ir0 = dr*ith;
10122 const int ir1 = MIN(ir0 + dr, nr);
10123
10124 const size_t nb01 = src0->nb[1];
10125
10126 const size_t nb1 = dst->nb[1];
10127
10128 for (int i1 = ir0; i1 < ir1; i1++) {
10129 if (dst->data != src0->data) {
10130 // src0 is same shape as dst => same indices
10131 memcpy((char *)dst->data + i1*nb1, (char *)src0->data + i1*nb01, nc * sizeof(float));
10132 }
10133 ggml_vec_scale_f32(nc, (float *) ((char *) dst->data + i1*nb1), v);
10134 }
10135}
10136
10137static void ggml_compute_forward_scale(
10138 const struct ggml_compute_params * params,

Callers 1

Calls 5

ggml_is_contiguousFunction · 0.70
ggml_are_same_shapeFunction · 0.70
ggml_is_scalarFunction · 0.70
ggml_nrowsFunction · 0.70
ggml_vec_scale_f32Function · 0.70

Tested by

no test coverage detected