[PATCH] D48037: [CUDA] Add tests to ensure that std::min/max can be called from __host__ __device__ functions.

Justin Lebar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 11 10:39:06 PDT 2018


jlebar created this revision.
jlebar added a reviewer: rsmith.
Herald added subscribers: llvm-commits, sanjoy.

Tests for https://reviews.llvm.org/D48036 / PR37753.


Repository:
  rT test-suite

https://reviews.llvm.org/D48037

Files:
  External/CUDA/algorithm.cu


Index: External/CUDA/algorithm.cu
===================================================================
--- External/CUDA/algorithm.cu
+++ External/CUDA/algorithm.cu
@@ -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 @@
 #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 @@
     printf("CUDA error %d\n", (int)err);
     return 1;
   }
+
+  min_hd();
+  max_hd();
+  cpp14_tests_hd();
+
   printf("Success!\n");
   return 0;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48037.150792.patch
Type: text/x-patch
Size: 1483 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180611/997e9f54/attachment.bin>


More information about the cfe-commits mailing list