Skip to content

Commit

Permalink
Retooled entire CMakeLists (still works!)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spudz76 committed Sep 30, 2018
1 parent bf225a2 commit c74d9d0
Show file tree
Hide file tree
Showing 8 changed files with 985 additions and 435 deletions.
917 changes: 485 additions & 432 deletions CMakeLists.txt

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions cmake/CUDA.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
get_filename_component(DEVICE_COMPILER "${CMAKE_CUDA_COMPILER}" NAME)
set(CUDA_COMPILER "${DEVICE_COMPILER}" CACHE STRING "Select the device compiler")

if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
list(APPEND DEVICE_COMPILER "clang")
endif()

set_property(CACHE CUDA_COMPILER PROPERTY STRINGS "${DEVICE_COMPILER}")

if(XMR-STAK_LARGEGRID)
list(APPEND CUDA_NVCC_FLAGS "-DXMR_STAK_LARGEGRID=${XMR-STAK_LARGEGRID}")
endif()

if(CUDA_COMPILER STREQUAL "clang")
set(CLANG_BUILD_FLAGS "-O3 -x cuda --cuda-path=${CUDA_TOOLKIT_ROOT_DIR}")
# activation usage of FMA
set(CLANG_BUILD_FLAGS "${CLANG_BUILD_FLAGS} -ffp-contract=fast")

if(CUDA_SHOW_REGISTER)
set(CLANG_BUILD_FLAGS "${CLANG_BUILD_FLAGS} -Xcuda-ptxas -v")
endif(CUDA_SHOW_REGISTER)

if(CUDA_KEEP_FILES)
set(CLANG_BUILD_FLAGS "${CLANG_BUILD_FLAGS} -save-temps=${PROJECT_BINARY_DIR}")
endif(CUDA_KEEP_FILES)

foreach(CUDA_ARCH_ELEM ${CUDA_ARCH})
# set flags to create device code for the given architectures
set(CLANG_BUILD_FLAGS "${CLANG_BUILD_FLAGS} --cuda-gpu-arch=sm_${CUDA_ARCH_ELEM}")
endforeach()
elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" OR CUDA_COMPILER STREQUAL "nvcc")
# add c++11 for cuda
set(CMAKE_CUDA_STANDARD 11)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)

# avoid that nvcc in CUDA 8 complains about sm_20 pending removal
if(CUDA_VERSION VERSION_EQUAL 8.0)
list(APPEND CUDA_NVCC_FLAGS "-Wno-deprecated-gpu-targets")
endif()

foreach(CUDA_ARCH_ELEM ${CUDA_ARCH})
# set flags to create device code for the given architecture
list(APPEND CUDA_NVCC_FLAGS
"--generate-code arch=compute_${CUDA_ARCH_ELEM},code=sm_${CUDA_ARCH_ELEM}"
"--generate-code arch=compute_${CUDA_ARCH_ELEM},code=compute_${CUDA_ARCH_ELEM}")
endforeach()

# give each thread an independent default stream
list(APPEND CUDA_NVCC_FLAGS "--default-stream per-thread")

if(CUDA_SHOW_REGISTER)
list(APPEND CUDA_NVCC_FLAGS "-Xptxas=-v")
endif(CUDA_SHOW_REGISTER)

if(CUDA_SHOW_CODELINES)
list(APPEND CUDA_NVCC_FLAGS "--source-in-ptx" "-lineinfo")
set(CUDA_KEEP_FILES ON CACHE BOOL "activate keep files" FORCE)
endif(CUDA_SHOW_CODELINES)

if(CUDA_KEEP_FILES)
list(APPEND CUDA_NVCC_FLAGS "--keep" "--keep-dir ${PROJECT_BINARY_DIR}")
endif(CUDA_KEEP_FILES)

