From 317cdf4ef29952eb37eb02bae07de7502be2eccd Mon Sep 17 00:00:00 2001 From: Tony Butler Date: Fri, 28 Sep 2018 22:02:28 -0600 Subject: [PATCH] Retooled entire CMakeLists (still works!) --- .appveyor.yml | 228 ++++- CMakeLists.txt | 952 ++++++++++-------- cmake/CUDA.cmake | 84 ++ cmake/CUDAold.cmake | 194 ++++ cmake/FindMicroHttpd.cmake | 117 +++ cmake/funcCUDA.cmake | 73 ++ cmake/funcUtil.cmake | 30 + doc/compile.md | 8 +- xmrstak/backend/amd/autoAdjust.hpp | 4 +- xmrstak/backend/nvidia/nvcc_code/cuda_core.cu | 10 +- xmrstak/cli/cli-miner.cpp | 14 +- xmrstak/misc/executor.cpp | 2 +- xmrstak/net/socks.hpp | 2 +- 13 files changed, 1263 insertions(+), 455 deletions(-) create mode 100644 cmake/CUDA.cmake create mode 100644 cmake/CUDAold.cmake create mode 100644 cmake/FindMicroHttpd.cmake create mode 100644 cmake/funcCUDA.cmake create mode 100644 cmake/funcUtil.cmake diff --git a/.appveyor.yml b/.appveyor.yml index c336842d5..dc47bede9 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,33 +1,211 @@ -# image -image: Visual Studio 2015 +# image, platform, configuration +image: +- Visual Studio 2017 +platform: +- x64 +configuration: +- Release -# build platform -platform: x64 +environment: + global: + #setup global source, build, deps, bin paths + XMR_SRC: c:\xmr-stak + XMR_BLD: $(XMR_SRC)\build + XMR_DEP: $(XMR_BLD)\dep + XMR_BIN: $(XMR_BLD)\bin + # preload various CUDA toolkit paths + NVKIT: $(ProgramFiles)\NVIDIA GPU Computing Toolkit + CUDA_PATH_V8_0: $(NVKIT)\CUDA\v8.0 + CUDA_PATH_V9_0: $(NVKIT)\CUDA\v9.0 + CUDA_PATH_V9_1: $(NVKIT)\CUDA\v9.1 + CUDA_PATH_V9_2: $(NVKIT)\CUDA\v9.2 + CUDA_PATH_V10_0: $(NVKIT)\CUDA\v10.0 + # for test phase + XMRSTAK_NOWAIT: 1 + ARCHLIST: 30;999;21;75;1.5;69 + # for build phase / default to latest VS2017 with tools 14.11 (compatible with the most CUDA versions) + VS15DIR: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community + VS14DIR: C:\Program Files (x86)\Microsoft Visual Studio 14.0 + V140MSB: C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140 + V141MSB: $(VS15DIR)\Common7\IDE\VC\VCTargets + G_ARG: Visual Studio 14 2015 Win64 + TOOLSET: v140 + VCVARSV: 14.0 + XMR_DEP_VER: $(XMR_DEP)\$(TOOLSET) + CMAKE_PREFIX_PATH: $(XMR_DEP_VER)\hwloc;$(XMR_DEP_VER)\libmicrohttpd;$(XMR_DEP_VER)\openssl + matrix: + - cuda: 8.0 + - cuda: 9.0 + - cuda: 9.1 + - cuda: 9.2 + - cuda: 10.0 +matrix: + fast_finish: true -# clone directory -clone_folder: c:\xmr-stak +clone_folder: $(XMR_SRC) install: - - mkdir c:\xmr-stak-dep - - curl -sL https://github.com/fireice-uk/xmr-stak-dep/releases/download/v1/xmr-stak-dep.zip -o xmr-stak-dep.zip - - 7z x xmr-stak-dep.zip -o"c:\xmr-stak-dep" -y > nul - - appveyor DownloadFile https://developer.nvidia.com/compute/cuda/8.0/prod/local_installers/cuda_8.0.44_windows-exe -FileName cuda_8.0.44_windows.exe - - cuda_8.0.44_windows.exe -s compiler_8.0 cudart_8.0 - - set PATH=%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin;%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v8.0\libnvvp;%PATH% - - nvcc -V +- mkdir "%XMR_BLD%" +- mkdir "%XMR_DEP%" +- set INCLUDE= +- set LIBPATH= +- set LIB= build_script: - - call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsMSBuildCmd.bat" - - cd c:\xmr-stak - - mkdir build - - cd build - - set CMAKE_PREFIX_PATH=C:\xmr-stak-dep\hwloc;C:\xmr-stak-dep\libmicrohttpd;C:\xmr-stak-dep\openssl; - - cmake -G "Visual Studio 14 2015 Win64" -T v140,host=x64 .. -DCUDA_ARCH=30 - - cmake --build . --config Release --target install +- rem this triggers non-MSBuild mode but gets overridden by matrix below + +for: +- + matrix: + only: + - cuda: 8.0 + environment: + CUDA_PATH: $(CUDA_PATH_V8_0) + PATH: $(CUDA_PATH)\bin;$(CUDA_PATH)\libnvvp;$(PATH) + build_script: + - call "%VS14DIR%\Common7\Tools\VsMSBuildCmd.bat" + - call "%VS14DIR%\VC\vcvarsall.bat" x64 8.1 + - cd "%XMR_DEP%" + # install nvcc + - appveyor DownloadFile https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_win10-exe -FileName cuda80.exe + - cuda80.exe -s compiler_8.0 + - nvcc -V + # install manually just the integration parts MSBuild needs + # if done normally it drags in profilers and NVTX and the driver etc which fails + - 7z x -y -ocudapkg cuda80.exe CUDAVisualStudioIntegration/extras/visual_studio_integration > nul + - copy cudapkg\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions\* "%V140MSB%\BuildCustomizations" + # xmr-stak-dep for v140 + - appveyor DownloadFile https://github.com/fireice-uk/xmr-stak-dep/releases/download/v1/xmr-stak-dep.zip + - 7z x xmr-stak-dep.zip -o"%TOOLSET%" -y > nul + - cd "%XMR_BLD%" + - cmake -G "%G_ARG%" -T %TOOLSET%,host=x64,cuda=%cuda% -DCUDA_ARCH=%ARCHLIST% -DCUDA_SHOW_REGISTER=ON "%XMR_SRC%" + - cmake --build "%XMR_BLD%" --config %CONFIGURATION% --target install + +- + matrix: + only: + - cuda: 9.0 + environment: + CUDA_PATH: $(CUDA_PATH_V9_0) + PATH: $(CUDA_PATH)\bin;$(CUDA_PATH)\libnvvp;$(PATH) + build_script: + - call "%VS14DIR%\Common7\Tools\VsMSBuildCmd.bat" + - call "%VS14DIR%\VC\vcvarsall.bat" x64 8.1 + - cd "%XMR_DEP%" + # install nvcc + - appveyor DownloadFile https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda_9.0.176_win10-exe -FileName cuda90.exe + - cuda90.exe -s compiler_9.0 + - nvcc -V + # install nvcc update from patch3 + - appveyor DownloadFile https://developer.nvidia.com/compute/cuda/9.0/Prod/patches/3/cuda_9.0.176.3_windows-exe -FileName cuda90p3.exe + - cuda90p3.exe -s compiler_9.0 + - nvcc -V + # install manually just the integration parts MSBuild needs + # if done normally it drags in profilers and NVTX and the driver etc which fails + - 7z x -y -ocudapkg cuda90.exe CUDAVisualStudioIntegration/extras/visual_studio_integration > nul + - copy cudapkg\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions\* "%V140MSB%\BuildCustomizations" + # xmr-stak-dep for v140 + - appveyor DownloadFile https://github.com/fireice-uk/xmr-stak-dep/releases/download/v1/xmr-stak-dep.zip + - 7z x xmr-stak-dep.zip -o"%TOOLSET%" -y > nul + - cd "%XMR_BLD%" + - cmake -G "%G_ARG%" -T %TOOLSET%,host=x64,cuda=%cuda% -DCUDA_ARCH=%ARCHLIST% -DCUDA_SHOW_REGISTER=ON "%XMR_SRC%" + - cmake --build "%XMR_BLD%" --config %CONFIGURATION% --target install + +- + matrix: + only: + - cuda: 9.1 + environment: + CUDA_PATH: $(CUDA_PATH_V9_1) + PATH: $(CUDA_PATH)\bin;$(CUDA_PATH)\libnvvp;$(PATH) + build_script: + - call "%VS14DIR%\Common7\Tools\VsMSBuildCmd.bat" + - call "%VS14DIR%\VC\vcvarsall.bat" x64 8.1 + - cd "%XMR_DEP%" + # install nvcc + - appveyor DownloadFile https://developer.nvidia.com/compute/cuda/9.1/Prod/local_installers/cuda_9.1.85_win10 -FileName cuda91.exe + - cuda91 -s nvcc_9.1 + - nvcc -V + # install nvcc update from patch2 + - appveyor DownloadFile https://developer.nvidia.com/compute/cuda/9.1/Prod/patches/2/cuda_9.1.85.2_windows -FileName cuda91p2.exe + - cuda91p2 -s nvcc_9.1 + - nvcc -V + # install manually just the integration parts MSBuild needs + # if done normally it drags in profilers and NVTX and the driver etc which fails + - 7z x -y -ocudapkg cuda91.exe CUDAVisualStudioIntegration/extras/visual_studio_integration > nul + - copy cudapkg\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions\* "%V140MSB%\BuildCustomizations" + # xmr-stak-dep for v140 + - appveyor DownloadFile https://github.com/fireice-uk/xmr-stak-dep/releases/download/v1/xmr-stak-dep.zip + - 7z x xmr-stak-dep.zip -o"%TOOLSET%" -y > nul + - cd "%XMR_BLD%" + - cmake -G "%G_ARG%" -T %TOOLSET%,host=x64,cuda=%cuda% -DCUDA_ARCH=%ARCHLIST% -DCUDA_SHOW_REGISTER=ON "%XMR_SRC%" + - cmake --build "%XMR_BLD%" --config %CONFIGURATION% --target install + +- + matrix: + only: + - cuda: 9.2 + environment: + CUDA_PATH: $(CUDA_PATH_V9_2) + PATH: $(CUDA_PATH)\bin;$(CUDA_PATH)\libnvvp;$(PATH) + build_script: + - call "%VS14DIR%\Common7\Tools\VsMSBuildCmd.bat" + - call "%VS14DIR%\VC\vcvarsall.bat" x64 8.1 + - cd "%XMR_DEP%" + # install nvcc + - appveyor DownloadFile https://developer.nvidia.com/compute/cuda/9.2/Prod2/local_installers2/cuda_9.2.148_win10 -FileName cuda92.exe + - cuda92 -s nvcc_9.2 + - nvcc -V + # install manually just the integration parts MSBuild needs + # if done normally it drags in profilers and NVTX and the driver etc which fails + - 7z x -y -ocudapkg cuda92.exe CUDAVisualStudioIntegration/extras/visual_studio_integration > nul + - copy cudapkg\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions\* "%V140MSB%\BuildCustomizations" + # xmr-stak-dep for v140 + - appveyor DownloadFile https://github.com/fireice-uk/xmr-stak-dep/releases/download/v1/xmr-stak-dep.zip + - 7z x xmr-stak-dep.zip -o"%TOOLSET%" -y > nul + - cd "%XMR_BLD%" + - cmake -G "%G_ARG%" -T %TOOLSET%,host=x64,cuda=%cuda% -DCUDA_ARCH=%ARCHLIST% -DCUDA_SHOW_REGISTER=ON "%XMR_SRC%" + - cmake --build "%XMR_BLD%" --config %CONFIGURATION% --target install + +- + matrix: + only: + - cuda: 10.0 + environment: + G_ARG: Visual Studio 15 2017 Win64 + TOOLSET: v141 + VCVARSV: 14.15 + XMR_DEP_VER: $(XMR_DEP)\$(TOOLSET) + CMAKE_PREFIX_PATH: $(XMR_DEP_VER)\hwloc;$(XMR_DEP_VER)\libmicrohttpd;$(XMR_DEP_VER)\openssl + CUDA_PATH: $(CUDA_PATH_V10_0) + PATH: $(CUDA_PATH)\bin;$(CUDA_PATH)\libnvvp;$(PATH) + build_script: + - call "%VS15DIR%\VC\Auxiliary\Build\vcvars64.bat" x64 -vcvars_ver=%VCVARSV% + - cd "%XMR_DEP%" + # install nvcc + - appveyor DownloadFile https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda_10.0.130_411.31_win10 -FileName cuda100.exe + - cuda100 -s nvcc_10.0 + - nvcc -V + # install manually just the integration parts MSBuild needs + # if done normally it drags in profilers and NVTX and the driver etc which fails + - 7z x -y -ocudapkg cuda100.exe CUDAVisualStudioIntegration/extras/visual_studio_integration > nul + - copy cudapkg\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions\* "%V141MSB%\BuildCustomizations" + # xmr-stak-dep for v141 + - appveyor DownloadFile https://github.com/fireice-uk/xmr-stak-dep/releases/download/v2/xmr-stak-dep.zip + - 7z x xmr-stak-dep.zip -y > nul + - move /y xmr-stak-dep %TOOLSET% + - cd "%XMR_BLD%" + - cmake -G "%G_ARG%" -T %TOOLSET%,host=x64,cuda=%cuda% -DCUDA_ARCH=%ARCHLIST% -DCUDA_SHOW_REGISTER=ON "%XMR_SRC%" + - cmake --build "%XMR_BLD%" --config %CONFIGURATION% --target install test_script: - - cd c:\xmr-stak\build\bin\Release - - dir - - copy C:\xmr-stak-dep\openssl\bin\* . - - set XMRSTAK_NOWAIT=1 - - xmr-stak.exe --help --noUAC +- cd "%XMR_BIN%\%CONFIGURATION%" +- copy "%XMR_DEP_VER%\openssl\bin\*.dll" . +- del "*.lib" "*.exp" +- dir +- xmr-stak --noUAC --version-long +- xmr-stak --noUAC --help +# bench CPU v7+v8 / let other backends naturally fail the first time to make sure dll chain works +- xmr-stak --noUAC --httpd 0 --url test:3333 -u test -p x -r test --currency cryptonight_v7 --benchmark 7 --benchwait 4 --benchwork 20 +- xmr-stak --noUAC --noAMD --noNVIDIA --currency cryptonight_v8 --benchmark 8 --benchwait 4 --benchwork 20 +- type "*.txt" diff --git a/CMakeLists.txt b/CMakeLists.txt index b714ee0ce..7030e3fd7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,35 +1,37 @@ +cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR) +message("* COMPILERS: detect and configure...") 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_CXX_STANDARD_REQUIRED TRUE) +set(CMAKE_CXX_EXTENSIONS OFF) +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,189 +40,461 @@ 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 + set(BUILD_SHARED_LIBRARIES OFF) + set(OPENSSL_USE_STATIC_LIBS TRUE) + #set(CMAKE_FIND_LIBRARY_SUFFIXES .a .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) +else() + 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) -if(CUDA_ENABLE) - find_package(CUDA 7.5) +################################################################################ +# Configure Assembler +################################################################################ +message("* COMPILERS(ASM): detect and configure...") +if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + enable_language(ASM_MASM) +else() + enable_language(ASM) +endif() +message("* COMPILERS(ASM): configuration complete!") - 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}") +################################################################################ +# 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) + option(CUDA_LARGEGRID "Support large CUDA block count > 128" ON) + set(CUDA_THREADS_MAX 0 CACHE STRING "Set maximum number of threads (for compile time optimization)") + set(CUDA_ARCH_USER "${CUDA_ARCH}" CACHE STRING "User supplied CUDA_ARCH before filtering") + include(funcCUDA) + + message("* COMPILERS(CUDA): detect and configure...") + file(TO_CMAKE_PATH "$ENV{CUDA_PATH}" CUDA_PATH) + if("" STREQUAL "${CUDA_PATH}") + #try normal system paths + find_program(_nvccbin NAME "nvcc") + else() + #try envvar CUDA_PATH first + set(CUDA_TOOLKIT_ROOT_DIR "${CUDA_PATH}") + find_program(_nvccbin NAME "nvcc" + PATHS "${CUDA_PATH}" "${CMAKE_SYSTEM_PROGRAM_PATH}" + PATH_SUFFIXES "bin" "" + NO_DEFAULT_PATH) + endif() + if(NOT "${_nvccbin}" MATCHES "NOTFOUND") + set(CUDACXX "${_nvccbin}") + set(CMAKE_CUDA_COMPILER "${_nvccbin}") + message(STATUS "Found nvcc: ${_nvccbin}") + endif() + find_package(CUDA REQUIRED QUIET) + enable_language(CUDA) + cuda_arch_probe() + message(STATUS "The CUDA compiler architectures are ${CMAKE_CUDA_ARCHLIST}") + if("" STREQUAL "${CUDA_ARCH}") + message(STATUS "Provided CUDA_ARCH empty, build for ALL (this will be large)") + message(STATUS "You should set CUDA_ARCH to a subset of the above") + set(CUDA_ARCH_OUT "${CMAKE_CUDA_ARCHLIST}") + else() + cuda_arch_filter("${CUDA_ARCH}" "${CMAKE_CUDA_ARCHLIST}" CUDA_ARCH_FILTERED) + if("" STREQUAL "${CUDA_ARCH_FILTERED}") + message(FATAL_ERROR "Provided CUDA_ARCH failed, note the list above") endif() + set(CUDA_ARCH_OUT "${CUDA_ARCH_FILTERED}") + unset(CUDA_ARCH_FILTERED) + endif() + set(CUDA_ARCH "${CUDA_ARCH_OUT}" CACHE STRING + "Set GPU architecture (semicolon separated list, e.g. '-DCUDA_ARCH=${CMAKE_CUDA_ARCHLIST}')" FORCE) + unset(CUDA_ARCH_OUT) + message("* COMPILERS(CUDA): configuration complete!") +endif() +message("* COMPILERS: configuration complete!") - set(DEVICE_COMPILER "nvcc") - set(CUDA_COMPILER "${DEVICE_COMPILER}" CACHE STRING "Select the device compiler") +############################################################################### +# 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}) - if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") - list(APPEND DEVICE_COMPILER "clang") - endif() +############################################################################### +# 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) - set_property(CACHE CUDA_COMPILER PROPERTY STRINGS "${DEVICE_COMPILER}") +############################################################################### +# Define target: xmr-stak-asm; Crypto Library, optional assembler code +############################################################################### +if(CMAKE_C_COMPILER_ID MATCHES "MSVC") + # asm optimized monero v8 code + 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 CPP) + set_source_files_properties("xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.S" PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp") + 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(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") - 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") +############################################################################### +# 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/cpuType.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) + +################################################################################ +# 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 Turing support for CUDA >= 10.0 - if(NOT CUDA_VERSION VERSION_LESS 10.0) - list(APPEND DEFAULT_CUDA_ARCH "75") + 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() + 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() + 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() - 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() - - # 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() +######################### +### LIBRARIES SECTION ### +######################### +message("* LIBS: detect and configure...") +if(CMAKE_LINK_STATIC) + message(STATUS "Library mode: STATIC") +else() + message(STATUS "Library mode: SHARED") +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) + 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() +message("* LIBS configuration complete!") - if(CUDA_KEEP_FILES) - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" --keep --keep-dir "${PROJECT_BINARY_DIR}") - endif(CUDA_KEEP_FILES) +######################### +### BACKENDS SECTION ### +######################### +message("* BACKENDS: detect and configure...") +############################################################################### +# Define backend: cpu +############################################################################### +if(NOT CPU_ENABLE) + target_compile_definitions(xmr-stak-backend PUBLIC CONF_NO_CPU) + message(STATUS "BACKENDS: Disable CPU") +else() + list(APPEND BACKEND_TYPES "cpu") + message(STATUS "BACKENDS: Enable 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 OR - CUDA_VERSION VERSION_EQUAL 10.0) - ) - # 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_SEPARABLE_COMPILATION ON) + set_target_properties(xmrstak_cuda_backend PROPERTIES POSITION_INDEPENDENT_CODE 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 CUDA_THREADS_MAX EQUAL 0) + message(STATUS "xmr-stak-nvidia: set max threads per block to ${CUDA_THREADS_MAX}") + target_compile_definitions(xmrstak_cuda_backend PUBLIC "CUDA_THREADS_MAX=${CUDA_THREADS_MAX}") endif() + + # generate comma separated list with architectures + string(REPLACE ";" "+" STR_CUDA_ARCH "${CUDA_ARCH}") + target_compile_definitions(xmr-stak-backend PUBLIC "XMRSTAK_CUDA_ARCH_LIST=${STR_CUDA_ARCH}") + + target_link_libraries(xmrstak_cuda_backend xmr-stak-backend ${CUDA_LIBRARIES}) + list(APPEND BACKEND_TYPES "nvidia") + message(STATUS "BACKENDS: Enable CUDA" + " v${CUDA_VERSION}" + " @ ${CUDA_TOOLKIT_ROOT_DIR}" + ) 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) + message(STATUS "BACKENDS: Disable 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 @@ -241,7 +515,6 @@ if(OpenCL_ENABLE) find_library(OpenCL_LIBRARY NAMES OpenCL - OpenCL.lib NO_DEFAULT_PATH PATHS ENV "OpenCL_ROOT" @@ -255,172 +528,131 @@ if(OpenCL_ENABLE) lib/x64 OpenCL/common/lib/x64) # find package will use the previews searched path variables - find_package(OpenCL) + find_package(OpenCL QUIET) if(OpenCL_FOUND) - list(APPEND BACKEND_TYPES "amd") + ############################################################################### + # 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(OpenCL_VERSION_MAJOR "1") + set(OpenCL_VERSION_MINOR "2") + endif() + set(CL_TARGET_OPENCL_VERSION "${OpenCL_VERSION_MAJOR}${OpenCL_VERSION_MINOR}0") + #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") + message(STATUS "BACKENDS: Enable OpenCL" + " v${OpenCL_VERSION_MAJOR}.${OpenCL_VERSION_MINOR}" + " @ ${OpenCL_LIBRARY} (${OpenCL_INCLUDE_DIRS})" + ) 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") + target_compile_definitions(xmr-stak-backend PUBLIC CONF_NO_OPENCL) + message(STATUS "BACKENDS: Disable OpenCL") endif() +message("* BACKENDS configuration complete!") -############################################################################### -# 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 +# Versioning ################################################################################ +message(STATUS "Collecting version information...") -if(NOT WIN32) - find_package(Threads REQUIRED) - set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT}) -endif() -################################################################################ -# Find microhttpd -################################################################################ +# 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") -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") +# generate backend string +list(SORT BACKEND_TYPES) +string(REPLACE ";" "-" STR_BACKEND_TYPES "${BACKEND_TYPES}") +target_compile_definitions(xmr-stak-c PUBLIC "BACKEND_TYPE=${STR_BACKEND_TYPES}") + +# Find Git and ask about CMAKE_SOURCE_DIR +find_package(Git QUIET) +if(GIT_FOUND) + # Get the current working branch + 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() -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}) + # 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() -else() - add_definitions("-DCONF_NO_HWLOC") endif() - -################################################################################ -# Windows Sockets -################################################################################ - -if(WIN32) - set(LIBS ${LIBS} wsock32 ws2_32) -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_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;}" ) - -# 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 +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 ) - -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}") +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 + ) +else() + message(FATAL_ERROR "${BLDLOG}") endif() - -# generate backend string -string(REPLACE ";" "-" STR_BACKEND_TYPES "${BACKEND_TYPES}") -add_definitions("-DBACKEND_TYPE=${STR_BACKEND_TYPES}") +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}]") ################################################################################ # Compile & Link ################################################################################ include_directories(BEFORE .) +target_link_libraries(xmr-stak xmr-stak-backend) set (CMAKE_POSITION_INDEPENDENT_CODE TRUE) @@ -458,116 +690,9 @@ if(CMAKE_LINK_STATIC) 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 CPP) - set_source_files_properties("xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.S" PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp") - 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) - -# compile C files -file(GLOB SRCFILES_C "xmrstak/backend/cpu/crypto/*.c") - -add_library(xmr-stak-c - STATIC - ${SRCFILES_C} -) -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} -) -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} - ) - 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}) -endif() - -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) - ################################################################################ # Install ################################################################################ - # do not install the binary if the project and install are equal if( NOT CMAKE_INSTALL_PREFIX STREQUAL PROJECT_BINARY_DIR ) install(TARGETS xmr-stak @@ -594,3 +719,4 @@ else() # this rule is used if the install prefix is the build directory install(CODE "MESSAGE(\"xmr-stak installed to folder 'bin'\")") 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..619c767a8 --- /dev/null +++ b/cmake/CUDA.cmake @@ -0,0 +1,84 @@ +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(CUDA_LARGEGRID) + list(APPEND CUDA_NVCC_FLAGS "-DCUDA_LARGEGRID=${CUDA_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 TRUE) + + foreach(CUDA_ARCH_ELEM ${CUDA_ARCH}) + # set flags to create device code for the given architecture + if(21 EQUAL CUDA_ARCH_ELEM) + list(APPEND CUDA_NVCC_FLAGS + "-gencode=arch=compute_20,code=sm_${CUDA_ARCH_ELEM}") + else() + list(APPEND CUDA_NVCC_FLAGS + "-gencode=arch=compute_${CUDA_ARCH_ELEM},code=sm_${CUDA_ARCH_ELEM}") + list(APPEND CUDA_NVCC_FLAGS + "-gencode=arch=compute_${CUDA_ARCH_ELEM},code=compute_${CUDA_ARCH_ELEM}") + endif() + 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_GREATER_EQUAL 9.0) + # 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() + string(REPLACE ";" " " STR_NVCC_FLAGS "${CUDA_NVCC_FLAGS}") + string(APPEND CMAKE_CUDA_FLAGS " ${STR_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..3d00fc801 --- /dev/null +++ b/cmake/CUDAold.cmake @@ -0,0 +1,194 @@ +################################################################################ +# 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(CUDA_LARGEGRID "Support large CUDA block count > 128" ON) + set(CUDA_THREADS_MAX 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() + # add Turing support for CUDA >= 10.0 + if(NOT CUDA_VERSION VERSION_LESS 10.0) + list(APPEND DEFAULT_CUDA_ARCH "75") + 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(CUDA_LARGEGRID) + list(APPEND CUDA_NVCC_FLAGS "-DCUDA_LARGEGRID=${CUDA_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_GREATER_EQUAL 9.0) + # 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 CUDA_THREADS_MAX EQUAL 0) + message(STATUS "xmr-stak-nvidia: set max threads per block to ${CUDA_THREADS_MAX}") + target_compile_definitions(xmrstak_cuda_backend PUBLIC "CUDA_THREADS_MAX=${CUDA_THREADS_MAX}") + 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..a5758ef74 --- /dev/null +++ b/cmake/funcCUDA.cmake @@ -0,0 +1,73 @@ +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 "...CUDA architecture '${_arch}' removed, is not two digits") + elseif(${_arch} LESS 20) + message(STATUS "...CUDA architecture '${_arch}' removed, does not support required functions (arch 20 or newer!)") + elseif(-1 EQUAL ${_arch_good}) + message(STATUS "...CUDA architecture '${_arch}' removed, 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/doc/compile.md b/doc/compile.md index 4987260bc..5bd238e75 100644 --- a/doc/compile.md +++ b/doc/compile.md @@ -78,10 +78,10 @@ After the configuration you need to compile the miner, follow the guide for your export CXX=/usr/bin/clang++ cmake .. -DCUDA_COMPILER=clang ``` -- `XMR-STAK_LARGEGRID` use `32` or `64` bit integer for on device indices +- `CUDA_LARGEGRID` use `32` or `64` bit integer for on device indices - default is enabled - - on old GPUs it can increase the hash rate if disabled: `cmake .. -DXMR-STAK_LARGEGRID=OFF` + - on old GPUs it can increase the hash rate if disabled: `cmake .. -DCUDA_LARGEGRID=OFF` - if disabled it is not allowed to use more than `1000` threads on the device -- `XMR-STAK_THREADS` give the compiler information which value for `threads` is used at runtime +- `CUDA_THREADS_MAX` give the compiler information which value for `threads` is used at runtime - default is `0` (compile time optimization) - - if the miner is compiled and used at runtime with the some value it can increase the hash rate: `cmake .. -DXMR-STAK_THREADS=32` + - if the miner is compiled and used at runtime with the some value it can increase the hash rate: `cmake .. -DCUDA_THREADS_MAX=32` 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/backend/nvidia/nvcc_code/cuda_core.cu b/xmrstak/backend/nvidia/nvcc_code/cuda_core.cu index 7742e740e..61cdd5810 100644 --- a/xmrstak/backend/nvidia/nvcc_code/cuda_core.cu +++ b/xmrstak/backend/nvidia/nvcc_code/cuda_core.cu @@ -64,7 +64,7 @@ extern "C" void compat_usleep(uint64_t waitTime) /* sm_2X is limited to 2GB due to the small TLB * therefore we never use 64bit indices */ -#if defined(XMR_STAK_LARGEGRID) && (__CUDA_ARCH__ >= 300) +#if defined(CUDA_LARGEGRID) && (__CUDA_ARCH__ >= 300) typedef uint64_t IndexType; #else typedef int IndexType; @@ -261,8 +261,8 @@ struct u64 : public uint2 * else if `1` 256bit operations will be used */ template -#ifdef XMR_STAK_THREADS -__launch_bounds__( XMR_STAK_THREADS * 2 ) +#ifdef CUDA_THREADS_MAX +__launch_bounds__( CUDA_THREADS_MAX * 2 ) #endif __global__ void cryptonight_core_gpu_phase2_double( int threads, int bfactor, int partidx, uint32_t * d_long_state, uint32_t * d_ctx_a, uint32_t * d_ctx_b, uint32_t * d_ctx_state, uint32_t startNonce, uint32_t * __restrict__ d_input ) @@ -476,8 +476,8 @@ __global__ void cryptonight_core_gpu_phase2_double( int threads, int bfactor, in } template -#ifdef XMR_STAK_THREADS -__launch_bounds__( XMR_STAK_THREADS * 4 ) +#ifdef CUDA_THREADS_MAX +__launch_bounds__( CUDA_THREADS_MAX * 4 ) #endif __global__ void cryptonight_core_gpu_phase2_quad( int threads, int bfactor, int partidx, uint32_t * d_long_state, uint32_t * d_ctx_a, uint32_t * d_ctx_b, uint32_t * d_ctx_state, uint32_t startNonce, uint32_t * __restrict__ d_input ) diff --git a/xmrstak/cli/cli-miner.cpp b/xmrstak/cli/cli-miner.cpp index 40fb9d948..4467d606b 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 @@ -437,13 +436,13 @@ int main(int argc, char *argv[]) if(opName.compare("-v") == 0 || opName.compare("--version") == 0) { std::cout<< "Version: " << get_version_str_short() << std::endl; - win_exit(); + win_exit(0); return 0; } else if(opName.compare("-V") == 0 || opName.compare("--version-long") == 0) { std::cout<< "Version: " << get_version_str() << std::endl; - win_exit(); + win_exit(0); return 0; } else if(opName.compare("--noCPU") == 0) @@ -806,7 +805,8 @@ int main(int argc, char *argv[]) if(params::inst().benchmark_block_version >= 0) { printer::inst()->print_str("!!!! Doing only a benchmark and exiting. To mine, remove the '--benchmark' option. !!!!\n"); - return do_benchmark(params::inst().benchmark_block_version, params::inst().benchmark_wait_sec, params::inst().benchmark_work_sec); + win_exit(do_benchmark(params::inst().benchmark_block_version, params::inst().benchmark_wait_sec, params::inst().benchmark_work_sec)); + return 1; } executor::inst()->ex_start(jconf::inst()->DaemonMode()); @@ -862,6 +862,12 @@ int do_benchmark(int block_version, int wait_sec, int work_sec) printer::inst()->print_msg(L0, "Wait %d sec until all backends are initialized",wait_sec); std::this_thread::sleep_for(std::chrono::seconds(wait_sec)); + if(pvThreads->size()==0) + { + printer::inst()->print_msg(L1, "ERROR: No miner backend enabled."); + return 1; + } + /* AMD and NVIDIA is currently only supporting work sizes up to 84byte * \todo fix this issue */ diff --git a/xmrstak/misc/executor.cpp b/xmrstak/misc/executor.cpp index 4fcce1f97..8f8624498 100644 --- a/xmrstak/misc/executor.cpp +++ b/xmrstak/misc/executor.cpp @@ -518,7 +518,7 @@ void executor::ex_main() #ifdef CONF_NO_TLS if(cfg.tls) { - printer::inst()->print_msg(L1, "ERROR: No miner was compiled without TLS support."); + printer::inst()->print_msg(L1, "ERROR: Miner was compiled without TLS support, can't use SSL pools."); win_exit(); } #endif diff --git a/xmrstak/net/socks.hpp b/xmrstak/net/socks.hpp index 86749e527..cf3764862 100644 --- a/xmrstak/net/socks.hpp +++ b/xmrstak/net/socks.hpp @@ -2,7 +2,7 @@ #ifdef _WIN32 #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0601 /* Windows 7 */ +#define _WIN32_WINNT _WIN32_WINNT_WIN7 #endif #include #include