detail/stream.hpp
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
6 
7 #include <map>
8 #include <mutex>
9 #include <thread>
10 
11 #include <kvikio/shim/cuda.hpp>
12 
13 namespace kvikio::detail {
30  private:
31  std::map<std::pair<CUcontext, std::thread::id>, CUstream> _streams;
32  std::mutex mutable _mutex;
33 
34  private:
36  ~StreamCachePerThreadAndContext() = default;
37 
38  public:
48  KVIKIO_EXPORT static CUstream get();
49 
54 };
55 } // namespace kvikio::detail
Singleton cache that provides one CUDA stream per (context, thread) pair.
static KVIKIO_EXPORT CUstream get()
Get or create a CUDA stream for the current context and thread.