if(CUDA_VERSION VERSION_LESS 8.0)
# avoid that nvcc in CUDA < 8 tries to use libc `memcpy` within the kernel
list(APPEND CUDA_NVCC_FLAGS "-D_FORCE_INLINES")
# for CUDA 7.5 fix compile error: https://github.com/fireice-uk/xmr-stak/issues/34
list(APPEND CUDA_NVCC_FLAGS "-D_MWAITXINTRIN_H_INCLUDED")
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND
(CUDA_VERSION VERSION_EQUAL 9.0 OR CUDA_VERSION VERSION_EQUAL 9.1 OR CUDA_VERSION VERSION_EQUAL 9.2)
)
# workaround find_package(CUDA) is using the wrong path to the CXX host compiler
# overwrite the CUDA host compiler variable with the used CXX MSVC
set(CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER} CACHE FILEPATH "Host side compiler used by NVCC" FORCE)
endif()
list(SORT CUDA_NVCC_FLAGS)
set(CMAKE_${CMAKE_CUDA_COMPILER_ENV_VAR}_FLAGS "${CUDA_NVCC_FLAGS}")
set(CUDA_FOUND TRUE)
else()
message(FATAL_ERROR "selected CUDA compiler '${CUDA_COMPILER}' is not supported")
set(CUDA_FOUND FALSE)
endif()
# vim: et sw=4 sts=4 ts=4:
192 changes: 192 additions & 0 deletions cmake/CUDAold.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
################################################################################
# Define backend: nvidia
################################################################################
#option(CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" OFF)
#set(CUDA_USE_STATIC_CUDA_RUNTIME OFF CACHE BOOL "Use the static version of the CUDA runtime library if available" FORCE)
option(CUDA_ENABLE "Enable or disable CUDA support (NVIDIA backend)" ON)
if(CUDA_ENABLE)
# Find CUDA
# help for systems with a software module system
list(APPEND CMAKE_PREFIX_PATH "$ENV{CUDA_ROOT}")

find_package(CUDA 7.5)
if(CUDA_FOUND)
CUDA_SELECT_NVCC_ARCH_FLAGS(ARCH_FLAGS "All")
message(STATUS "ARCH_FLAGS: ${ARCH_FLAGS}")
list(APPEND CUDA_NVCC_FLAGS ${ARCH_FLAGS})
foreach(THIS_FLAG ${ARCH_FLAGS})
message(STATUS "THIS_FLAG: ${THIS_FLAG}")
string(REGEX MATCH "^arch[0-9]+$" IS_ARCH ${THIS_FLAG})
if(IS_ARCH)
list(APPEND DEFAULT_CUDA_ARCH ${THIS_FLAG})
endif()
endforeach()
#message(STATUS "ARCHS: ${ARCH_FLAGS}")

option(XMR-STAK_LARGEGRID "Support large CUDA block count > 128" ON)
set(XMR-STAK_THREADS 0 CACHE STRING "Set maximum number of threads (for compile time optimization)")
option(CUDA_SHOW_REGISTER "Show registers used for each kernel and compute architecture" OFF)
option(CUDA_KEEP_FILES "Keep all intermediate files that are generated during internal compilation steps" OFF)
option(CUDA_SHOW_CODELINES "Show kernel lines in cuda-gdb and cuda-memcheck" OFF)

set(DEVICE_COMPILER "nvcc")
set(CUDA_COMPILER "${DEVICE_COMPILER}" CACHE STRING "Select the device compiler")

if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
list(APPEND DEVICE_COMPILER "clang")
endif()

set_property(CACHE CUDA_COMPILER PROPERTY STRINGS "${DEVICE_COMPILER}")

set(DEFAULT_CUDA_ARCH "30;35;37;50;52")
# Fermi GPUs are only supported with CUDA < 9.0
if(CUDA_VERSION VERSION_LESS 9.0)
list(APPEND DEFAULT_CUDA_ARCH "20")
endif()
# add Pascal support for CUDA >= 8.0
if(NOT CUDA_VERSION VERSION_LESS 8.0)
list(APPEND DEFAULT_CUDA_ARCH "60" "61" "62")
endif()
# add Volta support for CUDA >= 9.0
if(NOT CUDA_VERSION VERSION_LESS 9.0)
# Volta GPUs are currently not supported on MACOSX
# https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-general-known-issues
if(NOT APPLE)
list(APPEND DEFAULT_CUDA_ARCH "70")
endif()
endif()
set(CUDA_ARCH "${DEFAULT_CUDA_ARCH}" CACHE STRING "Set GPU architecture (semicolon separated list, e.g. '-DCUDA_ARCH=20;35;60')")
list(SORT CUDA_ARCH)
list(REMOVE_DUPLICATES CUDA_ARCH)

