Skip to content

Commit d718ade

Browse files
authored
Merge pull request #2272 from martygrant/martin/virtual-memory-cts-spec-gap
Improvements to align CTS and Spec for Virtual Memory
2 parents 4fdb8f5 + 5df72d4 commit d718ade

40 files changed

+941
-43
lines changed

include/ur_api.h

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ typedef enum ur_function_t {
233233
UR_FUNCTION_ENQUEUE_EVENTS_WAIT_WITH_BARRIER_EXT = 246, ///< Enumerator for ::urEnqueueEventsWaitWithBarrierExt
234234
UR_FUNCTION_TENSOR_MAP_ENCODE_IM_2_COL_EXP = 247, ///< Enumerator for ::urTensorMapEncodeIm2ColExp
235235
UR_FUNCTION_TENSOR_MAP_ENCODE_TILED_EXP = 248, ///< Enumerator for ::urTensorMapEncodeTiledExp
236+
UR_FUNCTION_PHYSICAL_MEM_GET_INFO = 249, ///< Enumerator for ::urPhysicalMemGetInfo
236237
/// @cond
237238
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
238239
/// @endcond
@@ -2525,7 +2526,7 @@ typedef enum ur_mem_type_t {
25252526
///////////////////////////////////////////////////////////////////////////////
25262527
/// @brief Memory Information type
25272528
typedef enum ur_mem_info_t {
2528-
UR_MEM_INFO_SIZE = 0, ///< [size_t] actual size of of memory object in bytes
2529+
UR_MEM_INFO_SIZE = 0, ///< [size_t] actual size of the memory object in bytes
25292530
UR_MEM_INFO_CONTEXT = 1, ///< [::ur_context_handle_t] context in which the memory object was created
25302531
UR_MEM_INFO_REFERENCE_COUNT = 2, ///< [uint32_t] Reference count of the memory object.
25312532
///< The reference count returned should be considered immediately stale.
@@ -4138,6 +4139,50 @@ urPhysicalMemRelease(
41384139
ur_physical_mem_handle_t hPhysicalMem ///< [in][release] handle of the physical memory object to release.
41394140
);
41404141

4142+
///////////////////////////////////////////////////////////////////////////////
4143+
/// @brief Physical memory range info queries.
4144+
typedef enum ur_physical_mem_info_t {
4145+
UR_PHYSICAL_MEM_INFO_CONTEXT = 0, ///< [::ur_context_handle_t] context in which the physical memory object
4146+
///< was created.
4147+
UR_PHYSICAL_MEM_INFO_DEVICE = 1, ///< [::ur_device_handle_t] device associated with this physical memory
4148+
///< object.
4149+
UR_PHYSICAL_MEM_INFO_SIZE = 2, ///< [size_t] actual size of the physical memory object in bytes.
4150+
UR_PHYSICAL_MEM_INFO_PROPERTIES = 3, ///< [::ur_physical_mem_properties_t] properties set when creating this
4151+
///< physical memory object.
4152+
UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT = 4, ///< [uint32_t] Reference count of the physical memory object.
4153+
///< The reference count returned should be considered immediately stale.
4154+
///< It is unsuitable for general use in applications. This feature is
4155+
///< provided for identifying memory leaks.
4156+
/// @cond
4157+
UR_PHYSICAL_MEM_INFO_FORCE_UINT32 = 0x7fffffff
4158+
/// @endcond
4159+
4160+
} ur_physical_mem_info_t;
4161+
4162+
///////////////////////////////////////////////////////////////////////////////
4163+
/// @brief Get information about a physical memory object.
4164+
///
4165+
/// @returns
4166+
/// - ::UR_RESULT_SUCCESS
4167+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
4168+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
4169+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
4170+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
4171+
/// + `NULL == hPhysicalMem`
4172+
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
4173+
/// + `::UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT < propName`
4174+
UR_APIEXPORT ur_result_t UR_APICALL
4175+
urPhysicalMemGetInfo(
4176+
ur_physical_mem_handle_t hPhysicalMem, ///< [in] handle of the physical memory object to query.
4177+
ur_physical_mem_info_t propName, ///< [in] type of the info to query.
4178+
size_t propSize, ///< [in] size in bytes of the memory pointed to by pPropValue.
4179+
void *pPropValue, ///< [out][optional][typename(propName, propSize)] array of bytes holding
4180+
///< the info. If propSize is less than the real number of bytes needed to
4181+
///< return the info then the ::UR_RESULT_ERROR_INVALID_SIZE error is
4182+
///< returned and pPropValue is not used.
4183+
size_t *pPropSizeRet ///< [out][optional] pointer to the actual size in bytes of the queried propName."
4184+
);
4185+
41414186
#if !defined(__GNUC__)
41424187
#pragma endregion
41434188
#endif
@@ -11317,6 +11362,18 @@ typedef struct ur_physical_mem_release_params_t {
1131711362
ur_physical_mem_handle_t *phPhysicalMem;
1131811363
} ur_physical_mem_release_params_t;
1131911364

11365+
///////////////////////////////////////////////////////////////////////////////
11366+
/// @brief Function parameters for urPhysicalMemGetInfo
11367+
/// @details Each entry is a pointer to the parameter passed to the function;
11368+
/// allowing the callback the ability to modify the parameter's value
11369+
typedef struct ur_physical_mem_get_info_params_t {
11370+
ur_physical_mem_handle_t *phPhysicalMem;
11371+
ur_physical_mem_info_t *ppropName;
11372+
size_t *ppropSize;
11373+
void **ppPropValue;
11374+
size_t **ppPropSizeRet;
11375+
} ur_physical_mem_get_info_params_t;
11376+
1132011377
///////////////////////////////////////////////////////////////////////////////
1132111378
/// @brief Function parameters for urAdapterGet
1132211379
/// @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
@@ -978,12 +978,22 @@ typedef ur_result_t(UR_APICALL *ur_pfnPhysicalMemRetain_t)(
978978
typedef ur_result_t(UR_APICALL *ur_pfnPhysicalMemRelease_t)(
979979
ur_physical_mem_handle_t);
980980

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

989999
///////////////////////////////////////////////////////////////////////////////

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
@@ -1850,6 +1858,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urPrintPhysicalMemRetainParams(const struct
18501858
/// - `buff_size < out_size`
18511859
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);
18521860

1861+
///////////////////////////////////////////////////////////////////////////////
1862+
/// @brief Print ur_physical_mem_get_info_params_t struct
1863+
/// @returns
1864+
/// - ::UR_RESULT_SUCCESS
1865+
/// - ::UR_RESULT_ERROR_INVALID_SIZE
1866+
/// - `buff_size < out_size`
1867+
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);
1868+
18531869
///////////////////////////////////////////////////////////////////////////////
18541870
/// @brief Print ur_adapter_get_params_t struct
18551871
/// @returns

include/ur_print.hpp

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

158+
template <>
159+
inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_physical_mem_info_t value, size_t size);
160+
158161
inline ur_result_t printUnion(
159162
std::ostream &os,
160163
const union ur_program_metadata_value_t params,
@@ -313,6 +316,7 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_virtual_mem_access_fla
313316
inline std::ostream &operator<<(std::ostream &os, enum ur_virtual_mem_info_t value);
314317
inline std::ostream &operator<<(std::ostream &os, enum ur_physical_mem_flag_t value);
315318
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_physical_mem_properties_t params);
319+
inline std::ostream &operator<<(std::ostream &os, enum ur_physical_mem_info_t value);
316320
inline std::ostream &operator<<(std::ostream &os, enum ur_program_metadata_type_t value);
317321
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_program_metadata_t params);
318322
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_program_properties_t params);
@@ -994,6 +998,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) {
994998
case UR_FUNCTION_TENSOR_MAP_ENCODE_TILED_EXP:
995999
os << "UR_FUNCTION_TENSOR_MAP_ENCODE_TILED_EXP";
9961000
break;
1001+
case UR_FUNCTION_PHYSICAL_MEM_GET_INFO:
1002+
os << "UR_FUNCTION_PHYSICAL_MEM_GET_INFO";
1003+
break;
9971004
default:
9981005
os << "unknown enumerator";
9991006
break;
@@ -7498,6 +7505,113 @@ inline std::ostream &operator<<(std::ostream &os, const struct ur_physical_mem_p
74987505
os << "}";
74997506
return os;
75007507
}
7508+
///////////////////////////////////////////////////////////////////////////////
7509+
/// @brief Print operator for the ur_physical_mem_info_t type
7510+
/// @returns
7511+
/// std::ostream &
7512+
inline std::ostream &operator<<(std::ostream &os, enum ur_physical_mem_info_t value) {
7513+
switch (value) {
7514+
case UR_PHYSICAL_MEM_INFO_CONTEXT:
7515+
os << "UR_PHYSICAL_MEM_INFO_CONTEXT";
7516+
break;
7517+
case UR_PHYSICAL_MEM_INFO_DEVICE:
7518+
os << "UR_PHYSICAL_MEM_INFO_DEVICE";
7519+
break;
7520+
case UR_PHYSICAL_MEM_INFO_SIZE:
7521+
os << "UR_PHYSICAL_MEM_INFO_SIZE";
7522+
break;
7523+
case UR_PHYSICAL_MEM_INFO_PROPERTIES:
7524+
os << "UR_PHYSICAL_MEM_INFO_PROPERTIES";
7525+
break;
7526+
case UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT:
7527+
os << "UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT";
7528+
break;
7529+
default:
7530+
os << "unknown enumerator";
7531+
break;
7532+
}
7533+
return os;
7534+
}
7535+
namespace ur::details {
7536+
///////////////////////////////////////////////////////////////////////////////
7537+
/// @brief Print ur_physical_mem_info_t enum value
7538+
template <>
7539+
inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_physical_mem_info_t value, size_t size) {
7540+
if (ptr == NULL) {
7541+
return printPtr(os, ptr);
7542+
}
7543+
7544+
switch (value) {
7545+
case UR_PHYSICAL_MEM_INFO_CONTEXT: {
7546+
const ur_context_handle_t *tptr = (const ur_context_handle_t *)ptr;
7547+
if (sizeof(ur_context_handle_t) > size) {
7548+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_context_handle_t) << ")";
7549+
return UR_RESULT_ERROR_INVALID_SIZE;
7550+
}
7551+
os << (const void *)(tptr) << " (";
7552+
7553+
ur::details::printPtr(os,
7554+
*tptr);
7555+
7556+
os << ")";
7557+
} break;
7558+
case UR_PHYSICAL_MEM_INFO_DEVICE: {
7559+
const ur_device_handle_t *tptr = (const ur_device_handle_t *)ptr;
7560+
if (sizeof(ur_device_handle_t) > size) {
7561+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_device_handle_t) << ")";
7562+
return UR_RESULT_ERROR_INVALID_SIZE;
7563+
}
7564+
os << (const void *)(tptr) << " (";
7565+
7566+
ur::details::printPtr(os,
7567+
*tptr);
7568+
7569+
os << ")";
7570+
} break;
7571+
case UR_PHYSICAL_MEM_INFO_SIZE: {
7572+
const size_t *tptr = (const size_t *)ptr;
7573+
if (sizeof(size_t) > size) {
7574+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(size_t) << ")";
7575+
return UR_RESULT_ERROR_INVALID_SIZE;
7576+
}
7577+
os << (const void *)(tptr) << " (";
7578+
7579+
os << *tptr;
7580+
7581+
os << ")";
7582+
} break;
7583+
case UR_PHYSICAL_MEM_INFO_PROPERTIES: {
7584+
const ur_physical_mem_properties_t *tptr = (const ur_physical_mem_properties_t *)ptr;
7585+
if (sizeof(ur_physical_mem_properties_t) > size) {
7586+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_physical_mem_properties_t) << ")";
7587+
return UR_RESULT_ERROR_INVALID_SIZE;
7588+
}
7589+
os << (const void *)(tptr) << " (";
7590+
7591+
os << *tptr;
7592+
7593+
os << ")";
7594+
} break;
7595+
case UR_PHYSICAL_MEM_INFO_REFERENCE_COUNT: {
7596+
const uint32_t *tptr = (const uint32_t *)ptr;
7597+
if (sizeof(uint32_t) > size) {
7598+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(uint32_t) << ")";
7599+
return UR_RESULT_ERROR_INVALID_SIZE;
7600+
}
7601+
os << (const void *)(tptr) << " (";
7602+
7603+
os << *tptr;
7604+
7605+
os << ")";
7606+
} break;
7607+
default:
7608+
os << "unknown enumerator";
7609+
return UR_RESULT_ERROR_INVALID_ENUMERATION;
7610+
}
7611+
return UR_RESULT_SUCCESS;
7612+
}
7613+
} // namespace ur::details
7614+
75017615
///////////////////////////////////////////////////////////////////////////////
75027616
/// @brief Print operator for the ur_program_metadata_type_t type
75037617
/// @returns
@@ -13805,6 +13919,40 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1380513919
return os;
1380613920
}
1380713921

