Skip to content

Commit 3706cbc

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 5b57041 commit 3706cbc

40 files changed

+942
-43
lines changed

include/ur_api.h

Lines changed: 58 additions & 1 deletion
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
@@ -2518,7 +2519,7 @@ typedef enum ur_mem_type_t {
25182519
///////////////////////////////////////////////////////////////////////////////
25192520
/// @brief Memory Information type
25202521
typedef enum ur_mem_info_t {
2521-
UR_MEM_INFO_SIZE = 0, ///< [size_t] actual size of of memory object in bytes
2522+
UR_MEM_INFO_SIZE = 0, ///< [size_t] actual size of the memory object in bytes
25222523
UR_MEM_INFO_CONTEXT = 1, ///< [::ur_context_handle_t] context in which the memory object was created
25232524
UR_MEM_INFO_REFERENCE_COUNT = 2, ///< [uint32_t] Reference count of the memory object.
25242525
///< The reference count returned should be considered immediately stale.
@@ -4126,6 +4127,50 @@ 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_CONTEXT = 0, ///< [::ur_context_handle_t] context in which the physical memory object
4134+
///< was created.
4135+
UR_PHYSICAL_MEM_INFO_DEVICE = 1, ///< [::ur_device_handle_t] device associated with this physical memory
4136+
///< object.
4137+
UR_PHYSICAL_MEM_INFO_SIZE = 2, ///< [size_t] actual size of the physical memory object in bytes.
4138+
UR_PHYSICAL_MEM_INFO_PROPERTIES = 3, ///< [::ur_physical_mem_properties_t] properties set when creating this
4139+
///< physical memory object.
4140+
UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT = 4, ///< [uint32_t] Reference count of the physical memory object.
4141+
///< The reference count returned should be considered immediately stale.
4142+
///< It is unsuitable for general use in applications. This feature is
4143+
///< provided for identifying memory leaks.
4144+
/// @cond
4145+
UR_PHYSICAL_MEM_INFO_FORCE_UINT32 = 0x7fffffff
4146+
/// @endcond
4147+
4148+
} ur_physical_mem_info_t;
4149+
4150+
///////////////////////////////////////////////////////////////////////////////
4151+
/// @brief Get information about a physical memory object.
4152+
///
4153+
/// @returns
4154+
/// - ::UR_RESULT_SUCCESS
4155+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
4156+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
4157+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
4158+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
4159+
/// + `NULL == hPhysicalMem`
4160+
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
4161+
/// + `::UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT < propName`
4162+
UR_APIEXPORT ur_result_t UR_APICALL
4163+
urPhysicalMemGetInfo(
4164+
ur_physical_mem_handle_t hPhysicalMem, ///< [in][] handle of the physical memory object to query.
4165+
ur_physical_mem_info_t propName, ///< [in] type of the info to query.
4166+
size_t propSize, ///< [in] size in bytes of the memory pointed to by pPropValue.
4167+
void *pPropValue, ///< [out][optional][typename(propName, propSize)] array of bytes holding
4168+
///< the info. If propSize is less than the real number of bytes needed to
4169+
///< return the info then the ::UR_RESULT_ERROR_INVALID_SIZE error is
4170+
///< returned and pPropValue is not used.
4171+
size_t *pPropSizeRet ///< [out][optional] pointer to the actual size in bytes of the queried propName."
4172+
);
4173+
41294174
#if !defined(__GNUC__)
41304175
#pragma endregion
41314176
#endif
@@ -11072,6 +11117,18 @@ typedef struct ur_physical_mem_release_params_t {
1107211117
ur_physical_mem_handle_t *phPhysicalMem;
1107311118
} ur_physical_mem_release_params_t;
1107411119

11120+
///////////////////////////////////////////////////////////////////////////////
11121+
/// @brief Function parameters for urPhysicalMemGetInfo
11122+
/// @details Each entry is a pointer to the parameter passed to the function;
11123+
/// allowing the callback the ability to modify the parameter's value
11124+
typedef struct ur_physical_mem_get_info_params_t {
11125+
ur_physical_mem_handle_t *phPhysicalMem;
11126+
ur_physical_mem_info_t *ppropName;
11127+
size_t *ppropSize;
11128+
void **ppPropValue;
11129+
size_t **ppPropSizeRet;
11130+
} ur_physical_mem_get_info_params_t;
11131+
1107511132
///////////////////////////////////////////////////////////////////////////////
1107611133
/// @brief Function parameters for urAdapterGet
1107711134
/// @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: 151 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,113 @@ 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_CONTEXT:
7451+
os << "UR_PHYSICAL_MEM_INFO_CONTEXT";
7452+
break;
7453+
case UR_PHYSICAL_MEM_INFO_DEVICE:
7454+
os << "UR_PHYSICAL_MEM_INFO_DEVICE";
7455+
break;
7456+
case UR_PHYSICAL_MEM_INFO_SIZE:
7457+
os << "UR_PHYSICAL_MEM_INFO_SIZE";
7458+
break;
7459+
case UR_PHYSICAL_MEM_INFO_PROPERTIES:
7460+
os << "UR_PHYSICAL_MEM_INFO_PROPERTIES";
7461+
break;
7462+
case UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT:
7463+
os << "UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT";
7464+
break;
7465+
default:
7466+
os << "unknown enumerator";
7467+
break;
7468+
}
7469+
return os;
7470+
}
7471+
namespace ur::details {
7472+
///////////////////////////////////////////////////////////////////////////////
7473+
/// @brief Print ur_physical_mem_info_t enum value
7474+
template <>
7475+
inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_physical_mem_info_t value, size_t size) {
7476+
if (ptr == NULL) {
7477+
return printPtr(os, ptr);
7478+
}
7479+
7480+
switch (value) {
7481+
case UR_PHYSICAL_MEM_INFO_CONTEXT: {
7482+
const ur_context_handle_t *tptr = (const ur_context_handle_t *)ptr;
7483+
if (sizeof(ur_context_handle_t) > size) {
7484+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_context_handle_t) << ")";
7485+
return UR_RESULT_ERROR_INVALID_SIZE;
7486+
}
7487+
os << (const void *)(tptr) << " (";
7488+
7489+
ur::details::printPtr(os,
7490+
*tptr);
7491+
7492+
os << ")";
7493+
} break;
7494+
case UR_PHYSICAL_MEM_INFO_DEVICE: {
7495+
const ur_device_handle_t *tptr = (const ur_device_handle_t *)ptr;
7496+
if (sizeof(ur_device_handle_t) > size) {
7497+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_device_handle_t) << ")";
7498+
return UR_RESULT_ERROR_INVALID_SIZE;
7499+
}
7500+
os << (const void *)(tptr) << " (";
7501+
7502+
ur::details::printPtr(os,
7503+
*tptr);
7504+
7505+
os << ")";
7506+
} break;
7507+
case UR_PHYSICAL_MEM_INFO_SIZE: {
7508+
const size_t *tptr = (const size_t *)ptr;
7509+
if (sizeof(size_t) > size) {
7510+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(size_t) << ")";
7511+
return UR_RESULT_ERROR_INVALID_SIZE;
7512+
}
7513+
os << (const void *)(tptr) << " (";
7514+
7515+
os << *tptr;
7516+
7517+
os << ")";
7518+
} break;
7519+
case UR_PHYSICAL_MEM_INFO_PROPERTIES: {
7520+
const ur_physical_mem_properties_t *tptr = (const ur_physical_mem_properties_t *)ptr;
7521+
if (sizeof(ur_physical_mem_properties_t) > size) {
7522+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_physical_mem_properties_t) << ")";
7523+
return UR_RESULT_ERROR_INVALID_SIZE;
7524+
}
7525+
os << (const void *)(tptr) << " (";
7526+
7527+
os << *tptr;
7528+
7529+
os << ")";
7530+
} break;
7531+
case UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT: {
7532+
const uint32_t *tptr = (const uint32_t *)ptr;
7533+
if (sizeof(uint32_t) > size) {
7534+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(uint32_t) << ")";
7535+
return UR_RESULT_ERROR_INVALID_SIZE;
7536+
}
7537+
os << (const void *)(tptr) << " (";
7538+
7539+
os << *tptr;
7540+
7541+
os << ")";
7542+
} break;
7543+
default:
7544+
os << "unknown enumerator";
7545+
return UR_RESULT_ERROR_INVALID_ENUMERATION;
7546+
}
7547+
return UR_RESULT_SUCCESS;
7548+
}
7549+
} // namespace ur::details
7550+
74377551
///////////////////////////////////////////////////////////////////////////////
74387552
/// @brief Print operator for the ur_program_metadata_type_t type
74397553
/// @returns
@@ -13085,6 +13199,40 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1308513199
return os;
1308613200
}
1308713201