# validate architectures (only numbers are allowed)
foreach(CUDA_ARCH_ELEM ${CUDA_ARCH})
string(REGEX MATCH "^[0-9]+$" IS_NUMBER ${CUDA_ARCH_ELEM})
if(NOT IS_NUMBER)
message(FATAL_ERROR "Defined compute architecture '${CUDA_ARCH_ELEM}' in "
"'${CUDA_ARCH}' is not an integral number, use e.g. '30' (for compute architecture 3.0).")
endif()
unset(IS_NUMBER)

if(${CUDA_ARCH_ELEM} LESS 20)
message(FATAL_ERROR "Unsupported CUDA architecture '${CUDA_ARCH_ELEM}' specified. "
"Use '20' (for compute architecture 2.0) or higher.")
endif()
endforeach()

if(XMR-STAK_LARGEGRID)
list(APPEND CUDA_NVCC_FLAGS "-DXMR_STAK_LARGEGRID=${XMR-STAK_LARGEGRID}")
endif()

if(CUDA_COMPILER STREQUAL "clang")
set(CLANG_BUILD_FLAGS "-O3 -x cuda --cuda-path=${CUDA_TOOLKIT_ROOT_DIR}")
# activation usage of FMA
set(CLANG_BUILD_FLAGS "${CLANG_BUILD_FLAGS} -ffp-contract=fast")

if(CUDA_SHOW_REGISTER)
set(CLANG_BUILD_FLAGS "${CLANG_BUILD_FLAGS} -Xcuda-ptxas -v")
endif(CUDA_SHOW_REGISTER)

if(CUDA_KEEP_FILES)
set(CLANG_BUILD_FLAGS "${CLANG_BUILD_FLAGS} -save-temps=${PROJECT_BINARY_DIR}")
endif(CUDA_KEEP_FILES)

foreach(CUDA_ARCH_ELEM ${CUDA_ARCH})
# set flags to create device code for the given architectures
set(CLANG_BUILD_FLAGS "${CLANG_BUILD_FLAGS} --cuda-gpu-arch=sm_${CUDA_ARCH_ELEM}")
endforeach()
elseif(CUDA_COMPILER STREQUAL "nvcc")
# add c++11 for cuda
if(NOT CMAKE_CXX_FLAGS MATCHES "-std=c\\+\\+11")
list(APPEND CUDA_NVCC_FLAGS "-std=c++11")
endif()

# avoid that nvcc in CUDA 8 complains about sm_20 pending removal
if(CUDA_VERSION VERSION_EQUAL 8.0)
list(APPEND CUDA_NVCC_FLAGS "-Wno-deprecated-gpu-targets")
endif()

foreach(CUDA_ARCH_ELEM ${CUDA_ARCH})
# set flags to create device code for the given architecture
list(APPEND CUDA_NVCC_FLAGS
"--generate-code arch=compute_${CUDA_ARCH_ELEM},code=sm_${CUDA_ARCH_ELEM}"
"--generate-code arch=compute_${CUDA_ARCH_ELEM},code=compute_${CUDA_ARCH_ELEM}")
endforeach()

# give each thread an independent default stream
list(APPEND CUDA_NVCC_FLAGS "--default-stream per-thread")

if(CUDA_SHOW_REGISTER)
list(APPEND CUDA_NVCC_FLAGS "-Xptxas=-v")
endif(CUDA_SHOW_REGISTER)

if(CUDA_SHOW_CODELINES)
list(APPEND CUDA_NVCC_FLAGS "--source-in-ptx" "-lineinfo")
set(CUDA_KEEP_FILES ON CACHE BOOL "activate keep files" FORCE)
endif(CUDA_SHOW_CODELINES)

if(CUDA_KEEP_FILES)
list(APPEND CUDA_NVCC_FLAGS "--keep" "--keep-dir ${PROJECT_BINARY_DIR}")
endif(CUDA_KEEP_FILES)

if(CUDA_VERSION VERSION_LESS 8.0)
# avoid that nvcc in CUDA < 8 tries to use libc `memcpy` within the kernel
list(APPEND CUDA_NVCC_FLAGS "-D_FORCE_INLINES")
# for CUDA 7.5 fix compile error: https://github.com/fireice-uk/xmr-stak/issues/34
list(APPEND CUDA_NVCC_FLAGS "-D_MWAITXINTRIN_H_INCLUDED")
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND
(CUDA_VERSION VERSION_EQUAL 9.0 OR CUDA_VERSION VERSION_EQUAL 9.1 OR CUDA_VERSION VERSION_EQUAL 9.2)
)
# workaround find_package(CUDA) is using the wrong path to the CXX host compiler
# overwrite the CUDA host compiler variable with the used CXX MSVC
set(CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER} CACHE FILEPATH "Host side compiler used by NVCC" FORCE)
endif()
else()
message(FATAL_ERROR "selected CUDA compiler '${CUDA_COMPILER}' is not supported")
endif()

