okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-own-2n (ead5a32ae) into f-own-int: the Arm NEON tier of the quant layer0a9381336

main
1.3 KiB37 linesraw
1// src/quant/arm/tier_common.hpp - what the Arm tier files of the layer need before they include ggml's ported NEON code (arm_dots.inc, arm_act.inc).
2//
3// dot_neon.cpp and act_neon.cpp are compiled with the flavour ggml-cpu ships on arm64 (cmake/backends/quant.cmake): armv8.2-a + dotprod + fp16 + i8mm, no SVE
4// (the DGX Spark's STRATA_PORTABLE build; the Mac's native build has the same features and no SVE).  Never include this header from a file compiled without them.
5#pragma once
6
7#define STRATA_QUANT_TABLES
8#include "../internal.hpp"
9
10#include <arm_neon.h>
11
12#include <cassert>
13#include <cstdlib>
14
15#if !defined(__ARM_NEON) || !defined(__ARM_FEATURE_DOTPROD)
16#error "the Arm tier needs NEON and the dot product extension (armv8.2-a+dotprod)"
17#endif
18#if defined(__ARM_FEATURE_SVE)
19#error "the Arm tier is the no-SVE flavour of ggml-cpu: compile it without SVE (-march=armv8.2-a+dotprod+fp16+i8mm)"
20#endif
21
22#define UNUSED(x) (void) (x)
23
24// ggml's own choice on arm64: the hardware conversions through __fp16 (the same values as the software ones for every finite input).
25namespace strata::quant {
26inline float h2f(uint16_t h) {
27    __fp16 t;
28    std::memcpy(&t, &h, sizeof t);
29    return (float) t;
30}
31inline uint16_t f2h(float f) {
32    const __fp16 t = f;
33    uint16_t r;
34    std::memcpy(&r, &t, sizeof r);
35    return r;
36}
37}  // namespace strata::quant