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

Function row_dot_multi

engine/src/kernels/cpu/expert.cpp:233–255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231/// accumulator sees exactly the operations `row_dot` would apply to it, in the same order.
232template<int NT>
233inline void row_dot_multi(const uint8_t* codes, const uint8_t* scales, const ActQ* const* a, int nblocks,
234 float* res) {
235 if (kZmm) { row_dot_multi_z<NT>(codes, scales, a, nblocks, res); return; }
236 __m256 acc[NT];
237 float corr[NT];
238 for (int t = 0; t < NT; ++t) { acc[t] = _mm256_setzero_ps(); corr[t] = 0.f; }
239 for (int b = 0; b < nblocks; ++b) {
240 const float d = h2f(scales + 2 * b);
241 const __m256i lo = unpack_q2_0(codes + b * 16);
242 const __m256i hi = unpack_q2_0(codes + b * 16 + 8);
243 for (int t = 0; t < NT; ++t) {
244 const __m256 slo = _mm256_cvtepi32_ps(
245 _mm256_dpbusd_epi32(_mm256_setzero_si256(), lo, _mm256_load_si256((const __m256i*) (a[t]->q + b * QK))));
246 const __m256 shi = _mm256_cvtepi32_ps(
247 _mm256_dpbusd_epi32(_mm256_setzero_si256(), hi,
248 _mm256_load_si256((const __m256i*) (a[t]->q + b * QK + QKA))));
249 acc[t] = _mm256_fmadd_ps(_mm256_set1_ps(d * a[t]->scale[2 * b]), slo, acc[t]);
250 acc[t] = _mm256_fmadd_ps(_mm256_set1_ps(d * a[t]->scale[2 * b + 1]), shi, acc[t]);
251 corr[t] += d * (a[t]->hx[2 * b] + a[t]->hx[2 * b + 1]);
252 }
253 }
254 for (int t = 0; t < NT; ++t) res[t] = hsum_ps(acc[t]) - corr[t];
255}
256
257template<int NT>
258void expert_multi(const uint8_t* blob, const ActQ* const* a1, float* const* out, ExpertScratchMulti& ws) {

Callers

nothing calls this directly

Calls 3

unpack_q2_0Function · 0.85
hsum_psFunction · 0.85
h2fFunction · 0.70

Tested by

no test coverage detected