Define double OpenCL threads in simple way.

This commit is contained in:
XMRig 2019-09-05 09:27:29 +07:00
parent e7b2b4fc3d
commit 1ad30d50a6
11 changed files with 73 additions and 67 deletions

View file

@ -35,7 +35,7 @@ namespace xmrig {
class CpuThread class CpuThread
{ {
public: public:
inline constexpr CpuThread() {} inline constexpr CpuThread() = default;
inline constexpr CpuThread(int64_t affinity, uint32_t intensity) : m_affinity(affinity), m_intensity(intensity) {} inline constexpr CpuThread(int64_t affinity, uint32_t intensity) : m_affinity(affinity), m_intensity(intensity) {}
CpuThread(const rapidjson::Value &value); CpuThread(const rapidjson::Value &value);

View file

@ -227,7 +227,7 @@ void xmrig::OclBackend::printHashrate(bool details)
for (const OclLaunchData &data : d_ptr->threads) { for (const OclLaunchData &data : d_ptr->threads) {
Log::print("| %8zu | %8" PRId64 " | %7s | %7s | %7s |" CYAN_BOLD(" #%u") YELLOW(" %s") " %s", Log::print("| %8zu | %8" PRId64 " | %7s | %7s | %7s |" CYAN_BOLD(" #%u") YELLOW(" %s") " %s",
i, i,
data.thread.affinity(), data.affinity,
Hashrate::format(hashrate()->calc(i, Hashrate::ShortInterval), num, sizeof num / 3), 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::MediumInterval), num + 8, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::LargeInterval), num + 8 * 2, sizeof num / 3), Hashrate::format(hashrate()->calc(i, Hashrate::LargeInterval), num + 8 * 2, sizeof num / 3),
@ -341,7 +341,7 @@ rapidjson::Value xmrig::OclBackend::toJSON(rapidjson::Document &doc) const
for (const OclLaunchData &data : d_ptr->threads) { for (const OclLaunchData &data : d_ptr->threads) {
Value thread(kObjectType); Value thread(kObjectType);
thread.AddMember("intensity", data.thread.intensity(), allocator); thread.AddMember("intensity", data.thread.intensity(), allocator);
thread.AddMember("affinity", data.thread.affinity(), allocator); thread.AddMember("affinity", data.affinity, allocator);
Value hashrate(kArrayType); Value hashrate(kArrayType);
hashrate.PushBack(Hashrate::normalize(hr->calc(i, Hashrate::ShortInterval)), allocator); hashrate.PushBack(Hashrate::normalize(hr->calc(i, Hashrate::ShortInterval)), allocator);

View file

@ -96,7 +96,7 @@ xmrig::OclPlatform xmrig::OclConfig::platform() const
{ {
const auto platforms = OclPlatform::get(); const auto platforms = OclPlatform::get();
if (platforms.empty()) { if (platforms.empty()) {
return OclPlatform(); return {};
} }
if (!m_platformVendor.isEmpty()) { if (!m_platformVendor.isEmpty()) {
@ -127,7 +127,7 @@ xmrig::OclPlatform xmrig::OclConfig::platform() const
return platforms[m_platformIndex]; return platforms[m_platformIndex];
} }
return OclPlatform(); return {};
} }
@ -166,7 +166,9 @@ std::vector<xmrig::OclLaunchData> xmrig::OclConfig::get(const Miner *miner, cons
continue; continue;
} }
out.emplace_back(miner, algorithm, *this, platform, thread, devices[thread.index()]); for (int64_t affinity : thread.threads()) {
out.emplace_back(miner, algorithm, *this, platform, thread, devices[thread.index()], affinity);
}
} }
return out; return out;

View file

@ -28,9 +28,10 @@
#include "backend/opencl/OclConfig.h" #include "backend/opencl/OclConfig.h"
xmrig::OclLaunchData::OclLaunchData(const Miner *miner, const Algorithm &algorithm, const OclConfig &config, const OclPlatform &platform, const OclThread &thread, const OclDevice &device) : xmrig::OclLaunchData::OclLaunchData(const Miner *miner, const Algorithm &algorithm, const OclConfig &config, const OclPlatform &platform, const OclThread &thread, const OclDevice &device, int64_t affinity) :
algorithm(algorithm), algorithm(algorithm),
cache(config.isCacheEnabled()), cache(config.isCacheEnabled()),
affinity(affinity),
miner(miner), miner(miner),
device(device), device(device),
platform(platform), platform(platform),

View file

@ -34,7 +34,7 @@
#include "crypto/common/Nonce.h" #include "crypto/common/Nonce.h"
typedef struct _cl_context *cl_context; using cl_context = struct _cl_context *;
namespace xmrig { namespace xmrig {
@ -47,7 +47,7 @@ class Miner;
class OclLaunchData class OclLaunchData
{ {
public: public:
OclLaunchData(const Miner *miner, const Algorithm &algorithm, const OclConfig &config, const OclPlatform &platform, const OclThread &thread, const OclDevice &device); OclLaunchData(const Miner *miner, const Algorithm &algorithm, const OclConfig &config, const OclPlatform &platform, const OclThread &thread, const OclDevice &device, int64_t affinity);
bool isEqual(const OclLaunchData &other) const; bool isEqual(const OclLaunchData &other) const;
@ -59,6 +59,7 @@ public:
cl_context ctx = nullptr; cl_context ctx = nullptr;
const Algorithm algorithm; const Algorithm algorithm;
const bool cache; const bool cache;
const int64_t affinity;
const Miner *miner; const Miner *miner;
const OclDevice device; const OclDevice device;
const OclPlatform platform; const OclPlatform platform;

View file

@ -23,22 +23,21 @@
*/ */
#include <algorithm>
#include "backend/opencl/OclThread.h" #include "backend/opencl/OclThread.h"
#include "base/io/json/Json.h" #include "base/io/json/Json.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include <algorithm>
namespace xmrig { namespace xmrig {
static const char *kAffinity = "affinity";
static const char *kCompMode = "comp_mode";
static const char *kIndex = "index"; static const char *kIndex = "index";
static const char *kIntensity = "intensity"; static const char *kIntensity = "intensity";
static const char *kMemChunk = "mem_chunk";
static const char *kStridedIndex = "strided_index"; static const char *kStridedIndex = "strided_index";
static const char *kThreads = "threads";
static const char *kUnroll = "unroll"; static const char *kUnroll = "unroll";
static const char *kWorksize = "worksize"; static const char *kWorksize = "worksize";
@ -54,13 +53,10 @@ static const char* kDatasetHost = "dataset_host";
xmrig::OclThread::OclThread(const rapidjson::Value &value) xmrig::OclThread::OclThread(const rapidjson::Value &value)
{ {
m_index = Json::getUint(value, kIndex); m_index = Json::getUint(value, kIndex);
m_intensity = Json::getUint(value, kIntensity); m_worksize = std::max(std::min(Json::getUint(value, kWorksize), 128u), 1u);
m_worksize = Json::getUint(value, kWorksize); m_unrollFactor = std::max(std::min(Json::getUint(value, kUnroll, m_unrollFactor), 128u), 1u);
m_affinity = Json::getInt64(value, kAffinity, -1);
m_memChunk = std::min(Json::getUint(value, kMemChunk, m_memChunk), 18u);
m_compMode = Json::getBool(value, kCompMode, m_compMode);
setUnrollFactor(Json::getUint(value, kUnroll, m_unrollFactor)); setIntensity(Json::getUint(value, kIntensity));
# ifdef XMRIG_ALGO_RANDOMX # ifdef XMRIG_ALGO_RANDOMX
m_bfactor = Json::getUint(value, kBFactor, 6); m_bfactor = Json::getUint(value, kBFactor, 6);
@ -68,20 +64,31 @@ xmrig::OclThread::OclThread(const rapidjson::Value &value)
m_datasetHost = Json::getInt(value, kDatasetHost, m_datasetHost); m_datasetHost = Json::getInt(value, kDatasetHost, m_datasetHost);
# endif # endif
const rapidjson::Value &stridedIndex = Json::getValue(value, kStridedIndex); const rapidjson::Value &si = Json::getArray(value, kStridedIndex);
if (stridedIndex.IsBool()) { if (si.IsArray() && si.Size() >= 2) {
m_stridedIndex = stridedIndex.GetBool() ? 1 : 0; m_stridedIndex = std::min(si[0].GetUint(), 2u);
m_memChunk = std::min(si[1].GetUint(), 18u);
} }
else if (stridedIndex.IsUint()) {
m_stridedIndex = std::min(stridedIndex.GetUint(), 2u); const rapidjson::Value &threads = Json::getArray(value, kThreads);
if (threads.IsArray()) {
m_threads.reserve(threads.Size());
for (const auto &affinity : threads.GetArray()) {
m_threads.emplace_back(affinity.GetInt64());
}
}
if (m_threads.empty()) {
m_threads.emplace_back(-1);
} }
} }
bool xmrig::OclThread::isEqual(const OclThread &other) const bool xmrig::OclThread::isEqual(const OclThread &other) const
{ {
return other.m_compMode == m_compMode && return other.m_threads.size() == m_threads.size() &&
other.m_affinity == m_affinity && std::equal(m_threads.begin(), m_threads.end(), other.m_threads.begin()) &&
other.m_bfactor == m_bfactor && other.m_bfactor == m_bfactor &&
other.m_datasetHost == m_datasetHost && other.m_datasetHost == m_datasetHost &&
other.m_gcnAsm == m_gcnAsm && other.m_gcnAsm == m_gcnAsm &&
@ -104,18 +111,22 @@ rapidjson::Value xmrig::OclThread::toJSON(rapidjson::Document &doc) const
out.AddMember(StringRef(kIndex), index(), allocator); out.AddMember(StringRef(kIndex), index(), allocator);
out.AddMember(StringRef(kIntensity), intensity(), allocator); out.AddMember(StringRef(kIntensity), intensity(), allocator);
out.AddMember(StringRef(kWorksize), worksize(), allocator); out.AddMember(StringRef(kWorksize), worksize(), allocator);
out.AddMember(StringRef(kStridedIndex), stridedIndex(), allocator);
if (stridedIndex() == 2) { Value si(kArrayType);
out.AddMember(StringRef(kMemChunk), memChunk(), allocator); si.Reserve(2, allocator);
si.PushBack(stridedIndex(), allocator);
si.PushBack(memChunk(), allocator);
Value threads(kArrayType);
threads.Reserve(m_threads.size(), allocator);
for (auto thread : m_threads) {
threads.PushBack(thread, allocator);
} }
out.AddMember(StringRef(kStridedIndex), si, allocator);
out.AddMember(StringRef(kThreads), threads, allocator);
out.AddMember(StringRef(kUnroll), unrollFactor(), allocator); out.AddMember(StringRef(kUnroll), unrollFactor(), allocator);
out.AddMember(StringRef(kAffinity), affinity(), allocator);
if (isCompMode()) {
out.AddMember(StringRef(kCompMode), true, allocator);
}
# ifdef XMRIG_ALGO_RANDOMX # ifdef XMRIG_ALGO_RANDOMX
if (m_datasetHost != -1) { if (m_datasetHost != -1) {
@ -127,9 +138,3 @@ rapidjson::Value xmrig::OclThread::toJSON(rapidjson::Document &doc) const
return out; return out;
} }
void xmrig::OclThread::setUnrollFactor(uint32_t unrollFactor)
{
m_unrollFactor = unrollFactor == 0 ? 1 : std::min(unrollFactor, 128u);
}

View file

@ -29,27 +29,30 @@
#include "rapidjson/fwd.h" #include "rapidjson/fwd.h"
#include <vector>
namespace xmrig { namespace xmrig {
class OclThread class OclThread
{ {
public: public:
OclThread() = default; OclThread() = delete;
OclThread(uint32_t index, uint32_t intensity, uint32_t worksize, uint32_t stridedIndex, uint32_t memChunk, int64_t affinity = -1) : OclThread(uint32_t index, uint32_t intensity, uint32_t worksize, uint32_t stridedIndex, uint32_t memChunk, uint32_t threads) :
m_affinity(affinity), m_threads(threads, -1),
m_index(index), m_index(index),
m_intensity(intensity),
m_memChunk(memChunk), m_memChunk(memChunk),
m_stridedIndex(stridedIndex), m_stridedIndex(stridedIndex),
m_worksize(worksize) m_worksize(worksize)
{} {
setIntensity(intensity);
}
OclThread(const rapidjson::Value &value); OclThread(const rapidjson::Value &value);
inline bool isCompMode() const { return m_compMode; }
inline bool isValid() const { return m_intensity > 0; } inline bool isValid() const { return m_intensity > 0; }
inline int64_t affinity() const { return m_affinity; } inline const std::vector<int64_t> &threads() const { return m_threads; }
inline uint32_t bfactor() const { return m_bfactor; } inline uint32_t bfactor() const { return m_bfactor; }
inline uint32_t datasetHost() const { return m_datasetHost < 0 ? 0 : static_cast<uint32_t>(m_datasetHost); } inline uint32_t datasetHost() const { return m_datasetHost < 0 ? 0 : static_cast<uint32_t>(m_datasetHost); }
inline uint32_t gcnAsm() const { return m_gcnAsm; } inline uint32_t gcnAsm() const { return m_gcnAsm; }
@ -67,11 +70,10 @@ public:
rapidjson::Value toJSON(rapidjson::Document &doc) const; rapidjson::Value toJSON(rapidjson::Document &doc) const;
private: private:
void setUnrollFactor(uint32_t unrollFactor); inline void setIntensity(uint32_t intensity) { m_intensity = intensity / m_worksize * m_worksize; }
bool m_compMode = false;
int m_datasetHost = -1; int m_datasetHost = -1;
int64_t m_affinity = -1; std::vector<int64_t> m_threads;
uint32_t m_bfactor = 6; uint32_t m_bfactor = 6;
uint32_t m_gcnAsm = 1; uint32_t m_gcnAsm = 1;
uint32_t m_index = 0; uint32_t m_index = 0;

View file

@ -54,7 +54,7 @@ static inline uint32_t roundSize(uint32_t intensity) { return kReserveCount / in
xmrig::OclWorker::OclWorker(size_t id, const OclLaunchData &data) : xmrig::OclWorker::OclWorker(size_t id, const OclLaunchData &data) :
Worker(id, data.thread.affinity(), -1), Worker(id, data.affinity, -1),
m_algorithm(data.algorithm), m_algorithm(data.algorithm),
m_miner(data.miner), m_miner(data.miner),
m_intensity(data.thread.intensity()) m_intensity(data.thread.intensity())

View file

@ -184,14 +184,9 @@ void xmrig::OclDevice::generate(const Algorithm &algorithm, OclThreads &threads)
const uint32_t worksize = getWorksize(algorithm); const uint32_t worksize = getWorksize(algorithm);
const uint32_t stridedIndex = getStridedIndex(algorithm); const uint32_t stridedIndex = getStridedIndex(algorithm);
const uint32_t memChunk = getMemChunk(algorithm); const uint32_t memChunk = getMemChunk(algorithm);
const uint32_t threadCount = ((globalMem() - intensity * 2 * algorithm.l3()) > 128 * oneMiB) ? 2 : 1;
intensity -= intensity % worksize; threads.add(OclThread(index(), intensity, worksize, stridedIndex, memChunk, threadCount));
threads.add(OclThread(index(), intensity, worksize, stridedIndex, memChunk));
if ((globalMem() - intensity * 2 * algorithm.l3()) > 128 * oneMiB) {
threads.add(OclThread(index(), intensity, worksize, stridedIndex, memChunk));
}
} }

View file

@ -34,8 +34,8 @@
#include "base/tools/String.h" #include "base/tools/String.h"
typedef struct _cl_device_id *cl_device_id; using cl_device_id = struct _cl_device_id *;
typedef struct _cl_platform_id *cl_platform_id; using cl_platform_id = struct _cl_platform_id *;
namespace xmrig { namespace xmrig {
@ -59,7 +59,7 @@ public:
Navi_10 Navi_10
}; };
OclDevice() = default; OclDevice() = delete;
OclDevice(uint32_t index, cl_device_id id, cl_platform_id platform); OclDevice(uint32_t index, cl_device_id id, cl_platform_id platform);
size_t freeMem() const; size_t freeMem() const;

View file

@ -28,7 +28,7 @@
#include <memory.h> #include <memory.h>
#include <stdint.h> #include <cstdint>
#include "base/tools/String.h" #include "base/tools/String.h"
@ -41,7 +41,7 @@ namespace xmrig {
class JobResult class JobResult
{ {
public: public:
inline JobResult() {} JobResult() = delete;
inline JobResult(const Job &job, uint32_t nonce, const uint8_t *result) : inline JobResult(const Job &job, uint32_t nonce, const uint8_t *result) :
algorithm(job.algorithm()), algorithm(job.algorithm()),
@ -66,7 +66,7 @@ public:
const uint8_t index = 0; const uint8_t index = 0;
private: private:
uint8_t m_result[32]; uint8_t m_result[32] = { 0 };
}; };