Skip to content

Commit 400e289

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 3a5b23c commit 400e289

37 files changed

+712
-26
lines changed

include/ur_api.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ typedef enum ur_function_t {
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
233233
UR_FUNCTION_ENQUEUE_EVENTS_WAIT_WITH_BARRIER_EXT = 246, ///< Enumerator for ::urEnqueueEventsWaitWithBarrierExt
234+
UR_FUNCTION_PHYSICAL_MEM_GET_INFO = 247, ///< Enumerator for ::urPhysicalMemGetInfo
234235
/// @cond
235236
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
236237
/// @endcond
@@ -4126,6 +4127,43 @@ urPhysicalMemRelease(
41264127
ur_physical_mem_handle_t hPhysicalMem ///< [in][release] handle of the physical memory object to release.
41274128
);
41284129

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

11113+
///////////////////////////////////////////////////////////////////////////////
11114+
/// @brief Function parameters for urPhysicalMemGetInfo
11115+
/// @details Each entry is a pointer to the parameter passed to the function;
11116+
/// allowing the callback the ability to modify the parameter's value
11117+
typedef struct ur_physical_mem_get_info_params_t {
11118+
ur_physical_mem_handle_t *phPhysicalMem;
11119+
ur_physical_mem_info_t *ppropName;
11120+
size_t *ppropSize;
11121+
void **ppPropValue;
11122+
size_t **ppPropSizeRet;
11123+
} ur_physical_mem_get_info_params_t;
11124+
1107511125
///////////////////////////////////////////////////////////////////////////////
1107611126
/// @brief Function parameters for urAdapterGet
1107711127
/// @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
@@ -1802,6 +1810,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urPrintPhysicalMemRetainParams(const struct
18021810
/// - `buff_size < out_size`
18031811
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);
18041812

1813+
///////////////////////////////////////////////////////////////////////////////
1814+
/// @brief Print ur_physical_mem_get_info_params_t struct
1815+
/// @returns
1816+
/// - ::UR_RESULT_SUCCESS
1817+
/// - ::UR_RESULT_ERROR_INVALID_SIZE
1818+
/// - `buff_size < out_size`
1819+
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);
1820+
18051821
///////////////////////////////////////////////////////////////////////////////
18061822
/// @brief Print ur_adapter_get_params_t struct
18071823
/// @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,
@@ -293,6 +296,7 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_virtual_mem_access_fla
293296
inline std::ostream &operator<<(std::ostream &os, enum ur_virtual_mem_info_t value);
294297
inline std::ostream &operator<<(std::ostream &os, enum ur_physical_mem_flag_t value);
295298
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_physical_mem_properties_t params);
299+
inline std::ostream &operator<<(std::ostream &os, enum ur_physical_mem_info_t value);
296300
inline std::ostream &operator<<(std::ostream &os, enum ur_program_metadata_type_t value);
297301
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_program_metadata_t params);
298302
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_program_properties_t params);
@@ -962,6 +966,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) {
962966
case UR_FUNCTION_ENQUEUE_EVENTS_WAIT_WITH_BARRIER_EXT:
963967
os << "UR_FUNCTION_ENQUEUE_EVENTS_WAIT_WITH_BARRIER_EXT";
964968
break;
969+
case UR_FUNCTION_PHYSICAL_MEM_GET_INFO:
970+
os << "UR_FUNCTION_PHYSICAL_MEM_GET_INFO";
971+
break;
965972
default:
966973
os << "unknown enumerator";
967974
break;
@@ -7434,6 +7441,51 @@ inline std::ostream &operator<<(std::ostream &os, const struct ur_physical_mem_p
74347441
os << "}";
74357442
return os;
74367443
}
7444+
///////////////////////////////////////////////////////////////////////////////
7445+
/// @brief Print operator for the ur_physical_mem_info_t type
7446+
/// @returns
7447+
/// std::ostream &
7448+
inline std::ostream &operator<<(std::ostream &os, enum ur_physical_mem_info_t value) {
7449+
switch (value) {
7450+
case UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT:
7451+
os << "UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT";
7452+
break;
7453+
default:
7454+
os << "unknown enumerator";
7455+
break;
7456+
}
7457+
return os;
7458+
}
7459+
namespace ur::details {
7460+
///////////////////////////////////////////////////////////////////////////////
7461+
/// @brief Print ur_physical_mem_info_t enum value
7462+
template <>
7463+
inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_physical_mem_info_t value, size_t size) {
7464+
if (ptr == NULL) {
7465+
return printPtr(os, ptr);
7466+
}
7467+
7468+
switch (value) {
7469+
case UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT: {
7470+
const uint32_t *tptr = (const uint32_t *)ptr;
7471+
if (sizeof(uint32_t) > size) {
7472+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(uint32_t) << ")";
7473+
return UR_RESULT_ERROR_INVALID_SIZE;
7474+
}
7475+
os << (const void *)(tptr) << " (";
7476+
7477+
os << *tptr;
7478+
7479+
os << ")";
7480+
} break;
7481+
default:
7482+
os << "unknown enumerator";
7483+
return UR_RESULT_ERROR_INVALID_ENUMERATION;
7484+
}
7485+
return UR_RESULT_SUCCESS;
7486+
}
7487+
} // namespace ur::details
7488+
74377489
///////////////////////////////////////////////////////////////////////////////
74387490
/// @brief Print operator for the ur_program_metadata_type_t type
74397491
/// @returns
@@ -13085,6 +13137,40 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1308513137
return os;
1308613138
}
1308713139