###############################################################################
# Define target: xmrstak_cuda_backend; nvidia backend shared lib
###############################################################################
file(GLOB CUDASRCFILES
"xmrstak/backend/nvidia/nvcc_code/*.cu"
"xmrstak/backend/nvidia/*.cpp")
if(CUDA_COMPILER STREQUAL "clang")
# build device code with clang
add_library(
xmrstak_cuda_backend
SHARED
${CUDASRCFILES}
)
set_target_properties(xmrstak_cuda_backend PROPERTIES COMPILE_FLAGS ${CLANG_BUILD_FLAGS})
set_target_properties(xmrstak_cuda_backend PROPERTIES LINKER_LANGUAGE CXX)
set_source_files_properties(${CUDASRCFILES} PROPERTIES LANGUAGE CXX)
else()
# build device code with nvcc
cuda_add_library(
xmrstak_cuda_backend
SHARED
${CUDASRCFILES}
)
endif()

if(NOT XMR-STAK_THREADS EQUAL 0)
message(STATUS "xmr-stak-nvidia: set max threads per block to ${XMR-STAK_THREADS}")
target_compile_definitions(xmrstak_cuda_backend PUBLIC "XMR_STAK_THREADS=${XMR-STAK_THREADS}")
endif()

# generate comma separated list with architectures
string(REPLACE ";" "+" STR_CUDA_ARCH "${CUDA_ARCH}")
target_compile_definitions(xmrstak_cuda_backend PUBLIC "XMRSTAK_CUDA_ARCH_LIST=${STR_CUDA_ARCH}")

target_link_libraries(xmrstak_cuda_backend ${CUDA_LIBRARIES} xmr-stak-backend)
list(APPEND BACKEND_TYPES "nvidia")
else()
message(FATAL_ERROR "CUDA NOT found: use `-DCUDA_ENABLE=OFF` to build without NVIDIA GPU support")
endif()
else()
target_compile_definitions(xmr-stak-c PUBLIC CONF_NO_CUDA)
endif()
# vim: et sw=4 sts=4 ts=4:
117 changes: 117 additions & 0 deletions cmake/FindMicroHttpd.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# -*- mode: cmake; -*-
# - Try to find libmicrohttpd include dirs and libraries
# Usage of this module as follows:
# This file defines:
# * MICROHTTPD_FOUND if protoc was found
# * MICROHTTPD_LIBRARY The lib to link to (currently only a static unix lib, not portable)
# * MICROHTTPD_INCLUDE The include directories for libmicrohttpd.

#message(STATUS "FindMicrohttpd check")
# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
if(MICROHTTPD_USE_STATIC_LIBS)
set(_microhttpd_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a )
endif()
endif()
IF(NOT WIN32)
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(_MICROHTTPD QUIET microhttpd>=0.9)
if("" STREQUAL "${_MICROHTTPD_CFLAGS_OTHER}")
pkg_check_modules(_MICROHTTPD QUIET libmicrohttpd>=0.9)
endif()
set(MICROHTTPD_DEFINITIONS ${_MICROHTTPD_CFLAGS_OTHER})
endif()
endif()

#
# set defaults
SET(_microhttpd_INCLUDE_SEARCH_DIRS
${CMAKE_INCLUDE_PATH}
/usr/local/include
/usr/include
)

SET(_microhttpd_LIBRARIES_SEARCH_DIRS
${CMAKE_LIBRARY_PATH}
/usr/local/lib
/usr/lib
)

