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

Commit 5fe780d

Browse files
authored
Merge pull request #172 from NVIDIA/bugfix/abi_breaking_changes
Fix issues in the library that require an ABI break. This introduces ABI version 4.
2 parents 2863fde + b302b19 commit 5fe780d

File tree

7 files changed

+217
-26
lines changed

7 files changed

+217
-26
lines changed

.upstream-tests/test/cuda/pipeline_arrive_on.pass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
// UNSUPPORTED: pre-sm-70
1111

12+
// Remove after bump to version 4
13+
#define _LIBCUDACXX_CUDA_ABI_VERSION 3
14+
1215
#pragma nv_diag_suppress static_var_with_dynamic_init
1316
#pragma nv_diag_suppress declared_but_not_referenced
1417

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// <cuda/std/complex>
10+
11+
// template<class T>
12+
// class complex
13+
// {
14+
// public:
15+
// typedef T value_type;
16+
// ...
17+
// };
18+
19+
#include <cuda/std/complex>
20+
#include <cuda/std/type_traits>
21+
22+
#include "test_macros.h"
23+
24+
template <class T>
25+
__host__ __device__ void
26+
test()
27+
{
28+
typedef cuda::std::complex<T> C;
29+
30+
static_assert(sizeof(C) == (sizeof(T)*2), "wrong size");
31+
static_assert(alignof(C) == (alignof(T)*2), "misaligned");
32+
}
33+
34+
int main(int, char**)
35+
{
36+
test<float>();
37+
test<double>();
38+
// CUDA treats long double as double
39+
// test<long double>();
40+
41+
return 0;
42+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// <cuda/std/complex>
10+
11+
// template<class T>
12+
// class complex
13+
// {
14+
// public:
15+
// typedef T value_type;
16+
// ...
17+
// };
18+
19+
#define _LIBCUDACXX_CUDA_ABI_VERSION 3
20+
21+
#include <cuda/std/complex>
22+
#include <cuda/std/type_traits>
23+
24+
#include "test_macros.h"
25+
26+
template <class T>
27+
__host__ __device__ void
28+
test()
29+
{
30+
typedef cuda::std::complex<T> C;
31+
32+
static_assert(sizeof(C) == (sizeof(T)*2), "wrong size");
33+
static_assert(alignof(C) == (alignof(T)), "misaligned");
34+
}
35+
36+
int main(int, char**)
37+
{
38+
test<float>();
39+
test<double>();
40+
// CUDA treats long double as double
41+
// test<long double>();
42+
43+
return 0;
44+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++98, c++03, c++11
10+
// <cuda/std/chrono>
11+
12+
#pragma nv_diag_suppress declared_but_not_referenced
13+
#pragma nv_diag_suppress set_but_not_used
14+
15+
#define _LIBCUDACXX_CUDA_ABI_VERSION 3
16+
17+
#include <cuda/std/chrono>
18+
#include <cuda/std/type_traits>
19+
#include <cuda/std/cassert>
20+
21+
#include "test_macros.h"
22+
template <typename T>
23+
__host__ __device__
24+
constexpr bool unused(T &&) {return true;}
25+
26+
int main(int, char**)
27+
{
28+
using namespace cuda::std::literals::chrono_literals;
29+
30+
// long long ABI v3 check
31+
{
32+
constexpr auto _h = 3h;
33+
constexpr auto _min = 3min;
34+
constexpr auto _s = 3s;
35+
constexpr auto _ms = 3ms;
36+
constexpr auto _us = 3us;
37+
constexpr auto _ns = 3ns;
38+
39+
unused(_h);
40+
unused(_min);
41+
unused(_s);
42+
unused(_ms);
43+
unused(_us);
44+
unused(_ns);
45+
46+
static_assert(cuda::std::is_same< decltype(_h.count()), cuda::std::chrono::hours::rep >::value, "");
47+
static_assert(cuda::std::is_same< decltype(_min.count()), cuda::std::chrono::minutes::rep >::value, "");
48+
static_assert(cuda::std::is_same< decltype(_s.count()), cuda::std::chrono::seconds::rep >::value, "");
49+
static_assert(cuda::std::is_same< decltype(_ms.count()), cuda::std::chrono::milliseconds::rep >::value, "");
50+
static_assert(cuda::std::is_same< decltype(_us.count()), cuda::std::chrono::microseconds::rep >::value, "");
51+
static_assert(cuda::std::is_same< decltype(_ns.count()), cuda::std::chrono::nanoseconds::rep >::value, "");
52+
53+
static_assert ( cuda::std::is_same<decltype(3h), cuda::std::chrono::hours>::value, "" );
54+
static_assert ( cuda::std::is_same<decltype(3min), cuda::std::chrono::minutes>::value, "" );
55+
static_assert ( cuda::std::is_same<decltype(3s), cuda::std::chrono::seconds>::value, "" );
56+
static_assert ( cuda::std::is_same<decltype(3ms), cuda::std::chrono::milliseconds>::value, "" );
57+
static_assert ( cuda::std::is_same<decltype(3us), cuda::std::chrono::microseconds>::value, "" );
58+
static_assert ( cuda::std::is_same<decltype(3ns), cuda::std::chrono::nanoseconds>::value, "" );
59+
}
60+
61+
// long double ABI v3 check
62+
{
63+
constexpr auto _h = 3.0h;
64+
constexpr auto _min = 3.0min;
65+
constexpr auto _s = 3.0s;
66+
constexpr auto _ms = 3.0ms;
67+
constexpr auto _us = 3.0us;
68+
constexpr auto _ns = 3.0ns;
69+
70+
unused(_h);
71+
unused(_min);
72+
unused(_s);
73+
unused(_ms);
74+
unused(_us);
75+
unused(_ns);
76+
77+
using cuda::std::ratio;
78+
using cuda::std::milli;
79+
using cuda::std::micro;
80+
using cuda::std::nano;
81+
82+
static_assert(cuda::std::is_same< decltype(_h.count()), cuda::std::chrono::duration<long double, ratio<3600>>::rep >::value, "");
83+
static_assert(cuda::std::is_same< decltype(_min.count()), cuda::std::chrono::duration<long double, ratio< 60>>::rep >::value, "");
84+
// static_assert(cuda::std::is_same< decltype(s.count()), cuda::std::chrono::duration<long double >::rep >::value, "");
85+
static_assert(cuda::std::is_same< decltype(_ms.count()), cuda::std::chrono::duration<long double, milli>::rep >::value, "");
86+
static_assert(cuda::std::is_same< decltype(_us.count()), cuda::std::chrono::duration<long double, micro>::rep >::value, "");
87+
static_assert(cuda::std::is_same< decltype(_ns.count()), cuda::std::chrono::duration<long double, nano>::rep >::value, "");
88+
}
89+
90+
return 0;
91+
}

include/cuda/std/detail/__config

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,21 @@
109109
(_LIBCUDACXX_CUDA_API_VERSION % 1000)
110110

111111
#ifndef _LIBCUDACXX_CUDA_ABI_VERSION_LATEST
112-
# define _LIBCUDACXX_CUDA_ABI_VERSION_LATEST 3
112+
# define _LIBCUDACXX_CUDA_ABI_VERSION_LATEST 4
113113
#endif
114114

115115
#ifdef _LIBCUDACXX_CUDA_ABI_VERSION
116-
# if _LIBCUDACXX_CUDA_ABI_VERSION != 2 && _LIBCUDACXX_CUDA_ABI_VERSION != 3
116+
# if _LIBCUDACXX_CUDA_ABI_VERSION != 2 && _LIBCUDACXX_CUDA_ABI_VERSION != 3 && _LIBCUDACXX_CUDA_ABI_VERSION != 4
117117
# error Unsupported libcu++ ABI version requested. Please define _LIBCUDACXX_CUDA_ABI_VERSION to either 2 or 3.
118118
# endif
119119
#else
120120
# define _LIBCUDACXX_CUDA_ABI_VERSION _LIBCUDACXX_CUDA_ABI_VERSION_LATEST
121121
#endif
122122

123123
#ifdef _LIBCUDACXX_PIPELINE_ASSUMED_ABI_VERSION
124-
#if _LIBCUDACXX_PIPELINE_ASSUMED_ABI_VERSION != _LIBCUDACXX_CUDA_ABI_VERSION
125-
#error cuda_pipeline.h has assumed a different libcu++ ABI version than provided by this library. To fix this, please include a libcu++ header before including cuda_pipeline.h, or upgrade to a version of the toolkit this version of libcu++ shipped in.
126-
#endif
124+
# if _LIBCUDACXX_PIPELINE_ASSUMED_ABI_VERSION != _LIBCUDACXX_CUDA_ABI_VERSION
125+
# error cuda_pipeline.h has assumed a different libcu++ ABI version than provided by this library. To fix this, please include a libcu++ header before including cuda_pipeline.h, or upgrade to a version of the toolkit this version of libcu++ shipped in.
126+
# endif
127127
#endif
128128

129129
#ifndef _LIBCUDACXX_CUDA_ABI_NAMESPACE

libcxx/include/chrono

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,12 @@ struct _FilesystemClock;
843843
_LIBCUDACXX_END_NAMESPACE_FILESYSTEM
844844
#endif // !_LIBCUDACXX_CXX03_LANG
845845

846+
# if _LIBCUDACXX_CUDA_ABI_VERSION > 3
847+
# define _LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T double
848+
# else
849+
# define _LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T long double
850+
# endif
851+
846852
_LIBCUDACXX_BEGIN_NAMESPACE_STD
847853

848854
namespace chrono
@@ -1013,7 +1019,7 @@ round(const duration<_Rep, _Period>& __d)
10131019
return __upper;
10141020
return __lower.count() & 1 ? __upper : __lower;
10151021
}
1016-
#endif // _LIBCUDACXX_STD_VER > 11
1022+
#endif // _LIBCUDACXX_STD_VER > 11
10171023

10181024
// duration
10191025

@@ -2539,7 +2545,7 @@ inline constexpr days year_month_day::__to_days() const noexcept
25392545
static_assert(std::numeric_limits<unsigned>::digits >= 18, "");
25402546
static_assert(std::numeric_limits<int>::digits >= 20 , "");
25412547

2542-
// nvcc doesn't allow ODR using constexpr globals. Therefore,
2548+
// nvcc doesn't allow ODR using constexpr globals. Therefore,
25432549
// make a temporary initialized from the global
25442550
auto constexpr __Feb = February;
25452551
const int __yr = static_cast<int>(__y) - (__m <= __Feb);
@@ -2705,7 +2711,7 @@ chrono::day year_month_day_last::day() const noexcept
27052711
chrono::day(31), chrono::day(30), chrono::day(31)
27062712
};
27072713

