@@ -22,9 +22,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMHostAlloc(ur_context_handle_t hContext,
22
22
size_t size, void **ppMem) {
23
23
OL_RETURN_ON_ERR (olMemAlloc (hContext->Device ->OffloadDevice ,
24
24
OL_ALLOC_TYPE_HOST, size, ppMem));
25
-
26
- hContext->AllocTypeMap .insert_or_assign (
27
- *ppMem, alloc_info_t {OL_ALLOC_TYPE_HOST, size});
28
25
return UR_RESULT_SUCCESS;
29
26
}
30
27
@@ -33,9 +30,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMDeviceAlloc(
33
30
ur_usm_pool_handle_t , size_t size, void **ppMem) {
34
31
OL_RETURN_ON_ERR (olMemAlloc (hContext->Device ->OffloadDevice ,
35
32
OL_ALLOC_TYPE_DEVICE, size, ppMem));
36
-
37
- hContext->AllocTypeMap .insert_or_assign (
38
- *ppMem, alloc_info_t {OL_ALLOC_TYPE_DEVICE, size});
39
33
return UR_RESULT_SUCCESS;
40
34
}
41
35
@@ -44,23 +38,83 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMSharedAlloc(
44
38
ur_usm_pool_handle_t , size_t size, void **ppMem) {
45
39
OL_RETURN_ON_ERR (olMemAlloc (hContext->Device ->OffloadDevice ,
46
40
OL_ALLOC_TYPE_MANAGED, size, ppMem));
47
-
48
- hContext->AllocTypeMap .insert_or_assign (
49
- *ppMem, alloc_info_t {OL_ALLOC_TYPE_MANAGED, size});
50
41
return UR_RESULT_SUCCESS;
51
42
}
52
43
53
44
UR_APIEXPORT ur_result_t UR_APICALL urUSMFree (ur_context_handle_t hContext,
54
45
void *pMem) {
55
- hContext-> AllocTypeMap . erase (pMem);
56
- return offloadResultToUR ( olMemFree (pMem));
46
+ return offloadResultToUR (
47
+ olMemFree (hContext-> Device -> Platform -> OffloadPlatform , pMem));
57
48
}
58
49
59
- UR_APIEXPORT ur_result_t UR_APICALL urUSMGetMemAllocInfo (
60
- [[maybe_unused]] ur_context_handle_t hContext,
61
- [[maybe_unused]] const void *pMem,
62
- [[maybe_unused]] ur_usm_alloc_info_t propName,
63
- [[maybe_unused]] size_t propSize, [[maybe_unused]] void *pPropValue,
64
- [[maybe_unused]] size_t *pPropSizeRet) {
65
- return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
50
+ UR_APIEXPORT ur_result_t UR_APICALL
51
+ urUSMGetMemAllocInfo (ur_context_handle_t hContext, const void *pMem,
52
+ ur_usm_alloc_info_t propName, size_t propSize,
53
+ void *pPropValue, size_t *pPropSizeRet) {
54
+ UrReturnHelper ReturnValue (propSize, pPropValue, pPropSizeRet);
55
+
56
+ auto Platform = hContext->Device ->Platform ->OffloadPlatform ;
57
+ ol_mem_info_t olInfo;
58
+
59
+ switch (propName) {
60
+ case UR_USM_ALLOC_INFO_TYPE:
61
+ olInfo = OL_MEM_INFO_TYPE;
62
+ break ;
63
+ case UR_USM_ALLOC_INFO_BASE_PTR:
64
+ olInfo = OL_MEM_INFO_BASE;
65
+ break ;
66
+ case UR_USM_ALLOC_INFO_SIZE:
67
+ olInfo = OL_MEM_INFO_SIZE;
68
+ break ;
69
+ case UR_USM_ALLOC_INFO_DEVICE:
70
+ // Contexts can only contain one device
71
+ return ReturnValue (hContext->Device );
72
+ case UR_USM_ALLOC_INFO_POOL:
73
+ default :
74
+ return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
75
+ break ;
76
+ }
77
+
78
+ if (pPropSizeRet) {
79
+ OL_RETURN_ON_ERR (olGetMemInfoSize (Platform, pMem, olInfo, pPropSizeRet));
80
+ }
81
+
82
+ if (pPropValue) {
83
+ auto Err = olGetMemInfo (Platform, pMem, olInfo, propSize, pPropValue);
84
+ if (Err && Err->Code == OL_ERRC_NOT_FOUND) {
85
+ // If the device didn't allocate this object, return default values
86
+ switch (propName) {
87
+ case UR_USM_ALLOC_INFO_TYPE:
88
+ return ReturnValue (UR_USM_TYPE_UNKNOWN);
89
+ case UR_USM_ALLOC_INFO_BASE_PTR:
90
+ return ReturnValue (nullptr );
91
+ case UR_USM_ALLOC_INFO_SIZE:
92
+ return ReturnValue (0 );
93
+ default :
94
+ return UR_RESULT_ERROR_UNKNOWN;
95
+ }
96
+ }
97
+ OL_RETURN_ON_ERR (Err);
98
+
99
+ if (propName == UR_USM_ALLOC_INFO_TYPE) {
100
+ auto *OlType = reinterpret_cast <ol_alloc_type_t *>(pPropValue);
101
+ auto *UrType = reinterpret_cast <ur_usm_type_t *>(pPropValue);
102
+ switch (*OlType) {
103
+ case OL_ALLOC_TYPE_HOST:
104
+ *UrType = UR_USM_TYPE_HOST;
105
+ break ;
106
+ case OL_ALLOC_TYPE_DEVICE:
107
+ *UrType = UR_USM_TYPE_DEVICE;
108
+ break ;
109
+ case OL_ALLOC_TYPE_MANAGED:
110
+ *UrType = UR_USM_TYPE_SHARED;
111
+ break ;
112
+ default :
113
+ *UrType = UR_USM_TYPE_UNKNOWN;
114
+ break ;
115
+ }
116
+ }
117
+ }
118
+
119
+ return UR_RESULT_SUCCESS;
66
120
}
0 commit comments