Skip to content

Commit

Permalink
smoosh
Browse files Browse the repository at this point in the history
  • Loading branch information
Spudz76 committed Sep 30, 2018
1 parent 66b4527 commit de23d1f
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 86 deletions.
46 changes: 31 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.4.0 FATAL_ERROR)
project(xmr-stak)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
include(utilFunctions)
include(funcUtil)

# enforce C++11
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -19,6 +19,8 @@ option(MICROHTTPD_ENABLE "Enable or disable the requirement of microhttpd (http
option(CPU_ENABLE "Enable or disable CPU support" ON)
option(CUDA_ENABLE "Enable or disable CUDA support (NVIDIA backend)" ON)
option(OpenCL_ENABLE "Enable or disable OpenCL support (AMD GPU support)" ON)
option(CMAKE_LINK_STATIC "link as much as possible libraries static" OFF)

set(EXECUTABLE_OUTPUT_PATH "bin" CACHE STRING "Path to place executables relative to ${CMAKE_INSTALL_PREFIX}")
set(LIBRARY_OUTPUT_PATH "bin" CACHE STRING "Path to place libraries relative to ${CMAKE_INSTALL_PREFIX}")

Expand All @@ -42,9 +44,6 @@ if(NOT (XMR-STAK_COMPILE STREQUAL "generic" OR XMR-STAK_COMPILE STREQUAL "native
endif()

# option to add static libgcc and libstdc++
option(CMAKE_LINK_STATIC "link as much as possible libraries static" OFF)
#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)
if(CMAKE_LINK_STATIC)
# activate static libgcc and libstdc++ linking
message(STATUS "Library mode: STATIC")
Expand Down Expand Up @@ -80,14 +79,32 @@ endif()
# Configure NVCC
################################################################################
if(CUDA_ENABLE)
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_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(CUDA_ARCH "${CUDA_ARCH}" CACHE STRING "Set GPU architecture (semicolon separated list, e.g. '-DCUDA_ARCH=20;35;60')")
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)")

include(funcCUDA)
if(NOT CMAKE_VERSION VERSION_LESS 3.8)
#if(NOT "" STREQUAL "$ENV{CUDA_PATH}")
# find_program(_nvccbin NAME "nvcc"
# PATH ENV "CUDA_PATH" ENV "Path")
# if(NOT "" STREQUAL "${_nvccbin}")
# set(CMAKE_CUDA_COMPILER "${_nvccbin}")
# endif()
#endif()
set(CMAKE_CUDA_COMPILER "nvcc")
enable_language(CUDA)
endif()
find_package(CUDA REQUIRED QUIET)
include(CUDAprobe)
CUDA_PROBE_ARCHS()
cuda_arch_probe()
message(STATUS "The CUDA compiler architectures are ${CMAKE_CUDA_ARCHLIST}")
cuda_arch_filter("${CUDA_ARCH}" "${CMAKE_CUDA_ARCHLIST}" CUDA_ARCH_FILTERED)
set(CUDA_ARCH "${CUDA_ARCH_FILTERED}" CACHE STRING "CUDA architecture filtered" FORCE)
endif()

###############################################################################
Expand Down Expand Up @@ -320,7 +337,7 @@ if(OpenSSL_ENABLE)
set_target_properties(libcrypto PROPERTIES IMPORTED_LOCATION "${OPENSSL_CRYPTO_LIBRARY}")
target_link_libraries(xmr-stak-backend libcrypto)
endif()
target_link_libraries(xmr-stak-backend dl)
target_link_libraries(xmr-stak-backend ${CMAKE_DL_LIBS})
else()
message(FATAL_ERROR "OpenSSL NOT found: use `-DOpenSSL_ENABLE=OFF` to build without SSL support")
endif()
Expand Down Expand Up @@ -416,8 +433,8 @@ if(CUDA_ENABLE)
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})
target_link_libraries(xmr-stak-backend xmrstak_cuda_backend)
target_link_libraries(xmrstak_cuda_backend xmr-stak-backend ${CUDA_LIBRARIES})
#target_link_libraries(xmr-stak-backend xmrstak_cuda_backend)
list(APPEND BACKEND_TYPES "nvidia")
else()
message(FATAL_ERROR "CUDA NOT found: use `-DCUDA_ENABLE=OFF` to build without NVIDIA GPU support")
Expand Down Expand Up @@ -472,24 +489,23 @@ if(OpenCL_ENABLE)
set(CL_TARGET_OPENCL_VERSION "${OpenCL_VERSION_MAJOR}${OpenCL_VERSION_MINOR}0")

