diff --git a/CMakeLists.txt b/CMakeLists.txt index 004b5555c94d80fd9ec089b6d3201ea20bb389b7..41e993eee79beb6fccf0cea03a299c1f5545ceb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,10 +84,11 @@ if(CUDA_ENABLE) /usr /usr/local/cuda PATH_SUFFIXES - lib64 + lib64 lib/x64 lib/Win32 - lib64/stubs) + lib64/stubs + lib) #nvrtc find_library(CUDA_NVRTC_LIB @@ -104,7 +105,8 @@ if(CUDA_ENABLE) PATH_SUFFIXES lib64 lib/x64 - lib/Win32) + lib/Win32 + lib) list(APPEND BACKEND_TYPES "nvidia") option(XMR-STAK_LARGEGRID "Support large CUDA block count > 128" ON) @@ -322,7 +324,7 @@ endif() ################################################################################ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - set_source_files_properties(xmrstak/backend/cpu/crypto/cn_gpu_avx.cpp PROPERTIES COMPILE_FLAGS "-mavx2") + set_source_files_properties(xmrstak/backend/cpu/crypto/cn_gpu_avx.cpp PROPERTIES COMPILE_FLAGS "-mavx2") endif() ################################################################################ diff --git a/xmrstak/backend/amd/OclCryptonightR_gen.cpp b/xmrstak/backend/amd/OclCryptonightR_gen.cpp index 7358e98570386de0353815df3eb19eab717455f8..ccb836e41b13a36e4a9b8708c8aafddda991326d 100644 --- a/xmrstak/backend/amd/OclCryptonightR_gen.cpp +++ b/xmrstak/backend/amd/OclCryptonightR_gen.cpp @@ -135,14 +135,9 @@ static cl_program CryptonightR_build_program( xmrstak_algo algo, uint64_t height, uint32_t precompile_count, - cl_kernel old_kernel, std::string source_code, std::string options) { - if(old_kernel) - clReleaseKernel(old_kernel); - - std::vector<cl_program> old_programs; old_programs.reserve(32); { @@ -253,12 +248,12 @@ static cl_program CryptonightR_build_program( return program; } -cl_program CryptonightR_get_program(GpuContext* ctx, xmrstak_algo algo, uint64_t height, uint32_t precompile_count, bool background, cl_kernel old_kernel) +cl_program CryptonightR_get_program(GpuContext* ctx, xmrstak_algo algo, uint64_t height, uint32_t precompile_count, bool background) { printer::inst()->print_msg(LDEBUG, "CryptonightR: start %llu released",height); if (background) { - background_exec([=](){ CryptonightR_get_program(ctx, algo, height, precompile_count, false, old_kernel); }); + background_exec([=](){ CryptonightR_get_program(ctx, algo, height, precompile_count, false); }); return nullptr; } @@ -350,7 +345,7 @@ cl_program CryptonightR_get_program(GpuContext* ctx, xmrstak_algo algo, uint64_t } - return CryptonightR_build_program(ctx, algo, height, precompile_count, old_kernel, source, options); + return CryptonightR_build_program(ctx, algo, height, precompile_count, source, options); } } // namespace amd diff --git a/xmrstak/backend/amd/OclCryptonightR_gen.hpp b/xmrstak/backend/amd/OclCryptonightR_gen.hpp index 5f97d1e5142fa2552146c22af257ffbe02f39ae8..7dce77b850568eb6fe777c6ef400ece97200544e 100644 --- a/xmrstak/backend/amd/OclCryptonightR_gen.hpp +++ b/xmrstak/backend/amd/OclCryptonightR_gen.hpp @@ -20,7 +20,7 @@ namespace amd { cl_program CryptonightR_get_program(GpuContext* ctx, const xmrstak_algo algo, - uint64_t height, uint32_t precompile_count, bool background = false, cl_kernel old_kernel = nullptr); + uint64_t height, uint32_t precompile_count, bool background = false); } // namespace amd } // namespace xmrstak diff --git a/xmrstak/backend/amd/amd_gpu/gpu.cpp b/xmrstak/backend/amd/amd_gpu/gpu.cpp index 9c9db2ee3d274fa1d170b043548e4f1b116b72de..9f3f75469fae7666bd854fca82ea96ffa47aa9c3 100644 --- a/xmrstak/backend/amd/amd_gpu/gpu.cpp +++ b/xmrstak/backend/amd/amd_gpu/gpu.cpp @@ -48,25 +48,12 @@ #ifdef _WIN32 #include <windows.h> -#include <Shlobj.h> static inline void create_directory(std::string dirname) { _mkdir(dirname.data()); } -static inline std::string get_home() -{ - char path[MAX_PATH + 1]; - // get folder "appdata\local" - if (SHGetSpecialFolderPathA(HWND_DESKTOP, path, CSIDL_LOCAL_APPDATA, FALSE)) - { - return path; - } - else - return "."; -} - static inline void port_sleep(size_t sec) { Sleep(sec * 1000); @@ -80,16 +67,6 @@ static inline void create_directory(std::string dirname) mkdir(dirname.data(), 0744); } -static inline std::string get_home() -{ - const char *home = "."; - - if ((home = getenv("HOME")) == nullptr) - home = getpwuid(getuid())->pw_dir; - - return home; -} - static inline void port_sleep(size_t sec) { sleep(sec); @@ -339,7 +316,7 @@ size_t InitOpenCLGpu(cl_context opencl_ctx, GpuContext* ctx, const char* source_ isWindowsOs = 1; #endif options += " -DIS_WINDOWS_OS=" + std::to_string(isWindowsOs); - + if(miner_algo == cryptonight_gpu) options += " -cl-fp32-correctly-rounded-divide-sqrt"; @@ -358,7 +335,9 @@ size_t InitOpenCLGpu(cl_context opencl_ctx, GpuContext* ctx, const char* source_ std::string hash_hex_str; picosha2::hash256_hex_string(src_str, hash_hex_str); - std::string cache_file = get_home() + "/.openclcache/" + hash_hex_str + ".openclbin"; + const std::string cache_dir = xmrstak::params::inst().rootAMDCacheDir; + + std::string cache_file = cache_dir + hash_hex_str + ".openclbin"; std::ifstream clBinFile(cache_file, std::ofstream::in | std::ofstream::binary); if(xmrstak::params::inst().AMDCache == false || !clBinFile.good()) { @@ -854,7 +833,8 @@ size_t InitOpenCL(GpuContext* ctx, size_t num_gpus, size_t platform_idx) source_code = std::regex_replace(source_code, std::regex("XMRSTAK_INCLUDE_CN_GPU"), cryptonight_gpu); // create a directory for the OpenCL compile cache - create_directory(get_home() + "/.openclcache"); + const std::string cache_dir = xmrstak::params::inst().rootAMDCacheDir; + create_directory(cache_dir); std::vector<std::shared_ptr<InterleaveData>> interleaveData(num_gpus, nullptr); @@ -967,20 +947,21 @@ size_t XMRSetJob(GpuContext* ctx, uint8_t* input, size_t input_len, uint64_t tar cl_int ret; cl_kernel kernel = clCreateKernel(program, "cn1_cryptonight_r", &ret); - cl_kernel old_kernel = nullptr; if (ret != CL_SUCCESS) { printer::inst()->print_msg(LDEBUG, "CryptonightR: clCreateKernel returned error %s", err_to_str(ret)); } - else { - old_kernel = Kernels[1]; + else + { + cl_kernel old_kernel = Kernels[1]; + if(old_kernel) + clReleaseKernel(old_kernel); Kernels[1] = kernel; } ctx->ProgramCryptonightR = program; // Precompile next program in background - xmrstak::amd::CryptonightR_get_program(ctx, miner_algo, height + 1, PRECOMPILATION_DEPTH, true, old_kernel); - for (int i = 2; i <= PRECOMPILATION_DEPTH; ++i) - xmrstak::amd::CryptonightR_get_program(ctx, miner_algo, height + i, PRECOMPILATION_DEPTH, true, nullptr); + for (int i = 1; i <= PRECOMPILATION_DEPTH; ++i) + xmrstak::amd::CryptonightR_get_program(ctx, miner_algo, height + i, PRECOMPILATION_DEPTH, true); printer::inst()->print_msg(LDEBUG, "Thread #%zu updated CryptonightR", ctx->deviceIdx); } diff --git a/xmrstak/cli/cli-miner.cpp b/xmrstak/cli/cli-miner.cpp index d6822cd63c544e07975d22ecd28474a6e2be904b..7b974f66946a6f4eb61c5eef0a077f15c1f5f964 100644 --- a/xmrstak/cli/cli-miner.cpp +++ b/xmrstak/cli/cli-miner.cpp @@ -84,6 +84,7 @@ void help() cout<<" --noAMDCache disable the AMD(OpenCL) cache for precompiled binaries"<<endl; cout<<" --openCLVendor VENDOR use OpenCL driver of VENDOR and devices [AMD,NVIDIA]"<<endl; cout<<" default: AMD"<<endl; + cout<<" --amdCacheDir DIRECTORY directory to store AMD binary files"<<endl; cout<<" --amd FILE AMD backend miner config file"<<endl; #endif #ifndef CONF_NO_CUDA @@ -502,6 +503,17 @@ int main(int argc, char *argv[]) } params::inst().configFileAMD = argv[i]; } + else if(opName.compare("--amdCacheDir") == 0) + { + ++i; + if( i >=argc ) + { + printer::inst()->print_msg(L0, "No argument for parameter '--amdCacheDir' given"); + win_exit(); + return 1; + } + params::inst().rootAMDCacheDir = std::string(argv[i]) + "/"; + } else if(opName.compare("--nvidia") == 0) { ++i; diff --git a/xmrstak/misc/home_dir.hpp b/xmrstak/misc/home_dir.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8eb0fa4ea2a5256495bc4975f5ba1aebec93ba72 --- /dev/null +++ b/xmrstak/misc/home_dir.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include <string> + +#ifdef _WIN32 +#include <WinSock2.h> +#include <Shlobj.h> + +namespace +{ + inline std::string get_home() + { + char path[MAX_PATH + 1]; + // get folder "appdata\local" + if (SHGetSpecialFolderPathA(HWND_DESKTOP, path, CSIDL_LOCAL_APPDATA, FALSE)) + { + return path; + } + else + return "."; + } +} // namespace anonymous + +#else +#include <unistd.h> +#include <pwd.h> +#include <cstdlib> + +namespace +{ + inline std::string get_home() + { + const char *home = "."; + + if ((home = getenv("HOME")) == nullptr) + home = getpwuid(getuid())->pw_dir; + + return home; + } +} // namespace anonymous + +#endif // _WIN32 diff --git a/xmrstak/params.hpp b/xmrstak/params.hpp index 16089aed7e524979e03ac031e272bb1a19f279c1..146aaa42fd387a826bbf2a8a1c17c0f31ebc5479 100644 --- a/xmrstak/params.hpp +++ b/xmrstak/params.hpp @@ -1,6 +1,7 @@ #pragma once #include "xmrstak/misc/environment.hpp" +#include "xmrstak/misc/home_dir.hpp" #include <string> @@ -45,6 +46,7 @@ struct params std::string configFile; std::string configFilePools; std::string configFileAMD; + std::string rootAMDCacheDir; std::string configFileNVIDIA; std::string configFileCPU; @@ -68,6 +70,7 @@ struct params configFile("config.txt"), configFilePools("pools.txt"), configFileAMD("amd.txt"), + rootAMDCacheDir(get_home() + "/.openclcache/"), configFileCPU("cpu.txt"), configFileNVIDIA("nvidia.txt") {} diff --git a/xmrstak/version.cpp b/xmrstak/version.cpp index 412fc221335944e0a11c2c1414ca0b6642d7eae4..c9fa175acd748e6e325a8b96bc28f866d84316d8 100644 --- a/xmrstak/version.cpp +++ b/xmrstak/version.cpp @@ -18,7 +18,7 @@ #endif #define XMR_STAK_NAME "xmr-stak" -#define XMR_STAK_VERSION "2.10.1" +#define XMR_STAK_VERSION "2.10.2" #if defined(_WIN32) #define OS_TYPE "win"