Reputation: 216
I'm currently writing a HIP equivalent to NVIDIA's deviceQuery sample code. I want my code to work on both AMD and NVIDIA hardware.
Now, hipDeviceProp_t
isn't exactly the same as cudaDeviceProp_t
, because the former has both new and missing fields in the struct compared to the latter.
Currently the code I wrote works on AMD GPUs only and segfaults when I try it on an NVIDIA GPU, which I believe is due to accessing fields that are nonexistent in cudaDeviceProp_t
. It is also still missing a critical part to detect the exact GPU model within the same gfx???
GCN architecture code.
How do I figure out whether the detected GPU is AMD or NVIDIA?
Edit: for comparison, SYCL has sycl::info::device::vendor
that provides this information.
Upvotes: 2
Views: 980
Reputation: 656
When using HIP you known at compile time if you are compiling for AMD or Nvidia GPUs. There is no support for both AMD and Nvidia GPU code in the same translation unit.
Thus you could try relying on the following pre-processor definitions:
#if defined(__HIP_PLATFORM_AMD__)
// AMD GPU code should take this code path
#elif defined(__HIP_PLATFORM_NVIDIA__)
// Nvidia takes this code path.
#else
#error "Unknown platform"
#endif
Upvotes: 4
Reputation: 11
You can get the vendor ID with IDXGIAdapter::VendorId
. If you need to get a vendor's ID, there are websites like PCI Lookup.
You will need a Direct3D and DXGI device.
#define VENDOR_NVIDIA 0x10DE
extern IDXGIAdapter* pDXGIAdapter;
std::string GetGPUVendor()
{
DXGI_ADAPTER_DESC Description;
if (SUCCEEDED(pDXGIAdapter->GetDesc(&Description)))
{
switch (Description.VendorId)
{
case VENDOR_NVIDIA:
return "NVIDIA";
// ...
default:
return "Unknown";
}
}
else
{
return "Failed";
}
}
Upvotes: 0