From c9f7cbae09744278e03c909e51afbd06c93046f9 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 27 Oct 2019 17:53:00 +0700 Subject: [PATCH] Implemented cryptonight mining. --- src/backend/cuda/CudaLaunchData.cpp | 5 +- src/backend/cuda/CudaWorker.cpp | 60 +++++++++------- src/backend/cuda/CudaWorker.h | 4 ++ src/backend/cuda/cuda.cmake | 7 ++ src/backend/cuda/interfaces/ICudaRunner.h | 71 ++++++++++++++++++ src/backend/cuda/runners/CudaBaseRunner.cpp | 76 ++++++++++++++++++++ src/backend/cuda/runners/CudaBaseRunner.h | 66 +++++++++++++++++ src/backend/cuda/runners/CudaCnRunner.cpp | 38 ++++++++++ src/backend/cuda/runners/CudaCnRunner.h | 48 +++++++++++++ src/backend/cuda/runners/CudaRxRunner.cpp | 42 +++++++++++ src/backend/cuda/runners/CudaRxRunner.h | 53 ++++++++++++++ src/backend/cuda/wrappers/CudaLib.cpp | 36 ++++++++++ src/backend/cuda/wrappers/CudaLib.h | 3 + src/backend/opencl/runners/OclBaseRunner.cpp | 2 +- src/backend/opencl/runners/OclBaseRunner.h | 4 +- 15 files changed, 486 insertions(+), 29 deletions(-) create mode 100644 src/backend/cuda/interfaces/ICudaRunner.h create mode 100644 src/backend/cuda/runners/CudaBaseRunner.cpp create mode 100644 src/backend/cuda/runners/CudaBaseRunner.h create mode 100644 src/backend/cuda/runners/CudaCnRunner.cpp create mode 100644 src/backend/cuda/runners/CudaCnRunner.h create mode 100644 src/backend/cuda/runners/CudaRxRunner.cpp create mode 100644 src/backend/cuda/runners/CudaRxRunner.h diff --git a/src/backend/cuda/CudaLaunchData.cpp b/src/backend/cuda/CudaLaunchData.cpp index b19c42e72..11cf70c89 100644 --- a/src/backend/cuda/CudaLaunchData.cpp +++ b/src/backend/cuda/CudaLaunchData.cpp @@ -39,8 +39,9 @@ xmrig::CudaLaunchData::CudaLaunchData(const Miner *miner, const Algorithm &algor bool xmrig::CudaLaunchData::isEqual(const CudaLaunchData &other) const { - return (other.algorithm == algorithm && - other.thread == thread); + return (other.algorithm.family() == algorithm.family() && + other.algorithm.l3() == algorithm.l3() && + other.thread == thread); } diff --git a/src/backend/cuda/CudaWorker.cpp b/src/backend/cuda/CudaWorker.cpp index 98765fb33..1f2625742 100644 --- a/src/backend/cuda/CudaWorker.cpp +++ b/src/backend/cuda/CudaWorker.cpp @@ -26,6 +26,7 @@ #include "backend/cuda/CudaWorker.h" #include "backend/common/Tags.h" +#include "backend/cuda/runners/CudaCnRunner.h" #include "base/io/log/Log.h" #include "base/tools/Chrono.h" #include "core/Miner.h" @@ -33,6 +34,11 @@ #include "net/JobResults.h" +#ifdef XMRIG_ALGO_RANDOMX +# include "backend/cuda/runners/CudaRxRunner.h" +#endif + + #include #include @@ -64,25 +70,42 @@ xmrig::CudaWorker::CudaWorker(size_t id, const CudaLaunchData &data) : m_miner(data.miner), m_intensity(data.thread.threads() * data.thread.blocks()) { + switch (m_algorithm.family()) { + case Algorithm::RANDOM_X: +# ifdef XMRIG_ALGO_RANDOMX + m_runner = new CudaRxRunner(id, data); +# endif + break; + + case Algorithm::ARGON2: + break; + + default: + m_runner = new CudaCnRunner(id, data); + break; + } + + if (!m_runner || !m_runner->init()) { + return; + } } xmrig::CudaWorker::~CudaWorker() { -// delete m_runner; + delete m_runner; } bool xmrig::CudaWorker::selfTest() { - return false; // FIXME + return m_runner != nullptr; } size_t xmrig::CudaWorker::intensity() const { - return 0; // FIXME; -// return m_runner ? m_runner->intensity() : 0; + return m_runner ? m_runner->intensity() : 0; } @@ -105,18 +128,16 @@ void xmrig::CudaWorker::start() } while (!Nonce::isOutdated(Nonce::CUDA, m_job.sequence())) { -// try { -// m_runner->run(*m_job.nonce(), results); -// } -// catch (std::exception &ex) { -// printError(id(), ex.what()); + uint32_t foundNonce[10] = { 0 }; + uint32_t foundCount = 0; -// return; -// } + if (!m_runner->run(*m_job.nonce(), &foundCount, foundNonce)) { + return; + } -// if (results[0xFF] > 0) { -// JobResults::submit(m_job.currentJob(), results, results[0xFF]); -// } + if (foundCount) { + JobResults::submit(m_job.currentJob(), foundNonce, foundCount); + } m_job.nextRound(roundSize(m_intensity), m_intensity); @@ -139,16 +160,7 @@ bool xmrig::CudaWorker::consumeJob() m_job.add(m_miner->job(), Nonce::sequence(Nonce::CUDA), roundSize(m_intensity) * m_intensity); -// try { -// m_runner->set(m_job.currentJob(), m_job.blob()); -// } -// catch (std::exception &ex) { -// printError(id(), ex.what()); - -// return false; -// } - - return true; + return m_runner->set(m_job.currentJob(), m_job.blob());; } diff --git a/src/backend/cuda/CudaWorker.h b/src/backend/cuda/CudaWorker.h index 0ba71e860..4fb006ba9 100644 --- a/src/backend/cuda/CudaWorker.h +++ b/src/backend/cuda/CudaWorker.h @@ -37,6 +37,9 @@ namespace xmrig { +class ICudaRunner; + + class CudaWorker : public Worker { public: @@ -60,6 +63,7 @@ private: const Algorithm m_algorithm; const Miner *m_miner; const uint32_t m_intensity; + ICudaRunner *m_runner = nullptr; WorkerJob<1> m_job; }; diff --git a/src/backend/cuda/cuda.cmake b/src/backend/cuda/cuda.cmake index 93348964b..764acd0f0 100644 --- a/src/backend/cuda/cuda.cmake +++ b/src/backend/cuda/cuda.cmake @@ -9,6 +9,10 @@ if (WITH_CUDA) src/backend/cuda/CudaThread.h src/backend/cuda/CudaThreads.h src/backend/cuda/CudaWorker.h + src/backend/cuda/interfaces/ICudaRunner.h + src/backend/cuda/runners/CudaBaseRunner.h + src/backend/cuda/runners/CudaCnRunner.h + src/backend/cuda/runners/CudaRxRunner.h src/backend/cuda/wrappers/CudaDevice.h src/backend/cuda/wrappers/CudaLib.h ) @@ -20,6 +24,9 @@ if (WITH_CUDA) src/backend/cuda/CudaThread.cpp src/backend/cuda/CudaThreads.cpp src/backend/cuda/CudaWorker.cpp + src/backend/cuda/runners/CudaBaseRunner.cpp + src/backend/cuda/runners/CudaCnRunner.cpp + src/backend/cuda/runners/CudaRxRunner.cpp src/backend/cuda/wrappers/CudaDevice.cpp src/backend/cuda/wrappers/CudaLib.cpp ) diff --git a/src/backend/cuda/interfaces/ICudaRunner.h b/src/backend/cuda/interfaces/ICudaRunner.h new file mode 100644 index 000000000..b5772c890 --- /dev/null +++ b/src/backend/cuda/interfaces/ICudaRunner.h @@ -0,0 +1,71 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_ICUDARUNNER_H +#define XMRIG_ICUDARUNNER_H + + +#include "base/tools/Object.h" + + +#include + + +namespace xmrig { + + +class Job; + + +class ICudaRunner +{ +public: + XMRIG_DISABLE_COPY_MOVE(ICudaRunner) + + ICudaRunner() = default; + virtual ~ICudaRunner() = default; + +// virtual cl_context ctx() const = 0; +// virtual const Algorithm &algorithm() 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 intensity() const = 0; +// virtual size_t threadId() const = 0; +// virtual uint32_t deviceIndex() const = 0; +// virtual void build() = 0; + virtual bool init() = 0; + virtual bool run(uint32_t startNonce, uint32_t *rescount, uint32_t *resnonce) = 0; + virtual bool set(const Job &job, uint8_t *blob) = 0; + +protected: +// virtual size_t bufferSize() const = 0; +}; + + +} /* namespace xmrig */ + + +#endif // XMRIG_ICUDARUNNER_H diff --git a/src/backend/cuda/runners/CudaBaseRunner.cpp b/src/backend/cuda/runners/CudaBaseRunner.cpp new file mode 100644 index 000000000..9428b16c4 --- /dev/null +++ b/src/backend/cuda/runners/CudaBaseRunner.cpp @@ -0,0 +1,76 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "backend/cuda/runners/CudaBaseRunner.h" +#include "backend/cuda/wrappers/CudaLib.h" +#include "backend/cuda/CudaLaunchData.h" +//#include "backend/opencl/cl/OclSource.h" +//#include "backend/opencl/OclCache.h" +//#include "backend/opencl/OclLaunchData.h" +//#include "backend/opencl/runners/tools/OclSharedState.h" +//#include "backend/opencl/wrappers/OclError.h" +//#include "backend/opencl/wrappers/OclLib.h" +#include "base/io/log/Log.h" +#include "base/net/stratum/Job.h" +//#include "crypto/common/VirtualMemory.h" + + +xmrig::CudaBaseRunner::CudaBaseRunner(size_t id, const CudaLaunchData &data) : + m_data(data), + m_threadId(id) +{ +} + + +xmrig::CudaBaseRunner::~CudaBaseRunner() +{ + CudaLib::release(m_ctx); +} + + +bool xmrig::CudaBaseRunner::init() +{ + m_ctx = CudaLib::alloc(m_data.thread.index(), m_data.thread.bfactor(), m_data.thread.bsleep()); + if (CudaLib::deviceInfo(m_ctx, m_data.thread.blocks(), m_data.thread.threads(), m_data.algorithm) != 0) { + return false; + } + + return CudaLib::deviceInit(m_ctx); +} + + +bool xmrig::CudaBaseRunner::set(const Job &job, uint8_t *blob) +{ + m_height = job.height(); + m_target = job.target(); + + return CudaLib::setJob(m_ctx, blob, job.size(), job.algorithm()); +} + + +size_t xmrig::CudaBaseRunner::intensity() const +{ + return m_data.thread.threads() * m_data.thread.blocks(); +} diff --git a/src/backend/cuda/runners/CudaBaseRunner.h b/src/backend/cuda/runners/CudaBaseRunner.h new file mode 100644 index 000000000..7bdc7bea7 --- /dev/null +++ b/src/backend/cuda/runners/CudaBaseRunner.h @@ -0,0 +1,66 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_CUDABASERUNNER_H +#define XMRIG_CUDABASERUNNER_H + + +#include "backend/cuda/interfaces/ICudaRunner.h" + + +using nvid_ctx = struct nvid_ctx; + + +namespace xmrig { + + +class CudaLaunchData; + + +class CudaBaseRunner : public ICudaRunner +{ +public: + XMRIG_DISABLE_COPY_MOVE_DEFAULT(CudaBaseRunner) + + CudaBaseRunner(size_t id, const CudaLaunchData &data); + ~CudaBaseRunner() override; + +protected: + bool init() override; + bool set(const Job &job, uint8_t *blob) override; + size_t intensity() const override; + +protected: + const CudaLaunchData &m_data; + const size_t m_threadId; + nvid_ctx *m_ctx = nullptr; + uint64_t m_height = 0; + uint64_t m_target = 0; +}; + + +} /* namespace xmrig */ + + +#endif // XMRIG_CUDABASERUNNER_H diff --git a/src/backend/cuda/runners/CudaCnRunner.cpp b/src/backend/cuda/runners/CudaCnRunner.cpp new file mode 100644 index 000000000..f75f09950 --- /dev/null +++ b/src/backend/cuda/runners/CudaCnRunner.cpp @@ -0,0 +1,38 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "backend/cuda/runners/CudaCnRunner.h" +#include "backend/cuda/wrappers/CudaLib.h" + + +xmrig::CudaCnRunner::CudaCnRunner(size_t index, const CudaLaunchData &data) : CudaBaseRunner(index, data) +{ +} + + +bool xmrig::CudaCnRunner::run(uint32_t startNonce, uint32_t *rescount, uint32_t *resnonce) +{ + return CudaLib::cnHash(m_ctx, startNonce, m_height, m_target, rescount, resnonce); +} diff --git a/src/backend/cuda/runners/CudaCnRunner.h b/src/backend/cuda/runners/CudaCnRunner.h new file mode 100644 index 000000000..e563435be --- /dev/null +++ b/src/backend/cuda/runners/CudaCnRunner.h @@ -0,0 +1,48 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_CUDACNRUNNER_H +#define XMRIG_CUDACNRUNNER_H + + +#include "backend/cuda/runners/CudaBaseRunner.h" + + +namespace xmrig { + + +class CudaCnRunner : public CudaBaseRunner +{ +public: + CudaCnRunner(size_t index, const CudaLaunchData &data); + +protected: + bool run(uint32_t startNonce, uint32_t *rescount, uint32_t *resnonce) override; +}; + + +} /* namespace xmrig */ + + +#endif // XMRIG_CUDACNRUNNER_H diff --git a/src/backend/cuda/runners/CudaRxRunner.cpp b/src/backend/cuda/runners/CudaRxRunner.cpp new file mode 100644 index 000000000..92b2d9f90 --- /dev/null +++ b/src/backend/cuda/runners/CudaRxRunner.cpp @@ -0,0 +1,42 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "backend/cuda/runners/CudaRxRunner.h" + + +xmrig::CudaRxRunner::CudaRxRunner(size_t index, const CudaLaunchData &data) : CudaBaseRunner(index, data) +{ +} + + +xmrig::CudaRxRunner::~CudaRxRunner() +{ +} + + +bool xmrig::CudaRxRunner::run(uint32_t startNonce, uint32_t *rescount, uint32_t *resnonce) +{ + return false; +} diff --git a/src/backend/cuda/runners/CudaRxRunner.h b/src/backend/cuda/runners/CudaRxRunner.h new file mode 100644 index 000000000..8aba75f54 --- /dev/null +++ b/src/backend/cuda/runners/CudaRxRunner.h @@ -0,0 +1,53 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_CUDARXRUNNER_H +#define XMRIG_CUDARXRUNNER_H + + +#include "backend/cuda/runners/CudaBaseRunner.h" + + +namespace xmrig { + + +class CudaRxRunner : public CudaBaseRunner +{ +public: + XMRIG_DISABLE_COPY_MOVE_DEFAULT(CudaRxRunner) + + CudaRxRunner(size_t index, const CudaLaunchData &data); + ~CudaRxRunner() override; + +protected: + bool run(uint32_t startNonce, uint32_t *rescount, uint32_t *resnonce) override; + +private: +}; + + +} /* namespace xmrig */ + + +#endif // XMRIG_CUDARXRUNNER_H diff --git a/src/backend/cuda/wrappers/CudaLib.cpp b/src/backend/cuda/wrappers/CudaLib.cpp index 58ce66bb5..d0c720eec 100644 --- a/src/backend/cuda/wrappers/CudaLib.cpp +++ b/src/backend/cuda/wrappers/CudaLib.cpp @@ -46,39 +46,51 @@ static uv_lib_t cudaLib; static const char *kAlloc = "alloc"; +static const char *kCnHash = "cnHash"; static const char *kDeviceCount = "deviceCount"; static const char *kDeviceInfo = "deviceInfo"; +static const char *kDeviceInit = "deviceInit"; static const char *kDeviceInt = "deviceInt"; static const char *kDeviceName = "deviceName"; static const char *kDeviceUint = "deviceUint"; static const char *kDeviceUlong = "deviceUlong"; +static const char *kInit = "init"; static const char *kPluginVersion = "pluginVersion"; static const char *kRelease = "release"; +static const char *kSetJob = "setJob"; static const char *kSymbolNotFound = "symbol not found"; static const char *kVersion = "version"; using alloc_t = nvid_ctx * (*)(uint32_t, int32_t, int32_t); +using cnHash_t = bool (*)(nvid_ctx *, uint32_t, uint64_t, uint64_t, uint32_t *, uint32_t *); using deviceCount_t = uint32_t (*)(); using deviceInfo_t = int32_t (*)(nvid_ctx *, int32_t, int32_t, int32_t); +using deviceInit_t = bool (*)(nvid_ctx *); using deviceInt_t = int32_t (*)(nvid_ctx *, CudaLib::DeviceProperty); using deviceName_t = const char * (*)(nvid_ctx *); using deviceUint_t = uint32_t (*)(nvid_ctx *, CudaLib::DeviceProperty); using deviceUlong_t = uint64_t (*)(nvid_ctx *, CudaLib::DeviceProperty); +using init_t = void (*)(); using pluginVersion_t = const char * (*)(); using release_t = void (*)(nvid_ctx *); +using setJob_t = bool (*)(nvid_ctx *, const void *, size_t, int32_t); using version_t = uint32_t (*)(Version); static alloc_t pAlloc = nullptr; +static cnHash_t pCnHash = nullptr; static deviceCount_t pDeviceCount = nullptr; static deviceInfo_t pDeviceInfo = nullptr; +static deviceInit_t pDeviceInit = nullptr; static deviceInt_t pDeviceInt = nullptr; static deviceName_t pDeviceName = nullptr; static deviceUint_t pDeviceUint = nullptr; static deviceUlong_t pDeviceUlong = nullptr; +static init_t pInit = nullptr; static pluginVersion_t pPluginVersion = nullptr; static release_t pRelease = nullptr; +static setJob_t pSetJob = nullptr; static version_t pVersion = nullptr; @@ -117,6 +129,24 @@ void xmrig::CudaLib::close() } +bool xmrig::CudaLib::cnHash(nvid_ctx *ctx, uint32_t startNonce, uint64_t height, uint64_t target, uint32_t *rescount, uint32_t *resnonce) +{ + return pCnHash(ctx, startNonce, height, target, rescount, resnonce); +} + + +bool xmrig::CudaLib::deviceInit(nvid_ctx *ctx) noexcept +{ + return pDeviceInit(ctx); +} + + +bool xmrig::CudaLib::setJob(nvid_ctx *ctx, const void *data, size_t size, const Algorithm &algorithm) noexcept +{ + return pSetJob(ctx, data, size, algorithm); +} + + const char *xmrig::CudaLib::deviceName(nvid_ctx *ctx) noexcept { return pDeviceName(ctx); @@ -216,19 +246,25 @@ bool xmrig::CudaLib::load() try { DLSYM(Alloc); + DLSYM(CnHash); DLSYM(DeviceCount); DLSYM(DeviceInfo); + DLSYM(DeviceInit); DLSYM(DeviceInt); DLSYM(DeviceName); DLSYM(DeviceUint); DLSYM(DeviceUlong); + DLSYM(Init); DLSYM(PluginVersion); DLSYM(Release); + DLSYM(SetJob); DLSYM(Version); } catch (std::exception &ex) { return false; } + pInit(); + return true; } diff --git a/src/backend/cuda/wrappers/CudaLib.h b/src/backend/cuda/wrappers/CudaLib.h index 253a15a4f..5aafeaea8 100644 --- a/src/backend/cuda/wrappers/CudaLib.h +++ b/src/backend/cuda/wrappers/CudaLib.h @@ -70,6 +70,9 @@ public: static inline bool isInitialized() { return m_initialized; } static inline const String &loader() { return m_loader; } + static bool cnHash(nvid_ctx *ctx, uint32_t startNonce, uint64_t height, uint64_t target, uint32_t *rescount, uint32_t *resnonce); + static bool deviceInit(nvid_ctx *ctx) noexcept; + static bool setJob(nvid_ctx *ctx, const void *data, size_t size, const Algorithm &algorithm) noexcept; static const char *deviceName(nvid_ctx *ctx) noexcept; static const char *pluginVersion() noexcept; static int deviceInfo(nvid_ctx *ctx, int32_t blocks, int32_t threads, const Algorithm &algorithm) noexcept; diff --git a/src/backend/opencl/runners/OclBaseRunner.cpp b/src/backend/opencl/runners/OclBaseRunner.cpp index d8497e94f..2e75d9b61 100644 --- a/src/backend/opencl/runners/OclBaseRunner.cpp +++ b/src/backend/opencl/runners/OclBaseRunner.cpp @@ -39,8 +39,8 @@ constexpr size_t oneGiB = 1024 * 1024 * 1024; xmrig::OclBaseRunner::OclBaseRunner(size_t id, const OclLaunchData &data) : - m_algorithm(data.algorithm), m_ctx(data.ctx), + m_algorithm(data.algorithm), m_source(OclSource::get(data.algorithm)), m_data(data), m_align(OclLib::getUint(data.device.id(), CL_DEVICE_MEM_BASE_ADDR_ALIGN)), diff --git a/src/backend/opencl/runners/OclBaseRunner.h b/src/backend/opencl/runners/OclBaseRunner.h index 558d68077..6abbb2b72 100644 --- a/src/backend/opencl/runners/OclBaseRunner.h +++ b/src/backend/opencl/runners/OclBaseRunner.h @@ -70,21 +70,21 @@ protected: void enqueueWriteBuffer(cl_mem buffer, cl_bool blocking_write, size_t offset, size_t size, const void *ptr); void finalize(uint32_t *hashOutput); - Algorithm m_algorithm; cl_command_queue m_queue = nullptr; cl_context m_ctx; cl_mem m_buffer = nullptr; cl_mem m_input = nullptr; cl_mem m_output = nullptr; cl_program m_program = nullptr; + const Algorithm m_algorithm; const char *m_source; const OclLaunchData &m_data; const size_t m_align; const size_t m_threadId; + const uint32_t m_intensity; size_t m_offset = 0; std::string m_deviceKey; std::string m_options; - uint32_t m_intensity; };