2708-
// nvcc doesn't allow ODR using constexpr globals. Therefore,
2714+
// nvcc doesn't allow ODR using constexpr globals. Therefore,
27092715
// make a temporary initialized from the global
27102716
auto constexpr __Feb = February;
27112717
return month() != __Feb || !__y.is_leap() ?
@@ -3184,7 +3190,6 @@ constexpr hours make24(const hours& __h, bool __is_pm) noexcept
31843190
}
31853191
#endif // _LIBCUDACXX_STD_VER > 11
31863192
} // chrono
3187-
31883193
#if _LIBCUDACXX_STD_VER > 11
31893194

31903195
// GCC 5 and 6 warn (and then error) on us using the standard reserved UDL names,
@@ -3208,9 +3213,9 @@ inline namespace literals
32083213
}
32093214

32103215
_LIBCUDACXX_INLINE_VISIBILITY
3211-
constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h)
3216+
constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, ratio<3600,1>> operator""h(long double __h)
32123217
{
3213-
return chrono::duration<long double, ratio<3600,1>>(__h);
3218+
return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, ratio<3600,1>>(__h);
32143219
}
32153220

32163221
_LIBCUDACXX_INLINE_VISIBILITY
@@ -3220,9 +3225,9 @@ inline namespace literals
32203225
}
32213226

