24 #include <type_traits>
26 #include <kvikio/error.hpp>
27 #include <kvikio/shim/cuda.hpp>
32 inline constexpr std::size_t page_size = 4096;
34 [[nodiscard]] off_t convert_size2off(std::size_t x);
36 [[nodiscard]] ssize_t convert_size2ssize(std::size_t x);
38 [[nodiscard]] CUdeviceptr convert_void2deviceptr(
void const* devPtr);
44 template <
typename T, std::enable_if_t<std::is_
integral_v<T>>* =
nullptr>
47 if constexpr (std::numeric_limits<T>::max() > std::numeric_limits<std::int64_t>::max()) {
48 KVIKIO_EXPECT(value <= std::numeric_limits<std::int64_t>::max(),
49 "convert_to_64bit(x): x too large to fit std::int64_t",
52 return std::int64_t(value);
59 [[nodiscard]]
inline std::uint64_t
convert_to_64bit(std::uint64_t value) {
return value; }
64 template <
typename T, std::enable_if_t<std::is_
floating_po
int_v<T>>* =
nullptr>
78 #ifdef KVIKIO_CUDA_FOUND
153 std::tuple<void*, std::size_t, std::size_t> get_alloc_info(
void const* devPtr,
154 CUcontext* ctx =
nullptr);
167 template <
typename T>
170 std::promise<std::decay_t<T>> p;
171 auto fut = p.get_future();
172 p.set_value(std::forward<T>(t));
187 template <
typename T>
191 "The future object does not refer to a valid shared state.",
192 std::invalid_argument);
193 return future.wait_for(std::chrono::seconds(0)) != std::future_status::timeout;
#define KVIKIO_EXPECT(...)
用于检查前置条件或条件的宏,当条件被违反时会抛出异常...
CUcontext get_context_from_pointer(void const *devPtr)
返回一个可以与给定设备指针一起使用的 CUDA 上下文。
constexpr bool is_host_memory(void const *ptr)
检查 ptr 是否指向主机内存(而不是设备内存)
std::int64_t convert_to_64bit(T value)
辅助函数,用于将值转换为 64 位带符号整数。
bool current_context_can_access_pointer(CUdeviceptr dev_ptr)
检查当前的 CUDA 上下文是否可以访问给定的设备指针。
bool is_future_done(T const &future)
检查 future 对象的状态。True 表示结果在 future 的共享状态中可用。
KVIKIO_EXPORT CUcontext get_primary_cuda_context(int ordinal)
给定设备序号,返回设备的主上下文。
std::future< std::decay_t< T > > make_ready_future(T &&t)
在 future 对象中创建一个立即就绪的共享状态。
std::optional< CUcontext > get_context_associated_pointer(CUdeviceptr dev_ptr)
返回与给定设备指针关联的 CUDA 上下文(如果存在)。
int get_device_ordinal_from_pointer(CUdeviceptr dev_ptr)
返回拥有该指针的设备。