-
Notifications
You must be signed in to change notification settings - Fork 425
[libcu++] Use cccl runtime in thrust tests pt 4 #9778
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 |
|---|---|---|
|
|
@@ -5,8 +5,10 @@ | |
|
|
||
| #include <cuda/__cccl_config> | ||
| #include <cuda/algorithm> | ||
| #include <cuda/buffer> | ||
| #include <cuda/devices> | ||
| #include <cuda/launch> | ||
| #include <cuda/memory_resource> | ||
| #include <cuda/std/cstddef> | ||
| #include <cuda/std/initializer_list> | ||
| #include <cuda/std/span> | ||
|
|
@@ -42,6 +44,30 @@ _CCCL_DEVICE_API inline void assert_device(bool condition, const char* expressio | |
| } | ||
| } | ||
|
|
||
| template <typename T> | ||
| [[nodiscard]] _CCCL_HOST_API inline auto make_host_buffer(cuda::stream_ref stream, cuda::std::size_t size) | ||
| { | ||
| using resource_t = cuda::mr::synchronous_resource_adapter<cuda::mr::legacy_pinned_memory_resource>; | ||
| resource_t resource{cuda::mr::legacy_pinned_memory_resource{cuda::device_ref{0}}}; | ||
| return cuda::make_buffer<T>(stream, resource, size, cuda::no_init); | ||
| } | ||
|
|
||
| template <typename T, typename RandomT = T> | ||
| [[nodiscard]] _CCCL_HOST_API inline auto | ||
| random_samples_buffer(cuda::stream_ref stream, cuda::std::size_t size, cuda::std::size_t first = 0) | ||
| { | ||
| auto result = make_host_buffer<T>(stream, size); | ||
| stream.sync(); | ||
|
|
||
| const auto generator = unittest::generate_random_sample<RandomT>{}; | ||
| for (cuda::std::size_t i = 0; i < size; ++i) | ||
| { | ||
| result[i] = static_cast<T>(generator(static_cast<unsigned int>(first + i))); | ||
|
Comment on lines
+59
to
+65
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. 🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect the target file and locate the helper types it uses.
git ls-files thrust/testing/cuda/cccl_runtime_test_helper.cuh
printf '\n--- file outline ---\n'
ast-grep outline thrust/testing/cuda/cccl_runtime_test_helper.cuh --view expanded || true
printf '\n--- relevant lines ---\n'
cat -n thrust/testing/cuda/cccl_runtime_test_helper.cuh | sed -n '1,220p'
printf '\n--- search for make_host_buffer and buffer accessors ---\n'
rg -n "make_host_buffer|get_unsynchronized|unsynchronized|operator\\[" thrust/testing -g'*.cuh' -g'*.cu' -g'*.cpp' -g'*.h' || trueRepository: NVIDIA/cccl Length of output: 5418 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Focus on the helper implementation and any nearby buffer type definitions/usages.
cat -n thrust/testing/cuda/cccl_runtime_test_helper.cuh | sed -n '1,180p'
printf '\n--- search exact accessor names in repo ---\n'
rg -n "get_unsynchronized|unsynchronized" thrust libcudacxx cub c python -g'*.h' -g'*.hpp' -g'*.hh' -g'*.cuh' -g'*.cu' -g'*.cpp' || trueRepository: NVIDIA/cccl Length of output: 9785 🌐 Web query:
💡 Result: In the NVIDIA CUDA Core Compute Libraries (CCCL), specifically within libcudacxx's runtime components, the Citations:
important: After Source: MCP tools |
||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| template <typename Buffer> | ||
| _CCCL_HOST_API inline void | ||
| assert_equal(cuda::stream_ref stream, Buffer& buffer, cuda::std::initializer_list<int> expected) | ||
|
|
@@ -57,6 +83,19 @@ assert_equal(cuda::stream_ref stream, Buffer& buffer, cuda::std::initializer_lis | |
| ASSERT_EQUAL(expected.begin()[i], actual[i]); | ||
| } | ||
| } | ||
|
|
||
| template <typename Buffer> | ||
| _CCCL_HOST_API inline void assert_filled(cuda::stream_ref stream, Buffer& buffer, typename Buffer::value_type expected) | ||
| { | ||
| std::vector<typename Buffer::value_type> actual(buffer.size()); | ||
| cuda::copy_bytes(stream, buffer, actual); | ||
| stream.sync(); | ||
|
|
||
| for (cuda::std::size_t i = 0; i < actual.size(); ++i) | ||
| { | ||
| ASSERT_EQUAL(expected, actual[i]); | ||
| } | ||
| } | ||
| } // namespace test_runtime | ||
|
|
||
| #define TEST_ASSERT_DEVICE(condition) ::test_runtime::assert_device((condition), #condition, __FILE__, __LINE__) | ||
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: NVIDIA/cccl
Length of output: 50367
🏁 Script executed:
Repository: NVIDIA/cccl
Length of output: 29273
🏁 Script executed:
Repository: NVIDIA/cccl
Length of output: 16289
🏁 Script executed:
Repository: NVIDIA/cccl
Length of output: 3535
🏁 Script executed:
Repository: NVIDIA/cccl
Length of output: 4192
🏁 Script executed:
Repository: NVIDIA/cccl
Length of output: 3223
🏁 Script executed:
Repository: NVIDIA/cccl
Length of output: 8730
important: thrust/testing/cuda/cccl_runtime_test_helper.cuh:48-57 thread
cuda::device_refthroughmake_host_buffer()andrandom_samples_buffer()instead of hard-codingcuda::device_ref{0}. These helpers are used with streams and device buffers bound tocurrent_test_device(), so non-zero-device runs can tie pinned host memory to the wrong device.Source: MCP tools