KernelShift / solutions /simd-loop /baseline-simd-loop-sve2 /loop_123 /baseline-simd-loop-sve2_loop_123.json
Download solutions/simd-loop/baseline-simd-loop-sve2/loop_123/baseline-simd-loop-sve2_loop_123.json from l3lab/KernelShift: direct link, hf CLI and curl.
- Browser
- Download file 24.1 kB
-
https://huggingface.co/datasets/l3lab/KernelShift/resolve/main/solutions/simd-loop/baseline-simd-loop-sve2/loop_123/baseline-simd-loop-sve2_loop_123.json
- Command line
-
hf download hf://datasets/l3lab/KernelShift/solutions/simd-loop/baseline-simd-loop-sve2/loop_123/baseline-simd-loop-sve2_loop_123.json
-
curl -L -o baseline-simd-loop-sve2_loop_123.json https://huggingface.co/datasets/l3lab/KernelShift/resolve/main/solutions/simd-loop/baseline-simd-loop-sve2/loop_123/baseline-simd-loop-sve2_loop_123.json
24.1 kB
| { | |
| "name": "baseline-simd-loop-sve2_loop_123", | |
| "definition": "loop_123", | |
| "dataset": "simd-loop", | |
| "author": "baseline-simd-loop-sve2", | |
| "spec": { | |
| "language": "cpp", | |
| "target_hardware": [ | |
| "aarch64" | |
| ], | |
| "entry_point": "kernel.cpp::inner_loop_123", | |
| "dependencies": [], | |
| "isa_features": [ | |
| "sve2" | |
| ], | |
| "compile_flags": [ | |
| "-O3", | |
| "-std=c++14", | |
| "-march=native", | |
| "-Wno-c++11-narrowing" | |
| ], | |
| "link_flags": [] | |
| }, | |
| "sources": [ | |
| { | |
| "path": "loop_123.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_123_data {\n int32_t *data;\n int32_t *temp;\n uint32_t *block_sizes;\n uint32_t n;\n};\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\nint kernelshift_entry_loop_123(void *data, void *temp, void *block_sizes, int64_t n, void *unused);\n#ifdef __cplusplus\n}\n#endif\n" | |
| }, | |
| { | |
| "path": "loop_123.cpp", | |
| "content": "// Auto-generated by scripts/gen_simd_loop_harness.py \u2014 do not hand-edit.\n#include \"loop_123.h\"\n#include <stdint.h>\n\nextern \"C\" void inner_loop_123(struct loop_123_data *data);\n\nextern \"C\" int kernelshift_entry_loop_123(void *data, void *temp, void *block_sizes, int64_t n, void *unused) {\n struct loop_123_data d;\n d.n = static_cast<uint32_t>(n);\n d.data = static_cast<int32_t *>(data);\n d.temp = static_cast<int32_t *>(temp);\n d.block_sizes = static_cast<uint32_t *>(block_sizes);\n inner_loop_123(&d);\n return 0;\n}\n" | |
| }, | |
| { | |
| "path": "kernel.cpp", | |
| "content": "#include \"loop_123.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\n#define SORT_H_ \n#define IS_NOT_POWER_OF_2(v) (((v) & ((v)-1)) && (v))\ninline uint32_t mylog2_32(uint32_t val) {\n uint32_t ret = -1;\n while (val != 0) {\n val >>= 1;\n ret++;\n }\n return ret;\n}\ninline uint32_t min2_32u(uint32_t a, uint32_t b) {\n uint32_t result;\n asm(\"cmp %w1, %w2 ; csel %w0, %w1, %w2, lo\" : \"=r\"(result) : \"r\"(a), \"r\"(b));\n return result;\n}\ninline uint32_t max2_32u(uint32_t a, uint32_t b) {\n uint32_t result;\n asm(\"cmp %w1, %w2 ; csel %w0, %w1, %w2, hi\" : \"=r\"(result) : \"r\"(a), \"r\"(b));\n return result;\n}\ninline uint32_t upper_power_of_two_32u(uint32_t v) {\n v--;\n v |= v >> 1;\n v |= v >> 2;\n v |= v >> 4;\n v |= v >> 8;\n v |= v >> 16;\n v++;\n return v;\n}\n#define SWAP_DECL(NAME,TYPE) void NAME(TYPE *a, TYPE *b) { TYPE c; c = *a; *a = *b; *b = c; }\ninline SWAP_DECL(swap_32, int32_t);\ninline int check_sorted(uint32_t n, int32_t *v) {\n int r = 0;\n for (uint32_t i = 1; i < n; i++) r += (int)(v[i] < v[i - 1]);\n return r;\n}\nvoid com_sort_oet(uint32_t, int32_t *, uint32_t);\nvoid com_sort_insertion(uint32_t, int32_t *);\nvoid com_sort_radix(uint32_t, int32_t *, int32_t *);\ntypedef struct {\n uint32_t bits;\n int32_t offset;\n} radix_t;\nradix_t find_radix_sub_offset(uint32_t, int32_t *);\nvoid post_add_offset(uint32_t, int32_t *, int32_t);\nvoid com_sort_oet(uint32_t n, int32_t * data, uint32_t partition) {\n uint32_t k = n - 1;\n for (uint32_t i = 0; i < partition; i++) {\n for (uint32_t j = i % 2; j < k; j += 2 * svcntw()) {\n svbool_t p_loop = svwhilelt_b32(0u, (n - j) / 2);\n svint32x2_t a01 = svld2(p_loop, data + j);\n svint32_t a0 = svget2(a01, 0);\n svint32_t a1 = svget2(a01, 1);\n svbool_t p_comp = svcmplt(p_loop, a0, a1);\n svint32_t b0 = svsel(p_comp, a0, a1);\n svint32_t b1 = svsel(p_comp, a1, a0);\n svst2(p_loop, data + j, svcreate2(b0, b1));\n }\n }\n}\nvoid com_sort_insertion(uint32_t n, int32_t * data) {\n uint32_t i, j;\n for (i = 1; i < n; i++) {\n int32_t tmp = data[i];\n for (j = i; j > 0 && data[j - 1] > tmp; j--) {\n data[j] = data[j - 1];\n }\n data[j] = tmp;\n }\n}\nvoid com_sort_radix(uint32_t n, int32_t * data,\n int32_t * temp) {\n int32_t min = data[0];\n int32_t max = data[0];\n for (uint32_t i = 1; i < n; i++) {\n min = (min < data[i]) ? min : data[i];\n max = (max > data[i]) ? max : data[i];\n }\n for (uint32_t i = 0; i < n; i++) data[i] -= min;\n uint32_t lim = max - min;\n#define BIT_STRIDE 8\n#define BIN_INDEX(i,o) (((uint32_t)data[i] >> o) % (1 << BIT_STRIDE))\n for (int off = 0; lim != 0; off += BIT_STRIDE, lim >>= BIT_STRIDE) {\n uint32_t count[1 << BIT_STRIDE] = {0};\n for (uint32_t i = 0; i < n; i++) count[BIN_INDEX(i, off)]++;\n uint32_t count_tmp = count[0];\n for (int j = 1; j < (1 << BIT_STRIDE); j++) {\n count[j] += count_tmp;\n count_tmp = count[j];\n }\n for (uint32_t i = n; i > 0; i--)\n temp[--count[BIN_INDEX(i - 1, off)]] = data[i - 1];\n memcpy(data, temp, sizeof(data[0]) * n);\n }\n for (uint32_t i = 0; i < n; i++) data[i] += min;\n}\nradix_t find_radix_sub_offset(uint32_t n, int32_t * data) {\n svint32_t acc_min, acc_max;\n svint32_t vec_off, vec_val;\n svbool_t q = svwhilelt_b32(0u, n);\n acc_min = svld1(q, data);\n acc_max = acc_min;\n uint32_t i;\n svbool_t p;\n FOR_LOOP_32(, i, 0, n, p) {\n vec_val = svld1(p, data + i);\n acc_min = svmin_m(p, acc_min, vec_val);\n acc_max = svmax_m(p, acc_max, vec_val);\n }\n int32_t min = svminv(q, acc_min);\n int32_t max = svmaxv(q, acc_max);\n radix_t result = {\n .bits = sizeof(int32_t) * 8 - __builtin_clz(max - min),\n .offset = min,\n };\n vec_off = svdup_s32(result.offset);\n FOR_LOOP_32(, i, 0, n, p) {\n vec_val = svld1(p, data + i);\n vec_val = svsub_m(p, vec_val, vec_off);\n svst1(p, data + i, vec_val);\n }\n return result;\n}\nvoid post_add_offset(uint32_t n, int32_t * data, int32_t off) {\n svint32_t vec_val, vec_off = svdup_s32(off);\n svbool_t p;\n FOR_LOOP_32(uint32_t, i, 0, n, p) {\n vec_val = svld1(p, data + i);\n vec_val = svadd_m(p, vec_val, vec_off);\n svst1(p, data + i, vec_val);\n }\n}\ninline SWAP_DECL(swap_s32p, int32_t *);\nconst uint8_t rearrange_8x1_4x2_lhs[4] = {0, 4, 2, 6};\nconst uint8_t rearrange_8x1_4x2_rhs[4] = {5, 1, 7, 3};\nconst uint8_t rearrange_4x2_2x4_lhs[4] = {0, 1, 4, 5};\nconst uint8_t rearrange_4x2_2x4_rhs[4] = {7, 6, 3, 2};\nconst uint8_t shuffle_4x2_2x4_stage1_lhs[4] = {0, 4, 2, 6};\nconst uint8_t shuffle_4x2_2x4_stage1_rhs[4] = {1, 5, 3, 7};\nconst uint8_t shuffle_4x2_2x4_stage2_lhs[4] = {5, 1, 7, 3};\nconst uint8_t shuffle_4x2_2x4_stage2_rhs[4] = {4, 0, 6, 2};\nconst uint8_t shuffle_2x4_1x8_stage1_lhs[4] = {0, 1, 4, 5};\nconst uint8_t shuffle_2x4_1x8_stage1_rhs[4] = {2, 3, 6, 7};\nconst uint8_t shuffle_2x4_1x8_stage2_lhs[4] = {0, 4, 2, 6};\nconst uint8_t shuffle_2x4_1x8_stage2_rhs[4] = {1, 5, 3, 7};\nconst uint8_t shuffle_2x4_1x8_stage3_lhs[4] = {7, 3, 6, 2};\nconst uint8_t shuffle_2x4_1x8_stage3_rhs[4] = {5, 1, 4, 0};\nconst uint8_t rearrange_16x1_8x2_lhs[8] = {0, 8, 2, 10, 4, 12, 6, 14};\nconst uint8_t rearrange_16x1_8x2_rhs[8] = {9, 1, 11, 3, 13, 5, 15, 7};\nconst uint8_t rearrange_8x2_4x4_lhs[8] = {0, 1, 8, 9, 4, 5, 12, 13};\nconst uint8_t rearrange_8x2_4x4_rhs[8] = {11, 10, 3, 2, 15, 14, 7, 6};\nconst uint8_t rearrange_4x4_2x8_lhs[8] = {0, 1, 2, 3, 8, 9, 10, 11};\nconst uint8_t rearrange_4x4_2x8_rhs[8] = {15, 14, 13, 12, 7, 6, 5, 4};\nconst uint8_t shuffle_8x2_4x4_stage1_lhs[8] = {0, 8, 2, 10,\n 4, 12, 6, 14};\nconst uint8_t shuffle_8x2_4x4_stage1_rhs[8] = {1, 9, 3, 11,\n 5, 13, 7, 15};\nconst uint8_t shuffle_8x2_4x4_stage2_lhs[8] = {9, 1, 11, 3,\n 13, 5, 15, 7};\nconst uint8_t shuffle_8x2_4x4_stage2_rhs[8] = {8, 0, 10, 2,\n 12, 4, 14, 6};\nconst uint8_t shuffle_4x4_2x8_stage1_lhs[8] = {0, 1, 8, 9, 4, 5, 12, 13};\nconst uint8_t shuffle_4x4_2x8_stage1_rhs[8] = {2, 3, 10, 11,\n 6, 7, 14, 15};\nconst uint8_t shuffle_4x4_2x8_stage2_lhs[8] = {0, 8, 2, 10,\n 4, 12, 6, 14};\nconst uint8_t shuffle_4x4_2x8_stage2_rhs[8] = {1, 9, 3, 11,\n 5, 13, 7, 15};\nconst uint8_t shuffle_4x4_2x8_stage3_lhs[8] = {11, 3, 10, 2,\n 15, 7, 14, 6};\nconst uint8_t shuffle_4x4_2x8_stage3_rhs[8] = {9, 1, 8, 0, 13, 5, 12, 4};\nconst uint8_t shuffle_2x8_1x16_stage1_lhs[8] = {0, 1, 2, 3,\n 8, 9, 10, 11};\nconst uint8_t shuffle_2x8_1x16_stage1_rhs[8] = {4, 5, 6, 7,\n 12, 13, 14, 15};\nconst uint8_t shuffle_2x8_1x16_stage2_lhs[8] = {0, 1, 8, 9,\n 4, 5, 12, 13};\nconst uint8_t shuffle_2x8_1x16_stage2_rhs[8] = {2, 3, 10, 11,\n 6, 7, 14, 15};\nconst uint8_t shuffle_2x8_1x16_stage3_lhs[8] = {0, 8, 2, 10,\n 4, 12, 6, 14};\nconst uint8_t shuffle_2x8_1x16_stage3_rhs[8] = {1, 9, 3, 11,\n 5, 13, 7, 15};\nconst uint8_t shuffle_2x8_1x16_stage4_lhs[8] = {15, 7, 14, 6,\n 13, 5, 12, 4};\nconst uint8_t shuffle_2x8_1x16_stage4_rhs[8] = {11, 3, 10, 2,\n 9, 1, 8, 0};\nconst uint8_t rearrange_32x1_16x2_lhs[16] = {\n 0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30};\nconst uint8_t rearrange_32x1_16x2_rhs[16] = {\n 17, 1, 19, 3, 21, 5, 23, 7, 25, 9, 27, 11, 29, 13, 31, 15};\nconst uint8_t rearrange_16x2_8x4_lhs[16] = {\n 0, 1, 16, 17, 4, 5, 20, 21, 8, 9, 24, 25, 12, 13, 28, 29};\nconst uint8_t rearrange_16x2_8x4_rhs[16] = {\n 19, 18, 3, 2, 23, 22, 7, 6, 27, 26, 11, 10, 31, 30, 15, 14};\nconst uint8_t rearrange_8x4_4x8_lhs[16] = {0, 1, 2, 3, 16, 17, 18, 19,\n 8, 9, 10, 11, 24, 25, 26, 27};\nconst uint8_t rearrange_8x4_4x8_rhs[16] = {\n 23, 22, 21, 20, 7, 6, 5, 4, 31, 30, 29, 28, 15, 14, 13, 12};\nconst uint8_t rearrange_4x8_2x16_lhs[16] = {\n 0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23};\nconst uint8_t rearrange_4x8_2x16_rhs[16] = {\n 31, 30, 29, 28, 27, 26, 25, 24, 15, 14, 13, 12, 11, 10, 9, 8};\nconst uint8_t shuffle_16x2_8x4_stage1_lhs[16] = {\n 0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30};\nconst uint8_t shuffle_16x2_8x4_stage1_rhs[16] = {\n 1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31};\nconst uint8_t shuffle_16x2_8x4_stage2_lhs[16] = {\n 17, 1, 19, 3, 21, 5, 23, 7, 25, 9, 27, 11, 29, 13, 31, 15};\nconst uint8_t shuffle_16x2_8x4_stage2_rhs[16] = {\n 16, 0, 18, 2, 20, 4, 22, 6, 24, 8, 26, 10, 28, 12, 30, 14};\nconst uint8_t shuffle_8x4_4x8_stage1_lhs[16] = {\n 0, 1, 16, 17, 4, 5, 20, 21, 8, 9, 24, 25, 12, 13, 28, 29};\nconst uint8_t shuffle_8x4_4x8_stage1_rhs[16] = {\n 2, 3, 18, 19, 6, 7, 22, 23, 10, 11, 26, 27, 14, 15, 30, 31};\nconst uint8_t shuffle_8x4_4x8_stage2_lhs[16] = {\n 0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30};\nconst uint8_t shuffle_8x4_4x8_stage2_rhs[16] = {\n 1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31};\nconst uint8_t shuffle_8x4_4x8_stage3_lhs[16] = {\n 19, 3, 18, 2, 23, 7, 22, 6, 27, 11, 26, 10, 31, 15, 30, 14};\nconst uint8_t shuffle_8x4_4x8_stage3_rhs[16] = {\n 17, 1, 16, 0, 21, 5, 20, 4, 25, 9, 24, 8, 29, 13, 28, 12};\nconst uint8_t shuffle_4x8_2x16_stage1_lhs[16] = {\n 0, 1, 2, 3, 16, 17, 18, 19, 8, 9, 10, 11, 24, 25, 26, 27};\nconst uint8_t shuffle_4x8_2x16_stage1_rhs[16] = {\n 4, 5, 6, 7, 20, 21, 22, 23, 12, 13, 14, 15, 28, 29, 30, 31};\nconst uint8_t shuffle_4x8_2x16_stage2_lhs[16] = {\n 0, 1, 16, 17, 4, 5, 20, 21, 8, 9, 24, 25, 12, 13, 28, 29};\nconst uint8_t shuffle_4x8_2x16_stage2_rhs[16] = {\n 2, 3, 18, 19, 6, 7, 22, 23, 10, 11, 26, 27, 14, 15, 30, 31};\nconst uint8_t shuffle_4x8_2x16_stage3_lhs[16] = {\n 0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30};\nconst uint8_t shuffle_4x8_2x16_stage3_rhs[16] = {\n 1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31};\nconst uint8_t shuffle_4x8_2x16_stage4_lhs[16] = {\n 23, 7, 22, 6, 21, 5, 20, 4, 31, 15, 30, 14, 29, 13, 28, 12};\nconst uint8_t shuffle_4x8_2x16_stage4_rhs[16] = {\n 19, 3, 18, 2, 17, 1, 16, 0, 27, 11, 26, 10, 25, 9, 24, 8};\nconst uint8_t shuffle_2x16_1x32_stage1_lhs[16] = {\n 0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23};\nconst uint8_t shuffle_2x16_1x32_stage1_rhs[16] = {\n 8, 9, 10, 11, 12, 13, 14, 15, 24, 25, 26, 27, 28, 29, 30, 31};\nconst uint8_t shuffle_2x16_1x32_stage2_lhs[16] = {\n 0, 1, 2, 3, 16, 17, 18, 19, 8, 9, 10, 11, 24, 25, 26, 27};\nconst uint8_t shuffle_2x16_1x32_stage2_rhs[16] = {\n 4, 5, 6, 7, 20, 21, 22, 23, 12, 13, 14, 15, 28, 29, 30, 31};\nconst uint8_t shuffle_2x16_1x32_stage3_lhs[16] = {\n 0, 1, 16, 17, 4, 5, 20, 21, 8, 9, 24, 25, 12, 13, 28, 29};\nconst uint8_t shuffle_2x16_1x32_stage3_rhs[16] = {\n 2, 3, 18, 19, 6, 7, 22, 23, 10, 11, 26, 27, 14, 15, 30, 31};\nconst uint8_t shuffle_2x16_1x32_stage4_lhs[16] = {\n 0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30};\nconst uint8_t shuffle_2x16_1x32_stage4_rhs[16] = {\n 1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31};\nconst uint8_t shuffle_2x16_1x32_stage5_lhs[16] = {\n 31, 15, 30, 14, 29, 13, 28, 12, 27, 11, 26, 10, 25, 9, 24, 8};\nconst uint8_t shuffle_2x16_1x32_stage5_rhs[16] = {\n 23, 7, 22, 6, 21, 5, 20, 4, 19, 3, 18, 2, 17, 1, 16, 0};\n#define ARRANGE(N,S) rearrange_##N##_##S##hs\n#define SHUFFLE(N,M,S) shuffle_##N##_stage##M##_##S##hs\ninline svint32x2_t bitonic_snip_1(const uint8_t *l, const uint8_t *r,\n svint32x2_t w, svbool_t p) {\n svuint32_t a = svld1ub_u32(p, l);\n svuint32_t b = svld1ub_u32(p, r);\n svint32_t u = svtbl2(w, a);\n svint32_t v = svtbl2(w, b);\n return svcreate2(u, v);\n}\ninline svint32x2_t bitonic_snip_2(svint32x2_t w, svbool_t p) {\n svint32_t u = svget2(w, 0);\n svint32_t v = svget2(w, 1);\n svbool_t q = svcmpgt(p, u, v);\n svint32_t a = svsel(q, u, v);\n svint32_t b = svsel(q, v, u);\n return svcreate2(a, b);\n}\ninline svint32x2_t bitonic_snip_3(const uint8_t *l, const uint8_t *r,\n svint32x2_t w, svbool_t p) {\n svuint32_t c = svld1ub_u32(p, l);\n svuint32_t d = svld1ub_u32(p, r);\n svint32_t u = svget2(w, 0);\n svint32_t v = svget2(w, 1);\n svbool_t q = svcmpgt(p, u, v);\n svint32_t a = svsel(q, u, v);\n svint32_t b = svsel(q, v, u);\n w = svcreate2(a, b);\n u = svtbl2(w, c);\n v = svtbl2(w, d);\n return svcreate2(u, v);\n}\n#define BITONIC_SNIP_1(N) bitonic_snip_1(ARRANGE(N, l), ARRANGE(N, r), w, p)\n#define BITONIC_SNIP_2() bitonic_snip_2(w, p)\n#define BITONIC_SNIP_3(N,M) bitonic_snip_3(SHUFFLE(N, M, l), SHUFFLE(N, M, r), w, p)\ninline svint32x2_t bitonic_step_8x1_4x2(svint32x2_t w, svbool_t p) {\n return BITONIC_SNIP_2();\n}\ninline svint32x2_t bitonic_step_4x2_2x4(svint32x2_t w, svbool_t p) {\n w = BITONIC_SNIP_3(4x2_2x4, 1);\n w = BITONIC_SNIP_3(4x2_2x4, 2);\n return w;\n}\ninline svint32x2_t bitonic_step_2x4_1x8(svint32x2_t w, svbool_t p) {\n w = BITONIC_SNIP_3(2x4_1x8, 1);\n w = BITONIC_SNIP_3(2x4_1x8, 2);\n w = BITONIC_SNIP_3(2x4_1x8, 3);\n return w;\n}\nsvint32x2_t bitonic_sort_8x1_1x8(svint32x2_t w, svbool_t p) {\n w = bitonic_step_8x1_4x2(w, p);\n w = BITONIC_SNIP_1(8x1_4x2);\n w = bitonic_step_4x2_2x4(w, p);\n w = BITONIC_SNIP_1(4x2_2x4);\n w = bitonic_step_2x4_1x8(w, p);\n return w;\n}\ninline svint32x2_t bitonic_step_16x1_8x2(svint32x2_t w, svbool_t p) {\n return BITONIC_SNIP_2();\n}\ninline svint32x2_t bitonic_step_8x2_4x4(svint32x2_t w, svbool_t p) {\n w = BITONIC_SNIP_3(8x2_4x4, 1);\n w = BITONIC_SNIP_3(8x2_4x4, 2);\n return w;\n}\ninline svint32x2_t bitonic_step_4x4_2x8(svint32x2_t w, svbool_t p) {\n w = BITONIC_SNIP_3(4x4_2x8, 1);\n w = BITONIC_SNIP_3(4x4_2x8, 2);\n w = BITONIC_SNIP_3(4x4_2x8, 3);\n return w;\n}\ninline svint32x2_t bitonic_step_2x8_1x16(svint32x2_t w, svbool_t p) {\n w = BITONIC_SNIP_3(2x8_1x16, 1);\n w = BITONIC_SNIP_3(2x8_1x16, 2);\n w = BITONIC_SNIP_3(2x8_1x16, 3);\n w = BITONIC_SNIP_3(2x8_1x16, 4);\n return w;\n}\nsvint32x2_t bitonic_sort_16x1_1x16(svint32x2_t w, svbool_t p) {\n w = bitonic_step_16x1_8x2(w, p);\n w = BITONIC_SNIP_1(16x1_8x2);\n w = bitonic_step_8x2_4x4(w, p);\n w = BITONIC_SNIP_1(8x2_4x4);\n w = bitonic_step_4x4_2x8(w, p);\n w = BITONIC_SNIP_1(4x4_2x8);\n w = bitonic_step_2x8_1x16(w, p);\n return w;\n}\ninline svint32x2_t bitonic_step_32x1_16x2(svint32x2_t w, svbool_t p) {\n return BITONIC_SNIP_2();\n}\ninline svint32x2_t bitonic_step_16x2_8x4(svint32x2_t w, svbool_t p) {\n w = BITONIC_SNIP_3(16x2_8x4, 1);\n w = BITONIC_SNIP_3(16x2_8x4, 2);\n return w;\n}\ninline svint32x2_t bitonic_step_8x4_4x8(svint32x2_t w, svbool_t p) {\n w = BITONIC_SNIP_3(8x4_4x8, 1);\n w = BITONIC_SNIP_3(8x4_4x8, 2);\n w = BITONIC_SNIP_3(8x4_4x8, 3);\n return w;\n}\ninline svint32x2_t bitonic_step_4x8_2x16(svint32x2_t w, svbool_t p) {\n w = BITONIC_SNIP_3(4x8_2x16, 1);\n w = BITONIC_SNIP_3(4x8_2x16, 2);\n w = BITONIC_SNIP_3(4x8_2x16, 3);\n w = BITONIC_SNIP_3(4x8_2x16, 4);\n return w;\n}\ninline svint32x2_t bitonic_step_2x16_1x32(svint32x2_t w, svbool_t p) {\n w = BITONIC_SNIP_3(2x16_1x32, 1);\n w = BITONIC_SNIP_3(2x16_1x32, 2);\n w = BITONIC_SNIP_3(2x16_1x32, 3);\n w = BITONIC_SNIP_3(2x16_1x32, 4);\n w = BITONIC_SNIP_3(2x16_1x32, 5);\n return w;\n}\nsvint32x2_t bitonic_sort_32x1_1x32(svint32x2_t w, svbool_t p) {\n w = bitonic_step_32x1_16x2(w, p);\n w = BITONIC_SNIP_1(32x1_16x2);\n w = bitonic_step_16x2_8x4(w, p);\n w = BITONIC_SNIP_1(16x2_8x4);\n w = bitonic_step_8x4_4x8(w, p);\n w = BITONIC_SNIP_1(8x4_4x8);\n w = bitonic_step_4x8_2x16(w, p);\n w = BITONIC_SNIP_1(4x8_2x16);\n w = bitonic_step_2x16_1x32(w, p);\n return w;\n}\nvoid bitonic_make_blocks(uint32_t n, int32_t *data) {\n typedef svint32x2_t (*sort_func)(svint32x2_t, svbool_t);\n const sort_func bitonic_sorting_networks[5] = {\n NULL,\n NULL,\n bitonic_sort_8x1_1x8,\n bitonic_sort_16x1_1x16,\n bitonic_sort_32x1_1x32,\n };\n const uint32_t mvl = svcntw();\n const uint32_t m = n - (n % (2 * mvl));\n sort_func network_pass = bitonic_sorting_networks[mylog2_32(mvl)];\n svint32_t x, y, z;\n svint32x2_t w;\n uint32_t i;\n svbool_t p, q;\n p = svptrue_b32();\n for (i = 0; i < m; i += 2 * svcntw()) {\n y = svld1_vnum(p, &data[i], 0);\n z = svld1_vnum(p, &data[i], 1);\n w = network_pass(svcreate2(y, z), p);\n svst1_vnum(p, &data[i], 0, svget2(w, 0));\n svst1_vnum(p, &data[i], 1, svget2(w, 1));\n }\n if (i < n) {\n p = svwhilelt_b32(i + mvl * 0, n);\n q = svwhilelt_b32(i + mvl * 1, n);\n x = svdup_s32(INT_MAX);\n y = svsel(p, svld1_vnum(p, &data[i], 0), x);\n z = svsel(q, svld1_vnum(q, &data[i], 1), x);\n w = network_pass(svcreate2(y, z), p);\n svst1_vnum(p, &data[i], 0, svget2(w, 0));\n svst1_vnum(q, &data[i], 1, svget2(w, 1));\n }\n}\nvoid bitonic_merge_blocks(uint32_t n_lhs, uint32_t n_rhs,\n int32_t *data_lhs, int32_t *data_rhs,\n int32_t *data_out) {\n typedef svint32x2_t (*merge_func)(svint32x2_t, svbool_t);\n const merge_func bitonic_merging_networks[5] = {\n NULL,\n NULL,\n bitonic_step_2x4_1x8,\n bitonic_step_2x8_1x16,\n bitonic_step_2x16_1x32,\n };\n const uint32_t mvl = svcntw();\n merge_func network_pass = bitonic_merging_networks[mylog2_32(mvl)];\n svbool_t p = svptrue_b32();\n svint32_t u, v;\n svint32x2_t w;\n uint32_t ptr_out = 0;\n uint32_t ptr_lhs = 0;\n uint32_t ptr_rhs = 0;\n#define LOAD_SIDE(R,S) R = svld1(p, &data_##S##hs[ptr_##S##hs]); ptr_##S##hs += svcntw()\n#define STORE_REG(R) svst1(p, &data_out[ptr_out], R); ptr_out += svcntw()\n#define NET_PASS w = svcreate2(u, svrev(v)); w = network_pass(w, p); u = svget2(w, 0); v = svget2(w, 1);\n LOAD_SIDE(u, l);\n LOAD_SIDE(v, r);\n NET_PASS;\n STORE_REG(u);\n while (ptr_lhs < n_lhs && ptr_rhs < n_rhs) {\n if (data_lhs[ptr_lhs] < data_rhs[ptr_rhs]) {\n LOAD_SIDE(u, l);\n } else {\n LOAD_SIDE(u, r);\n }\n NET_PASS;\n STORE_REG(u);\n }\n while (ptr_lhs < n_lhs) {\n LOAD_SIDE(u, l);\n NET_PASS;\n STORE_REG(u);\n }\n while (ptr_rhs < n_rhs) {\n LOAD_SIDE(u, r);\n NET_PASS;\n STORE_REG(u);\n }\n STORE_REG(v);\n#undef LOAD_SIDE\n#undef STORE_REG\n#undef NET_PASS\n}\nvoid NOINLINE do_sort(struct loop_123_data * input) {\n const uint32_t n = input->n;\n const uint32_t mvl = get_sve_vl() / 32;\n if (n % mvl) {\n printf(\" - Error: buffer size must be a multiple of SVLs\\n\");\n return;\n }\n if (IS_NOT_POWER_OF_2(mvl) || mvl < 4 || mvl > 16) {\n printf(\"ABORT: disabled for VL > 64 bytes.\\n\");\n exit(2);\n }\n uint32_t num_blocks = (n + 2 * mvl - 1) / (2 * mvl);\n if (input->temp == NULL)\n ALLOC_64B(input->temp, n, \"intermediate buffer\");\n if (input->block_sizes == NULL)\n ALLOC_64B(input->block_sizes, num_blocks, \"block size table\");\n int32_t *data = input->data;\n int32_t *temp = input->temp;\n uint32_t *block_sizes = input->block_sizes;\n bitonic_make_blocks(n, data);\n int32_t *data_inp = data;\n int32_t *data_out = temp;\n uint32_t i;\n for (i = 0; i < num_blocks; i++)\n block_sizes[i] = min2_32u(2 * mvl, n - (i * 2 * mvl));\n while (num_blocks > 1) {\n uint32_t offset = 0;\n uint32_t num_blocks_temp = 0;\n for (i = 1; i < num_blocks; i += 2) {\n uint32_t n_lhs = block_sizes[i - 1];\n uint32_t n_rhs = block_sizes[i];\n uint32_t n_tot = n_lhs + n_rhs;\n bitonic_merge_blocks(n_lhs, n_rhs, &data_inp[offset],\n &data_inp[offset + n_lhs], &data_out[offset]);\n offset += n_tot;\n block_sizes[num_blocks_temp++] = n_tot;\n }\n if (i == num_blocks) {\n uint32_t n_last = block_sizes[i - 1];\n memcpy(data_out + offset, data_inp + offset, sizeof(int32_t) * n_last);\n block_sizes[num_blocks_temp++] = n_last;\n }\n swap_s32p(&data_inp, &data_out);\n num_blocks = num_blocks_temp;\n }\n if (data_inp != data) {\n memcpy(data_out, data_inp, sizeof(int32_t) * n);\n }\n}\nextern \"C\" void inner_loop_123(struct loop_123_data * input) {\n do_sort(input);\n}\n" | |
| } | |
| ], | |
| "description": "Arm hand-written SVE kernel for loop_123 (sve2 tier expert ceiling)." | |
| } | |