13922+
///////////////////////////////////////////////////////////////////////////////
13923+
/// @brief Print operator for the ur_physical_mem_get_info_params_t type
13924+
/// @returns
13925+
/// std::ostream &
13926+
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_physical_mem_get_info_params_t *params) {
13927+
13928+
os << ".hPhysicalMem = ";
13929+
13930+
ur::details::printPtr(os,
13931+
*(params->phPhysicalMem));
13932+
13933+
os << ", ";
13934+
os << ".propName = ";
13935+
13936+
os << *(params->ppropName);
13937+
13938+
os << ", ";
13939+
os << ".propSize = ";
13940+
13941+
os << *(params->ppropSize);
13942+
13943+
os << ", ";
13944+
os << ".pPropValue = ";
13945+
ur::details::printTagged(os, *(params->ppPropValue), *(params->ppropName), *(params->ppropSize));
13946+
13947+
os << ", ";
13948+
os << ".pPropSizeRet = ";
13949+
13950+
ur::details::printPtr(os,
13951+
*(params->ppPropSizeRet));
13952+
13953+
return os;
13954+
}
13955+
1380813956
///////////////////////////////////////////////////////////////////////////////
1380913957
/// @brief Print operator for the ur_adapter_get_params_t type
1381013958
/// @returns
@@ -19652,6 +19800,9 @@ inline ur_result_t UR_APICALL printFunctionParams(std::ostream &os, ur_function_
1965219800
case UR_FUNCTION_PHYSICAL_MEM_RELEASE: {
1965319801
os << (const struct ur_physical_mem_release_params_t *)params;
1965419802
} break;
19803+
case UR_FUNCTION_PHYSICAL_MEM_GET_INFO: {
19804+
os << (const struct ur_physical_mem_get_info_params_t *)params;
19805+
} break;
1965519806
case UR_FUNCTION_ADAPTER_GET: {
1965619807
os << (const struct ur_adapter_get_params_t *)params;
1965719808
} 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
@@ -613,6 +613,9 @@ etors:
613613
- name: TENSOR_MAP_ENCODE_TILED_EXP
614614
desc: Enumerator for $xTensorMapEncodeTiledExp
615615
value: '248'
616+
- name: PHYSICAL_MEM_GET_INFO
617+
desc: Enumerator for $xPhysicalMemGetInfo
618+
value: '249'
616619
---
617620
type: enum
618621
desc: Defines structure types

0 commit comments

Comments
 (0)