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

Commit b223930

Browse files
authored
Merge pull request #1605 from allisonvacanti/if_target_prep
Add libcu++ dependency; initial round of `NV_IF_TARGET` ports.
2 parents 9ca1210 + 4cdf6de commit b223930

38 files changed

+640
-609
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "cub"]
22
path = dependencies/cub
33
url = ../cub.git
4+
[submodule "libcudacxx"]
5+
path = dependencies/libcudacxx
6+
url = ../libcudacxx.git

cmake/ThrustInstallRules.cmake

+29-21
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,35 @@ configure_file("${Thrust_SOURCE_DIR}/thrust/cmake/thrust-header-search.cmake.in"
2424
install(FILES "${Thrust_BINARY_DIR}/thrust/cmake/thrust-header-search.cmake"
2525
DESTINATION "${install_location}")
2626

27-
# Depending on how Thrust is configured, CUB's CMake scripts may or may not be
28-
# included, so maintain a set of CUB install rules in both projects. By default
29-
# CUB headers are installed alongside Thrust -- this may be disabled by turning
30-
# off THRUST_INSTALL_CUB_HEADERS.
31-
option(THRUST_INSTALL_CUB_HEADERS "Include cub headers when installing." ON)
27+
# Depending on how Thrust is configured, libcudacxx and CUB's CMake scripts may
28+
# or may not be include()'d, so force include their install rules when requested.
29+
# By default, these projects are installed alongside Thrust. This is controlled by
30+
# THRUST_INSTALL_CUB_HEADERS and THRUST_INSTALL_LIBCUDACXX_HEADERS.
31+
option(THRUST_INSTALL_CUB_HEADERS "Include CUB headers when installing." ON)
3232
if (THRUST_INSTALL_CUB_HEADERS)
33-
install(DIRECTORY "${Thrust_SOURCE_DIR}/dependencies/cub/cub"
34-
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
35-
FILES_MATCHING
36-
PATTERN "*.cuh"
37-
)
33+
# Use a function to limit scope of the CUB_*_DIR vars:
34+
function(_thrust_install_cub_headers)
35+
# Fake these for the logic in CUBInstallRules.cmake:
36+
set(CUB_SOURCE_DIR "${Thrust_SOURCE_DIR}/dependencies/cub/")
37+
set(CUB_BINARY_DIR "${Thrust_BINARY_DIR}/cub-config/")
38+
set(CUB_ENABLE_INSTALL_RULES ON)
39+
set(CUB_IN_THRUST OFF)
40+
include("${Thrust_SOURCE_DIR}/dependencies/cub/cmake/CubInstallRules.cmake")
41+
endfunction()
3842

39-
# Need to configure a file to store THRUST_INSTALL_HEADER_INFIX
40-
install(DIRECTORY "${Thrust_SOURCE_DIR}/dependencies/cub/cub/cmake/"
41-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cub"
42-
PATTERN cub-header-search EXCLUDE
43-
)
44-
set(install_location "${CMAKE_INSTALL_LIBDIR}/cmake/cub")
45-
configure_file("${Thrust_SOURCE_DIR}/dependencies/cub/cub/cmake/cub-header-search.cmake.in"
46-
"${Thrust_BINARY_DIR}/dependencies/cub/cub/cmake/cub-header-search.cmake"
47-
@ONLY)
48-
install(FILES "${Thrust_BINARY_DIR}/dependencies/cub/cub/cmake/cub-header-search.cmake"
49-
DESTINATION "${install_location}")
43+
_thrust_install_cub_headers()
44+
endif()
45+
46+
option(THRUST_INSTALL_LIBCUDACXX_HEADERS "Include libcudacxx headers when installing." ON)
47+
if (THRUST_INSTALL_LIBCUDACXX_HEADERS)
48+
# Use a function to limit scope of the libcudacxx_*_DIR vars:
49+
function(_thrust_install_libcudacxx_headers)
50+
# Fake these for the logic in libcudacxxInstallRules.cmake:
51+
set(libcudacxx_SOURCE_DIR "${Thrust_SOURCE_DIR}/dependencies/libcudacxx/")
52+
set(libcudacxx_BINARY_DIR "${Thrust_BINARY_DIR}/libcudacxx-config/")
53+
set(libcudacxx_ENABLE_INSTALL_RULES ON)
54+
include("${Thrust_SOURCE_DIR}/dependencies/libcudacxx/cmake/libcudacxxInstallRules.cmake")
55+
endfunction()
56+
57+
_thrust_install_libcudacxx_headers()
5058
endif()

dependencies/cub

Submodule cub updated 63 files

dependencies/libcudacxx

Submodule libcudacxx added at 05d48aa

testing/allocator.cu

+14-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#include <thrust/detail/config.h>
33
#include <thrust/device_malloc_allocator.h>
44
#include <thrust/system/cpp/vector.h>
5+
6+
#include <nv/target>
7+
58
#include <memory>
69

710
template <typename T>
@@ -60,9 +63,12 @@ DECLARE_VARIABLE_UNITTEST(TestAllocatorCustomCopyConstruct);
6063
template <typename T>
6164
struct my_allocator_with_custom_destroy
6265
{
63-
typedef T value_type;
64-
typedef T & reference;
65-
typedef const T & const_reference;
66+
// This is only used with thrust::cpp::vector:
67+
using system_type = thrust::cpp::tag;
68+
69+
using value_type = T;
70+
using reference = T &;
71+
using const_reference = const T &;
6672

6773
static bool g_state;
6874

@@ -80,9 +86,7 @@ struct my_allocator_with_custom_destroy
8086
__host__ __device__
8187
void destroy(T *)
8288
{
83-
#if !__CUDA_ARCH__
84-
g_state = true;
85-
#endif
89+
NV_IF_TARGET(NV_IS_HOST, (g_state = true;));
8690
}
8791

8892
value_type *allocate(std::ptrdiff_t n)
@@ -119,12 +123,14 @@ bool my_allocator_with_custom_destroy<T>::g_state = false;
119123
template <typename T>
120124
void TestAllocatorCustomDestroy(size_t n)
121125
{
126+
my_allocator_with_custom_destroy<T>::g_state = false;
127+
122128
{
123129
thrust::cpp::vector<T, my_allocator_with_custom_destroy<T> > vec(n);
124130
} // destroy everything
125131

126-
if (0 < n)
127-
ASSERT_EQUAL(true, my_allocator_with_custom_destroy<T>::g_state);
132+
// state should only be true when there are values to destroy:
133+
ASSERT_EQUAL(n > 0, my_allocator_with_custom_destroy<T>::g_state);
128134
}
129135
DECLARE_VARIABLE_UNITTEST(TestAllocatorCustomDestroy);
130136

@@ -203,7 +209,6 @@ void TestAllocatorTraitsRebind()
203209
}
204210
DECLARE_UNITTEST(TestAllocatorTraitsRebind);
205211

206-
#if THRUST_CPP_DIALECT >= 2011
207212
void TestAllocatorTraitsRebindCpp11()
208213
{
209214
ASSERT_EQUAL(
@@ -251,5 +256,3 @@ void TestAllocatorTraitsRebindCpp11()
251256
);
252257
}
253258
DECLARE_UNITTEST(TestAllocatorTraitsRebindCpp11);
254-
#endif // C++11
255-

testing/cuda/pair_sort.cu

+6-16
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@
44
#include <thrust/execution_policy.h>
55

66

7-
template<typename ExecutionPolicy, typename Iterator1, typename Iterator2>
7+
template<typename ExecutionPolicy, typename Iterator>
88
__global__
9-
void stable_sort_kernel(ExecutionPolicy exec, Iterator1 first, Iterator1 last, Iterator2 is_supported)
9+
void stable_sort_kernel(ExecutionPolicy exec, Iterator first, Iterator last)
1010
{
11-
#if (__CUDA_ARCH__ >= 200)
12-
*is_supported = true;
1311
thrust::stable_sort(exec, first, last);
14-
#else
15-
*is_supported = false;
16-
#endif
1712
}
1813

1914

@@ -43,19 +38,14 @@ void TestPairStableSortDevice(ExecutionPolicy exec)
4338

4439
thrust::device_vector<P> d_pairs = h_pairs;
4540

46-
thrust::device_vector<bool> is_supported(1);
47-
48-
stable_sort_kernel<<<1,1>>>(exec, d_pairs.begin(), d_pairs.end(), is_supported.begin());
41+
stable_sort_kernel<<<1,1>>>(exec, d_pairs.begin(), d_pairs.end());
4942
cudaError_t const err = cudaDeviceSynchronize();
5043
ASSERT_EQUAL(cudaSuccess, err);
5144

52-
if(is_supported[0])
53-
{
54-
// sort on the host
55-
thrust::stable_sort(h_pairs.begin(), h_pairs.end());
45+
// sort on the host
46+
thrust::stable_sort(h_pairs.begin(), h_pairs.end());
5647

57-
ASSERT_EQUAL_QUIET(h_pairs, d_pairs);
58-
}
48+
ASSERT_EQUAL_QUIET(h_pairs, d_pairs);
5949
};
6050