13202+
///////////////////////////////////////////////////////////////////////////////
13203+
/// @brief Print operator for the ur_physical_mem_get_info_params_t type
13204+
/// @returns
13205+
/// std::ostream &
13206+
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_physical_mem_get_info_params_t *params) {
13207+
13208+
os << ".hPhysicalMem = ";
13209+
13210+
ur::details::printPtr(os,
13211+
*(params->phPhysicalMem));
13212+
13213+
os << ", ";
13214+
os << ".propName = ";
13215+
13216+
os << *(params->ppropName);
13217+
13218+
os << ", ";
13219+
os << ".propSize = ";
13220+
13221+
os << *(params->ppropSize);
13222+
13223+
os << ", ";
13224+
os << ".pPropValue = ";
13225+
ur::details::printTagged(os, *(params->ppPropValue), *(params->ppropName), *(params->ppropSize));
13226+
13227+
os << ", ";
13228+
os << ".pPropSizeRet = ";
13229+
13230+
ur::details::printPtr(os,
13231+
*(params->ppPropSizeRet));
13232+
13233+
return os;
13234+
}
13235+
1308813236
///////////////////////////////////////////////////////////////////////////////
1308913237
/// @brief Print operator for the ur_adapter_get_params_t type
1309013238
/// @returns
@@ -18528,6 +18676,9 @@ inline ur_result_t UR_APICALL printFunctionParams(std::ostream &os, ur_function_
1852818676
case UR_FUNCTION_PHYSICAL_MEM_RELEASE: {
1852918677
os << (const struct ur_physical_mem_release_params_t *)params;
1853018678
} break;
18679+
case UR_FUNCTION_PHYSICAL_MEM_GET_INFO: {
18680+
os << (const struct ur_physical_mem_get_info_params_t *)params;
18681+
} break;
1853118682
case UR_FUNCTION_ADAPTER_GET: {
1853218683
os << (const struct ur_adapter_get_params_t *)params;
1853318684
} break;

scripts/core/memory.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ name: $x_mem_info_t
5959
typed_etors: True
6060
etors:
6161
- name: SIZE
62-
desc: "[size_t] actual size of of memory object in bytes"
62+
desc: "[size_t] actual size of the memory object in bytes"
6363
- name: CONTEXT
6464
desc: "[$x_context_handle_t] context in which the memory object was created"
6565
- name: REFERENCE_COUNT

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

0 commit comments

Comments
 (0)