13140+
///////////////////////////////////////////////////////////////////////////////
13141+
/// @brief Print operator for the ur_physical_mem_get_info_params_t type
13142+
/// @returns
13143+
/// std::ostream &
13144+
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_physical_mem_get_info_params_t *params) {
13145+
13146+
os << ".hPhysicalMem = ";
13147+
13148+
ur::details::printPtr(os,
13149+
*(params->phPhysicalMem));
13150+
13151+
os << ", ";
13152+
os << ".propName = ";
13153+
13154+
os << *(params->ppropName);
13155+
13156+
os << ", ";
13157+
os << ".propSize = ";
13158+
13159+
os << *(params->ppropSize);
13160+
13161+
os << ", ";
13162+
os << ".pPropValue = ";
13163+
ur::details::printTagged(os, *(params->ppPropValue), *(params->ppropName), *(params->ppropSize));
13164+
13165+
os << ", ";
13166+
os << ".pPropSizeRet = ";
13167+
13168+
ur::details::printPtr(os,
13169+
*(params->ppPropSizeRet));
13170+
13171+
return os;
13172+
}
13173+
1308813174
///////////////////////////////////////////////////////////////////////////////
1308913175
/// @brief Print operator for the ur_adapter_get_params_t type
1309013176
/// @returns
@@ -18528,6 +18614,9 @@ inline ur_result_t UR_APICALL printFunctionParams(std::ostream &os, ur_function_
1852818614
case UR_FUNCTION_PHYSICAL_MEM_RELEASE: {
1852918615
os << (const struct ur_physical_mem_release_params_t *)params;
1853018616
} break;
18617+
case UR_FUNCTION_PHYSICAL_MEM_GET_INFO: {
18618+
os << (const struct ur_physical_mem_get_info_params_t *)params;
18619+
} break;
1853118620
case UR_FUNCTION_ADAPTER_GET: {
1853218621
os << (const struct ur_adapter_get_params_t *)params;
1853318622
} break;

scripts/core/registry.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ etors:
607607
- name: ENQUEUE_EVENTS_WAIT_WITH_BARRIER_EXT
608608
desc: Enumerator for $xEnqueueEventsWaitWithBarrierExt
609609
value: '246'
610+
- name: PHYSICAL_MEM_GET_INFO
611+
desc: Enumerator for $xPhysicalMemGetInfo
612+
value: '247'
610613
---
611614
type: enum
612615
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)