@@ -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,80 @@ 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
- UR_APIEXPORT ur_result_t UR_APICALL urUSMFree (ur_context_handle_t hContext,
54
- void *pMem) {
55
- hContext->AllocTypeMap .erase (pMem);
44
+ UR_APIEXPORT ur_result_t UR_APICALL urUSMFree (ur_context_handle_t , void *pMem) {
56
45
return offloadResultToUR (olMemFree (pMem));
57
46
}
58
47
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;
48
+ UR_APIEXPORT ur_result_t UR_APICALL
49
+ urUSMGetMemAllocInfo (ur_context_handle_t hContext, const void *pMem,
50
+ ur_usm_alloc_info_t propName, size_t propSize,
51
+ void *pPropValue, size_t *pPropSizeRet) {
52
+ UrReturnHelper ReturnValue (propSize, pPropValue, pPropSizeRet);
53
+
54
+ ol_mem_info_t olInfo;
55
+
56
+ switch (propName) {
57
+ case UR_USM_ALLOC_INFO_TYPE:
58
+ olInfo = OL_MEM_INFO_TYPE;
59
+ break ;
60
+ case UR_USM_ALLOC_INFO_BASE_PTR:
61
+ olInfo = OL_MEM_INFO_BASE;
62
+ break ;
63
+ case UR_USM_ALLOC_INFO_SIZE:
64
+ olInfo = OL_MEM_INFO_SIZE;
65
+ break ;
66
+ case UR_USM_ALLOC_INFO_DEVICE:
67
+ // Contexts can only contain one device
68
+ return ReturnValue (hContext->Device );
69
+ case UR_USM_ALLOC_INFO_POOL:
70
+ default :
71
+ return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
72
+ break ;
73
+ }
74
+
75
+ if (pPropSizeRet) {
76
+ OL_RETURN_ON_ERR (olGetMemInfoSize (pMem, olInfo, pPropSizeRet));
77
+ }
78
+
79
+ if (pPropValue) {
80
+ auto Err = olGetMemInfo (pMem, olInfo, propSize, pPropValue);
81
+ if (Err && Err->Code == OL_ERRC_NOT_FOUND) {
82
+ // If the device didn't allocate this object, return default values
83
+ switch (propName) {
84
+ case UR_USM_ALLOC_INFO_TYPE:
85
+ return ReturnValue (UR_USM_TYPE_UNKNOWN);
86
+ case UR_USM_ALLOC_INFO_BASE_PTR:
87
+ return ReturnValue (nullptr );
88
+ case UR_USM_ALLOC_INFO_SIZE:
89
+ return ReturnValue (0 );
90
+ default :
91
+ return UR_RESULT_ERROR_UNKNOWN;
92
+ }
93
+ }
94
+ OL_RETURN_ON_ERR (Err);
95
+
96
+ if (propName == UR_USM_ALLOC_INFO_TYPE) {
97
+ auto *OlType = reinterpret_cast <ol_alloc_type_t *>(pPropValue);
98
+ auto *UrType = reinterpret_cast <ur_usm_type_t *>(pPropValue);
99
+ switch (*OlType) {
100
+ case OL_ALLOC_TYPE_HOST:
101
+ *UrType = UR_USM_TYPE_HOST;
102
+ break ;
103
+ case OL_ALLOC_TYPE_DEVICE:
104
+ *UrType = UR_USM_TYPE_DEVICE;
105
+ break ;
106
+ case OL_ALLOC_TYPE_MANAGED:
107
+ *UrType = UR_USM_TYPE_SHARED;
108
+ break ;
109
+ default :
110
+ *UrType = UR_USM_TYPE_UNKNOWN;
111
+ break ;
112
+ }
113
+ }
114
+ }
115
+
116
+ return UR_RESULT_SUCCESS;
66
117
}
0 commit comments