mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-22 19:49:36 +00:00
Added initial CUDA backend stub.
This commit is contained in:
parent
534a764023
commit
0fc215c457
18 changed files with 871 additions and 7 deletions
|
@ -15,6 +15,7 @@ option(WITH_TLS "Enable OpenSSL support" ON)
|
|||
option(WITH_ASM "Enable ASM PoW implementations" ON)
|
||||
option(WITH_EMBEDDED_CONFIG "Enable internal embedded JSON config" OFF)
|
||||
option(WITH_OPENCL "Enable OpenCL backend" ON)
|
||||
option(WITH_CUDA "Enable CUDA backend" ON)
|
||||
option(WITH_STRICT_CACHE "Enable strict checks for OpenCL cache" ON)
|
||||
option(WITH_INTERLEAVE_DEBUG_LOG "Enable debug log for threads interleave" OFF)
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
include (src/backend/cpu/cpu.cmake)
|
||||
include (src/backend/opencl/opencl.cmake)
|
||||
include (src/backend/cuda/cuda.cmake)
|
||||
include (src/backend/common/common.cmake)
|
||||
|
||||
|
||||
|
@ -7,10 +8,12 @@ set(HEADERS_BACKEND
|
|||
"${HEADERS_BACKEND_COMMON}"
|
||||
"${HEADERS_BACKEND_CPU}"
|
||||
"${HEADERS_BACKEND_OPENCL}"
|
||||
"${HEADERS_BACKEND_CUDA}"
|
||||
)
|
||||
|
||||
set(SOURCES_BACKEND
|
||||
"${SOURCES_BACKEND_COMMON}"
|
||||
"${SOURCES_BACKEND_CPU}"
|
||||
"${SOURCES_BACKEND_OPENCL}"
|
||||
"${SOURCES_BACKEND_CUDA}"
|
||||
)
|
||||
|
|
|
@ -38,6 +38,12 @@ const char *ocl_tag();
|
|||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_CUDA
|
||||
const char *cuda_tag();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef XMRIG_ALGO_RANDOMX
|
||||
const char *rx_tag();
|
||||
#endif
|
||||
|
|
|
@ -34,6 +34,11 @@
|
|||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_CUDA
|
||||
# include "backend/cuda/CudaThreads.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
|
@ -167,4 +172,8 @@ template class Threads<CpuThreads>;
|
|||
template class Threads<OclThreads>;
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_FEATURE_CUDA
|
||||
template class Threads<CudaThreads>;
|
||||
#endif
|
||||
|
||||
} // namespace xmrig
|
||||
|
|
217
src/backend/cuda/CudaBackend.cpp
Normal file
217
src/backend/cuda/CudaBackend.cpp
Normal file
|
@ -0,0 +1,217 @@
|
|||
/* 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 <string>
|
||||
|
||||
|
||||
#include "backend/cuda/CudaBackend.h"
|
||||
#include "backend/common/Hashrate.h"
|
||||
#include "backend/common/interfaces/IWorker.h"
|
||||
#include "backend/common/Tags.h"
|
||||
#include "backend/common/Workers.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>;
|
||||
|
||||
|
||||
constexpr const size_t oneMiB = 1024u * 1024u;
|
||||
static const char *tag = MAGENTA_BG_BOLD(WHITE_BOLD_S " nv ");
|
||||
static const String kType = "cuda";
|
||||
static std::mutex mutex;
|
||||
|
||||
|
||||
|
||||
class CudaBackendPrivate
|
||||
{
|
||||
public:
|
||||
inline CudaBackendPrivate(Controller *controller) :
|
||||
controller(controller)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void init(const OclConfig &cl)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline void start(const Job &job)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Algorithm algo;
|
||||
Controller *controller;
|
||||
String profileName;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
const char *xmrig::cuda_tag()
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
xmrig::CudaBackend::CudaBackend(Controller *controller) :
|
||||
d_ptr(new CudaBackendPrivate(controller))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::CudaBackend::~CudaBackend()
|
||||
{
|
||||
delete d_ptr;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::CudaBackend::isEnabled() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::CudaBackend::isEnabled(const Algorithm &algorithm) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const xmrig::Hashrate *xmrig::CudaBackend::hashrate() const
|
||||
{
|
||||
return nullptr;
|
||||
// return d_ptr->workers.hashrate();
|
||||
}
|
||||
|
||||
|
||||
const xmrig::String &xmrig::CudaBackend::profileName() const
|
||||
{
|
||||
return d_ptr->profileName;
|
||||
}
|
||||
|
||||
|
||||
const xmrig::String &xmrig::CudaBackend::type() const
|
||||
{
|
||||
return kType;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CudaBackend::prepare(const Job &)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CudaBackend::printHashrate(bool details)
|
||||
{
|
||||
if (!details || !hashrate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
char num[8 * 3] = { 0 };
|
||||
|
||||
Log::print(WHITE_BOLD_S "| CUDA # | AFFINITY | 10s H/s | 60s H/s | 15m H/s |");
|
||||
|
||||
// size_t i = 0;
|
||||
// for (const OclLaunchData &data : d_ptr->threads) {
|
||||
// Log::print("| %8zu | %8" PRId64 " | %7s | %7s | %7s |" CYAN_BOLD(" #%u") YELLOW(" %s") " %s",
|
||||
// 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),
|
||||
// data.device.index(),
|
||||
// data.device.topology().toString().data(),
|
||||
// data.device.printableName().data()
|
||||
// );
|
||||
|
||||
// i++;
|
||||
// }
|
||||
|
||||
Log::print(WHITE_BOLD_S "| - | - | %7s | %7s | %7s |",
|
||||
Hashrate::format(hashrate()->calc(Hashrate::ShortInterval), num, sizeof num / 3),
|
||||
Hashrate::format(hashrate()->calc(Hashrate::MediumInterval), num + 8, sizeof num / 3),
|
||||
Hashrate::format(hashrate()->calc(Hashrate::LargeInterval), num + 8 * 2, sizeof num / 3)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CudaBackend::setJob(const Job &job)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CudaBackend::start(IWorker *worker, bool ready)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CudaBackend::stop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CudaBackend::tick(uint64_t ticks)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_API
|
||||
rapidjson::Value xmrig::CudaBackend::toJSON(rapidjson::Document &doc) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
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);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CudaBackend::handleRequest(IApiRequest &)
|
||||
{
|
||||
}
|
||||
#endif
|
79
src/backend/cuda/CudaBackend.h
Normal file
79
src/backend/cuda/CudaBackend.h
Normal file
|
@ -0,0 +1,79 @@
|
|||
/* 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_CUDABACKEND_H
|
||||
#define XMRIG_CUDABACKEND_H
|
||||
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
||||
#include "backend/common/interfaces/IBackend.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Controller;
|
||||
class CudaBackendPrivate;
|
||||
class Miner;
|
||||
|
||||
|
||||
class CudaBackend : public IBackend
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(CudaBackend)
|
||||
|
||||
CudaBackend(Controller *controller);
|
||||
|
||||
~CudaBackend() 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, bool ready) 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:
|
||||
CudaBackendPrivate *d_ptr;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_CUDABACKEND_H */
|
115
src/backend/cuda/CudaConfig.cpp
Normal file
115
src/backend/cuda/CudaConfig.cpp
Normal file
|
@ -0,0 +1,115 @@
|
|||
/* 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/cuda/CudaConfig.h"
|
||||
#include "backend/cuda/CudaConfig_gen.h"
|
||||
#include "base/io/json/Json.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
static const char *kDevicesHint = "devices-hint";
|
||||
static const char *kEnabled = "enabled";
|
||||
|
||||
|
||||
extern template class Threads<CudaThreads>;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
rapidjson::Value xmrig::CudaConfig::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;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CudaConfig::read(const rapidjson::Value &value)
|
||||
{
|
||||
if (value.IsObject()) {
|
||||
m_enabled = Json::getBool(value, kEnabled, m_enabled);
|
||||
|
||||
setDevicesHint(Json::getString(value, kDevicesHint));
|
||||
|
||||
m_threads.read(value);
|
||||
|
||||
generate();
|
||||
}
|
||||
else if (value.IsBool()) {
|
||||
m_enabled = value.GetBool();
|
||||
|
||||
generate();
|
||||
}
|
||||
else {
|
||||
m_shouldSave = true;
|
||||
|
||||
generate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CudaConfig::generate()
|
||||
{
|
||||
if (!isEnabled() || m_threads.has("*")) {
|
||||
return;
|
||||
}
|
||||
|
||||
size_t count = 0;
|
||||
|
||||
// count += xmrig::generate<Algorithm::CN>(m_threads, devices);
|
||||
// count += xmrig::generate<Algorithm::CN_LITE>(m_threads, devices);
|
||||
// count += xmrig::generate<Algorithm::CN_HEAVY>(m_threads, devices);
|
||||
// count += xmrig::generate<Algorithm::CN_PICO>(m_threads, devices);
|
||||
// count += xmrig::generate<Algorithm::RANDOM_X>(m_threads, devices);
|
||||
|
||||
m_shouldSave = count > 0;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CudaConfig::setDevicesHint(const char *devicesHint)
|
||||
{
|
||||
if (devicesHint == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto indexes = String(devicesHint).split(',');
|
||||
m_devicesHint.reserve(indexes.size());
|
||||
|
||||
for (const auto &index : indexes) {
|
||||
m_devicesHint.push_back(strtoul(index, nullptr, 10));
|
||||
}
|
||||
}
|
62
src/backend/cuda/CudaConfig.h
Normal file
62
src/backend/cuda/CudaConfig.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_CUDACONFIG_H
|
||||
#define XMRIG_CUDACONFIG_H
|
||||
|
||||
|
||||
#include "backend/common/Threads.h"
|
||||
#include "backend/cuda/CudaThreads.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class CudaConfig
|
||||
{
|
||||
public:
|
||||
CudaConfig() = default;
|
||||
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
void read(const rapidjson::Value &value);
|
||||
|
||||
inline bool isEnabled() const { return m_enabled; }
|
||||
inline bool isShouldSave() const { return m_shouldSave; }
|
||||
inline const Threads<CudaThreads> &threads() const { return m_threads; }
|
||||
|
||||
private:
|
||||
void generate();
|
||||
void setDevicesHint(const char *devicesHint);
|
||||
|
||||
bool m_enabled = false;
|
||||
bool m_shouldSave = false;
|
||||
std::vector<uint32_t> m_devicesHint;
|
||||
Threads<CudaThreads> m_threads;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_CUDACONFIG_H */
|
42
src/backend/cuda/CudaConfig_gen.h
Normal file
42
src/backend/cuda/CudaConfig_gen.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* 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_GEN_H
|
||||
#define XMRIG_OCLCONFIG_GEN_H
|
||||
|
||||
|
||||
#include "backend/common/Threads.h"
|
||||
#include "backend/cuda/CudaThreads.h"
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_OCLCONFIG_GEN_H */
|
63
src/backend/cuda/CudaThread.cpp
Normal file
63
src/backend/cuda/CudaThread.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/* 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/cuda/CudaThread.h"
|
||||
|
||||
#include "base/io/json/Json.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::CudaThread::CudaThread(const rapidjson::Value &value)
|
||||
{
|
||||
if (!value.IsObject()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::CudaThread::isEqual(const CudaThread &other) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
rapidjson::Value xmrig::CudaThread::toJSON(rapidjson::Document &doc) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
Value out(kObjectType);
|
||||
|
||||
return out;
|
||||
}
|
62
src/backend/cuda/CudaThread.h
Normal file
62
src/backend/cuda/CudaThread.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_CUDATHREAD_H
|
||||
#define XMRIG_CUDATHREAD_H
|
||||
|
||||
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
#include <bitset>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class CudaThread
|
||||
{
|
||||
public:
|
||||
CudaThread() = delete;
|
||||
|
||||
CudaThread(const rapidjson::Value &value);
|
||||
|
||||
inline bool isValid() const { return false; }
|
||||
|
||||
inline bool operator!=(const CudaThread &other) const { return !isEqual(other); }
|
||||
inline bool operator==(const CudaThread &other) const { return isEqual(other); }
|
||||
|
||||
bool isEqual(const CudaThread &other) const;
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_CUDATHREAD_H */
|
71
src/backend/cuda/CudaThreads.cpp
Normal file
71
src/backend/cuda/CudaThreads.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 "backend/cuda/CudaThreads.h"
|
||||
#include "base/io/json/Json.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
xmrig::CudaThreads::CudaThreads(const rapidjson::Value &value)
|
||||
{
|
||||
if (value.IsArray()) {
|
||||
for (auto &v : value.GetArray()) {
|
||||
CudaThread thread(v);
|
||||
if (thread.isValid()) {
|
||||
add(std::move(thread));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::CudaThreads::isEqual(const CudaThreads &other) const
|
||||
{
|
||||
if (isEmpty() && other.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return count() == other.count() && std::equal(m_data.begin(), m_data.end(), other.m_data.begin());
|
||||
}
|
||||
|
||||
|
||||
rapidjson::Value xmrig::CudaThreads::toJSON(rapidjson::Document &doc) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
Value out(kArrayType);
|
||||
|
||||
out.SetArray();
|
||||
|
||||
for (const CudaThread &thread : m_data) {
|
||||
out.PushBack(thread.toJSON(doc), allocator);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
64
src/backend/cuda/CudaThreads.h
Normal file
64
src/backend/cuda/CudaThreads.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_CUDATHREADS_H
|
||||
#define XMRIG_CUDATHREADS_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
#include "backend/cuda/CudaThread.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class CudaThreads
|
||||
{
|
||||
public:
|
||||
CudaThreads() = default;
|
||||
CudaThreads(const rapidjson::Value &value);
|
||||
|
||||
inline bool isEmpty() const { return m_data.empty(); }
|
||||
inline const std::vector<CudaThread> &data() const { return m_data; }
|
||||
inline size_t count() const { return m_data.size(); }
|
||||
inline void add(CudaThread &&thread) { m_data.push_back(thread); }
|
||||
inline void reserve(size_t capacity) { m_data.reserve(capacity); }
|
||||
|
||||
inline bool operator!=(const CudaThreads &other) const { return !isEqual(other); }
|
||||
inline bool operator==(const CudaThreads &other) const { return isEqual(other); }
|
||||
|
||||
bool isEqual(const CudaThreads &other) const;
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
|
||||
private:
|
||||
std::vector<CudaThread> m_data;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_CUDATHREADS_H */
|
23
src/backend/cuda/cuda.cmake
Normal file
23
src/backend/cuda/cuda.cmake
Normal file
|
@ -0,0 +1,23 @@
|
|||
if (WITH_CUDA)
|
||||
add_definitions(/DXMRIG_FEATURE_CUDA)
|
||||
|
||||
set(HEADERS_BACKEND_CUDA
|
||||
src/backend/cuda/CudaBackend.h
|
||||
src/backend/cuda/CudaConfig.h
|
||||
src/backend/cuda/CudaConfig_gen.h
|
||||
src/backend/cuda/CudaThread.h
|
||||
src/backend/cuda/CudaThreads.h
|
||||
)
|
||||
|
||||
set(SOURCES_BACKEND_CUDA
|
||||
src/backend/cuda/CudaBackend.cpp
|
||||
src/backend/cuda/CudaConfig.cpp
|
||||
src/backend/cuda/CudaThread.cpp
|
||||
src/backend/cuda/CudaThreads.cpp
|
||||
)
|
||||
else()
|
||||
remove_definitions(/DXMRIG_FEATURE_CUDA)
|
||||
|
||||
set(HEADERS_BACKEND_CUDA "")
|
||||
set(SOURCES_BACKEND_CUDA "")
|
||||
endif()
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
|
||||
#include "backend/common/interfaces/IBackend.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -43,16 +44,12 @@ class Miner;
|
|||
class OclBackend : public IBackend
|
||||
{
|
||||
public:
|
||||
OclBackend() = delete;
|
||||
OclBackend(const OclBackend &other) = delete;
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(OclBackend)
|
||||
|
||||
OclBackend(Controller *controller);
|
||||
OclBackend(OclBackend &&other) = delete;
|
||||
|
||||
~OclBackend() override;
|
||||
|
||||
OclBackend &operator=(const OclBackend &other) = delete;
|
||||
OclBackend &operator=(OclBackend &&other) = delete;
|
||||
|
||||
protected:
|
||||
bool isEnabled() const override;
|
||||
bool isEnabled(const Algorithm &algorithm) const override;
|
||||
|
|
|
@ -56,6 +56,11 @@
|
|||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_CUDA
|
||||
# include "backend/cuda/CudaBackend.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_ALGO_RANDOMX
|
||||
# include "crypto/rx/RxConfig.h"
|
||||
#endif
|
||||
|
@ -270,12 +275,17 @@ xmrig::Miner::Miner(Controller *controller)
|
|||
|
||||
d_ptr->timer = new Timer(this);
|
||||
|
||||
d_ptr->backends.reserve(3);
|
||||
d_ptr->backends.push_back(new CpuBackend(controller));
|
||||
|
||||
# ifdef XMRIG_FEATURE_OPENCL
|
||||
d_ptr->backends.push_back(new OclBackend(controller));
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_CUDA
|
||||
d_ptr->backends.push_back(new CudaBackend(controller));
|
||||
# endif
|
||||
|
||||
d_ptr->rebuild();
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,11 @@
|
|||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_CUDA
|
||||
# include "backend/cuda/CudaConfig.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
static const char *kCPU = "cpu";
|
||||
|
@ -60,6 +65,10 @@ static const char *kRandomX = "randomx";
|
|||
static const char *kOcl = "opencl";
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_FEATURE_CUDA
|
||||
static const char *kCuda = "cuda";
|
||||
#endif
|
||||
|
||||
|
||||
class ConfigPrivate
|
||||
{
|
||||
|
@ -73,6 +82,10 @@ public:
|
|||
# ifdef XMRIG_FEATURE_OPENCL
|
||||
OclConfig cl;
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_CUDA
|
||||
CudaConfig cuda;
|
||||
# endif
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -104,6 +117,14 @@ const xmrig::OclConfig &xmrig::Config::cl() const
|
|||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_CUDA
|
||||
const xmrig::CudaConfig &xmrig::Config::cuda() const
|
||||
{
|
||||
return d_ptr->cuda;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_ALGO_RANDOMX
|
||||
const xmrig::RxConfig &xmrig::Config::rx() const
|
||||
{
|
||||
|
@ -124,6 +145,12 @@ bool xmrig::Config::isShouldSave() const
|
|||
}
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_CUDA
|
||||
if (cuda().isShouldSave()) {
|
||||
return true;
|
||||
}
|
||||
# endif
|
||||
|
||||
return (m_upgrade || cpu().isShouldSave());
|
||||
}
|
||||
|
||||
|
@ -146,6 +173,10 @@ bool xmrig::Config::read(const IJsonReader &reader, const char *fileName)
|
|||
d_ptr->cl.read(reader.getValue(kOcl));
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_CUDA
|
||||
d_ptr->cuda.read(reader.getValue(kCuda));
|
||||
# endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -178,6 +209,10 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
|
|||
doc.AddMember(StringRef(kOcl), cl().toJSON(doc), allocator);
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_CUDA
|
||||
doc.AddMember(StringRef(kCuda), cuda().toJSON(doc), allocator);
|
||||
# endif
|
||||
|
||||
doc.AddMember("donate-level", m_pools.donateLevel(), allocator);
|
||||
doc.AddMember("donate-over-proxy", m_pools.proxyDonate(), allocator);
|
||||
doc.AddMember("log-file", m_logFile.toJSON(), allocator);
|
||||
|
|
|
@ -39,9 +39,10 @@ namespace xmrig {
|
|||
|
||||
|
||||
class ConfigPrivate;
|
||||
class CudaConfig;
|
||||
class IThread;
|
||||
class RxConfig;
|
||||
class OclConfig;
|
||||
class RxConfig;
|
||||
|
||||
|
||||
class Config : public BaseConfig
|
||||
|
@ -58,6 +59,10 @@ public:
|
|||
const OclConfig &cl() const;
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_CUDA
|
||||
const CudaConfig &cuda() const;
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
const RxConfig &rx() const;
|
||||
# endif
|
||||
|
|
Loading…
Reference in a new issue