diff --git a/xmrstak/backend/amd/OclCryptonightR_gen.cpp b/xmrstak/backend/amd/OclCryptonightR_gen.cpp index 13785d64b..7358e9857 100644 --- a/xmrstak/backend/amd/OclCryptonightR_gen.cpp +++ b/xmrstak/backend/amd/OclCryptonightR_gen.cpp @@ -134,6 +134,7 @@ static cl_program CryptonightR_build_program( const GpuContext* ctx, xmrstak_algo algo, uint64_t height, + uint32_t precompile_count, cl_kernel old_kernel, std::string source_code, std::string options) @@ -151,7 +152,7 @@ static cl_program CryptonightR_build_program( for(size_t i = 0; i < CryptonightR_cache.size();) { const CacheEntry& entry = CryptonightR_cache[i]; - if ((entry.algo == algo) && (entry.height + 2 < height)) + if ((entry.algo == algo) && (entry.height + 2 + precompile_count < height)) { printer::inst()->print_msg(LDEBUG, "CryptonightR: program for height %llu released (old program)", entry.height); old_programs.push_back(entry.program); @@ -252,10 +253,12 @@ static cl_program CryptonightR_build_program( return program; } -cl_program CryptonightR_get_program(GpuContext* ctx, xmrstak_algo algo, uint64_t height, 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, cl_kernel old_kernel) { + printer::inst()->print_msg(LDEBUG, "CryptonightR: start %llu released",height); + if (background) { - background_exec([=](){ CryptonightR_get_program(ctx, algo, height, false, old_kernel); }); + background_exec([=](){ CryptonightR_get_program(ctx, algo, height, precompile_count, false, old_kernel); }); return nullptr; } @@ -347,7 +350,7 @@ cl_program CryptonightR_get_program(GpuContext* ctx, xmrstak_algo algo, uint64_t } - return CryptonightR_build_program(ctx, algo, height, old_kernel, source, options); + return CryptonightR_build_program(ctx, algo, height, precompile_count, old_kernel, source, options); } } // namespace amd diff --git a/xmrstak/backend/amd/OclCryptonightR_gen.hpp b/xmrstak/backend/amd/OclCryptonightR_gen.hpp index a69df9074..5f97d1e51 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, bool background = false, cl_kernel old_kernel = nullptr); + uint64_t height, uint32_t precompile_count, bool background = false, cl_kernel old_kernel = nullptr); } // namespace amd } // namespace xmrstak diff --git a/xmrstak/backend/amd/amd_gpu/gpu.cpp b/xmrstak/backend/amd/amd_gpu/gpu.cpp index ace1c34bb..ca790c91d 100644 --- a/xmrstak/backend/amd/amd_gpu/gpu.cpp +++ b/xmrstak/backend/amd/amd_gpu/gpu.cpp @@ -952,8 +952,10 @@ size_t XMRSetJob(GpuContext* ctx, uint8_t* input, size_t input_len, uint64_t tar if ((miner_algo == cryptonight_r) || (miner_algo == cryptonight_r_wow)) { + uint32_t PRECOMPILATION_DEPTH = 4; + // Get new kernel - cl_program program = xmrstak::amd::CryptonightR_get_program(ctx, miner_algo, height); + cl_program program = xmrstak::amd::CryptonightR_get_program(ctx, miner_algo, height, PRECOMPILATION_DEPTH); if (program != ctx->ProgramCryptonightR) { cl_int ret; @@ -969,12 +971,10 @@ size_t XMRSetJob(GpuContext* ctx, uint8_t* input, size_t input_len, uint64_t tar } ctx->ProgramCryptonightR = program; - uint32_t PRECOMPILATION_DEPTH = 4; - // Precompile next program in background - xmrstak::amd::CryptonightR_get_program(ctx, miner_algo, height + 1, true, old_kernel); + 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, true, nullptr); + xmrstak::amd::CryptonightR_get_program(ctx, miner_algo, height + i, PRECOMPILATION_DEPTH, true, nullptr); printer::inst()->print_msg(LDEBUG, "Thread #%zu updated CryptonightR", ctx->deviceIdx); } diff --git a/xmrstak/backend/nvidia/CudaCryptonightR_gen.cpp b/xmrstak/backend/nvidia/CudaCryptonightR_gen.cpp index 87eb05540..f1bf75819 100644 --- a/xmrstak/backend/nvidia/CudaCryptonightR_gen.cpp +++ b/xmrstak/backend/nvidia/CudaCryptonightR_gen.cpp @@ -153,6 +153,7 @@ static void CryptonightR_build_program( std::string& lowered_name, const xmrstak_algo& algo, uint64_t height, + uint32_t precompile_count, int arch_major, int arch_minor, std::string source) @@ -164,7 +165,7 @@ static void CryptonightR_build_program( for (size_t i = 0; i < CryptonightR_cache.size();) { const CacheEntry& entry = CryptonightR_cache[i]; - if ((entry.algo == algo) && (entry.height + 2 < height)) + if ((entry.algo == algo) && (entry.height + 2 + precompile_count < height)) { printer::inst()->print_msg(LDEBUG, "CryptonightR: program for height %llu released (old program)", entry.height); CryptonightR_cache[i] = std::move(CryptonightR_cache.back()); @@ -273,10 +274,10 @@ static void CryptonightR_build_program( CryptonightR_cache_mutex.UnLock(); } -void CryptonightR_get_program(std::vector& ptx, std::string& lowered_name, const xmrstak_algo algo, uint64_t height, int arch_major, int arch_minor, bool background) +void CryptonightR_get_program(std::vector& ptx, std::string& lowered_name, const xmrstak_algo algo, uint64_t height, uint32_t precompile_count, int arch_major, int arch_minor, bool background) { if (background) { - background_exec([=]() { std::vector tmp; std::string s; CryptonightR_get_program(tmp, s, algo, height, arch_major, arch_minor, false); }); + background_exec([=]() { std::vector tmp; std::string s; CryptonightR_get_program(tmp, s, algo, height, precompile_count, arch_major, arch_minor, false); }); return; } @@ -329,7 +330,7 @@ void CryptonightR_get_program(std::vector& ptx, std::string& lowered_name, CryptonightR_cache_mutex.UnLock(); } - CryptonightR_build_program(ptx, lowered_name, algo, height, arch_major, arch_minor, source_code); + CryptonightR_build_program(ptx, lowered_name, algo, height, precompile_count, arch_major, arch_minor, source_code); } } // namespace xmrstak diff --git a/xmrstak/backend/nvidia/CudaCryptonightR_gen.hpp b/xmrstak/backend/nvidia/CudaCryptonightR_gen.hpp index e214647b9..c3d8827b0 100644 --- a/xmrstak/backend/nvidia/CudaCryptonightR_gen.hpp +++ b/xmrstak/backend/nvidia/CudaCryptonightR_gen.hpp @@ -29,7 +29,7 @@ namespace nvidia { void CryptonightR_get_program(std::vector& ptx, std::string& lowered_name, - const xmrstak_algo algo, uint64_t height, int arch_major, int arch_minor, bool background = false); + const xmrstak_algo algo, uint64_t height, uint32_t precompile_count, int arch_major, int arch_minor, bool background = false); } // namespace xmrstak diff --git a/xmrstak/backend/nvidia/nvcc_code/cuda_core.cu b/xmrstak/backend/nvidia/nvcc_code/cuda_core.cu index 3c62bd090..718cff0c7 100644 --- a/xmrstak/backend/nvidia/nvcc_code/cuda_core.cu +++ b/xmrstak/backend/nvidia/nvcc_code/cuda_core.cu @@ -1033,9 +1033,11 @@ void cryptonight_core_cpu_hash(nvid_ctx* ctx, const xmrstak_algo& miner_algo, ui if(ctx->module) cuModuleUnload(ctx->module); + uint32_t PRECOMPILATION_DEPTH = 4; + std::vector ptx; std::string lowered_name; - xmrstak::nvidia::CryptonightR_get_program(ptx, lowered_name, miner_algo, chain_height, ctx->device_arch[0], ctx->device_arch[1]); + xmrstak::nvidia::CryptonightR_get_program(ptx, lowered_name, miner_algo, chain_height, PRECOMPILATION_DEPTH, ctx->device_arch[0], ctx->device_arch[1]); CU_CHECK(ctx->device_id, cuModuleLoadDataEx(&ctx->module, ptx.data(), 0, 0, 0)); CU_CHECK(ctx->device_id, cuModuleGetFunction(&ctx->kernel, ctx->module, lowered_name.c_str())); @@ -1043,7 +1045,9 @@ void cryptonight_core_cpu_hash(nvid_ctx* ctx, const xmrstak_algo& miner_algo, ui ctx->kernel_height = chain_height; ctx->cached_algo = miner_algo; - xmrstak::nvidia::CryptonightR_get_program(ptx, lowered_name, miner_algo, chain_height + 1, ctx->device_arch[0], ctx->device_arch[1], true); + for (int i = 1; i <= PRECOMPILATION_DEPTH; ++i) + xmrstak::nvidia::CryptonightR_get_program(ptx, lowered_name, miner_algo, + chain_height + i, PRECOMPILATION_DEPTH, ctx->device_arch[0], ctx->device_arch[1], true); } }