| 694 | |
| 695 | template<typename T> |
| 696 | Maybe<Symbol<Stream>> GetAccessStream(const T tensor) { |
| 697 | Symbol<Device> device = JUST(GetDevice(tensor)); |
| 698 | // Do not use producer_stream or last_used_stream. |
| 699 | // Bug case when using producer_stream or last_used_stream: |
| 700 | // |
| 701 | // ```python |
| 702 | // tensor = oneflow.ones((1024, 1024, 1024), device='cuda').cpu() |
| 703 | // ndarray = tensor.numpy() # share memory |
| 704 | // |
| 705 | // ``` |
| 706 | // `ndarray` may not be ones because instruction AccessBlobByCallback is prescheduled before |
| 707 | // oneflow.ones actually finished. |
| 708 | Symbol<Stream> stream = JUST(GetDefaultStreamByDevice(device)); |
| 709 | return StreamGuard::TryConvertStream(stream); |
| 710 | } |
| 711 | |
| 712 | } // namespace |
| 713 |
no test coverage detected