Replace loop of dispatch_async with dispatch_apply

This commit is contained in:
Alex Azarov 2024-01-14 14:54:30 +01:00
parent bb0c139247
commit 4176a92cad

View file

@ -733,10 +733,8 @@ static bool ggml_metal_graph_compute(
ctx->command_encoders[i] = [ctx->command_buffers[i] computeCommandEncoderWithDescriptor: edesc];
}
for (int cb_idx = 0; cb_idx < n_cb; ++cb_idx) {
const int n_nodes_per_cb = (n_nodes + n_cb - 1) / n_cb;
dispatch_async(ctx->d_queue, ^{
dispatch_apply(n_cb, ctx->d_queue, ^(size_t cb_idx) {
size_t offs_src0 = 0;
size_t offs_src1 = 0;
size_t offs_dst = 0;
@ -2244,10 +2242,6 @@ static bool ggml_metal_graph_compute(
[command_buffer commit];
});
}
// wait for all threads to finish
dispatch_barrier_sync(ctx->d_queue, ^{});
// check status of command buffers
// needed to detect if the device ran out-of-memory for example (#1881)