diff --git a/CMakeLists.txt b/CMakeLists.txt index eec03df9b..d3a9f9e63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,35 +1,36 @@ +cmake_minimum_required(VERSION 3.4.0 FATAL_ERROR) project(xmr-stak) -cmake_minimum_required(VERSION 3.4.0) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") +include(funcUtil) # enforce C++11 set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_STANDARD 11) +set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) + +################################################################################ +# CMake user options +################################################################################ +option(HWLOC_ENABLE "Enable or disable the requirement of hwloc" ON) +option(OpenSSL_ENABLE "Enable or disable the requirement of OpenSSL" ON) +option(MICROHTTPD_ENABLE "Enable or disable the requirement of microhttpd (http daemon)" ON) +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}") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "install prefix" FORCE) endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) -# help to find cuda on systems with a software module system -list(APPEND CMAKE_PREFIX_PATH "$ENV{CUDA_ROOT}") -# allow user to extent CMAKE_PREFIX_PATH via environment variable +# allow user to extend CMAKE_PREFIX_PATH via environment variable list(APPEND CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}") -################################################################################ -# CMake user options -################################################################################ - -# gcc 5.1 is the first GNU version without CoW strings -# https://github.com/fireice-uk/xmr-stak-nvidia/pull/10#issuecomment-290821792 -# If you remove this guard to compile with older gcc versions the miner will produce -# a high rate of wrong shares. -if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) - message(FATAL_ERROR "g++ version must be at least 5.1!") - endif() -endif() - set(BUILD_TYPE "Release;Debug") if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build" FORCE) @@ -38,181 +39,418 @@ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${BUILD_TYPE}") set(XMR-STAK_COMPILE "native" CACHE STRING "select CPU compute architecture") set_property(CACHE XMR-STAK_COMPILE PROPERTY STRINGS "native;generic") -if(XMR-STAK_COMPILE STREQUAL "native") - if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - set(CMAKE_CXX_FLAGS "-march=native -mtune=native ${CMAKE_CXX_FLAGS}") - set(CMAKE_C_FLAGS "-march=native -mtune=native ${CMAKE_C_FLAGS}") - endif() -elseif(XMR-STAK_COMPILE STREQUAL "generic") - add_definitions("-DCONF_ENFORCE_OpenCL_1_2=1") -else() +if(NOT (XMR-STAK_COMPILE STREQUAL "generic" OR XMR-STAK_COMPILE STREQUAL "native")) message(FATAL_ERROR "XMR-STAK_COMPILE is set to an unknown value '${XMR-STAK_COMPILE}'") endif() # option to add static libgcc and libstdc++ -option(CMAKE_LINK_STATIC "link as much as possible libraries static" OFF) +if(CMAKE_LINK_STATIC) + # activate static libgcc and libstdc++ linking + message(STATUS "Library mode: STATIC") + #set(_LINKTYPE "STATIC") + set(BUILD_SHARED_LIBRARIES OFF) + set(OPENSSL_USE_STATIC_LIBS TRUE) + #set(CMAKE_FIND_LIBRARY_SUFFIXES .a .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) +else() + message(STATUS "Library mode: SHARED") + #set(_LINKTYPE "SHARED") + set(BUILD_SHARED_LIBRARIES ON) + set(OPENSSL_USE_STATIC_LIBS FALSE) + set(MICROHTTPD_USE_STATIC_LIBS FALSE) +endif() ################################################################################ -# Find CUDA +# Find Threads (prefer Pthreads and compiler native flag) ################################################################################ -#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) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG FALSE) +find_package(Threads REQUIRED QUIET) -option(CUDA_ENABLE "Enable or disable CUDA support (NVIDIA backend)" ON) +################################################################################ +# Configure Assembler +################################################################################ +if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + enable_language(ASM_MASM) +else() + enable_language(ASM) +endif() + +################################################################################ +# Configure NVCC +################################################################################ if(CUDA_ENABLE) - find_package(CUDA 7.5) + 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) + 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() - if(CUDA_FOUND) - list(APPEND BACKEND_TYPES "nvidia") - option(XMR-STAK_LARGEGRID "Support large CUDA block count > 128" ON) - if(XMR-STAK_LARGEGRID) - add_definitions("-DXMR_STAK_LARGEGRID=${XMR-STAK_LARGEGRID}") - endif() +############################################################################### +# Define target: xmr-stak; Main CLI +############################################################################### +set(SRCFILES_CPP "xmrstak/cli/cli-miner.cpp") +set_source_files_properties(${SRCFILES_CPP} PROPERTIES LANGUAGE CXX) +if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + list(APPEND SRCFILES_CPP "xmrstak/cli/xmr-stak.manifest") +endif() +add_executable(xmr-stak ${SRCFILES_CPP}) - set(DEVICE_COMPILER "nvcc") - set(CUDA_COMPILER "${DEVICE_COMPILER}" CACHE STRING "Select the device compiler") +############################################################################### +# Define target: xmr-stak-c; Crypto Library +############################################################################### +add_library(xmr-stak-c + STATIC + "xmrstak/backend/cpu/crypto/c_blake256.c" + "xmrstak/backend/cpu/crypto/c_groestl.c" + "xmrstak/backend/cpu/crypto/c_jh.c" + "xmrstak/backend/cpu/crypto/c_keccak.c" + "xmrstak/backend/cpu/crypto/c_skein.c" +) +set_property(TARGET xmr-stak-c PROPERTY C_STANDARD 99) +#target_link_libraries(xmr-stak-c Threads::Threads) - if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") - list(APPEND DEVICE_COMPILER "clang") - endif() +############################################################################### +# Define target: xmr-stak-asm; Crypto Library, optional assembler code +############################################################################### +if(CMAKE_C_COMPILER_ID MATCHES "MSVC") + # MASM dialect + set_property(SOURCE "xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.asm" PROPERTY ASM_MASM) + add_library(xmr-stak-asm + STATIC + "xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.asm" + ) +else() + # default dialect with C-preprocessor pass + set_property(SOURCE "xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.S" PROPERTY C) + add_library(xmr-stak-asm + STATIC + "xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.S" + ) +endif() +set_property(TARGET xmr-stak-asm PROPERTY LINKER_LANGUAGE C) +target_link_libraries(xmr-stak-c xmr-stak-asm) - set_property(CACHE CUDA_COMPILER PROPERTY STRINGS "${DEVICE_COMPILER}") +############################################################################### +# Define target: xmr-stak-backend; generic backend files +############################################################################### +add_library(xmr-stak-backend + STATIC + "xmrstak/version.cpp" + "xmrstak/jconf.cpp" + "xmrstak/backend/cpu/jconf.cpp" + "xmrstak/backend/cpu/hwlocMemory.cpp" + "xmrstak/backend/cpu/minethd.cpp" + "xmrstak/backend/backendConnector.cpp" + "xmrstak/backend/globalStates.cpp" + "xmrstak/backend/cpu/crypto/cryptonight_common.cpp" + "xmrstak/http/webdesign.cpp" + "xmrstak/http/httpd.cpp" + "xmrstak/misc/console.cpp" + "xmrstak/misc/executor.cpp" + "xmrstak/misc/telemetry.cpp" + "xmrstak/misc/uac.cpp" + "xmrstak/misc/utility.cpp" + "xmrstak/net/jpsock.cpp" + "xmrstak/net/socket.cpp" +) +target_link_libraries(xmr-stak-backend xmr-stak-c) - set(XMR-STAK_THREADS 0 CACHE STRING "Set maximum number of threads (for compile time optimization)") - if(NOT XMR-STAK_THREADS EQUAL 0) - message(STATUS "xmr-stak-nvidia: set max threads per block to ${XMR-STAK_THREADS}") - add_definitions("-DXMR_STAK_THREADS=${XMR-STAK_THREADS}") - endif() - 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") +################################################################################ +# Probe compilers, work around bugs, add optimal flags +################################################################################ +if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + # remove warnings that f_open() is not save and f_open_s should be used + target_compile_definitions(xmr-stak-c PUBLIC _CRT_SECURE_NO_DEPRECATE) + # disable min define to allow usage of std::min + target_compile_definitions(xmr-stak-c PUBLIC NOMINMAX) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + get_filename_component(ICC_ROOT ${CMAKE_C_COMPILER} DIRECTORY) + get_filename_component(ICC_ROOT ${ICC_ROOT} DIRECTORY) + message(STATUS "ICC: adding include+lib root ${ICC_ROOT}") + list(INSERT 0 CMAKE_PREFIX_PATH "${ICC_ROOT}") + #include_directories("${ICC_ROOT}/include") + link_directories("${ICC_ROOT}/lib") + unset(ICC_REAL) + unset(ICC_ROOT) + if(NOT WIN32) + execute_process( + COMMAND gcc -dumpversion + OUTPUT_VARIABLE GCCMAJOR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 17) AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19)) + #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") + #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") + # locate best gcc version to pass to icc-18 (gcc-8 doesn't work, for example) + if(${GCCMAJOR} VERSION_GREATER 7 OR DEFINED ICC_GCCVER) + # Use -DICC_GCCVER=6 for example to force 'gcc-6' and 'g++-6' + if(DEFINED ICC_GCCVER) + # just literally override, no checks + set(ICC_GXX "g++-${ICC_GCCVER}") + set(ICC_GCC "gcc-${ICC_GCCVER}") + else() + message(STATUS "ICC: version 18 can't use system compiler gcc-${GCCMAJOR}, seeking alternative") + # Otherwise, the newest available and compatible pair will be selected + find_program(ICC_GXX NAMES "g++-7" "g++-6" "g++") + get_filename_component(ICC_GXX ${ICC_GXX} NAME) + find_program(ICC_GCC NAMES "gcc-7" "gcc-6" "gcc") + get_filename_component(ICC_GCC ${ICC_GCC} NAME) + endif() + message(STATUS "ICC: setting subcompiler flags: -gxx-name=${ICC_GXX} -gcc-name=${ICC_GCC}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gxx-name=${ICC_GXX} -gcc-name=${ICC_GCC}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gxx-name=${ICC_GXX} -gcc-name=${ICC_GCC}") + unset(ICC_GXX) + unset(ICC_GCC) + endif() 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() + if(XMR-STAK_COMPILE STREQUAL "native") + # activate optimize for current host CPU + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fast") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fast") + target_compile_definitions(xmr-stak-c PUBLIC __PURE_INTEL_C99_HEADERS__) + endif() + if(CMAKE_LINK_STATIC) + set(LIBS "-static-libgcc -static-libstdc++ -static-intel ${LIBS}") + endif() +else() + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) + # gcc 5.1 is the first GNU version without CoW strings + # https://github.com/fireice-uk/xmr-stak-nvidia/pull/10#issuecomment-290821792 + # If you remove this guard to compile with older gcc versions the miner will produce + # a high rate of wrong shares. + message(FATAL_ERROR "g++ version must be at least 5.1!") 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() + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + # add -Wall for debug builds with gcc + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") endif() - set(CUDA_ARCH "${DEFAULT_CUDA_ARCH}" CACHE STRING "Set GPU architecture (semicolon separated list, e.g. '-DCUDA_ARCH=20;35;60')") - - # generate comma separated list with architectures - string(REPLACE ";" "+" STR_CUDA_ARCH "${CUDA_ARCH}") - add_definitions("-DXMRSTAK_CUDA_ARCH_LIST=${STR_CUDA_ARCH}") - - # validate architectures (only numbers are allowed) - foreach(CUDA_ARCH_ELEM ${CUDA_ARCH}) - string(REGEX MATCH "^[0-9]+$" IS_NUMBER ${CUDA_ARCH}) - 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() - - 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) - - 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") - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11") - endif() + endif() + if(CMAKE_LINK_STATIC AND (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID} STREQUAL "GNU")) + set(LIBS "-static-libgcc -static-libstdc++ ${LIBS}") + endif() + # below here is applied to all other compilers including GNU + if(XMR-STAK_COMPILE STREQUAL "native") + # activate optimize for current host CPU + set(CMAKE_CXX_FLAGS "-march=native -mtune=native ${CMAKE_CXX_FLAGS}") + set(CMAKE_C_FLAGS "-march=native -mtune=native ${CMAKE_C_FLAGS}") + endif() + # activate sse2 and aes-ni in all cases + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -maes") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -maes") +endif() - # avoid that nvcc in CUDA 8 complains about sm_20 pending removal - if(CUDA_VERSION VERSION_EQUAL 8.0) - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Wno-deprecated-gpu-targets") - endif() +################################################################################ +# Define feature: Windows Sockets +################################################################################ +if(WIN32) + message(STATUS "Adding Windows Socket Libraries: wsock32 ws2_32") + target_link_libraries(xmr-stak-backend wsock32 ws2_32) +endif() - # avoid that nvcc in CUDA < 8 tries to use libc `memcpy` within the kernel - if(CUDA_VERSION VERSION_LESS 8.0) - add_definitions(-D_FORCE_INLINES) - endif() - foreach(CUDA_ARCH_ELEM ${CUDA_ARCH}) - # set flags to create device code for the given architecture - set(CUDA_NVCC_FLAGS ${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() +################################################################################ +# Define feature: libhwloc +################################################################################ +if(HWLOC_ENABLE) + # Find hwloc + find_path(HWLOC_INCLUDE_DIR + NAMES + hwloc.h + PATHS + ENV "HWLOC_ROOT" + /opt/local + /usr/local + /usr + ENV "PROGRAMFILES(X86)" + PATH_SUFFIXES + include) - # give each thread an independent default stream - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} --default-stream per-thread") + find_library(HWLOC_LIBRARY + NAMES + libhwloc.lib + hwloc + PATHS + ENV "HWLOC_ROOT" + PATH_SUFFIXES + lib) - option(CUDA_SHOW_CODELINES "Show kernel lines in cuda-gdb and cuda-memcheck" OFF) + if(HWLOC STREQUAL "HWLOC-NOTFOUND" OR ${HWLOC_INCLUDE_DIR} STREQUAL "HWLOC_INCLUDE_DIR-NOTFOUND") + message(FATAL_ERROR "hwloc NOT found: use `-DHWLOC_ENABLE=OFF` to build without hwloc support") + else() + set(HWLOC_FOUND TRUE) + listFilterLibs("${HWLOC_LIBRARY}" HWLOC_LIBRARY) + message(STATUS "Found hwloc @ ${HWLOC_LIBRARY} (${HWLOC_INCLUDE_DIR})") + add_library(libhwloc MODULE IMPORTED) + target_include_directories(libhwloc INTERFACE "${HWLOC_INCLUDE_DIR}") + set_target_properties(libhwloc PROPERTIES IMPORTED_LOCATION "${HWLOC_LIBRARY}") + target_link_libraries(xmr-stak-backend libhwloc) + endif() +else() + target_compile_definitions(xmr-stak-backend PUBLIC CONF_NO_HWLOC) +endif() - if(CUDA_SHOW_CODELINES) - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" --source-in-ptx -lineinfo) - set(CUDA_KEEP_FILES ON CACHE BOOL "activate keep files" FORCE) - endif(CUDA_SHOW_CODELINES) +############################################################################### +# Define feature: OpenSSL (for connection to pools) +############################################################################### +if(OpenSSL_ENABLE) + # Find OpenSSL + find_package(OpenSSL QUIET) + if(OPENSSL_FOUND) + if(OPENSSL_SSL_LIBRARY) + listFilterLibs("${OPENSSL_SSL_LIBRARY}" OPENSSL_SSL_LIBRARY) + message(STATUS "Found OpenSSL v${OPENSSL_VERSION} libssl @ ${OPENSSL_SSL_LIBRARY} (${OPENSSL_INCLUDE_DIR})") + add_library(libssl MODULE IMPORTED) + #add_library(libssl ${_LINKTYPE} IMPORTED) + target_include_directories(libssl INTERFACE "${OPENSSL_INCLUDE_DIR}") + set_target_properties(libssl PROPERTIES IMPORTED_LOCATION "${OPENSSL_SSL_LIBRARY}") + target_link_libraries(xmr-stak-backend libssl) + endif() + if(OPENSSL_CRYPTO_LIBRARY) + listFilterLibs("${OPENSSL_CRYPTO_LIBRARY}" OPENSSL_CRYPTO_LIBRARY) + message(STATUS "Found OpenSSL v${OPENSSL_VERSION} libcrypto @ ${OPENSSL_CRYPTO_LIBRARY} (${OPENSSL_INCLUDE_DIR})") + add_library(libcrypto MODULE IMPORTED) + target_include_directories(libcrypto INTERFACE "${OPENSSL_INCLUDE_DIR}") + set_target_properties(libcrypto PROPERTIES IMPORTED_LOCATION "${OPENSSL_CRYPTO_LIBRARY}") + target_link_libraries(xmr-stak-backend libcrypto) + endif() + 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() +else() + target_compile_definitions(xmr-stak-backend PUBLIC CONF_NO_TLS) +endif() - if(CUDA_SHOW_REGISTER) - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" -Xptxas=-v) - endif(CUDA_SHOW_REGISTER) +################################################################################ +# Define feature: microhttpd +################################################################################ +if(MICROHTTPD_ENABLE) + find_package(MicroHttpd QUIET) + if(MICROHTTPD_FOUND) + listFilterLibs("${MICROHTTPD_LIBRARY}" MICROHTTPD_LIBRARY) + message(STATUS "Found microhttpd v${MICROHTTPD_VERSION} @ ${MICROHTTPD_LIBRARY} (${MICROHTTPD_INCLUDE_DIR})") + add_library(libmicrohttpd MODULE IMPORTED) + target_include_directories(libmicrohttpd INTERFACE "${MICROHTTPD_INCLUDE_DIR}") + set_target_properties(libmicrohttpd PROPERTIES IMPORTED_LOCATION "${MICROHTTPD_LIBRARY}") + target_link_libraries(xmr-stak-backend libmicrohttpd "${MICROHTTPD_LIBS_EXTRA}") + target_link_libraries(xmr-stak "${MICROHTTPD_LIBS_EXTRA}") + else() + message(FATAL_ERROR "microhttpd NOT found: use `-DMICROHTTPD_ENABLE=OFF` to build without http daemon support") + endif() +else() + target_compile_definitions(xmr-stak-backend PUBLIC CONF_NO_HTTPD) +endif() - if(CUDA_KEEP_FILES) - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" --keep --keep-dir "${PROJECT_BINARY_DIR}") - endif(CUDA_KEEP_FILES) +############################################################################### +# Define backend: cpu +############################################################################### +if(NOT CPU_ENABLE) + target_compile_definitions(xmr-stak-backend PUBLIC CONF_NO_CPU) +else() + list(APPEND BACKEND_TYPES "cpu") +endif() - if(CUDA_VERSION VERSION_LESS 8.0) - # for CUDA 7.5 fix compile error: https://github.com/fireice-uk/xmr-stak/issues/34 - set(CUDA_NVCC_FLAGS "${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) +################################################################################ +# Define backend: nvidia +################################################################################ +if(CUDA_ENABLE) + if(CMAKE_VERSION VERSION_LESS 3.8) + include(CUDAold) + else() + include(CUDA) + endif() + if(CUDA_FOUND) + ############################################################################### + # Define target: xmrstak_cuda_backend; nvidia backend shared lib + ############################################################################### + set(CUDASRCFILES "") + list(APPEND CUDASRCFILES + "xmrstak/backend/nvidia/jconf.cpp" + "xmrstak/backend/nvidia/nvcc_code/cuda_core.cu" + "xmrstak/backend/nvidia/nvcc_code/cuda_extra.cu" + "xmrstak/backend/nvidia/minethd.cpp" + ) + if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" OR CUDA_COMPILER STREQUAL "nvcc") + # build device code with nvcc + if(NOT CMAKE_VERSION VERSION_LESS 3.8) + #native CUDA support + add_library( + xmrstak_cuda_backend + SHARED + ${CUDASRCFILES} + ) + set_target_properties(xmrstak_cuda_backend PROPERTIES CUDA_SEPERABLE_COMPILATION ON) + else() + #plugin CUDA support (old) + cuda_add_library( + xmrstak_cuda_backend + SHARED + ${CUDASRCFILES} + ) endif() else() - message(FATAL_ERROR "selected CUDA compiler '${CUDA_COMPILER}' is not supported") + # 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) + 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 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") endif() else() - add_definitions("-DCONF_NO_CUDA") + target_compile_definitions(xmr-stak-backend PUBLIC CONF_NO_CUDA) endif() -# help to find AMD app SDK on systems with a software module system -list(APPEND CMAKE_PREFIX_PATH "$ENV{AMDAPPSDKROOT}") -# allow user to extent CMAKE_PREFIX_PATH via environment variable -list(APPEND CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}") - ############################################################################### -# Find OpenCL +# Define backend: amd ############################################################################### - -option(OpenCL_ENABLE "Enable or disable OpenCL spport (AMD GPU support)" ON) if(OpenCL_ENABLE) + # Find OpenCL + # help systems with a software module system + list(APPEND CMAKE_PREFIX_PATH "$ENV{AMDAPPSDKROOT}") + # try to find AMD OpenCL before NVIDIA OpenCL find_path(OpenCL_INCLUDE_DIR NAMES @@ -233,7 +471,6 @@ if(OpenCL_ENABLE) find_library(OpenCL_LIBRARY NAMES OpenCL - OpenCL.lib NO_DEFAULT_PATH PATHS ENV "OpenCL_ROOT" @@ -249,306 +486,121 @@ if(OpenCL_ENABLE) # find package will use the previews searched path variables find_package(OpenCL) if(OpenCL_FOUND) - list(APPEND BACKEND_TYPES "amd") + set(CL_TARGET_OPENCL_VERSION "${OpenCL_VERSION_MAJOR}${OpenCL_VERSION_MINOR}0") + + ############################################################################### + # 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" + ) + 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_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}) - #set(LIBS ${LIBS} ${OpenCL_LIBRARY}) - link_directories(${OpenCL_LIBRARY}) + list(APPEND BACKEND_TYPES "amd") else() message(FATAL_ERROR "OpenCL NOT found: use `-DOpenCL_ENABLE=OFF` to build without OpenCL support for AMD gpu's") endif() else() - add_definitions("-DCONF_NO_OPENCL") -endif() - -############################################################################### -# CPU backend -############################################################################### - -option(CPU_ENABLE "Enable or disable CPU support" ON) -if(NOT CPU_ENABLE) - add_definitions("-DCONF_NO_CPU") -else() - list(APPEND BACKEND_TYPES "cpu") -endif() - -################################################################################ -# Find PThreads -################################################################################ - -if(NOT WIN32) - find_package(Threads REQUIRED) - set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT}) -endif() -################################################################################ -# Find microhttpd -################################################################################ - -option(MICROHTTPD_ENABLE "Enable or disable the requirement of microhttp (http daemon)" ON) -if(MICROHTTPD_ENABLE) - find_path(MTHD_INCLUDE_DIR - NAMES - microhttpd.h - PATHS - /opt/local - /usr/local - /usr - ENV "PROGRAMFILES(X86)" - ENV "MICROHTTPD_ROOT" - PATH_SUFFIXES - include) - - find_library(MHTD - NAMES - microhttpd - libmicrohttpd.lib - PATHS - ENV "MICROHTTPD_ROOT" - PATH_SUFFIXES - lib) - if(MHTD STREQUAL "MHTD-NOTFOUND") - message(FATAL_ERROR "microhttpd NOT found: use `-DMICROHTTPD_ENABLE=OFF` to build without http daemon support") - else() - set(LIBS ${LIBS} ${MHTD}) - include_directories(AFTER ${MTHD_INCLUDE_DIR}) - endif() -else() - add_definitions("-DCONF_NO_HTTPD") -endif() - -############################################################################### -# Find OpenSSL -############################################################################### - -option(OpenSSL_ENABLE "Enable or disable the requirement of OpenSSL" ON) -if(OpenSSL_ENABLE) - find_package(OpenSSL) - if(OPENSSL_FOUND) - include_directories(${OPENSSL_INCLUDE_DIR}) - set(LIBS ${LIBS} ${OPENSSL_LIBRARIES}) - else() - message(FATAL_ERROR "OpenSSL NOT found: use `-DOpenSSL_ENABLE=OFF` to build without SSL support") - endif() -else() - add_definitions("-DCONF_NO_TLS") -endif() - -################################################################################ -# Find hwloc -################################################################################ - -option(HWLOC_ENABLE "Enable or disable the requirement of hwloc" ON) -if(HWLOC_ENABLE) - find_path(HWLOC_INCLUDE_DIR - NAMES - hwloc.h - PATHS - /opt/local - /usr/local - /usr - ENV "PROGRAMFILES(X86)" - ENV "HWLOC_ROOT" - PATH_SUFFIXES - include) - - find_library(HWLOC - NAMES - libhwloc.lib - hwloc - PATHS - ENV "HWLOC_ROOT" - PATH_SUFFIXES - lib) - - if(HWLOC STREQUAL "HWLOC-NOTFOUND" OR ${HWLOC_INCLUDE_DIR} STREQUAL "HWLOC_INCLUDE_DIR-NOTFOUND") - message(FATAL_ERROR "hwloc NOT found: use `-DHWLOC_ENABLE=OFF` to build without hwloc support") - else() - set(LIBS ${LIBS} ${HWLOC}) - include_directories(AFTER ${HWLOC_INCLUDE_DIR}) - endif() -else() - add_definitions("-DCONF_NO_HWLOC") -endif() - -################################################################################ -# Windows Sockets -################################################################################ - -if(WIN32) - set(LIBS ${LIBS} wsock32 ws2_32) + target_compile_definitions(xmr-stak-backend PUBLIC CONF_NO_OPENCL) endif() ################################################################################ # Versioning ################################################################################ -# Get the current working branch -execute_process( - COMMAND git rev-parse --abbrev-ref HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_BRANCH - OUTPUT_STRIP_TRAILING_WHITESPACE -) - -# Get the latest abbreviated commit hash of the working branch -execute_process( - COMMAND git log -1 --format=%h - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_COMMIT_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE -) +message(STATUS "Collecting version information...") -if(NOT GIT_COMMIT_HASH STREQUAL "") - add_definitions("-DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}") -endif() -if(NOT GIT_BRANCH STREQUAL "") - add_definitions("-DGIT_BRANCH=${GIT_BRANCH}") -endif() +# default known unknowns +set(XMR_STAK_NAME "xmr-stak") +set(XMR_STAK_VERSION "0.0.0") +set(GIT_BRANCH "unknown") +set(GIT_COMMIT_HASH "0000000") # generate backend string +list(SORT BACKEND_TYPES) string(REPLACE ";" "-" STR_BACKEND_TYPES "${BACKEND_TYPES}") -add_definitions("-DBACKEND_TYPE=${STR_BACKEND_TYPES}") - -################################################################################ -# Compile & Link -################################################################################ - -include_directories(BEFORE .) - -set (CMAKE_POSITION_INDEPENDENT_CODE TRUE) - -if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - # remove warnings that f_open() is not save and f_open_s should be used - add_definitions(-D_CRT_SECURE_NO_DEPRECATE) - # disable min define to allow usage of std::min - add_definitions(-DNOMINMAX) -else() - # activate sse2 and aes-ni - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -maes") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -maes") -endif() - -# add -Wall for debug builds with gcc -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") - endif() -endif() - -# activate static libgcc and libstdc++ linking -if(CMAKE_LINK_STATIC) - set(BUILD_SHARED_LIBRARIES OFF) - set(DL_LIB ${CMAKE_DL_LIBS}) - set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") - if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID} STREQUAL "GNU") - set(LIBS "-static-libgcc -static-libstdc++ ${LIBS}") +target_compile_definitions(xmr-stak-c PUBLIC "BACKEND_TYPE=${STR_BACKEND_TYPES}") + +# get the current working branch +find_package(Git QUIET) +if(GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT GIT_BRANCH STREQUAL "") + target_compile_definitions(xmr-stak-c PUBLIC "GIT_BRANCH=${GIT_BRANCH}") endif() -endif() -if(CMAKE_C_COMPILER_ID MATCHES "MSVC") - # asm optimized monero v8 code - enable_language(ASM_MASM) - set_property(SOURCE "xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.asm" PROPERTY ASM_MASM) - add_library(xmr-stak-asm - STATIC - "xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.asm" - ) -else() - # asm optimized monero v8 code - enable_language(ASM) - set_property(SOURCE "xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.S" PROPERTY C) - add_library(xmr-stak-asm - STATIC - "xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.S" + # Get the latest abbreviated commit hash of the working branch + execute_process( + COMMAND ${GIT_EXECUTABLE} log -1 --format=%h + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE ) + if(NOT GIT_COMMIT_HASH STREQUAL "") + target_compile_definitions(xmr-stak-c PUBLIC "GIT_COMMIT_HASH=${GIT_COMMIT_HASH}") + endif() endif() - -set_property(TARGET xmr-stak-asm PROPERTY LINKER_LANGUAGE C) - -# compile C files -file(GLOB SRCFILES_C "xmrstak/backend/cpu/crypto/*.c") - -add_library(xmr-stak-c - STATIC - ${SRCFILES_C} +get_target_property(DEFS xmr-stak-c COMPILE_DEFINITIONS) +string(REGEX REPLACE ";" " -D" DEFS "-D${DEFS}") +set(CMAKE_BINTMP_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp") +file(WRITE "${CMAKE_BINTMP_DIR}/xmr-stak-ver.cpp" + "#include \"xmrstak/donate-level.hpp\"\n" + "#include \"xmrstak/version.hpp\"\n" + "#include \n" + "int main(int argc,char *argv[]){std::cout<< get_version_str() << std::endl;return 0;}" ) -set_property(TARGET xmr-stak-c PROPERTY C_STANDARD 99) -if(MICROHTTPD_ENABLE) - target_link_libraries(xmr-stak-c ${MHTD}) -endif() -target_link_libraries(xmr-stak-c ${LIBS} xmr-stak-asm) - -# compile generic backend files -file(GLOB BACKEND_CPP - "xmrstak/*.cpp" - "xmrstak/backend/cpu/*.cpp" - "xmrstak/backend/*.cpp" - "xmrstak/backend/cpu/crypto/*.cpp" - "xmrstak/http/*.cpp" - "xmrstak/misc/*.cpp" - "xmrstak/net/*.cpp") - -add_library(xmr-stak-backend - STATIC - ${BACKEND_CPP} +try_compile(BUILD_OK + ${CMAKE_BINARY_DIR} + SOURCES "${CMAKE_SOURCE_DIR}/xmrstak/version.cpp" "${CMAKE_BINTMP_DIR}/xmr-stak-ver.cpp" + CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${CMAKE_SOURCE_DIR}" + COMPILE_DEFINITIONS ${DEFS} + OUTPUT_VARIABLE BLDLOG + COPY_FILE ${CMAKE_BINTMP_DIR}/xmr-stak-ver ) -target_link_libraries(xmr-stak-backend xmr-stak-c ${CMAKE_DL_LIBS} xmr-stak-asm) - -# compile CUDA backend -if(CUDA_FOUND) - 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() - target_link_libraries(xmrstak_cuda_backend ${CUDA_LIBRARIES}) - target_link_libraries(xmrstak_cuda_backend xmr-stak-backend xmr-stak-asm) -endif() - -# compile AMD backend -if(OpenCL_FOUND) - file(GLOB OPENCLSRCFILES - "xmrstak/backend/amd/amd_gpu/*.cpp" - "xmrstak/backend/amd/*.cpp") - add_library(xmrstak_opencl_backend - SHARED - ${OPENCLSRCFILES} +if(BUILD_OK) + execute_process( + COMMAND ${CMAKE_BINTMP_DIR}/xmr-stak-ver + WORKING_DIRECTORY ${CMAKE_BINTMP_DIR} + OUTPUT_VARIABLE VERSION_LONG + OUTPUT_STRIP_TRAILING_WHITESPACE ) - target_link_libraries(xmrstak_opencl_backend ${OpenCL_LIBRARY} ) - target_link_libraries(xmrstak_opencl_backend xmr-stak-backend xmr-stak-asm) -endif() - -# compile final binary -file(GLOB SRCFILES_CPP "xmrstak/cli/*.cpp") -set_source_files_properties(${SRCFILES_CPP} PROPERTIES LANGUAGE CXX) - -if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - add_executable(xmr-stak ${SRCFILES_CPP} xmrstak/cli/xmr-stak.manifest) else() - add_executable(xmr-stak ${SRCFILES_CPP}) + message(FATAL_ERROR "${BLDLOG}") endif() +message(STATUS "Version: ${VERSION_LONG}") +string(REPLACE "/" ";" lst_ver "${VERSION_LONG}") +list(APPEND lst_ver "${PROJECT_NAME}" "0.0.0") +list(GET lst_ver 1 nVersion) +project(xmr-stak VERSION ${nVersion}) +message(STATUS "Libs:" + " [threads:${THREADS_FOUND}]" + " [hwloc:${HWLOC_FOUND}]" + " [ssl:${OPENSSL_FOUND}]" + " [httpd:${MICROHTTPD_FOUND}]" +) +message(STATUS "Backend: [cpu:${CPU_ENABLE}] [amd:${OpenCL_ENABLE}] [nvidia:${CUDA_ENABLE}]") -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}") - -target_link_libraries(xmr-stak ${LIBS} xmr-stak-c xmr-stak-backend xmr-stak-asm) +################################################################################ +# Compile & Link +################################################################################ +include_directories(BEFORE .) +target_link_libraries(xmr-stak xmr-stak-backend) ################################################################################ # Install @@ -579,4 +631,5 @@ if( NOT CMAKE_INSTALL_PREFIX STREQUAL PROJECT_BINARY_DIR ) else() # this rule is used if the install prefix is the build directory install(CODE "MESSAGE(\"xmr-stak installed to folder 'bin'\")") -endif() \ No newline at end of file +endif() +# vim: et sw=4 sts=4 ts=4: diff --git a/cmake/CUDA.cmake b/cmake/CUDA.cmake new file mode 100644 index 000000000..e94026ca7 --- /dev/null +++ b/cmake/CUDA.cmake @@ -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: diff --git a/cmake/CUDAold.cmake b/cmake/CUDAold.cmake new file mode 100644 index 000000000..76448e7f1 --- /dev/null +++ b/cmake/CUDAold.cmake @@ -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: diff --git a/cmake/FindMicroHttpd.cmake b/cmake/FindMicroHttpd.cmake new file mode 100644 index 000000000..64d9a370b --- /dev/null +++ b/cmake/FindMicroHttpd.cmake @@ -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: diff --git a/cmake/funcCUDA.cmake b/cmake/funcCUDA.cmake new file mode 100644 index 000000000..ef2236f77 --- /dev/null +++ b/cmake/funcCUDA.cmake @@ -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: diff --git a/cmake/funcUtil.cmake b/cmake/funcUtil.cmake new file mode 100644 index 000000000..244c9a040 --- /dev/null +++ b/cmake/funcUtil.cmake @@ -0,0 +1,30 @@ +function(listFilterLibs _strI _strO) + set(_lst_in "") + list(APPEND _lst_in ${_strI}) + list(FIND _lst_in "optimized" _msFmt) + if(-1 EQUAL _msFmt) + list(FIND _lst_in "debug" _msFmt) + if(-1 EQUAL _msFmt) + set(${_strO} "${_strI}" PARENT_SCOPE) + endif() + else() + string(TOLOWER "${CMAKE_BUILD_TYPE}" _type) + set(_grab_next FALSE) + foreach(_ent ${_lst_in}) + if(_grab_next) + set(${_strO} "${_ent}" PARENT_SCOPE) + break() + endif() + if("${_ent}" STREQUAL "optimized") + set(_ent "release") + endif() + if("${_type}" STREQUAL "${_ent}") + set(_grab_next TRUE) + endif() + endforeach() + unset(_ent) + unset(_type) + unset(_grab_next) + endif() +endfunction() +# vim: et sw=4 sts=4 ts=4: diff --git a/xmrstak/backend/amd/autoAdjust.hpp b/xmrstak/backend/amd/autoAdjust.hpp index c5b331c87..f9d11c633 100644 --- a/xmrstak/backend/amd/autoAdjust.hpp +++ b/xmrstak/backend/amd/autoAdjust.hpp @@ -50,7 +50,7 @@ class autoAdjust if(platformIndex == -1) { - printer::inst()->print_msg(L0,"WARNING: No AMD OpenCL platform found. Possible driver issues or wrong vendor driver."); + printer::inst()->print_msg(L0,"WARNING: No OpenCL platform found. Possible driver issues or wrong vendor driver."); return false; } @@ -61,7 +61,7 @@ class autoAdjust if(deviceCount == 0) { - printer::inst()->print_msg(L0,"WARNING: No AMD device found."); + printer::inst()->print_msg(L0,"WARNING: No OpenCL device found."); return false; } diff --git a/xmrstak/cli/cli-miner.cpp b/xmrstak/cli/cli-miner.cpp index ae39d2505..c35868f01 100644 --- a/xmrstak/cli/cli-miner.cpp +++ b/xmrstak/cli/cli-miner.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #ifndef CONF_NO_TLS #include