From a48905ec9cfe0e017cc64943195be82b530117d7 Mon Sep 17 00:00:00 2001 From: Alex Voicu Date: Tue, 17 Sep 2024 03:14:56 +0100 Subject: [PATCH] Add scaffolding for SPIR-V support. --- hipamd/src/hip_fatbin.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/hipamd/src/hip_fatbin.cpp b/hipamd/src/hip_fatbin.cpp index b26377135..f9ffdc8c3 100644 --- a/hipamd/src/hip_fatbin.cpp +++ b/hipamd/src/hip_fatbin.cpp @@ -242,6 +242,9 @@ hipError_t FatBinaryInfo::ExtractFatBinaryUsingCOMGR(const std::vectordevices()[0]->isa().isaName(); unique_isa_names.insert({device_name, std::make_pair(0,0)}); } + unique_isa_names.emplace(std::piecewise_construct, + std::forward_as_tuple("spirv64-amd-amdhsa--amdgcnspirv"), + std::forward_as_tuple(0u, 0u)); // Create a query list using COMGR info for unique ISAs. std::vector query_list_array; @@ -263,29 +266,35 @@ hipError_t FatBinaryInfo::ExtractFatBinaryUsingCOMGR(const std::vectorsecond = std::pair - (static_cast(item.size), - static_cast(item.offset)); + unique_it->second = std::make_pair(item.size, item.offset); } for (auto device : devices) { std::string device_name = device->devices()[0]->isa().isaName(); auto dev_it = unique_isa_names.find(device_name); - // If the size is 0, then COMGR API could not find the CO for this GPU device/ISA - if (dev_it->second.first == 0) { + guarantee(unique_isa_names.cend() != dev_it, + "Cannot find the device name in the unique device name"); + if (dev_it->second.first != 0) { + fatbin_dev_info_[device->deviceId()] + = new FatBinaryDeviceInfo(reinterpret_cast
(const_cast(image_)) + + dev_it->second.second, dev_it->second.first, + dev_it->second.second); + } else if (unique_isa_names["spirv64-amd-amdhsa--amdgcnspirv"].first) { + LogPrintfError("SPIR-V support is not yet available, even though it " + "is needed for the bundle %s, which does not contain " + "requested ISA: %s", + fname_.c_str(), device_name.c_str()); + hip_status = hipErrorNoBinaryForGpu; + ListAllDeviceWithNoCOFromBundle(unique_isa_names); + break; + } else { LogPrintfError("Cannot find CO in the bundle %s for ISA: %s", fname_.c_str(), device_name.c_str()); hip_status = hipErrorNoBinaryForGpu; ListAllDeviceWithNoCOFromBundle(unique_isa_names); break; } - guarantee(unique_isa_names.cend() != dev_it, - "Cannot find the device name in the unique device name"); - fatbin_dev_info_[device->deviceId()] - = new FatBinaryDeviceInfo(reinterpret_cast
(const_cast(image_)) - + dev_it->second.second, dev_it->second.first, - dev_it->second.second); + fatbin_dev_info_[device->deviceId()]->program_ = new amd::Program(*(device->asContext())); }