/* XMRig * Copyright 2010 Jeff Garzik * Copyright 2012-2014 pooler * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "backend/opencl/wrappers/OclLib.h" #include "backend/opencl/wrappers/OclPlatform.h" #include "rapidjson/document.h" std::vector xmrig::OclPlatform::get() { const std::vector platforms = OclLib::getPlatformIDs(); std::vector out; if (platforms.empty()) { return out; } out.reserve(platforms.size()); for (size_t i = 0; i < platforms.size(); i++) { out.emplace_back(i, platforms[i]); } return out; } 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()); } } 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; } std::vector xmrig::OclPlatform::devices() const { std::vector out; if (!isValid()) { return out; } cl_uint num_devices = 0; OclLib::getDeviceIDs(id(), CL_DEVICE_TYPE_GPU, 0, nullptr, &num_devices); if (num_devices == 0) { return out; } out.reserve(num_devices); std::vector devices(num_devices); OclLib::getDeviceIDs(id(), CL_DEVICE_TYPE_GPU, num_devices, devices.data(), nullptr); for (size_t i = 0; i < devices.size(); ++i) { out.emplace_back(i, devices[i], id()); } return out; } 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 { return OclLib::getPlatformInfo(id(), CL_PLATFORM_VENDOR); } xmrig::String xmrig::OclPlatform::version() const { return OclLib::getPlatformInfo(id(), CL_PLATFORM_VERSION); }