Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
cusolver/execution.hpp
Go to the documentation of this file.
1#pragma once
2
11
12#include <cusolverDn.h>
13
14#include <cstddef>
15#include <optional>
16
17namespace uni20::cusolver
18{
19
22 public:
23 explicit HandleSlot(int device);
24 HandleSlot(HandleSlot const&) = delete;
25 HandleSlot& operator=(HandleSlot const&) = delete;
26 HandleSlot(HandleSlot&& other) noexcept;
27 HandleSlot& operator=(HandleSlot&& other) noexcept;
29
30 [[nodiscard]] int device() const noexcept { return device_; }
31 [[nodiscard]] cusolverDnHandle_t native_handle() const noexcept { return handle_; }
32
34 void bind(cuda::Stream const& stream);
35
36 private:
37 void reset() noexcept;
38
39 int device_ = -1;
40 cusolverDnHandle_t handle_ = nullptr;
41};
42
45 public:
47
48 ExecutionLease() noexcept = default;
50 ExecutionLease& operator=(ExecutionLease const&) = delete;
51 ExecutionLease(ExecutionLease&& other) noexcept;
52 ExecutionLease& operator=(ExecutionLease&& other) noexcept;
54
55 [[nodiscard]] explicit operator bool() const noexcept
56 {
57 return static_cast<bool>(handle_) && static_cast<bool>(stream_);
58 }
59 [[nodiscard]] HandleSlot& handle() const { return handle_.get(); }
60 [[nodiscard]] cuda::Stream const& stream() const noexcept { return stream_; }
61
63 void release() noexcept;
64
65 private:
66 ExecutionLease(handle_lease_type handle, cuda::Stream stream);
67
68 handle_lease_type handle_;
69 cuda::Stream stream_;
70
71 friend class ExecutionPool;
72};
73
76 public:
77 ExecutionPool(cuda::StreamPool& streams, std::size_t handle_count);
78 ExecutionPool(ExecutionPool const&) = delete;
82
83 [[nodiscard]] std::optional<ExecutionLease> try_acquire();
84 [[nodiscard]] ExecutionLease acquire();
85 [[nodiscard]] int device() const noexcept { return streams_->device(); }
86 [[nodiscard]] std::size_t handle_count() const noexcept { return handles_.size(); }
87 [[nodiscard]] std::size_t idle_handle_count() const noexcept { return handles_.idle_count(); }
88
89 private:
90 [[nodiscard]] ExecutionLease make_lease(cuda::ResourceLease<HandleSlot> handle, cuda::Stream stream);
91
92 cuda::StreamPool* streams_;
94};
95
99[[nodiscard]] ExecutionPool& execution_pool(cuda::DeviceResources& resources);
100
107[[nodiscard]] ExecutionPool& execution_pool(cuda::DeviceResources& resources, std::size_t handle_count);
108
109} // namespace uni20::cusolver
Mutable stream and provider resources associated with one CUDA device.
Definition runtime.hpp:222
Fixed-capacity pool of preconstructed provider resources.
Definition resource_pool.hpp:96
Device-local pool whose streams become available only after their queued work completes.
Definition runtime.hpp:163
Reference-counted lease of one CUDA stream-pool slot.
Definition runtime.hpp:65
Move-only pairing of one cuSOLVER handle slot and one idle stream.
Definition cusolver/execution.hpp:44
cuda::Stream const & stream() const noexcept
Definition cusolver/execution.hpp:60
HandleSlot & handle() const
Definition cusolver/execution.hpp:59
ExecutionLease() noexcept=default
Device-local cuSOLVER handle pool paired with the shared stream pool.
Definition cusolver/execution.hpp:75
std::size_t idle_handle_count() const noexcept
Definition cusolver/execution.hpp:87
std::size_t handle_count() const noexcept
Definition cusolver/execution.hpp:86
ExecutionPool & operator=(ExecutionPool &&)=delete
ExecutionPool(ExecutionPool const &)=delete
ExecutionPool & operator=(ExecutionPool const &)=delete
ExecutionPool(ExecutionPool &&)=delete
int device() const noexcept
Definition cusolver/execution.hpp:85
One reusable cuSOLVER handle and its handle-local state.
Definition cusolver/execution.hpp:21
~HandleSlot()
Definition cusolver/execution.cpp:93
cusolverDnHandle_t native_handle() const noexcept
Definition cusolver/execution.hpp:31
int device() const noexcept
Definition cusolver/execution.hpp:30
HandleSlot & operator=(HandleSlot const &)=delete
void bind(cuda::Stream const &stream)
Bind one operation stream to the exclusively leased handle.
Definition cusolver/execution.cpp:95
HandleSlot(HandleSlot const &)=delete
cuda::ResourceLease< HandleSlot > handle
Definition cublas/execution.cpp:33
Definition cusolver_error.cpp:10
ExecutionPool & execution_pool(cuda::DeviceResources &resources)
Return the lazily constructed cuSOLVER execution pool for one device.
Definition cusolver/execution.cpp:205
Fixed-capacity pools and move-only leases for CUDA provider resources.
CUDA device, stream, resource, and scoped runtime primitives.