OpenCL RandomX WIP

This commit is contained in:
XMRig 2019-09-11 15:48:02 +07:00
parent ff89ec660c
commit 4c90f9960e
72 changed files with 1717 additions and 505 deletions

View file

@ -25,17 +25,7 @@
*/
#include <map>
#include <mutex>
#include <thread>
#include <uv.h>
#ifdef XMRIG_FEATURE_HWLOC
# include <hwloc.h>
# include "backend/cpu/platform/HwlocCpuInfo.h"
#endif
#include "crypto/rx/Rx.h"
#include "backend/common/interfaces/IRxListener.h"
#include "backend/cpu/Cpu.h"
@ -45,12 +35,24 @@
#include "base/tools/Buffer.h"
#include "base/tools/Chrono.h"
#include "base/tools/Handle.h"
#include "crypto/rx/Rx.h"
#include "base/tools/Object.h"
#include "crypto/rx/RxAlgo.h"
#include "crypto/rx/RxCache.h"
#include "crypto/rx/RxDataset.h"
#ifdef XMRIG_FEATURE_HWLOC
# include <hwloc.h>
# include "backend/cpu/platform/HwlocCpuInfo.h"
#endif
#include <map>
#include <mutex>
#include <thread>
#include <uv.h>
namespace xmrig {
@ -92,8 +94,9 @@ inline static void bindToNUMANode(uint32_t) {}
class RxPrivate
{
public:
inline RxPrivate() :
m_seed()
XMRIG_DISABLE_COPY_MOVE(RxPrivate)
inline RxPrivate()
{
m_async = new uv_async_t;
m_async->data = this;
@ -144,12 +147,12 @@ public:
LOG_INFO("%s" CYAN_BOLD("#%u") MAGENTA_BOLD(" allocate") CYAN_BOLD(" %zu MB") BLACK_BOLD(" (%zu+%zu) for RandomX dataset & cache"),
tag,
nodeId,
(RxDataset::size() + RxCache::size()) / 1024 / 1024,
RxDataset::size() / 1024 / 1024,
RxCache::size() / 1024 / 1024
(RxDataset::maxSize() + RxCache::maxSize()) / 1024 / 1024,
RxDataset::maxSize() / 1024 / 1024,
RxCache::maxSize() / 1024 / 1024
);
RxDataset *dataset = new RxDataset(d_ptr->m_hugePages);
auto dataset = new RxDataset(d_ptr->m_hugePages);
d_ptr->datasets[nodeId] = dataset;
if (dataset->get() != nullptr) {
@ -244,7 +247,7 @@ private:
bool m_numa = true;
IRxListener *m_listener = nullptr;
size_t m_ready = 0;
uint8_t m_seed[32];
uint8_t m_seed[32]{ 0 };
uv_async_t *m_async;
};

View file

@ -28,7 +28,7 @@
#define XMRIG_RX_H
#include <stdint.h>
#include <cstdint>
#include <utility>

View file

@ -47,3 +47,29 @@ xmrig::Algorithm::Id xmrig::RxAlgo::apply(Algorithm::Id algorithm)
return algorithm;
}
uint32_t xmrig::RxAlgo::version(Algorithm::Id algorithm)
{
return algorithm == Algorithm::RX_WOW ? 103 : 104;
}
uint32_t xmrig::RxAlgo::programSize(Algorithm::Id algorithm)
{
switch (algorithm) {
case Algorithm::RX_0:
return RandomX_MoneroConfig.ProgramSize;
case Algorithm::RX_WOW:
return RandomX_WowneroConfig.ProgramSize;
case Algorithm::RX_LOKI:
return RandomX_LokiConfig.ProgramSize;
default:
break;
}
return 0;
}

View file

@ -28,8 +28,8 @@
#define XMRIG_RX_ALGO_H
#include <stddef.h>
#include <stdint.h>
#include <cstddef>
#include <cstdint>
#include "crypto/common/Algorithm.h"
@ -43,6 +43,8 @@ class RxAlgo
{
public:
static Algorithm::Id apply(Algorithm::Id algorithm);
static uint32_t programSize(Algorithm::Id algorithm);
static uint32_t version(Algorithm::Id algorithm);
};

View file

@ -28,7 +28,7 @@
#define XMRIG_RX_CACHE_H
#include <stdint.h>
#include <cstdint>
#include "crypto/randomx/configuration.h"
@ -55,7 +55,7 @@ public:
bool init(const uint8_t *seed);
static inline constexpr size_t size() { return RANDOMX_CACHE_MAX_SIZE; }
static inline constexpr size_t maxSize() { return RANDOMX_CACHE_MAX_SIZE; }
private:
bool isReady(const uint8_t *seed) const;

View file

@ -99,16 +99,16 @@ bool xmrig::RxDataset::init(const uint8_t *seed, uint32_t numThreads)
std::pair<size_t, size_t> xmrig::RxDataset::hugePages() const
{
constexpr size_t twoMiB = 2u * 1024u * 1024u;
constexpr const size_t total = (VirtualMemory::align(size(), twoMiB) + VirtualMemory::align(RxCache::size(), twoMiB)) / twoMiB;
constexpr const size_t total = (VirtualMemory::align(maxSize(), twoMiB) + VirtualMemory::align(RxCache::maxSize(), twoMiB)) / twoMiB;
size_t count = 0;
if (isHugePages()) {
count += VirtualMemory::align(size(), twoMiB) / twoMiB;
count += VirtualMemory::align(maxSize(), twoMiB) / twoMiB;
}
if (m_cache->isHugePages()) {
count += VirtualMemory::align(RxCache::size(), twoMiB) / twoMiB;
count += VirtualMemory::align(RxCache::maxSize(), twoMiB) / twoMiB;
}
return std::pair<size_t, size_t>(count, total);
return { count, total };
}

View file

@ -30,6 +30,7 @@
#include "crypto/common/Algorithm.h"
#include "crypto/randomx/configuration.h"
#include "base/tools/Object.h"
struct randomx_dataset;
@ -45,6 +46,8 @@ class RxCache;
class RxDataset
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(RxDataset)
RxDataset(bool hugePages = true);
~RxDataset();
@ -55,7 +58,7 @@ public:
bool init(const uint8_t *seed, uint32_t numThreads);
std::pair<size_t, size_t> hugePages() const;
static inline constexpr size_t size() { return RANDOMX_DATASET_MAX_SIZE; }
static inline constexpr size_t maxSize() { return RANDOMX_DATASET_MAX_SIZE; }
private:
Algorithm m_algorithm;