test_matmul_simd.h (3778B)
1 /* 2 * Copyright (c) 2026 finwo 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 * this software and associated documentation files (the "Software"), to use, copy, 6 * modify, and distribute the Software, subject to the following conditions: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions, and the following disclaimer. 10 * 11 * 2. Redistributions in binary form, or any public offering of the Software 12 * (including hosted or managed services), must reproduce the above copyright 13 * notice, this list of conditions, and the following disclaimer in the 14 * documentation and/or other materials provided. 15 * 16 * 3. Any redistribution or public offering of the Software must clearly attribute 17 * the Software to the original copyright holder, reference this License, and 18 * include a link to the official project repository or website. 19 * 20 * 4. The Software may not be renamed, rebranded, or marketed in a manner that 21 * implies it is an independent or proprietary product. Derivative works must 22 * clearly state that they are based on the Software. 23 * 24 * 5. Modifications to copies of the Software must carry prominent notices stating 25 * that changes were made, the nature of the modifications, and the date of the 26 * modifications. 27 * 28 * Any violation of these conditions terminates the permissions granted herein. 29 * 30 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 32 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT 33 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 34 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 35 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 36 */ 37 38 #ifndef TEST_MATMUL_SIMD_H 39 #define TEST_MATMUL_SIMD_H 40 41 #include <stddef.h> 42 #include <stdint.h> 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 #define MATMUL_SIMD_VERSION "1.0.0" 49 50 #define MATMUL_FLAG_SCALAR (1 << 0) 51 #define MATMUL_FLAG_AVX2 (1 << 1) 52 #define MATMUL_FLAG_AVX512 (1 << 2) 53 #define MATMUL_FLAG_AVX512_VNNI (1 << 3) 54 #define MATMUL_FLAG_AVXVNNI (1 << 4) 55 56 typedef uint32_t matmul_feature_t; 57 58 matmul_feature_t matmul_get_feature(void); 59 const char *matmul_get_feature_name(matmul_feature_t feat); 60 61 int matmul_scalar_u8_i8_u8(size_t m, size_t n, size_t p, const uint8_t *A, const int8_t *B, uint8_t *C, double scale); 62 63 #ifdef __AVX2__ 64 #include <immintrin.h> 65 int matmul_avx2_u8_i8_u8(size_t m, size_t n, size_t p, const uint8_t *A, const int8_t *B, uint8_t *C, double scale); 66 #endif 67 68 #ifdef __AVX512VNNI__ 69 int matmul_avx512vnni_u8_i8_u8(size_t m, size_t n, size_t p, const uint8_t *A, const int8_t *B, uint8_t *C, 70 double scale); 71 #endif 72 73 int matmul_scalar_f32_f32_f32(size_t m, size_t n, size_t p, const float *A, const float *B, float *C, double scale); 74 #ifdef __AVX2__ 75 int matmul_avx2_f32_f32_f32(size_t m, size_t n, size_t p, const float *A, const float *B, float *C, double scale); 76 #endif 77 #ifdef __AVX512F__ 78 int matmul_avx512_f32_f32_f32(size_t m, size_t n, size_t p, const float *A, const float *B, float *C, double scale); 79 #endif 80 81 int matmul_scalar_f64_f64_f64(size_t m, size_t n, size_t p, const double *A, const double *B, double *C, double scale); 82 #ifdef __AVX2__ 83 int matmul_avx2_f64_f64_f64(size_t m, size_t n, size_t p, const double *A, const double *B, double *C, double scale); 84 #endif 85 #ifdef __AVX512F__ 86 int matmul_avx512_f64_f64_f64(size_t m, size_t n, size_t p, const double *A, const double *B, double *C, double scale); 87 #endif 88 89 #ifdef __cplusplus 90 } 91 #endif 92 93 #endif