Skip to content
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

Change the device library to use CUDA runtime API #589

Merged
merged 5 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions config/component_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ endmacro( add_component_executable )
# SOURCES "file1.cc;file2.cc;..."
# HEADERS "file1.hh;file2.hh;..."
# LIBRARY_NAME_PREFIX "rtt_"
# LIBRARY_TYPE "SHARED"
# VENDOR_LIST "MPI;GSL"
# VENDOR_LIBS "${MPI_CXX_LIBRARIES};${GSL_LIBRARIES}"
# VENDOR_INCLUDE_DIRS "${MPI_CXX_INCLUDE_DIR};${GSL_INCLUDE_DIR}"
Expand All @@ -279,7 +280,7 @@ macro( add_component_library )
cmake_parse_arguments(
acl
"NOEXPORT"
"PREFIX;TARGET;LIBRARY_NAME;LIBRARY_NAME_PREFIX;LINK_LANGUAGE"
"PREFIX;TARGET;LIBRARY_NAME;LIBRARY_NAME_PREFIX;LIBRARY_TYPE;LINK_LANGUAGE"
"HEADERS;SOURCES;TARGET_DEPS;VENDOR_LIST;VENDOR_LIBS;VENDOR_INCLUDE_DIRS"
${ARGV}
)
Expand All @@ -305,6 +306,11 @@ macro( add_component_library )
endif()
endif()

# if a library type was not specified use the default Draco setting
if(NOT acl_LIBRARY_TYPE)
set( acl_LIBRARY_TYPE ${DRACO_LIBRARY_TYPE})
endif()

#
# Create the library and set the properties
#
Expand All @@ -314,7 +320,7 @@ macro( add_component_library )
# extract project name, minus leading "Lib_"
string( REPLACE "Lib_" "" folder_name ${acl_TARGET} )

add_library( ${acl_TARGET} ${DRACO_LIBRARY_TYPE} ${acl_SOURCES} )
add_library( ${acl_TARGET} ${acl_LIBRARY_TYPE} ${acl_SOURCES} )
# Some properties are set at a global scope in compilerEnv.cmake:
# - C_STANDARD, C_EXTENSIONS, CXX_STANDARD, CXX_EXTENSIONS,
# CXX_STANDARD_REQUIRED, and POSITION_INDEPENDENT_CODE
Expand Down
38 changes: 38 additions & 0 deletions config/query_gpu.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//----------------------------------*-C++-*----------------------------------//
/*!
* \file config/query_gpu.cu
* \author Alex Long
* \brief Small CUDA code that prints the architecture version, used by CMake
* \date Thu Mat 21 15:53:51 2019
* \note Copyright (C) 2019 Triad National Security, LLC.
* All rights reserved. */
//---------------------------------------------------------------------------//

// NOTE: This code is from
// wagonhelm.github.io/articles/2018-03/detecting-cuda-capability-with-cmake

#include <stdio.h>

int main(int argc, char **argv) {
cudaDeviceProp dP;
float min_cc = 3.0;

int rc = cudaGetDeviceProperties(&dP, 0);
if (rc != cudaSuccess) {
cudaError_t error = cudaGetLastError();
printf("CUDA error: %s", cudaGetErrorString(error));
return rc; /* Failure */
}
if ((dP.major + (dP.minor / 10)) < min_cc) {
printf("Min Compute Capability of %2.1f required: %d.%d found\n Not "
"Building CUDA Code",
min_cc, dP.major, dP.minor);
return 1; /* Failure */
} else {
printf("-arch=sm_%d%d", dP.major, dP.minor);
return 0; /* Success */
}
}
//---------------------------------------------------------------------------//
// end of query_gpu.cu
//---------------------------------------------------------------------------//
47 changes: 20 additions & 27 deletions config/vendor_libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -295,36 +295,29 @@ macro( setupCudaEnv )

add_feature_info( Cuda WITH_CUDA "Build CUDA kernels for GPU compute.")

if( WITH_CUDA )
if( WITH_CUDA AND NOT DEFINED CUDA_DBS_STRING )
set( CUDA_DBS_STRING "CUDA" CACHE BOOL
"If CUDA is available, this variable is 'CUDA'")

# message("
# CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES = ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
# CMAKE_CUDA_HOST_COMPILER = ${CMAKE_CUDA_HOST_COMPILER}
# CMAKE_GENERATOR_TOOLSET = ${CMAKE_GENERATOR_TOOLSET}
# CMAKE_VS_PLATFORM_TOOLSET_CUDA = ${CMAKE_VS_PLATFORM_TOOLSET_CUDA}
# CUDA_EXTENSIONS = ${CUDA_EXTENSIONS}
# CUDAHOSTCXX = ${CUDAHOSTCXX}
# CUDAFLAGS = ${CUDAFLAGS}
# CUDACXX = ${CUDACXX}
# CUDA_STANDARD = ${CUDA_STANDARD}
# CUDA_SEPARABLE_COMPILATION = ${CUDA_SEPARABLE_COMPILATION}
# CUDA_RESOLVE_DEVICE_SYMBOLS = ${CUDA_RESOLVE_DEVICE_SYMBOLS}
# CUDA_PTX_COMPILATION = ${CUDA_PTX_COMPILATION}
# ")

# $ENV{CUDACXX}
# $ENV{CUDAFLAGS}
# $ENV{CUDAHOSTCXX}

# target properties
# - CUDA_EXTENSIONS
# - CUDA_PTX_COMPILATION
# - CUDA_RESOLVE_DEVICE_SYMBOLS
# - CUDA_SEPARABLE_COMPILATION
# - CUDA_STANDARD
# - CUDA_STANDARD_REQUIRED
set(OUTPUTFILE ${CMAKE_CURRENT_SOURCE_DIR}/config/cuda_script) # No suffix required
set(CUDAFILE ${CMAKE_CURRENT_SOURCE_DIR}/config/query_gpu.cu)
execute_process(COMMAND nvcc -lcuda ${CUDAFILE} -o ${OUTPUTFILE})
execute_process(COMMAND ${OUTPUTFILE}
RESULT_VARIABLE CUDA_RETURN_CODE OUTPUT_VARIABLE ARCH)

if (${CUDA_RETURN_CODE EQUAL 0})
message(STATUS "CUDA Architecture: ${ARCH}")
set(CMAKE_CUDA_FLAGS "${ARCH} -g -G" CACHE STRING
set(CMAKE_CUDA_FLAGS_DEBUG "-O0" CACHE STRING
"CUDA debug flags" FORCE)
"CUDA debug flags" FORCE)
set(CMAKE_CUDA_FLAGS_RELWITHDEBINFO "-O2 --generate-line-info" CACHE STRING
"CUDA release with debug information flags" FORCE)
set(CMAKE_CUDA_FLAGS_RELEASE "-O2" CACHE STRING
"CUDA release flags" FORCE)
else()
message(WARNING ${ARCH})
endif()
endif()

endmacro()
Expand Down
Loading