@@ -57,23 +57,23 @@ CudaMempoolArena::~CudaMempoolArena() {
5757 for (auto & kv : alloc_map_) {
5858 void * p = kv.first ;
5959 const cudaStream_t s = kv.second .stream ;
60- ( void ) cudaFreeAsync (p, s); // ignore errors in destructor
60+ ORT_IGNORE_RETURN_VALUE ( cudaFreeAsync (p, s) ); // ignore errors in destructor
6161 }
6262
63+ // 2) Synchronize all streams we know about (those that ever held allocations).
64+ SyncAllKnownStreams_NoThrow ();
65+
6366 // Now it is safe to drop our bookkeeping.
6467 alloc_map_.clear ();
6568 stream_map_.clear ();
6669
67- // 2) Synchronize all streams we know about (those that ever held allocations).
68- SyncAllKnownStreams_NoThrow ();
69-
7070 // 3) Safety barrier: ensure any frees enqueued on destroyed/unknown streams are completed.
71- ( void ) cudaDeviceSynchronize (); // ignore errors in destructor
71+ ORT_IGNORE_RETURN_VALUE ( cudaDeviceSynchronize () ); // ignore errors in destructor
7272
7373 // 4) Trim to zero and destroy the pool.
7474 if (pool_) {
75- ( void ) cudaMemPoolTrimTo (pool_, 0 ); // best-effort
76- ( void ) cudaMemPoolDestroy (pool_);
75+ ORT_IGNORE_RETURN_VALUE ( cudaMemPoolTrimTo (pool_, 0 ) ); // best-effort
76+ ORT_IGNORE_RETURN_VALUE ( cudaMemPoolDestroy (pool_) );
7777 pool_ = nullptr ;
7878 }
7979}
@@ -93,7 +93,7 @@ void* CudaMempoolArena::Alloc(size_t size) {
9393 << size << " bytes at " << p << " on default stream." ;
9494
9595 // In case the default stream is busy.
96- :: cudaStreamSynchronize (kDefaultStream );
96+ ORT_IGNORE_RETURN_VALUE ( cudaStreamSynchronize (kDefaultStream ) );
9797
9898 {
9999 std::lock_guard<std::mutex> lock (mutex_);
@@ -231,8 +231,41 @@ void CudaMempoolArena::MaybeRehashLocked() {
231231void CudaMempoolArena::SyncAllKnownStreams_NoThrow () {
232232 for (const auto & kv : stream_map_) {
233233 const cudaStream_t s = kv.first ;
234- (void )cudaStreamSynchronize (s); // ignore errors; device-wide sync follows
234+ ORT_IGNORE_RETURN_VALUE (cudaStreamSynchronize (s)); // ignore errors; device-wide sync follows
235+ }
236+ }
237+
238+ bool CudaMempoolArena::IsCudaVersionSupported () noexcept {
239+ int ort_cuda_rt_version = 0 ;
240+ cudaError_t cuda_status = cudaRuntimeGetVersion (&ort_cuda_rt_version);
241+ if (cuda_status != cudaSuccess) {
242+ return false ;
243+ }
244+
245+ if (ort_cuda_rt_version < 11020 ) {
246+ return false ;
247+ }
248+
249+ int ort_cuda_driver_version = 0 ;
250+ cuda_status = cudaDriverGetVersion (&ort_cuda_driver_version);
251+ if (cuda_status != cudaSuccess) {
252+ return false ;
253+ }
254+
255+ if (ort_cuda_driver_version < 11020 ) {
256+ return false ;
235257 }
258+
259+ // Check if the driver version supports the runtime version
260+ if (ort_cuda_rt_version >= 12000 && ort_cuda_driver_version < 12000 ) {
261+ return false ;
262+ }
263+
264+ if (ort_cuda_rt_version >= 13000 && ort_cuda_driver_version < 13000 ) {
265+ return false ;
266+ }
267+
268+ return true ;
236269}
237270
238271} // namespace cuda
0 commit comments