mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-18 18:11:05 +00:00
Define double OpenCL threads in simple way.
This commit is contained in:
parent
e7b2b4fc3d
commit
1ad30d50a6
11 changed files with 73 additions and 67 deletions
|
@ -35,7 +35,7 @@ namespace xmrig {
|
|||
class CpuThread
|
||||
{
|
||||
public:
|
||||
inline constexpr CpuThread() {}
|
||||
inline constexpr CpuThread() = default;
|
||||
inline constexpr CpuThread(int64_t affinity, uint32_t intensity) : m_affinity(affinity), m_intensity(intensity) {}
|
||||
|
||||
CpuThread(const rapidjson::Value &value);
|
||||
|
|
|
@ -227,7 +227,7 @@ void xmrig::OclBackend::printHashrate(bool details)
|
|||
for (const OclLaunchData &data : d_ptr->threads) {
|
||||
Log::print("| %8zu | %8" PRId64 " | %7s | %7s | %7s |" CYAN_BOLD(" #%u") YELLOW(" %s") " %s",
|
||||
i,
|
||||
data.thread.affinity(),
|
||||
data.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),
|
||||
|
@ -341,7 +341,7 @@ rapidjson::Value xmrig::OclBackend::toJSON(rapidjson::Document &doc) const
|
|||
for (const OclLaunchData &data : d_ptr->threads) {
|
||||
Value thread(kObjectType);
|
||||
thread.AddMember("intensity", data.thread.intensity(), allocator);
|
||||
thread.AddMember("affinity", data.thread.affinity(), allocator);
|
||||
thread.AddMember("affinity", data.affinity, allocator);
|
||||
|
||||
Value hashrate(kArrayType);
|
||||
hashrate.PushBack(Hashrate::normalize(hr->calc(i, Hashrate::ShortInterval)), allocator);
|
||||
|
|
|
@ -96,7 +96,7 @@ xmrig::OclPlatform xmrig::OclConfig::platform() const
|
|||
{
|
||||
const auto platforms = OclPlatform::get();
|
||||
if (platforms.empty()) {
|
||||
return OclPlatform();
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!m_platformVendor.isEmpty()) {
|
||||
|
@ -127,7 +127,7 @@ xmrig::OclPlatform xmrig::OclConfig::platform() const
|
|||
return platforms[m_platformIndex];
|
||||
}
|
||||
|
||||
return OclPlatform();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
|
@ -166,7 +166,9 @@ std::vector<xmrig::OclLaunchData> xmrig::OclConfig::get(const Miner *miner, cons
|
|||
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;
|
||||
|
|
|
@ -28,9 +28,10 @@
|
|||
#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),
|
||||
cache(config.isCacheEnabled()),
|
||||
affinity(affinity),
|
||||
miner(miner),
|
||||
device(device),
|
||||
platform(platform),
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "crypto/common/Nonce.h"
|
||||
|
||||
|
||||
typedef struct _cl_context *cl_context;
|
||||
using cl_context = struct _cl_context *;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -47,7 +47,7 @@ class Miner;
|
|||
class OclLaunchData
|
||||
{
|
||||
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;
|
||||
|
||||
|
@ -59,6 +59,7 @@ public:
|
|||
cl_context ctx = nullptr;
|
||||
const Algorithm algorithm;
|
||||
const bool cache;
|
||||
const int64_t affinity;
|
||||
const Miner *miner;
|
||||
const OclDevice device;
|
||||
const OclPlatform platform;
|
||||
|
|
|
@ -23,22 +23,21 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
#include "backend/opencl/OclThread.h"
|
||||
|
||||
#include "base/io/json/Json.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
static const char *kAffinity = "affinity";
|
||||
static const char *kCompMode = "comp_mode";
|
||||
static const char *kIndex = "index";
|
||||
static const char *kIntensity = "intensity";
|
||||
static const char *kMemChunk = "mem_chunk";
|
||||
static const char *kStridedIndex = "strided_index";
|
||||
static const char *kThreads = "threads";
|
||||
static const char *kUnroll = "unroll";
|
||||
static const char *kWorksize = "worksize";
|
||||
|
||||
|
@ -53,14 +52,11 @@ static const char* kDatasetHost = "dataset_host";
|
|||
|
||||
xmrig::OclThread::OclThread(const rapidjson::Value &value)
|
||||
{
|
||||
m_index = Json::getUint(value, kIndex);
|
||||
m_intensity = Json::getUint(value, kIntensity);
|
||||
m_worksize = Json::getUint(value, kWorksize);
|
||||
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);
|
||||
m_index = Json::getUint(value, kIndex);
|
||||
m_worksize = std::max(std::min(Json::getUint(value, kWorksize), 128u), 1u);
|
||||
m_unrollFactor = std::max(std::min(Json::getUint(value, kUnroll, m_unrollFactor), 128u), 1u);
|
||||
|
||||
setUnrollFactor(Json::getUint(value, kUnroll, m_unrollFactor));
|
||||
setIntensity(Json::getUint(value, kIntensity));
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
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);
|
||||
# endif
|
||||
|
||||
const rapidjson::Value &stridedIndex = Json::getValue(value, kStridedIndex);
|
||||
if (stridedIndex.IsBool()) {
|
||||
m_stridedIndex = stridedIndex.GetBool() ? 1 : 0;
|
||||
const rapidjson::Value &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);
|
||||
}
|
||||
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
|
||||
{
|
||||
return other.m_compMode == m_compMode &&
|
||||
other.m_affinity == m_affinity &&
|
||||
return other.m_threads.size() == m_threads.size() &&
|
||||
std::equal(m_threads.begin(), m_threads.end(), other.m_threads.begin()) &&
|
||||
other.m_bfactor == m_bfactor &&
|
||||
other.m_datasetHost == m_datasetHost &&
|
||||
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(kIntensity), intensity(), allocator);
|
||||
out.AddMember(StringRef(kWorksize), worksize(), allocator);
|
||||
out.AddMember(StringRef(kStridedIndex), stridedIndex(), allocator);
|
||||
|
||||
if (stridedIndex() == 2) {
|
||||
out.AddMember(StringRef(kMemChunk), memChunk(), allocator);
|
||||
Value si(kArrayType);
|
||||
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(kAffinity), affinity(), allocator);
|
||||
|
||||
if (isCompMode()) {
|
||||
out.AddMember(StringRef(kCompMode), true, allocator);
|
||||
}
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (m_datasetHost != -1) {
|
||||
|
@ -127,9 +138,3 @@ rapidjson::Value xmrig::OclThread::toJSON(rapidjson::Document &doc) const
|
|||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::OclThread::setUnrollFactor(uint32_t unrollFactor)
|
||||
{
|
||||
m_unrollFactor = unrollFactor == 0 ? 1 : std::min(unrollFactor, 128u);
|
||||
}
|
||||
|
|
|
@ -29,27 +29,30 @@
|
|||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class OclThread
|
||||
{
|
||||
public:
|
||||
OclThread() = default;
|
||||
OclThread(uint32_t index, uint32_t intensity, uint32_t worksize, uint32_t stridedIndex, uint32_t memChunk, int64_t affinity = -1) :
|
||||
m_affinity(affinity),
|
||||
OclThread() = delete;
|
||||
OclThread(uint32_t index, uint32_t intensity, uint32_t worksize, uint32_t stridedIndex, uint32_t memChunk, uint32_t threads) :
|
||||
m_threads(threads, -1),
|
||||
m_index(index),
|
||||
m_intensity(intensity),
|
||||
m_memChunk(memChunk),
|
||||
m_stridedIndex(stridedIndex),
|
||||
m_worksize(worksize)
|
||||
{}
|
||||
{
|
||||
setIntensity(intensity);
|
||||
}
|
||||
|
||||
OclThread(const rapidjson::Value &value);
|
||||
|
||||
inline bool isCompMode() const { return m_compMode; }
|
||||
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 datasetHost() const { return m_datasetHost < 0 ? 0 : static_cast<uint32_t>(m_datasetHost); }
|
||||
inline uint32_t gcnAsm() const { return m_gcnAsm; }
|
||||
|
@ -67,11 +70,10 @@ public:
|
|||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
|
||||
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;
|
||||
int64_t m_affinity = -1;
|
||||
std::vector<int64_t> m_threads;
|
||||
uint32_t m_bfactor = 6;
|
||||
uint32_t m_gcnAsm = 1;
|
||||
uint32_t m_index = 0;
|
||||
|
|
|
@ -54,7 +54,7 @@ static inline uint32_t roundSize(uint32_t intensity) { return kReserveCount / in
|
|||
|
||||
|
||||
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_miner(data.miner),
|
||||
m_intensity(data.thread.intensity())
|
||||
|
|
|
@ -184,14 +184,9 @@ void xmrig::OclDevice::generate(const Algorithm &algorithm, OclThreads &threads)
|
|||
const uint32_t worksize = getWorksize(algorithm);
|
||||
const uint32_t stridedIndex = getStridedIndex(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));
|
||||
|
||||
if ((globalMem() - intensity * 2 * algorithm.l3()) > 128 * oneMiB) {
|
||||
threads.add(OclThread(index(), intensity, worksize, stridedIndex, memChunk));
|
||||
}
|
||||
threads.add(OclThread(index(), intensity, worksize, stridedIndex, memChunk, threadCount));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
#include "base/tools/String.h"
|
||||
|
||||
|
||||
typedef struct _cl_device_id *cl_device_id;
|
||||
typedef struct _cl_platform_id *cl_platform_id;
|
||||
using cl_device_id = struct _cl_device_id *;
|
||||
using cl_platform_id = struct _cl_platform_id *;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -59,7 +59,7 @@ public:
|
|||
Navi_10
|
||||
};
|
||||
|
||||
OclDevice() = default;
|
||||
OclDevice() = delete;
|
||||
OclDevice(uint32_t index, cl_device_id id, cl_platform_id platform);
|
||||
|
||||
size_t freeMem() const;
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
|
||||
#include <memory.h>
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
#include "base/tools/String.h"
|
||||
|
@ -41,7 +41,7 @@ namespace xmrig {
|
|||
class JobResult
|
||||
{
|
||||
public:
|
||||
inline JobResult() {}
|
||||
JobResult() = delete;
|
||||
|
||||
inline JobResult(const Job &job, uint32_t nonce, const uint8_t *result) :
|
||||
algorithm(job.algorithm()),
|
||||
|
@ -66,7 +66,7 @@ public:
|
|||
const uint8_t index = 0;
|
||||
|
||||
private:
|
||||
uint8_t m_result[32];
|
||||
uint8_t m_result[32] = { 0 };
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue