Function: allocator_register

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product / Atlas A3 inference product

Atlas A2 training product / Atlas A2 inference product

Atlas training product

Atlas inference product

Atlas 200I/500 A2 inference product

x

Description

Registers the user-provided Allocator and its callback function, so that the Allocator can be used.

Prototype

  • C Prototype
    1
    aclError aclrtAllocatorRegister(aclrtStream stream, aclrtAllocatorDesc allocatorDesc )
    
  • Python Function
    1
    ret = acl.rt.allocator_register(stream, allocatorDesc)
    

Parameters

Parameter

Description

stream

Int, stream to be registered by the Allocator. The value cannot be NULL. Otherwise, an error is reported.

allocatorDesc

Int, pointer address of the allocator descriptor.

Return Value

Return Value

Description

ret

Int, error code. 0 on success; else, failure.

Restrictions

  • The Atlas 200/500 A2 Inference Product does not support this API.
  • Currently, this API can be used only in single-operator model execution and dynamic shape model inference scenarios.

    In the single-operator model scenario, this API needs to be called before the operator execution API (such as acl.op.execute_v2).

    In the dynamic-shape model inference scenario, this API must be used together with the aclmdlExecuteAsync API, and this API must be called before the aclmdlExecuteAsync API.

  • Before calling this API, you need to call acl.rt.allocator_create_desc to create an Allocator descriptor, and then call acl.rt.allocator_set_obj_to_desc, acl.rt.allocator_set_alloc_func_to_desc, acl.rt.allocator_set_get_addr_from_block_func_to_desc, and acl.rt.allocator_set_free_func_to_desc to set the Allocator object and callback function. After the Allocator descriptor is used, call the acl.rt.allocator_destroy_desc API to destroy the Allocator descriptor.
  • For the same stream, if this API is called for multiple times, the last registration is used.
  • For different streams, if you use the same Allocator, concurrent execution on multiple streams is not allowed. Before you execute the next stream, synchronize the previous one.
  • Before releasing the memory in the Allocator to the OS, call the acl.rt.synchronize_stream API to perform stream synchronization to ensure that the tasks in the stream have been executed.

Reference

For the API call example, see Dynamic Shape Input (Setting the Shape Range).