Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/gpu/amd/gfx942/fp8gemv/plain_ref_test.cpp # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / gpu / amd / gfx942 / fp8gemv / plain_ref_test.cpp` 105 lines ยท 3143 bytes Raw Blame History 1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 // Locks plain_ref.h to bit patterns check.om already accepts. A drift here 3 // fails check.sh before any device is involved. 4 5 #include "plain_ref.h" 6 7 #include 8 #include 9 #include 10 11 namespace { 12 13 int fails = 0; 14 15 void expect(const char* name, uint32_t got, uint32_t want) { 16 if (got == want) return; 17 std::fprintf(stderr, "FAIL %s got %08x want %08x\n", name, got, want); 18 fails += 1; 19 } 20 21 void expect_true(const char* name, bool ok) { 22 if (ok) return; 23 std::fprintf(stderr, "FAIL %s\n", name); 24 fails += 1; 25 } 26 27 } // namespace 28 29 int main() { 30 expect("fnuz 0x40", fnuz_bits(0x40), 0x3f800000u); 31 expect("fnuz 0x00", fnuz_bits(0x00), 0); 32 expect("fnuz 0x80", fnuz_bits(0x80), 0x7fc00000u); 33 expect("fnuz 0x01", fnuz_bits(0x01), 0x3a800000u); 34 expect("fnuz 0x81", fnuz_bits(0x81), 0xba800000u); 35 expect("fnuz 0xC0", fnuz_bits(0xc0), 0xbf800000u); 36 expect("fnuz 0xFF", fnuz_bits(0xff), 0xc3700000u); 37 expect("fnuz 0x7F", fnuz_bits(0x7f), 0x43700000u); 38 expect("i2f 1", i2f_bits(1), 0x3f800000u); 39 expect("i2f 17", i2f_bits(17), 0x41880000u); 40 expect("i2f 1026", i2f_bits(1026), 0x44804000u); 41 42 const uint32_t one = 0x3f800000u; 43 std::vector w(32, 0); 44 std::vector x(32, 0); 45 46 w[0] = 0x40; 47 x[0] = one; 48 expect("K=1", plain_row(w.data(), x.data(), 1, one).bits, 0x3f800000u); 49 50 for (int i = 0; i < 16; ++i) { 51 w[i] = 0x40; 52 x[i] = one; 53 } 54 expect("K=16", plain_row(w.data(), x.data(), 16, one).bits, 0x41800000u); 55 w[16] = 0x40; 56 x[16] = one; 57 expect("K=17", plain_row(w.data(), x.data(), 17, one).bits, 0x41880000u); 58 59 w.assign(32, 0); 60 x.assign(32, 0); 61 w[0] = 0xff; 62 x[0] = one; 63 expect("0xFF", plain_row(w.data(), x.data(), 1, one).bits, 0xc3700000u); 64 w[0] = 0x80; 65 expect("0x80", plain_row(w.data(), x.data(), 1, one).bits, 0x7fc00000u); 66 w[0] = 0x7f; 67 x[0] = 0x7c800000u; 68 expect("240*2^122", plain_row(w.data(), x.data(), 1, one).bits, 0x7f800000u); 69 70 w.assign(32, 0); 71 x.assign(32, 0); 72 w[0] = 0x40; 73 x[0] = 0x49800000u; 74 w[1] = 0x40; 75 x[1] = 0x3a800000u; 76 w[16] = 0xc0; 77 x[16] = 0x49800000u; 78 w[17] = 0x40; 79 x[17] = 0x3a800000u; 80 PlainRow cancel = plain_row(w.data(), x.data(), 32, one); 81 expect("cancel plain", cancel.bits, 0x3a800000u); 82 uint32_t bound = tolerance_bits(cancel.sumabs, 32, one, 0, cancel.bits); 83 expect_true("cancel kernel 0 is inside the bound", 84 within_plain(0, cancel.bits, bound)); 85 86 w.assign(1, 0x40); 87 x.assign(1, one); 88 PlainRow k1 = plain_row(w.data(), x.data(), 1, one); 89 uint32_t tight = tolerance_bits(k1.sumabs, 1, one, k1.bits, k1.bits); 90 expect_true("K=1 rejects a result of 0", 91 !within_plain(0, k1.bits, tight)); 92 expect_true("K=1 accepts itself", 93 within_plain(k1.bits, k1.bits, tight)); 94 expect_true("nonfinite mismatch fails", 95 !within_plain(0x7f800000u, 0x3f800000u, tight)); 96 expect_true("matching inf passes", 97 within_plain(0x7f800000u, 0x7f800000u, tight)); 98 99 if (fails) { 100 std::printf("FAIL\n"); 101 return 1; 102 } 103 std::printf("plain ref pass\n"); 104 return 0; 105 }