-
Notifications
You must be signed in to change notification settings - Fork 343
[CUDA][HIP] add test for uses of std::array on device code #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Check that we can use std::array on device code | ||
// | ||
// After libstdc++ 15, some internal asserts rely on function that are neither | ||
// constexpr nor device. This can trigger errors when using std::array members | ||
// on device code. | ||
// | ||
// This workaround is implemented in bits/c++config.h | ||
|
||
#include <stdio.h> | ||
|
||
#if __cplusplus >= 201103L | ||
|
||
#include <array> | ||
#include <assert.h> | ||
|
||
#if __cplusplus >= 201402L && STDLIB_VERSION >= 2014 | ||
constexpr | ||
#endif | ||
__host__ __device__ size_t | ||
test_array() { | ||
std::array<int, 4> A = {0, 1, 2, 3}; | ||
size_t N = A.size(); | ||
assert(N == 4); | ||
|
||
#if __cplusplus >= 201402L && STDLIB_VERSION >= 2014 | ||
const int fst = A[0]; | ||
assert(fst == 0); | ||
#endif | ||
|
||
#if __cplusplus >= 201703L && STDLIB_VERSION >= 2017 | ||
A[0] = 4; | ||
int snd = A[0]; | ||
assert(snd == 4); | ||
#endif | ||
return N; | ||
} | ||
|
||
__host__ __device__ void do_test() { | ||
// call the function in a constexpr and a non-constexpr context | ||
size_t M = test_array(); | ||
(void)(M); | ||
#if __cplusplus >= 201402L && STDLIB_VERSION >= 2014 | ||
constexpr size_t N = test_array(); | ||
(void)(N); | ||
#endif | ||
} | ||
|
||
__global__ void kernel() { do_test(); } | ||
|
||
int main() { | ||
kernel<<<32, 32>>>(); | ||
cudaError_t err = cudaDeviceSynchronize(); | ||
if (err != cudaSuccess) { | ||
printf("CUDA error %d\n", (int)err); | ||
return 1; | ||
} | ||
|
||
do_test(); | ||
|
||
printf("Success!\n"); | ||
return 0; | ||
} | ||
|
||
#else | ||
|
||
int main() { | ||
printf("Success!\n"); | ||
return 0; | ||
} | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Success! | ||
exit 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include "cuda2hip.h" | ||
#include "../CUDA/array.cu" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Success! | ||
exit 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef CUDA_2_HIP | ||
#define CUDA_2_HIP | ||
|
||
#include "hip/hip_runtime.h" | ||
|
||
#define cudaError_t hipError_t | ||
#define cudaSuccess hipSuccess | ||
#define cudaDeviceSynchronize hipDeviceSynchronize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wondering whether we have a systematic way to use CUDA tests for HIP. Using macro to map CUDA entries to HIP is not only tedious but may impose restrictions on how those CUDA tests are written. I am wondering whether we could hipify the .cu file instead. Currently /opt/rocm/bin/hipify-perl is available on the HIP buildbot. For each .cu file to be hipified, you can use add_custom_command to hipify it to a .hip file then test it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we try using hipify-clang instead? hipify-perl is going to be deprecated soon more than likely There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've just built the upstream buildbot image from https://github.com/ROCm/aomp/tree/aomp-dev/upstream-buildbots/Ubu22 and there is no hipify in Rocm's installation (it's quite a minimal install). I'll check if I install them if the tests work. I agree that it would be much better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tried with
One common error case was with multiple main definitions (even if they are on different ifdef branches): #include <stdio.h>
#if __cplusplus < 201103L
int main() { puts("foo\n"); return 0; }
#else
int main() { puts("bar\n"); return 0; }
#endif
I'll adapt these tests to run with |
||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can std::array be parameter type of kernel or device functions?
can it be used as non-constexpr stack variable in kernel or device functions?
if so, can we have testcases for those?