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

Function check_dot

engine/src/quant/selfcheck.cpp:107–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105bool same_float(float a, float b) { return std::memcmp(&a, &b, sizeof a) == 0 || (a == b) || (a != a && b != b); }
106
107bool 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
136bool check_act(const ActKernel& k, std::string* why) {
137 const TypeInfo* ti = type_info(k.act);

Callers 2

selfcheckFunction · 0.85
checked_dot_kernelFunction · 0.85

Calls 7

dot_refFunction · 0.85
f32_to_bitsFunction · 0.85
type_infoFunction · 0.70
make_weightsFunction · 0.70
make_actFunction · 0.70
same_floatFunction · 0.70
dataMethod · 0.45

Tested by

no test coverage detected