Implemented OclLaunchData creation.

This commit is contained in:
XMRig 2019-08-24 00:14:41 +07:00
parent 55e12fb34b
commit 797d90c4dd
7 changed files with 53 additions and 52 deletions

View file

@ -263,7 +263,7 @@ void xmrig::CpuBackend::setJob(const Job &job)
const CpuConfig &cpu = d_ptr->controller->config()->cpu();
std::vector<CpuLaunchData> 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();

View file

@ -121,7 +121,7 @@ std::vector<xmrig::CpuLaunchData> 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;

View file

@ -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<size_t>(data.intensity);
}
workers.start(threads);
}
size_t ways()
{
std::lock_guard<std::mutex> 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<OclLaunchData> 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<OclLaunchData> 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);

View file

@ -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::OclLaunchData> xmrig::OclConfig::get(const Miner *miner, const Algorithm &algorithm) const
std::vector<xmrig::OclLaunchData> xmrig::OclConfig::get(const Miner *miner, const Algorithm &algorithm, const std::vector<OclDevice> &devices, const char *tag) const
{
std::vector<OclLaunchData> 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;
}

View file

@ -42,7 +42,7 @@ public:
OclPlatform platform() const;
rapidjson::Value toJSON(rapidjson::Document &doc) const;
std::vector<OclLaunchData> get(const Miner *miner, const Algorithm &algorithm) const;
std::vector<OclLaunchData> get(const Miner *miner, const Algorithm &algorithm, const std::vector<OclDevice> &devices, const char *tag) const;
void read(const rapidjson::Value &value);
inline bool isCacheEnabled() const { return m_cache; }

View file

@ -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);
}

View file

@ -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;
};