###############################################################################
# Define target: xmrstak_cuda_backend; nvidia backend shared lib
# Define target: xmrstak_opencl_backend; OpenCL (AMD) backend shared lib
###############################################################################
add_library(xmrstak_opencl_backend
SHARED
"xmrstak/backend/amd/jconf.cpp"
"xmrstak/backend/amd/amd_gpu/gpu.cpp"
"xmrstak/backend/amd/minethd.cpp"
)
set(CL_TARGET_OPENCL_VERSION "120")
if(XMR-STAK_COMPILE STREQUAL "generic")
message(STATUS "Forcing OpenCL 1.2 due to XMR-STAK_COMPILE=generic")
target_compile_definitions(xmrstak_opencl_backend PRIVATE "CONF_ENFORCE_OpenCL_1_2=1")
set(CL_TARGET_OPENCL_VERSION "120")
endif()
target_compile_definitions(xmrstak_opencl_backend PRIVATE "CL_TARGET_OPENCL_VERSION=${CL_TARGET_OPENCL_VERSION}")
target_link_libraries(xmrstak_opencl_backend "${OpenCL_LIBRARY}")
target_compile_definitions(xmr-stak-backend PRIVATE "CL_TARGET_OPENCL_VERSION=${CL_TARGET_OPENCL_VERSION}")
target_link_libraries(xmr-stak-backend xmrstak_opencl_backend)
#target_compile_definitions(xmrstak_opencl_backend PRIVATE "CL_TARGET_OPENCL_VERSION=${CL_TARGET_OPENCL_VERSION}")
target_compile_definitions(xmr-stak-backend PUBLIC "CL_TARGET_OPENCL_VERSION=${CL_TARGET_OPENCL_VERSION}")
target_link_libraries(xmrstak_opencl_backend xmr-stak-backend "${OpenCL_LIBRARY}")
#target_link_libraries(xmr-stak-backend xmrstak_opencl_backend)
include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS})
list(APPEND BACKEND_TYPES "amd")
else()
Expand Down
41 changes: 0 additions & 41 deletions cmake/CUDA.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
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)

get_filename_component(DEVICE_COMPILER "${CMAKE_CUDA_COMPILER}" NAME)
set(CUDA_COMPILER "${DEVICE_COMPILER}" CACHE STRING "Select the device compiler")

Expand All @@ -13,41 +7,6 @@ endif()

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

set(DEFAULT_CUDA_ARCH "${CMAKE_CUDA_ARCHLIST}")
# Volta GPUs are currently not supported on MACOSX
# https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-general-known-issues
if(APPLE)
list(REMOVE DEFAULT_CUDA_ARCH "70")
endif()
string(REGEX REPLACE "[^;0-9]+" "" CUDA_ARCH "${CUDA_ARCH}")
if(NOT "" STREQUAL "${CUDA_ARCH}")
list(SORT CUDA_ARCH)
list(REMOVE_DUPLICATES CUDA_ARCH)
foreach(_arch ${CUDA_ARCH})
# validate architectures (only numbers are allowed)
string(REGEX MATCH "^[0-9]+$" IS_NUMBER ${_arch})
if(NOT IS_NUMBER)
message(FATAL_ERROR "Defined compute architecture '${_arch}' in "
"'${CUDA_ARCH}' is not an integral number, use e.g. '30' (for compute architecture 3.0).")
endif()
if(${_arch} LESS 20)
message(WARNING "Removing ${_arch} from provided CUDA_ARCH, it does not support required math functions. "
"Miner kernels require compute architecture 2.0 or higher.")
endif()
endforeach()
foreach(_arch ${DEFAULT_CUDA_ARCH})
string(MATCH "${_arch}" _arch_good "${CUDA_ARCH}")
if(NOT _arch_good)
message(WARNING "Removing ${_arch} from provided CUDA_ARCH, it is not supported by this nvcc")
list(REMOVE "${_arch}" CUDA_ARCH)
endif()
endforeach()
unset(IS_NUMBER)
unset(_arch_good)
unset(_arch)
endif()
set(CUDA_ARCH "${DEFAULT_CUDA_ARCH}" CACHE STRING "Set GPU architecture (semicolon separated list, e.g. '-DCUDA_ARCH=20;35;60')")

