aclrtCreateStream

Description

Creates a stream.

Restrictions

  • Each context has a default stream, which is implicitly created with the call to aclrtSetDevice or aclrtCreateContext. You are advised to use aclrtCreateStream 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.
  • The maximum number of streams supported by hardware varies depending on the hardware model. If multiple streams (including the default stream and the stream for internal synchronization) exist, only N streams can be explicitly created, where N = Maximum number of streams – Number of existing streams. For example, if the maximum number of streams is 1,024 and there are already two streams, you can only call this API to explicitly create 1,022 streams.

    Model

    Maximum Number of Streams

    Atlas 200/300/500 Inference Product

    1,024

    Atlas Training Series Product

    2,048

    NOTE:

    In the multi-process scenario, if the total number of streams to be created at a time is approaching 2048, the creation may fail. In this case, you are advised to: (1) Clear unnecessary streams. (2) Adjust the code logic to create streams in batches. For example, create some streams in the first batch, create some streams in the second batch, and so on until the total number of streams is approaching 2048.

Prototype

aclError aclrtCreateStream(aclrtStream *stream)

Parameters

Parameter

Input/Output

Description

stream

Output

Stream pointer.

Returns

The value 0 indicates success, and other values indicate failure. For details, see aclError.

See Also

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