32223227
_LIBCUDACXX_INLINE_VISIBILITY
3223-
constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m)
3228+
constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, ratio<60,1>> operator""min(long double __m)
32243229
{
3225-
return chrono::duration<long double, ratio<60,1>> (__m);
3230+
return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, ratio<60,1>> (__m);
32263231
}
32273232

32283233
_LIBCUDACXX_INLINE_VISIBILITY
@@ -3232,9 +3237,9 @@ inline namespace literals
32323237
}
32333238

32343239
_LIBCUDACXX_INLINE_VISIBILITY
3235-
constexpr chrono::duration<long double> operator""s(long double __s)
3240+
constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T> operator""s(long double __s)
32363241
{
3237-
return chrono::duration<long double> (__s);
3242+
return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T> (__s);
32383243
}
32393244

32403245
_LIBCUDACXX_INLINE_VISIBILITY
@@ -3244,9 +3249,9 @@ inline namespace literals
32443249
}
32453250

32463251
_LIBCUDACXX_INLINE_VISIBILITY
3247-
constexpr chrono::duration<long double, milli> operator""ms(long double __ms)
3252+
constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, milli> operator""ms(long double __ms)
32483253
{
3249-
return chrono::duration<long double, milli>(__ms);
3254+
return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, milli>(__ms);
32503255
}
32513256

