Function: create_stream

C Prototype

aclError aclrtCreateStream(aclrtStream *stream)

Python Function

stream, ret = acl.rt.create_stream()

Function Usage

Creates a stream in the calling process or thread.

Input Description

None

Return Value

stream: int, pointer address of the created stream.

ret: int, error code.

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 200/300/500 Inference Product
    • The hardware allows a maximum of 1024 streams.
    • 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 Series Product
    • 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.

Reference

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