[test-suite] r281701 - [CUDA] [test-suite] Add <algorithm> test.

Justin Lebar via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 15 21:07:38 PDT 2016


Author: jlebar
Date: Thu Sep 15 23:07:37 2016
New Revision: 281701

URL: http://llvm.org/viewvc/llvm-project?rev=281701&view=rev
Log:
[CUDA] [test-suite] Add <algorithm> test.

Just call some constexpr functions from <algorithm> with c++14 mode.
This isn't comprehensive; mostly just trying to check that nothing
explodes on us.

Added:
    test-suite/trunk/External/CUDA/algorithm.cu
    test-suite/trunk/External/CUDA/algorithm.reference_output
Modified:
    test-suite/trunk/External/CUDA/CMakeLists.txt

Modified: test-suite/trunk/External/CUDA/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/External/CUDA/CMakeLists.txt?rev=281701&r1=281700&r2=281701&view=diff
==============================================================================
--- test-suite/trunk/External/CUDA/CMakeLists.txt (original)
+++ test-suite/trunk/External/CUDA/CMakeLists.txt Thu Sep 15 23:07:37 2016
@@ -45,6 +45,7 @@ endmacro()
 macro(create_local_cuda_tests VariantSuffix)
   create_one_local_test(assert assert.cu)
   create_one_local_test(axpy axpy.cu)
+  create_one_local_test(algorithm algorithm.cu)
   create_one_local_test(cmath cmath.cu)
   create_one_local_test(math_h math_h.cu)
   create_one_local_test(empty empty.cu)
@@ -249,7 +250,8 @@ macro(create_cuda_tests)
       set(_Std_LDFLAGS -std=${_Std})
       foreach(_GccPath IN LISTS GCC_PATHS)
         get_version(_GccVersion ${_GccPath})
-        if (${_Std} STREQUAL "c++14" AND ${_GccVersion} VERSION_LESS "4.9")
+        # Our <algorithm> tests don't work with libstdc++ earlier than 5.0.
+        if (${_Std} STREQUAL "c++14" AND ${_GccVersion} VERSION_LESS "5.0")
           continue()
         endif()
         set(_Gcc_Suffix "libstdc++-${_GccVersion}")

Added: test-suite/trunk/External/CUDA/algorithm.cu
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/External/CUDA/algorithm.cu?rev=281701&view=auto
==============================================================================
--- test-suite/trunk/External/CUDA/algorithm.cu (added)
+++ test-suite/trunk/External/CUDA/algorithm.cu Thu Sep 15 23:07:37 2016
@@ -0,0 +1,64 @@
+// Check that we can call some constexpr functions from <algorithm> and
+// <functional> when compiling with C++14.  (We require C++14 because only in
+// that version do these functions become constexpr and therefore implicitly
+// __host__ __device__.)
+//
+// We assume our standard library is correct, but we still want to ensure that
+// we can successfully compile and run the standard library's implementations
+// of these functions.
+
+#if __cplusplus >= 201402L
+
+#include <assert.h>
+#include <algorithm>
+#include <functional>
+#include <stdio.h>
+
+__device__ void greater() {
+  assert(std::greater<int>()(1, 0));
+}
+
+__device__ void min() {
+  assert(std::min(0, 1) == 0);
+  assert(std::min({5, 1, 10}) == 1);
+}
+
+__device__ void max() {
+  assert(std::max(0, 1) == 1);
+  assert(std::max({5, 1, 10}, std::less<int>()) == 10);
+}
+
+__device__ void minmax() {
+  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);
+}
+
+__global__ void kernel() {
+  greater();
+  min();
+  max();
+  minmax();
+}
+
+int main() {
+  kernel<<<32, 32>>>();
+  cudaError_t err = cudaDeviceSynchronize();
+  if (err != cudaSuccess) {
+    printf("CUDA error %d\n", (int)err);
+    return 1;
+  }
+  printf("Success!\n");
+  return 0;
+}
+
+#else
+
+#include <stdio.h>
+int main() {
+  printf("Success!\n");
+  return 0;
+}
+
+#endif

Added: test-suite/trunk/External/CUDA/algorithm.reference_output
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/External/CUDA/algorithm.reference_output?rev=281701&view=auto
==============================================================================
--- test-suite/trunk/External/CUDA/algorithm.reference_output (added)
+++ test-suite/trunk/External/CUDA/algorithm.reference_output Thu Sep 15 23:07:37 2016
@@ -0,0 +1,2 @@
+Success!
+exit 0




More information about the llvm-commits mailing list