Skip to content

Commit f99185d

Browse files
griwesbrycelelbach
authored andcommitted
Thrust CMake conversion:
* Disable a test that crashes NVCC in C++14 mode. * Make `thrust::complex` be actually trivially copyable whenever possible.
1 parent 264eff4 commit f99185d

3 files changed

Lines changed: 50 additions & 30 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,13 @@ set(THRUST_PARTIALLY_IMPLEMENTED
386386
${THRUST_PARTIALLY_IMPLEMENTED_OMP}
387387
)
388388

389+
if ("CUDA" STREQUAL "${THRUST_DEVICE_SYSTEM}")
390+
if (14 EQUAL ${CMAKE_CXX_STANDARD})
391+
# temporarily disable until NVBug 2492786 is fixed
392+
list(APPEND THRUST_PARTIALLY_IMPLEMENTED tuple_algorithms)
393+
endif()
394+
endif ()
395+
389396
list(REMOVE_DUPLICATES THRUST_PARTIALLY_IMPLEMENTED)
390397

391398
foreach (THRUST_TEST_SOURCE IN LISTS THRUST_TESTS)
@@ -474,6 +481,7 @@ endforeach ()
474481

475482
# Handle examples
476483

484+
option(THRUST_EXAMPLE_FILECHECK_PATH "Path to the LLVM FileCheck utility." "")
477485
option(THRUST_ENABLE_EXAMPLES_WITH_RDC "Also build all examples with RDC." OFF)
478486

479487
list(APPEND THRUST_EXAMPLE_GLOBS examples/*.cu)

thrust/complex.h

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ struct complex
6868

6969
/* --- Constructors --- */
7070

71-
/*! Default construct a complex number.
72-
*/
73-
__host__ __device__
74-
complex();
75-
7671
/*! Construct a complex number with an imaginary part of 0.
7772
*
7873
* \param re The real part of the number.
@@ -88,13 +83,31 @@ struct complex
8883
__host__ __device__
8984
complex(const T& re, const T& im);
9085

86+
#if THRUST_CPP_DIALECT >= 2011
87+
/*! Default construct a complex number.
88+
*/
89+
complex() = default;
90+
91+
/*! This copy constructor copies from a \p complex with a type that is
92+
* convertible to this \p complex's \c value_type.
93+
*
94+
* \param z The \p complex to copy from.
95+
*/
96+
complex(const complex<T>& z) = default;
97+
#else
98+
/*! Default construct a complex number.
99+
*/
100+
__host__ __device__
101+
complex();
102+
91103
/*! This copy constructor copies from a \p complex with a type that is
92104
* convertible to this \p complex's \c value_type.
93105
*
94106
* \param z The \p complex to copy from.
95107
*/
96108
__host__ __device__
97109
complex(const complex<T>& z);
110+
#endif
98111

99112
/*! This converting copy constructor copies from a \p complex with a type
100113
* that is convertible to this \p complex's \c value_type.
@@ -114,15 +127,15 @@ struct complex
114127
*/
115128
__host__
116129
complex(const std::complex<T>& z);
117-
130+
118131
/*! This converting copy constructor copies from a <tt>std::complex</tt> with
119132
* a type that is convertible to this \p complex's \c value_type.
120133
*
121134
* \param z The \p complex to copy from.
122135
*
123136
* \tparam U is convertible to \c value_type.
124137
*/
125-
template <typename U>
138+
template <typename U>
126139
__host__
127140
complex(const std::complex<U>& z);
128141

@@ -138,13 +151,22 @@ struct complex
138151
__host__ __device__
139152
complex& operator=(const T& re);
140153

154+
#if THRUST_CPP_DIALECT >= 2011
155+
/*! Assign `z.real()` and `z.imag()` to the real and imaginary parts of this
156+
* \p complex respectively.
157+
*
158+
* \param z The \p complex to copy from.
159+
*/
160+
complex& operator=(const complex<T>& z) = default;
161+
#else
141162
/*! Assign `z.real()` and `z.imag()` to the real and imaginary parts of this
142163
* \p complex respectively.
143164
*
144165
* \param z The \p complex to copy from.
145166
*/
146167
__host__ __device__
147168
complex& operator=(const complex<T>& z);
169+
#endif
148170

149171
/*! Assign `z.real()` and `z.imag()` to the real and imaginary parts of this
150172
* \p complex respectively.
@@ -164,20 +186,19 @@ struct complex
164186
*/
165187
__host__
166188
complex& operator=(const std::complex<T>& z);
167-
189+
168190
/*! Assign `z.real()` and `z.imag()` to the real and imaginary parts of this
169191
* \p complex respectively.
170192
*
171193
* \param z The \p complex to copy from.
172194
*
173195
* \tparam U is convertible to \c value_type.
174196
*/
175-
template <typename U>
197+
template <typename U>
176198
__host__
177199
complex& operator=(const std::complex<U>& z);
178200

179201

180-
181202
/* --- Compound Assignment Operators --- */
182203

183204
/*! Adds a \p complex to this \p complex and assigns the result to this

thrust/detail/complex/complex.inl

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,14 @@ namespace thrust
2424

2525
/* --- Constructors --- */
2626

27+
#if THRUST_CPP_DIALECT < 2011
2728
template <typename T>
2829
__host__ __device__
2930
complex<T>::complex()
30-
#if THRUST_CPP_DIALECT >= 2011
31-
// Initialize the storage in the member initializer list using C++ unicorn
32-
// initialization. This allows `complex<T const>` to work.
33-
// We do a functional-style cast here to suppress conversion warnings.
34-
: data{T(), T()}
35-
{}
36-
#else
3731
{
3832
real(T());
3933
imag(T());
40-
}
34+
}
4135
#endif
4236

