1717#include "memory_provider_internal.h"
1818#include "provider/provider_tracking.h"
1919
20+ // TODO flag - IPC?
2021umf_result_t
2122umfGetMemoryPropertiesHandle (const void * ptr ,
2223 umf_memory_properties_handle_t * props_handle ) {
2324
24- LOG_DEBUG ("umfGetMemoryPropertiesHandle: ptr=%p, props_handle=%p" , ptr ,
25- props_handle );
25+ // LOG_DEBUG("umfGetMemoryPropertiesHandle: ptr=%p, props_handle=%p", ptr,
26+ // props_handle);
2627
27- if (props_handle == NULL ) {
28+ if (UNLIKELY ( props_handle == NULL ) ) {
2829 return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
2930 }
3031
3132 tracker_alloc_info_t * info = NULL ;
3233 umf_result_t ret = umfMemoryTrackerGetAllocInfo (ptr , & info );
33- if (ret != UMF_RESULT_SUCCESS ) {
34- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
34+ if (ret == UMF_RESULT_SUCCESS ) {
35+ * props_handle = & info -> props ;
36+ //LOG_DEBUG("umfGetMemoryPropertiesHandle: props_handle=%p, id=%" PRIu64,
37+ // *props_handle, (*props_handle)->id);
38+ return UMF_RESULT_SUCCESS ;
3539 }
3640
37- * props_handle = & info -> props ;
41+ // try to get IPC info
42+ umf_ipc_info_t ipc_info ;
43+ ret = umfMemoryTrackerGetIpcInfo (ptr , & ipc_info );
44+ if (ret != UMF_RESULT_SUCCESS ) {
45+ LOG_ERR ("Failed to get memory properties handle for ptr=%p" , ptr );
46+ return ret ;
47+ }
3848
39- LOG_DEBUG ("umfGetMemoryPropertiesHandle: props_handle=%p, id=%" PRIu64 ,
40- * props_handle , (* props_handle )-> id );
49+ * props_handle = ipc_info .props ;
50+ //LOG_DEBUG(
51+ // "umfGetMemoryPropertiesHandle (IPC info): props_handle=%p, id=%" PRIu64,
52+ // *props_handle, (*props_handle)->id);
4153
4254 return UMF_RESULT_SUCCESS ;
4355}
@@ -46,62 +58,85 @@ umf_result_t umfGetMemoryProperty(umf_memory_properties_handle_t props_handle,
4658 umf_memory_property_id_t memory_property_id ,
4759 size_t max_property_size , void * value ) {
4860
61+ /*
4962 LOG_DEBUG("umfGetMemoryProperty: props_handle=%p, memory_property_id=%d, "
5063 "max_property_size=%zu, value=%p",
5164 props_handle, memory_property_id, max_property_size, value);
65+ */
5266
53- if ((value == NULL ) || (props_handle == NULL ) || (max_property_size == 0 )) {
67+ if (UNLIKELY ((value == NULL ) || (props_handle == NULL ) ||
68+ (max_property_size == 0 ))) {
5469 return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
5570 }
5671
5772 umf_memory_provider_t * provider = props_handle -> provider ;
5873
74+ /*
5975 LOG_DEBUG("umfGetMemoryProperty: provider=%p", provider);
6076 LOG_DEBUG("dereferencing value...");
6177
6278 LOG_DEBUG("value: %zu", *(size_t *)value);
79+ */
80+
81+ /*
82+ int x = (int)memory_property_id;
83+ for (int i = 0; i < 1000; i++) {
84+ x += (double)i / 10000000.0;
85+ memory_property_id = x;
86+ }
87+ */
6388
6489 switch (memory_property_id ) {
6590 case UMF_MEMORY_PROPERTY_INVALID :
6691 return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
6792
6893 case UMF_MEMORY_PROPERTY_POOL_HANDLE :
69- if (max_property_size < sizeof (umf_memory_pool_handle_t )) {
94+ if (UNLIKELY ( max_property_size < sizeof (umf_memory_pool_handle_t ) )) {
7095 return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
7196 }
7297 * (umf_memory_pool_handle_t * )value = props_handle -> pool ;
7398 return UMF_RESULT_SUCCESS ;
7499
75100 case UMF_MEMORY_PROPERTY_PROVIDER_HANDLE :
76- if (max_property_size < sizeof (umf_memory_provider_handle_t )) {
101+ if (UNLIKELY (max_property_size <
102+ sizeof (umf_memory_provider_handle_t ))) {
77103 return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
78104 }
79105 * (umf_memory_provider_handle_t * )value = provider ;
80106 return UMF_RESULT_SUCCESS ;
81107
82108 case UMF_MEMORY_PROPERTY_BUFFER_ID :
83- if (max_property_size < sizeof (uint64_t )) {
109+ if (UNLIKELY ( max_property_size < sizeof (uint64_t ) )) {
84110 return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
85111 }
86112 * (uint64_t * )value = props_handle -> id ;
87113 return UMF_RESULT_SUCCESS ;
88114
89115 case UMF_MEMORY_PROPERTY_BASE_ADDRESS :
90- if (max_property_size < sizeof (uintptr_t )) {
116+ if (UNLIKELY ( max_property_size < sizeof (uintptr_t ) )) {
91117 return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
92118 }
93119 * (uintptr_t * )value = (uintptr_t )props_handle -> base ;
94120 return UMF_RESULT_SUCCESS ;
95121
96122 case UMF_MEMORY_PROPERTY_BASE_SIZE :
97- if (max_property_size < sizeof (size_t )) {
123+ if (UNLIKELY ( max_property_size < sizeof (size_t ) )) {
98124 return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
99125 }
100126 * (size_t * )value = props_handle -> base_size ;
101127 return UMF_RESULT_SUCCESS ;
102128
103- // GPU Memory Provider specific properties
104129 case UMF_MEMORY_PROPERTY_POINTER_TYPE :
130+ // NOTE: this property is "cached" in the props_handle but the value is
131+ // determined by the memory provider and set during addition to the
132+ // tracker.
133+ if (UNLIKELY (max_property_size < sizeof (umf_usm_memory_type_t ))) {
134+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
135+ }
136+ * (umf_usm_memory_type_t * )value = props_handle -> memory_type ;
137+ return UMF_RESULT_SUCCESS ;
138+
139+ // GPU Memory Provider specific properties
105140 case UMF_MEMORY_PROPERTY_CONTEXT :
106141 case UMF_MEMORY_PROPERTY_DEVICE :
107142 return provider -> ops .ext_get_allocation_properties (
0 commit comments