| 197 | } |
| 198 | |
| 199 | void endCaptureOnError(TrtCudaStream& stream) |
| 200 | { |
| 201 | // There are two possibilities why stream capture would fail: |
| 202 | // (1) stream is in cudaErrorStreamCaptureInvalidated state. |
| 203 | // (2) TRT reports a failure. |
| 204 | // In case (1), the returning mGraph should be nullptr. |
| 205 | // In case (2), the returning mGraph is not nullptr, but it should not be used. |
| 206 | const auto ret = cudaStreamEndCapture(stream.get(), &mGraph); |
| 207 | if (ret == cudaErrorStreamCaptureInvalidated) |
| 208 | { |
| 209 | assert(mGraph == nullptr); |
| 210 | } |
| 211 | else |
| 212 | { |
| 213 | assert(ret == cudaSuccess); |
| 214 | assert(mGraph != nullptr); |
| 215 | cudaCheck(cudaGraphDestroy(mGraph)); |
| 216 | mGraph = nullptr; |
| 217 | } |
| 218 | // Clean up any CUDA error. |
| 219 | cudaGetLastError(); |
| 220 | sample::gLogWarning << "The CUDA graph capture on the stream has failed." << std::endl; |
| 221 | } |
| 222 | |
| 223 | private: |
| 224 | cudaGraph_t mGraph{}; |
no test coverage detected