Added OclWorker class.

This commit is contained in:
XMRig 2019-08-25 03:50:49 +07:00
parent cf123b7d88
commit d27990b273
7 changed files with 201 additions and 33 deletions

View file

@ -31,6 +31,11 @@
#include "base/io/log/Log.h"
#ifdef XMRIG_FEATURE_OPENCL
# include "backend/opencl/OclWorker.h"
#endif
namespace xmrig {
@ -155,6 +160,8 @@ void xmrig::Workers<T>::onReady(void *arg)
return;
}
assert(handle->backend() != nullptr);
handle->setWorker(worker);
handle->backend()->start(worker);
}
@ -194,7 +201,7 @@ template class Workers<CpuLaunchData>;
template<>
xmrig::IWorker *xmrig::Workers<OclLaunchData>::create(Thread<OclLaunchData> *handle)
{
return nullptr;
return new OclWorker(handle->index(), handle->config());
}

View file

@ -63,7 +63,7 @@ static const char *tag = CYAN_BG_BOLD(" cpu ");
static const String kType = "cpu";
struct LaunchStatus
struct CpuLaunchStatus
{
public:
inline void reset()
@ -161,7 +161,7 @@ public:
Algorithm algo;
Controller *controller;
LaunchStatus status;
CpuLaunchStatus status;
std::mutex mutex;
std::vector<CpuLaunchData> threads;
String profileName;

View file

@ -30,7 +30,6 @@
#include "backend/common/Worker.h"
#include "backend/common/WorkerJob.h"
#include "backend/cpu/CpuLaunchData.h"
#include "base/net/stratum/Job.h"
#include "net/JobResult.h"

View file

@ -54,9 +54,10 @@ namespace xmrig {
extern template class Threads<OclThreads>;
constexpr const size_t oneGiB = 1024u * 1024u * 1024u;
static const char *tag = MAGENTA_BG_BOLD(WHITE_BOLD_S " ocl ");
static const String kType = "opencl";
constexpr const size_t oneGiB = 1024u * 1024u * 1024u;
static std::mutex mutex;
static void printDisabled(const char *reason)
@ -65,25 +66,18 @@ static void printDisabled(const char *reason)
}
struct LaunchStatus
struct OclLaunchStatus
{
public:
inline void reset()
{
hugePages = 0;
memory = 0;
pages = 0;
started = 0;
threads = 0;
ts = Chrono::steadyMSecs();
}
inline bool started() { m_started++; return m_started == m_threads; }
inline size_t threads() const { return m_threads; }
inline uint64_t ts() const { return Chrono::steadyMSecs() - m_ts; }
inline void start(size_t threads) { m_started = 0; m_threads = threads; m_ts = Chrono::steadyMSecs(); }
size_t hugePages = 0;
size_t memory = 0;
size_t pages = 0;
size_t started = 0;
size_t threads = 0;
uint64_t ts = 0;
private:
size_t m_started = 0;
size_t m_threads = 0;
uint64_t m_ts = 0;
};
@ -143,20 +137,16 @@ public:
workers.stop();
status.reset();
status.memory = algo.l3();
status.threads = threads.size();
//workers.start(threads); // FIXME
status.start(threads.size());
workers.start(threads);
}
Algorithm algo;
Controller *controller;
LaunchStatus status;
OclContext context;
OclLaunchStatus status;
OclPlatform platform;
std::mutex mutex;
std::vector<OclDevice> devices;
std::vector<OclLaunchData> threads;
String profileName;
@ -277,14 +267,17 @@ void xmrig::OclBackend::setJob(const Job &job)
void xmrig::OclBackend::start(IWorker *worker)
{
d_ptr->mutex.lock();
mutex.lock();
d_ptr->status.started++;
if (d_ptr->status.started == d_ptr->status.threads) {
if (d_ptr->status.started()) {
LOG_INFO("%s" GREEN_BOLD(" READY") " threads " CYAN_BOLD("%zu") BLACK_BOLD(" (%" PRIu64 " ms)"),
tag,
d_ptr->status.threads(),
d_ptr->status.ts()
);
}
d_ptr->mutex.unlock();
mutex.unlock();
worker->start();
}

View file

@ -0,0 +1,106 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include <thread>
#include "backend/opencl/OclWorker.h"
#include "core/Miner.h"
#include "crypto/common/Nonce.h"
#include "net/JobResults.h"
namespace xmrig {
static constexpr uint32_t kReserveCount = 4096;
} // namespace xmrig
xmrig::OclWorker::OclWorker(size_t index, const OclLaunchData &data) :
Worker(index, data.thread.affinity(), -1),
m_algorithm(data.algorithm),
m_miner(data.miner)
{
}
xmrig::OclWorker::~OclWorker()
{
}
bool xmrig::OclWorker::selfTest()
{
return true;
}
void xmrig::OclWorker::start()
{
while (Nonce::sequence(Nonce::OPENCL) > 0) {
if (Nonce::isPaused()) {
do {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
while (Nonce::isPaused() && Nonce::sequence(Nonce::OPENCL) > 0);
if (Nonce::sequence(Nonce::OPENCL) == 0) {
break;
}
consumeJob();
}
while (!Nonce::isOutdated(Nonce::OPENCL, m_job.sequence())) {
if ((m_count & 0x7) == 0) {
storeStats();
}
const Job &job = m_job.currentJob();
if (job.algorithm().l3() != m_algorithm.l3()) {
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(2000)); // FIXME
m_job.nextRound(kReserveCount);
std::this_thread::yield();
}
consumeJob();
}
}
void xmrig::OclWorker::consumeJob()
{
m_job.add(m_miner->job(), Nonce::sequence(Nonce::OPENCL), kReserveCount);
}

View file

@ -0,0 +1,61 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_OCLWORKER_H
#define XMRIG_OCLWORKER_H
#include "backend/common/Worker.h"
#include "backend/common/WorkerJob.h"
#include "backend/opencl/OclLaunchData.h"
#include "net/JobResult.h"
namespace xmrig {
class OclWorker : public Worker
{
public:
OclWorker(size_t index, const OclLaunchData &data);
~OclWorker() override;
protected:
bool selfTest() override;
void start() override;
private:
void consumeJob();
const Algorithm m_algorithm;
const Miner *m_miner;
WorkerJob<1> m_job;
};
} // namespace xmrig
#endif /* XMRIG_OCLWORKER_H */

View file

@ -10,6 +10,7 @@ if (WITH_OPENCL)
src/backend/opencl/OclLaunchData.h
src/backend/opencl/OclThread.h
src/backend/opencl/OclThreads.h
src/backend/opencl/OclWorker.h
src/backend/opencl/wrappers/OclContext.h
src/backend/opencl/wrappers/OclDevice.h
src/backend/opencl/wrappers/OclError.h
@ -25,6 +26,7 @@ if (WITH_OPENCL)
src/backend/opencl/OclLaunchData.cpp
src/backend/opencl/OclThread.cpp
src/backend/opencl/OclThreads.cpp
src/backend/opencl/OclWorker.cpp
src/backend/opencl/wrappers/OclContext.cpp
src/backend/opencl/wrappers/OclDevice.cpp
src/backend/opencl/wrappers/OclError.cpp