WIP GPU integration

This commit is contained in:
BenDr0id 2018-08-14 15:43:54 +02:00
parent cbc56a3a64
commit c91c7cd798
12 changed files with 432 additions and 110 deletions

View file

@ -1,10 +1,4 @@
/* 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 2016-2017 XMRig <support@xmrig.com>
/* XMRigCC
* Copyright 2017- BenDr0id <ben@graef.in>
*
*
@ -28,18 +22,26 @@
#include <3rdparty/rapidjson/stringbuffer.h>
#include <3rdparty/rapidjson/prettywriter.h>
#include <version.h>
#include <log/RemoteLog.h>
#include <api/NetworkState.h>
#include "CCClient.h"
#include "App.h"
#include "Platform.h"
#include "Cpu.h"
#include "Mem.h"
#include "ControlCommand.h"
#include "api/NetworkState.h"
#ifdef TYPE_AMD_GPU
#include "common/log/Log.h"
#include "common/log/RemoteLog.h"
#include "common/Platform.h"
#include "core/Config.h"
#else
#include "Mem.h"
#include "log/Log.h"
#include "log/RemoteLog.h"
#include "Platform.h"
#include "api/NetworkState.h"
#endif
#include "workers/Workers.h"
#include "workers/Hashrate.h"
@ -55,8 +57,12 @@
CCClient* CCClient::m_self = nullptr;
uv_mutex_t CCClient::m_mutex;
CCClient::CCClient(Options* options, uv_async_t* async)
: m_options(options),
#ifdef TYPE_AMD_GPU
CCClient::CCClient(xmrig::Config* config, uv_async_t* async)
#else
CCClient::CCClient(Options* config, uv_async_t* async)
#endif
: m_config(config),
m_async(async)
{
uv_mutex_init(&m_mutex);
@ -64,8 +70,8 @@ CCClient::CCClient(Options* options, uv_async_t* async)
m_self = this;
std::string clientId;
if (m_options->ccWorkerId()) {
clientId = m_options->ccWorkerId();
if (config->ccWorkerId()) {
clientId =m_self->m_config->ccWorkerId();
} else {
char hostname[128];
memset(hostname, 0, sizeof(hostname));
@ -74,27 +80,28 @@ CCClient::CCClient(Options* options, uv_async_t* async)
}
m_clientStatus.setClientId(clientId);
if (m_options->algoName() != nullptr) {
m_clientStatus.setCurrentAlgoName(m_options->algoName());
}
m_clientStatus.setHashFactor(Mem::hashFactor());
m_clientStatus.setVersion(Version::string());
m_clientStatus.setCpuBrand(Cpu::brand());
m_clientStatus.setCpuAES(Cpu::hasAES());
m_clientStatus.setCpuSockets(Cpu::sockets());
m_clientStatus.setCpuCores(Cpu::cores());
m_clientStatus.setCpuThreads(Cpu::threads());
m_clientStatus.setCpuSockets(static_cast<int>(Cpu::sockets()));
m_clientStatus.setCpuCores(static_cast<int>(Cpu::cores()));
m_clientStatus.setCpuThreads(static_cast<int>(Cpu::threads()));
m_clientStatus.setCpuX64(Cpu::isX64());
m_clientStatus.setCpuL2(Cpu::l2());
m_clientStatus.setCpuL3(Cpu::l3());
m_clientStatus.setCurrentThreads(m_options->threads());
m_clientStatus.setCpuL2(static_cast<int>(Cpu::l2()));
m_clientStatus.setCpuL3(static_cast<int>(Cpu::l3()));
#ifdef TYPE_AMD_GPU
m_clientStatus.setCurrentThreads(static_cast<int>(config->threads().size()));
m_clientStatus.setCurrentAlgoName(config->algorithm().name());
#else
m_clientStatus.setCurrentThreads(static_cast<int>(config->threads()));
m_clientStatus.setCurrentAlgoName(config->algoName());
#endif
m_startTime = std::chrono::system_clock::now();
if (m_options->ccToken() != nullptr) {
m_authorization = std::string("Bearer ") + m_self->m_options->ccToken();
if (config->ccToken() != nullptr) {
m_authorization = std::string("Bearer ") + m_self->m_config->ccToken();
}
uv_thread_create(&m_thread, CCClient::onThreadStarted, this);
@ -133,16 +140,54 @@ void CCClient::updateNetworkState(const NetworkState& network)
m_self->m_clientStatus.setHashesTotal(network.total);
m_self->m_clientStatus.setAvgTime(network.avgTime());
#ifdef TYPE_AMD_GPU
m_clientStatus.setHashFactor(0);
m_self->m_clientStatus.setHugepagesEnabled(false);
m_self->m_clientStatus.setHugepages(false);
m_self->m_clientStatus.setTotalPages(0);
m_self->m_clientStatus.setTotalHugepages(0);
m_self->m_clientStatus.setCurrentPowVariantName(xmrig::Algorithm::getVariantName(network.powVariant));
#else
m_self->m_clientStatus.setHashFactor(Mem::hashFactor());
m_self->m_clientStatus.setHugepagesEnabled(Mem::isHugepagesEnabled());
m_self->m_clientStatus.setHugepages(Mem::isHugepagesAvailable());
m_self->m_clientStatus.setTotalPages(Mem::getTotalPages());
m_self->m_clientStatus.setTotalHugepages(Mem::getTotalHugepages());
m_self->m_clientStatus.setCurrentPowVariantName(getPowVariantName(network.powVariant));
#endif
uv_mutex_unlock(&m_mutex);
}
}
#ifdef TYPE_AMD_GPU
void CCClient::updateGpuInfo(const std::vector<GpuContext>& gpuContext)
{
if (m_self) {
uv_mutex_lock(&m_mutex);
m_self->m_clientStatus.clearGPUInfoList();
for (auto gpu : gpuContext) {
GPUInfo gpuInfo;
gpuInfo.setName(gpu.name);
gpuInfo.setCompMode(gpu.compMode);
gpuInfo.setComputeUnits(gpu.computeUnits);
gpuInfo.setDeviceIdx(gpu.deviceIdx);
gpuInfo.setFreeMem(gpu.freeMem);
gpuInfo.setWorkSize(gpu.workSize);
gpuInfo.setMaxWorkSize(gpu.maximumWorkSize);
gpuInfo.setMemChunk(gpu.memChunk);
gpuInfo.setRawIntensity(gpu.rawIntensity);
m_self->m_clientStatus.addGPUInfo(gpuInfo);
}
uv_mutex_unlock(&m_mutex);
}
}
#endif
void CCClient::publishClientStatusReport()
{
std::string requestUrl = "/client/setClientStatus?clientId=" + m_self->m_clientStatus.getClientId();
@ -151,10 +196,10 @@ void CCClient::publishClientStatusReport()
auto res = performRequest(requestUrl, requestBuffer, "POST");
if (!res) {
LOG_ERR("[CC-Client] error: unable to performRequest POST -> http://%s:%d%s",
m_self->m_options->ccHost(), m_self->m_options->ccPort(), requestUrl.c_str());
m_self->m_config->ccHost(), m_self->m_config->ccPort(), requestUrl.c_str());
} else if (res->status != 200) {
LOG_ERR("[CC-Client] error: \"%d\" -> http://%s:%d%s", res->status, m_self->m_options->ccHost(),
m_self->m_options->ccPort(), requestUrl.c_str());
LOG_ERR("[CC-Client] error: \"%d\" -> http://%s:%d%s", res->status,m_self->m_config->ccHost(),
m_self->m_config->ccPort(), requestUrl.c_str());
} else {
ControlCommand controlCommand;
if (controlCommand.parseFromJsonString(res->body)) {
@ -194,14 +239,14 @@ void CCClient::updateConfig()
auto res = performRequest(requestUrl, requestBuffer, "GET");
if (!res) {
LOG_ERR("[CC-Client] error: unable to performRequest GET -> http://%s:%d%s",
m_self->m_options->ccHost(), m_self->m_options->ccPort(), requestUrl.c_str());
m_self->m_config->ccHost(), m_self->m_config->ccPort(), requestUrl.c_str());
} else if (res->status != 200) {
LOG_ERR("[CC-Client] error: \"%d\" -> http://%s:%d%s", res->status, m_self->m_options->ccHost(),
m_self->m_options->ccPort(), requestUrl.c_str());
LOG_ERR("[CC-Client] error: \"%d\" -> http://%s:%d%s", res->status, m_self->m_config->ccHost(),
m_self->m_config->ccPort(), requestUrl.c_str());
} else {
rapidjson::Document document;
if (!document.Parse(res->body.c_str()).HasParseError()) {
std::ofstream clientConfigFile(m_self->m_options->configFile());
std::ofstream clientConfigFile(m_self->m_config->fileName());
if (clientConfigFile) {
rapidjson::StringBuffer buffer(0, 65536);
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
@ -213,7 +258,7 @@ void CCClient::updateConfig()
LOG_WARN("[CC-Client] Config updated. -> trigger restart");
} else {
LOG_ERR("[CC-Client] Not able to store client config to file %s.", m_self->m_options->configFile());
LOG_ERR("[CC-Client] Not able to store client config to file %s.", m_self->m_config->fileName());
}
} else {
LOG_ERR("[CC-Client] Not able to store client config. received client config is broken!");
@ -226,7 +271,7 @@ void CCClient::publishConfig()
std::string requestUrl = "/client/setClientConfig?clientId=" + m_self->m_clientStatus.getClientId();
std::stringstream data;
std::ifstream clientConfig(m_self->m_options->configFile());
std::ifstream clientConfig(m_self->m_config->fileName());
if (clientConfig) {
data << clientConfig.rdbuf();
@ -246,16 +291,16 @@ void CCClient::publishConfig()
auto res = performRequest(requestUrl, buffer.GetString(), "POST");
if (!res) {
LOG_ERR("[CC-Client] error: unable to performRequest POST -> http://%s:%d%s",
m_self->m_options->ccHost(), m_self->m_options->ccPort(), requestUrl.c_str());
m_self->m_config->ccHost(), m_self->m_config->ccPort(), requestUrl.c_str());
} else if (res->status != 200) {
LOG_ERR("[CC-Client] error: \"%d\" -> http://%s:%d%s", res->status, m_self->m_options->ccHost(),
m_self->m_options->ccPort(), requestUrl.c_str());
LOG_ERR("[CC-Client] error: \"%d\" -> http://%s:%d%s", res->status, m_self->m_config->ccHost(),
m_self->m_config->ccPort(), requestUrl.c_str());
}
} else {
LOG_ERR("Not able to send config. Client config %s is broken!", m_self->m_options->configFile());
LOG_ERR("Not able to send config. Client config %s is broken!", m_self->m_config->fileName());
}
} else {
LOG_ERR("Not able to load client config %s. Please make sure it exists!", m_self->m_options->configFile());
LOG_ERR("Not able to load client config %s. Please make sure it exists!", m_self->m_config->fileName());
}
}
@ -266,11 +311,11 @@ std::shared_ptr<httplib::Response> CCClient::performRequest(const std::string& r
std::shared_ptr<httplib::Client> cli;
# ifndef XMRIG_NO_TLS
if (m_self->m_options->ccUseTls()) {
cli = std::make_shared<httplib::SSLClient>(m_self->m_options->ccHost(), m_self->m_options->ccPort(), 10);
if (m_self->m_config->ccUseTls()) {
cli = std::make_shared<httplib::SSLClient>(m_self->m_config->ccHost(), m_self->m_config->ccPort(), 10);
} else {
# endif
cli = std::make_shared<httplib::Client>(m_self->m_options->ccHost(), m_self->m_options->ccPort(), 10);
cli = std::make_shared<httplib::Client>(m_self->m_config->ccHost(), m_self->m_config->ccPort(), 10);
# ifndef XMRIG_NO_TLS
}
# endif
@ -317,10 +362,10 @@ void CCClient::onThreadStarted(void* handle)
uv_timer_init(&m_self->m_client_loop, &m_self->m_timer);
uv_timer_start(&m_self->m_timer, CCClient::onReport,
static_cast<uint64_t>(m_self->m_options->ccUpdateInterval() * 1000),
static_cast<uint64_t>(m_self->m_options->ccUpdateInterval() * 1000));
static_cast<uint64_t>(m_self->m_config->ccUpdateInterval() * 1000),
static_cast<uint64_t>(m_self->m_config->ccUpdateInterval() * 1000));
if (m_self->m_options->ccUploadConfigOnStartup()) {
if (m_self->m_config->ccUploadConfigOnStartup()) {
m_self->publishConfig();
}