From 67e29c1af1c5090ad060752801fe5c919139ecc5 Mon Sep 17 00:00:00 2001 From: Tony Butler Date: Tue, 18 May 2021 23:05:04 -0600 Subject: [PATCH] Readjust OclDevice logic and add OCL_VENDOR_APPLE --- src/backend/opencl/wrappers/OclDevice.cpp | 75 ++++++++++++++++++++--- src/backend/opencl/wrappers/OclDevice.h | 8 ++- src/backend/opencl/wrappers/OclVendor.h | 3 +- 3 files changed, 75 insertions(+), 11 deletions(-) diff --git a/src/backend/opencl/wrappers/OclDevice.cpp b/src/backend/opencl/wrappers/OclDevice.cpp index a3fcdd03b..18767d25d 100644 --- a/src/backend/opencl/wrappers/OclDevice.cpp +++ b/src/backend/opencl/wrappers/OclDevice.cpp @@ -38,6 +38,21 @@ typedef union struct { cl_uint type; cl_uint data[5]; } raw; struct { cl_uint type; cl_char unused[17]; cl_char bus; cl_char device; cl_char function; } pcie; } topology_amd; +#ifndef CL_DEVICE_TOPOLOGY_AMD +#define CL_DEVICE_TOPOLOGY_AMD 0x4037 +#endif +#ifndef CL_DEVICE_BOARD_NAME_AMD +#define CL_DEVICE_BOARD_NAME_AMD 0x4038 +#endif +#ifndef CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD +#define CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD 1 +#endif +#ifndef CL_DEVICE_PCI_BUS_ID_NV +#define CL_DEVICE_PCI_BUS_ID_NV 0x4008 +#endif +#ifndef CL_DEVICE_PCI_SLOT_ID_NV +#define CL_DEVICE_PCI_SLOT_ID_NV 0x4009 +#endif namespace xmrig { @@ -74,6 +89,28 @@ static ocl_gen_config_fun generators[] = { }; +static OclVendor getPlatformVendorId(const String &vendor, const String &extensions) +{ + if (extensions.contains("cl_amd_") || vendor.contains("Advanced Micro Devices") || vendor.contains("AMD")) { + return OCL_VENDOR_AMD; + } + + if (extensions.contains("cl_nv_") || vendor.contains("NVIDIA")) { + return OCL_VENDOR_NVIDIA; + } + + if (extensions.contains("cl_intel_") || vendor.contains("Intel")) { + return OCL_VENDOR_INTEL; + } + + if (extensions.contains("cl_APPLE_") || vendor.contains("Apple")) { + return OCL_VENDOR_APPLE; + } + + return OCL_VENDOR_UNKNOWN; +} + + static OclVendor getVendorId(const String &vendor) { if (vendor.contains("Advanced Micro Devices") || vendor.contains("AMD")) { @@ -81,19 +118,36 @@ static OclVendor getVendorId(const String &vendor) } if (vendor.contains("NVIDIA")) { - return OCL_VENDOR_NVIDIA; + return OCL_VENDOR_NVIDIA; } if (vendor.contains("Intel")) { return OCL_VENDOR_INTEL; } + if (vendor.contains("Apple")) { + return OCL_VENDOR_APPLE; + } + return OCL_VENDOR_UNKNOWN; } -static OclDevice::Type getType(const String &name) +static OclDevice::Type getType(const String &name, const OclVendor platformVendorId) { + if (platformVendorId == OCL_VENDOR_APPLE) { + // Apple Platform: uses product names, not gfx# or codenames + if (name.contains("AMD Radeon")) { + if (name.contains("Pro 5300M")) { + return OclDevice::Navi_14; + } + + if (name.contains("RX 580")) { + return OclDevice::Polaris; + } + } + } + if (name == "gfx900" || name == "gfx901") { return OclDevice::Vega_10; } @@ -140,28 +194,31 @@ static OclDevice::Type getType(const String &name) xmrig::OclDevice::OclDevice(uint32_t index, cl_device_id id, cl_platform_id platform) : m_id(id), m_platform(platform), - m_board(OclLib::getString(id, 0x4038 /* CL_DEVICE_BOARD_NAME_AMD */)), + m_platformVendor(OclLib::getString(platform, CL_PLATFORM_VENDOR)), m_name(OclLib::getString(id, CL_DEVICE_NAME)), m_vendor(OclLib::getString(id, CL_DEVICE_VENDOR)), + m_extensions(OclLib::getString(id, CL_DEVICE_EXTENSIONS)), m_maxMemoryAlloc(OclLib::getUlong(id, CL_DEVICE_MAX_MEM_ALLOC_SIZE)), m_globalMemory(OclLib::getUlong(id, CL_DEVICE_GLOBAL_MEM_SIZE)), m_computeUnits(OclLib::getUint(id, CL_DEVICE_MAX_COMPUTE_UNITS, 1)), m_index(index) { m_vendorId = getVendorId(m_vendor); - m_type = getType(m_name); + m_platformVendorId = getPlatformVendorId(m_platformVendor, m_extensions); + m_type = getType(m_name, m_platformVendorId); - if (m_vendorId == OCL_VENDOR_AMD) { + if (m_extensions.contains("cl_amd_device_attribute_query")) { topology_amd topology; - if (OclLib::getDeviceInfo(id, 0x4037 /* CL_DEVICE_TOPOLOGY_AMD */, sizeof(topology), &topology, nullptr) == CL_SUCCESS && topology.raw.type == 1) { + if (OclLib::getDeviceInfo(id, CL_DEVICE_TOPOLOGY_AMD, sizeof(topology), &topology, nullptr) == CL_SUCCESS && topology.raw.type == CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD) { m_topology = PciTopology(static_cast(topology.pcie.bus), static_cast(topology.pcie.device), static_cast(topology.pcie.function)); } + m_board = OclLib::getString(id, CL_DEVICE_BOARD_NAME_AMD); } - else if (m_vendorId == OCL_VENDOR_NVIDIA) { + else if (m_extensions.contains("cl_nv_device_attribute_query")) { cl_uint bus = 0; - if (OclLib::getDeviceInfo(id, 0x4008 /* CL_DEVICE_PCI_BUS_ID_NV */, sizeof (bus), &bus, nullptr) == CL_SUCCESS) { - cl_uint slot = OclLib::getUint(id, 0x4009 /* CL_DEVICE_PCI_SLOT_ID_NV */); + if (OclLib::getDeviceInfo(id, CL_DEVICE_PCI_BUS_ID_NV, sizeof (bus), &bus, nullptr) == CL_SUCCESS) { + cl_uint slot = OclLib::getUint(id, CL_DEVICE_PCI_SLOT_ID_NV); m_topology = PciTopology(bus, (slot >> 3) & 0xff, slot & 7); } } diff --git a/src/backend/opencl/wrappers/OclDevice.h b/src/backend/opencl/wrappers/OclDevice.h index b698ad3a5..11dec1871 100644 --- a/src/backend/opencl/wrappers/OclDevice.h +++ b/src/backend/opencl/wrappers/OclDevice.h @@ -64,11 +64,14 @@ public: inline bool isValid() const { return m_id != nullptr && m_platform != nullptr; } inline cl_device_id id() const { return m_id; } + inline const String &platformVendor() const { return m_platformVendor; } + inline OclVendor platformVendorId() const { return m_vendorId; } inline const PciTopology &topology() const { return m_topology; } inline const String &board() const { return m_board.isNull() ? m_name : m_board; } inline const String &name() const { return m_name; } inline const String &vendor() const { return m_vendor; } inline OclVendor vendorId() const { return m_vendorId; } + inline const String &extensions() const { return m_extensions; } inline Type type() const { return m_type; } inline uint32_t computeUnits() const { return m_computeUnits; } inline size_t freeMemSize() const { return std::min(maxMemAllocSize(), globalMemSize()); } @@ -83,13 +86,16 @@ public: private: cl_device_id m_id = nullptr; cl_platform_id m_platform = nullptr; - const String m_board; + const String m_platformVendor; + String m_board; const String m_name; const String m_vendor; + String m_extensions; const size_t m_maxMemoryAlloc = 0; const size_t m_globalMemory = 0; const uint32_t m_computeUnits = 1; const uint32_t m_index = 0; + OclVendor m_platformVendorId = OCL_VENDOR_UNKNOWN; OclVendor m_vendorId = OCL_VENDOR_UNKNOWN; PciTopology m_topology; Type m_type = Unknown; diff --git a/src/backend/opencl/wrappers/OclVendor.h b/src/backend/opencl/wrappers/OclVendor.h index def59b77b..67bd34bb0 100644 --- a/src/backend/opencl/wrappers/OclVendor.h +++ b/src/backend/opencl/wrappers/OclVendor.h @@ -33,7 +33,8 @@ enum OclVendor : unsigned { OCL_VENDOR_UNKNOWN, OCL_VENDOR_AMD, OCL_VENDOR_NVIDIA, - OCL_VENDOR_INTEL + OCL_VENDOR_INTEL, + OCL_VENDOR_APPLE };