matmul.h (3068B)
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 MATMUL_H 39 #define MATMUL_H 40 41 #include <stddef.h> 42 #include <stdint.h> 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 #define __matmul_TYPE_u8 uint8_t 49 #define __matmul_TYPE_i8 int8_t 50 #define __matmul_TYPE_f32 float 51 #define __matmul_TYPE_f64 double 52 53 extern int matmul_not_implemented(size_t m, size_t n, size_t p, void *A, void *B, void *C, double scale); 54 55 extern int (*matmul_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); 56 extern int (*matmul_f32_f32_f32)(size_t m, size_t n, size_t p, const float *A, const float *B, float *C, double scale); 57 extern int (*matmul_f64_f64_f64)(size_t m, size_t n, size_t p, const double *A, const double *B, double *C, double scale); 58 59 #define matmul(m,n,p,A,B,C) \ 60 _Generic((void (*)(__typeof(A),__typeof(B),__typeof(C)))NULL, \ 61 default: matmul_not_implemented, \ 62 void (*)(uint8_t *, int8_t *, uint8_t *): matmul_u8_i8_u8 \ 63 void (*)(float *, float *, float *): matmul_f32_f32_f32 \ 64 void (*)(double *, double *, double *): matmul_f64_f64_f64 \ 65 )(m,n,p,A,B,C,scale) 66 67 #ifdef __cplusplus 68 } 69 #endif 70 71 #endif