Implemented VM mode for OpenCL RandomX.
This commit is contained in:
parent
4c90f9960e
commit
95daab4bc0
42 changed files with 450 additions and 165 deletions
|
@ -131,7 +131,7 @@ public:
|
|||
|
||||
inline bool isNUMA() const { return m_numa; }
|
||||
inline const Algorithm &algorithm() const { return m_algorithm; }
|
||||
inline const uint8_t *seed() const { return m_seed; }
|
||||
inline const Buffer &seed() const { return m_seed; }
|
||||
inline size_t count() const { return isNUMA() ? datasets.size() : 1; }
|
||||
inline void asyncSend() { m_ready++; if (m_ready == count()) { uv_async_send(m_async); } }
|
||||
|
||||
|
@ -221,14 +221,13 @@ public:
|
|||
m_numa = numa && Cpu::info()->nodes() > 1;
|
||||
m_hugePages = hugePages;
|
||||
m_listener = listener;
|
||||
|
||||
memcpy(m_seed, job.seedHash(), sizeof(m_seed));
|
||||
m_seed = job.seed();
|
||||
}
|
||||
|
||||
|
||||
inline bool isReady(const Job &job)
|
||||
{
|
||||
return m_ready == count() && m_algorithm == job.algorithm() && memcmp(m_seed, job.seedHash(), sizeof(m_seed)) == 0;
|
||||
return m_ready == count() && m_algorithm == job.algorithm() && m_seed == job.seed();
|
||||
}
|
||||
|
||||
|
||||
|
@ -245,9 +244,9 @@ private:
|
|||
Algorithm m_algorithm;
|
||||
bool m_hugePages = true;
|
||||
bool m_numa = true;
|
||||
Buffer m_seed;
|
||||
IRxListener *m_listener = nullptr;
|
||||
size_t m_ready = 0;
|
||||
uint8_t m_seed[32]{ 0 };
|
||||
uv_async_t *m_async;
|
||||
};
|
||||
|
||||
|
@ -269,7 +268,7 @@ bool xmrig::Rx::init(const Job &job, int initThreads, bool hugePages, bool numa,
|
|||
|
||||
d_ptr->setState(job, hugePages, numa, listener);
|
||||
const uint32_t threads = initThreads < 1 ? static_cast<uint32_t>(Cpu::info()->threads()) : static_cast<uint32_t>(initThreads);
|
||||
const String buf = Buffer::toHex(job.seedHash(), 8);
|
||||
const String buf = Buffer::toHex(job.seed().data(), 8);
|
||||
|
||||
LOG_INFO("%s" MAGENTA_BOLD("init dataset%s") " algo " WHITE_BOLD("%s (") CYAN_BOLD("%u") WHITE_BOLD(" threads)") BLACK_BOLD(" seed %s..."),
|
||||
tag,
|
||||
|
|
|
@ -55,6 +55,46 @@ uint32_t xmrig::RxAlgo::version(Algorithm::Id algorithm)
|
|||
}
|
||||
|
||||
|
||||
uint32_t xmrig::RxAlgo::programCount(Algorithm::Id algorithm)
|
||||
{
|
||||
switch (algorithm) {
|
||||
case Algorithm::RX_0:
|
||||
return RandomX_MoneroConfig.ProgramCount;
|
||||
|
||||
case Algorithm::RX_WOW:
|
||||
return RandomX_WowneroConfig.ProgramCount;
|
||||
|
||||
case Algorithm::RX_LOKI:
|
||||
return RandomX_LokiConfig.ProgramCount;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
uint32_t xmrig::RxAlgo::programIterations(Algorithm::Id algorithm)
|
||||
{
|
||||
switch (algorithm) {
|
||||
case Algorithm::RX_0:
|
||||
return RandomX_MoneroConfig.ProgramIterations;
|
||||
|
||||
case Algorithm::RX_WOW:
|
||||
return RandomX_WowneroConfig.ProgramIterations;
|
||||
|
||||
case Algorithm::RX_LOKI:
|
||||
return RandomX_LokiConfig.ProgramIterations;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
uint32_t xmrig::RxAlgo::programSize(Algorithm::Id algorithm)
|
||||
{
|
||||
switch (algorithm) {
|
||||
|
|
|
@ -43,6 +43,8 @@ class RxAlgo
|
|||
{
|
||||
public:
|
||||
static Algorithm::Id apply(Algorithm::Id algorithm);
|
||||
static uint32_t programCount(Algorithm::Id algorithm);
|
||||
static uint32_t programIterations(Algorithm::Id algorithm);
|
||||
static uint32_t programSize(Algorithm::Id algorithm);
|
||||
static uint32_t version(Algorithm::Id algorithm);
|
||||
};
|
||||
|
|
|
@ -34,8 +34,7 @@ static_assert(RANDOMX_FLAG_LARGE_PAGES == 1, "RANDOMX_FLAG_LARGE_PAGES flag mism
|
|||
|
||||
|
||||
|
||||
xmrig::RxCache::RxCache(bool hugePages) :
|
||||
m_seed()
|
||||
xmrig::RxCache::RxCache(bool hugePages)
|
||||
{
|
||||
if (hugePages) {
|
||||
m_flags = RANDOMX_FLAG_JIT | RANDOMX_FLAG_LARGE_PAGES;
|
||||
|
@ -62,14 +61,14 @@ xmrig::RxCache::~RxCache()
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::RxCache::init(const uint8_t *seed)
|
||||
bool xmrig::RxCache::init(const Buffer &seed)
|
||||
{
|
||||
if (isReady(seed)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(m_seed, seed, sizeof(m_seed));
|
||||
randomx_init_cache(m_cache, m_seed, sizeof(m_seed));
|
||||
m_seed = seed;
|
||||
randomx_init_cache(m_cache, m_seed.data(), sizeof(m_seed));
|
||||
|
||||
m_initCount++;
|
||||
|
||||
|
@ -77,7 +76,7 @@ bool xmrig::RxCache::init(const uint8_t *seed)
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::RxCache::isReady(const uint8_t *seed) const
|
||||
bool xmrig::RxCache::isReady(const Buffer &seed) const
|
||||
{
|
||||
return m_initCount && memcmp(m_seed, seed, sizeof(m_seed)) == 0;
|
||||
return !m_seed.isEmpty() && m_seed == seed;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include <cstdint>
|
||||
|
||||
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/Object.h"
|
||||
#include "crypto/randomx/configuration.h"
|
||||
|
||||
|
||||
|
@ -44,26 +46,28 @@ namespace xmrig
|
|||
class RxCache
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(RxCache)
|
||||
|
||||
RxCache(bool hugePages = true);
|
||||
~RxCache();
|
||||
|
||||
inline bool isHugePages() const { return m_flags & 1; }
|
||||
inline bool isJIT() const { return m_flags & 8; }
|
||||
inline const uint8_t *seed() const { return m_seed; }
|
||||
inline const Buffer &seed() const { return m_seed; }
|
||||
inline randomx_cache *get() const { return m_cache; }
|
||||
inline uint64_t initCount() const { return m_initCount; }
|
||||
|
||||
bool init(const uint8_t *seed);
|
||||
bool init(const Buffer &seed);
|
||||
|
||||
static inline constexpr size_t maxSize() { return RANDOMX_CACHE_MAX_SIZE; }
|
||||
|
||||
private:
|
||||
bool isReady(const uint8_t *seed) const;
|
||||
bool isReady(const Buffer &seed) const;
|
||||
|
||||
Buffer m_seed;
|
||||
int m_flags = 0;
|
||||
randomx_cache *m_cache = nullptr;
|
||||
uint64_t m_initCount = 0;
|
||||
uint8_t m_seed[32];
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ xmrig::RxDataset::~RxDataset()
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::RxDataset::init(const uint8_t *seed, uint32_t numThreads)
|
||||
bool xmrig::RxDataset::init(const Buffer &seed, uint32_t numThreads)
|
||||
{
|
||||
cache()->init(seed);
|
||||
|
||||
|
@ -112,3 +112,9 @@ std::pair<size_t, size_t> xmrig::RxDataset::hugePages() const
|
|||
|
||||
return { count, total };
|
||||
}
|
||||
|
||||
|
||||
void *xmrig::RxDataset::raw() const
|
||||
{
|
||||
return m_dataset ? randomx_get_dataset_memory(m_dataset) : nullptr;
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ namespace xmrig
|
|||
{
|
||||
|
||||
|
||||
class Buffer;
|
||||
class RxCache;
|
||||
|
||||
|
||||
|
@ -54,9 +55,11 @@ public:
|
|||
inline bool isHugePages() const { return m_flags & 1; }
|
||||
inline randomx_dataset *get() const { return m_dataset; }
|
||||
inline RxCache *cache() const { return m_cache; }
|
||||
inline size_t size() const { return maxSize(); }
|
||||
|
||||
bool init(const uint8_t *seed, uint32_t numThreads);
|
||||
bool init(const Buffer &seed, uint32_t numThreads);
|
||||
std::pair<size_t, size_t> hugePages() const;
|
||||
void *raw() const;
|
||||
|
||||
static inline constexpr size_t maxSize() { return RANDOMX_DATASET_MAX_SIZE; }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue