From 046eb4d9fd32665b79c9b1875443377c4c093517 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 12 Sep 2019 15:21:14 +0700 Subject: [PATCH] Added autoconfig stub for RandomX. --- src/backend/opencl/OclConfig.cpp | 57 ++++++++++++------- src/backend/opencl/OclThread.cpp | 41 +++++++------ src/backend/opencl/OclThread.h | 16 ++++++ .../generators/ocl_generic_rx_generator.cpp | 51 +++++++++++++++++ src/backend/opencl/opencl.cmake | 1 + src/backend/opencl/wrappers/OclDevice.cpp | 7 +++ 6 files changed, 137 insertions(+), 36 deletions(-) create mode 100644 src/backend/opencl/generators/ocl_generic_rx_generator.cpp diff --git a/src/backend/opencl/OclConfig.cpp b/src/backend/opencl/OclConfig.cpp index 2e27dcd62..cdb38ccb8 100644 --- a/src/backend/opencl/OclConfig.cpp +++ b/src/backend/opencl/OclConfig.cpp @@ -60,8 +60,8 @@ static const char *kCnPico = "cn-pico"; #endif #ifdef XMRIG_ALGO_RANDOMX -//static const char *kRx = "rx"; -//static const char *kRxWOW = "rx/wow"; +static const char *kRx = "rx"; +static const char *kRxWOW = "rx/wow"; #endif #ifdef XMRIG_ALGO_ARGON2 @@ -72,14 +72,21 @@ static const char *kCnPico = "cn-pico"; extern template class Threads; -static OclThreads generate(const Algorithm &algorithm, const std::vector &devices) +static size_t generate(const char *key, Threads &threads, const Algorithm &algorithm, const std::vector &devices) { - OclThreads threads; - for (const OclDevice &device : devices) { - device.generate(algorithm, threads); + if (threads.has(key) || threads.isExist(algorithm)) { + return 0; } - return threads; + OclThreads profile; + for (const OclDevice &device : devices) { + device.generate(algorithm, profile); + } + + const size_t count = profile.count(); + threads.move(key, std::move(profile)); + + return count; } @@ -208,7 +215,9 @@ void xmrig::OclConfig::read(const rapidjson::Value &value) setPlatform(Json::getValue(value, kPlatform)); - if (isEnabled() && !m_threads.read(value)) { + if (isEnabled()) { + m_threads.read(value); + generate(); } } @@ -232,33 +241,43 @@ void xmrig::OclConfig::generate() return; } - m_shouldSave = true; + size_t count = 0; - m_threads.disable(Algorithm::CN_0); - m_threads.move(kCn, xmrig::generate(Algorithm::CN_0, devices)); - m_threads.move(kCn2, xmrig::generate(Algorithm::CN_2, devices)); + count += xmrig::generate(kCn, m_threads, Algorithm::CN_0, devices); + count += xmrig::generate(kCn2, m_threads, Algorithm::CN_2, devices); + + if (!m_threads.isExist(Algorithm::CN_0)) { + m_threads.disable(Algorithm::CN_0); + count++; + } # ifdef XMRIG_ALGO_CN_GPU - m_threads.move(kCnGPU, xmrig::generate(Algorithm::CN_GPU, devices)); + count += xmrig::generate(kCnGPU, m_threads, Algorithm::CN_GPU, devices); # endif # ifdef XMRIG_ALGO_CN_LITE - m_threads.disable(Algorithm::CN_LITE_0); - m_threads.move(kCnLite, xmrig::generate(Algorithm::CN_LITE_1, devices)); + count += xmrig::generate(kCnLite, m_threads, Algorithm::CN_LITE_1, devices); + + if (!m_threads.isExist(Algorithm::CN_LITE_0)) { + m_threads.disable(Algorithm::CN_LITE_0); + count++; + } # endif # ifdef XMRIG_ALGO_CN_HEAVY - m_threads.move(kCnHeavy, xmrig::generate(Algorithm::CN_HEAVY_0, devices)); + count += xmrig::generate(kCnHeavy, m_threads, Algorithm::CN_HEAVY_0, devices); # endif # ifdef XMRIG_ALGO_CN_PICO - m_threads.move(kCnPico, xmrig::generate(Algorithm::CN_PICO_0, devices)); + count += xmrig::generate(kCnPico, m_threads, Algorithm::CN_PICO_0, devices); # endif # ifdef XMRIG_ALGO_RANDOMX -// m_threads.move(kRx, xmrig::generate(Algorithm::RX_0, devices)); -// m_threads.move(kRxWOW, xmrig::generate(Algorithm::RX_WOW, devices)); + count += xmrig::generate(kRx, m_threads, Algorithm::RX_0, devices); + count += xmrig::generate(kRxWOW, m_threads, Algorithm::RX_WOW, devices); # endif + + m_shouldSave = count > 0; } diff --git a/src/backend/opencl/OclThread.cpp b/src/backend/opencl/OclThread.cpp index d5fb36ea2..02ef5f3b2 100644 --- a/src/backend/opencl/OclThread.cpp +++ b/src/backend/opencl/OclThread.cpp @@ -58,13 +58,7 @@ xmrig::OclThread::OclThread(const rapidjson::Value &value) setIntensity(Json::getUint(value, kIntensity)); -# ifdef XMRIG_ALGO_RANDOMX - m_bfactor = Json::getUint(value, kBFactor, 6); - m_gcnAsm = Json::getBool(value, kGCNAsm, m_gcnAsm); - m_datasetHost = Json::getBool(value, kDatasetHost, m_datasetHost); -# endif - - const rapidjson::Value &si = Json::getArray(value, kStridedIndex); + const auto &si = Json::getArray(value, kStridedIndex); if (si.IsArray() && si.Size() >= 2) { m_stridedIndex = std::min(si[0].GetUint(), 2u); m_memChunk = std::min(si[1].GetUint(), 18u); @@ -75,7 +69,7 @@ xmrig::OclThread::OclThread(const rapidjson::Value &value) m_fields.set(STRIDED_INDEX_FIELD, false); } - const rapidjson::Value &threads = Json::getArray(value, kThreads); + const auto &threads = Json::getArray(value, kThreads); if (threads.IsArray()) { m_threads.reserve(threads.Size()); @@ -87,6 +81,17 @@ xmrig::OclThread::OclThread(const rapidjson::Value &value) if (m_threads.empty()) { m_threads.emplace_back(-1); } + +# ifdef XMRIG_ALGO_RANDOMX + const auto &gcnAsm = Json::getValue(value, kGCNAsm); + if (gcnAsm.IsBool()) { + m_fields.set(RANDOMX_FIELDS, true); + + m_gcnAsm = gcnAsm.GetBool(); + m_bfactor = Json::getUint(value, kBFactor, m_bfactor); + m_datasetHost = Json::getBool(value, kDatasetHost, m_datasetHost); + } +# endif } @@ -132,16 +137,18 @@ rapidjson::Value xmrig::OclThread::toJSON(rapidjson::Document &doc) const threads.PushBack(thread, allocator); } - out.AddMember(StringRef(kThreads), threads, allocator); - out.AddMember(StringRef(kUnroll), unrollFactor(), allocator); + out.AddMember(StringRef(kThreads), threads, allocator); -# ifdef XMRIG_ALGO_RANDOMX -// if (m_datasetHost != -1) { -// out.AddMember(StringRef(kBFactor), bfactor(), allocator); -// out.AddMember(StringRef(kGCNAsm), gcnAsm(), allocator); -// out.AddMember(StringRef(kDatasetHost), isDatasetHost(), allocator); -// } -# endif + if (m_fields.test(RANDOMX_FIELDS)) { +# ifdef XMRIG_ALGO_RANDOMX + out.AddMember(StringRef(kBFactor), bfactor(), allocator); + out.AddMember(StringRef(kGCNAsm), isAsm(), allocator); + out.AddMember(StringRef(kDatasetHost), isDatasetHost(), allocator); +# endif + } + else { + out.AddMember(StringRef(kUnroll), unrollFactor(), allocator); + } return out; } diff --git a/src/backend/opencl/OclThread.h b/src/backend/opencl/OclThread.h index d811898ce..1882abf7a 100644 --- a/src/backend/opencl/OclThread.h +++ b/src/backend/opencl/OclThread.h @@ -66,6 +66,22 @@ public: } # endif +# ifdef XMRIG_ALGO_RANDOMX + OclThread(uint32_t index, uint32_t intensity, uint32_t worksize, uint32_t threads, bool gcnAsm, bool datasetHost, uint32_t bfactor) : + m_datasetHost(datasetHost), + m_gcnAsm(gcnAsm), + m_fields(2), + m_threads(threads, -1), + m_bfactor(bfactor), + m_index(index), + m_memChunk(0), + m_stridedIndex(0), + m_worksize(worksize) + { + setIntensity(intensity); + } +# endif + OclThread(const rapidjson::Value &value); inline bool isAsm() const { return m_gcnAsm; } diff --git a/src/backend/opencl/generators/ocl_generic_rx_generator.cpp b/src/backend/opencl/generators/ocl_generic_rx_generator.cpp new file mode 100644 index 000000000..98962032a --- /dev/null +++ b/src/backend/opencl/generators/ocl_generic_rx_generator.cpp @@ -0,0 +1,51 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "backend/opencl/OclThreads.h" +#include "backend/opencl/wrappers/OclDevice.h" +#include "crypto/common/Algorithm.h" + + +namespace xmrig { + + +constexpr const size_t oneMiB = 1024u * 1024u; + + + +bool ocl_generic_rx_generator(const OclDevice &device, const Algorithm &algorithm, OclThreads &threads) +{ + if (algorithm.family() != Algorithm::RANDOM_X) { + return false; + } + +// threads.add(OclThread(device.index(), 500, 8, 1, true, false, 6)); + + return true; +} + + +} // namespace xmrig diff --git a/src/backend/opencl/opencl.cmake b/src/backend/opencl/opencl.cmake index 1c4bd271a..c5a6335fb 100644 --- a/src/backend/opencl/opencl.cmake +++ b/src/backend/opencl/opencl.cmake @@ -82,6 +82,7 @@ if (WITH_OPENCL) ) list(APPEND SOURCES_BACKEND_OPENCL + src/backend/opencl/generators/ocl_generic_rx_generator.cpp src/backend/opencl/kernels/rx/Blake2bHashRegistersKernel.cpp src/backend/opencl/kernels/rx/Blake2bInitialHashKernel.cpp src/backend/opencl/kernels/rx/ExecuteVmKernel.cpp diff --git a/src/backend/opencl/wrappers/OclDevice.cpp b/src/backend/opencl/wrappers/OclDevice.cpp index b005d4902..32f3a4656 100644 --- a/src/backend/opencl/wrappers/OclDevice.cpp +++ b/src/backend/opencl/wrappers/OclDevice.cpp @@ -47,6 +47,10 @@ typedef union namespace xmrig { +#ifdef XMRIG_ALGO_RANDOMX +extern bool ocl_generic_rx_generator(const OclDevice &device, const Algorithm &algorithm, OclThreads &threads); +#endif + #ifdef XMRIG_ALGO_CN_GPU extern bool ocl_generic_cn_gpu_generator(const OclDevice &device, const Algorithm &algorithm, OclThreads &threads); #endif @@ -56,6 +60,9 @@ extern bool ocl_generic_cn_generator(const OclDevice &device, const Algorithm &a ocl_gen_config_fun generators[] = { +# ifdef XMRIG_ALGO_RANDOMX + ocl_generic_rx_generator, +# endif # ifdef XMRIG_ALGO_CN_GPU ocl_generic_cn_gpu_generator, # endif