6151

testing/cuda/pair_sort_by_key.cu

+7-17
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@
66
#include <thrust/execution_policy.h>
77

88

9-
template<typename ExecutionPolicy, typename Iterator1, typename Iterator2, typename Iterator3>
9+
template<typename ExecutionPolicy, typename Iterator1, typename Iterator2>
1010
__global__
11-
void stable_sort_by_key_kernel(ExecutionPolicy exec, Iterator1 keys_first, Iterator1 keys_last, Iterator2 values_first, Iterator3 is_supported)
11+
void stable_sort_by_key_kernel(ExecutionPolicy exec, Iterator1 keys_first, Iterator1 keys_last, Iterator2 values_first)
1212
{
13-
#if (__CUDA_ARCH__ >= 200)
14-
*is_supported = true;
1513
thrust::stable_sort_by_key(exec, keys_first, keys_last, values_first);
16-
#else
17-
*is_supported = false;
18-
#endif
1914
}
2015

2116

@@ -51,21 +46,16 @@ void TestPairStableSortByKeyDevice(ExecutionPolicy exec)
5146
thrust::device_vector<P> d_pairs = h_pairs;
5247
thrust::device_vector<int> d_values = h_values;
5348

54-
thrust::device_vector<bool> is_supported(1);
55-
5649
// sort on the device
57-
stable_sort_by_key_kernel<<<1,1>>>(exec, d_pairs.begin(), d_pairs.end(), d_values.begin(), is_supported.begin());
50+
stable_sort_by_key_kernel<<<1,1>>>(exec, d_pairs.begin(), d_pairs.end(), d_values.begin());
5851
cudaError_t const err = cudaDeviceSynchronize();
5952
ASSERT_EQUAL(cudaSuccess, err);
6053

