MCPcopy Create free account
hub / github.com/Niko1221/Strata / test_fp16

Function test_fp16

engine/tests/quant/quant_parity.cpp:596–627  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

594}
595
596void test_fp16() {
597 // our software fp16 conversions against ggml's, every fp16 value and a spread of floats (one group, two rows: the two directions)
598 Group& g = open_group("fp16", "fp16", 0);
599 int bad = 0;
600 uint64_t h = kFnvBasis;
601 for (uint32_t hv = 0; hv < 65536; ++hv) {
602 const uint16_t u = (uint16_t) hv;
603 const float a = ggml_fp16_to_fp32((ggml_fp16_t) u);
604 const float b = sq::fp16_to_fp32(u);
605 g.in = golden_fnv1a64(&u, 2, g.in);
606 g.ref = golden_fnv1a64(&a, 4, g.ref);
607 h = golden_fnv1a64(&b, 4, h);
608 if (std::isnan(a) ? !std::isnan(b) : !bits_equal(a, b)) ++bad;
609 }
610 ++g.rows;
611 Rng r(5);
612 for (int i = 0; i < 4000000; ++i) {
613 uint32_t w = r.next();
614 float f;
615 std::memcpy(&f, &w, 4);
616 if (std::isnan(f)) continue;
617 const uint16_t a = ggml_fp32_to_fp16(f), b = sq::fp32_to_fp16(f);
618 g.in = golden_fnv1a64(&f, 4, g.in);
619 g.ref = golden_fnv1a64(&a, 2, g.ref);
620 h = golden_fnv1a64(&b, 2, h);
621 if (a != b) ++bad;
622 }
623 ++g.rows;
624 ++g_checked;
625 if (bad) live_diff("fp16", std::to_string(bad) + " conversions differ from ggml's");
626 close_group(g, {{"fp16", h}});
627}
628
629std::string golden_lines_of_this_run() {
630 std::string s;

Callers 1

mainFunction · 0.85

Calls 11

ggml_fp16_to_fp32Function · 0.85
golden_fnv1a64Function · 0.85
bits_equalFunction · 0.85
memcpyFunction · 0.85
fp32_to_fp16Function · 0.85
live_diffFunction · 0.85
close_groupFunction · 0.85
fp16_to_fp32Function · 0.50
isnanFunction · 0.50
to_stringFunction · 0.50
nextMethod · 0.45

Tested by

no test coverage detected