Mojo struct
DeviceStream
struct DeviceStream
Represents a CUDA/HIP stream for asynchronous GPU operations.
A DeviceStream provides a queue for GPU operations that can execute concurrently with operations in other streams. Operations within a single stream execute in the order they are issued, but operations in different streams may execute in any relative order or concurrently.
This abstraction allows for better utilization of GPU resources by enabling overlapping of computation and data transfers.
Example:
```mojo
from gpu.host import DeviceContext, DeviceStream
var ctx = DeviceContext(0) # Select first GPU
var stream = DeviceStream(ctx)
# Launch operations on the stream
# ...
# Wait for all operations in the stream to complete
stream.synchronize()
```
```mojo
from gpu.host import DeviceContext, DeviceStream
var ctx = DeviceContext(0) # Select first GPU
var stream = DeviceStream(ctx)
# Launch operations on the stream
# ...
# Wait for all operations in the stream to complete
stream.synchronize()
```
Implemented traits
AnyType
,
UnknownDestructibility
Methods
synchronize
synchronize(self)
Blocks the calling CPU thread until all operations in this stream complete.
This function waits until all previously issued commands in this stream have completed execution. It provides a synchronization point between host and device code.
Example:
```mojo
# Launch kernel or memory operations on the stream
# ...
# Wait for completion
stream.synchronize()
# Now it's safe to use results on the host
```
.
```mojo
# Launch kernel or memory operations on the stream
# ...
# Wait for completion
stream.synchronize()
# Now it's safe to use results on the host
```
.
Raises:
If synchronization fails.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!