Function: create_stream

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

Function Usage

Creates a stream in the calling process or thread.

Prototype

  • C Prototype
    1
    aclError aclrtCreateStream(aclrtStream *stream)
    
  • Python Function
    1
    stream, ret = acl.rt.create_stream()
    

Parameter Description

None.

Return Value Description

Return Value

Description

stream

Int, pointer address of the created context.

ret

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

Restrictions

  • Each context has a default stream, which is implicitly created with the call to acl.rt.set_device or acl.rt.create_context. You are advised to use acl.rt.create_stream to explicitly create a stream.
    • Implicit stream creation: applies to simple apps with low complicity of interaction logic. However, in multithreaded programming, the execution result depends on the thread scheduling sequence.
    • (Recommended) Explicit stream creation: applies to large apps with complex interaction logic, offering better app readability and maintainability.
  • Atlas 200I/500 A2 inference products
    • The hardware allows a maximum of 512 streams.
    • If multiple default streams exist, only N streams can be explicitly created (N = 512 – Default number of streamsNumber of streams for internal synchronization).

      For example, if a default stream and a stream that performs internal synchronization already exist, only 510 streams can be explicitly created.

  • Atlas inference products
    • The hardware allows a maximum of 1024 streams.
    • In standard form, if multiple default streams exist, only N streams can be explicitly created (N = 1024 – Default number of streamsNumber of streams for internal synchronization).

      For example, if a default stream and a stream that performs internal synchronization already exist, only 1022 streams can be explicitly created.

  • Atlas training products
    • The hardware allows a maximum of 2048 streams.
    • If multiple default streams exist, only N streams can be explicitly created (N = 2048 – Default number of streamsNumber of streams for internal synchronization).

      For example, if a default stream and a stream that performs internal synchronization already exist, only 2046 streams can be explicitly created.

    • In the multi-process scenario, if the total number of streams created at a time is close to 2048, streams may fail to be created. In this case, you are advised to perform the following operations:
      1. Clear redundant streams.
      2. Adjust the code logic to create streams in batches.

        For example, create some streams in the first batch, then the second batch, and so on until the total number of streams is close to 2048.

  • Atlas A2 training products / Atlas A2 inference products
    • The hardware allows a maximum of 1984 streams.
    • If multiple default streams exist, only N streams can be explicitly created (N = 1984 – Default number of streamsNumber of streams for internal synchronization).

      For example, if a default stream and a stream that performs internal synchronization already exist, only 2046 streams can be explicitly created.

Reference

For details about the API call sequence and example, see Runtime Resource Allocation and Deallocation.