| 105 | bool same_float(float a, float b) { return std::memcmp(&a, &b, sizeof a) == 0 || (a == b) || (a != a && b != b); } |
| 106 | |
| 107 | bool check_dot(const DotKernel& k, std::string* why) { |
| 108 | const TypeInfo* ti = type_info(k.weight); |
| 109 | const TypeInfo* ai = type_info(k.act); |
| 110 | if (ti == nullptr || ai == nullptr) return false; |
| 111 | const int unit = ti->blck > ai->blck ? ti->blck : ai->blck; |
| 112 | const int counts[] = {1, 2, 3, 5}; |
| 113 | Rng r((uint64_t) k.weight * 1000 + 7); |
| 114 | for (int c : counts) { |
| 115 | const int n = unit * c; |
| 116 | for (int rep = 0; rep < 3; ++rep) { |
| 117 | const std::vector<uint8_t> w = make_weights(k.weight, n, r); |
| 118 | const std::vector<uint8_t> a = make_act(k.act, n, r); |
| 119 | float ref = 0.f, got = 0.f; |
| 120 | dot_ref(k.weight, n, &ref, w.data(), a.data()); |
| 121 | k.fn(n, &got, w.data(), a.data()); |
| 122 | if (!same_float(ref, got)) { |
| 123 | if (why) { |
| 124 | char buf[160]; |
| 125 | std::snprintf(buf, sizeof buf, "%s: n=%d reference %.9g (%08x) kernel %.9g (%08x)", k.name, n, ref, f32_to_bits(ref), got, |
| 126 | f32_to_bits(got)); |
| 127 | *why = buf; |
| 128 | } |
| 129 | return false; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | return true; |
| 134 | } |
| 135 | |
| 136 | bool check_act(const ActKernel& k, std::string* why) { |
| 137 | const TypeInfo* ti = type_info(k.act); |
no test coverage detected