Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-blas/blob/main/include/omegablas.h # omega-blas aien-dev/omega-blas Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-blas / include / omegablas.h` 114 lines ยท 6440 bytes Raw Blame History 1 /* omegablas.h: the C interface of libomegablas (aien-dev/omega-blas). 2 * 3 * The arithmetic is the Omega unit om/blas.om, bound through omega-bridge native ABI v2. This 4 * header and src/omegablas.c are the INTERIM C orchestration layer (argument mapping, workspace, 5 * blocking, batching); see docs/EXTENSIONS.md for the Omega features that retire it. 6 * 7 * Standard entry points follow the public CBLAS and Fortran 77 BLAS calling conventions (LP64: 8 * 32-bit integers). The omb_* entry points are omega-blas extensions. 9 * 10 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 11 */ 12 #ifndef OMEGABLAS_H 13 #define OMEGABLAS_H 14 15 #include 16 #include 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 enum CBLAS_ORDER { CblasRowMajor = 101, CblasColMajor = 102 }; 23 enum CBLAS_TRANSPOSE { CblasNoTrans = 111, CblasTrans = 112, CblasConjTrans = 113 }; 24 typedef enum CBLAS_ORDER CBLAS_LAYOUT; 25 26 /* CBLAS level 2 and 3 (single precision real) */ 27 void cblas_sgemv(CBLAS_LAYOUT layout, enum CBLAS_TRANSPOSE TransA, int M, int N, float alpha, 28 const float *A, int lda, const float *X, int incX, float beta, float *Y, int incY); 29 void cblas_sgemm(CBLAS_LAYOUT layout, enum CBLAS_TRANSPOSE TransA, enum CBLAS_TRANSPOSE TransB, 30 int M, int N, int K, float alpha, const float *A, int lda, const float *B, int ldb, 31 float beta, float *C, int ldc); 32 void cblas_xerbla(int p, const char *rout, const char *form, ...); 33 34 /* Fortran 77 entries (hidden string lengths last, ignored) */ 35 void sgemv_(const char *trans, const int *m, const int *n, const float *alpha, const float *a, 36 const int *lda, const float *x, const int *incx, const float *beta, float *y, 37 const int *incy, size_t ltrans); 38 void sgemm_(const char *transa, const char *transb, const int *m, const int *n, const int *k, 39 const float *alpha, const float *a, const int *lda, const float *b, const int *ldb, 40 const float *beta, float *c, const int *ldc, size_t lta, size_t ltb); 41 void xerbla_(const char *srname, const int *info, size_t len); 42 43 /* ---- omega-blas extensions ---- */ 44 45 /* Element types. Products are f32 x f32 with an f32 accumulator; the narrow input formats are 46 * widened exactly, and a 16-bit C is written with round-to-nearest-even. */ 47 typedef enum { 48 OMB_F32 = 0, 49 OMB_F16 = 1, 50 OMB_BF16 = 2, 51 OMB_E4M3 = 3, /* OCP FP8 E4M3 (finite-only, NaN = S.1111.111) */ 52 OMB_E5M2 = 4 /* OCP FP8 E5M2 (IEEE-like) */ 53 } omb_type; 54 55 /* Fused epilogue: C = act(alpha * op(A) op(B) + beta * C + bias). */ 56 typedef enum { OMB_ACT_NONE = 0, OMB_ACT_RELU = 1, OMB_ACT_GELU_TANH = 2 } omb_act; 57 typedef enum { OMB_BIAS_NONE = 0, OMB_BIAS_ROW = 1 /* bias[i], length M */, 58 OMB_BIAS_COL = 2 /* bias[j], length N */ } omb_bias; 59 60 /* Returns 0, or the CBLAS argument number of the first invalid argument (nothing is written). 61 * A and B: OMB_F32 .. OMB_E5M2; C: OMB_F32, OMB_F16 or OMB_BF16. */ 62 int omb_gemm_ex(CBLAS_LAYOUT layout, enum CBLAS_TRANSPOSE TransA, enum CBLAS_TRANSPOSE TransB, 63 int M, int N, int K, float alpha, const void *A, omb_type atype, int lda, 64 const void *B, omb_type btype, int ldb, float beta, void *C, omb_type ctype, 65 int ldc, const float *bias, omb_bias bias_mode, omb_act act); 66 67 /* hgemm and bf16 gemm: 16-bit A, B and C, f32 accumulation. */ 68 int omb_hgemm(CBLAS_LAYOUT layout, enum CBLAS_TRANSPOSE TransA, enum CBLAS_TRANSPOSE TransB, 69 int M, int N, int K, float alpha, const uint16_t *A, int lda, const uint16_t *B, 70 int ldb, float beta, uint16_t *C, int ldc); 71 int omb_bfgemm(CBLAS_LAYOUT layout, enum CBLAS_TRANSPOSE TransA, enum CBLAS_TRANSPOSE TransB, 72 int M, int N, int K, float alpha, const uint16_t *A, int lda, const uint16_t *B, 73 int ldb, float beta, uint16_t *C, int ldc); 74 75 /* Pointer-array batch: count independent problems of one shape. */ 76 int omb_gemm_batched(CBLAS_LAYOUT layout, enum CBLAS_TRANSPOSE TransA, 77 enum CBLAS_TRANSPOSE TransB, int M, int N, int K, float alpha, 78 const void *const *A, omb_type atype, int lda, const void *const *B, 79 omb_type btype, int ldb, float beta, void *const *C, omb_type ctype, int ldc, 80 int count); 81 /* Strided batch: problem b uses A + b*strideA, B + b*strideB, C + b*strideC (in elements). */ 82 int omb_gemm_strided_batched(CBLAS_LAYOUT layout, enum CBLAS_TRANSPOSE TransA, 83 enum CBLAS_TRANSPOSE TransB, int M, int N, int K, float alpha, 84 const void *A, omb_type atype, int lda, int64_t strideA, 85 const void *B, omb_type btype, int ldb, int64_t strideB, float beta, 86 void *C, omb_type ctype, int ldc, int64_t strideC, int count); 87 88 /* Format conversion through the Omega unit (exact widening, RNE narrowing). */ 89 void omb_widen(omb_type src, const void *s, float *d, size_t n); 90 void omb_narrow(omb_type dst, const float *s, void *d, size_t n); 91 92 /* The identity string of the bound Omega unit (source and compiler sha256). */ 93 const char *omb_ident(void); 94 95 /* Device selection (README.md, "GB10 device path"). OMB_DEVICE_HOST runs every call in the Omega unit on the CPU. 96 * OMB_DEVICE_GB10 sends the f32 products without an epilogue (sgemm_, cblas_sgemm, sgemv_, 97 * cblas_sgemv, omb_gemm_ex / batched / strided with A, B and C f32, no bias, act none) to 98 * CUDApp omega_gpu_gemm_ex (bf16x3 on the GB10 tensor cores, not bit-exact fp32: docs/TOLERANCE.md); 99 * every other call stays on the host and is counted as such. A device error aborts the process 100 * (no silent host fallback). The initial device comes from the environment variable 101 * OMEGABLAS_DEVICE=host|gb10 (unset: host), read once at the first call. */ 102 typedef enum { OMB_DEVICE_HOST = 0, OMB_DEVICE_GB10 = 1 } omb_device; 103 /* Returns 0, or -1 (device unchanged) when the library was built without the GB10 path. */ 104 int omb_set_device(omb_device d); 105 omb_device omb_get_device(void); 106 /* Route counters since load: products computed on the host, omega_gpu_gemm_ex calls, the C3 107 * kernel calls they made, and outputs gemm_ex recomputed on the host for non-finite inputs. */ 108 typedef struct { uint64_t host, gb10, gb10_core_calls, gb10_host_fixed; } omb_route_counts; 109 void omb_get_route_counts(omb_route_counts *out); 110 111 #ifdef __cplusplus 112 } 113 #endif 114 #endif