| 601 | } |
| 602 | |
| 603 | Error dispatch(Stream st, MTL::ComputePipelineState* p, const void* args, size_t arg_bytes, Grid groups, Grid threads, |
| 604 | size_t tg_bytes) { |
| 605 | if (arg_bytes > 4096) return fail(kErrorInvalidValue); // setBytes limit |
| 606 | { // Metal skips a dispatch above the pipeline's maxTotalThreadsPerThreadgroup without any error (#2323): stop instead |
| 607 | const uint64_t want = (uint64_t) threads.x * threads.y * threads.z; |
| 608 | if (p && want > (uint64_t) p->maxTotalThreadsPerThreadgroup()) { |
| 609 | Runtime& r = rt(); |
| 610 | std::string name = "?"; |
| 611 | { |
| 612 | std::lock_guard<std::mutex> lk(r.mu); |
| 613 | for (const auto& kv : r.pipes) |
| 614 | if (kv.second == p) { name = kv.first; break; } |
| 615 | } |
| 616 | std::fprintf(stderr, |
| 617 | "strata metal: the kernel %s can run at most %lu threads per threadgroup on this GPU (%s), but the " |
| 618 | "launch asks for %lu.\nMetal skips such a dispatch without any error, so every answer would be " |
| 619 | "wrong; stopping here instead. Please report this (the GPU, macOS version and this line) at " |
| 620 | "https://github.com/Niko1221/Strata/issues . (#2323)\n", |
| 621 | name.c_str(), (unsigned long) p->maxTotalThreadsPerThreadgroup(), |
| 622 | r.dev->name()->utf8String(), (unsigned long) want); |
| 623 | std::fflush(stderr); |
| 624 | std::exit(6); |
| 625 | } |
| 626 | } |
| 627 | StreamImpl* s = S(st); |
| 628 | Op o; |
| 629 | o.kind = Op::Dispatch; |
| 630 | o.pipe = p; |
| 631 | if (arg_bytes <= sizeof o.args) { std::memcpy(o.args, args, arg_bytes); o.arg_bytes = arg_bytes; } |
| 632 | else o.big_args.assign((const uint8_t*) args, (const uint8_t*) args + arg_bytes); |
| 633 | o.groups = groups; |
| 634 | o.threads = threads; |
| 635 | o.tg_bytes = tg_bytes; |
| 636 | if (s->rec) { s->rec->ops.push_back(std::move(o)); return kSuccess; } |
| 637 | return encode_dispatch(s, o); |
| 638 | } |
| 639 | |
| 640 | Stats stats() { return rt().stats; } |
| 641 | |