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

Function ggml_compute_forward_set_f32

ggml.c:10156–10224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10154// ggml_compute_forward_set
10155
10156static void ggml_compute_forward_set_f32(
10157 const struct ggml_compute_params * params,
10158 const struct ggml_tensor * src0,
10159 const struct ggml_tensor * src1,
10160 struct ggml_tensor * dst) {
10161 GGML_ASSERT(ggml_are_same_shape(src0, dst));
10162 GGML_ASSERT(ggml_is_contiguous(dst) && ggml_is_contiguous(src0));
10163
10164 // view src0 and dst with these strides and data offset inbytes during set
10165 // nb0 is implicitely element_size because src0 and dst are contiguous
10166 size_t nb1 = ((int32_t *) dst->op_params)[0];
10167 size_t nb2 = ((int32_t *) dst->op_params)[1];
10168 size_t nb3 = ((int32_t *) dst->op_params)[2];
10169 size_t offset = ((int32_t *) dst->op_params)[3];
10170 bool inplace = (bool) ((int32_t *) dst->op_params)[4];
10171
10172 if (!inplace && (params->type == GGML_TASK_INIT)) {
10173 // memcpy needs to be synchronized across threads to avoid race conditions.
10174 // => do it in INIT phase
10175 memcpy(
10176 ((char *) dst->data),
10177 ((char *) src0->data),
10178 ggml_nbytes(dst));
10179 }
10180
10181 if (params->type == GGML_TASK_INIT || params->type == GGML_TASK_FINALIZE) {
10182 return;
10183 }
10184
10185 const int ith = params->ith;
10186 const int nth = params->nth;
10187
10188 const int nr = ggml_nrows(src1);
10189 const int nc = src1->ne[0];
10190
10191 GGML_TENSOR_LOCALS(int64_t, ne1, src1, ne)
10192 GGML_TENSOR_LOCALS(size_t, nb1, src1, nb)
10193
10194 // src0 and dst as viewed during set
10195 const size_t nb0 = ggml_element_size(src0);
10196
10197 const int im0 = (ne10 == 0 ? 0 : ne10-1);
10198 const int im1 = (ne11 == 0 ? 0 : ne11-1);
10199 const int im2 = (ne12 == 0 ? 0 : ne12-1);
10200 const int im3 = (ne13 == 0 ? 0 : ne13-1);
10201
10202 GGML_ASSERT(offset + im0*nb0 + im1*nb1 + im2*nb2 + im3*nb3 <= ggml_nbytes(dst));
10203
10204 GGML_ASSERT(nb10 == sizeof(float));
10205
10206 // rows per thread
10207 const int dr = (nr + nth - 1)/nth;
10208
10209 // row range for this thread
10210 const int ir0 = dr*ith;
10211 const int ir1 = MIN(ir0 + dr, nr);
10212
10213 for (int ir = ir0; ir < ir1; ++ir) {

Callers 1

ggml_compute_forward_setFunction · 0.70

Calls 6

ggml_are_same_shapeFunction · 0.70
ggml_is_contiguousFunction · 0.70
ggml_nbytesFunction · 0.70
ggml_nrowsFunction · 0.70
ggml_element_sizeFunction · 0.70
ggml_vec_cpy_f32Function · 0.70

Tested by

no test coverage detected