MCPcopy Create free account
hub / github.com/KnowingNothing/MatmulTutorial / assert_allclose

Function assert_allclose

include/common.h:368–397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

366
367template <class DType>
368void assert_allclose(DType* res_ptr, DType* golden_ptr, std::vector<int> shape,
369 float rtol = 1e-5, bool dump = false) {
370 int errors = 0;
371 int length =
372 std::accumulate(shape.begin(), shape.end(), 1, std::multiplies<int>());
373 int row_size = shape[shape.size() - 1];
374 double total_diff = 0.0;
375 for (int i = 0; i < length; ++i) {
376 float r = (float)res_ptr[i];
377 float g = (float)golden_ptr[i];
378 assert(!std::isinf(r) && "Result value contains inf.");
379 assert(!std::isinf(g) && "Golden value contains inf.");
380 if (_abs(r - g) > rtol * _abs(g)) {
381 errors += 1;
382 total_diff += _abs(r - g);
383 }
384 if (dump) {
385 std::cout << "(" << r << " " << g << ") ";
386 if ((i + 1) % row_size == 0) {
387 std::cout << "\n";
388 }
389 }
390 }
391 if (errors > 0) {
392 std::cout << "Wrong answer! " << errors << " errors! "
393 << (float)errors / length * 100 << "%\n";
394 std::cout << "Average diff = " << total_diff / errors << "\n";
395 }
396 assert(errors == 0);
397}
398
399DEVICE uint32_t cast_smem_ptr_to_uint(void const* const ptr) {
400 return static_cast<uint32_t>(__cvta_generic_to_shared(ptr));

Callers

nothing calls this directly

Calls 1

_absFunction · 0.85

Tested by

no test coverage detected