src/api/native_tensor_int8.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // native_tensor_int8.cpp — bodies for the INT8 / GGUF-quant group, restored | ||
| 2 | // from the QuickJS binding (src/js/tensor_bindings_int8.cpp). | ||
| 3 | // | ||
| 4 | // Every op except quantizeInt8PerRowHost is GPU-only (see the header): on a | ||
| 5 | // CPU-only build the dispatcher throws "not implemented on CPU", the | ||
| 6 | // BROTENSOR_API_CATCH below records it, and the JS wrapper rethrows it as an | ||
| 7 | // Error. Nothing here has a CPU fallback. | ||
| 8 | |||
| 9 | #include "native_tensor_int8_decl.h" | ||
| 10 | #include "api_internal.h" | ||
| 11 | #include "native_register.h" | ||
| 12 | |||
| 13 | #include <cstdint> | ||
| 14 | #include <string> | ||
| 15 | #include <vector> | ||
| 16 | |||
| 17 | using namespace brotensor::api; | ||
| 18 | |||
| 19 | namespace { | ||
| 20 | |||
| 21 | // The last quantizeInt8PerRowHost result on this thread. The weights cross as | ||
| 22 | // the native's `i8[]` return, the scales through the companion native — one | ||
| 23 | // quantise pass, two typed arrays, as the old `{ weights, scales }` object. | ||
| 24 | // Both are copied out by the runtime (release == nullptr), so the vectors may | ||
| 25 | // be reused by the next call. | ||
| 26 | thread_local std::vector<int8_t> tl_quant_weights; | ||
| 27 | thread_local std::vector<float> tl_quant_scales; | ||
| 28 | |||
| 29 | 40 | void clearBuffer(bronze_native_buffer* out) { | |
| 30 | 40 | out->data = nullptr; | |
| 31 | 40 | out->length = 0; | |
| 32 | 40 | out->release = nullptr; | |
| 33 | 40 | out->ctx = nullptr; | |
| 34 | 40 | } | |
| 35 | |||
| 36 | using brotensor::Tensor; | ||
| 37 | |||
| 38 | 44 | Tensor* T(void* p) { return toTensor(p); } | |
| 39 | |||
| 40 | // The device ops check weight dtypes and (out,in) shapes themselves; what | ||
| 41 | // they take on trust is the activation extent the caller's dims imply, the | ||
| 42 | // optional bias lengths and the raw `const float*` masks. Those are checked | ||
| 43 | // here. | ||
| 44 | |||
| 45 | // An optional per-output bias of `out` elements carried in a kDyn slot. | ||
| 46 | 22 | bool needBias(const char* L, const char* name, uint64_t bits, int64_t out) { | |
| 47 | 22 | const Tensor* b = tensorFromValue(bits); | |
| 48 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | return !b || needElems(L, name, b, out); |
| 49 | } | ||
| 50 | |||
| 51 | } // namespace | ||
| 52 | |||
| 53 | extern "C" { | ||
| 54 | |||
| 55 | // ---- GGUF k-quant dequant -------------------------------------------------- | ||
| 56 | |||
| 57 | 2 | void bro_tensor_dequantQ4kToFp16(void* W_q, void* W_fp16) { | |
| 58 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need("dequantQ4kToFp16", {W_q, W_fp16})) return; |
| 59 | BROTENSOR_API_TRY | ||
| 60 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | brotensor::dequant_q4k_to_fp16(*toTensor(W_q), *toTensor(W_fp16)); |
| 61 |
5/12✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("dequantQ4kToFp16") |
| 62 | 4 | } | |
| 63 | |||
| 64 | 2 | void bro_tensor_dequantQ6kToFp16(void* W_q, void* W_fp16) { | |
| 65 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need("dequantQ6kToFp16", {W_q, W_fp16})) return; |
| 66 | BROTENSOR_API_TRY | ||
| 67 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | brotensor::dequant_q6k_to_fp16(*toTensor(W_q), *toTensor(W_fp16)); |
| 68 |
5/12✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("dequantQ6kToFp16") |
| 69 | 4 | } | |
| 70 | |||
| 71 | 2 | void bro_tensor_dequantQ8_0ToFp16(void* W_q, void* W_fp16) { | |
| 72 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need("dequantQ8_0ToFp16", {W_q, W_fp16})) return; |
| 73 | BROTENSOR_API_TRY | ||
| 74 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | brotensor::dequant_q8_0_to_fp16(*toTensor(W_q), *toTensor(W_fp16)); |
| 75 |
5/12✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("dequantQ8_0ToFp16") |
| 76 | 4 | } | |
| 77 | |||
| 78 | // ---- GGUF k-quant weight-only linear --------------------------------------- | ||
| 79 | |||
| 80 | 2 | void bro_tensor_linearForwardQ4kFp16(void* W_q, uint64_t bias_bits, void* x, void* y) { | |
| 81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need("linearForwardQ4kFp16", {W_q, x, y})) return; |
| 82 | BROTENSOR_API_TRY | ||
| 83 |
5/10✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
|
2 | brotensor::linear_forward_q4k_fp16(*toTensor(W_q), tensorFromValue(bias_bits), *toTensor(x), *toTensor(y)); |
| 84 |
5/12✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("linearForwardQ4kFp16") |
| 85 | 4 | } | |
| 86 | |||
| 87 | 2 | void bro_tensor_linearForwardQ6kFp16(void* W_q, uint64_t bias_bits, void* x, void* y) { | |
| 88 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need("linearForwardQ6kFp16", {W_q, x, y})) return; |
| 89 | BROTENSOR_API_TRY | ||
| 90 |
5/10✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
|
2 | brotensor::linear_forward_q6k_fp16(*toTensor(W_q), tensorFromValue(bias_bits), *toTensor(x), *toTensor(y)); |
| 91 |
5/12✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("linearForwardQ6kFp16") |
| 92 | 4 | } | |
| 93 | |||
| 94 | 2 | void bro_tensor_linearForwardQ8_0Fp16(void* W_q, uint64_t bias_bits, void* x, void* y) { | |
| 95 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need("linearForwardQ8_0Fp16", {W_q, x, y})) return; |
| 96 | BROTENSOR_API_TRY | ||
| 97 |
5/10✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
|
2 | brotensor::linear_forward_q8_0_fp16(*toTensor(W_q), tensorFromValue(bias_bits), *toTensor(x), *toTensor(y)); |
| 98 |
5/12✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("linearForwardQ8_0Fp16") |
| 99 | 4 | } | |
| 100 | |||
| 101 | 2 | void bro_tensor_linearForwardBatchedQ4kFp16(void* W_q, uint64_t bias_bits, void* X_BD, void* Y_BD) { | |
| 102 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need("linearForwardBatchedQ4kFp16", {W_q, X_BD, Y_BD})) return; |
| 103 | BROTENSOR_API_TRY | ||
| 104 |
5/10✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
|
2 | brotensor::linear_forward_batched_q4k_fp16(*toTensor(W_q), tensorFromValue(bias_bits), *toTensor(X_BD), *toTensor(Y_BD)); |
| 105 |
5/12✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("linearForwardBatchedQ4kFp16") |
| 106 | 4 | } | |
| 107 | |||
| 108 | 2 | void bro_tensor_linearForwardBatchedQ6kFp16(void* W_q, uint64_t bias_bits, void* X_BD, void* Y_BD) { | |
| 109 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need("linearForwardBatchedQ6kFp16", {W_q, X_BD, Y_BD})) return; |
| 110 | BROTENSOR_API_TRY | ||
| 111 |
5/10✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
|
2 | brotensor::linear_forward_batched_q6k_fp16(*toTensor(W_q), tensorFromValue(bias_bits), *toTensor(X_BD), *toTensor(Y_BD)); |
| 112 |
5/12✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("linearForwardBatchedQ6kFp16") |
| 113 | 4 | } | |
| 114 | |||
| 115 | 2 | void bro_tensor_linearForwardBatchedQ8_0Fp16(void* W_q, uint64_t bias_bits, void* X_BD, void* Y_BD) { | |
| 116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need("linearForwardBatchedQ8_0Fp16", {W_q, X_BD, Y_BD})) return; |
| 117 | BROTENSOR_API_TRY | ||
| 118 |
5/10✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
|
2 | brotensor::linear_forward_batched_q8_0_fp16(*toTensor(W_q), tensorFromValue(bias_bits), *toTensor(X_BD), *toTensor(Y_BD)); |
| 119 |
5/12✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("linearForwardBatchedQ8_0Fp16") |
| 120 | 4 | } | |
| 121 | |||
| 122 | // ---- W8A16 host quantiser -------------------------------------------------- | ||
| 123 | |||
| 124 | 20 | void bro_tensor_quantizeInt8PerRowHost(const uint16_t* W_fp16, uint32_t W_fp16_len, | |
| 125 | int32_t out, int32_t in, bronze_native_buffer* weights_out) { | ||
| 126 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | if (!weights_out) return; |
| 127 | 20 | clearBuffer(weights_out); | |
| 128 | 20 | tl_quant_weights.clear(); | |
| 129 | 20 | tl_quant_scales.clear(); | |
| 130 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | if (!W_fp16) { |
| 131 | ✗ | setError("quantizeInt8PerRowHost: W_fp16 must be a Uint16Array (binary16 bit pattern)"); | |
| 132 | ✗ | return; | |
| 133 | } | ||
| 134 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
|
20 | if (out <= 0 || in <= 0) { |
| 135 | ✗ | setError("quantizeInt8PerRowHost: out, in must be > 0"); | |
| 136 | ✗ | return; | |
| 137 | } | ||
| 138 | 20 | const size_t count = static_cast<size_t>(out) * static_cast<size_t>(in); | |
| 139 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (static_cast<size_t>(W_fp16_len) < count) { |
| 140 | ✗ | setError("quantizeInt8PerRowHost: W_fp16 view too small for (out, in)"); | |
| 141 | ✗ | return; | |
| 142 | } | ||
| 143 | BROTENSOR_API_TRY | ||
| 144 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | tl_quant_weights.resize(count); |
| 145 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | tl_quant_scales.resize(static_cast<size_t>(out)); |
| 146 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
40 | brotensor::quantize_int8_per_row_host(W_fp16, out, in, |
| 147 | 20 | tl_quant_weights.data(), tl_quant_scales.data()); | |
| 148 | 20 | weights_out->data = tl_quant_weights.data(); | |
| 149 | 20 | weights_out->length = static_cast<uint32_t>(tl_quant_weights.size()); | |
| 150 |
0/12✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
20 | BROTENSOR_API_CATCH("quantizeInt8PerRowHost") |
| 151 | 20 | } | |
| 152 | |||
| 153 | 20 | void bro_tensor_quantizeInt8PerRowHostScales(bronze_native_buffer* scales_out) { | |
| 154 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | if (!scales_out) return; |
| 155 | 20 | clearBuffer(scales_out); | |
| 156 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (tl_quant_scales.empty()) return; |
| 157 | 20 | scales_out->data = tl_quant_scales.data(); | |
| 158 | 20 | scales_out->length = static_cast<uint32_t>(tl_quant_scales.size()); | |
| 159 | 20 | } | |
| 160 | |||
| 161 | // ---- W8A16 dense ----------------------------------------------------------- | ||
| 162 | |||
| 163 | 2 | void bro_tensor_matmulInt8wFp16(void* W_int8, void* scales, void* X, void* Y) { | |
| 164 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need("matmulInt8wFp16", {W_int8, scales, X, Y})) return; |
| 165 | BROTENSOR_API_TRY | ||
| 166 |
5/10✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
|
2 | brotensor::matmul_int8w_fp16(*toTensor(W_int8), *toTensor(scales), *toTensor(X), *toTensor(Y)); |
| 167 |
0/12✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("matmulInt8wFp16") |
| 168 | 2 | } | |
| 169 | |||
| 170 | 2 | void bro_tensor_linearForwardBatchedInt8wFp16(void* W_int8, void* scales, uint64_t bias_bits, | |
| 171 | void* X_BD, void* Y_BD) { | ||
| 172 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if (!need("linearForwardBatchedInt8wFp16", {W_int8, scales, X_BD, Y_BD}) || |
| 173 | 2 | !needBias("linearForwardBatchedInt8wFp16", "bias", bias_bits, T(W_int8)->rows)) return; | |
| 174 | BROTENSOR_API_TRY | ||
| 175 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
4 | brotensor::linear_forward_batched_int8w_fp16(*toTensor(W_int8), *toTensor(scales), |
| 176 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | tensorFromValue(bias_bits), |
| 177 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | *toTensor(X_BD), *toTensor(Y_BD)); |
| 178 |
0/12✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("linearForwardBatchedInt8wFp16") |
| 179 | 2 | } | |
| 180 | |||
| 181 | // ---- W8A16 convolution ----------------------------------------------------- | ||
| 182 | |||
| 183 | 2 | void bro_tensor_conv2dInt8wFp16Forward(void* X, void* W_int8, void* scales, uint64_t bias_bits, | |
| 184 | int32_t N, int32_t C_in, int32_t H, int32_t Win, | ||
| 185 | int32_t C_out, int32_t kH, int32_t kW, | ||
| 186 | int32_t sH, int32_t sW, int32_t pH, int32_t pW, | ||
| 187 | int32_t dH, int32_t dW, int32_t groups, void* Y) { | ||
| 188 | 2 | const char* L = "conv2dInt8wFp16Forward"; | |
| 189 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need(L, {X, W_int8, scales, Y})) return; |
| 190 | 2 | int64_t H_out = 0, W_out = 0; | |
| 191 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (!convGeom2d(L, C_in, C_out, H, Win, kH, kW, sH, sW, pH, pW, dH, dW, groups, H_out, W_out)) return; |
| 192 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | if (!needNonNegative(L, {N}) || !needElems(L, "X", T(X), elems({N, C_in, H, Win})) || |
| 193 | 2 | !needBias(L, "bias", bias_bits, C_out)) return; | |
| 194 | BROTENSOR_API_TRY | ||
| 195 |
4/8✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
4 | brotensor::conv2d_int8w_fp16_forward(*toTensor(X), *toTensor(W_int8), *toTensor(scales), |
| 196 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | tensorFromValue(bias_bits), |
| 197 | 2 | N, C_in, H, Win, C_out, kH, kW, | |
| 198 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | sH, sW, pH, pW, dH, dW, groups, *toTensor(Y)); |
| 199 |
0/12✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("conv2dInt8wFp16Forward") |
| 200 | 2 | } | |
| 201 | |||
| 202 | 2 | void bro_tensor_conv3dInt8wFp16Forward(void* X, void* W_int8, void* scales, uint64_t bias_bits, | |
| 203 | int32_t N, int32_t C_in, int32_t T, int32_t H, int32_t Win, | ||
| 204 | int32_t C_out, int32_t kT, int32_t kH, int32_t kW, | ||
| 205 | int32_t sT, int32_t sH, int32_t sW, | ||
| 206 | int32_t pT, int32_t pH, int32_t pW, | ||
| 207 | int32_t dT, int32_t dH, int32_t dW, | ||
| 208 | int32_t groups, void* Y) { | ||
| 209 | 2 | const char* L = "conv3dInt8wFp16Forward"; | |
| 210 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need(L, {X, W_int8, scales, Y})) return; |
| 211 | 2 | int64_t H_out = 0, W_out = 0; | |
| 212 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (!convGeom2d(L, C_in, C_out, H, Win, kH, kW, sH, sW, pH, pW, dH, dW, groups, H_out, W_out)) return; |
| 213 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if (!needPositive(L, {kT, sT, dT}) || !needNonNegative(L, {N, T, pT})) return; |
| 214 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if (!needElems(L, "X", toTensor(X), elems({N, C_in, T, H, Win})) || !needBias(L, "bias", bias_bits, C_out)) return; |
| 215 | BROTENSOR_API_TRY | ||
| 216 |
4/8✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
4 | brotensor::conv3d_int8w_fp16_forward(*toTensor(X), *toTensor(W_int8), *toTensor(scales), |
| 217 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | tensorFromValue(bias_bits), |
| 218 | 2 | N, C_in, T, H, Win, C_out, kT, kH, kW, | |
| 219 | 2 | sT, sH, sW, pT, pH, pW, dT, dH, dW, | |
| 220 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | groups, *toTensor(Y)); |
| 221 |
0/12✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("conv3dInt8wFp16Forward") |
| 222 | 2 | } | |
| 223 | |||
| 224 | // ---- W8A16 diffusion resblock ---------------------------------------------- | ||
| 225 | |||
| 226 | 2 | void bro_tensor_resblockForwardInt8wFp16(void* X, void* gamma1, void* beta1, | |
| 227 | void* W1_int8, void* s1, uint64_t b1_bits, | ||
| 228 | uint64_t t_emb_shift_bits, | ||
| 229 | void* gamma2, void* beta2, | ||
| 230 | void* W2_int8, void* s2, uint64_t b2_bits, | ||
| 231 | uint64_t Wskip_bits, uint64_t sskip_bits, uint64_t bskip_bits, | ||
| 232 | int32_t N, int32_t C_in, int32_t C_out, int32_t H, int32_t Win, | ||
| 233 | int32_t numGroups, double eps, void* Y) { | ||
| 234 | 2 | const char* L = "resblockForwardInt8wFp16"; | |
| 235 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need(L, {X, gamma1, beta1, W1_int8, s1, gamma2, beta2, W2_int8, s2, Y})) return; |
| 236 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if (!needPositive(L, {numGroups}) || !needNonNegative(L, {N, C_in, C_out, H, Win})) return; |
| 237 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
2 | if (C_in != C_out && !tensorFromValue(Wskip_bits)) { |
| 238 | ✗ | setError(std::string(L) + ": C_in != C_out needs a Wskip projection"); | |
| 239 | ✗ | return; | |
| 240 | } | ||
| 241 | // The op checks dtypes, numGroups and W1/W2 shapes; the FP16 operands' | ||
| 242 | // extents and the optional tensors are checked here. | ||
| 243 |
9/18✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 2 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 2 times.
|
18 | if (!needOperands(L, T(X), {{"X", T(X), elems({N, C_in, H, Win})}, |
| 244 | 4 | {"gamma1", T(gamma1), C_in}, {"beta1", T(beta1), C_in}, | |
| 245 | 2 | {"b1", tensorFromValue(b1_bits), C_out}, | |
| 246 | 2 | {"t_emb_shift", tensorFromValue(t_emb_shift_bits), C_out}, | |
| 247 | 4 | {"gamma2", T(gamma2), C_out}, {"beta2", T(beta2), C_out}, | |
| 248 | 2 | {"b2", tensorFromValue(b2_bits), C_out}, | |
| 249 | 2 | {"bskip", tensorFromValue(bskip_bits), C_out}})) return; | |
| 250 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if (!needMask(L, T(s1), C_out, "s1") || !needMask(L, T(s2), C_out, "s2")) return; |
| 251 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (const Tensor* ws = tensorFromValue(Wskip_bits)) { |
| 252 | ✗ | const Tensor* ss = tensorFromValue(sskip_bits); | |
| 253 | ✗ | if (!ss) { setError(std::string(L) + ": Wskip_int8 needs sskip scales"); return; } | |
| 254 | ✗ | if (!needElems(L, "Wskip_int8", ws, elems({C_out, C_in})) || !needMask(L, ss, C_out, "sskip")) return; | |
| 255 | ✗ | } | |
| 256 | BROTENSOR_API_TRY | ||
| 257 |
4/8✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
4 | brotensor::resblock_forward_int8w_fp16(*toTensor(X), *toTensor(gamma1), *toTensor(beta1), |
| 258 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | *toTensor(W1_int8), *toTensor(s1), |
| 259 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | tensorFromValue(b1_bits), tensorFromValue(t_emb_shift_bits), |
| 260 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | *toTensor(gamma2), *toTensor(beta2), |
| 261 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | *toTensor(W2_int8), *toTensor(s2), |
| 262 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | tensorFromValue(b2_bits), |
| 263 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | tensorFromValue(Wskip_bits), tensorFromValue(sskip_bits), |
| 264 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | tensorFromValue(bskip_bits), |
| 265 | 2 | N, C_in, C_out, H, Win, numGroups, | |
| 266 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | static_cast<float>(eps), *toTensor(Y)); |
| 267 |
0/12✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("resblockForwardInt8wFp16") |
| 268 | 2 | } | |
| 269 | |||
| 270 | // ---- W8A16 flash-attention triplet ----------------------------------------- | ||
| 271 | |||
| 272 | 2 | void bro_tensor_flashAttentionProjectKvInt8wFp16(void* ctx, void* Wk_int8, void* sk, uint64_t bk_bits, | |
| 273 | void* Wv_int8, void* sv, uint64_t bv_bits, | ||
| 274 | void* K_out, void* V_out) { | ||
| 275 | 2 | const char* L = "flashAttentionProjectKvInt8wFp16"; | |
| 276 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need(L, {ctx, Wk_int8, sk, Wv_int8, sv, K_out, V_out})) return; |
| 277 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if (!needBias(L, "bk", bk_bits, T(Wk_int8)->rows) || !needBias(L, "bv", bv_bits, T(Wv_int8)->rows)) return; |
| 278 | BROTENSOR_API_TRY | ||
| 279 |
4/8✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
4 | brotensor::flash_attention_project_kv_int8w_fp16(*toTensor(ctx), *toTensor(Wk_int8), *toTensor(sk), |
| 280 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | tensorFromValue(bk_bits), |
| 281 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | *toTensor(Wv_int8), *toTensor(sv), |
| 282 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | tensorFromValue(bv_bits), |
| 283 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | *toTensor(K_out), *toTensor(V_out)); |
| 284 |
0/12✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("flashAttentionProjectKvInt8wFp16") |
| 285 | 2 | } | |
| 286 | |||
| 287 | 2 | void bro_tensor_flashAttentionQWithKvCachedInt8wFp16(void* X, void* K, void* V, | |
| 288 | void* Wq_int8, void* sq, uint64_t bq_bits, | ||
| 289 | void* Wo_int8, void* so, uint64_t bo_bits, | ||
| 290 | uint64_t mask_bits, int32_t numHeads, | ||
| 291 | bool causal, void* O) { | ||
| 292 | 2 | const char* L = "flashAttentionQWithKvCachedInt8wFp16"; | |
| 293 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need(L, {X, K, V, Wq_int8, sq, Wo_int8, so, O})) return; |
| 294 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | if (!needBias(L, "bq", bq_bits, T(Wq_int8)->rows) || !needBias(L, "bo", bo_bits, T(Wo_int8)->rows) || |
| 295 | 2 | !needMask(L, tensorFromValue(mask_bits), T(K)->rows)) return; | |
| 296 | BROTENSOR_API_TRY | ||
| 297 |
4/8✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
4 | brotensor::flash_attention_q_with_kv_cached_int8w_fp16(*toTensor(X), *toTensor(K), *toTensor(V), |
| 298 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | *toTensor(Wq_int8), *toTensor(sq), |
| 299 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | tensorFromValue(bq_bits), |
| 300 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | *toTensor(Wo_int8), *toTensor(so), |
| 301 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | tensorFromValue(bo_bits), |
| 302 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | maskPtr(mask_bits), numHeads, causal, |
| 303 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | *toTensor(O)); |
| 304 |
0/12✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("flashAttentionQWithKvCachedInt8wFp16") |
| 305 | 2 | } | |
| 306 | |||
| 307 | 2 | void bro_tensor_flashAttentionQkvoInt8wFp16(void* X, uint64_t Ctx_bits, | |
| 308 | void* Wq_int8, void* sq, uint64_t bq_bits, | ||
| 309 | void* Wk_int8, void* sk, uint64_t bk_bits, | ||
| 310 | void* Wv_int8, void* sv, uint64_t bv_bits, | ||
| 311 | void* Wo_int8, void* so, uint64_t bo_bits, | ||
| 312 | uint64_t mask_bits, int32_t numHeads, | ||
| 313 | bool causal, void* O) { | ||
| 314 | 2 | const char* L = "flashAttentionQkvoInt8wFp16"; | |
| 315 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!need(L, {X, Wq_int8, sq, Wk_int8, sk, Wv_int8, sv, Wo_int8, so, O})) return; |
| 316 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | const Tensor* kvSrc = tensorFromValue(Ctx_bits) ? tensorFromValue(Ctx_bits) : T(X); |
| 317 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
4 | if (!needBias(L, "bq", bq_bits, T(Wq_int8)->rows) || !needBias(L, "bk", bk_bits, T(Wk_int8)->rows) || |
| 318 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | !needBias(L, "bv", bv_bits, T(Wv_int8)->rows) || !needBias(L, "bo", bo_bits, T(Wo_int8)->rows) || |
| 319 | 2 | !needMask(L, tensorFromValue(mask_bits), kvSrc->rows)) return; | |
| 320 | BROTENSOR_API_TRY | ||
| 321 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
4 | brotensor::flash_attention_qkvo_int8w_fp16(*toTensor(X), tensorFromValue(Ctx_bits), |
| 322 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | *toTensor(Wq_int8), *toTensor(sq), tensorFromValue(bq_bits), |
| 323 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | *toTensor(Wk_int8), *toTensor(sk), tensorFromValue(bk_bits), |
| 324 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | *toTensor(Wv_int8), *toTensor(sv), tensorFromValue(bv_bits), |
| 325 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | *toTensor(Wo_int8), *toTensor(so), tensorFromValue(bo_bits), |
| 326 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | maskPtr(mask_bits), numHeads, causal, *toTensor(O)); |
| 327 |
0/12✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2 | BROTENSOR_API_CATCH("flashAttentionQkvoInt8wFp16") |
| 328 | 2 | } | |
| 329 | |||
| 330 | // ---- W8A16 T5-style bias self-attention ------------------------------------ | ||
| 331 | |||
| 332 | 4 | void bro_tensor_selfAttentionBiasInt8wFp16(void* X, | |
| 333 | void* Wq_int8, void* sq, | ||
| 334 | void* Wk_int8, void* sk, | ||
| 335 | void* Wv_int8, void* sv, | ||
| 336 | void* Wo_int8, void* so, | ||
| 337 | uint64_t mask_bits, uint64_t attnBias_bits, | ||
| 338 | int32_t numHeads, double scale, void* O) { | ||
| 339 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
4 | if (!need("selfAttentionBiasInt8wFp16", {X, Wq_int8, sq, Wk_int8, sk, Wv_int8, sv, Wo_int8, so, O}) || |
| 340 | 4 | !needMask("selfAttentionBiasInt8wFp16", tensorFromValue(mask_bits), T(X)->rows)) return; | |
| 341 | BROTENSOR_API_TRY | ||
| 342 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
8 | brotensor::self_attention_bias_int8w_fp16(*toTensor(X), |
| 343 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | *toTensor(Wq_int8), *toTensor(sq), |
| 344 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | *toTensor(Wk_int8), *toTensor(sk), |
| 345 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | *toTensor(Wv_int8), *toTensor(sv), |
| 346 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | *toTensor(Wo_int8), *toTensor(so), |
| 347 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | maskPtr(mask_bits), tensorFromValue(attnBias_bits), |
| 348 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | numHeads, static_cast<float>(scale), *toTensor(O)); |
| 349 |
0/12✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
4 | BROTENSOR_API_CATCH("selfAttentionBiasInt8wFp16") |
| 350 | 4 | } | |
| 351 | |||
| 352 | } // extern "C" | ||
| 353 | |||
| 354 | namespace brotensor::api { | ||
| 355 | |||
| 356 | 3 | bool registerTensorNatives_int8(std::string* error) { | |
| 357 | using namespace brotensor::api::reg; | ||
| 358 | 3 | bool ok = | |
| 359 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.dequantQ4kToFp16", p(&bro_tensor_dequantQ4kToFp16), "void", {kTensorCls, kTensorCls}, error) && |
| 360 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.dequantQ6kToFp16", p(&bro_tensor_dequantQ6kToFp16), "void", {kTensorCls, kTensorCls}, error) && |
| 361 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.dequantQ8_0ToFp16", p(&bro_tensor_dequantQ8_0ToFp16), "void", {kTensorCls, kTensorCls}, error) && |
| 362 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.linearForwardQ4kFp16", p(&bro_tensor_linearForwardQ4kFp16), "void", {kTensorCls, kDyn, kTensorCls, kTensorCls}, error) && |
| 363 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.linearForwardQ6kFp16", p(&bro_tensor_linearForwardQ6kFp16), "void", {kTensorCls, kDyn, kTensorCls, kTensorCls}, error) && |
| 364 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.linearForwardQ8_0Fp16", p(&bro_tensor_linearForwardQ8_0Fp16), "void", {kTensorCls, kDyn, kTensorCls, kTensorCls}, error) && |
| 365 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.linearForwardBatchedQ4kFp16", p(&bro_tensor_linearForwardBatchedQ4kFp16), "void", {kTensorCls, kDyn, kTensorCls, kTensorCls}, error) && |
| 366 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.linearForwardBatchedQ6kFp16", p(&bro_tensor_linearForwardBatchedQ6kFp16), "void", {kTensorCls, kDyn, kTensorCls, kTensorCls}, error) && |
| 367 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.linearForwardBatchedQ8_0Fp16", p(&bro_tensor_linearForwardBatchedQ8_0Fp16), "void", {kTensorCls, kDyn, kTensorCls, kTensorCls}, error) && |
| 368 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.quantizeInt8PerRowHost", p(&bro_tensor_quantizeInt8PerRowHost), "i8[]", {"u16[]", "i32", "i32"}, error) && |
| 369 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.quantizeInt8PerRowHostScales", p(&bro_tensor_quantizeInt8PerRowHostScales), "f32[]", {}, error) && |
| 370 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.matmulInt8wFp16", p(&bro_tensor_matmulInt8wFp16), "void", {kTensorCls, kTensorCls, kTensorCls, kTensorCls}, error) && |
| 371 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.linearForwardBatchedInt8wFp16", p(&bro_tensor_linearForwardBatchedInt8wFp16), "void", {kTensorCls, kTensorCls, kDyn, kTensorCls, kTensorCls}, error) && |
| 372 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.conv2dInt8wFp16Forward", p(&bro_tensor_conv2dInt8wFp16Forward), "void", {kTensorCls, kTensorCls, kTensorCls, kDyn, "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", kTensorCls}, error) && |
| 373 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.conv3dInt8wFp16Forward", p(&bro_tensor_conv3dInt8wFp16Forward), "void", {kTensorCls, kTensorCls, kTensorCls, kDyn, "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", kTensorCls}, error) && |
| 374 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.resblockForwardInt8wFp16", p(&bro_tensor_resblockForwardInt8wFp16), "void", {kTensorCls, kTensorCls, kTensorCls, kTensorCls, kTensorCls, kDyn, kDyn, kTensorCls, kTensorCls, kTensorCls, kTensorCls, kDyn, kDyn, kDyn, kDyn, "i32", "i32", "i32", "i32", "i32", "i32", "f64", kTensorCls}, error) && |
| 375 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.flashAttentionProjectKvInt8wFp16", p(&bro_tensor_flashAttentionProjectKvInt8wFp16), "void", {kTensorCls, kTensorCls, kTensorCls, kDyn, kTensorCls, kTensorCls, kDyn, kTensorCls, kTensorCls}, error) && |
| 376 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | fn("__bro_native.tensor.flashAttentionQWithKvCachedInt8wFp16", p(&bro_tensor_flashAttentionQWithKvCachedInt8wFp16), "void", {kTensorCls, kTensorCls, kTensorCls, kTensorCls, kTensorCls, kDyn, kTensorCls, kTensorCls, kDyn, kDyn, "i32", "bool", kTensorCls}, error) && |
| 377 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | fn("__bro_native.tensor.flashAttentionQkvoInt8wFp16", p(&bro_tensor_flashAttentionQkvoInt8wFp16), "void", {kTensorCls, kDyn, kTensorCls, kTensorCls, kDyn, kTensorCls, kTensorCls, kDyn, kTensorCls, kTensorCls, kDyn, kTensorCls, kTensorCls, kDyn, kDyn, "i32", "bool", kTensorCls}, error) && |
| 378 | 3 | fn("__bro_native.tensor.selfAttentionBiasInt8wFp16", p(&bro_tensor_selfAttentionBiasInt8wFp16), "void", {kTensorCls, kTensorCls, kTensorCls, kTensorCls, kTensorCls, kTensorCls, kTensorCls, kTensorCls, kTensorCls, kDyn, kDyn, "i32", "f64", kTensorCls}, error); | |
| 379 | 3 | return ok; | |
| 380 | } | ||
| 381 | |||
| 382 | } // namespace brotensor::api | ||
| 383 |