Skip to content

Commit

Permalink
Some changes to the device library to use runtime API
Browse files Browse the repository at this point in the history
+ Add a simple CUDA compilation step during configure to determine the apporiate arhcitecture flags
+ Allow add_componenet_library to accept a library type different than the DRACO_LIBRARY_TYPE variable
+ Change the GPU_Device class to use the newer CUDA Runtime API
+ Remove the GPU_Module class (explicit module and contexts are not necessary in the Runtime API)
+ Remove "EXTERN C" decorations (these are also no longer necessary in the Runtime API since functions do not need to be loaded explicity)
+ Add a test that shows an example of calling code from both the host and device
+ Consolidate calls to simple GPU test kernels into a "basic_kernels" header and implementation file
+ Compile auxillary GPU test code into a static library callable by the individual gpu tests
  • Loading branch information
Alex Roberts Long - 283434 authored and alexrlongne committed Mar 29, 2019
1 parent 631e407 commit 507ab6d
Show file tree
Hide file tree
Showing 21 changed files with 612 additions and 817 deletions.
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
//---------------------------------------------------------------------------//
26 changes: 26 additions & 0 deletions config/vendor_libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,32 @@ macro( setupCudaEnv )
set( CUDA_DBS_STRING "CUDA" CACHE BOOL
"If CUDA is available, this variable is 'CUDA'")

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)
set(CUDA_SUCCESS "TRUE")
else()
set(CUDA_SUCCESS "FALSE")
endif()

if (${CUDA_SUCCESS})
message(STATUS "CUDA Architecture: ${ARCH}")
set(CMAKE_CUDA_FLAGS "${ARCH} -G -O0")
# ARL: These variables are set by the find_package(CUDA) call, which we
# currently do not use
#message(STATUS "CUDA Version: ${CUDA_VERSION_STRING}")
#message(STATUS "CUDA Path: ${CUDA_TOOLKIT_ROOT_DIR}")
#message(STATUS "CUDA Libararies: ${CUDA_LIBRARIES}")
#message(STATUS "CUDA Performance Primitives: ${CUDA_npp_LIBRARY}")
else()
message(WARNING ${ARCH})
endif()

# message("
# CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES = ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
# CMAKE_CUDA_HOST_COMPILER = ${CMAKE_CUDA_HOST_COMPILER}
Expand Down
Loading

0 comments on commit 507ab6d

Please sign in to comment.