Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds wrapper to hard copy write events for opencl copies #3217

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/stan/model/indexing/rvalue_cl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,17 @@ inline auto rvalue(Expr&& expr, const char* name, const index_uni row_index,
decltype(auto) expr_eval = expr.eval();
math::check_range("uni indexing", name, expr_eval.rows(), row_index.n_);
math::check_range("uni indexing", name, expr_eval.cols(), col_index.n_);
cl::CommandQueue queue = stan::math::opencl_context.queue();
Val res;
try {
cl::Event copy_event;
std::vector<cl::Event> copy_write_events(expr_eval.write_events().begin(),
expr_eval.write_events().end());
cl::CommandQueue& queue = stan::math::opencl_context.queue();
queue.enqueueReadBuffer(
expr_eval.buffer(), true,
sizeof(Val)
* (row_index.n_ - 1 + (col_index.n_ - 1) * expr_eval.rows()),
sizeof(Val), &res, &expr_eval.write_events(), &copy_event);
sizeof(Val), &res, &copy_write_events, &copy_event);
copy_event.wait();
} catch (const cl::Error& e) {
std::ostringstream m;
Expand Down Expand Up @@ -251,14 +253,16 @@ inline math::var rvalue(Expr&& expr, const char* name,
using Val = stan::value_type_t<stan::value_type_t<Expr>>;
math::check_range("uni indexing", name, expr.rows(), row_index.n_);
math::check_range("uni indexing", name, expr.cols(), col_index.n_);
cl::CommandQueue queue = stan::math::opencl_context.queue();
Val res;
try {
std::vector<cl::Event> copy_write_events(expr_.write_events().begin(),
expr.write_events().end());
cl::Event copy_event;
cl::CommandQueue& queue = stan::math::opencl_context.queue();
queue.enqueueReadBuffer(
expr.val().buffer(), true,
sizeof(Val) * (row_index.n_ - 1 + (col_index.n_ - 1) * expr.rows()),
sizeof(Val), &res, &expr.val().write_events(), &copy_event);
sizeof(Val), &res, &copy_write_events, &copy_event);
copy_event.wait();
} catch (const cl::Error& e) {
std::ostringstream m;
Expand Down