Skip to content

Commit

Permalink
Minor fixes from code review II.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfep committed Nov 17, 2023
1 parent 286d76e commit 7e86c4f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions samples/core/callback/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ endif()

add_sample(
TEST
TARGET callback_cpp
TARGET callbackcpp
VERSION 300
SOURCES main.cpp
KERNELS reaction_diffusion.cl)
target_link_libraries(callback_cpp PRIVATE
target_link_libraries(callbackcpp PRIVATE
$<TARGET_NAME_IF_EXISTS:Threads::Threads>)
14 changes: 9 additions & 5 deletions samples/core/callback/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,32 +448,36 @@ int main(int argc, char* argv[])
state.img_b = tmp;
}

// Make sure that all queued items are dispatched for execution
OCLERROR_RET(clFlush(state.compute_queue), error, read_ev);
OCLERROR_RET(clFlush(state.copy_queue), error, read_ev);
OCLERROR_RET(clFlush(state.read_queue), error, read_ev);

size_t num_saved_images =
(cb_opts.iterations + cb_opts.write_iter - 1) / cb_opts.write_iter;

for (;;)
{
THRDERROR(mtx_lock(&g_state.image_save_finished_mtx), error,
free_image_b);
THRDERROR(mtx_lock(&g_state.image_save_finished_mtx), error, read_ev);
bool wait_for_saving =
num_saved_images != g_state.image_save_finished_count;
if (wait_for_saving)
{
cnd_wait(&g_state.image_save_finished_signal,
&g_state.image_save_finished_mtx);
THRDERROR(mtx_unlock(&g_state.image_save_finished_mtx), error,
free_image_b);
read_ev);
}
else
{
THRDERROR(mtx_unlock(&g_state.image_save_finished_mtx), error,
free_image_b);
read_ev);
break;
}
}

cl_int end_error = CL_SUCCESS;
// read_ev:
read_ev:
OCLERROR_RET(clReleaseEvent(state.read_event), end_error, copy_ev);
copy_ev:
OCLERROR_RET(clReleaseEvent(state.copy_event), end_error, compute_ev);
Expand Down

0 comments on commit 7e86c4f

Please sign in to comment.