From 76422029c11e800ff1c421bafdd1a4d8d9996810 Mon Sep 17 00:00:00 2001 From: Chris Olivier Date: Wed, 1 Feb 2017 13:02:24 -0800 Subject: [PATCH] Fix warnings, build adjustments in CMake (#209) * Fix warnings, build adjustments in CMake * fix cuda variable-declaration order problems * Remove gpu flavors below 30, no longer compatible --- .gitignore | 1 + cmake/Cuda.cmake | 48 ++++++++++++++++--------- cmake/mshadowUtils.cmake | 2 ++ mshadow/extension/broadcast.h | 2 +- mshadow/extension/broadcast_with_axis.h | 6 ++-- mshadow/tensor_cpu-inl.h | 2 +- 6 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 cmake/mshadowUtils.cmake diff --git a/.gitignore b/.gitignore index 9cceebd0..6f01527e 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ rabit dmlc-core *.db *.bak +build diff --git a/cmake/Cuda.cmake b/cmake/Cuda.cmake index 38b1ab7e..49a3d135 100644 --- a/cmake/Cuda.cmake +++ b/cmake/Cuda.cmake @@ -5,16 +5,6 @@ endif() include(CheckCXXCompilerFlag) check_cxx_compiler_flag("-std=c++11" SUPPORT_CXX11) - -# Known NVIDIA GPU achitectures mshadow can be compiled for. -# This list will be used for CUDA_ARCH_NAME = All option -if(${CUDA_VERSION} GREATER 7.5) - set(mshadow_known_gpu_archs "20 21(20) 30 35 50 52 60 61") -else() - set(mshadow_known_gpu_archs "20 21(20) 30 35 50 52") -endif() - - ################################################################################################ # A function for automatic detection of GPUs installed (if autodetection is enabled) # Usage: @@ -167,17 +157,14 @@ macro(mshadow_cuda_compile objlist_variable) endforeach() if(UNIX OR APPLE) list(APPEND CUDA_NVCC_FLAGS -Xcompiler -fPIC) - if(SUPPORT_CXX11) - list(APPEND CUDA_NVCC_FLAGS -Xcompiler -fPIC --std=c++11) - endif() endif() if(APPLE) list(APPEND CUDA_NVCC_FLAGS -Xcompiler -Wno-unused-function) endif() - + set(CUDA_NVCC_FLAGS_DEBUG "${CUDA_NVCC_FLAGS_DEBUG} -G -lineinfo") - + if(MSVC) # disable noisy warnings: # 4819: The file contains a character that cannot be represented in the current code page (number). @@ -191,6 +178,14 @@ macro(mshadow_cuda_compile objlist_variable) endforeach(flag_var) endif() + # If the build system is a container, make sure the nvcc intermediate files + # go into the build output area rather than in /tmp, which may run out of space + if(IS_CONTAINER_BUILD) + set(CUDA_NVCC_INTERMEDIATE_DIR "${CMAKE_CURRENT_BINARY_DIR}") + message(STATUS "Container build enabled, so nvcc intermediate files in: ${CUDA_NVCC_INTERMEDIATE_DIR}") + list(APPEND CUDA_NVCC_FLAGS "--keep --keep-dir ${CUDA_NVCC_INTERMEDIATE_DIR}") + endif() + cuda_compile(cuda_objcs ${ARGN}) foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG) @@ -232,7 +227,16 @@ endfunction() ### Non macro section ################################################################################################ -find_package(CUDA 5.5 QUIET) +# Try to prime CUDA_TOOLKIT_ROOT_DIR by looking for libcudart.so +if(NOT CUDA_TOOLKIT_ROOT_DIR) + find_library(CUDA_LIBRARY_PATH libcudart.so PATHS ENV LD_LIBRARY_PATH PATH_SUFFIXES lib lib64) + if(CUDA_LIBRARY_PATH) + get_filename_component(CUDA_LIBRARY_PATH ${CUDA_LIBRARY_PATH} DIRECTORY) + set(CUDA_TOOLKIT_ROOT_DIR "${CUDA_LIBRARY_PATH}/..") + endif() +endif() + +find_package(CUDA 5.5 QUIET REQUIRED) find_cuda_helper_libs(curand) # cmake 2.8.7 compartibility which doesn't search for curand if(NOT CUDA_FOUND) @@ -245,6 +249,18 @@ include_directories(SYSTEM ${CUDA_INCLUDE_DIRS}) list(APPEND mshadow_LINKER_LIBS ${CUDA_CUDART_LIBRARY} ${CUDA_curand_LIBRARY} ${CUDA_CUBLAS_LIBRARIES}) +# Known NVIDIA GPU achitectures mshadow can be compiled for. +# This list will be used for CUDA_ARCH_NAME = All option +if(CUDA_ARCH_ALL) + set(mshadow_known_gpu_archs "${CUDA_ARCH_ALL}") +else() + if(${CUDA_VERSION} GREATER 7.5) + set(mshadow_known_gpu_archs "30 35 50 52 60 61") + else() + set(mshadow_known_gpu_archs "30 35 50 52") + endif() +endif() + # cudnn detection if(USE_CUDNN) detect_cuDNN() diff --git a/cmake/mshadowUtils.cmake b/cmake/mshadowUtils.cmake new file mode 100644 index 00000000..d4b8bfc8 --- /dev/null +++ b/cmake/mshadowUtils.cmake @@ -0,0 +1,2 @@ +include("${CMAKE_CURRENT_LIST_DIR}/Utils.cmake") + diff --git a/mshadow/extension/broadcast.h b/mshadow/extension/broadcast.h index 0f09f44b..ea138ccd 100644 --- a/mshadow/extension/broadcast.h +++ b/mshadow/extension/broadcast.h @@ -92,7 +92,7 @@ broadcast_scalar(const expr::Exp &src, Shape shape TypeCheckPass::kDim == 1> ::Error_Expression_Does_Not_Meet_Dimension_Req(); typedef ShapeCheck<1, SrcExp> ShapeCheckDim1SrcExp; - CHECK_EQ(ShapeCheckDim1SrcExp::Check(src.self())[0], 1) + CHECK_EQ(ShapeCheckDim1SrcExp::Check(src.self())[0], 1U) << "broadcast_scalar, source need to be scalar expression"; return BroadcastScalarExp(src.self(), shape); } diff --git a/mshadow/extension/broadcast_with_axis.h b/mshadow/extension/broadcast_with_axis.h index 2ec6c87d..80f4ed3e 100644 --- a/mshadow/extension/broadcast_with_axis.h +++ b/mshadow/extension/broadcast_with_axis.h @@ -193,13 +193,13 @@ const TShape &axes, const TShape &sizes) { template inline BroadcastWithMultiAxesExp::kDim> broadcast_to(const Exp &src, const TShape &target_shape) { - static const int dimsrc = ExpInfo::kDim; + static const size_t dimsrc = ExpInfo::kDim; CHECK_EQ(target_shape.ndim(), dimsrc); std::vector axes_vec, sizes_vec; Shape src_shape = ShapeCheck::Check(src.self()); - for (int i = 0; i < dimsrc; ++i) { + for (size_t i = 0; i < dimsrc; ++i) { if (src_shape[i] != target_shape[i]) { - CHECK_EQ(src_shape[i], 1) << "broadcasting axis must have size 1, received shape=" + CHECK_EQ(src_shape[i], 1U) << "broadcasting axis must have size 1, received shape=" << src_shape << " target_shape=" << target_shape; axes_vec.push_back(i); sizes_vec.push_back(target_shape[i]); diff --git a/mshadow/tensor_cpu-inl.h b/mshadow/tensor_cpu-inl.h index f98e294f..8a1a491f 100755 --- a/mshadow/tensor_cpu-inl.h +++ b/mshadow/tensor_cpu-inl.h @@ -475,7 +475,7 @@ inline void VectorDot(Tensor dst, const Tensor &rhs) { CHECK_EQ(lhs.size(0), rhs.size(0)) << "VectorDot: Shape mismatch"; - CHECK_EQ(dst.size(0), 1) + CHECK_EQ(dst.size(0), 1U) << "VectorDot: expect dst to be scalar"; expr::BLASEngine::SetStream(lhs.stream_); mshadow::expr::BLASEngine::dot(