Added OclContext class.

This commit is contained in:
XMRig 2019-08-24 14:58:50 +07:00
parent 2a07bc4ef3
commit cf123b7d88
9 changed files with 161 additions and 16 deletions

View file

@ -32,6 +32,7 @@
#include "backend/opencl/OclBackend.h"
#include "backend/opencl/OclConfig.h"
#include "backend/opencl/OclLaunchData.h"
#include "backend/opencl/wrappers/OclContext.h"
#include "backend/opencl/wrappers/OclLib.h"
#include "base/io/log/Log.h"
#include "base/net/stratum/Job.h"
@ -119,27 +120,14 @@ public:
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("#%zu ") WHITE_BOLD("%s") "/" WHITE_BOLD("%s"), "OPENCL", platform.index(), platform.name().data(), platform.version().data());
for (const OclDevice &device : devices) {
const String topo = device.hasTopology() ? device.topology().toString() : "n/a";
const size_t size = device.board().size() + device.name().size() + 64;
char *name = new char[size]();
if (device.board() == device.name()) {
snprintf(name, size, GREEN_BOLD(" %s"), device.name().data());
}
else {
snprintf(name, size, GREEN_BOLD(" %s") " (" CYAN_BOLD("%s") ")", device.board().data(), device.name().data());
}
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("#%zu") YELLOW(" %s") "%s " WHITE_BOLD("%uMHz") " cu:" WHITE_BOLD("%u") " mem:" CYAN("%1.2f/%1.2f") " GB", "OPENCL GPU",
device.index(),
topo.data(),
name,
device.hasTopology() ? device.topology().toString().data() : "n/a",
device.printableName().data(),
device.clock(),
device.computeUnits(),
static_cast<double>(device.freeMem()) / oneGiB,
static_cast<double>(device.globalMem()) / oneGiB);
delete [] name;
}
}
@ -166,6 +154,7 @@ public:
Algorithm algo;
Controller *controller;
LaunchStatus status;
OclContext context;
OclPlatform platform;
std::mutex mutex;
std::vector<OclDevice> devices;
@ -275,6 +264,12 @@ void xmrig::OclBackend::setJob(const Job &job)
return stop();
}
if (!d_ptr->context.init(d_ptr->devices, threads)) {
LOG_WARN("%s " RED_BOLD("disabled") YELLOW(" (OpenCL context unavailable)"), tag);
return stop();
}
d_ptr->threads = std::move(threads);
d_ptr->start();
}