##
if(NOT "" MATCHES "$ENV{MICROHTTPD_HOME}")
set (MICROHTTPD_HOME "$ENV{MICROHTTPD_HOME}")
endif()
IF( NOT $ENV{MICROHTTPD_INCLUDEDIR} STREQUAL "" )
SET(_microhttpd_INCLUDE_SEARCH_DIRS $ENV{MICROHTTPD_INCLUDEDIR} ${_microhttpd_INCLUDE_SEARCH_DIRS})
ENDIF( NOT $ENV{MICROHTTPD_INCLUDEDIR} STREQUAL "" )
IF( NOT $ENV{MICROHTTPD_LIBRARYDIR} STREQUAL "" )
SET(_microhttpd_LIBRARIES_SEARCH_DIRS $ENV{MICROHTTPD_LIBRARYDIR} ${_microhttpd_LIBRARIES_SEARCH_DIRS})
ENDIF( NOT $ENV{MICROHTTPD_LIBRARYDIR} STREQUAL "" )

##

IF( NOT ${MICROHTTPD_HOME} STREQUAL "" )
#message(STATUS "Looking for microhttpd in ${MICROHTTPD_HOME}")
set(_microhttpd_INCLUDE_SEARCH_DIRS ${MICROHTTPD_HOME}/include ${_microhttpd_INCLUDE_SEARCH_DIRS})
set(_microhttpd_LIBRARIES_SEARCH_DIRS ${MICROHTTPD_HOME}/lib ${_microhttpd_LIBRARIES_SEARCH_DIRS})
set(_microhttpd_HOME ${MICROHTTPD_HOME})
ENDIF( NOT ${MICROHTTPD_HOME} STREQUAL "" )

IF( MICROHTTPD_HOME )
SET(_microhttpd_INCLUDE_SEARCH_DIRS ${MICROHTTPD_HOME}/include ${_microhttpd_INCLUDE_SEARCH_DIRS})
SET(_microhttpd_LIBRARIES_SEARCH_DIRS ${MICROHTTPD_HOME}/lib ${_microhttpd_LIBRARIES_SEARCH_DIRS})
SET(_microhttpd_HOME ${MICROHTTPD_HOME})
ENDIF( MICROHTTPD_HOME )

# find the include files
FIND_PATH(MICROHTTPD_INCLUDE_DIR microhttpd.h
HINTS
${_microhttpd_INCLUDE_SEARCH_DIRS}
${_MICROHTTPD_INCLUDEDIR}
${_MICROHTTPD_INCLUDE_DIRS}
${CMAKE_INCLUDE_PATH}
)

# locate the library
IF(WIN32)
SET(MICROHTTPD_LIBRARY_NAMES ${MICROHTTPD_LIBRARY_NAMES} libmicrohttpd.lib)
ELSE(WIN32)
SET(MICROHTTPD_LIBRARY_NAMES ${MICROHTTPD_LIBRARY_NAMES} libmicrohttpd.so)
#SET(MICROHTTPD_LIBRARY_NAMES ${MICROHTTPD_LIBRARY_NAMES} libmicrohttpd.a)
ENDIF(WIN32)
FIND_LIBRARY(MICROHTTPD_LIBRARY NAMES ${MICROHTTPD_LIBRARY_NAMES}
HINTS
${_microhttpd_LIBRARIES_SEARCH_DIRS}
${_MICROHTTPD_LIBDIR}
${_MICROHTTPD_LIBRARY_DIRS}
)

# if the include and the program are found then we have it
IF(MICROHTTPD_INCLUDE_DIR AND MICROHTTPD_LIBRARY)
SET(MICROHTTPD_FOUND TRUE)
set(MICROHTTPD_VERSION ${_MICROHTTPD_VERSION})
if(NOT WIN32)
set(MICROHTTPD_LIBS_EXTRA "-lrt")
endif(NOT WIN32)
set(MICROHTTPD_LIBRARIES ${MICROHTTPD_LIBRARY})
list(APPEND MICROHTTPD_LIBRARIES "${MICROHTTPD_LIBS_EXTRA}")
ENDIF(MICROHTTPD_INCLUDE_DIR AND MICROHTTPD_LIBRARY)

MARK_AS_ADVANCED(
MICROHTTPD_FOUND
MICROHTTPD_VERSION
MICROHTTPD_LIBRARY
MICROHTTPD_LIBS_EXTRA
MICROHTTPD_LIBRARIES
MICROHTTPD_INCLUDE_DIR
)

# Restore the original find library ordering
if(MICROHTTPD_USE_STATIC_LIBS)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_microhttpd_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
# vim: et sw=4 sts=4 ts=4:
Loading

0 comments on commit c74d9d0

Please sign in to comment.