add memory properties API - #1301
Conversation
92db71d to
56573df
Compare
a5c357c to
17f6335
Compare
96bb935 to
5015432
Compare
lplewa
left a comment
There was a problem hiding this comment.
Please add tests too all umf pools
you should use poolfixtures.hpp
Including it's abstraction to create custom pools and providers.
| static void do_umf_mem_props_benchmark(ze_context_handle_t context, | ||
| bool use_umf, alloc_t *allocs, | ||
| size_t num_allocs, size_t repeats) { | ||
| assert(context != NULL); | ||
|
|
||
| for (size_t r = 0; r < repeats * 10; ++r) { | ||
| for (size_t i = 0; i < num_allocs; ++i) { | ||
| if (use_umf) { | ||
| umf_memory_properties_handle_t props_handle = NULL; | ||
| umf_result_t res = | ||
| umfGetMemoryPropertiesHandle(allocs[i].ptr, &props_handle); | ||
| (void)res; | ||
| assert(res == UMF_RESULT_SUCCESS); | ||
|
|
||
| umf_usm_memory_type_t type = UMF_MEMORY_TYPE_UNKNOWN; | ||
| res = umfGetMemoryProperty( | ||
| props_handle, UMF_MEMORY_PROPERTY_POINTER_TYPE, &type); | ||
| assert(res == UMF_RESULT_SUCCESS); | ||
| if (type != UMF_MEMORY_TYPE_DEVICE) { | ||
| fprintf(stderr, | ||
| "error: unexpected alloc_props.type value: %d\n", | ||
| type); | ||
| exit(-1); |
There was a problem hiding this comment.
Please in final version add benchmark to new framework.
There was a problem hiding this comment.
I removed the old version of the benchmark, but the new one should be done in a separate PR
| /// be filled. NOTE: the type and size of the value depends on the | ||
| /// memory property ID and should be checked in the documentation |
There was a problem hiding this comment.
api like this should include size parameter for safety
| /// @brief Get the memory properties handle for a given pointer | ||
| /// @param ptr pointer to the allocated memory | ||
| /// @param props_handle [out] pointer to the memory properties handle | ||
| /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure | ||
| umf_result_t | ||
| umfGetMemoryPropertiesHandle(const void *ptr, | ||
| umf_memory_properties_handle_t *props_handle); |
There was a problem hiding this comment.
document ownership of this handle.
| typedef struct umf_memory_properties_t { | ||
| // TODO alloc_info_t | ||
| void *ptr; | ||
| umf_memory_pool_handle_t pool; | ||
| umf_memory_provider_handle_t provider; | ||
| uint64_t id; | ||
| void *base; | ||
| size_t base_size; | ||
| } umf_memory_properties_t; |
There was a problem hiding this comment.
if we have api to literaly read this structure - it should be defined in .c file
There was a problem hiding this comment.
other files directly access fields of this struct so it cannot be moved
| #include <umf/memory_provider.h> | ||
|
|
||
| #if UMF_BUILD_LEVEL_ZERO_PROVIDER | ||
| #include "ze_api.h" |
There was a problem hiding this comment.
i do not see a reason to include this file there
| /// @param value [out] pointer to the preallocated variable where the value will be stored | ||
| /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure, | ||
| /// UMF_RESULT_ERROR_INVALID_ARGUMENT if memory_property_id is invalid or value is NULL, | ||
| /// UMF_RESULT_ERROR_NOT_SUPPORTED if the property is not supported by this provider. |
There was a problem hiding this comment.
This is not true:
Please include tests to ensure that comment it true (as far i see we return EINVAL
There was a problem hiding this comment.
Especially please include also test with custom user provided provider, which support extra property which is user defined.
There was a problem hiding this comment.
comment changed
about user provider - this should be done by adding an example, not the test, and probably in a separate PR
3d40afe to
7228b45
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds a comprehensive memory properties API to the unified memory framework, enabling users to query various properties of allocated memory such as memory type, base address, size, and provider-specific information.
- Introduces memory properties API with two main functions:
umfGetMemoryPropertiesHandleandumfGetMemoryProperty - Extends memory provider operations with
ext_get_allocation_propertiesfunction - Adds comprehensive test coverage for the new memory properties functionality
Reviewed Changes
Copilot reviewed 37 out of 38 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| include/umf/base.h | Defines memory property types and handle structures |
| include/umf/experimental/memory_props.h | Public API for memory properties functionality |
| src/memory_props.c | Core implementation of memory properties API |
| src/provider/provider_tracking.c | Updates tracking provider to support memory properties |
| test/props/ | Comprehensive test suite for memory properties API |
| Various provider files | Updates all providers to support new allocation properties interface |
add memory properties API
https://reviewable.io/reviews/bratpiorka/unified-memory-framework/3
fixes #1263