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

Function ggml_compute_forward_clamp_f32

ggml.c:11050–11088  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11048// ggml_compute_forward_clamp
11049
11050static void ggml_compute_forward_clamp_f32(
11051 const struct ggml_compute_params * params,
11052 const struct ggml_tensor * src0,
11053 struct ggml_tensor * dst) {
11054 assert(params->ith == 0);
11055
11056 if (params->type == GGML_TASK_INIT || params->type == GGML_TASK_FINALIZE) {
11057 return;
11058 }
11059
11060 float min;
11061 float max;
11062 memcpy(&min, (float *) dst->op_params + 0, sizeof(float));
11063 memcpy(&max, (float *) dst->op_params + 1, sizeof(float));
11064
11065 const int ith = params->ith;
11066 const int nth = params->nth;
11067
11068 const int n = ggml_nrows(src0);
11069 const int nc = src0->ne[0];
11070
11071 const size_t nb00 = src0->nb[0];
11072 const size_t nb01 = src0->nb[1];
11073
11074 const size_t nb0 = dst->nb[0];
11075 const size_t nb1 = dst->nb[1];
11076
11077 GGML_ASSERT( nb0 == sizeof(float));
11078 GGML_ASSERT(nb00 == sizeof(float));
11079
11080 for (int j = ith; j < n; j += nth) {
11081 float * dst_ptr = (float *) ((char *) dst->data + j*nb1);
11082 float * src0_ptr = (float *) ((char *) src0->data + j*nb01);
11083
11084 for (int i = 0; i < nc; i++) {
11085 dst_ptr[i] = MAX(MIN(src0_ptr[i], max), min);
11086 }
11087 }
11088}
11089
11090static void ggml_compute_forward_clamp(
11091 const struct ggml_compute_params * params,

Callers 1

Calls 1

ggml_nrowsFunction · 0.70

Tested by

no test coverage detected