61-
if(is_supported[0])
62-
{
63-
// sort on the host
64-
thrust::stable_sort_by_key(h_pairs.begin(), h_pairs.end(), h_values.begin());
54+
// sort on the host
55+
thrust::stable_sort_by_key(h_pairs.begin(), h_pairs.end(), h_values.begin());
6556

66-
ASSERT_EQUAL_QUIET(h_pairs, d_pairs);
67-
ASSERT_EQUAL(h_values, d_values);
68-
}
57+
ASSERT_EQUAL_QUIET(h_pairs, d_pairs);
58+
ASSERT_EQUAL(h_values, d_values);
6959
};
7060

7161

testing/cuda/partition.cu

+24-42
Original file line numberDiff line numberDiff line change
@@ -286,16 +286,11 @@ void TestPartitionCopyStencilDeviceNoSync()
286286
DECLARE_UNITTEST(TestPartitionCopyStencilDeviceNoSync);
287287

288288

289-
template<typename ExecutionPolicy, typename Iterator1, typename Predicate, typename Iterator2, typename Iterator3>
289+
template<typename ExecutionPolicy, typename Iterator1, typename Predicate, typename Iterator2>
290290
__global__
291-
void stable_partition_kernel(ExecutionPolicy exec, Iterator1 first, Iterator1 last, Predicate pred, Iterator2 result, Iterator3 is_supported)
291+
void stable_partition_kernel(ExecutionPolicy exec, Iterator1 first, Iterator1 last, Predicate pred, Iterator2 result)
292292
{
293-
#if (__CUDA_ARCH__ >= 200)
294-
*is_supported = true;
295293
*result = thrust::stable_partition(exec, first, last, pred);
296-
#else
297-
*is_supported = false;
298-
#endif
299294
}
300295

301296

@@ -313,24 +308,20 @@ void TestStablePartitionDevice(ExecutionPolicy exec)
313308
data[4] = 2;
314309

315310
thrust::device_vector<iterator> result(1);
316-
thrust::device_vector<bool> is_supported(1);
317-
318-
stable_partition_kernel<<<1,1>>>(exec, data.begin(), data.end(), is_even<T>(), result.begin(), is_supported.begin());
311+
312+
stable_partition_kernel<<<1,1>>>(exec, data.begin(), data.end(), is_even<T>(), result.begin());
319313
cudaError_t const err = cudaDeviceSynchronize();
320314
ASSERT_EQUAL(cudaSuccess, err);
321315

322-
if(is_supported[0])
323-
{
324-
thrust::device_vector<T> ref(5);
325-
ref[0] = 2;
326-
ref[1] = 2;
327-
ref[2] = 1;
328-
ref[3] = 1;
329-
ref[4] = 1;
316+
thrust::device_vector<T> ref(5);
317+
ref[0] = 2;
318+
ref[1] = 2;
319+
ref[2] = 1;
320+
ref[3] = 1;
321+
ref[4] = 1;
330322

331-
ASSERT_EQUAL(2, (iterator)result[0] - data.begin());
332-
ASSERT_EQUAL(ref, data);
333-
}
323+
ASSERT_EQUAL(2, (iterator)result[0] - data.begin());
324+
ASSERT_EQUAL(ref, data);
334325
}
335326

336327

@@ -355,16 +346,11 @@ void TestStablePartitionDeviceNoSync()
355346
DECLARE_UNITTEST(TestStablePartitionDeviceNoSync);
356347

