From aa294ff066591b4eb9a52d0170a57b5b08fba01d Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 28 Aug 2019 02:05:19 +0700 Subject: [PATCH] Initial stub for setting job in OpenCL backend. --- src/backend/cpu/CpuWorker.cpp | 4 ++++ src/backend/opencl/OclWorker.cpp | 5 ++++ src/backend/opencl/interfaces/IOclRunner.h | 21 +++++++++------- src/backend/opencl/runners/OclBaseRunner.cpp | 16 ++++++------- src/backend/opencl/runners/OclBaseRunner.h | 2 +- src/backend/opencl/runners/OclCnRunner.cpp | 25 +++++++++++++++++--- src/backend/opencl/runners/OclCnRunner.h | 3 ++- src/backend/opencl/runners/OclRxRunner.cpp | 6 +++++ src/backend/opencl/runners/OclRxRunner.h | 1 + src/backend/opencl/wrappers/OclLib.cpp | 7 +++++- 10 files changed, 67 insertions(+), 23 deletions(-) diff --git a/src/backend/cpu/CpuWorker.cpp b/src/backend/cpu/CpuWorker.cpp index 297bd84a4..5af01bb34 100644 --- a/src/backend/cpu/CpuWorker.cpp +++ b/src/backend/cpu/CpuWorker.cpp @@ -297,6 +297,10 @@ void xmrig::CpuWorker::allocateCnCtx() template void xmrig::CpuWorker::consumeJob() { + if (Nonce::sequence(Nonce::CPU) == 0) { + return; + } + m_job.add(m_miner->job(), Nonce::sequence(Nonce::CPU), kReserveCount); # ifdef XMRIG_ALGO_RANDOMX diff --git a/src/backend/opencl/OclWorker.cpp b/src/backend/opencl/OclWorker.cpp index 0ed558c46..4bc2654ab 100644 --- a/src/backend/opencl/OclWorker.cpp +++ b/src/backend/opencl/OclWorker.cpp @@ -130,5 +130,10 @@ void xmrig::OclWorker::start() void xmrig::OclWorker::consumeJob() { + if (Nonce::sequence(Nonce::OPENCL) == 0) { + return; + } + m_job.add(m_miner->job(), Nonce::sequence(Nonce::OPENCL), kReserveCount); + m_runner->set(m_job.currentJob(), m_job.blob()); } diff --git a/src/backend/opencl/interfaces/IOclRunner.h b/src/backend/opencl/interfaces/IOclRunner.h index f122fd7d7..6c828c534 100644 --- a/src/backend/opencl/interfaces/IOclRunner.h +++ b/src/backend/opencl/interfaces/IOclRunner.h @@ -41,15 +41,18 @@ class IOclRunner public: virtual ~IOclRunner() = default; - virtual bool selfTest() const = 0; - virtual const char *buildOptions() const = 0; - virtual const char *deviceKey() const = 0; - virtual const char *source() const = 0; - virtual const OclLaunchData &data() const = 0; - virtual size_t threadId() const = 0; - virtual void build() = 0; - virtual void run(uint32_t *hashOutput) = 0; - virtual void set(const Job &job) = 0; + virtual bool selfTest() const = 0; + virtual bool set(const Job &job, uint8_t *blob) = 0; + virtual const char *buildOptions() const = 0; + virtual const char *deviceKey() const = 0; + virtual const char *source() const = 0; + virtual const OclLaunchData &data() const = 0; + virtual size_t threadId() const = 0; + virtual void build() = 0; + virtual void run(uint32_t *hashOutput) = 0; + +protected: + virtual bool isReadyToBuild() const = 0; }; diff --git a/src/backend/opencl/runners/OclBaseRunner.cpp b/src/backend/opencl/runners/OclBaseRunner.cpp index e2ceed831..4cae74981 100644 --- a/src/backend/opencl/runners/OclBaseRunner.cpp +++ b/src/backend/opencl/runners/OclBaseRunner.cpp @@ -73,15 +73,21 @@ xmrig::OclBaseRunner::~OclBaseRunner() } -bool xmrig::OclBaseRunner::selfTest() const +bool xmrig::OclBaseRunner::isReadyToBuild() const { return m_queue != nullptr && m_input != nullptr && m_output != nullptr && !m_options.empty() && m_source != nullptr; } +bool xmrig::OclBaseRunner::selfTest() const +{ + return isReadyToBuild() && m_program != nullptr; +} + + void xmrig::OclBaseRunner::build() { - if (!selfTest()) { + if (!isReadyToBuild()) { return; } @@ -93,9 +99,3 @@ void xmrig::OclBaseRunner::run(uint32_t *hashOutput) { } - - -void xmrig::OclBaseRunner::set(const Job &job) -{ - -} diff --git a/src/backend/opencl/runners/OclBaseRunner.h b/src/backend/opencl/runners/OclBaseRunner.h index 742a34645..782620c50 100644 --- a/src/backend/opencl/runners/OclBaseRunner.h +++ b/src/backend/opencl/runners/OclBaseRunner.h @@ -53,10 +53,10 @@ protected: inline const OclLaunchData &data() const override { return m_data; } inline size_t threadId() const override { return m_threadId; } + bool isReadyToBuild() const override; bool selfTest() const override; void build() override; void run(uint32_t *hashOutput) override; - void set(const Job &job) override; protected: Algorithm m_algorithm; diff --git a/src/backend/opencl/runners/OclCnRunner.cpp b/src/backend/opencl/runners/OclCnRunner.cpp index e8ba9f273..e62cdd17a 100644 --- a/src/backend/opencl/runners/OclCnRunner.cpp +++ b/src/backend/opencl/runners/OclCnRunner.cpp @@ -23,9 +23,11 @@ */ +#include "backend/opencl/OclLaunchData.h" #include "backend/opencl/runners/OclCnRunner.h" #include "backend/opencl/wrappers/OclLib.h" -#include "backend/opencl/OclLaunchData.h" +#include "base/io/log/Log.h" +#include "base/net/stratum/Job.h" #include "crypto/cn/CnAlgo.h" @@ -87,9 +89,9 @@ xmrig::OclCnRunner::~OclCnRunner() } -bool xmrig::OclCnRunner::selfTest() const +bool xmrig::OclCnRunner::isReadyToBuild() const { - return OclBaseRunner::selfTest() && + return OclBaseRunner::isReadyToBuild() && m_scratchpads != nullptr && m_states != nullptr && m_blake256 != nullptr && @@ -97,3 +99,20 @@ bool xmrig::OclCnRunner::selfTest() const m_jh256 != nullptr && m_skein512 != nullptr; } + + +bool xmrig::OclCnRunner::set(const Job &job, uint8_t *blob) +{ + if (job.size() > (Job::kMaxBlobSize - 4)) { + return false; + } + + blob[job.size()] = 0x01; + memset(blob + job.size() + 1, 0, Job::kMaxBlobSize - job.size() - 1); + + if (OclLib::enqueueWriteBuffer(m_queue, m_input, CL_TRUE, 0, Job::kMaxBlobSize, blob, 0, nullptr, nullptr) != CL_SUCCESS) { + return false; + } + + return false; +} diff --git a/src/backend/opencl/runners/OclCnRunner.h b/src/backend/opencl/runners/OclCnRunner.h index 31f22c89e..ac3691e3c 100644 --- a/src/backend/opencl/runners/OclCnRunner.h +++ b/src/backend/opencl/runners/OclCnRunner.h @@ -39,7 +39,8 @@ public: ~OclCnRunner() override; protected: - bool selfTest() const override; + bool isReadyToBuild() const override; + bool set(const Job &job, uint8_t *blob) override; private: cl_mem m_blake256 = nullptr; diff --git a/src/backend/opencl/runners/OclRxRunner.cpp b/src/backend/opencl/runners/OclRxRunner.cpp index 6378defeb..803dea848 100644 --- a/src/backend/opencl/runners/OclRxRunner.cpp +++ b/src/backend/opencl/runners/OclRxRunner.cpp @@ -34,3 +34,9 @@ bool xmrig::OclRxRunner::selfTest() const { return false; // TODO } + + +bool xmrig::OclRxRunner::set(const Job &job, uint8_t *blob) +{ + return false; +} diff --git a/src/backend/opencl/runners/OclRxRunner.h b/src/backend/opencl/runners/OclRxRunner.h index 096935556..54848c1c0 100644 --- a/src/backend/opencl/runners/OclRxRunner.h +++ b/src/backend/opencl/runners/OclRxRunner.h @@ -39,6 +39,7 @@ public: protected: bool selfTest() const override; + bool set(const Job &job, uint8_t *blob) override; }; diff --git a/src/backend/opencl/wrappers/OclLib.cpp b/src/backend/opencl/wrappers/OclLib.cpp index b0da3f647..d536db74a 100644 --- a/src/backend/opencl/wrappers/OclLib.cpp +++ b/src/backend/opencl/wrappers/OclLib.cpp @@ -295,7 +295,12 @@ cl_int xmrig::OclLib::enqueueWriteBuffer(cl_command_queue command_queue, cl_mem { assert(pEnqueueWriteBuffer != nullptr); - return pEnqueueWriteBuffer(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event); + const cl_int ret = pEnqueueWriteBuffer(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event); + if (ret != CL_SUCCESS) { + LOG_ERR(kErrorTemplate, OclError::toString(ret), kEnqueueWriteBuffer); + } + + return ret; }