SWDEV-546223 - Get image support info from ISA meta (#773)

Tento commit je obsažen v:
Ioannis Assiouras
2025-09-02 15:05:18 +01:00
odevzdal GitHub
rodič ae874b489d
revize a1c30318fb
8 změnil soubory, kde provedl 83 přidání a 159 odebrání
-58
Zobrazit soubor
@@ -79,9 +79,6 @@ extern const char* BlitImageSourceCode;
bool VirtualDevice::ActiveWait() const { return device_().ActiveWait(); } bool VirtualDevice::ActiveWait() const { return device_().ActiveWait(); }
#if defined(USE_COMGR_LIBRARY)
extern amd_comgr_status_t getMetaBuf(const amd_comgr_metadata_node_t meta, std::string* str);
#endif
} // namespace amd::device } // namespace amd::device
static_assert(static_cast<uint32_t>(device::Memory::MemAccess::kMemAccessNone) == static_assert(static_cast<uint32_t>(device::Memory::MemAccess::kMemAccessNone) ==
@@ -350,61 +347,6 @@ const Isa* Isa::begin() { return supportedIsas().first; }
const Isa* Isa::end() { return supportedIsas().second; } const Isa* Isa::end() { return supportedIsas().second; }
#if defined(USE_COMGR_LIBRARY)
void Isa::setAvailableSgprVgprCached() const {
std::call_once(setSgprVgprFlag, [this]() {
std::string buf;
amd_comgr_metadata_node_t isaMeta;
amd_comgr_metadata_node_t sgprMeta;
amd_comgr_metadata_node_t vgprMeta;
bool hasIsaMeta = false;
bool hasSgprMeta = false;
bool hasVgprMeta = false;
amd_comgr_status_t status = amd::Comgr::get_isa_metadata(isaName().c_str(), &isaMeta);
if (status == AMD_COMGR_STATUS_SUCCESS) {
hasIsaMeta = true;
status = amd::Comgr::metadata_lookup(isaMeta, "AddressableNumSGPRs", &sgprMeta);
}
if (status == AMD_COMGR_STATUS_SUCCESS) {
hasSgprMeta = true;
status = amd::device::getMetaBuf(sgprMeta, &buf);
}
sgprPerWavefront_ = (status == AMD_COMGR_STATUS_SUCCESS) ? atoi(buf.c_str()) : 0;
if (status == AMD_COMGR_STATUS_SUCCESS) {
status = amd::Comgr::metadata_lookup(isaMeta, "AddressableNumVGPRs", &vgprMeta);
}
if (status == AMD_COMGR_STATUS_SUCCESS) {
hasVgprMeta = true;
status = amd::device::getMetaBuf(vgprMeta, &buf);
}
vgprPerWavefront_ = (status == AMD_COMGR_STATUS_SUCCESS) ? atoi(buf.c_str()) : 0;
if (hasVgprMeta) {
amd::Comgr::destroy_metadata(vgprMeta);
}
if (hasSgprMeta) {
amd::Comgr::destroy_metadata(sgprMeta);
}
if (hasIsaMeta) {
amd::Comgr::destroy_metadata(isaMeta);
}
if (status != AMD_COMGR_STATUS_SUCCESS) {
DevLogPrintfError("Failed to set SGPR/VGPR for ISA: %s", isaName().c_str());
}
});
}
#endif
std::vector<Device*>* Device::devices_ = nullptr; std::vector<Device*>* Device::devices_ = nullptr;
AppProfile Device::appProfile_; AppProfile Device::appProfile_;
+6 -28
Zobrazit soubor
@@ -1376,6 +1376,10 @@ class VirtualDevice : public amd::HeapObject {
mutable std::atomic<uint64_t> queued_async_handlers_ = 0; //!< Outstanding HSA async handlers mutable std::atomic<uint64_t> queued_async_handlers_ = 0; //!< Outstanding HSA async handlers
}; };
#if defined(USE_COMGR_LIBRARY)
extern bool getValueFromIsaMeta(const std::string& isa, const char* key, std::string& retValue);
#endif
} // namespace amd::device } // namespace amd::device
namespace amd { namespace amd {
@@ -1535,20 +1539,6 @@ class Isa {
/// @returns This Isa's number of banks of local memory. /// @returns This Isa's number of banks of local memory.
uint32_t localMemBanks() const { return localMemBanks_; } uint32_t localMemBanks() const { return localMemBanks_; }
#if defined(USE_COMGR_LIBRARY)
/// @returns This Isa's available sgprs per wavefront
size_t sgprPerWavefront() const {
setAvailableSgprVgprCached();
return sgprPerWavefront_;
}
/// @returns This Isa's available vgprs per wavefront
size_t vgprPerWavefront() const {
setAvailableSgprVgprCached();
return vgprPerWavefront_;
}
#endif
/// @returns True if @p codeObjectIsa and @p agentIsa are compatible, /// @returns True if @p codeObjectIsa and @p agentIsa are compatible,
/// false otherwise. /// false otherwise.
static bool isCompatible(const Isa& codeObjectIsa, const Isa& agentIsa); static bool isCompatible(const Isa& codeObjectIsa, const Isa& agentIsa);
@@ -1586,19 +1576,11 @@ class Isa {
simdInstructionWidth_(simdInstructionWidth), simdInstructionWidth_(simdInstructionWidth),
memChannelBankWidth_(memChannelBankWidth), memChannelBankWidth_(memChannelBankWidth),
localMemSizePerCU_(localMemSizePerCU), localMemSizePerCU_(localMemSizePerCU),
localMemBanks_(localMemBanks), localMemBanks_(localMemBanks) {}
sgprPerWavefront_(0),
vgprPerWavefront_(0) {}
// @brief Returns the begin and end iterators for the suppported ISAs. // @brief Returns the begin and end iterators for the suppported ISAs.
static std::pair<const Isa*, const Isa*> supportedIsas(); static std::pair<const Isa*, const Isa*> supportedIsas();
#if defined(USE_COMGR_LIBRARY)
// @brief Populate this Isa's available sgprs/vgprs per wavefront from comgr.
// Only called once per Isa.
void setAvailableSgprVgprCached() const;
#endif
// @brief Isa's target ID name. Used for LLVM COde Object Manager // @brief Isa's target ID name. Used for LLVM COde Object Manager
// compilations. // compilations.
const char* targetId_; const char* targetId_;
@@ -1621,11 +1603,7 @@ class Isa {
uint32_t memChannelBankWidth_; //!< Memory channel bank width. uint32_t memChannelBankWidth_; //!< Memory channel bank width.
uint32_t localMemSizePerCU_; //!< Local memory size per CU. uint32_t localMemSizePerCU_; //!< Local memory size per CU.
uint32_t localMemBanks_; //!< Number of banks of local memory. uint32_t localMemBanks_; //!< Number of banks of local memory.
}; // class Isa
mutable size_t sgprPerWavefront_; //!< Number of sgpr per wavefront.
mutable size_t vgprPerWavefront_; //!< Number of vgpr per wavefront.
mutable std::once_flag setSgprVgprFlag; //!< Once flag for sgpr and vgpr retrieval.
}; // class Isa
/*! \addtogroup Runtime /*! \addtogroup Runtime
* @{ * @{
+33 -2
Zobrazit soubor
@@ -52,19 +52,50 @@ static constexpr clk_value_type_t ClkValueMapType[6][6] = {
}; };
#if defined(USE_COMGR_LIBRARY) #if defined(USE_COMGR_LIBRARY)
// ================================================================================================ // ================================================================================================
amd_comgr_status_t getMetaBuf(const amd_comgr_metadata_node_t meta, std::string* str) { amd_comgr_status_t getMetaBuf(const amd_comgr_metadata_node_t meta,
std::string* str) {
size_t size = 0; size_t size = 0;
amd_comgr_status_t status = amd::Comgr::get_metadata_string(meta, &size, NULL); amd_comgr_status_t status = amd::Comgr::get_metadata_string(meta, &size, NULL);
if (status == AMD_COMGR_STATUS_SUCCESS) { if (status == AMD_COMGR_STATUS_SUCCESS) {
str->resize(size - 1); // minus one to discount the null character str->resize(size-1); // minus one to discount the null character
status = amd::Comgr::get_metadata_string(meta, &size, &((*str)[0])); status = amd::Comgr::get_metadata_string(meta, &size, &((*str)[0]));
} }
return status; return status;
} }
// ================================================================================================
bool getValueFromIsaMeta(const std::string& isa, const char* key, std::string& retValue) {
amd_comgr_metadata_node_t isaMeta;
amd_comgr_status_t status = amd::Comgr::get_isa_metadata(isa.c_str(), &isaMeta);
if (status != AMD_COMGR_STATUS_SUCCESS) {
ClPrint(amd::LOG_ERROR, amd::LOG_INIT, "getIsaMeta(%s) failed!", isa.c_str());
return false;
}
amd_comgr_metadata_node_t valMeta;
size_t size = 0;
status = amd::Comgr::metadata_lookup(isaMeta, key, &valMeta);
if (status == AMD_COMGR_STATUS_SUCCESS) {
status = amd::Comgr::get_metadata_string(valMeta, &size, NULL);
}
if (status == AMD_COMGR_STATUS_SUCCESS) {
retValue.resize(size - 1);
status = amd::Comgr::get_metadata_string(valMeta, &size, &(retValue[0]));
}
if (status == AMD_COMGR_STATUS_SUCCESS) {
status = amd::Comgr::destroy_metadata(valMeta);
}
amd::Comgr::destroy_metadata(isaMeta);
return (status == AMD_COMGR_STATUS_SUCCESS) ? true : false;
}
// ================================================================================================ // ================================================================================================
static amd_comgr_status_t populateArgs(const amd_comgr_metadata_node_t key, static amd_comgr_status_t populateArgs(const amd_comgr_metadata_node_t key,
const amd_comgr_metadata_node_t value, void* data) { const amd_comgr_metadata_node_t value, void* data) {
+2 -2
Zobrazit soubor
@@ -256,7 +256,7 @@ bool NullDevice::create(const char* palName, const amd::Isa& isa, Pal::GfxIpLeve
// Create setting for the offline target // Create setting for the offline target
if ((palSettings == nullptr) || if ((palSettings == nullptr) ||
!palSettings->create(properties, heaps, wscaps, isa.xnack() == amd::Isa::Feature::Enabled)) { !palSettings->create(properties, heaps, wscaps, isa)) {
LogPrintfError("Unable to create PAL setting for offline PAL device %s", isa.targetId()); LogPrintfError("Unable to create PAL setting for offline PAL device %s", isa.targetId());
return false; return false;
} }
@@ -1005,7 +1005,7 @@ bool Device::create(Pal::IDevice* device) {
pal::Settings* gpuSettings = reinterpret_cast<pal::Settings*>(settings_); pal::Settings* gpuSettings = reinterpret_cast<pal::Settings*>(settings_);
if (!gpuSettings || if (!gpuSettings ||
!gpuSettings->create(properties(), heaps_, wscaps, isa->xnack() == amd::Isa::Feature::Enabled, !gpuSettings->create(properties(), heaps_, wscaps, *isa,
appProfile_.reportAsOCL12Device())) { appProfile_.reportAsOCL12Device())) {
return false; return false;
} }
+10 -4
Zobrazit soubor
@@ -140,7 +140,7 @@ Settings::Settings() {
bool Settings::create(const Pal::DeviceProperties& palProp, bool Settings::create(const Pal::DeviceProperties& palProp,
const Pal::GpuMemoryHeapProperties* heaps, const Pal::WorkStationCaps& wscaps, const Pal::GpuMemoryHeapProperties* heaps, const Pal::WorkStationCaps& wscaps,
bool enableXNACK, bool reportAsOCL12Device) { const amd::Isa& isa, bool reportAsOCL12Device) {
uint32_t osVer = 0x0; uint32_t osVer = 0x0;
// Disable thread trace by default for all devices // Disable thread trace by default for all devices
@@ -151,8 +151,8 @@ bool Settings::create(const Pal::DeviceProperties& palProp,
apuSystem_ = true; apuSystem_ = true;
} }
enableXNACK_ = enableXNACK; enableXNACK_ = (isa.xnack() == amd::Isa::Feature::Enabled);
hsailExplicitXnack_ = enableXNACK; hsailExplicitXnack_ = enableXNACK_;
bool useWavefront64 = false; bool useWavefront64 = false;
std::string appName = {}; std::string appName = {};
@@ -292,7 +292,13 @@ bool Settings::create(const Pal::DeviceProperties& palProp,
} }
imageSupport_ = true; imageSupport_ = true;
std::string imageSupport;
if (amd::device::getValueFromIsaMeta(isa.isaName(), "ImageSupport", imageSupport)) {
imageSupport_ = atoi(imageSupport.c_str());
ClPrint(amd::LOG_INFO, amd::LOG_INIT, "imageSupport=%u", imageSupport_);
} else {
LogInfo("Can not get image support info from ISA meta");
}
// Use kernels for blit if appropriate // Use kernels for blit if appropriate
blitEngine_ = BlitEngineKernel; blitEngine_ = BlitEngineKernel;
+1 -1
Zobrazit soubor
@@ -120,7 +120,7 @@ class Settings : public device::Settings {
bool create(const Pal::DeviceProperties& palProp, //!< PAL device properties bool create(const Pal::DeviceProperties& palProp, //!< PAL device properties
const Pal::GpuMemoryHeapProperties* heaps, //!< PAL heap settings const Pal::GpuMemoryHeapProperties* heaps, //!< PAL heap settings
const Pal::WorkStationCaps& wscaps, //!< PAL workstation settings const Pal::WorkStationCaps& wscaps, //!< PAL workstation settings
bool enableXNACK, //!< XNACK is enabled on this device const amd::Isa& isa, //!< XNACK is enabled on this device
bool reportAsOCL12Device = false //!< Report As OpenCL1.2 Device bool reportAsOCL12Device = false //!< Report As OpenCL1.2 Device
); );
+29 -62
Zobrazit soubor
@@ -80,41 +80,6 @@ static_assert(static_cast<uint32_t>(amd::Device::VmmAccess::kReadWrite) ==
#ifndef WITHOUT_HSA_BACKEND #ifndef WITHOUT_HSA_BACKEND
namespace {
inline bool getIsaMeta(std::string isaName, amd_comgr_metadata_node_t& isaMeta) {
amd_comgr_status_t status;
status = amd::Comgr::get_isa_metadata(isaName.c_str(), &isaMeta);
return (status == AMD_COMGR_STATUS_SUCCESS) ? true : false;
}
inline bool releaseIsaMeta(amd_comgr_metadata_node_t& isaMeta) {
return AMD_COMGR_STATUS_SUCCESS == amd::Comgr::destroy_metadata(isaMeta);
}
bool getValueFromIsaMeta(amd_comgr_metadata_node_t& isaMeta, const char* key,
std::string& retValue) {
amd_comgr_status_t status;
amd_comgr_metadata_node_t valMeta;
size_t size = 0;
status = amd::Comgr::metadata_lookup(isaMeta, key, &valMeta);
if (status == AMD_COMGR_STATUS_SUCCESS) {
status = amd::Comgr::get_metadata_string(valMeta, &size, NULL);
}
if (status == AMD_COMGR_STATUS_SUCCESS) {
retValue.resize(size - 1);
status = amd::Comgr::get_metadata_string(valMeta, &size, &(retValue[0]));
}
if (status == AMD_COMGR_STATUS_SUCCESS) {
status = amd::Comgr::destroy_metadata(valMeta);
}
return (status == AMD_COMGR_STATUS_SUCCESS) ? true : false;
}
} // namespace
namespace amd::device { namespace amd::device {
extern const char* HipExtraSourceCode; extern const char* HipExtraSourceCode;
extern const char* HipExtraSourceCodeNoGWS; extern const char* HipExtraSourceCodeNoGWS;
@@ -1621,36 +1586,38 @@ bool Device::populateOCLDeviceConstants() {
info_.maxOnDeviceQueues_ = 1; info_.maxOnDeviceQueues_ = 1;
info_.maxOnDeviceEvents_ = settings().numDeviceEvents_; info_.maxOnDeviceEvents_ = settings().numDeviceEvents_;
// Get Values from from Comgr std::string addressableNumVGPRs, totalNumVGPRs, vGPRAllocGranule;
amd_comgr_metadata_node_t isaMeta; std::string isaName = isa().isaName();
if (getIsaMeta(std::move(isa().isaName()), isaMeta)) { info_.availableVGPRs_ =
std::string addressableNumVGPRs, totalNumVGPRs, vGPRAllocGranule; amd::device::getValueFromIsaMeta(isaName, "AddressableNumVGPRs", addressableNumVGPRs)
info_.availableVGPRs_ = getValueFromIsaMeta(isaMeta, "AddressableNumVGPRs", addressableNumVGPRs) ? atoi(addressableNumVGPRs.c_str())
? atoi(addressableNumVGPRs.c_str()) : 0;
: 0; info_.vgprsPerSimd_ = amd::device::getValueFromIsaMeta(isaName, "TotalNumVGPRs", totalNumVGPRs)
info_.vgprsPerSimd_ = getValueFromIsaMeta(isaMeta, "TotalNumVGPRs", totalNumVGPRs) ? atoi(totalNumVGPRs.c_str())
? atoi(totalNumVGPRs.c_str()) : 0;
: 0; info_.vgprAllocGranularity_ =
info_.vgprAllocGranularity_ = getValueFromIsaMeta(isaMeta, "VGPRAllocGranule", vGPRAllocGranule) amd::device::getValueFromIsaMeta(isaName, "VGPRAllocGranule", vGPRAllocGranule)
? atoi(vGPRAllocGranule.c_str()) ? atoi(vGPRAllocGranule.c_str())
: 0; : 0;
info_.availableRegistersPerCU_ = info_.vgprsPerSimd_ * info_.simdPerCU_ * info_.wavefrontWidth_; info_.availableRegistersPerCU_ = info_.vgprsPerSimd_ * info_.simdPerCU_ * info_.wavefrontWidth_;
ClPrint(amd::LOG_INFO, amd::LOG_INIT, ClPrint(amd::LOG_INFO, amd::LOG_INIT,
"addressableNumVGPRs=%u, totalNumVGPRs=%u, vGPRAllocGranule=%u," "addressableNumVGPRs=%u, totalNumVGPRs=%u, vGPRAllocGranule=%u,"
" availableRegistersPerCU_=%u", " availableRegistersPerCU_=%u",
info_.availableVGPRs_, info_.vgprsPerSimd_, info_.vgprAllocGranularity_, info_.availableVGPRs_, info_.vgprsPerSimd_, info_.vgprAllocGranularity_,
info_.availableRegistersPerCU_); info_.availableRegistersPerCU_);
std::string sgprValue; std::string sgprValue;
info_.availableSGPRs_ = (getValueFromIsaMeta(isaMeta, "AddressableNumSGPRs", sgprValue)) info_.availableSGPRs_ =
? (atoi(sgprValue.c_str())) (amd::device::getValueFromIsaMeta(isaName, "AddressableNumSGPRs", sgprValue))
: 0; ? (atoi(sgprValue.c_str()))
if (!releaseIsaMeta(isaMeta)) { : 0;
LogInfo("Can not release the isa meta node"); std::string imageSupport;
} if (amd::device::getValueFromIsaMeta(isaName, "ImageSupport", imageSupport)) {
info_.imageSupport_ = atoi(imageSupport.c_str());
ClPrint(amd::LOG_INFO, amd::LOG_INIT, "imageSupport=%u", info_.imageSupport_);
} else { } else {
ClPrint(amd::LOG_ERROR, amd::LOG_INIT, "getIsaMeta(%s) failed!", isa().isaName().c_str()); LogInfo("Can not get image support info from ISA meta");
} }
// Generic support for HMM interfaces // Generic support for HMM interfaces
+2 -2
Zobrazit soubor
@@ -131,8 +131,8 @@ bool Kernel::postLoad() {
} }
assert(wavefront_size > 0); assert(wavefront_size > 0);
workGroupInfo_.availableVGPRs_ = device().isa().vgprPerWavefront(); workGroupInfo_.availableVGPRs_ = device().info().vgprsPerSimd_;
workGroupInfo_.availableSGPRs_ = device().isa().sgprPerWavefront(); workGroupInfo_.availableSGPRs_ = device().info().availableSGPRs_;
workGroupInfo_.privateMemSize_ = workitemPrivateSegmentByteSize_; workGroupInfo_.privateMemSize_ = workitemPrivateSegmentByteSize_;
workGroupInfo_.localMemSize_ = workgroupGroupSegmentByteSize_; workGroupInfo_.localMemSize_ = workgroupGroupSegmentByteSize_;
workGroupInfo_.usedLDSSize_ = workgroupGroupSegmentByteSize_; workGroupInfo_.usedLDSSize_ = workgroupGroupSegmentByteSize_;