Improved --print-platforms option.

This commit is contained in:
XMRig 2019-08-19 02:49:43 +07:00
parent d8d173db4d
commit 476e5dcb18
5 changed files with 83 additions and 38 deletions

View file

@ -465,20 +465,7 @@ cl_uint xmrig::OclLib::getDeviceMaxComputeUnits(cl_device_id id)
}
std::vector<cl_platform_id> xmrig::OclLib::getPlatformIDs()
{
const uint32_t count = getNumPlatforms();
std::vector<cl_platform_id> 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<cl_platform_id> xmrig::OclLib::getPlatformIDs()
{
const uint32_t count = getNumPlatforms();
std::vector<cl_platform_id> 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;

View file

@ -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<cl_platform_id> getPlatformIDs();
static uint32_t getNumPlatforms();
static cl_uint getNumPlatforms();
static OclVendor getDeviceVendor(cl_device_id id);
static std::vector<cl_platform_id> 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:

View file

@ -22,6 +22,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "backend/opencl/wrappers/OclLib.h"
#include "backend/opencl/wrappers/OclPlatform.h"
@ -44,16 +48,48 @@ std::vector<xmrig::OclPlatform> 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);
}

View file

@ -45,11 +45,16 @@ public:
OclPlatform(size_t index, cl_platform_id id) : m_id(id), m_index(index) {}
static std::vector<OclPlatform> 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;

View file

@ -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