src/dispatch.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Backend registration + per-operand dispatch: the dispatcher core. | ||
| 2 | // | ||
| 3 | // Storage is two parallel std::array<>s indexed by static_cast<int>(Device). | ||
| 4 | // Registration happens during static init (CPU) and at brotensor::init() | ||
| 5 | // time (CUDA/Metal probe success). Both are single-threaded entry points | ||
| 6 | // before any op call, so no mutex is required. | ||
| 7 | |||
| 8 | #include <brotensor/detail/dispatch.h> | ||
| 9 | #include <brotensor/tensor.h> | ||
| 10 | #include <brotensor/runtime.h> | ||
| 11 | |||
| 12 | #include <array> | ||
| 13 | #include <cstddef> | ||
| 14 | #include <cstring> | ||
| 15 | #include <initializer_list> | ||
| 16 | #include <stdexcept> | ||
| 17 | #include <string> | ||
| 18 | |||
| 19 | #if defined(BROTENSOR_HAS_CUDA) | ||
| 20 | extern "C" void brotensor_cuda_set_device(int dev_index); | ||
| 21 | #endif | ||
| 22 | |||
| 23 | namespace brotensor::detail { | ||
| 24 | |||
| 25 | namespace { | ||
| 26 | |||
| 27 | constexpr int kNumDevices = 5; // CPU, CUDA, Metal, (3 unused), VULKAN | ||
| 28 | |||
| 29 | // Upper bound on operands a single dispatch call inspects. The widest op is | ||
| 30 | // resblock_backward (25 operands); 32 leaves headroom. dispatch_with_opts | ||
| 31 | // throws if a future op ever exceeds this rather than silently truncating. | ||
| 32 | constexpr std::size_t kMaxOperands = 32; | ||
| 33 | |||
| 34 | struct Slot { | ||
| 35 | OpsVTable ops{}; | ||
| 36 | AllocVTable alloc{}; | ||
| 37 | bool registered = false; | ||
| 38 | }; | ||
| 39 | |||
| 40 | 352094 | std::array<Slot, kNumDevices>& slots() { | |
| 41 | static std::array<Slot, kNumDevices> s{}; | ||
| 42 | 352094 | return s; | |
| 43 | } | ||
| 44 | |||
| 45 | 25 | const char* dev_name(Device d) { | |
| 46 | 25 | return device_name(d); | |
| 47 | } | ||
| 48 | |||
| 49 | 2 | [[noreturn]] void throw_unregistered(Device d) { | |
| 50 | 2 | std::string msg = "brotensor: backend "; | |
| 51 | 2 | msg += dev_name(d); | |
| 52 | 2 | msg += " not registered"; | |
| 53 | 2 | throw std::runtime_error(msg); | |
| 54 | 2 | } | |
| 55 | |||
| 56 | // A tensor is "committed" to a device once it owns real storage. A freshly | ||
| 57 | // default-constructed (or resized-to-empty) tensor has data == nullptr and | ||
| 58 | // carries no device affinity yet — it is a wildcard that adopts the op's | ||
| 59 | // device. This is what lets callers pass an unsized output tensor to a GPU op | ||
| 60 | // without first pinning it to the right backend by hand. | ||
| 61 | 276295 | inline bool committed(const Tensor& t) { return t.data != nullptr; } | |
| 62 | |||
| 63 | 10 | [[noreturn]] void throw_device_mismatch(Device resolved, int idx, Device got) { | |
| 64 | 10 | std::string msg = "brotensor: dispatch: operand "; | |
| 65 | 10 | msg += std::to_string(idx); | |
| 66 | 10 | msg += " is on "; | |
| 67 | 10 | msg += dev_name(got); | |
| 68 | 10 | msg += " but the op resolved to "; | |
| 69 | 10 | msg += dev_name(resolved); | |
| 70 | 10 | throw std::runtime_error(msg); | |
| 71 | 10 | } | |
| 72 | |||
| 73 | 77901 | inline void activate_device_context(Device dev) { | |
| 74 | 77901 | dev = resolve_device_alias(dev); | |
| 75 | #if defined(BROTENSOR_HAS_CUDA) | ||
| 76 | if (dev.is_cuda()) { | ||
| 77 | brotensor_cuda_set_device(dev.index); | ||
| 78 | } | ||
| 79 | #endif | ||
| 80 | (void)dev; | ||
| 81 | 77901 | } | |
| 82 | |||
| 83 | // Resolve the op's device from the first committed operand; verify every other | ||
| 84 | // committed operand agrees (uncommitted operands are skipped). Returns the | ||
| 85 | // vtable for the resolved device. | ||
| 86 | 74284 | const OpsVTable& dispatch_v(std::initializer_list<const Tensor*> ts) { | |
| 87 | 74284 | Device dev = Device::CPU; | |
| 88 | 74284 | bool found = false; | |
| 89 | 74306 | for (const Tensor* t : ts) { | |
| 90 | 74288 | if (t && committed(*t)) { dev = t->device; found = true; break; } | |
| 91 | } | ||
| 92 | 74284 | if (!found && ts.size() != 0 && *ts.begin() != nullptr) { | |
| 93 | // All operands empty — degenerate but not an error (e.g. a fresh | ||
| 94 | // output passed before any input). Keep operand 0's tag. | ||
| 95 | 18 | dev = (*ts.begin())->device; | |
| 96 | 18 | } | |
| 97 | 74284 | int idx = 0; | |
| 98 | 244937 | for (const Tensor* t : ts) { | |
| 99 | 170657 | if (t && committed(*t) && t->device != dev) { | |
| 100 | 4 | throw_device_mismatch(dev, idx, t->device); | |
| 101 | } | ||
| 102 | 170653 | ++idx; | |
| 103 | } | ||
| 104 | 74280 | activate_device_context(dev); | |
| 105 | 74280 | return ops_for(dev); | |
| 106 | } | ||
| 107 | |||
| 108 | // Same resolution rule as dispatch_v, over a plain operand array — used by the | ||
| 109 | // optional-operand dispatch path so it needs no heap allocation. Null entries | ||
| 110 | // (skipped optional operands) are tolerated. | ||
| 111 | 3627 | const OpsVTable& resolve_over(const Tensor* const* all, std::size_t count) { | |
| 112 | 3627 | Device dev = Device::CPU; | |
| 113 | 3627 | bool found = false; | |
| 114 | 3633 | for (std::size_t i = 0; i < count; ++i) { | |
| 115 | 3631 | if (all[i] && committed(*all[i])) { | |
| 116 | 3625 | dev = all[i]->device; | |
| 117 | 3625 | found = true; | |
| 118 | 3625 | break; | |
| 119 | } | ||
| 120 | 6 | } | |
| 121 | 3627 | if (!found) { | |
| 122 | // No committed operand — adopt the first non-null operand's tag. | ||
| 123 | 2 | for (std::size_t i = 0; i < count; ++i) { | |
| 124 | 2 | if (all[i]) { dev = all[i]->device; break; } | |
| 125 | ✗ | } | |
| 126 | 2 | } | |
| 127 | 35943 | for (std::size_t i = 0; i < count; ++i) { | |
| 128 | 32322 | if (all[i] && committed(*all[i]) && all[i]->device != dev) { | |
| 129 | 6 | throw_device_mismatch(dev, static_cast<int>(i), all[i]->device); | |
| 130 | } | ||
| 131 | 32316 | } | |
| 132 | 3621 | activate_device_context(dev); | |
| 133 | 3621 | return ops_for(dev); | |
| 134 | } | ||
| 135 | |||
| 136 | 1 | [[noreturn]] void throw_too_many_operands(std::size_t n) { | |
| 137 | 2 | throw std::runtime_error( | |
| 138 | 1 | "brotensor: dispatch: operand count " + std::to_string(n) + | |
| 139 | 1 | " exceeds the fixed dispatch buffer (" + | |
| 140 | 2 | std::to_string(kMaxOperands) + ")"); | |
| 141 | 1 | } | |
| 142 | |||
| 143 | } // namespace | ||
| 144 | |||
| 145 | static int g_cuda_device_count = 0; | ||
| 146 | static int g_vulkan_device_count = 0; | ||
| 147 | |||
| 148 | ✗ | void set_cuda_device_count(int count) { | |
| 149 | ✗ | g_cuda_device_count = count; | |
| 150 | ✗ | } | |
| 151 | |||
| 152 | ✗ | void set_vulkan_device_count(int count) { | |
| 153 | ✗ | g_vulkan_device_count = count; | |
| 154 | ✗ | } | |
| 155 | |||
| 156 | 362 | void register_backend(DeviceType dt, const OpsVTable& ops, const AllocVTable& alloc) { | |
| 157 | 362 | auto& s = slots()[static_cast<int>(dt)]; | |
| 158 | 362 | std::memcpy(&s.ops, &ops, sizeof(OpsVTable)); | |
| 159 | 362 | std::memcpy(&s.alloc, &alloc, sizeof(AllocVTable)); | |
| 160 | 362 | s.registered = true; | |
| 161 | 362 | } | |
| 162 | |||
| 163 | 362 | void register_backend(Device d, const OpsVTable& ops, const AllocVTable& alloc) { | |
| 164 | 362 | register_backend(d.type, ops, alloc); | |
| 165 | 362 | } | |
| 166 | |||
| 167 | 15164 | bool is_registered(Device d) { | |
| 168 | 15164 | if (d.is_cpu()) return slots()[static_cast<int>(DeviceType::CPU)].registered; | |
| 169 | 10295 | if (d.is_cuda()) { | |
| 170 | 5072 | if (!slots()[static_cast<int>(DeviceType::CUDA)].registered) return false; | |
| 171 | ✗ | int count = ::brotensor::cuda_device_count(); | |
| 172 | ✗ | if (count <= 0) count = 1; | |
| 173 | ✗ | return d.index >= 0 && d.index < count; | |
| 174 | } | ||
| 175 | 5223 | if (d.is_metal()) { | |
| 176 | 5197 | return slots()[static_cast<int>(DeviceType::Metal)].registered && d.index == 0; | |
| 177 | } | ||
| 178 | 26 | if (d.is_vulkan()) { | |
| 179 | 26 | if (!slots()[static_cast<int>(DeviceType::VULKAN)].registered) return false; | |
| 180 | ✗ | return d.index >= 0 && d.index < ::brotensor::vulkan_device_count(); | |
| 181 | } | ||
| 182 | ✗ | return false; | |
| 183 | 15164 | } | |
| 184 | |||
| 185 | 573070 | Device resolve_device_alias(Device d) { | |
| 186 | 573070 | if (d.is_cuda() && !slots()[static_cast<int>(DeviceType::CUDA)].registered) { | |
| 187 | 2601 | const bool metal = slots()[static_cast<int>(DeviceType::Metal)].registered; | |
| 188 | 2601 | const bool vulkan = slots()[static_cast<int>(DeviceType::VULKAN)].registered; | |
| 189 | // With both, the default device decides (a Metal + Vulkan build run | ||
| 190 | // with BROTENSOR_DEFAULT_DEVICE=vulkan means Vulkan); otherwise Metal | ||
| 191 | // first, the order pick_default_from_available() uses. | ||
| 192 | 2601 | if (metal && vulkan && ::brotensor::default_device().is_vulkan()) return Device::vulkan(d.index); | |
| 193 | 2601 | if (metal) return Device::Metal; | |
| 194 | ✗ | if (vulkan) return Device::vulkan(d.index); | |
| 195 | ✗ | } | |
| 196 | 570469 | return d; | |
| 197 | 573070 | } | |
| 198 | |||
| 199 | 78027 | const OpsVTable& ops_for(Device d) { | |
| 200 | 78027 | d = resolve_device_alias(d); | |
| 201 | 78027 | auto& s = slots()[static_cast<int>(d.type)]; | |
| 202 | 78027 | if (!s.registered) throw_unregistered(d); | |
| 203 | 78026 | return s.ops; | |
| 204 | } | ||
| 205 | |||
| 206 | 250738 | const AllocVTable& alloc_for(Device d) { | |
| 207 | 250738 | d = resolve_device_alias(d); | |
| 208 | 250738 | auto& s = slots()[static_cast<int>(d.type)]; | |
| 209 | 250738 | if (!s.registered) throw_unregistered(d); | |
| 210 | 250737 | return s.alloc; | |
| 211 | } | ||
| 212 | |||
| 213 | // ─── dispatch overloads ──────────────────────────────────────────────────── | ||
| 214 | // | ||
| 215 | // Each forwards to dispatch_v, which resolves the device from the first | ||
| 216 | // committed operand and skips uncommitted (data == nullptr) wildcards. | ||
| 217 | |||
| 218 | 415 | const OpsVTable& dispatch(const Tensor& a) { | |
| 219 | 415 | return dispatch_v({&a}); | |
| 220 | } | ||
| 221 | |||
| 222 | 58231 | const OpsVTable& dispatch(const Tensor& a, const Tensor& b) { | |
| 223 | 58231 | return dispatch_v({&a, &b}); | |
| 224 | } | ||
| 225 | |||
| 226 | 10573 | const OpsVTable& dispatch(const Tensor& a, const Tensor& b, const Tensor& c) { | |
| 227 | 10573 | return dispatch_v({&a, &b, &c}); | |
| 228 | } | ||
| 229 | |||
| 230 | 4354 | const OpsVTable& dispatch(const Tensor& a, const Tensor& b, const Tensor& c, | |
| 231 | const Tensor& d) { | ||
| 232 | 4354 | return dispatch_v({&a, &b, &c, &d}); | |
| 233 | } | ||
| 234 | |||
| 235 | 213 | const OpsVTable& dispatch(const Tensor& a, const Tensor& b, const Tensor& c, | |
| 236 | const Tensor& d, const Tensor& e) { | ||
| 237 | 213 | return dispatch_v({&a, &b, &c, &d, &e}); | |
| 238 | } | ||
| 239 | |||
| 240 | 169 | const OpsVTable& dispatch(const Tensor& a, const Tensor& b, const Tensor& c, | |
| 241 | const Tensor& d, const Tensor& e, const Tensor& f) { | ||
| 242 | 169 | return dispatch_v({&a, &b, &c, &d, &e, &f}); | |
| 243 | } | ||
| 244 | |||
| 245 | 66 | const OpsVTable& dispatch(const Tensor& a, const Tensor& b, const Tensor& c, | |
| 246 | const Tensor& d, const Tensor& e, const Tensor& f, | ||
| 247 | const Tensor& g) { | ||
| 248 | 66 | return dispatch_v({&a, &b, &c, &d, &e, &f, &g}); | |
| 249 | } | ||
| 250 | |||
| 251 | 263 | const OpsVTable& dispatch(const Tensor& a, const Tensor& b, const Tensor& c, | |
| 252 | const Tensor& d, const Tensor& e, const Tensor& f, | ||
| 253 | const Tensor& g, const Tensor& h) { | ||
| 254 | 263 | return dispatch_v({&a, &b, &c, &d, &e, &f, &g, &h}); | |
| 255 | } | ||
| 256 | |||
| 257 | 290 | const OpsVTable& dispatch_with_opts(const Tensor& a, | |
| 258 | std::initializer_list<const Tensor*> opts) { | ||
| 259 | 290 | const std::size_t count = 1 + opts.size(); | |
| 260 | 290 | if (count > kMaxOperands) throw_too_many_operands(count); | |
| 261 | const Tensor* all[kMaxOperands]; | ||
| 262 | 289 | std::size_t n = 0; | |
| 263 | 289 | all[n++] = &a; | |
| 264 | 981 | for (const Tensor* p : opts) all[n++] = p; | |
| 265 | 289 | return resolve_over(all, n); | |
| 266 | } | ||
| 267 | |||
| 268 | 3338 | const OpsVTable& dispatch_with_opts(const Tensor& a, const Tensor& b, | |
| 269 | std::initializer_list<const Tensor*> opts) { | ||
| 270 | 3338 | const std::size_t count = 2 + opts.size(); | |
| 271 | 3338 | if (count > kMaxOperands) throw_too_many_operands(count); | |
| 272 | const Tensor* all[kMaxOperands]; | ||
| 273 | 3338 | std::size_t n = 0; | |
| 274 | 3338 | all[n++] = &a; | |
| 275 | 3338 | all[n++] = &b; | |
| 276 | 28016 | for (const Tensor* p : opts) all[n++] = p; | |
| 277 | 3338 | return resolve_over(all, n); | |
| 278 | } | ||
| 279 | |||
| 280 | // ─── output adoption ─────────────────────────────────────────────────────── | ||
| 281 | // | ||
| 282 | // An uncommitted output tensor (data == nullptr) has no device affinity yet. | ||
| 283 | // The wrapper calls this after dispatch so the tensor is pinned to the op's | ||
| 284 | // device before the backend impl resizes/allocates it. | ||
| 285 | 84696 | void adopt_output(Tensor& t, Device d) { | |
| 286 | 84696 | if (t.data == nullptr) t.device = resolve_device_alias(d); | |
| 287 | 84696 | } | |
| 288 | |||
| 289 | 3 | [[noreturn]] void throw_not_implemented(const char* op_name, Device d) { | |
| 290 | 3 | std::string msg = "brotensor: "; | |
| 291 | 3 | msg += op_name; | |
| 292 | 3 | msg += ": not implemented on "; | |
| 293 | 3 | msg += dev_name(d); | |
| 294 | 3 | throw std::runtime_error(msg); | |
| 295 | 3 | } | |
| 296 | |||
| 297 | 2 | [[noreturn]] void throw_spatial_1d_error(const char* op, const char* tensor_name, | |
| 298 | int N, int C, int L, int rows, int cols) { | ||
| 299 | 2 | std::string msg = "brotensor: "; | |
| 300 | 2 | msg += op; | |
| 301 | 2 | if (N <= 0 || C <= 0 || L <= 0) { | |
| 302 | ✗ | msg += ": non-positive spatial dimensions (N="; | |
| 303 | ✗ | msg += std::to_string(N); | |
| 304 | ✗ | msg += ", C="; | |
| 305 | ✗ | msg += std::to_string(C); | |
| 306 | ✗ | msg += ", L="; | |
| 307 | ✗ | msg += std::to_string(L); | |
| 308 | ✗ | msg += ") for "; | |
| 309 | ✗ | msg += tensor_name; | |
| 310 | ✗ | msg += " (rows="; | |
| 311 | ✗ | msg += std::to_string(rows); | |
| 312 | ✗ | msg += ", cols="; | |
| 313 | ✗ | msg += std::to_string(cols); | |
| 314 | ✗ | msg += ")"; | |
| 315 | ✗ | } else { | |
| 316 | 2 | const std::int64_t expected_cols = static_cast<std::int64_t>(C) * L; | |
| 317 | 2 | msg += ": shape mismatch for "; | |
| 318 | 2 | msg += tensor_name; | |
| 319 | 2 | msg += ": expected (N="; | |
| 320 | 2 | msg += std::to_string(N); | |
| 321 | 2 | msg += ", C*L="; | |
| 322 | 2 | msg += std::to_string(C); | |
| 323 | 2 | msg += "*"; | |
| 324 | 2 | msg += std::to_string(L); | |
| 325 | 2 | msg += "="; | |
| 326 | 2 | msg += std::to_string(expected_cols); | |
| 327 | 2 | msg += "), got (rows="; | |
| 328 | 2 | msg += std::to_string(rows); | |
| 329 | 2 | msg += ", cols="; | |
| 330 | 2 | msg += std::to_string(cols); | |
| 331 | 2 | msg += ")"; | |
| 332 | } | ||
| 333 | 2 | throw std::runtime_error(msg); | |
| 334 | 2 | } | |
| 335 | |||
| 336 | 10 | [[noreturn]] void throw_spatial_2d_error(const char* op, const char* tensor_name, | |
| 337 | int N, int C, int H, int W, int rows, int cols) { | ||
| 338 | 10 | std::string msg = "brotensor: "; | |
| 339 | 10 | msg += op; | |
| 340 | 10 | if (N <= 0 || C <= 0 || H <= 0 || W <= 0) { | |
| 341 | 2 | msg += ": non-positive spatial dimensions (N="; | |
| 342 | 2 | msg += std::to_string(N); | |
| 343 | 2 | msg += ", C="; | |
| 344 | 2 | msg += std::to_string(C); | |
| 345 | 2 | msg += ", H="; | |
| 346 | 2 | msg += std::to_string(H); | |
| 347 | 2 | msg += ", W="; | |
| 348 | 2 | msg += std::to_string(W); | |
| 349 | 2 | msg += ") for "; | |
| 350 | 2 | msg += tensor_name; | |
| 351 | 2 | msg += " (rows="; | |
| 352 | 2 | msg += std::to_string(rows); | |
| 353 | 2 | msg += ", cols="; | |
| 354 | 2 | msg += std::to_string(cols); | |
| 355 | 2 | msg += ")"; | |
| 356 | 2 | } else { | |
| 357 | 8 | const std::int64_t expected_cols = static_cast<std::int64_t>(C) * H * W; | |
| 358 | 8 | msg += ": shape mismatch for "; | |
| 359 | 8 | msg += tensor_name; | |
| 360 | 8 | msg += ": expected (N="; | |
| 361 | 8 | msg += std::to_string(N); | |
| 362 | 8 | msg += ", C*H*W="; | |
| 363 | 8 | msg += std::to_string(C); | |
| 364 | 8 | msg += "*"; | |
| 365 | 8 | msg += std::to_string(H); | |
| 366 | 8 | msg += "*"; | |
| 367 | 8 | msg += std::to_string(W); | |
| 368 | 8 | msg += "="; | |
| 369 | 8 | msg += std::to_string(expected_cols); | |
| 370 | 8 | msg += "), got (rows="; | |
| 371 | 8 | msg += std::to_string(rows); | |
| 372 | 8 | msg += ", cols="; | |
| 373 | 8 | msg += std::to_string(cols); | |
| 374 | 8 | msg += ")"; | |
| 375 | } | ||
| 376 | 10 | throw std::runtime_error(msg); | |
| 377 | 10 | } | |
| 378 | |||
| 379 | 3 | [[noreturn]] void throw_spatial_3d_error(const char* op, const char* tensor_name, | |
| 380 | int N, int C, int T, int H, int W, int rows, int cols) { | ||
| 381 | 3 | std::string msg = "brotensor: "; | |
| 382 | 3 | msg += op; | |
| 383 | 3 | if (N <= 0 || C <= 0 || T <= 0 || H <= 0 || W <= 0) { | |
| 384 | 1 | msg += ": non-positive spatial dimensions (N="; | |
| 385 | 1 | msg += std::to_string(N); | |
| 386 | 1 | msg += ", C="; | |
| 387 | 1 | msg += std::to_string(C); | |
| 388 | 1 | msg += ", T="; | |
| 389 | 1 | msg += std::to_string(T); | |
| 390 | 1 | msg += ", H="; | |
| 391 | 1 | msg += std::to_string(H); | |
| 392 | 1 | msg += ", W="; | |
| 393 | 1 | msg += std::to_string(W); | |
| 394 | 1 | msg += ") for "; | |
| 395 | 1 | msg += tensor_name; | |
| 396 | 1 | msg += " (rows="; | |
| 397 | 1 | msg += std::to_string(rows); | |
| 398 | 1 | msg += ", cols="; | |
| 399 | 1 | msg += std::to_string(cols); | |
| 400 | 1 | msg += ")"; | |
| 401 | 1 | } else { | |
| 402 | 2 | const std::int64_t expected_cols = static_cast<std::int64_t>(C) * T * H * W; | |
| 403 | 2 | msg += ": shape mismatch for "; | |
| 404 | 2 | msg += tensor_name; | |
| 405 | 2 | msg += ": expected (N="; | |
| 406 | 2 | msg += std::to_string(N); | |
| 407 | 2 | msg += ", C*T*H*W="; | |
| 408 | 2 | msg += std::to_string(C); | |
| 409 | 2 | msg += "*"; | |
| 410 | 2 | msg += std::to_string(T); | |
| 411 | 2 | msg += "*"; | |
| 412 | 2 | msg += std::to_string(H); | |
| 413 | 2 | msg += "*"; | |
| 414 | 2 | msg += std::to_string(W); | |
| 415 | 2 | msg += "="; | |
| 416 | 2 | msg += std::to_string(expected_cols); | |
| 417 | 2 | msg += "), got (rows="; | |
| 418 | 2 | msg += std::to_string(rows); | |
| 419 | 2 | msg += ", cols="; | |
| 420 | 2 | msg += std::to_string(cols); | |
| 421 | 2 | msg += ")"; | |
| 422 | } | ||
| 423 | 3 | throw std::runtime_error(msg); | |
| 424 | 3 | } | |
| 425 | |||
| 426 | 21 | [[noreturn]] void throw_quant_cols_error(const char* op, const char* tensor_name, | |
| 427 | Dtype dt, int rows, int cols) { | ||
| 428 | 21 | std::string msg = "brotensor: "; | |
| 429 | 21 | msg += op; | |
| 430 | 21 | msg += ": block-quant tensor "; | |
| 431 | 21 | msg += tensor_name; | |
| 432 | 21 | msg += " ("; | |
| 433 | 21 | msg += dtype_name(dt); | |
| 434 | 21 | msg += ", rows="; | |
| 435 | 21 | msg += std::to_string(rows); | |
| 436 | 21 | msg += ", cols="; | |
| 437 | 21 | msg += std::to_string(cols); | |
| 438 | 21 | msg += ") requires positive rows and cols with cols a multiple of block size ("; | |
| 439 | 21 | msg += std::to_string(dtype_block_size(dt)); | |
| 440 | 21 | msg += ")"; | |
| 441 | 21 | throw std::runtime_error(msg); | |
| 442 | 21 | } | |
| 443 | |||
| 444 | } // namespace brotensor::detail | ||
| 445 | |||
| 446 | namespace brotensor { | ||
| 447 | ✗ | int cuda_device_count() { | |
| 448 | ✗ | return detail::g_cuda_device_count; | |
| 449 | } | ||
| 450 | 4736 | int vulkan_device_count() { | |
| 451 | 4736 | return detail::g_vulkan_device_count; | |
| 452 | } | ||
| 453 | } | ||
| 454 |