Function: allocator_register

Applicability

Product

Supported (√/x)

Atlas A3 training products / Atlas A3 inference products

Atlas A2 training products / Atlas A2 inference products

Atlas training products

Atlas inference products

Atlas 200I/500 A2 inference products

x

Function Usage

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)
    

Parameter Description

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 Description

Return Value

Description

ret

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

Restrictions

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

    In the single-operator model scenario, call this API before executing an 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 the buffer is released by the Allocator to the operating system, call acl.rt.synchronize_stream to synchronize the stream and make sure that tasks in the stream have been executed.

Reference

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