mirror of
https://github.com/ml-explore/mlx.git
synced 2025-07-13 11:41:14 +08:00
Command buffer reports errors (#479)
* command buffer reports errors * typo * simplify
This commit is contained in:
parent
4a9012cba0
commit
275db7221a
@ -42,6 +42,15 @@ MTL::CommandBuffer* increment_command_buffer(Stream s) {
|
|||||||
return command_buffer;
|
return command_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void check_error(MTL::CommandBuffer* cbuf) {
|
||||||
|
if (cbuf->status() == MTL::CommandBufferStatusError) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "[METAL] Command buffer execution failed: "
|
||||||
|
<< cbuf->error()->localizedDescription()->utf8String();
|
||||||
|
throw std::runtime_error(msg.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::function<void()> make_task(
|
std::function<void()> make_task(
|
||||||
array& arr,
|
array& arr,
|
||||||
std::vector<std::shared_future<void>> deps,
|
std::vector<std::shared_future<void>> deps,
|
||||||
@ -59,7 +68,7 @@ std::function<void()> make_task(
|
|||||||
metal::device(s.device).end_encoding(s.index);
|
metal::device(s.device).end_encoding(s.index);
|
||||||
scheduler::notify_new_task(s);
|
scheduler::notify_new_task(s);
|
||||||
command_buffer->addCompletedHandler(
|
command_buffer->addCompletedHandler(
|
||||||
[s, arr, p = std::move(p)](MTL::CommandBuffer*) mutable {
|
[s, arr, p = std::move(p)](MTL::CommandBuffer* cbuf) mutable {
|
||||||
if (!arr.is_tracer()) {
|
if (!arr.is_tracer()) {
|
||||||
arr.detach();
|
arr.detach();
|
||||||
for (auto s : arr.siblings()) {
|
for (auto s : arr.siblings()) {
|
||||||
@ -68,14 +77,16 @@ std::function<void()> make_task(
|
|||||||
}
|
}
|
||||||
p->set_value();
|
p->set_value();
|
||||||
scheduler::notify_task_completion(s);
|
scheduler::notify_task_completion(s);
|
||||||
|
check_error(cbuf);
|
||||||
});
|
});
|
||||||
metal::device(s.device).commit_command_buffer(s.index);
|
metal::device(s.device).commit_command_buffer(s.index);
|
||||||
} else {
|
} else {
|
||||||
command_buffer->addCompletedHandler(
|
command_buffer->addCompletedHandler(
|
||||||
[s, arr](MTL::CommandBuffer*) mutable {
|
[s, arr](MTL::CommandBuffer* cbuf) mutable {
|
||||||
if (!arr.is_tracer()) {
|
if (!arr.is_tracer()) {
|
||||||
arr.detach();
|
arr.detach();
|
||||||
}
|
}
|
||||||
|
check_error(cbuf);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user