Skip to content

Commit 0cf1ef7

Browse files
authored
Merge pull request #50 from lubosz/vulkan-catch-errors
vulkan: Catch Vulkan C++ exceptions.
2 parents 535e409 + ba01c92 commit 0cf1ef7

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

ggml/src/ggml-vulkan/ggml-vulkan.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11943,11 +11943,21 @@ static bool ggml_vk_compute_forward(ggml_backend_vk_context * ctx, ggml_cgraph *
1194311943
memcpy(cpy.dst, cpy.src, cpy.n);
1194411944
}
1194511945

11946-
if (almost_ready && !ctx->almost_ready_fence_pending && !use_fence) {
11947-
ggml_vk_submit(subctx, ctx->almost_ready_fence);
11948-
ctx->almost_ready_fence_pending = true;
11949-
} else {
11950-
ggml_vk_submit(subctx, use_fence ? ctx->fence : vk::Fence{});
11946+
try {
11947+
if (almost_ready && !ctx->almost_ready_fence_pending && !use_fence) {
11948+
ggml_vk_submit(subctx, ctx->almost_ready_fence);
11949+
ctx->almost_ready_fence_pending = true;
11950+
} else {
11951+
ggml_vk_submit(subctx, use_fence ? ctx->fence : vk::Fence{});
11952+
}
11953+
} catch (const vk::DeviceLostError& e) {
11954+
std::stringstream ss;
11955+
ss << "Failed to submit queue for tensor " << tensor->name
11956+
<< " OP " << ggml_op_name(tensor->op) << ": " << e.what();
11957+
throw std::runtime_error(ss.str());
11958+
} catch (const vk::SystemError& e) {
11959+
GGML_LOG_ERROR("Failed to submit queue for tensor %s OP %s (%s)", tensor->name,
11960+
ggml_op_name(tensor->op), e.what());
1195111961
}
1195211962

1195311963
if (use_fence) {
@@ -12621,7 +12631,18 @@ static ggml_status ggml_backend_vk_graph_compute(ggml_backend_t backend, ggml_cg
1262112631
(i + ctx->num_additional_fused_ops == last_node) ||
1262212632
(almost_ready && !ctx->almost_ready_fence_pending);
1262312633

12624-
bool enqueued = ggml_vk_build_graph(ctx, cgraph, i, cgraph->nodes[submit_node_idx], submit_node_idx, false, i + ctx->num_additional_fused_ops == last_node, almost_ready, submit);
12634+
bool enqueued = false;
12635+
12636+
try {
12637+
enqueued = ggml_vk_build_graph(ctx, cgraph, i, cgraph->nodes[submit_node_idx],
12638+
submit_node_idx, false,
12639+
i + ctx->num_additional_fused_ops == last_node,
12640+
almost_ready, submit);
12641+
} catch (const std::runtime_error& e) {
12642+
ggml_vk_graph_cleanup(ctx);
12643+
GGML_LOG_ERROR("Failed to build graph: %s", e.what());
12644+
return GGML_STATUS_FAILED;
12645+
}
1262512646

1262612647
if (vk_perf_logger_enabled) {
1262712648
if (ctx->compute_ctx.expired()) {

0 commit comments

Comments
 (0)