diff --git a/src/backend/opencl/wrappers/OclLib.cpp b/src/backend/opencl/wrappers/OclLib.cpp index bb118525..f4b4a200 100644 --- a/src/backend/opencl/wrappers/OclLib.cpp +++ b/src/backend/opencl/wrappers/OclLib.cpp @@ -465,20 +465,7 @@ cl_uint xmrig::OclLib::getDeviceMaxComputeUnits(cl_device_id id) } -std::vector xmrig::OclLib::getPlatformIDs() -{ - const uint32_t count = getNumPlatforms(); - std::vector platforms(count); - - if (count) { - OclLib::getPlatformIDs(count, platforms.data(), nullptr); - } - - return platforms; -} - - -uint32_t xmrig::OclLib::getNumPlatforms() +cl_uint xmrig::OclLib::getNumPlatforms() { cl_uint count = 0; cl_int ret; @@ -518,6 +505,19 @@ xmrig::OclVendor xmrig::OclLib::getDeviceVendor(cl_device_id id) } +std::vector xmrig::OclLib::getPlatformIDs() +{ + const uint32_t count = getNumPlatforms(); + std::vector platforms(count); + + if (count) { + OclLib::getPlatformIDs(count, platforms.data(), nullptr); + } + + return platforms; +} + + xmrig::String xmrig::OclLib::getDeviceBoardName(cl_device_id id) { constexpr size_t size = 128; @@ -544,6 +544,20 @@ xmrig::String xmrig::OclLib::getDeviceName(cl_device_id id) } +xmrig::String xmrig::OclLib::getPlatformInfo(cl_platform_id platform, cl_platform_info param_name) +{ + size_t size = 0; + if (getPlatformInfo(platform, param_name, 0, nullptr, &size) != CL_SUCCESS) { + return String(); + } + + char *buf = new char[size](); + OclLib::getPlatformInfo(platform, param_name, size, buf, nullptr); + + return String(buf); +} + + xmrig::String xmrig::OclLib::getProgramBuildLog(cl_program program, cl_device_id device) { size_t size = 0; diff --git a/src/backend/opencl/wrappers/OclLib.h b/src/backend/opencl/wrappers/OclLib.h index 864d7de3..97bbdeb4 100644 --- a/src/backend/opencl/wrappers/OclLib.h +++ b/src/backend/opencl/wrappers/OclLib.h @@ -66,11 +66,12 @@ public: static cl_program createProgramWithBinary(cl_context context, cl_uint num_devices, const cl_device_id *device_list, const size_t *lengths, const unsigned char **binaries, cl_int *binary_status, cl_int *errcode_ret); static cl_program createProgramWithSource(cl_context context, cl_uint count, const char **strings, const size_t *lengths, cl_int *errcode_ret); static cl_uint getDeviceMaxComputeUnits(cl_device_id id); - static std::vector getPlatformIDs(); - static uint32_t getNumPlatforms(); + static cl_uint getNumPlatforms(); static OclVendor getDeviceVendor(cl_device_id id); + static std::vector getPlatformIDs(); static String getDeviceBoardName(cl_device_id id); static String getDeviceName(cl_device_id id); + static String getPlatformInfo(cl_platform_id platform, cl_platform_info param_name); static String getProgramBuildLog(cl_program program, cl_device_id device); private: diff --git a/src/backend/opencl/wrappers/OclPlatform.cpp b/src/backend/opencl/wrappers/OclPlatform.cpp index 7d1124f1..6a7651a9 100644 --- a/src/backend/opencl/wrappers/OclPlatform.cpp +++ b/src/backend/opencl/wrappers/OclPlatform.cpp @@ -22,6 +22,10 @@ * along with this program. If not, see . */ + +#include + + #include "backend/opencl/wrappers/OclLib.h" #include "backend/opencl/wrappers/OclPlatform.h" @@ -44,16 +48,48 @@ std::vector xmrig::OclPlatform::get() } +void xmrig::OclPlatform::print() +{ + const auto platforms = OclPlatform::get(); + + printf("%-28s%zu\n\n", "Number of platforms:", platforms.size()); + + for (const auto &platform : platforms) { + printf(" %-26s%zu\n", "Index:", platform.index()); + printf(" %-26s%s\n", "Profile:", platform.profile().data()); + printf(" %-26s%s\n", "Version:", platform.version().data()); + printf(" %-26s%s\n", "Name:", platform.name().data()); + printf(" %-26s%s\n", "Vendor:", platform.vendor().data()); + printf(" %-26s%s\n\n", "Extensions:", platform.extensions().data()); + } +} + + +xmrig::String xmrig::OclPlatform::extensions() const +{ + return OclLib::getPlatformInfo(id(), CL_PLATFORM_EXTENSIONS); +} + + +xmrig::String xmrig::OclPlatform::name() const +{ + return OclLib::getPlatformInfo(id(), CL_PLATFORM_NAME); +} + + +xmrig::String xmrig::OclPlatform::profile() const +{ + return OclLib::getPlatformInfo(id(), CL_PLATFORM_PROFILE); +} + + xmrig::String xmrig::OclPlatform::vendor() const { - constexpr size_t size = 128; - char *buf = new char[size](); - - if (OclLib::getPlatformInfo(id(), CL_PLATFORM_VENDOR, size, buf, nullptr) != CL_SUCCESS) { - delete [] buf; - - return String(); - } - - return String(buf); + return OclLib::getPlatformInfo(id(), CL_PLATFORM_VENDOR); +} + + +xmrig::String xmrig::OclPlatform::version() const +{ + return OclLib::getPlatformInfo(id(), CL_PLATFORM_VERSION); } diff --git a/src/backend/opencl/wrappers/OclPlatform.h b/src/backend/opencl/wrappers/OclPlatform.h index 94c9f714..9fd80ecf 100644 --- a/src/backend/opencl/wrappers/OclPlatform.h +++ b/src/backend/opencl/wrappers/OclPlatform.h @@ -45,11 +45,16 @@ public: OclPlatform(size_t index, cl_platform_id id) : m_id(id), m_index(index) {} static std::vector get(); + static void print(); inline cl_platform_id id() const { return m_id; } inline size_t index() const { return m_index; } + String extensions() const; + String name() const; + String profile() const; String vendor() const; + String version() const; private: cl_platform_id m_id = nullptr; diff --git a/src/base/kernel/Entry.cpp b/src/base/kernel/Entry.cpp index a0ab72df..605f8e20 100644 --- a/src/base/kernel/Entry.cpp +++ b/src/base/kernel/Entry.cpp @@ -49,17 +49,6 @@ namespace xmrig { -#ifdef XMRIG_FEATURE_OPENCL -static void printPlatforms() -{ - const auto platforms = OclPlatform::get(); - for (const auto &platform : platforms) { - printf("#%zu: %s\n", platform.index(), platform.vendor().data()); - } -} -#endif - - static int showVersion() { printf(APP_NAME " " APP_VERSION "\n built on " __DATE__ @@ -186,7 +175,7 @@ int xmrig::Entry::exec(const Process &process, Id id) # ifdef XMRIG_FEATURE_OPENCL case Platforms: if (OclLib::init()) { - printPlatforms(); + OclPlatform::print(); } return 0; # endif