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

Function check_mat_mul

tests/test-grad0.cpp:296–353  ·  view source on GitHub ↗

TODO: clean-up this ..

Source from the content-addressed store, hash-verified

294
295// TODO: clean-up this ..
296static bool check_mat_mul(
297 const struct ggml_tensor * y,
298 const struct ggml_tensor * x0,
299 const struct ggml_tensor * x1) {
300 float * dst = (float *) y->data;
301 float * src0 = (float *) x0->data;
302 float * src1 = (float *) x1->data;
303
304 const int nc = x0->ne[1];
305 const int nr = x1->ne[1];
306 const int nk = x0->ne[0];
307
308 GGML_PRINT_DEBUG("check_mat_mul: nc=%d, nr=%d, nk=%d\n", nc, nr, nk);
309
310 GGML_PRINT_DEBUG("x0:\n");
311 for (int j = 0; j < x0->ne[1]; ++j) {
312 for (int i = 0; i < x0->ne[0]; ++i) {
313 GGML_PRINT_DEBUG("%6.3f ", src0[j*nk + i]);
314 }
315 GGML_PRINT_DEBUG("\n");
316 }
317 GGML_PRINT_DEBUG("\n");
318
319 GGML_PRINT_DEBUG("x1:\n");
320 for (int j = 0; j < x1->ne[1]; ++j) {
321 for (int i = 0; i < x1->ne[0]; ++i) {
322 GGML_PRINT_DEBUG("%6.3f ", src1[j*nk + i]);
323 }
324 GGML_PRINT_DEBUG("\n");
325 }
326 GGML_PRINT_DEBUG("\n");
327
328 GGML_PRINT_DEBUG("y: n_dims = %d, (%lld, %lld)\n", y->n_dims, y->ne[0], y->ne[1]);
329 for (int j = 0; j < y->ne[1]; ++j) {
330 for (int i = 0; i < y->ne[0]; ++i) {
331 GGML_PRINT_DEBUG("%6.3f ", dst[j*nr + i]);
332 }
333 GGML_PRINT_DEBUG("\n");
334 }
335
336 for (int i = 0; i < nr; ++i) {
337 for (int j = 0; j < nc; ++j) {
338 float sum = 0.0f;
339
340 for (int k = 0; k < nk; ++k) {
341 sum += src0[j*nk + k]*src1[i*nk + k];
342 }
343
344 if (fabsf(dst[i*nc + j] - sum) > 1e-5f) {
345 fprintf(stderr, "check_mat_mul: dst[%d] = %f, sum = %f\n", i*nc + j, dst[i*nc + j], sum);
346 assert(false);
347 return false;
348 }
349 }
350 }
351
352 return true;
353}

Callers 1

mainFunction · 0.85

Calls 1

fprintfFunction · 0.85

Tested by

no test coverage detected