32523257
_LIBCUDACXX_INLINE_VISIBILITY
@@ -3256,9 +3261,9 @@ inline namespace literals
32563261
}
32573262

32583263
_LIBCUDACXX_INLINE_VISIBILITY
3259-
constexpr chrono::duration<long double, micro> operator""us(long double __us)
3264+
constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, micro> operator""us(long double __us)
32603265
{
3261-
return chrono::duration<long double, micro> (__us);
3266+
return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, micro> (__us);
32623267
}
32633268

32643269
_LIBCUDACXX_INLINE_VISIBILITY
@@ -3268,9 +3273,9 @@ inline namespace literals
32683273
}
32693274

32703275
_LIBCUDACXX_INLINE_VISIBILITY
3271-
constexpr chrono::duration<long double, nano> operator""ns(long double __ns)
3276+
constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, nano> operator""ns(long double __ns)
32723277
{
3273-
return chrono::duration<long double, nano> (__ns);
3278+
return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, nano> (__ns);
32743279
}
32753280

32763281
#if _LIBCUDACXX_STD_VER > 17 && !defined(_LIBCUDACXX_HAS_NO_CXX20_CHRONO_LITERALS)

libcxx/include/complex

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,15 @@ template<class T, class charT, class traits>
253253
#pragma GCC system_header
254254
#endif
255255

256+
# if _LIBCUDACXX_CUDA_ABI_VERSION > 3
257+
# define _LIBCUDACXX_COMPLEX_ALIGNAS(V) _ALIGNAS(V)
258+
# else
259+
# define _LIBCUDACXX_COMPLEX_ALIGNAS(V)
260+
# endif
261+
256262
_LIBCUDACXX_BEGIN_NAMESPACE_STD
257263

258-
template<class _Tp> class _LIBCUDACXX_TEMPLATE_VIS complex;
264+
template<class _Tp> class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_COMPLEX_ALIGNAS(2*sizeof(_Tp)) complex;
259265

260266
template<class _Tp> _LIBCUDACXX_INLINE_VISIBILITY
261267
complex<_Tp> operator*(const complex<_Tp>& __z, const complex<_Tp>& __w);
@@ -264,7 +270,7 @@ template<class _Tp> _LIBCUDACXX_INLINE_VISIBILITY
264270
complex<_Tp> operator/(const complex<_Tp>& __x, const complex<_Tp>& __y);
265271

266272
template<class _Tp>
267-
class _LIBCUDACXX_TEMPLATE_VIS complex
273+
class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_COMPLEX_ALIGNAS(2*sizeof(_Tp)) complex
268274
{
269275
public:
270276
typedef _Tp value_type;
@@ -328,7 +334,7 @@ template<> class complex<long double>;
328334
#endif // _LIBCUDACXX_HAS_COMPLEX_LONG_DOUBLE
329335

330336
template<>
331-
class _LIBCUDACXX_TEMPLATE_VIS complex<float>
337+
class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_COMPLEX_ALIGNAS(2*sizeof(float)) complex<float>
332338
{
333339
float __re_;
334340
float __im_;
@@ -386,7 +392,7 @@ public:
386392
};
387393

388394
template<>
389-
class _LIBCUDACXX_TEMPLATE_VIS complex<double>
395+
class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_COMPLEX_ALIGNAS(2*sizeof(double)) complex<double>
390396
{
391397
double __re_;
392398
double __im_;
@@ -444,7 +450,7 @@ public:
444450
};
445451

446452
template<>
447-
class _LIBCUDACXX_TEMPLATE_VIS complex<long double>
453+
class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_COMPLEX_ALIGNAS(2*sizeof(long double)) complex<long double>
448454
{
449455
#ifndef _LIBCUDACXX_HAS_COMPLEX_LONG_DOUBLE
450456
public:

0 commit comments

Comments
 (0)