From 4a13a8a75cf8c3ef63db9c37441da3c6203eaa82 Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Wed, 18 Dec 2024 13:18:11 +0100 Subject: [PATCH] CUDA backend: update RandomX dataset when it changes --- src/backend/cuda/runners/CudaRxRunner.cpp | 9 +++++++++ src/backend/cuda/runners/CudaRxRunner.h | 2 ++ src/backend/cuda/wrappers/CudaLib.cpp | 10 ++++++++++ src/backend/cuda/wrappers/CudaLib.h | 1 + 4 files changed, 22 insertions(+) diff --git a/src/backend/cuda/runners/CudaRxRunner.cpp b/src/backend/cuda/runners/CudaRxRunner.cpp index dd64e8654..c02fc0e9b 100644 --- a/src/backend/cuda/runners/CudaRxRunner.cpp +++ b/src/backend/cuda/runners/CudaRxRunner.cpp @@ -55,6 +55,15 @@ bool xmrig::CudaRxRunner::run(uint32_t startNonce, uint32_t *rescount, uint32_t bool xmrig::CudaRxRunner::set(const Job &job, uint8_t *blob) { + if (!m_datasetHost && (m_seed != job.seed())) { + m_seed = job.seed(); + + if (m_ready) { + auto dataset = Rx::dataset(job, 0); + callWrapper(CudaLib::rxUpdateDataset(m_ctx, dataset->raw(), dataset->size(false))); + } + } + const bool rc = CudaBaseRunner::set(job, blob); if (!rc || m_ready) { return rc; diff --git a/src/backend/cuda/runners/CudaRxRunner.h b/src/backend/cuda/runners/CudaRxRunner.h index 448400bc3..c8a923dfb 100644 --- a/src/backend/cuda/runners/CudaRxRunner.h +++ b/src/backend/cuda/runners/CudaRxRunner.h @@ -27,6 +27,7 @@ #include "backend/cuda/runners/CudaBaseRunner.h" +#include "base/tools/Buffer.h" namespace xmrig { @@ -46,6 +47,7 @@ protected: private: bool m_ready = false; const bool m_datasetHost = false; + Buffer m_seed; size_t m_intensity = 0; }; diff --git a/src/backend/cuda/wrappers/CudaLib.cpp b/src/backend/cuda/wrappers/CudaLib.cpp index 8ca11fa5b..ef028323c 100644 --- a/src/backend/cuda/wrappers/CudaLib.cpp +++ b/src/backend/cuda/wrappers/CudaLib.cpp @@ -68,6 +68,7 @@ static const char *kPluginVersion = "pluginVersion"; static const char *kRelease = "release"; static const char *kRxHash = "rxHash"; static const char *kRxPrepare = "rxPrepare"; +static const char *kRxUpdateDataset = "rxUpdateDataset"; static const char *kSetJob = "setJob"; static const char *kSetJob_v2 = "setJob_v2"; static const char *kVersion = "version"; @@ -92,6 +93,7 @@ using pluginVersion_t = const char * (*)(); using release_t = void (*)(nvid_ctx *); using rxHash_t = bool (*)(nvid_ctx *, uint32_t, uint64_t, uint32_t *, uint32_t *); using rxPrepare_t = bool (*)(nvid_ctx *, const void *, size_t, bool, uint32_t); +using rxUpdateDataset_t = bool (*)(nvid_ctx *, const void *, size_t); using setJob_t = bool (*)(nvid_ctx *, const void *, size_t, uint32_t); using setJob_v2_t = bool (*)(nvid_ctx *, const void *, size_t, const char *); using version_t = uint32_t (*)(Version); @@ -116,6 +118,7 @@ static pluginVersion_t pPluginVersion = nullptr; static release_t pRelease = nullptr; static rxHash_t pRxHash = nullptr; static rxPrepare_t pRxPrepare = nullptr; +static rxUpdateDataset_t pRxUpdateDataset = nullptr; static setJob_t pSetJob = nullptr; static setJob_v2_t pSetJob_v2 = nullptr; static version_t pVersion = nullptr; @@ -206,6 +209,12 @@ bool xmrig::CudaLib::rxPrepare(nvid_ctx *ctx, const void *dataset, size_t datase } +bool xmrig::CudaLib::rxUpdateDataset(nvid_ctx* ctx, const void* dataset, size_t datasetSize) noexcept +{ + return pRxUpdateDataset(ctx, dataset, datasetSize); +} + + bool xmrig::CudaLib::kawPowHash(nvid_ctx *ctx, uint8_t* job_blob, uint64_t target, uint32_t *rescount, uint32_t *resnonce, uint32_t *skipped_hashes) noexcept { return pKawPowHash(ctx, job_blob, target, rescount, resnonce, skipped_hashes); @@ -388,6 +397,7 @@ void xmrig::CudaLib::load() DLSYM(Release); DLSYM(RxHash); DLSYM(RxPrepare); + DLSYM(RxUpdateDataset); DLSYM(KawPowHash); DLSYM(KawPowPrepare_v2); DLSYM(KawPowStopHash); diff --git a/src/backend/cuda/wrappers/CudaLib.h b/src/backend/cuda/wrappers/CudaLib.h index cf1a538b3..e92ac11c1 100644 --- a/src/backend/cuda/wrappers/CudaLib.h +++ b/src/backend/cuda/wrappers/CudaLib.h @@ -71,6 +71,7 @@ public: static bool deviceInit(nvid_ctx *ctx) noexcept; static bool rxHash(nvid_ctx *ctx, uint32_t startNonce, uint64_t target, uint32_t *rescount, uint32_t *resnonce) noexcept; static bool rxPrepare(nvid_ctx *ctx, const void *dataset, size_t datasetSize, bool dataset_host, uint32_t batchSize) noexcept; + static bool rxUpdateDataset(nvid_ctx* ctx, const void* dataset, size_t datasetSize) noexcept; static bool kawPowHash(nvid_ctx *ctx, uint8_t* job_blob, uint64_t target, uint32_t *rescount, uint32_t *resnonce, uint32_t *skipped_hashes) noexcept; static bool kawPowPrepare(nvid_ctx *ctx, const void* cache, size_t cache_size, const void* dag_precalc, size_t dag_size, uint32_t height, const uint64_t* dag_sizes) noexcept; static bool kawPowStopHash(nvid_ctx *ctx) noexcept;