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

ANN_BENCH: AnnGPU::uses_stream() for optional algo GPU sync #2314

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion cpp/bench/ann/src/common/ann_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,16 @@ class AnnGPU {
* end.
*/
[[nodiscard]] virtual auto get_sync_stream() const noexcept -> cudaStream_t = 0;
virtual ~AnnGPU() noexcept = default;
/**
* By default a GPU algorithm uses a fixed stream to order GPU operations.
* However, an algorithm may need to synchronize with the host at the end of its execution.
* In that case, also synchronizing with a benchmark event would put it at disadvantage.
*
* We can disable event sync by passing `false` here
* - ONLY IF THE ALGORITHM HAS PRODUCED ITS OUTPUT BY THE TIME IT SYNCHRONIZES WITH CPU.
*/
[[nodiscard]] virtual auto uses_stream() const noexcept -> bool { return true; }
virtual ~AnnGPU() noexcept = default;
};

template <typename T>
Expand Down
4 changes: 3 additions & 1 deletion cpp/bench/ann/src/common/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ struct cuda_timer {
static inline auto extract_stream(AnnT* algo) -> std::optional<cudaStream_t>
{
auto gpu_ann = dynamic_cast<AnnGPU*>(algo);
if (gpu_ann != nullptr) { return std::make_optional(gpu_ann->get_sync_stream()); }
if (gpu_ann != nullptr && gpu_ann->uses_stream()) {
return std::make_optional(gpu_ann->get_sync_stream());
}
return std::nullopt;
}

Expand Down
Loading