Skip to content

Add custom 'tags' to the memory pool #687

@igchor

Description

@igchor

Add custom 'tags' to the memory pool

Rationale

In UR, there are a few use-cases that we can optimize by allowing the user to associated a 'tag' with the memory pool (and to later, query the 'tag'):

  1. Calls to zeMemGetAllocProperties (quite expensive) in L0 adapter: https://github.com/oneapi-src/unified-runtime/blob/main/source/adapters/level_zero/memory.cpp#L51
  2. Quite convoluted logic for finding ur_usm_pool_handle_t for a given ptr: https://github.com/oneapi-src/unified-runtime/blob/d61cf6680c7f620bd5092e2bb22524106fbdef63/source/adapters/level_zero/usm.cpp#L637

Description

Add one extra void *tag argument to umfPoolCreate and allow querying it later. Tag can point to a user-provided structure that user is responsible for freeing.

In UR we can create a custom structure struct pool_tag { ur_memory_type type; ur_usm_pool_handle_t urPool; } and store a pointer to that structure as a tag for each umf pool. This will make calls to zeMemGetAllocProperties unnecessary and logic for finding ur_usm_pool_handle_t will be just ((pool_tag *) umfPoolGetTag(umfPoolByPtr(ptr)))-> urPool

API Changes

umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops,
                           umf_memory_provider_handle_t provider, void *params,
                           void *tag, // <- NEW PARAMETER
                           umf_pool_create_flags_t flags,
                           umf_memory_pool_handle_t *hPool);
                           
                           
void *umfPoolGetTag(umf_memory_pool_handle_t hPool);                           

Implementation details

Store provided tag in the pool structure.

Meta

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions