Better cl_context wrapping.

This commit is contained in:
XMRig 2019-09-01 07:37:02 +07:00
parent b541960611
commit 10d2c0285c
7 changed files with 23 additions and 8 deletions

View file

@ -55,7 +55,7 @@ static cl_program createFromSource(const IOclRunner *runner)
const char *source = runner->source();
const uint64_t ts = Chrono::steadyMSecs();
cl_program program = OclLib::createProgramWithSource(runner->data().ctx, 1, &source, nullptr, &ret);
cl_program program = OclLib::createProgramWithSource(runner->ctx(), 1, &source, nullptr, &ret);
if (ret != CL_SUCCESS) {
return nullptr;
}
@ -91,7 +91,7 @@ static cl_program createFromBinary(const IOclRunner *runner, const std::string &
cl_int clStatus;
cl_int ret;
cl_program program = OclLib::createProgramWithBinary(runner->data().ctx, 1, &device, &bin_size, reinterpret_cast<const unsigned char **>(&data_ptr), &clStatus, &ret);
cl_program program = OclLib::createProgramWithBinary(runner->ctx(), 1, &device, &bin_size, reinterpret_cast<const unsigned char **>(&data_ptr), &clStatus, &ret);
if (ret != CL_SUCCESS) {
return nullptr;
}

View file

@ -29,6 +29,9 @@
#include <stdint.h>
typedef struct _cl_context *cl_context;
namespace xmrig {
@ -44,6 +47,7 @@ public:
virtual bool run(uint32_t nonce, uint32_t *hashOutput) = 0;
virtual bool selfTest() const = 0;
virtual bool set(const Job &job, uint8_t *blob) = 0;
virtual cl_context ctx() const = 0;
virtual const char *buildOptions() const = 0;
virtual const char *deviceKey() const = 0;
virtual const char *source() const = 0;

View file

@ -34,18 +34,19 @@
xmrig::OclBaseRunner::OclBaseRunner(size_t id, const OclLaunchData &data) :
m_algorithm(data.algorithm),
m_ctx(data.ctx),
m_source(OclSource::get(data.algorithm)),
m_data(data),
m_threadId(id)
{
cl_int ret;
m_queue = OclLib::createCommandQueue(data.ctx, data.device.id(), &ret);
m_queue = OclLib::createCommandQueue(m_ctx, data.device.id(), &ret);
if (ret != CL_SUCCESS) {
return;
}
m_input = OclLib::createBuffer(data.ctx, CL_MEM_READ_ONLY, Job::kMaxBlobSize, nullptr, &ret);
m_output = OclLib::createBuffer(data.ctx, CL_MEM_READ_WRITE, sizeof(cl_uint) * 0x100, nullptr, &ret);
m_input = OclLib::createBuffer(m_ctx, CL_MEM_READ_ONLY, Job::kMaxBlobSize, nullptr, &ret);
m_output = OclLib::createBuffer(m_ctx, CL_MEM_READ_WRITE, sizeof(cl_uint) * 0x100, nullptr, &ret);
m_deviceKey = data.device.name();

View file

@ -47,6 +47,7 @@ public:
~OclBaseRunner() override;
protected:
inline cl_context ctx() const override { return m_ctx; }
inline const char *buildOptions() const override { return m_options.c_str(); }
inline const char *deviceKey() const override { return m_deviceKey.c_str(); }
inline const char *source() const override { return m_source; }
@ -60,6 +61,7 @@ protected:
protected:
Algorithm m_algorithm;
cl_command_queue m_queue = nullptr;
cl_context m_ctx;
cl_mem m_input = nullptr;
cl_mem m_output = nullptr;
cl_program m_program = nullptr;

View file

@ -41,18 +41,18 @@ xmrig::OclCnRunner::OclCnRunner(size_t index, const OclLaunchData &data) : OclBa
const size_t g_thd = data.thread.intensity();
cl_int ret;
m_scratchpads = OclLib::createBuffer(data.ctx, CL_MEM_READ_WRITE, data.algorithm.l3() * g_thd, nullptr, &ret);
m_scratchpads = OclLib::createBuffer(m_ctx, CL_MEM_READ_WRITE, data.algorithm.l3() * g_thd, nullptr, &ret);
if (ret != CL_SUCCESS) {
return;
}
m_states = OclLib::createBuffer(data.ctx, CL_MEM_READ_WRITE, 200 * g_thd, nullptr, &ret);
m_states = OclLib::createBuffer(m_ctx, CL_MEM_READ_WRITE, 200 * g_thd, nullptr, &ret);
if (ret != CL_SUCCESS) {
return;
}
for (size_t i = 0; i < BRANCH_MAX; ++i) {
m_branches[i] = OclLib::createBuffer(data.ctx, CL_MEM_READ_WRITE, sizeof(cl_uint) * (g_thd + 2), nullptr, &ret);
m_branches[i] = OclLib::createBuffer(m_ctx, CL_MEM_READ_WRITE, sizeof(cl_uint) * (g_thd + 2), nullptr, &ret);
if (ret != CL_SUCCESS) {
return;
}

View file

@ -27,6 +27,13 @@
#include "backend/opencl/wrappers/OclContext.h"
xmrig::OclContext::OclContext(const OclDevice &device)
{
std::vector<cl_device_id> ids = { device.id() };
m_ctx = OclLib::createContext(ids);
}
xmrig::OclContext::~OclContext()
{
if (m_ctx) {

View file

@ -40,6 +40,7 @@ class OclContext
{
public:
OclContext() = default;
OclContext(const OclDevice &device);
~OclContext();
bool init(const std::vector<OclDevice> &devices, std::vector<OclLaunchData> &threads);