mindspore.hal.Stream
- class mindspore.hal.Stream(priority=0, **kwargs)[source]
Wrapper around a device stream, this api will be deprecated and removed in future versions, please use the api
mindspore.runtime.Stream
instead.A device stream is a linear sequence of execution that belongs to a specific device, independent from other streams.
- Parameters
- query()[source]
Check if all the work submitted has been completed.
- Returns
A boolean indicating if all kernels in this stream are completed.
Examples
>>> import mindspore >>> a = mindspore.tensor(mindspore.ops.ones([1024, 2048]), mindspore.float32) >>> b = mindspore.tensor(mindspore.ops.ones([2048, 4096]), mindspore.float32) >>> s1 = mindspore.hal.Stream() >>> with mindspore.hal.StreamCtx(s1): ... c = mindspore.ops.matmul(a, b) >>> s1.synchronize() >>> assert s1.query()
- record_event(event=None)[source]
Record an event.
- Parameters
event (Event, optional) – event to record. If not given, a new one will be allocated.
- Returns
Event, recorded event. If this argument is
None
, a new one will be allocated. Default isNone
.
Examples
>>> import mindspore >>> a = mindspore.tensor(mindspore.ops.ones([3, 3]), mindspore.float32) >>> b = mindspore.tensor(mindspore.ops.ones([3, 3]), mindspore.float32) >>> s1 = mindspore.hal.Stream() >>> with mindspore.hal.StreamCtx(s1): ... c = a + b ... event = s1.record_event() ... d = a * b >>> cur_stream = mindspore.hal.current_stream() >>> cur_stream.wait_event(event) >>> e = c + 3 >>> print(e) [[5. 5. 5.] [5. 5. 5.] [5. 5. 5.]]
- synchronize()[source]
Wait for all the kernels in this stream to complete.
Examples
>>> import mindspore >>> a = mindspore.tensor(mindspore.ops.ones([1024, 2048]), mindspore.float32) >>> b = mindspore.tensor(mindspore.ops.ones([2048, 4096]), mindspore.float32) >>> s1 = mindspore.hal.Stream() >>> with mindspore.hal.StreamCtx(s1): ... c = mindspore.ops.matmul(a, b) >>> s1.synchronize() >>> assert s1.query()
- wait_event(event)[source]
Make all future work submitted to the stream wait for an event.
- Parameters
event (Event) – an event to wait for.
Examples
>>> import mindspore >>> a = mindspore.tensor(mindspore.ops.ones([3, 3]), mindspore.float32) >>> b = mindspore.tensor(mindspore.ops.ones([3, 3]), mindspore.float32) >>> s1 = mindspore.hal.Stream() >>> with mindspore.hal.StreamCtx(s1): ... c = a + b ... event = s1.record_event() ... d = a * b >>> cur_stream = mindspore.hal.current_stream() >>> cur_stream.wait_event(event) >>> e = c + 3 >>> print(e) [[5. 5. 5.] [5. 5. 5.] [5. 5. 5.]]
- wait_stream(stream)[source]
Synchronize with another stream.
All future work submitted to this stream will wait until all kernels submitted to a given stream at the time of call complete.
- Parameters
stream (Stream) – a stream to synchronize.
Examples
>>> import mindspore >>> s1 = mindspore.hal.Stream() >>> s2 = mindspore.hal.Stream() >>> a = mindspore.tensor(mindspore.ops.ones([1, 2]), mindspore.float32) >>> b = mindspore.tensor(mindspore.ops.ones([2, 2]), mindspore.float32) >>> with mindspore.hal.StreamCtx(s1): ... c = mindspore.ops.matmul(a, b) >>> with mindspore.hal.StreamCtx(s2): ... s2.wait_stream(s1) ... d = mindspore.ops.matmul(c, b) >>> mindspore.hal.synchronize() >>> print(d) [[4. 4.]]