Skip to content

Commit

Permalink
Using new CMake FindCUDA elements (torch#415)
Browse files Browse the repository at this point in the history
* Use FindCUDA module

* Removed extra FindCUDA wrappers

* adjusted for new CUDA_ macro name

* Added fp16 recognition for mobile CUDA / new CMake

* Porting to new CMake
  • Loading branch information
borisfom authored and soumith committed May 27, 2016
1 parent 369bc80 commit 6b39d01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions lib/THC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ IF(APPLE)
ENDIF(APPLE)

# Detect CUDA architecture and get best NVCC flags
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/FindCudaArch.cmake)
SELECT_NVCC_ARCH_FLAGS(NVCC_FLAGS_EXTRA)
IF(DEFINED CUDA_HAS_FP16)
# New CMake macro, comes with FindCUDA
CUDA_SELECT_NVCC_ARCH_FLAGS(NVCC_FLAGS_EXTRA $ENV{TORCH_CUDA_ARCH_LIST})
ELSE()
# Old way of getting the flags, with extra include file
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/FindCudaArch.cmake)
SELECT_NVCC_ARCH_FLAGS(NVCC_FLAGS_EXTRA)
ENDIF()
LIST(APPEND CUDA_NVCC_FLAGS ${NVCC_FLAGS_EXTRA})

IF(NOT THC_INSTALL_BIN_SUBDIR
Expand Down Expand Up @@ -114,8 +120,10 @@ SET(src-cuda
THCTensorTopK.cu
)

IF(NOT ${CUDA_VERSION} LESS 7.5)
IF(${CUDA_HAS_FP16} OR NOT ${CUDA_VERSION} LESS 7.5)
LIST(APPEND src-cuda THCHalf.cu)
LIST(APPEND CUDA_NVCC_FLAGS "-DCUDA_HAS_FP16")
SET(CMAKE_C_FLAGS "-DCUDA_HAS_FP16 ${CMAKE_C_FLAGS}")
ENDIF()

CUDA_ADD_LIBRARY(THC SHARED ${src} ${src-cuda})
Expand Down
2 changes: 1 addition & 1 deletion lib/THC/THCHalf.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "THCGeneral.h"

#if CUDA_VERSION >= 7050
#if CUDA_VERSION >= 7050 || CUDA_HAS_FP16

#include <cuda_fp16.h>
#include <stdint.h>
Expand Down

0 comments on commit 6b39d01

Please sign in to comment.