Skip to content

Commit a3753bd

Browse files
committed
Improvements to align CTS and Spec for Virtual Memory:
- UR_RESULT_ERROR_INVALID_ENUMERATION test for urVirtualMemSetAccess - Add test for urVirtualMemMap with different access flags - Add test for urVirtualMemSetAccess with different access flags - InvalidEnumeration test for urPhysicalMemCreate and changed some tests to only run once - different size values were not needed for these - Add test for urPhysicalMemCreate with different flags (only one placeholder is available, this is just a fixture for future additions) - Add new urPhysicalMemGetInfo entry point along with a reference count enum. Added adapter implementations for this - Add a test for urPhysicalMemGetInfo and modified urPhysicalMemRelease/Retain to use GetInfo to verify reference count is updated accordingly
1 parent 09ae26a commit a3753bd

37 files changed

+740
-60
lines changed

include/ur_api.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ typedef enum ur_function_t {
230230
UR_FUNCTION_COMMAND_BUFFER_UPDATE_SIGNAL_EVENT_EXP = 243, ///< Enumerator for ::urCommandBufferUpdateSignalEventExp
231231
UR_FUNCTION_COMMAND_BUFFER_UPDATE_WAIT_EVENTS_EXP = 244, ///< Enumerator for ::urCommandBufferUpdateWaitEventsExp
232232
UR_FUNCTION_BINDLESS_IMAGES_MAP_EXTERNAL_LINEAR_MEMORY_EXP = 245, ///< Enumerator for ::urBindlessImagesMapExternalLinearMemoryExp
233+
UR_FUNCTION_PHYSICAL_MEM_GET_INFO = 246, ///< Enumerator for ::urPhysicalMemGetInfo
233234
/// @cond
234235
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
235236
/// @endcond
@@ -4123,6 +4124,43 @@ urPhysicalMemRelease(
41234124
ur_physical_mem_handle_t hPhysicalMem ///< [in][release] handle of the physical memory object to release.
41244125
);
41254126

4127+
///////////////////////////////////////////////////////////////////////////////
4128+
/// @brief Physical memory range info queries.
4129+
typedef enum ur_physical_mem_info_t {
4130+
UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT = 0, ///< [uint32_t] Reference count of the physical memory object.
4131+
///< The reference count returned should be considered immediately stale.
4132+
///< It is unsuitable for general use in applications. This feature is
4133+
///< provided for identifying memory leaks.
4134+
/// @cond
4135+
UR_PHYSICAL_MEM_INFO_FORCE_UINT32 = 0x7fffffff
4136+
/// @endcond
4137+
4138+
} ur_physical_mem_info_t;
4139+
4140+
///////////////////////////////////////////////////////////////////////////////
4141+
/// @brief Get information about a physical memory object.
4142+
///
4143+
/// @returns
4144+
/// - ::UR_RESULT_SUCCESS
4145+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
4146+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
4147+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
4148+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
4149+
/// + `NULL == hPhysicalMem`
4150+
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
4151+
/// + `::UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT < propName`
4152+
UR_APIEXPORT ur_result_t UR_APICALL
4153+
urPhysicalMemGetInfo(
4154+
ur_physical_mem_handle_t hPhysicalMem, ///< [in][] handle of the physical memory object to query.
4155+
ur_physical_mem_info_t propName, ///< [in] type of the info to query.
4156+
size_t propSize, ///< [in] size in bytes of the memory pointed to by pPropValue.
4157+
void *pPropValue, ///< [out][optional][typename(propName, propSize)] array of bytes holding
4158+
///< the info. If propSize is less than the real number of bytes needed to
4159+
///< return the info then the ::UR_RESULT_ERROR_INVALID_SIZE error is
4160+
///< returned and pPropValue is not used.
4161+
size_t *pPropSizeRet ///< [out][optional] pointer to the actual size in bytes of the queried propName."
4162+
);
4163+
41264164
#if !defined(__GNUC__)
41274165
#pragma endregion
41284166
#endif
@@ -10982,6 +11020,18 @@ typedef struct ur_physical_mem_release_params_t {
1098211020
ur_physical_mem_handle_t *phPhysicalMem;
1098311021
} ur_physical_mem_release_params_t;
1098411022

11023+
///////////////////////////////////////////////////////////////////////////////
11024+
/// @brief Function parameters for urPhysicalMemGetInfo
11025+
/// @details Each entry is a pointer to the parameter passed to the function;
11026+
/// allowing the callback the ability to modify the parameter's value
11027+
typedef struct ur_physical_mem_get_info_params_t {
11028+
ur_physical_mem_handle_t *phPhysicalMem;
11029+
ur_physical_mem_info_t *ppropName;
11030+
size_t *ppropSize;
11031+
void **ppPropValue;
11032+
size_t **ppPropSizeRet;
11033+
} ur_physical_mem_get_info_params_t;
11034+
1098511035
///////////////////////////////////////////////////////////////////////////////
1098611036
/// @brief Function parameters for urAdapterGet
1098711037
/// @details Each entry is a pointer to the parameter passed to the function;

include/ur_api_funcs.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ _UR_API(urMemImageGetInfo)
9696
_UR_API(urPhysicalMemCreate)
9797
_UR_API(urPhysicalMemRetain)
9898
_UR_API(urPhysicalMemRelease)
99+
_UR_API(urPhysicalMemGetInfo)
99100
_UR_API(urAdapterGet)
100101
_UR_API(urAdapterRelease)
101102
_UR_API(urAdapterRetain)

include/ur_ddi.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,12 +977,22 @@ typedef ur_result_t(UR_APICALL *ur_pfnPhysicalMemRetain_t)(
977977
typedef ur_result_t(UR_APICALL *ur_pfnPhysicalMemRelease_t)(
978978
ur_physical_mem_handle_t);
979979

980+
///////////////////////////////////////////////////////////////////////////////
981+
/// @brief Function-pointer for urPhysicalMemGetInfo
982+
typedef ur_result_t(UR_APICALL *ur_pfnPhysicalMemGetInfo_t)(
983+
ur_physical_mem_handle_t,
984+
ur_physical_mem_info_t,
985+
size_t,
986+
void *,
987+
size_t *);
988+
980989
///////////////////////////////////////////////////////////////////////////////
981990
/// @brief Table of PhysicalMem functions pointers
982991
typedef struct ur_physical_mem_dditable_t {
983992
ur_pfnPhysicalMemCreate_t pfnCreate;
984993
ur_pfnPhysicalMemRetain_t pfnRetain;
985994
ur_pfnPhysicalMemRelease_t pfnRelease;
995+
ur_pfnPhysicalMemGetInfo_t pfnGetInfo;
986996
} ur_physical_mem_dditable_t;
987997

988998
///////////////////////////////////////////////////////////////////////////////

include/ur_print.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urPrintPhysicalMemFlags(enum ur_physical_mem
594594
/// - `buff_size < out_size`
595595
UR_APIEXPORT ur_result_t UR_APICALL urPrintPhysicalMemProperties(const struct ur_physical_mem_properties_t params, char *buffer, const size_t buff_size, size_t *out_size);
596596

597+
///////////////////////////////////////////////////////////////////////////////
598+
/// @brief Print ur_physical_mem_info_t enum
599+
/// @returns
600+
/// - ::UR_RESULT_SUCCESS
601+
/// - ::UR_RESULT_ERROR_INVALID_SIZE
602+
/// - `buff_size < out_size`
603+
UR_APIEXPORT ur_result_t UR_APICALL urPrintPhysicalMemInfo(enum ur_physical_mem_info_t value, char *buffer, const size_t buff_size, size_t *out_size);
604+
597605
///////////////////////////////////////////////////////////////////////////////
598606
/// @brief Print ur_program_metadata_type_t enum
599607
/// @returns
@@ -1786,6 +1794,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urPrintPhysicalMemRetainParams(const struct
17861794
/// - `buff_size < out_size`
17871795
UR_APIEXPORT ur_result_t UR_APICALL urPrintPhysicalMemReleaseParams(const struct ur_physical_mem_release_params_t *params, char *buffer, const size_t buff_size, size_t *out_size);
17881796

1797+
///////////////////////////////////////////////////////////////////////////////
1798+
/// @brief Print ur_physical_mem_get_info_params_t struct
1799+
/// @returns
1800+
/// - ::UR_RESULT_SUCCESS
1801+
/// - ::UR_RESULT_ERROR_INVALID_SIZE
1802+
/// - `buff_size < out_size`
1803+
UR_APIEXPORT ur_result_t UR_APICALL urPrintPhysicalMemGetInfoParams(const struct ur_physical_mem_get_info_params_t *params, char *buffer, const size_t buff_size, size_t *out_size);
1804+
17891805
///////////////////////////////////////////////////////////////////////////////
17901806
/// @brief Print ur_adapter_get_params_t struct
17911807
/// @returns

include/ur_print.hpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_virtual_mem
153153
template <>
154154
inline ur_result_t printFlag<ur_physical_mem_flag_t>(std::ostream &os, uint32_t flag);
155155

156+
template <>
157+
inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_physical_mem_info_t value, size_t size);
158+
156159
inline ur_result_t printUnion(
157160
std::ostream &os,
158161
const union ur_program_metadata_value_t params,
@@ -290,6 +293,7 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_virtual_mem_access_fla
290293
inline std::ostream &operator<<(std::ostream &os, enum ur_virtual_mem_info_t value);
291294
inline std::ostream &operator<<(std::ostream &os, enum ur_physical_mem_flag_t value);
292295
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_physical_mem_properties_t params);
296+
inline std::ostream &operator<<(std::ostream &os, enum ur_physical_mem_info_t value);
293297
inline std::ostream &operator<<(std::ostream &os, enum ur_program_metadata_type_t value);
294298
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_program_metadata_t params);
295299
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_program_properties_t params);
@@ -954,6 +958,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) {
954958
case UR_FUNCTION_BINDLESS_IMAGES_MAP_EXTERNAL_LINEAR_MEMORY_EXP:
955959
os << "UR_FUNCTION_BINDLESS_IMAGES_MAP_EXTERNAL_LINEAR_MEMORY_EXP";
956960
break;
961+
case UR_FUNCTION_PHYSICAL_MEM_GET_INFO:
962+
os << "UR_FUNCTION_PHYSICAL_MEM_GET_INFO";
963+
break;
957964
default:
958965
os << "unknown enumerator";
959966
break;
@@ -7403,6 +7410,51 @@ inline std::ostream &operator<<(std::ostream &os, const struct ur_physical_mem_p
74037410
os << "}";
74047411
return os;
74057412
}
7413+
///////////////////////////////////////////////////////////////////////////////
7414+
/// @brief Print operator for the ur_physical_mem_info_t type
7415+
/// @returns
7416+
/// std::ostream &
7417+
inline std::ostream &operator<<(std::ostream &os, enum ur_physical_mem_info_t value) {
7418+
switch (value) {
7419+
case UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT:
7420+
os << "UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT";
7421+
break;
7422+
default:
7423+
os << "unknown enumerator";
7424+
break;
7425+
}
7426+
return os;
7427+
}
7428+
namespace ur::details {
7429+
///////////////////////////////////////////////////////////////////////////////
7430+
/// @brief Print ur_physical_mem_info_t enum value
7431+
template <>
7432+
inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_physical_mem_info_t value, size_t size) {
7433+
if (ptr == NULL) {
7434+
return printPtr(os, ptr);
7435+
}
7436+
7437+
switch (value) {
7438+
case UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT: {
7439+
const uint32_t *tptr = (const uint32_t *)ptr;
7440+
if (sizeof(uint32_t) > size) {
7441+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(uint32_t) << ")";
7442+
return UR_RESULT_ERROR_INVALID_SIZE;
7443+
}
7444+
os << (const void *)(tptr) << " (";
7445+
7446+
os << *tptr;
7447+
7448+
os << ")";
7449+
} break;
7450+
default:
7451+
os << "unknown enumerator";
7452+
return UR_RESULT_ERROR_INVALID_ENUMERATION;
7453+
}
7454+
return UR_RESULT_SUCCESS;
7455+
}
7456+
} // namespace ur::details
7457+
74067458
///////////////////////////////////////////////////////////////////////////////
74077459
/// @brief Print operator for the ur_program_metadata_type_t type
74087460
/// @returns
@@ -12970,6 +13022,40 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1297013022
return os;
1297113023
}
1297213024

