Function: allocator_register

Applicable Products

Product

Supported (√/x)

Ascend 950PR / Ascend 950DT

√

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

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 Values

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, call this API before executing an API (such as acl.op.execute_v2).

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

  • 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.
  • If you call this API multiple times for the same stream, the last registration applies.
  • If you call this API for different streams using the same Allocator, concurrent execution of these 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 details about the API call example, see Dynamic Shape Input (Setting the Shape Range).