File tree 4 files changed +89
-0
lines changed
4 files changed +89
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ macro(create_local_cuda_tests VariantSuffix)
63
63
list (APPEND CUDA_LOCAL_TESTS assert)
64
64
list (APPEND CUDA_LOCAL_TESTS axpy)
65
65
list (APPEND CUDA_LOCAL_TESTS algorithm)
66
+ list (APPEND CUDA_LOCAL_TESTS array)
66
67
list (APPEND CUDA_LOCAL_TESTS cmath)
67
68
list (APPEND CUDA_LOCAL_TESTS complex)
68
69
list (APPEND CUDA_LOCAL_TESTS math_h)
Original file line number Diff line number Diff line change
1
+ // Check that we can use std::array on device code
2
+ //
3
+ // After libstdc++ 15, some internal asserts rely on function that are neither
4
+ // constexpr nor device. This can trigger errors when using std::array members
5
+ // on device code.
6
+ //
7
+ // This workaround is implemented in bits/c++config.h
8
+
9
+ #include < stdio.h>
10
+
11
+ #if __cplusplus >= 201103L
12
+
13
+ #include < array>
14
+ #include < assert.h>
15
+
16
+ #if __cplusplus >= 201402L && STDLIB_VERSION >= 2014
17
+ // call the function in a constexpr and a non-constexpr context
18
+ #define TEST (expr ) \
19
+ do { \
20
+ size_t M = expr; \
21
+ (void )(M); \
22
+ constexpr size_t N = expr; \
23
+ (void )(N); \
24
+ } while (0 )
25
+ #define MAYBE_CONSTEXPR constexpr
26
+ #else
27
+ #define TEST (expr ) \
28
+ do { \
29
+ size_t M = expr; \
30
+ (void )(M); \
31
+ } while (0 )
32
+ #define MAYBE_CONSTEXPR
33
+ #endif
34
+
35
+ MAYBE_CONSTEXPR __host__ __device__ size_t test_array () {
36
+ // Before C++17 only "operator[] const" is constexpr (thus available on
37
+ // device).
38
+ #if __cplusplus < 201703L && STDLIB_VERSION < 2017
39
+ const
40
+ #endif
41
+ std::array<int , 4 >
42
+ A = {0 , 1 , 2 , 3 };
43
+
44
+ size_t N = A.size ();
45
+ assert (N == 4 );
46
+
47
+ #if __cplusplus >= 201402L && STDLIB_VERSION >= 2014
48
+ int fst = A[0 ];
49
+ assert (fst == 0 );
50
+ #endif
51
+
52
+ #if __cplusplus >= 201703L && STDLIB_VERSION >= 2017
53
+ A[0 ] = 4 ;
54
+ int snd = A[0 ];
55
+ assert (snd == 4 );
56
+ #endif
57
+ return N;
58
+ }
59
+
60
+ __host__ __device__ void do_all_tests () { TEST (test_array ()); }
61
+
62
+ __global__ void kernel () { do_all_tests (); }
63
+
64
+ int main () {
65
+ kernel<<<32 , 32 >>> ();
66
+ cudaError_t err = cudaDeviceSynchronize ();
67
+ if (err != cudaSuccess) {
68
+ printf (" CUDA error %d\n " , (int )err);
69
+ return 1 ;
70
+ }
71
+
72
+ do_all_tests ();
73
+
74
+ printf (" Success!\n " );
75
+ return 0 ;
76
+ }
77
+
78
+ #else
79
+
80
+ int main () {
81
+ printf (" Success!\n " );
82
+ return 0 ;
83
+ }
84
+
85
+ #endif
Original file line number Diff line number Diff line change
1
+ Success!
2
+ exit 0
Original file line number Diff line number Diff line change @@ -97,6 +97,7 @@ macro(create_local_hip_tests VariantSuffix)
97
97
endforeach ()
98
98
99
99
list (APPEND CUDA_LOCAL_TESTS algorithm)
100
+ list (APPEND CUDA_LOCAL_TESTS array)
100
101
list (APPEND CUDA_LOCAL_TESTS cmath)
101
102
list (APPEND CUDA_LOCAL_TESTS complex)
102
103
list (APPEND CUDA_LOCAL_TESTS math_h)
You can’t perform that action at this time.
0 commit comments