Skip to content

Commit f0b635e

Browse files
lhezfuryhawk
authored andcommitted
opencl: add backend_synchronize (ggml-org#13939)
* This is not needed by the normal use where the result is read using `tensor_get`, but it allows perf mode of `test-backend-ops` to properly measure performance.
1 parent 7e872fa commit f0b635e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ggml/src/ggml-opencl/ggml-opencl.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,7 +2022,12 @@ static bool ggml_backend_opencl_cpy_tensor_async(ggml_backend_t backend, const g
20222022
}
20232023

20242024
static void ggml_backend_opencl_synchronize(ggml_backend_t backend) {
2025-
GGML_UNUSED(backend);
2025+
auto * backend_ctx = static_cast<ggml_backend_opencl_context *>(backend->context);
2026+
2027+
cl_event evt;
2028+
CL_CHECK(clEnqueueBarrierWithWaitList(backend_ctx->queue, 0, nullptr, &evt));
2029+
CL_CHECK(clWaitForEvents(1, &evt));
2030+
CL_CHECK(clReleaseEvent(evt));
20262031
}
20272032

20282033
// Syncronizes the 'backend_ctx's device with others so that commands
@@ -2225,7 +2230,7 @@ static ggml_backend_i ggml_backend_opencl_i = {
22252230
/* .set_tensor_async = */ NULL, /* ggml_backend_opencl_set_tensor_async */
22262231
/* .get_tensor_async = */ NULL, /* ggml_backend_opencl_get_tensor_async */
22272232
/* .cpy_tensor_async = */ NULL, /* ggml_backend_opencl_cpy_tensor_async */
2228-
/* .synchronize = */ NULL, /* ggml_backend_opencl_synchronize */
2233+
/* .synchronize = */ ggml_backend_opencl_synchronize,
22292234
/* .graph_plan_create = */ NULL,
22302235
/* .graph_plan_free = */ NULL,
22312236
/* .graph_plan_update = */ NULL,

0 commit comments

Comments
 (0)