Added platform option.
This commit is contained in:
parent
476e5dcb18
commit
166a68244e
9 changed files with 194 additions and 26 deletions
|
@ -123,26 +123,36 @@ static setKernelArg_t pSetKernelArg = nu
|
|||
#define DLSYM(x) if (uv_dlsym(&oclLib, k##x, reinterpret_cast<void**>(&p##x)) == -1) { return false; }
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
bool OclLib::m_initialized = false;
|
||||
bool OclLib::m_ready = false;
|
||||
String OclLib::m_loader;
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
bool xmrig::OclLib::init(const char *fileName)
|
||||
{
|
||||
if (uv_dlopen(fileName == nullptr ? defaultLoader() : fileName, &oclLib) == -1 || !load()) {
|
||||
LOG_ERR("Failed to load OpenCL runtime: %s", uv_dlerror(&oclLib));
|
||||
return false;
|
||||
if (!m_initialized) {
|
||||
m_loader = fileName == nullptr ? defaultLoader() : fileName;
|
||||
m_ready = uv_dlopen(m_loader, &oclLib) == 0 && load();
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
return m_ready;
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::OclLib::defaultLoader()
|
||||
const char *xmrig::OclLib::lastError()
|
||||
{
|
||||
# if defined(__APPLE__)
|
||||
return "/System/Library/Frameworks/OpenCL.framework/OpenCL";
|
||||
# elif defined(_WIN32)
|
||||
return "OpenCL.dll";
|
||||
# else
|
||||
return "libOpenCL.so";
|
||||
# endif
|
||||
return uv_dlerror(&oclLib);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::OclLib::close()
|
||||
{
|
||||
uv_dlclose(&oclLib);
|
||||
}
|
||||
|
||||
|
||||
|
@ -181,6 +191,18 @@ bool xmrig::OclLib::load()
|
|||
}
|
||||
|
||||
|
||||
const char *xmrig::OclLib::defaultLoader()
|
||||
{
|
||||
# if defined(__APPLE__)
|
||||
return "/System/Library/Frameworks/OpenCL.framework/OpenCL";
|
||||
# elif defined(_WIN32)
|
||||
return "OpenCL.dll";
|
||||
# else
|
||||
return "libOpenCL.so";
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
cl_command_queue xmrig::OclLib::createCommandQueue(cl_context context, cl_device_id device, cl_int *errcode_ret)
|
||||
{
|
||||
cl_command_queue result;
|
||||
|
|
|
@ -40,7 +40,10 @@ class OclLib
|
|||
{
|
||||
public:
|
||||
static bool init(const char *fileName = nullptr);
|
||||
static const char *defaultLoader();
|
||||
static const char *lastError();
|
||||
static void close();
|
||||
|
||||
static inline const String &loader() { return m_loader; }
|
||||
|
||||
static cl_command_queue createCommandQueue(cl_context context, cl_device_id device, cl_int *errcode_ret);
|
||||
static cl_context createContext(const cl_context_properties *properties, cl_uint num_devices, const cl_device_id *devices, void (CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *), void *user_data, cl_int *errcode_ret);
|
||||
|
@ -76,6 +79,11 @@ public:
|
|||
|
||||
private:
|
||||
static bool load();
|
||||
static const char *defaultLoader();
|
||||
|
||||
static bool m_initialized;
|
||||
static bool m_ready;
|
||||
static String m_loader;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -23,11 +23,9 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include "backend/opencl/wrappers/OclLib.h"
|
||||
#include "backend/opencl/wrappers/OclPlatform.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
||||
std::vector<xmrig::OclPlatform> xmrig::OclPlatform::get()
|
||||
|
@ -65,6 +63,27 @@ void xmrig::OclPlatform::print()
|
|||
}
|
||||
|
||||
|
||||
rapidjson::Value xmrig::OclPlatform::toJSON(rapidjson::Document &doc) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
if (!isValid()) {
|
||||
return Value(kNullType);
|
||||
}
|
||||
|
||||
Value out(kObjectType);
|
||||
out.AddMember("index", index(), allocator);
|
||||
out.AddMember("profile", profile().toJSON(doc), allocator);
|
||||
out.AddMember("version", version().toJSON(doc), allocator);
|
||||
out.AddMember("name", name().toJSON(doc), allocator);
|
||||
out.AddMember("vendor", vendor().toJSON(doc), allocator);
|
||||
out.AddMember("extensions", extensions().toJSON(doc), allocator);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::OclPlatform::extensions() const
|
||||
{
|
||||
return OclLib::getPlatformInfo(id(), CL_PLATFORM_EXTENSIONS);
|
||||
|
|
|
@ -47,9 +47,11 @@ public:
|
|||
static std::vector<OclPlatform> get();
|
||||
static void print();
|
||||
|
||||
inline bool isValid() const { return m_id != nullptr; }
|
||||
inline cl_platform_id id() const { return m_id; }
|
||||
inline size_t index() const { return m_index; }
|
||||
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
String extensions() const;
|
||||
String name() const;
|
||||
String profile() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue