[test-suite] r336029 - [CUDA] Add tests to ensure that std::min/max can be called from __host__ __device__ functions.
Justin Lebar via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 29 17:32:52 PDT 2018
Author: jlebar
Date: Fri Jun 29 17:32:52 2018
New Revision: 336029
URL: http://llvm.org/viewvc/llvm-project?rev=336029&view=rev
Log:
[CUDA] Add tests to ensure that std::min/max can be called from __host__ __device__ functions.
Summary: Tests for D48036 / PR37753.
Reviewers: rsmith
Subscribers: sanjoy, llvm-commits, lahwaacz, cfe-commits
Differential Revision: https://reviews.llvm.org/D48037
Modified:
test-suite/trunk/External/CUDA/algorithm.cu
Modified: test-suite/trunk/External/CUDA/algorithm.cu
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/External/CUDA/algorithm.cu?rev=336029&r1=336028&r2=336029&view=diff
==============================================================================
--- test-suite/trunk/External/CUDA/algorithm.cu (original)
+++ test-suite/trunk/External/CUDA/algorithm.cu Fri Jun 29 17:32:52 2018
@@ -17,10 +17,16 @@
__device__ void min() {
assert(std::min(0, 1) == 0);
}
+__host__ __device__ void min_hd() {
+ assert(std::min(0, 1) == 0);
+}
__device__ void max() {
assert(std::max(0, 1) == 1);
}
+__host__ __device__ void max_hd() {
+ assert(std::max(0, 1) == 1);
+}
// Clang has device-side shims implementing std::min and std::max for scalars
// starting in C++11, but doesn't implement minimax or std::min/max on
@@ -39,10 +45,27 @@ __device__ void cpp14_tests() {
#endif
}
+// Same tests as cpp14_tests, but from a host-device context.
+__host__ __device__ void cpp14_tests_hd() {
+#if __cplusplus >= 201402L && STDLIB_VERSION >= 2014
+ assert(std::greater<int>()(1, 0));
+ assert(std::min({5, 1, 10}) == 1);
+ assert(std::max({5, 1, 10}, std::less<int>()) == 10);
+
+ assert(std::minmax(1, 0).first == 0);
+ assert(std::minmax(1, 0).second == 1);
+ assert(std::minmax({0, 10, -10, 100}, std::less<int>()).first == -10);
+ assert(std::minmax({0, 10, -10, 100}, std::less<int>()).second == 100);
+#endif
+}
+
__global__ void kernel() {
min();
+ min_hd();
max();
+ max_hd();
cpp14_tests();
+ cpp14_tests_hd();
}
int main() {
@@ -52,6 +75,11 @@ int main() {
printf("CUDA error %d\n", (int)err);
return 1;
}
+
+ min_hd();
+ max_hd();
+ cpp14_tests_hd();
+
printf("Success!\n");
return 0;
}
More information about the llvm-commits
mailing list