if(XMR-STAK_LARGEGRID)
list(APPEND CUDA_NVCC_FLAGS "-DXMR_STAK_LARGEGRID=${XMR-STAK_LARGEGRID}")
endif()
Expand Down
30 changes: 0 additions & 30 deletions cmake/CUDAprobe.cmake

This file was deleted.

74 changes: 74 additions & 0 deletions cmake/funcCUDA.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
function(cuda_arch_probe)
if(NOT "" STREQUAL "${CMAKE_CUDA_COMPILER}")
set(_nvcc "${CMAKE_CUDA_COMPILER}")
elseif(NOT "" STREQUAL "${CUDA_COMPILER}")
set(_nvcc "${CUDA_COMPILER}")
elseif(NOT "" STREQUAL "${DEVICE_COMPILER}")
set(_nvcc "${DEVICE_COMPILER}")
endif()
execute_process(
COMMAND ${_nvcc} --help
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE _nvcc_help
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX REPLACE ";" "\\\\;" _nvcc_help "${_nvcc_help}")
string(REGEX REPLACE "\n" ";" _nvcc_help "${_nvcc_help}")
set(_archlist "")
foreach(_line ${_nvcc_help})
string(REGEX MATCHALL "(sm|compute)_[0-9]+" _has_arch ${_line})
string(REGEX REPLACE "(sm|compute)_" "" _has_arch "${_has_arch}")
if(_has_arch)
string(REGEX REPLACE "\\;" ";" _has_arch "${_has_arch}")
list(APPEND _archlist ${_has_arch})
endif()
endforeach()
list(SORT _archlist)
list(REMOVE_DUPLICATES _archlist)
if(APPLE)
if("9.0" VERSION_EQUAL CUDA_VERSION)
list(FIND _archlist "70" _hasVolta)
if(NOT -1 EQUAL _hasVolta)
message(WARNING "Removing \"70\" from valid CUDA architectures (OSX+CUDA9.0 detected)")
list(REMOVE_ITEM VALID_CUDA_ARCHS "70")
endif()
endif()
endif()
set(CMAKE_CUDA_ARCHLIST ${_archlist} PARENT_SCOPE)
endfunction()

function(cuda_arch_filter _WHAT _VALID _OUT)
#strip any chars except numbers and semicolons | sort | uniq
string(REGEX REPLACE "[^;0-9]+" "" _WHAT "${_WHAT}")
list(SORT _WHAT)
list(REMOVE_DUPLICATES _WHAT)
if(NOT "" STREQUAL "${_WHAT}")
# validate architectures provided
message(STATUS "Filtering provided compute architectures: ${_WHAT}")
set(_archlist "")
foreach(_arch ${_WHAT})
if(_arch MATCHES "^[0-9]$")
#single digit, append a 0
set(_arch "${_arch}0")
endif()
list(FIND _VALID "${_arch}" _arch_good)
if(NOT _arch MATCHES "^[0-9][0-9]$")
# only numbers are allowed
message(STATUS "...architecture '${_arch}' is not a number")
elseif(${_arch} LESS 20)
message(STATUS "...architecture '${_arch}' does not support required math functions. "
"Miner kernels require compute architecture 2.0 or higher.")
elseif(-1 EQUAL ${_arch_good})
message(STATUS "...architecture '${_arch}' is not supported by this nvcc")
else()
# nothing disqualified _arch above, keep it
list(APPEND _archlist ${_arch})
endif()
endforeach()
message(STATUS "Filtered result: ${_archlist}")
unset(_arch_good)
unset(_arch)
endif()
set("${_OUT}" "${_archlist}" PARENT_SCOPE)
endfunction()
# vim: et sw=4 sts=4 ts=4:
File renamed without changes.

0 comments on commit de23d1f

Please sign in to comment.