From f33d2e560f0945e2142dbbe4081f092253a23358 Mon Sep 17 00:00:00 2001 From: psychocrypt <psychocryptHPC@gmail.com> Date: Tue, 12 Mar 2019 21:07:51 +0100 Subject: [PATCH] add cli option `amdCacheDir` add option to control where the amd cache data should be stored --- xmrstak/backend/amd/amd_gpu/gpu.cpp | 32 +++++----------------- xmrstak/cli/cli-miner.cpp | 12 +++++++++ xmrstak/misc/home_dir.hpp | 42 +++++++++++++++++++++++++++++ xmrstak/params.hpp | 3 +++ 4 files changed, 63 insertions(+), 26 deletions(-) create mode 100644 xmrstak/misc/home_dir.hpp diff --git a/xmrstak/backend/amd/amd_gpu/gpu.cpp b/xmrstak/backend/amd/amd_gpu/gpu.cpp index 9c9db2e..62e7323 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); diff --git a/xmrstak/cli/cli-miner.cpp b/xmrstak/cli/cli-miner.cpp index d6822cd..7b974f6 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 0000000..8eb0fa4 --- /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 16089ae..146aaa4 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") {} -- GitLab