-
Notifications
You must be signed in to change notification settings - Fork 432
[libcu++] Use CCCL Runtime in CUB metric pre-runs pt 1 #9802
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,10 @@ | |
|
|
||
| #include <cub/device/device_run_length_encode.cuh> | ||
|
|
||
| #include <cuda/buffer> | ||
| #include <cuda/std/execution> | ||
| #include <cuda/stream> | ||
|
|
||
| #include <look_back_helper.cuh> | ||
| #include <nvbench_helper.cuh> | ||
|
|
||
|
|
@@ -42,20 +46,32 @@ static void rle(nvbench::state& state, nvbench::type_list<T, OffsetT, RunLengthT | |
| constexpr std::size_t min_segment_size = 1; | ||
| const std::size_t max_segment_size = static_cast<std::size_t>(state.get_int64("MaxSegSize")); | ||
|
|
||
| thrust::device_vector<offset_t> num_runs_out(1); | ||
| thrust::device_vector<RunLengthT> out_counts(elements); | ||
| thrust::device_vector<T> out_keys(elements); | ||
| thrust::device_vector<T> in_keys = generate.uniform.key_segments(elements, min_segment_size, max_segment_size); | ||
| const auto stream = get_stream_ref(state); | ||
| const auto device = stream.device(); | ||
| caching_allocator_t alloc; | ||
|
|
||
| auto num_runs_out = cuda::make_buffer<offset_t>(stream, pinned_memory_resource(), 1, cuda::no_init); | ||
| auto out_counts = cuda::make_device_buffer<RunLengthT>(stream, device, elements, cuda::no_init); | ||
| auto out_keys = cuda::make_device_buffer<T>(stream, device, elements, cuda::no_init); | ||
| const auto in_keys = | ||
| generate.uniform.key_segments(elements, min_segment_size, max_segment_size).device_buffer<T>(stream, device); | ||
|
|
||
| const T* d_in_keys = thrust::raw_pointer_cast(in_keys.data()); | ||
| T* d_out_keys = thrust::raw_pointer_cast(out_keys.data()); | ||
| RunLengthT* d_out_counts = thrust::raw_pointer_cast(out_counts.data()); | ||
| offset_t* d_num_runs_out = thrust::raw_pointer_cast(num_runs_out.data()); | ||
| const T* d_in_keys = in_keys.data(); | ||
| T* d_out_keys = out_keys.data(); | ||
| RunLengthT* d_out_counts = out_counts.data(); | ||
| offset_t* d_num_runs_out = num_runs_out.data(); | ||
|
|
||
| // Run once to get num_runs for memory accounting | ||
| (void) cub::DeviceRunLengthEncode::Encode( | ||
| d_in_keys, d_out_keys, d_out_counts, d_num_runs_out, static_cast<OffsetT>(elements)); | ||
| cudaDeviceSynchronize(); | ||
| _CCCL_TRY_CUDA_API( | ||
| cub::DeviceRunLengthEncode::Encode, | ||
| "Encode failed", | ||
| d_in_keys, | ||
| d_out_keys, | ||
| d_out_counts, | ||
| d_num_runs_out, | ||
| static_cast<OffsetT>(elements), | ||
| cub_bench_env(alloc, stream)); | ||
| stream.sync(); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| const offset_t num_runs = num_runs_out[0]; | ||
|
|
||
| state.add_element_count(elements); | ||
|
|
@@ -64,13 +80,12 @@ static void rle(nvbench::state& state, nvbench::type_list<T, OffsetT, RunLengthT | |
| state.add_global_memory_writes<RunLengthT>(num_runs); | ||
| state.add_global_memory_writes<offset_t>(1); | ||
|
|
||
| caching_allocator_t alloc; | ||
| state.exec(nvbench::exec_tag::gpu | nvbench::exec_tag::no_batch, [&](nvbench::launch& launch) { | ||
| auto env = cub_bench_env( | ||
| alloc, | ||
| launch | ||
| get_stream_ref(launch) | ||
| #if !TUNE_BASE | ||
| , | ||
| , | ||
| cuda::execution::tune(bench_encode_policy_selector{}) | ||
| #endif // !TUNE_BASE | ||
| ); | ||
|
Comment on lines
84
to
91
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: Is In other words, we want the first warmup run to do all allocations, and all following runs not have any allocation overhead on the host. Q: Should we maybe run and compare a benchmark to be sure?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a small ~2% regression, probably from the overhead to call to the driver, the memory itself was cached in the mempool. I reverted back to the cached allocator |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Why do we use two different allocation functions to get a device buffer? Why does
num_runs_outneed to have a different memory resource?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its read on host later, so it need to be pinned memory