KernelShift / solutions /simd-loop /baseline-simd-loop-sve /loop_114 /baseline-simd-loop-sve_loop_114.json
Download solutions/simd-loop/baseline-simd-loop-sve/loop_114/baseline-simd-loop-sve_loop_114.json from l3lab/KernelShift: direct link, hf CLI and curl.
- Browser
- Download file 6.34 kB
-
https://huggingface.co/datasets/l3lab/KernelShift/resolve/main/solutions/simd-loop/baseline-simd-loop-sve/loop_114/baseline-simd-loop-sve_loop_114.json
- Command line
-
hf download hf://datasets/l3lab/KernelShift/solutions/simd-loop/baseline-simd-loop-sve/loop_114/baseline-simd-loop-sve_loop_114.json
-
curl -L -o baseline-simd-loop-sve_loop_114.json https://huggingface.co/datasets/l3lab/KernelShift/resolve/main/solutions/simd-loop/baseline-simd-loop-sve/loop_114/baseline-simd-loop-sve_loop_114.json
6.34 kB
| { | |
| "name": "baseline-simd-loop-sve_loop_114", | |
| "definition": "loop_114", | |
| "dataset": "simd-loop", | |
| "author": "baseline-simd-loop-sve", | |
| "spec": { | |
| "language": "cpp", | |
| "target_hardware": [ | |
| "aarch64" | |
| ], | |
| "entry_point": "kernel.cpp::inner_loop_114", | |
| "dependencies": [], | |
| "isa_features": [ | |
| "sve" | |
| ], | |
| "compile_flags": [ | |
| "-O3", | |
| "-std=c++14", | |
| "-march=armv8.2-a+sve", | |
| "-Wno-c++11-narrowing" | |
| ], | |
| "link_flags": [] | |
| }, | |
| "sources": [ | |
| { | |
| "path": "loop_114.h", | |
| "content": "// Auto-generated by scripts/gen_simd_loop_harness.py \u2014 do not hand-edit.\n#pragma once\n#include <stdint.h>\n\nstruct loop_114_data {\n int16_t *data;\n int16_t *res;\n int32_t n;\n int32_t lags;\n int16_t scale;\n};\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\nint kernelshift_entry_loop_114(void *data, int64_t n, int64_t lags, int64_t scale, void *res_out);\n#ifdef __cplusplus\n}\n#endif\n" | |
| }, | |
| { | |
| "path": "loop_114.cpp", | |
| "content": "// Auto-generated by scripts/gen_simd_loop_harness.py \u2014 do not hand-edit.\n// Expert-baseline binding: pads edge-size workloads to the sizes Arm's kernel\n// supports (see _SVE_PAD_BINDINGS in the generator). Plain call otherwise.\n#include \"loop_114.h\"\n#include <stdint.h>\n#include <stdlib.h>\n#include <string.h>\n// Vector-length units for the padding rules below. Arm's kernel is built for\n// 128-bit SVE (Graviton3/4), so a build without SVE (the neon arm of an ISA\n// ablation lifts this binding too) pads to the same sizes with constants.\n#if defined(__ARM_FEATURE_SVE)\n#include <arm_sve.h>\n#define _VLW() ((uint64_t)svcntw())\n#define _VLH() ((uint64_t)svcnth())\n#else\n#define _VLW() ((uint64_t)4)\n#define _VLH() ((uint64_t)8)\n#endif\n\nextern \"C\" void inner_loop_114(struct loop_114_data *data);\n\nstatic inline uint64_t _round_up(uint64_t v, uint64_t m) { return (v + m - 1) / m * m; }\nstatic inline void *_zeroed(uint64_t bytes) { void *p = calloc(bytes ? bytes : 1, 1); if (!p) abort(); return p; }\n\nextern \"C\" int kernelshift_entry_loop_114(void *data, int64_t n_in, int64_t lags_in, int64_t scale, void *res_out) {\n const uint64_t n = (uint64_t)n_in, lags = (uint64_t)lags_in, vlh = _VLH();\n struct loop_114_data _kd;\n int16_t *pd = (int16_t *)_zeroed((n + lags + 2 * vlh) * sizeof(int16_t));\n int16_t *pr = (int16_t *)_zeroed((_round_up(lags, vlh) + vlh) * sizeof(int16_t));\n memcpy(pd, data, n * sizeof(int16_t));\n _kd.data = pd; _kd.res = pr; _kd.n = (int32_t)n; _kd.lags = (int32_t)lags; _kd.scale = (int16_t)scale;\n inner_loop_114(&_kd);\n memcpy(res_out, pr, lags * sizeof(int16_t));\n free(pd); free(pr);\n return 0;\n}\n" | |
| }, | |
| { | |
| "path": "kernel.cpp", | |
| "content": "#include \"loop_114.h\"\n#include <stdint.h>\n#include <string.h>\n#include <stdlib.h>\n#include <stdio.h>\n#include <limits.h>\n#include <assert.h>\n#include <math.h>\n#include <arm_sve.h>\n#define restrict __restrict\n#define SC_SVE_ATTR\n#define SC_SVE_LOOP_ATTR\n#define NS_SVE_LOOP_ATTR\n#define NOINLINE __attribute__((noinline))\n#define FOR_COND(P, S, I, N) svptest_first(svptrue_b##S(), P = svwhilelt_b##S(I, N))\n#define FOR_LOOP(T, I, M, N, P, S, W) for (T I = M; FOR_COND(P, S, I, N); I += svcnt##W())\n#define FOR_LOOP_8(T, I, M, N, P) FOR_LOOP(T, I, M, N, P, 8, b)\n#define FOR_LOOP_16(T, I, M, N, P) FOR_LOOP(T, I, M, N, P, 16, h)\n#define FOR_LOOP_32(T, I, M, N, P) FOR_LOOP(T, I, M, N, P, 32, w)\n#define FOR_LOOP_64(T, I, M, N, P) FOR_LOOP(T, I, M, N, P, 64, d)\nstatic inline uint32_t get_sve_vl(void) {\n uint64_t vl = 0; asm volatile(\"incb %[vl], all, mul #8\" : [vl] \"+r\"(vl) : :);\n return (uint32_t)vl;\n}\nstatic inline uint32_t get_vl(void) { return get_sve_vl(); }\n// common/helpers.h: 64-byte-aligned scratch. Only reached when the harness\n// hands a kernel a NULL scratch buffer (it never does \u2014 every scratch field is\n// bound), so a plain aligned malloc stands in for Arm's arena allocator.\nstatic inline void *alloc_64b(uint64_t size, const char *name) {\n void *p = NULL; (void)name;\n if (posix_memalign(&p, 64, size ? size : 64) != 0) abort();\n return p;\n}\n#define ALLOC_64B(P, S, N) P = (__typeof__(P))alloc_64b((S) * sizeof((P)[0]), N)\n\nextern \"C\" void inner_loop_114(struct loop_114_data * input)\n\n{\n int16_t * data = input->data;\n int16_t * res = input->res;\n int32_t n = input->n;\n int32_t lags = input->lags;\n int16_t scale = input->scale;\n int64_t step = get_sve_vl() / 16;\n for (int64_t lag = 0; lag < lags; lag += step) {\n int16_t *lmt = data + n;\n int16_t *p0 = data;\n int16_t *p1 = data + lag;\n int16_t *dst = res + lag;\n asm volatile(\n \" ptrue p0.b \\n\"\n \" whilelo p1.h, xzr, %x[lags] \\n\"\n \" dup z5.s, %w[scale] \\n\"\n \" mov z0.s, #0x0 \\n\"\n \" mov z1.s, #0x0 \\n\"\n \"1: ld1rh z2.h, p1/z, [%[p0]] \\n\"\n \" ld1h z3.h, p1/z, [%[p1]] \\n\"\n \" add %[p0], %[p0], #2 \\n\"\n \" add %[p1], %[p1], #2 \\n\"\n \" movprfx z4.h, p0/z, z3.h \\n\"\n \" mul z4.h, p0/m, z4.h, z2.h \\n\"\n \" smulh z3.h, p0/m, z3.h, z2.h \\n\"\n \" zip1 z2.h, z4.h, z3.h \\n\"\n \" zip2 z3.h, z4.h, z3.h \\n\"\n \" asr z2.s, p0/m, z2.s, z5.s \\n\"\n \" asr z3.s, p0/m, z3.s, z5.s \\n\"\n \" add z0.s, z2.s, z0.s \\n\"\n \" add z1.s, z3.s, z1.s \\n\"\n \" cmp %[p0], %[lmt] \\n\"\n \" b.ne 1b \\n\"\n \" uzp2 z0.h, z0.h, z1.h \\n\"\n \" st1h z0.h, p1, [%[dst]] \\n\"\n : [p0] \"+&r\"(p0), [p1] \"+&r\"(p1)\n : [scale] \"r\"(scale), [dst] \"r\"(dst), [lmt] \"r\"(lmt), [lags] \"r\"(lags)\n : \"v0\", \"v1\", \"v2\", \"v3\", \"v4\", \"v5\", \"p0\", \"p1\", \"memory\", \"cc\");\n }\n}\n#define DATA 256\n#define LAGS 64\n#define SCALE 3\n_Static_assert(LAGS % 8 == 0, \"LAGS must be a multiple of 8\");\n" | |
| } | |
| ], | |
| "description": "Arm hand-written SVE kernel for loop_114 (sve tier expert ceiling)." | |
| } | |