4337
template <typename T>
@@ -52,7 +46,7 @@ complex<T>::complex(const T& re)
5246
{
5347
real(re);
5448
imag(T());
55-
}
49+
}
5650
#endif
5751

5852

@@ -69,25 +63,20 @@ complex<T>::complex(const T& re, const T& im)
6963
real(re);
7064
imag(im);
7165
}
72-
#endif
66+
#endif
7367

68+
#if THRUST_CPP_DIALECT < 2011
7469
template <typename T>
7570
__host__ __device__
7671
complex<T>::complex(const complex<T>& z)
77-
#if THRUST_CPP_DIALECT >= 2011
78-
// Initialize the storage in the member initializer list using C++ unicorn
79-
// initialization. This allows `complex<T const>` to work.
80-
: data{z.real(), z.imag()}
81-
{}
82-
#else
8372
{
8473
real(z.real());
8574
imag(z.imag());
8675
}
87-
#endif
76+
#endif
8877

8978
template <typename T>
90-
template <typename U>
79+
template <typename U>
9180
__host__ __device__
9281
complex<T>::complex(const complex<U>& z)
9382
#if THRUST_CPP_DIALECT >= 2011
@@ -101,7 +90,7 @@ complex<T>::complex(const complex<U>& z)
10190
real(T(z.real()));
10291
imag(T(z.imag()));
10392
}
104-
#endif
93+
#endif
10594

10695
template <typename T>
10796
__host__
@@ -132,7 +121,7 @@ complex<T>::complex(const std::complex<U>& z)
132121
{
133122
real(T(z.real()));
134123
imag(T(z.imag()));
135-
}
124+
}
136125
#endif
137126

138127

@@ -148,6 +137,7 @@ complex<T>& complex<T>::operator=(const T& re)
148137
return *this;
149138
}
150139

140+
#if THRUST_CPP_DIALECT < 2011
151141
template <typename T>
152142
__host__ __device__
153143
complex<T>& complex<T>::operator=(const complex<T>& z)
@@ -156,6 +146,7 @@ complex<T>& complex<T>::operator=(const complex<T>& z)
156146
imag(z.imag());
157147
return *this;
158148
}
149+
#endif
159150

160151
template <typename T>
161152
template <typename U>

0 commit comments

Comments
 (0)