11 #include <kvikio/shim/utils.hpp>
31 template <
typename Callable>
32 void set(Callable&& c)
34 _callable = std::function(c);
40 void reset() { _callable.reset(); }
53 template <
typename... Args>
56 using T = std::function<CUresult(Args...)>;
57 if (!_callable.has_value()) {
58 throw std::runtime_error(
"No callable has been assigned to the wrapper yet.");
60 return std::any_cast<T&>(_callable)(args...);
66 operator bool()
const {
return _callable.has_value(); }
80 int driver_version{0};
82 decltype(cuInit)* Init{
nullptr};
83 decltype(cuMemHostAlloc)* MemHostAlloc{
nullptr};
84 decltype(cuMemFreeHost)* MemFreeHost{
nullptr};
85 decltype(cuMemHostRegister)* MemHostRegister{
nullptr};
86 decltype(cuMemHostUnregister)* MemHostUnregister{
nullptr};
87 decltype(cuMemcpyHtoDAsync)* MemcpyHtoDAsync{
nullptr};
88 decltype(cuMemcpyDtoHAsync)* MemcpyDtoHAsync{
nullptr};
92 decltype(cuPointerGetAttribute)* PointerGetAttribute{
nullptr};
93 decltype(cuPointerGetAttributes)* PointerGetAttributes{
nullptr};
94 decltype(cuCtxPushCurrent)* CtxPushCurrent{
nullptr};
95 decltype(cuCtxPopCurrent)* CtxPopCurrent{
nullptr};
96 decltype(cuCtxGetCurrent)* CtxGetCurrent{
nullptr};
97 decltype(cuCtxGetDevice)* CtxGetDevice{
nullptr};
98 decltype(cuMemGetAddressRange)* MemGetAddressRange{
nullptr};
99 decltype(cuGetErrorName)* GetErrorName{
nullptr};
100 decltype(cuGetErrorString)* GetErrorString{
nullptr};
101 decltype(cuDeviceGet)* DeviceGet{
nullptr};
102 decltype(cuDeviceGetCount)* DeviceGetCount{
nullptr};
103 decltype(cuDeviceGetAttribute)* DeviceGetAttribute{
nullptr};
104 decltype(cuDevicePrimaryCtxRetain)* DevicePrimaryCtxRetain{
nullptr};
105 decltype(cuDevicePrimaryCtxRelease)* DevicePrimaryCtxRelease{
nullptr};
106 decltype(cuStreamSynchronize)* StreamSynchronize{
nullptr};
107 decltype(cuStreamCreate)* StreamCreate{
nullptr};
108 decltype(cuStreamDestroy)* StreamDestroy{
nullptr};
109 decltype(cuDriverGetVersion)* DriverGetVersion{
nullptr};
116 void operator=(
cudaAPI const&) =
delete;
118 KVIKIO_EXPORT
static cudaAPI& instance();
Shim layer of the cuda C-API.
Non-templated class to hold any callable that returns CUresult.
CUresult operator()(Args... args)
Invoke the container callable.
void reset()
Destroy the contained callable.
void set(Callable &&c)
Assign a callable to the object.
bool is_cuda_available()
Check if the CUDA library is available.