Class OclInterleave renamed to OclSharedData and added class OclSharedState.

This commit is contained in:
XMRig 2019-09-30 05:18:53 +07:00
parent c908ef2489
commit f4943b77f3
10 changed files with 154 additions and 34 deletions

View file

@ -35,6 +35,7 @@
#include "backend/opencl/OclConfig.h"
#include "backend/opencl/OclLaunchData.h"
#include "backend/opencl/OclWorker.h"
#include "backend/opencl/runners/tools/OclSharedState.h"
#include "backend/opencl/wrappers/OclContext.h"
#include "backend/opencl/wrappers/OclLib.h"
#include "base/io/log/Log.h"
@ -194,6 +195,8 @@ public:
i++;
}
OclSharedState::start(threads);
status.start(threads.size());
workers.start(threads);
}
@ -371,6 +374,8 @@ void xmrig::OclBackend::stop()
d_ptr->workers.stop();
d_ptr->threads.clear();
OclSharedState::release();
LOG_INFO("%s" YELLOW(" stopped") BLACK_BOLD(" (%" PRIu64 " ms)"), tag, Chrono::steadyMSecs() - ts);
}

View file

@ -198,11 +198,8 @@ std::vector<xmrig::OclLaunchData> xmrig::OclConfig::get(const Miner *miner, cons
# endif
if (thread.threads().size() > 1) {
auto interleave = std::make_shared<OclInterleave>(thread.threads().size());
for (int64_t affinity : thread.threads()) {
OclLaunchData data(miner, algorithm, *this, platform, thread, devices[thread.index()], affinity);
data.interleave = interleave;
# ifdef XMRIG_ALGO_RANDOMX
data.dataset = dataset;

View file

@ -27,8 +27,8 @@
#define XMRIG_OCLLAUNCHDATA_H
#include "backend/opencl/OclInterleave.h"
#include "backend/opencl/OclThread.h"
#include "backend/opencl/runners/tools/OclSharedData.h"
#include "backend/opencl/wrappers/OclDevice.h"
#include "backend/opencl/wrappers/OclPlatform.h"
#include "crypto/common/Algorithm.h"
@ -72,7 +72,6 @@ public:
const OclDevice device;
const OclPlatform platform;
const OclThread thread;
OclInterleavePtr interleave;
# ifdef XMRIG_ALGO_RANDOMX
OclRxDatasetPtr dataset;

View file

@ -28,6 +28,8 @@
#include "backend/common/Tags.h"
#include "backend/opencl/runners/OclCnRunner.h"
#include "backend/opencl/runners/tools/OclSharedData.h"
#include "backend/opencl/runners/tools/OclSharedState.h"
#include "base/io/log/Log.h"
#include "base/tools/Chrono.h"
#include "core/Miner.h"
@ -75,7 +77,7 @@ xmrig::OclWorker::OclWorker(size_t id, const OclLaunchData &data) :
m_algorithm(data.algorithm),
m_miner(data.miner),
m_intensity(data.thread.intensity()),
m_interleave(data.interleave)
m_sharedData(OclSharedState::get(data.device.index()))
{
switch (m_algorithm.family()) {
case Algorithm::RANDOM_X:
@ -149,9 +151,7 @@ void xmrig::OclWorker::start()
while (Nonce::sequence(Nonce::OPENCL) > 0) {
if (!isReady()) {
if (m_interleave) {
m_interleave->setResumeCounter(0);
}
m_sharedData.setResumeCounter(0);
do {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
@ -162,9 +162,7 @@ void xmrig::OclWorker::start()
break;
}
if (m_interleave) {
m_interleave->resumeDelay(m_id);
}
m_sharedData.resumeDelay(m_id);
if (!consumeJob()) {
return;
@ -172,9 +170,7 @@ void xmrig::OclWorker::start()
}
while (!Nonce::isOutdated(Nonce::OPENCL, m_job.sequence())) {
if (m_interleave) {
m_interleave->adjustDelay(m_id);
}
m_sharedData.adjustDelay(m_id);
const uint64_t t = Chrono::steadyMSecs();
@ -233,9 +229,7 @@ void xmrig::OclWorker::storeStats(uint64_t t)
m_count += m_intensity;
if (m_interleave) {
m_interleave->setRunTime(Chrono::steadyMSecs() - t);
}
m_sharedData.setRunTime(Chrono::steadyMSecs() - t);
Worker::storeStats();
}

View file

@ -67,7 +67,7 @@ private:
const Miner *m_miner;
const uint32_t m_intensity;
IOclRunner *m_runner = nullptr;
OclInterleavePtr m_interleave;
OclSharedData &m_sharedData;
WorkerJob<1> m_job;
};

View file

@ -14,7 +14,6 @@ if (WITH_OPENCL)
src/backend/opencl/OclCache.h
src/backend/opencl/OclConfig.h
src/backend/opencl/OclGenerator.h
src/backend/opencl/OclInterleave.h
src/backend/opencl/OclLaunchData.h
src/backend/opencl/OclThread.h
src/backend/opencl/OclThreads.h
@ -22,6 +21,8 @@ if (WITH_OPENCL)
src/backend/opencl/runners/OclBaseRunner.h
src/backend/opencl/runners/OclCnRunner.h
src/backend/opencl/runners/tools/OclCnR.h
src/backend/opencl/runners/tools/OclSharedData.h
src/backend/opencl/runners/tools/OclSharedState.h
src/backend/opencl/wrappers/OclContext.h
src/backend/opencl/wrappers/OclDevice.h
src/backend/opencl/wrappers/OclError.h
@ -42,7 +43,6 @@ if (WITH_OPENCL)
src/backend/opencl/OclBackend.cpp
src/backend/opencl/OclCache.cpp
src/backend/opencl/OclConfig.cpp
src/backend/opencl/OclInterleave.cpp
src/backend/opencl/OclLaunchData.cpp
src/backend/opencl/OclThread.cpp
src/backend/opencl/OclThreads.cpp
@ -50,6 +50,8 @@ if (WITH_OPENCL)
src/backend/opencl/runners/OclBaseRunner.cpp
src/backend/opencl/runners/OclCnRunner.cpp
src/backend/opencl/runners/tools/OclCnR.cpp
src/backend/opencl/runners/tools/OclSharedData.cpp
src/backend/opencl/runners/tools/OclSharedState.cpp
src/backend/opencl/wrappers/OclContext.cpp
src/backend/opencl/wrappers/OclDevice.cpp
src/backend/opencl/wrappers/OclError.cpp

View file

@ -23,7 +23,7 @@
*/
#include "backend/opencl/OclInterleave.h"
#include "backend/opencl/runners/tools/OclSharedData.h"
#include "base/io/log/Log.h"
#include "base/tools/Chrono.h"
@ -32,8 +32,12 @@
#include <thread>
uint64_t xmrig::OclInterleave::adjustDelay(size_t id)
uint64_t xmrig::OclSharedData::adjustDelay(size_t id)
{
if (m_threads < 2) {
return 0;
}
const uint64_t t0 = Chrono::steadyMSecs();
uint64_t delay = 0;
@ -69,8 +73,12 @@ uint64_t xmrig::OclInterleave::adjustDelay(size_t id)
}
uint64_t xmrig::OclInterleave::resumeDelay(size_t id)
uint64_t xmrig::OclSharedData::resumeDelay(size_t id)
{
if (m_threads < 2) {
return 0;
}
uint64_t delay = 0;
{
@ -99,14 +107,18 @@ uint64_t xmrig::OclInterleave::resumeDelay(size_t id)
}
void xmrig::OclInterleave::setResumeCounter(uint32_t value)
void xmrig::OclSharedData::setResumeCounter(uint32_t value)
{
if (m_threads < 2) {
return;
}
std::lock_guard<std::mutex> lock(m_mutex);
m_resumeCounter = value;
}
void xmrig::OclInterleave::setRunTime(uint64_t time)
void xmrig::OclSharedData::setRunTime(uint64_t time)
{
// averagingBias = 1.0 - only the last delta time is taken into account
// averagingBias = 0.5 - the last delta time has the same weight as all the previous ones combined

View file

@ -22,8 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_OCLINTERLEAVE_H
#define XMRIG_OCLINTERLEAVE_H
#ifndef XMRIG_OCLSHAREDDATA_H
#define XMRIG_OCLSHAREDDATA_H
#include <memory>
@ -33,31 +33,32 @@
namespace xmrig {
class OclInterleave
class OclSharedData
{
public:
OclInterleave() = delete;
inline OclInterleave(size_t threads) : m_threads(threads) {}
OclSharedData() = default;
uint64_t adjustDelay(size_t id);
uint64_t resumeDelay(size_t id);
void setResumeCounter(uint32_t value);
void setRunTime(uint64_t time);
inline OclSharedData &operator++() { ++m_threads; return *this; }
private:
const size_t m_threads;
double m_averageRunTime = 0.0;
double m_threshold = 0.95;
size_t m_threads = 0;
std::mutex m_mutex;
uint32_t m_resumeCounter = 0;
uint64_t m_timestamp = 0;
};
using OclInterleavePtr = std::shared_ptr<OclInterleave>;
using OclSharedDataPtr = std::shared_ptr<OclSharedData>;
} /* namespace xmrig */
#endif /* XMRIG_OCLINTERLEAVE_H */
#endif /* XMRIG_OCLSHAREDDATA_H */

View file

@ -0,0 +1,62 @@
/* 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-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 "backend/opencl/runners/tools/OclSharedState.h"
#include "backend/opencl/runners/tools/OclSharedData.h"
#include <cassert>
#include <map>
namespace xmrig {
static std::map<uint32_t, OclSharedData> map;
} // namespace xmrig
xmrig::OclSharedData &xmrig::OclSharedState::get(uint32_t index)
{
return map[index];
}
void xmrig::OclSharedState::release()
{
map.clear();
}
void xmrig::OclSharedState::start(const std::vector<OclLaunchData> &threads)
{
assert(map.empty());
for (const auto &data : threads) {
++map[data.device.index()];
}
}

View file

@ -0,0 +1,48 @@
/* 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-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_OCLSHAREDSTATE_H
#define XMRIG_OCLSHAREDSTATE_H
#include "backend/opencl/OclLaunchData.h"
namespace xmrig {
class OclSharedState
{
public:
static OclSharedData &get(uint32_t index);
static void release();
static void start(const std::vector<OclLaunchData> &threads);
};
} /* namespace xmrig */
#endif /* XMRIG_OCLSHAREDSTATE_H */