357348

358-
template<typename ExecutionPolicy, typename Iterator1, typename Iterator2, typename Predicate, typename Iterator3, typename Iterator4>
349+
template<typename ExecutionPolicy, typename Iterator1, typename Iterator2, typename Predicate, typename Iterator3>
359350
__global__
360-
void stable_partition_kernel(ExecutionPolicy exec, Iterator1 first, Iterator1 last, Iterator2 stencil_first, Predicate pred, Iterator3 result, Iterator4 is_supported)
351+
void stable_partition_kernel(ExecutionPolicy exec, Iterator1 first, Iterator1 last, Iterator2 stencil_first, Predicate pred, Iterator3 result)
361352
{
362-
#if (__CUDA_ARCH__ >= 200)
363-
*is_supported = true;
364353
*result = thrust::stable_partition(exec, first, last, stencil_first, pred);
365-
#else
366-
*is_supported = false;
367-
#endif
368354
}
369355

370356

@@ -389,24 +375,20 @@ void TestStablePartitionStencilDevice(ExecutionPolicy exec)
389375
stencil[4] = 2;
390376

391377
thrust::device_vector<iterator> result(1);
392-
thrust::device_vector<bool> is_supported(1);
393-
394-
stable_partition_kernel<<<1,1>>>(exec, data.begin(), data.end(), stencil.begin(), is_even<T>(), result.begin(), is_supported.begin());
378+
379+
stable_partition_kernel<<<1,1>>>(exec, data.begin(), data.end(), stencil.begin(), is_even<T>(), result.begin());
395380
cudaError_t const err = cudaDeviceSynchronize();
396381
ASSERT_EQUAL(cudaSuccess, err);
397382

398-
if(is_supported[0])
399-
{
400-
thrust::device_vector<T> ref(5);
401-
ref[0] = 1;
402-
ref[1] = 1;
403-
ref[2] = 0;
404-
ref[3] = 0;
405-
ref[4] = 0;
383+
thrust::device_vector<T> ref(5);
384+
ref[0] = 1;
385+
ref[1] = 1;
386+
ref[2] = 0;
387+
ref[3] = 0;
388+
ref[4] = 0;
406389

407-
ASSERT_EQUAL(2, (iterator)result[0] - data.begin());
408-
ASSERT_EQUAL(ref, data);
409-
}
390+
ASSERT_EQUAL(2, (iterator)result[0] - data.begin());
391+
ASSERT_EQUAL(ref, data);
410392
}
411393

412394

testing/cuda/sort.cu

+7-17
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@
44
#include <thrust/execution_policy.h>
55

66

7-
template<typename ExecutionPolicy, typename Iterator, typename Compare, typename Iterator2>
7+
template<typename ExecutionPolicy, typename Iterator, typename Compare>
88
__global__
9-
void sort_kernel(ExecutionPolicy exec, Iterator first, Iterator last, Compare comp, Iterator2 is_supported)
9+
void sort_kernel(ExecutionPolicy exec, Iterator first, Iterator last, Compare comp)
1010
{
11-
#if (__CUDA_ARCH__ >= 200)
12-
*is_supported = true;
1311
thrust::sort(exec, first, last, comp);
14-
#else
15-
*is_supported = false;
16-
#endif
1712
}
1813

1914

@@ -34,19 +29,14 @@ void TestComparisonSortDevice(ExecutionPolicy exec, const size_t n, Compare comp
3429
thrust::host_vector<T> h_data = unittest::random_integers<T>(n);
3530
thrust::device_vector<T> d_data = h_data;
3631

37-
thrust::device_vector<bool> is_supported(1);
38-
39-
sort_kernel<<<1,1>>>(exec, d_data.begin(), d_data.end(), comp, is_supported.begin());
32+
sort_kernel<<<1,1>>>(exec, d_data.begin(), d_data.end(), comp);
4033
cudaError_t const err = cudaDeviceSynchronize();
4134
ASSERT_EQUAL(cudaSuccess, err);
4235

4336

44-
if(is_supported[0])
45-
{
46-
thrust::sort(h_data.begin(), h_data.end(), comp);
47-
48-
ASSERT_EQUAL(h_data, d_data);
49-
}
37+
thrust::sort(h_data.begin(), h_data.end(), comp);
38+
39+
ASSERT_EQUAL(h_data, d_data);
5040
};
5141

5242

@@ -163,7 +153,7 @@ void TestComparisonSortCudaStreams()
163153
cudaStreamSynchronize(s);
164154

165155
ASSERT_EQUAL(true, thrust::is_sorted(keys.begin(), keys.end(), my_less<int>()));
166-
156+
167157
cudaStreamDestroy(s);
168158
}
169159
DECLARE_UNITTEST(TestComparisonSortCudaStreams);

0 commit comments

Comments
 (0)