Download ravager3-android-arm64.patch from wraith1337/ravager3-android-arm64: direct link, hf CLI and curl.
- Browser
- Download file 4.59 kB
-
https://huggingface.co/wraith1337/ravager3-android-arm64/resolve/main/ravager3-android-arm64.patch
- Command line
-
hf download hf://wraith1337/ravager3-android-arm64/ravager3-android-arm64.patch
-
curl -L -o ravager3-android-arm64.patch https://huggingface.co/wraith1337/ravager3-android-arm64/resolve/main/ravager3-android-arm64.patch
4.59 kB
| diff --git a/nnue/inference.c b/nnue/inference.c | |
| index 53094b0..982eda7 100644 | |
| --- a/nnue/inference.c | |
| +++ b/nnue/inference.c | |
| #define _GNU_SOURCE | |
| #include "inference.h" | |
| #include "bitboard.h" | |
| +#if defined(__x86_64__) || defined(__i386__) | |
| #include <immintrin.h> | |
| +#define RV_X86 1 | |
| +#endif | |
| #include <assert.h> | |
| #include <stdlib.h> | |
| #include <math.h> | |
| typedef struct { | |
| static _Thread_local Frame frames[FRAMES]; | |
| static _Thread_local CacheEntry bucket_cache[2][32]; | |
| static _Thread_local int base_ply; | |
| +#ifdef __ANDROID__ | |
| +/* Android arm64 (Bionic) refuses executables whose TLS segment is aligned below 64 bytes. */ | |
| +__attribute__((used)) static _Thread_local _Alignas(64) char rv_tls_align_pad[64]; | |
| +#endif | |
| static _Thread_local uint64_t seen_old[(AUX + 63) / 64], seen_new[(AUX + 63) / 64]; | |
| static uint16_t square_offset[12][64], piece_span[12]; | |
| static inline void prefetch_rows(const char *base, size_t rowbytes, const RowOps | |
| for (int r = 0; r < o->nsub; r++) { const char *q = base + (size_t)o->sub[r] * rowbytes + off; for (size_t k = 0; k < span; k += 64) __builtin_prefetch(q + k, 0, 3); } | |
| } | |
| +#ifdef RV_X86 | |
| __attribute__((target("avx2"))) | |
| static void psqt_rows_avx2(int16_t *dst, const int16_t *src, const RowOps *o) { | |
| prefetch_rows((const char *)pw, WIDTH * 2, o, 0, 256); | |
| static void aux_rows_avx512(int16_t *dst, const int16_t *src, const RowOps *o) { | |
| } | |
| } | |
| +#endif | |
| + | |
| static void (*psqt_rows)(int16_t *, const int16_t *, const RowOps *) = psqt_rows_scalar; | |
| static void (*aux_rows)(int16_t *, const int16_t *, const RowOps *) = aux_rows_scalar; | |
| +#ifdef RV_X86 | |
| static uint64_t square_diff(const uint8_t *x, const uint8_t *y) { | |
| uint64_t m = 0; | |
| for (int i = 0; i < 4; i++) { | |
| static uint64_t square_diff(const uint8_t *x, const uint8_t *y) { | |
| return m; | |
| } | |
| +#else | |
| +static uint64_t square_diff(const uint8_t *x, const uint8_t *y) { | |
| + uint64_t m = 0; | |
| + for (int i = 0; i < 64; i++) m |= (uint64_t)(x[i] != y[i]) << i; | |
| + return m; | |
| +} | |
| +#endif | |
| + | |
| /* Piece-square accumulator from scratch (verification and fresh frames). */ | |
| static void psqt_scratch(Frame *f, int p) { | |
| uint32_t add[32]; | |
| static int finish_scalar(const int32_t *s, int bucket) { | |
| return (int)(y * 240.0f); | |
| } | |
| +#ifdef RV_X86 | |
| /* Eight-lane float head; the FMA order matches finish_scalar exactly. */ | |
| __attribute__((target("avx2,fma"))) | |
| static int finish_avx2(const int32_t *s, int bucket) { | |
| static int finish_avx2(const int32_t *s, int bucket) { | |
| return (int)((_mm_cvtss_f32(t) + b3[bucket]) * 240.0f); | |
| } | |
| +#endif | |
| + | |
| static inline int output_bucket(const Board *b) { return (popcount(b->occ_all) - 2) / 4; } | |
| /* Pairwise CReLU product of the summed accumulators, stm half first. */ | |
| static void activate_scalar(const Frame *f, const Board *b, uint8_t *x) { | |
| } | |
| } | |
| +#ifdef RV_X86 | |
| __attribute__((target("avx2"))) | |
| static void activate_avx2(const Frame *f, const Board *b, uint8_t *x) { | |
| const __m256i zero = _mm256_setzero_si256(), cap = _mm256_set1_epi16(255); | |
| static void activate_avx2(const Frame *f, const Board *b, uint8_t *x) { | |
| } | |
| } | |
| +#endif | |
| + | |
| static int forward_scalar(const Frame *f, const Board *b) { | |
| uint8_t x[WIDTH]; | |
| activate_scalar(f, b, x); | |
| static int forward_scalar(const Frame *f, const Board *b) { | |
| return finish_scalar(s, bucket); | |
| } | |
| +#ifdef RV_X86 | |
| /* Indices of the 4-byte input groups with any nonzero byte, ascending. */ | |
| __attribute__((target("avx2"))) | |
| static inline int nonzero_groups(const uint8_t *x, uint16_t *idx) { | |
| static int forward_vnni(const Frame *f, const Board *b) { | |
| return finish_avx2(sums, bucket); | |
| } | |
| +#endif | |
| + | |
| static int (*forward)(const Frame *, const Board *) = forward_scalar; | |
| /* ---- loading ---- */ | |
| bool net_load(const unsigned char *bytes, size_t count) { | |
| aux_rows = aux_rows_scalar; | |
| forward = forward_scalar; | |
| net_tier = "scalar"; | |
| +#ifdef RV_X86 | |
| if (__builtin_cpu_supports("avx2") && __builtin_cpu_supports("fma")) { | |
| psqt_rows = psqt_rows_avx2; | |
| aux_rows = aux_rows_avx2; | |
| bool net_load(const unsigned char *bytes, size_t count) { | |
| net_tier = "avx512"; | |
| if (__builtin_cpu_supports("avx512vnni")) { forward = forward_vnni; net_tier = "avx512-vnni"; } | |
| } | |
| +#endif | |
| for (int i = 0; i < FRAMES; i++) frames[i].ready = false; | |
| return true; | |
| } | |