Skip to content

Commit

Permalink
[intel-npu] Bugfix for total allocable memory property
Browse files Browse the repository at this point in the history
  • Loading branch information
csoka committed Oct 28, 2024
1 parent 6f001e9 commit f24ae05
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/plugins/intel_npu/src/backend/src/zero_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "zero_infer_request.hpp"
#include "zero_remote_tensor.hpp"

#define ZD_LEGACY_MAX_MEM_ALLOC_SIZE_BYTES (2147483648) // 2GB in base-2

using namespace intel_npu;

ZeroDevice::ZeroDevice(const std::shared_ptr<ZeroInitStructsHolder>& initStructs)
Expand Down Expand Up @@ -167,7 +169,27 @@ uint64_t ZeroDevice::getTotalMemSize() const {
_graph_ddi_table_ext.pfnQueryContextMemory(_initStructs->getContext(), ZE_GRAPH_QUERY_MEMORY_DDR, &query);
THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnQueryContextMemory", result, _graph_ddi_table_ext);

return query.total;
// For drivers with graph_extension < 1.9 we report fixed 2GB max allocation size (old drivers don't support more)
// For drivers with graph_extension > 1.9 we report the value they return
// Extra case for windows only: for graph_extension 1.8 need to convert driver value to bytes
if (_initStructs->isExtensionSupported(std::string("ZE_extension_graph_1_9"), ZE_MAKE_VERSION(1, 9))) {
// we are safe here, can return the value directly from driver
return query.total;
}
#if defined(_WIN32) || defined(__CYGWIN__)
else if (_initStructs->isExtensionSupported(std::string("ZE_extension_graph_1_8"), ZE_MAKE_VERSION(1, 8))) {
// special case for windows-only. It supports correct value from 1.8 but in incorrect unit
// need to convert driver value from KB to B
return query.total * 1024; // KB to B -base2
}
#endif // _WIN32 || __CYGWIN__
else {
// for all older drivers we return fixed 2GB (in bytes)
return ZD_LEGACY_MAX_MEM_ALLOC_SIZE_BYTES;
}

// Default: return 2GB
return ZD_LEGACY_MAX_MEM_ALLOC_SIZE_BYTES;
}

ov::device::PCIInfo ZeroDevice::getPciInfo() const {
Expand Down

0 comments on commit f24ae05

Please sign in to comment.