From 797d90c4dde46db78bf3175a825e4a981c835465 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 24 Aug 2019 00:14:41 +0700 Subject: [PATCH] Implemented OclLaunchData creation. --- src/backend/cpu/CpuBackend.cpp | 12 +++++---- src/backend/cpu/CpuConfig.cpp | 2 +- src/backend/opencl/OclBackend.cpp | 40 +++++++++------------------- src/backend/opencl/OclConfig.cpp | 21 +++++++++++++-- src/backend/opencl/OclConfig.h | 2 +- src/backend/opencl/OclLaunchData.cpp | 17 +++++------- src/backend/opencl/OclLaunchData.h | 11 ++++---- 7 files changed, 53 insertions(+), 52 deletions(-) diff --git a/src/backend/cpu/CpuBackend.cpp b/src/backend/cpu/CpuBackend.cpp index 310b2bef5..ec4788a7a 100644 --- a/src/backend/cpu/CpuBackend.cpp +++ b/src/backend/cpu/CpuBackend.cpp @@ -263,7 +263,7 @@ void xmrig::CpuBackend::setJob(const Job &job) const CpuConfig &cpu = d_ptr->controller->config()->cpu(); std::vector threads = cpu.get(d_ptr->controller->miner(), job.algorithm()); - if (d_ptr->threads.size() == threads.size() && std::equal(d_ptr->threads.begin(), d_ptr->threads.end(), threads.begin())) { + if (!d_ptr->threads.empty() && d_ptr->threads.size() == threads.size() && std::equal(d_ptr->threads.begin(), d_ptr->threads.end(), threads.begin())) { return; } @@ -271,11 +271,9 @@ void xmrig::CpuBackend::setJob(const Job &job) d_ptr->profileName = cpu.threads().profileName(job.algorithm()); if (d_ptr->profileName.isNull() || threads.empty()) { - d_ptr->workers.stop(); + LOG_WARN("%s " RED_BOLD("disabled") YELLOW(" (no suitable configuration found)"), tag); - LOG_WARN(YELLOW_BOLD_S "CPU disabled, no suitable configuration for algo %s", job.algorithm().shortName()); - - return; + return stop(); } d_ptr->threads = std::move(threads); @@ -314,6 +312,10 @@ void xmrig::CpuBackend::start(IWorker *worker) void xmrig::CpuBackend::stop() { + if (d_ptr->threads.empty()) { + return; + } + const uint64_t ts = Chrono::steadyMSecs(); d_ptr->workers.stop(); diff --git a/src/backend/cpu/CpuConfig.cpp b/src/backend/cpu/CpuConfig.cpp index a044cc4a4..7ea6a38b7 100644 --- a/src/backend/cpu/CpuConfig.cpp +++ b/src/backend/cpu/CpuConfig.cpp @@ -121,7 +121,7 @@ std::vector xmrig::CpuConfig::get(const Miner *miner, cons out.reserve(threads.count()); for (const CpuThread &thread : threads.data()) { - out.push_back(CpuLaunchData(miner, algorithm, *this, thread)); + out.emplace_back(miner, algorithm, *this, thread); } return out; diff --git a/src/backend/opencl/OclBackend.cpp b/src/backend/opencl/OclBackend.cpp index fd1bdfb5f..acb0b627a 100644 --- a/src/backend/opencl/OclBackend.cpp +++ b/src/backend/opencl/OclBackend.cpp @@ -74,7 +74,6 @@ public: pages = 0; started = 0; threads = 0; - ways = 0; ts = Chrono::steadyMSecs(); } @@ -83,7 +82,6 @@ public: size_t pages = 0; size_t started = 0; size_t threads = 0; - size_t ways = 0; uint64_t ts = 0; }; @@ -161,19 +159,7 @@ public: status.memory = algo.l3(); status.threads = threads.size(); - for (const OclLaunchData &data : threads) { - status.ways += static_cast(data.intensity); - } - - workers.start(threads); - } - - - size_t ways() - { - std::lock_guard lock(mutex); - - return status.ways; + //workers.start(threads); // FIXME } @@ -256,7 +242,7 @@ void xmrig::OclBackend::printHashrate(bool details) for (const OclLaunchData &data : d_ptr->threads) { Log::print("| %13zu | %8" PRId64 " | %7s | %7s | %7s |", i, - data.affinity, + data.thread.affinity(), Hashrate::format(hashrate()->calc(i, Hashrate::ShortInterval), num, sizeof num / 3), Hashrate::format(hashrate()->calc(i, Hashrate::MediumInterval), num + 8, sizeof num / 3), Hashrate::format(hashrate()->calc(i, Hashrate::LargeInterval), num + 8 * 2, sizeof num / 3) @@ -275,21 +261,19 @@ void xmrig::OclBackend::setJob(const Job &job) const OclConfig &cl = d_ptr->controller->config()->cl(); - std::vector threads = cl.get(d_ptr->controller->miner(), job.algorithm()); -// if (d_ptr->threads.size() == threads.size() && std::equal(d_ptr->threads.begin(), d_ptr->threads.end(), threads.begin())) { -// return; -// } + std::vector threads = cl.get(d_ptr->controller->miner(), job.algorithm(), d_ptr->devices, tag); + if (!d_ptr->threads.empty() && d_ptr->threads.size() == threads.size() && std::equal(d_ptr->threads.begin(), d_ptr->threads.end(), threads.begin())) { + return; + } d_ptr->algo = job.algorithm(); d_ptr->profileName = cl.threads().profileName(job.algorithm()); -// if (d_ptr->profileName.isNull() || threads.empty()) { -// d_ptr->workers.stop(); + if (d_ptr->profileName.isNull() || threads.empty()) { + LOG_WARN("%s " RED_BOLD("disabled") YELLOW(" (no suitable configuration found)"), tag); -// LOG_WARN(YELLOW_BOLD_S "CPU disabled, no suitable configuration for algo %s", job.algorithm().shortName()); - -// return; -// } + return stop(); + } d_ptr->threads = std::move(threads); d_ptr->start(); @@ -355,8 +339,8 @@ rapidjson::Value xmrig::OclBackend::toJSON(rapidjson::Document &doc) const size_t i = 0; for (const OclLaunchData &data : d_ptr->threads) { Value thread(kObjectType); - thread.AddMember("intensity", data.intensity, allocator); - thread.AddMember("affinity", data.affinity, allocator); + thread.AddMember("intensity", data.thread.intensity(), allocator); + thread.AddMember("affinity", data.thread.affinity(), allocator); Value hashrate(kArrayType); hashrate.PushBack(Hashrate::normalize(hr->calc(i, Hashrate::ShortInterval)), allocator); diff --git a/src/backend/opencl/OclConfig.cpp b/src/backend/opencl/OclConfig.cpp index 3a6f39d32..03b36c576 100644 --- a/src/backend/opencl/OclConfig.cpp +++ b/src/backend/opencl/OclConfig.cpp @@ -26,6 +26,7 @@ #include "backend/opencl/OclConfig.h" #include "backend/opencl/wrappers/OclLib.h" #include "base/io/json/Json.h" +#include "base/io/log/Log.h" #include "rapidjson/document.h" @@ -34,12 +35,12 @@ namespace xmrig { static const char *kAMD = "AMD"; static const char *kCache = "cache"; static const char *kCn = "cn"; +static const char *kCn2 = "cn/2"; static const char *kEnabled = "enabled"; static const char *kINTEL = "INTEL"; static const char *kLoader = "loader"; static const char *kNVIDIA = "NVIDIA"; static const char *kPlatform = "platform"; -static const char *kCn2 = "cn/2"; #ifdef XMRIG_ALGO_CN_GPU @@ -148,9 +149,25 @@ rapidjson::Value xmrig::OclConfig::toJSON(rapidjson::Document &doc) const } -std::vector xmrig::OclConfig::get(const Miner *miner, const Algorithm &algorithm) const +std::vector xmrig::OclConfig::get(const Miner *miner, const Algorithm &algorithm, const std::vector &devices, const char *tag) const { std::vector out; + const OclThreads &threads = m_threads.get(algorithm); + + if (threads.isEmpty()) { + return out; + } + + out.reserve(threads.count()); + + for (const OclThread &thread : threads.data()) { + if (thread.index() >= devices.size()) { + LOG_INFO("%s" YELLOW(" skip non-existing device with index ") YELLOW_BOLD("%u"), tag, thread.index()); + continue; + } + + out.emplace_back(miner, algorithm, *this, thread, devices[thread.index()]); + } return out; } diff --git a/src/backend/opencl/OclConfig.h b/src/backend/opencl/OclConfig.h index d3a97bcea..05a303a5f 100644 --- a/src/backend/opencl/OclConfig.h +++ b/src/backend/opencl/OclConfig.h @@ -42,7 +42,7 @@ public: OclPlatform platform() const; rapidjson::Value toJSON(rapidjson::Document &doc) const; - std::vector get(const Miner *miner, const Algorithm &algorithm) const; + std::vector get(const Miner *miner, const Algorithm &algorithm, const std::vector &devices, const char *tag) const; void read(const rapidjson::Value &value); inline bool isCacheEnabled() const { return m_cache; } diff --git a/src/backend/opencl/OclLaunchData.cpp b/src/backend/opencl/OclLaunchData.cpp index 3704489dc..7a94cf754 100644 --- a/src/backend/opencl/OclLaunchData.cpp +++ b/src/backend/opencl/OclLaunchData.cpp @@ -28,21 +28,18 @@ #include "backend/opencl/OclConfig.h" -xmrig::OclLaunchData::OclLaunchData(const Miner *miner, const Algorithm &algorithm, const OclConfig &config, const OclThread &thread) : +xmrig::OclLaunchData::OclLaunchData(const Miner *miner, const Algorithm &algorithm, const OclConfig &config, const OclThread &thread, const OclDevice &device) : algorithm(algorithm), - intensity(thread.intensity()), - priority(-1), - affinity(thread.affinity()), - miner(miner) + cache(config.isCacheEnabled()), + miner(miner), + device(device), + thread(thread) { } bool xmrig::OclLaunchData::isEqual(const OclLaunchData &other) const { - return (algorithm.l3() == other.algorithm.l3() - && intensity == other.intensity - && priority == other.priority - && affinity == other.affinity - ); + return (other.algorithm.l3() == algorithm.l3() && + other.thread == thread); } diff --git a/src/backend/opencl/OclLaunchData.h b/src/backend/opencl/OclLaunchData.h index 535fb815b..474d6eba6 100644 --- a/src/backend/opencl/OclLaunchData.h +++ b/src/backend/opencl/OclLaunchData.h @@ -27,6 +27,8 @@ #define XMRIG_OCLLAUNCHDATA_H +#include "backend/opencl/OclThread.h" +#include "backend/opencl/wrappers/OclDevice.h" #include "crypto/common/Algorithm.h" #include "crypto/common/Nonce.h" @@ -35,14 +37,13 @@ namespace xmrig { class OclConfig; -class OclThread; class Miner; class OclLaunchData { public: - OclLaunchData(const Miner *miner, const Algorithm &algorithm, const OclConfig &config, const OclThread &thread); + OclLaunchData(const Miner *miner, const Algorithm &algorithm, const OclConfig &config, const OclThread &thread, const OclDevice &device); bool isEqual(const OclLaunchData &other) const; @@ -52,10 +53,10 @@ public: inline bool operator==(const OclLaunchData &other) const { return isEqual(other); } const Algorithm algorithm; - const int intensity; - const int priority; - const int64_t affinity; + const bool cache; const Miner *miner; + const OclDevice device; + const OclThread thread; };