Added OclBackend, OclConfig, OclLaunchData, OclThread and OclThreads stubs.
This commit is contained in:
parent
eda05edd6d
commit
d5f57c35e2
17 changed files with 1010 additions and 5 deletions
|
@ -28,6 +28,11 @@
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_OPENCL
|
||||||
|
# include "backend/opencl/OclThreads.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
@ -148,4 +153,8 @@ namespace xmrig {
|
||||||
|
|
||||||
template class Threads<CpuThreads>;
|
template class Threads<CpuThreads>;
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_OPENCL
|
||||||
|
template class Threads<OclThreads>;
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace xmrig
|
} // namespace xmrig
|
||||||
|
|
|
@ -137,7 +137,7 @@ void xmrig::Workers<T>::tick(uint64_t)
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
xmrig::IWorker *xmrig::Workers<T>::create(Thread<CpuLaunchData> *)
|
xmrig::IWorker *xmrig::Workers<T>::create(Thread<T> *)
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -201,4 +201,16 @@ xmrig::IWorker *xmrig::Workers<CpuLaunchData>::create(Thread<CpuLaunchData> *han
|
||||||
template class Workers<CpuLaunchData>;
|
template class Workers<CpuLaunchData>;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_OPENCL
|
||||||
|
template<>
|
||||||
|
xmrig::IWorker *xmrig::Workers<OclLaunchData>::create(Thread<OclLaunchData> *handle)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template class Workers<OclLaunchData>;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
} // namespace xmrig
|
} // namespace xmrig
|
||||||
|
|
|
@ -31,6 +31,11 @@
|
||||||
#include "backend/cpu/CpuLaunchData.h"
|
#include "backend/cpu/CpuLaunchData.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_OPENCL
|
||||||
|
# include "backend/opencl/OclLaunchData.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +57,7 @@ public:
|
||||||
void tick(uint64_t ticks);
|
void tick(uint64_t ticks);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static IWorker *create(Thread<CpuLaunchData> *handle);
|
static IWorker *create(Thread<T> *handle);
|
||||||
static void onReady(void *arg);
|
static void onReady(void *arg);
|
||||||
|
|
||||||
std::vector<Thread<T> *> m_workers;
|
std::vector<Thread<T> *> m_workers;
|
||||||
|
@ -62,11 +67,16 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
IWorker *Workers<CpuLaunchData>::create(Thread<CpuLaunchData> *handle);
|
IWorker *Workers<CpuLaunchData>::create(Thread<CpuLaunchData> *handle);
|
||||||
|
|
||||||
|
|
||||||
extern template class Workers<CpuLaunchData>;
|
extern template class Workers<CpuLaunchData>;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_OPENCL
|
||||||
|
template<>
|
||||||
|
IWorker *Workers<OclLaunchData>::create(Thread<OclLaunchData> *handle);
|
||||||
|
extern template class Workers<OclLaunchData>;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
} // namespace xmrig
|
} // namespace xmrig
|
||||||
|
|
||||||
|
|
||||||
|
|
318
src/backend/opencl/OclBackend.cpp
Normal file
318
src/backend/opencl/OclBackend.cpp
Normal file
|
@ -0,0 +1,318 @@
|
||||||
|
/* 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 <mutex>
|
||||||
|
|
||||||
|
|
||||||
|
#include "backend/common/Hashrate.h"
|
||||||
|
#include "backend/common/interfaces/IWorker.h"
|
||||||
|
#include "backend/common/Workers.h"
|
||||||
|
#include "backend/opencl/OclBackend.h"
|
||||||
|
#include "backend/opencl/OclLaunchData.h"
|
||||||
|
#include "base/io/log/Log.h"
|
||||||
|
#include "base/net/stratum/Job.h"
|
||||||
|
#include "base/tools/Chrono.h"
|
||||||
|
#include "base/tools/String.h"
|
||||||
|
#include "core/config/Config.h"
|
||||||
|
#include "core/Controller.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_API
|
||||||
|
# include "base/api/interfaces/IApiRequest.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
extern template class Threads<OclThreads>;
|
||||||
|
|
||||||
|
|
||||||
|
static const char *tag = MAGENTA_BG_BOLD(" ocl ");
|
||||||
|
static const String kType = "opencl";
|
||||||
|
|
||||||
|
|
||||||
|
struct LaunchStatus
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline void reset()
|
||||||
|
{
|
||||||
|
hugePages = 0;
|
||||||
|
memory = 0;
|
||||||
|
pages = 0;
|
||||||
|
started = 0;
|
||||||
|
threads = 0;
|
||||||
|
ways = 0;
|
||||||
|
ts = Chrono::steadyMSecs();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t hugePages = 0;
|
||||||
|
size_t memory = 0;
|
||||||
|
size_t pages = 0;
|
||||||
|
size_t started = 0;
|
||||||
|
size_t threads = 0;
|
||||||
|
size_t ways = 0;
|
||||||
|
uint64_t ts = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class OclBackendPrivate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline OclBackendPrivate(Controller *controller) :
|
||||||
|
controller(controller)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void start()
|
||||||
|
{
|
||||||
|
LOG_INFO("%s use profile " BLUE_BG(WHITE_BOLD_S " %s ") WHITE_BOLD_S " (" CYAN_BOLD("%zu") WHITE_BOLD(" threads)") " scratchpad " CYAN_BOLD("%zu KB"),
|
||||||
|
tag,
|
||||||
|
profileName.data(),
|
||||||
|
threads.size(),
|
||||||
|
algo.l3() / 1024
|
||||||
|
);
|
||||||
|
|
||||||
|
workers.stop();
|
||||||
|
|
||||||
|
status.reset();
|
||||||
|
status.memory = algo.l3();
|
||||||
|
status.threads = threads.size();
|
||||||
|
|
||||||
|
for (const OclLaunchData &data : threads) {
|
||||||
|
status.ways += static_cast<size_t>(data.intensity);
|
||||||
|
}
|
||||||
|
|
||||||
|
workers.start(threads);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
size_t ways()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
|
|
||||||
|
return status.ways;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Algorithm algo;
|
||||||
|
Controller *controller;
|
||||||
|
LaunchStatus status;
|
||||||
|
std::mutex mutex;
|
||||||
|
std::vector<OclLaunchData> threads;
|
||||||
|
String profileName;
|
||||||
|
Workers<OclLaunchData> workers;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace xmrig
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::OclBackend::OclBackend(Controller *controller) :
|
||||||
|
d_ptr(new OclBackendPrivate(controller))
|
||||||
|
{
|
||||||
|
d_ptr->workers.setBackend(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::OclBackend::~OclBackend()
|
||||||
|
{
|
||||||
|
delete d_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::OclBackend::isEnabled() const
|
||||||
|
{
|
||||||
|
return d_ptr->controller->config()->cl().isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::OclBackend::isEnabled(const Algorithm &algorithm) const
|
||||||
|
{
|
||||||
|
return !d_ptr->controller->config()->cl().threads().get(algorithm).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const xmrig::Hashrate *xmrig::OclBackend::hashrate() const
|
||||||
|
{
|
||||||
|
return d_ptr->workers.hashrate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const xmrig::String &xmrig::OclBackend::profileName() const
|
||||||
|
{
|
||||||
|
return d_ptr->profileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const xmrig::String &xmrig::OclBackend::type() const
|
||||||
|
{
|
||||||
|
return kType;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::OclBackend::prepare(const Job &)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::OclBackend::printHashrate(bool details)
|
||||||
|
{
|
||||||
|
if (!details || !hashrate()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char num[8 * 3] = { 0 };
|
||||||
|
|
||||||
|
Log::print(WHITE_BOLD_S "| OPENCL THREAD | AFFINITY | 10s H/s | 60s H/s | 15m H/s |");
|
||||||
|
|
||||||
|
size_t i = 0;
|
||||||
|
for (const OclLaunchData &data : d_ptr->threads) {
|
||||||
|
Log::print("| %13zu | %8" PRId64 " | %7s | %7s | %7s |",
|
||||||
|
i,
|
||||||
|
data.affinity,
|
||||||
|
Hashrate::format(hashrate()->calc(i, Hashrate::ShortInterval), num, sizeof num / 3),
|
||||||
|
Hashrate::format(hashrate()->calc(i, Hashrate::MediumInterval), num + 8, sizeof num / 3),
|
||||||
|
Hashrate::format(hashrate()->calc(i, Hashrate::LargeInterval), num + 8 * 2, sizeof num / 3)
|
||||||
|
);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::OclBackend::setJob(const Job &job)
|
||||||
|
{
|
||||||
|
if (!isEnabled()) {
|
||||||
|
return stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
const OclConfig &cl = d_ptr->controller->config()->cl();
|
||||||
|
|
||||||
|
std::vector<OclLaunchData> threads = cl.get(d_ptr->controller->miner(), job.algorithm());
|
||||||
|
// if (d_ptr->threads.size() == threads.size() && std::equal(d_ptr->threads.begin(), d_ptr->threads.end(), threads.begin())) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
d_ptr->algo = job.algorithm();
|
||||||
|
d_ptr->profileName = cl.threads().profileName(job.algorithm());
|
||||||
|
|
||||||
|
// if (d_ptr->profileName.isNull() || threads.empty()) {
|
||||||
|
// d_ptr->workers.stop();
|
||||||
|
|
||||||
|
// LOG_WARN(YELLOW_BOLD_S "CPU disabled, no suitable configuration for algo %s", job.algorithm().shortName());
|
||||||
|
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
d_ptr->threads = std::move(threads);
|
||||||
|
d_ptr->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::OclBackend::start(IWorker *worker)
|
||||||
|
{
|
||||||
|
d_ptr->mutex.lock();
|
||||||
|
|
||||||
|
d_ptr->status.started++;
|
||||||
|
|
||||||
|
if (d_ptr->status.started == d_ptr->status.threads) {
|
||||||
|
}
|
||||||
|
|
||||||
|
d_ptr->mutex.unlock();
|
||||||
|
|
||||||
|
worker->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::OclBackend::stop()
|
||||||
|
{
|
||||||
|
const uint64_t ts = Chrono::steadyMSecs();
|
||||||
|
|
||||||
|
d_ptr->workers.stop();
|
||||||
|
d_ptr->threads.clear();
|
||||||
|
|
||||||
|
LOG_INFO("%s" YELLOW(" stopped") BLACK_BOLD(" (%" PRIu64 " ms)"), tag, Chrono::steadyMSecs() - ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::OclBackend::tick(uint64_t ticks)
|
||||||
|
{
|
||||||
|
d_ptr->workers.tick(ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_API
|
||||||
|
rapidjson::Value xmrig::OclBackend::toJSON(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
const CpuConfig &cpu = d_ptr->controller->config()->cpu();
|
||||||
|
|
||||||
|
Value out(kObjectType);
|
||||||
|
out.AddMember("type", type().toJSON(), allocator);
|
||||||
|
out.AddMember("enabled", isEnabled(), allocator);
|
||||||
|
out.AddMember("algo", d_ptr->algo.toJSON(), allocator);
|
||||||
|
out.AddMember("profile", profileName().toJSON(), allocator);
|
||||||
|
out.AddMember("hw-aes", cpu.isHwAES(), allocator);
|
||||||
|
out.AddMember("priority", cpu.priority(), allocator);
|
||||||
|
out.AddMember("memory", static_cast<uint64_t>(d_ptr->algo.isValid() ? (d_ptr->ways() * d_ptr->algo.l3()) : 0), allocator);
|
||||||
|
|
||||||
|
if (d_ptr->threads.empty() || !hashrate()) {
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
Value threads(kArrayType);
|
||||||
|
const Hashrate *hr = hashrate();
|
||||||
|
|
||||||
|
size_t i = 0;
|
||||||
|
for (const OclLaunchData &data : d_ptr->threads) {
|
||||||
|
Value thread(kObjectType);
|
||||||
|
thread.AddMember("intensity", data.intensity, allocator);
|
||||||
|
thread.AddMember("affinity", data.affinity, allocator);
|
||||||
|
|
||||||
|
Value hashrate(kArrayType);
|
||||||
|
hashrate.PushBack(Hashrate::normalize(hr->calc(i, Hashrate::ShortInterval)), allocator);
|
||||||
|
hashrate.PushBack(Hashrate::normalize(hr->calc(i, Hashrate::MediumInterval)), allocator);
|
||||||
|
hashrate.PushBack(Hashrate::normalize(hr->calc(i, Hashrate::LargeInterval)), allocator);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
thread.AddMember("hashrate", hashrate, allocator);
|
||||||
|
threads.PushBack(thread, allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
out.AddMember("threads", threads, allocator);
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::OclBackend::handleRequest(IApiRequest &)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
75
src/backend/opencl/OclBackend.h
Normal file
75
src/backend/opencl/OclBackend.h
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
/* 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_OCLBACKEND_H
|
||||||
|
#define XMRIG_OCLBACKEND_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
|
||||||
|
#include "backend/common/interfaces/IBackend.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class Controller;
|
||||||
|
class OclBackendPrivate;
|
||||||
|
class Miner;
|
||||||
|
|
||||||
|
|
||||||
|
class OclBackend : public IBackend
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OclBackend(Controller *controller);
|
||||||
|
~OclBackend() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool isEnabled() const override;
|
||||||
|
bool isEnabled(const Algorithm &algorithm) const override;
|
||||||
|
const Hashrate *hashrate() const override;
|
||||||
|
const String &profileName() const override;
|
||||||
|
const String &type() const override;
|
||||||
|
void prepare(const Job &nextJob) override;
|
||||||
|
void printHashrate(bool details) override;
|
||||||
|
void setJob(const Job &job) override;
|
||||||
|
void start(IWorker *worker) override;
|
||||||
|
void stop() override;
|
||||||
|
void tick(uint64_t ticks) override;
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_API
|
||||||
|
rapidjson::Value toJSON(rapidjson::Document &doc) const override;
|
||||||
|
void handleRequest(IApiRequest &request) override;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
OclBackendPrivate *d_ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_OCLBACKEND_H */
|
90
src/backend/opencl/OclConfig.cpp
Normal file
90
src/backend/opencl/OclConfig.cpp
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/* 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/OclConfig.h"
|
||||||
|
#include "base/io/json/Json.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
static const char *kEnabled = "enabled";
|
||||||
|
|
||||||
|
|
||||||
|
extern template class Threads<OclThreads>;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::OclConfig::OclConfig()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rapidjson::Value xmrig::OclConfig::toJSON(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
Value obj(kObjectType);
|
||||||
|
|
||||||
|
obj.AddMember(StringRef(kEnabled), m_enabled, allocator);
|
||||||
|
|
||||||
|
m_threads.toJSON(obj, doc);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<xmrig::OclLaunchData> xmrig::OclConfig::get(const Miner *miner, const Algorithm &algorithm) const
|
||||||
|
{
|
||||||
|
std::vector<OclLaunchData> out;
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::OclConfig::read(const rapidjson::Value &value)
|
||||||
|
{
|
||||||
|
if (value.IsObject()) {
|
||||||
|
m_enabled = Json::getBool(value, kEnabled, m_enabled);
|
||||||
|
|
||||||
|
if (!m_threads.read(value)) {
|
||||||
|
generate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (value.IsBool() && value.IsFalse()) {
|
||||||
|
m_enabled = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
generate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::OclConfig::generate()
|
||||||
|
{
|
||||||
|
m_shouldSave = true;
|
||||||
|
}
|
62
src/backend/opencl/OclConfig.h
Normal file
62
src/backend/opencl/OclConfig.h
Normal 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XMRIG_OCLCONFIG_H
|
||||||
|
#define XMRIG_OCLCONFIG_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "backend/common/Threads.h"
|
||||||
|
#include "backend/opencl/OclLaunchData.h"
|
||||||
|
#include "backend/opencl/OclThreads.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class OclConfig
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OclConfig();
|
||||||
|
|
||||||
|
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||||
|
std::vector<OclLaunchData> get(const Miner *miner, const Algorithm &algorithm) const;
|
||||||
|
void read(const rapidjson::Value &value);
|
||||||
|
|
||||||
|
inline bool isEnabled() const { return m_enabled; }
|
||||||
|
inline bool isShouldSave() const { return m_shouldSave; }
|
||||||
|
inline const Threads<OclThreads> &threads() const { return m_threads; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void generate();
|
||||||
|
|
||||||
|
bool m_enabled = true;
|
||||||
|
bool m_shouldSave = false;
|
||||||
|
Threads<OclThreads> m_threads;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_OCLCONFIG_H */
|
48
src/backend/opencl/OclLaunchData.cpp
Normal file
48
src/backend/opencl/OclLaunchData.cpp
Normal 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 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 "backend/opencl/OclLaunchData.h"
|
||||||
|
#include "backend/opencl/OclConfig.h"
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::OclLaunchData::OclLaunchData(const Miner *miner, const Algorithm &algorithm, const OclConfig &config, const OclThread &thread) :
|
||||||
|
algorithm(algorithm),
|
||||||
|
intensity(thread.intensity()),
|
||||||
|
priority(-1),
|
||||||
|
affinity(thread.affinity()),
|
||||||
|
miner(miner)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::OclLaunchData::isEqual(const OclLaunchData &other) const
|
||||||
|
{
|
||||||
|
return (algorithm.l3() == other.algorithm.l3()
|
||||||
|
&& intensity == other.intensity
|
||||||
|
&& priority == other.priority
|
||||||
|
&& affinity == other.affinity
|
||||||
|
);
|
||||||
|
}
|
65
src/backend/opencl/OclLaunchData.h
Normal file
65
src/backend/opencl/OclLaunchData.h
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/* 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_OCLLAUNCHDATA_H
|
||||||
|
#define XMRIG_OCLLAUNCHDATA_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "crypto/common/Algorithm.h"
|
||||||
|
#include "crypto/common/Nonce.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class OclConfig;
|
||||||
|
class OclThread;
|
||||||
|
class Miner;
|
||||||
|
|
||||||
|
|
||||||
|
class OclLaunchData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OclLaunchData(const Miner *miner, const Algorithm &algorithm, const OclConfig &config, const OclThread &thread);
|
||||||
|
|
||||||
|
bool isEqual(const OclLaunchData &other) const;
|
||||||
|
|
||||||
|
inline constexpr static Nonce::Backend backend() { return Nonce::OPENCL; }
|
||||||
|
|
||||||
|
inline bool operator!=(const OclLaunchData &other) const { return !isEqual(other); }
|
||||||
|
inline bool operator==(const OclLaunchData &other) const { return isEqual(other); }
|
||||||
|
|
||||||
|
const Algorithm algorithm;
|
||||||
|
const int intensity;
|
||||||
|
const int priority;
|
||||||
|
const int64_t affinity;
|
||||||
|
const Miner *miner;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace xmrig
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_OCLLAUNCHDATA_H */
|
58
src/backend/opencl/OclThread.cpp
Normal file
58
src/backend/opencl/OclThread.cpp
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/* 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/OclThread.h"
|
||||||
|
#include "base/io/json/Json.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::OclThread::OclThread(const rapidjson::Value &value)
|
||||||
|
{
|
||||||
|
if (value.IsArray() && value.Size() >= 2) {
|
||||||
|
m_intensity = value[0].GetInt();
|
||||||
|
m_affinity = value[1].GetInt();
|
||||||
|
}
|
||||||
|
else if (value.IsInt()) {
|
||||||
|
m_intensity = -1;
|
||||||
|
m_affinity = value.GetInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rapidjson::Value xmrig::OclThread::toJSON(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
if (m_intensity == -1) {
|
||||||
|
return Value(m_affinity);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
Value out(kArrayType);
|
||||||
|
out.PushBack(m_intensity, allocator);
|
||||||
|
out.PushBack(m_affinity, allocator);
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
62
src/backend/opencl/OclThread.h
Normal file
62
src/backend/opencl/OclThread.h
Normal 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XMRIG_OCLTHREAD_H
|
||||||
|
#define XMRIG_OCLTHREAD_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "rapidjson/fwd.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class OclThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline constexpr OclThread() {}
|
||||||
|
inline constexpr OclThread(int64_t affinity, int intensity) : m_intensity(intensity), m_affinity(affinity) {}
|
||||||
|
|
||||||
|
OclThread(const rapidjson::Value &value);
|
||||||
|
|
||||||
|
inline bool isEqual(const OclThread &other) const { return other.m_affinity == m_affinity && other.m_intensity == m_intensity; }
|
||||||
|
inline bool isValid() const { return m_intensity == -1 || (m_intensity >= 1 && m_intensity <= 5); }
|
||||||
|
inline int intensity() const { return m_intensity == -1 ? 1 : m_intensity; }
|
||||||
|
inline int64_t affinity() const { return m_affinity; }
|
||||||
|
|
||||||
|
inline bool operator!=(const OclThread &other) const { return !isEqual(other); }
|
||||||
|
inline bool operator==(const OclThread &other) const { return isEqual(other); }
|
||||||
|
|
||||||
|
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_intensity = -1;
|
||||||
|
int64_t m_affinity = -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_OCLTHREAD_H */
|
71
src/backend/opencl/OclThreads.cpp
Normal file
71
src/backend/opencl/OclThreads.cpp
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
/* 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 <algorithm>
|
||||||
|
|
||||||
|
|
||||||
|
#include "backend/opencl/OclThreads.h"
|
||||||
|
#include "base/io/json/Json.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::OclThreads::OclThreads(const rapidjson::Value &value)
|
||||||
|
{
|
||||||
|
if (value.IsArray()) {
|
||||||
|
for (auto &v : value.GetArray()) {
|
||||||
|
OclThread thread(v);
|
||||||
|
if (thread.isValid()) {
|
||||||
|
add(std::move(thread));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::OclThreads::OclThreads(size_t count, int intensity)
|
||||||
|
{
|
||||||
|
m_data.reserve(count);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; ++i) {
|
||||||
|
add(-1, intensity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rapidjson::Value xmrig::OclThreads::toJSON(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
Value out(kArrayType);
|
||||||
|
|
||||||
|
out.SetArray();
|
||||||
|
|
||||||
|
for (const OclThread &thread : m_data) {
|
||||||
|
out.PushBack(thread.toJSON(doc), allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
64
src/backend/opencl/OclThreads.h
Normal file
64
src/backend/opencl/OclThreads.h
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
/* 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_OCLTHREADS_H
|
||||||
|
#define XMRIG_OCLTHREADS_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
#include "backend/opencl/OclThread.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class OclThreads
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline OclThreads() {}
|
||||||
|
inline OclThreads(size_t count) : m_data(count) {}
|
||||||
|
|
||||||
|
OclThreads(const rapidjson::Value &value);
|
||||||
|
OclThreads(size_t count, int intensity);
|
||||||
|
|
||||||
|
inline bool isEmpty() const { return m_data.empty(); }
|
||||||
|
inline const std::vector<OclThread> &data() const { return m_data; }
|
||||||
|
inline size_t count() const { return m_data.size(); }
|
||||||
|
inline void add(OclThread &&thread) { m_data.push_back(thread); }
|
||||||
|
inline void add(int64_t affinity, int intensity) { add(OclThread(affinity, intensity)); }
|
||||||
|
inline void reserve(size_t capacity) { m_data.reserve(capacity); }
|
||||||
|
|
||||||
|
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<OclThread> m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_OCLTHREADS_H */
|
|
@ -4,13 +4,23 @@ if (WITH_OPENCL)
|
||||||
add_definitions(/DXMRIG_FEATURE_OPENCL)
|
add_definitions(/DXMRIG_FEATURE_OPENCL)
|
||||||
|
|
||||||
set(HEADERS_BACKEND_OPENCL
|
set(HEADERS_BACKEND_OPENCL
|
||||||
|
src/backend/opencl/OclBackend.h
|
||||||
|
src/backend/opencl/OclConfig.h
|
||||||
src/backend/opencl/OclError.h
|
src/backend/opencl/OclError.h
|
||||||
|
src/backend/opencl/OclLaunchData.h
|
||||||
src/backend/opencl/OclLib.h
|
src/backend/opencl/OclLib.h
|
||||||
|
src/backend/opencl/OclThread.h
|
||||||
|
src/backend/opencl/OclThreads.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCES_BACKEND_OPENCL
|
set(SOURCES_BACKEND_OPENCL
|
||||||
|
src/backend/opencl/OclBackend.cpp
|
||||||
|
src/backend/opencl/OclConfig.cpp
|
||||||
src/backend/opencl/OclError.cpp
|
src/backend/opencl/OclError.cpp
|
||||||
|
src/backend/opencl/OclLaunchData.cpp
|
||||||
src/backend/opencl/OclLib.cpp
|
src/backend/opencl/OclLib.cpp
|
||||||
|
src/backend/opencl/OclThread.cpp
|
||||||
|
src/backend/opencl/OclThreads.cpp
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
remove_definitions(/DXMRIG_FEATURE_OPENCL)
|
remove_definitions(/DXMRIG_FEATURE_OPENCL)
|
||||||
|
|
|
@ -50,6 +50,11 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_OPENCL
|
||||||
|
# include "backend/opencl/OclBackend.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
@ -252,6 +257,10 @@ xmrig::Miner::Miner(Controller *controller)
|
||||||
|
|
||||||
d_ptr->backends.push_back(new CpuBackend(controller));
|
d_ptr->backends.push_back(new CpuBackend(controller));
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_OPENCL
|
||||||
|
d_ptr->backends.push_back(new OclBackend(controller));
|
||||||
|
# endif
|
||||||
|
|
||||||
d_ptr->rebuild();
|
d_ptr->rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,10 @@ static const char *kCPU = "cpu";
|
||||||
static const char *kRandomX = "randomx";
|
static const char *kRandomX = "randomx";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_OPENCL
|
||||||
|
static const char *kOcl = "opencl";
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,6 +58,22 @@ xmrig::Config::Config() : BaseConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::Config::isShouldSave() const
|
||||||
|
{
|
||||||
|
if (!isAutoSave()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_OPENCL
|
||||||
|
if (m_cl.isShouldSave()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
return (m_shouldSave || m_upgrade || m_cpu.isShouldSave());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool xmrig::Config::read(const IJsonReader &reader, const char *fileName)
|
bool xmrig::Config::read(const IJsonReader &reader, const char *fileName)
|
||||||
{
|
{
|
||||||
if (!BaseConfig::read(reader, fileName)) {
|
if (!BaseConfig::read(reader, fileName)) {
|
||||||
|
@ -68,6 +88,10 @@ bool xmrig::Config::read(const IJsonReader &reader, const char *fileName)
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_OPENCL
|
||||||
|
m_cl.read(reader.getValue(kOcl));
|
||||||
|
# endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +119,11 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
doc.AddMember(StringRef(kCPU), m_cpu.toJSON(doc), allocator);
|
doc.AddMember(StringRef(kCPU), m_cpu.toJSON(doc), allocator);
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_OPENCL
|
||||||
|
doc.AddMember(StringRef(kOcl), m_cl.toJSON(doc), allocator);
|
||||||
|
# endif
|
||||||
|
|
||||||
doc.AddMember("donate-level", m_pools.donateLevel(), allocator);
|
doc.AddMember("donate-level", m_pools.donateLevel(), allocator);
|
||||||
doc.AddMember("donate-over-proxy", m_pools.proxyDonate(), allocator);
|
doc.AddMember("donate-over-proxy", m_pools.proxyDonate(), allocator);
|
||||||
doc.AddMember("log-file", m_logFile.toJSON(), allocator);
|
doc.AddMember("log-file", m_logFile.toJSON(), allocator);
|
||||||
|
|
|
@ -39,6 +39,11 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_OPENCL
|
||||||
|
# include "backend/opencl/OclConfig.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,16 +55,20 @@ class Config : public BaseConfig
|
||||||
public:
|
public:
|
||||||
Config();
|
Config();
|
||||||
|
|
||||||
|
bool isShouldSave() const;
|
||||||
bool read(const IJsonReader &reader, const char *fileName) override;
|
bool read(const IJsonReader &reader, const char *fileName) override;
|
||||||
void getJSON(rapidjson::Document &doc) const override;
|
void getJSON(rapidjson::Document &doc) const override;
|
||||||
|
|
||||||
inline bool isShouldSave() const { return (m_shouldSave || m_upgrade || m_cpu.isShouldSave()) && isAutoSave(); }
|
|
||||||
inline const CpuConfig &cpu() const { return m_cpu; }
|
inline const CpuConfig &cpu() const { return m_cpu; }
|
||||||
|
|
||||||
# ifdef XMRIG_ALGO_RANDOMX
|
# ifdef XMRIG_ALGO_RANDOMX
|
||||||
inline const RxConfig &rx() const { return m_rx; }
|
inline const RxConfig &rx() const { return m_rx; }
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_OPENCL
|
||||||
|
inline const OclConfig &cl() const { return m_cl; }
|
||||||
|
# endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_shouldSave = false;
|
bool m_shouldSave = false;
|
||||||
CpuConfig m_cpu;
|
CpuConfig m_cpu;
|
||||||
|
@ -67,6 +76,10 @@ private:
|
||||||
# ifdef XMRIG_ALGO_RANDOMX
|
# ifdef XMRIG_ALGO_RANDOMX
|
||||||
RxConfig m_rx;
|
RxConfig m_rx;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_OPENCL
|
||||||
|
OclConfig m_cl;
|
||||||
|
# endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue