Creates a MIOpenHandle instance for stream. MIOpen API calls using the same handle instance need to be serialized across threads. This is guaranteed by MIOpenHandle instances locking the mutex owned by this class. Most MIOpen APIs taking a handle perform work on a HIP stream. The MIOpenHandle instance acquires the executor's ROCm context and sets MIOpen to use the provided stream. The stream ar
| 475 | // therefore a bad idea (performance wise) to call any MIOpen APIs that |
| 476 | // enqueue work in the stream. |
| 477 | MIOpenHandle GetHandle(GpuExecutor* executor, Stream* stream) { |
| 478 | auto lock = absl::make_unique<absl::MutexLock>(&mutex_); |
| 479 | mutex_.AssertHeld(); |
| 480 | gpu::ScopedActivateExecutorContext context(executor); |
| 481 | hipStream_t hip_stream = stream ? AsGpuStreamValue(stream) : nullptr; |
| 482 | auto status = wrap::miopenSetStream(handle_, hip_stream); |
| 483 | CHECK_EQ(status, miopenStatusSuccess) << "Failed to set MIOpen stream."; |
| 484 | return MIOpenHandle(std::move(context), std::move(lock), handle_); |
| 485 | } |
| 486 | |
| 487 | private: |
| 488 | // Guards the enqueueing of MIOpen operations via the handle_ below. |
no test coverage detected