@@ -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,70 @@ 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
+ OL_RETURN_ON_ERR (
84
+ olGetMemInfo (Platform, pMem, olInfo, propSize, pPropValue));
85
+
86
+ if (propName == UR_USM_ALLOC_INFO_TYPE) {
87
+ auto *OlType = reinterpret_cast <ol_alloc_type_t *>(pPropValue);
88
+ auto *UrType = reinterpret_cast <ur_usm_type_t *>(pPropValue);
89
+ switch (*OlType) {
90
+ case OL_ALLOC_TYPE_HOST:
91
+ *UrType = UR_USM_TYPE_HOST;
92
+ break ;
93
+ case OL_ALLOC_TYPE_DEVICE:
94
+ *UrType = UR_USM_TYPE_DEVICE;
95
+ break ;
96
+ case OL_ALLOC_TYPE_MANAGED:
97
+ *UrType = UR_USM_TYPE_SHARED;
98
+ break ;
99
+ default :
100
+ *UrType = UR_USM_TYPE_UNKNOWN;
101
+ break ;
102
+ }
103
+ }
104
+ }
105
+
106
+ return UR_RESULT_SUCCESS;
66
107
}
0 commit comments