[PATCH] D19434: [test-suite] Added CMake files for external CUDA tests.

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 22 15:59:36 PDT 2016


MatzeB accepted this revision.
MatzeB added a comment.
This revision is now accepted and ready to land.

This should not affect users without users without cuda stuff installed so this LGTM.

I don't have any experience from the cuda side and do not plan to use this. So consider the rest as a suggestion I got while glancing over the code (but feel free to do whatever you want in the cuda parts).


================
Comment at: External/CUDA/CMakeLists.txt:83-88
@@ +82,8 @@
+function(create_thrust_tests VariantSuffix)
+  list(APPEND CPPFLAGS
+    -DTHRUST_HOST_SYSTEM=THRUST_HOST_SYSTEM_CPP
+    -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA)
+  list(APPEND CPPFLAGS
+    -I${CudaPath}/include
+    -I${THRUST_PATH} -I${THRUST_PATH}/testing)
+
----------------
It's unusual to do stuff like setting CPPFLAGS in a function rather than toplevel. At least in the sense that it is inconsistent with the style in the rest of the test-suite.

================
Comment at: External/CUDA/CMakeLists.txt:114
@@ +113,3 @@
+    set(Source ${ThrustTestFramework} ${ThrustAllTestSources})
+    if(DEFINED LARGE_PROBLEM_SIZE)
+      llvm_test_run(--verbose --sizes=large)
----------------
`if(LARGE_PROBLEM_SIZE)` is probably enough.

================
Comment at: External/CUDA/CMakeLists.txt:132-159
@@ +131,30 @@
+# Sets VARIANT_CUDA_TESTS targets in parent's scope.
+function(create_cuda_test_variant CudaPath Std GccPath)
+  get_version(CudaVersion ${CudaPath})
+  set(VariantSuffix "cuda-${CudaVersion}")
+  list(APPEND CPPFLAGS --cuda-path=${CudaPath})
+  list(APPEND VariantLibs cudart-${CudaVersion})
+
+  if(Std)
+    set(VariantSuffix "${VariantSuffix}-${Std}")
+    list(APPEND CPPFLAGS -std=${Std})
+    list(APPEND LDFLAGS -std=${Std})
+  endif()
+
+  if(GccPath)
+    get_version(GccVersion ${GccPath})
+    set(VariantSuffix "${VariantSuffix}-libstdc++-${GccVersion}")
+
+    # Tell clang to use libstdc++ and where to find it.
+    list(APPEND CPPFLAGS -gcc-toolchain ${GccPath}/usr/local -stdlib=libstdc++)
+    # Add libstdc++ as link dependency.
+    list(APPEND VariantLibs libstdcxx-${GccVersion})
+  else()
+    # Tell clang to use libc++
+    # We also need to add compiler's include path for cxxabi.h
+    get_filename_component(_compiler_path ${CMAKE_CXX_COMPILER} DIRECTORY)
+    list(APPEND CPPFLAGS -stdlib=libc++ -I${_compiler_path}/../include)
+    list(APPEND LDFLAGS -stdlib=libc++)
+    list(APPEND VariantLibs libcxx)
+  endif()
+
----------------
This looks like magic to discover the host system. Maybe this would better fit in some global configuration variables combines with cmake/cache files for typical configurations? Esp. the hardcoding of the libstdc++ paths looks out of place here...

================
Comment at: External/CUDA/CMakeLists.txt:175-189
@@ +174,17 @@
+macro(create_cuda_tests)
+  message(STATUS "Checking CUDA prerequisites in ${TEST_SUITE_CUDA_ROOT}")
+  file(GLOB CudaVersions ${TEST_SUITE_CUDA_ROOT}/cuda-*)
+  foreach(CudaDir IN LISTS CudaVersions)
+    get_version(CudaVersion ${CudaDir})
+    message(STATUS "Found CUDA ${CudaVersion} ${CudaDir}")
+    list(APPEND CUDA_PATHS ${CudaDir})
+    add_library(cudart-${CudaVersion} SHARED IMPORTED)
+    set_property(TARGET cudart-${CudaVersion} PROPERTY IMPORTED_LOCATION
+      ${CudaDir}/lib64/libcudart.so)
+  endforeach(CudaDir)
+
+  if(NOT CUDA_PATHS)
+    message(SEND_ERROR
+      "There are no CUDA installations in ${TEST_SUITE_CUDA_ROOT}")
+    return()
+  endif()
----------------
ditto.

================
Comment at: External/CUDA/CMakeLists.txt:202-222
@@ +201,23 @@
+  file(GLOB GccVersions ${TEST_SUITE_CUDA_ROOT}/gcc-*)
+  foreach(GccDir IN LISTS GccVersions)
+    get_version(GccVersion ${GccDir})
+    message(STATUS "Found GCC ${GccVersion}")
+    list(APPEND GCC_PATHS ${GccDir})
+    add_library(libstdcxx-${GccVersion} SHARED IMPORTED)
+    set_property(TARGET libstdcxx-${GccVersion} PROPERTY IMPORTED_LOCATION
+      ${GccDir}/usr/local/lib64/libstdc++.so)
+  endforeach(GccDir)
+
+  # Find location of libc++
+  execute_process(
+    COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=libc++.so
+    OUTPUT_VARIABLE _path_to_libcxx
+    OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+  if (EXISTS ${_path_to_libcxx})
+    add_library(libcxx SHARED IMPORTED)
+    set_property(TARGET libcxx PROPERTY IMPORTED_LOCATION ${_path_to_libcxx})
+  else()
+    message(ERROR "Can't find libcxx location.")
+    return()
+  endif()
----------------
ditto.

================
Comment at: External/CUDA/README:4-6
@@ +3,5 @@
+
+Cuda tests are enabled if cmake is invoked with
+-DTEST_SUITE_EXTERNALS_DIR=<externals path> and specified externals
+directory contains at least one CUDA installation.
+
----------------
Note that as a convenience you can even do without this flag: If you checkout your externals in `test-suite/test-suite-externals` it will get picked up automatically at cmake time.


http://reviews.llvm.org/D19434





More information about the llvm-commits mailing list