Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit 078c02b

Browse files
committed
add tests for legacy and per-thread default streams
1 parent 0c81f42 commit 078c02b

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

testing/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ function(thrust_add_test target_name_var test_name test_src thrust_target)
111111
if (("OMP" IN_LIST config_systems) OR ("TBB" IN_LIST config_systems))
112112
set_tests_properties(${test_target} PROPERTIES RUN_SERIAL ON)
113113
endif()
114+
115+
# Check for per-test script. Script will be included in the current scope
116+
# to allow custom property modifications.
117+
get_filename_component(test_cmake_script "${test_src}" NAME_WLE)
118+
set(test_cmake_script "${CMAKE_CURRENT_LIST_DIR}/${test_cmake_script}.cmake")
119+
if (EXISTS "${test_cmake_script}")
120+
include("${test_cmake_script}")
121+
endif()
114122
endfunction()
115123

116124
file(GLOB test_srcs

testing/cuda/stream_legacy.cu

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <unittest/unittest.h>
2+
#include <thrust/execution_policy.h>
3+
#include <thrust/system/cuda/detail/util.h>
4+
5+
#include <thread>
6+
7+
void verify_stream()
8+
{
9+
auto exec = thrust::device;
10+
auto stream = thrust::cuda_cub::stream(exec);
11+
ASSERT_EQUAL(stream, cudaStreamLegacy);
12+
}
13+
14+
void TestLegacyDefaultStream()
15+
{
16+
verify_stream();
17+
18+
std::thread t(verify_stream);
19+
t.join();
20+
}
21+
DECLARE_UNITTEST(TestLegacyDefaultStream);

testing/cuda/stream_per_thread.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This test should always use per-thread streams on NVCC.
2+
# NVC++ does not have an equivalent option.
3+
set_target_properties(${test_target} PROPERTIES
4+
COMPILE_OPTIONS
5+
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:--default-stream=per-thread>
6+
)

testing/cuda/stream_per_thread.cu

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <unittest/unittest.h>
2+
#include <thrust/execution_policy.h>
3+
#include <thrust/system/cuda/detail/util.h>
4+
5+
#include <thread>
6+
7+
void verify_stream()
8+
{
9+
auto exec = thrust::device;
10+
auto stream = thrust::cuda_cub::stream(exec);
11+
ASSERT_EQUAL(stream, cudaStreamPerThread);
12+
}
13+
14+
void TestPerThreadDefaultStream()
15+
{
16+
verify_stream();
17+
18+
std::thread t(verify_stream);
19+
t.join();
20+
}
21+
DECLARE_UNITTEST(TestPerThreadDefaultStream);

testing/cuda/stream_per_thread.mk

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CUDACC_FLAGS += --default-stream per-thread

0 commit comments

Comments
 (0)