13025+
///////////////////////////////////////////////////////////////////////////////
13026+
/// @brief Print operator for the ur_physical_mem_get_info_params_t type
13027+
/// @returns
13028+
/// std::ostream &
13029+
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_physical_mem_get_info_params_t *params) {
13030+
13031+
os << ".hPhysicalMem = ";
13032+
13033+
ur::details::printPtr(os,
13034+
*(params->phPhysicalMem));
13035+
13036+
os << ", ";
13037+
os << ".propName = ";
13038+
13039+
os << *(params->ppropName);
13040+
13041+
os << ", ";
13042+
os << ".propSize = ";
13043+
13044+
os << *(params->ppropSize);
13045+
13046+
os << ", ";
13047+
os << ".pPropValue = ";
13048+
ur::details::printTagged(os, *(params->ppPropValue), *(params->ppropName), *(params->ppropSize));
13049+
13050+
os << ", ";
13051+
os << ".pPropSizeRet = ";
13052+
13053+
ur::details::printPtr(os,
13054+
*(params->ppPropSizeRet));
13055+
13056+
return os;
13057+
}
13058+
1297313059
///////////////////////////////////////////////////////////////////////////////
1297413060
/// @brief Print operator for the ur_adapter_get_params_t type
1297513061
/// @returns
@@ -18370,6 +18456,9 @@ inline ur_result_t UR_APICALL printFunctionParams(std::ostream &os, ur_function_
1837018456
case UR_FUNCTION_PHYSICAL_MEM_RELEASE: {
1837118457
os << (const struct ur_physical_mem_release_params_t *)params;
1837218458
} break;
18459+
case UR_FUNCTION_PHYSICAL_MEM_GET_INFO: {
18460+
os << (const struct ur_physical_mem_get_info_params_t *)params;
18461+
} break;
1837318462
case UR_FUNCTION_ADAPTER_GET: {
1837418463
os << (const struct ur_adapter_get_params_t *)params;
1837518464
} break;

scripts/core/registry.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,9 @@ etors:
604604
- name: BINDLESS_IMAGES_MAP_EXTERNAL_LINEAR_MEMORY_EXP
605605
desc: Enumerator for $xBindlessImagesMapExternalLinearMemoryExp
606606
value: '245'
607+
- name: PHYSICAL_MEM_GET_INFO
608+
desc: Enumerator for $xPhysicalMemGetInfo
609+
value: '246'
607610
---
608611
type: enum
609612
desc: Defines structure types

scripts/core/virtual_memory.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,45 @@ params:
303303
- type: $x_physical_mem_handle_t
304304
name: hPhysicalMem
305305
desc: "[in][release] handle of the physical memory object to release."
306+
307+
--- #--------------------------------------------------------------------------
308+
type: enum
309+
desc: "Physical memory range info queries."
310+
class: $xPhysicalMem
311+
name: $x_physical_mem_info_t
312+
typed_etors: True
313+
etors:
314+
# properties and size too
315+
- name: REFERENCE_COUNT
316+
desc: |
317+
[uint32_t] Reference count of the physical memory object.
318+
The reference count returned should be considered immediately stale.
319+
It is unsuitable for general use in applications. This feature is provided for identifying memory leaks.
320+
321+
--- #--------------------------------------------------------------------------
322+
type: function
323+
desc: "Get information about a physical memory object."
324+
class: $xPhysicalMem
325+
name: GetInfo
326+
params:
327+
- type: $x_physical_mem_handle_t
328+
name: hPhysicalMem
329+
desc: "[in][] handle of the physical memory object to query."
330+
- type: $x_physical_mem_info_t
331+
name: propName
332+
desc: "[in] type of the info to query."
333+
- type: size_t
334+
name: propSize
335+
desc: "[in] size in bytes of the memory pointed to by pPropValue."
336+
- type: void*
337+
name: pPropValue
338+
desc: >
339+
[out][optional][typename(propName, propSize)] array of bytes holding
340+
the info. If propSize is less than the real number of bytes needed to
341+
return the info then the $X_RESULT_ERROR_INVALID_SIZE error is
342+
returned and pPropValue is not used.
343+
- type: size_t*
344+
name: pPropSizeRet
345+
desc: >
346+
[out][optional] pointer to the actual size in bytes of the queried
347+
propName."

source/adapters/cuda/physical_mem.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,19 @@ urPhysicalMemRelease(ur_physical_mem_handle_t hPhysicalMem) {
6666
}
6767
return UR_RESULT_SUCCESS;
6868
}
69+
70+
UR_APIEXPORT ur_result_t UR_APICALL urPhysicalMemGetInfo(
71+
ur_physical_mem_handle_t hPhysicalMem, ur_physical_mem_info_t propName,
72+
size_t propSize, void *pPropValue, size_t *pPropSizeRet) {
73+
74+
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
75+
76+
switch (propName) {
77+
case UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT: {
78+
return ReturnValue(hPhysicalMem->getReferenceCount());
79+
}
80+
default:
81+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
82+
}
83+
return UR_RESULT_SUCCESS;
84+
}

source/adapters/cuda/ur_interface_loader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetPhysicalMemProcAddrTable(
400400
pDdiTable->pfnCreate = urPhysicalMemCreate;
401401
pDdiTable->pfnRelease = urPhysicalMemRelease;
402402
pDdiTable->pfnRetain = urPhysicalMemRetain;
403+
pDdiTable->pfnGetInfo = urPhysicalMemGetInfo;
403404

404405
return retVal;
405406
}

source/adapters/hip/physical_mem.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ UR_APIEXPORT ur_result_t UR_APICALL
2828
urPhysicalMemRelease(ur_physical_mem_handle_t) {
2929
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
3030
}
31+
32+
UR_APIEXPORT ur_result_t UR_APICALL
33+
urPhysicalMemGetInfo(ur_physical_mem_handle_t, ur_physical_mem_info_t, size_t,
34+
void *, size_t *) {
35+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
36+
}

0 commit comments

Comments
 (0)