互操作#
#include <cuvs/core/interop.hpp>
namespace cuvs::core
- inline bool is_dlpack_device_compatible(DLTensor tensor)#
检查 DLTensor 是否具有设备可访问的内存。当
DLDeviceType
的值为kDLCUDA
、kDLCUDAHost
或kDLCUDAManaged
时,此函数返回 true。
- 参数:
tensor – [in] 要检查底层内存类型的 DLTensor 对象
- 返回值:
bool
- inline bool is_dlpack_host_compatible(DLTensor tensor)#
检查 DLTensor 是否具有主机可访问的内存。当
DLDeviceType
的值为kDLCPU
、kDLCUDAHost
或kDLCUDAManaged
时,此函数返回 true。
- 参数:
tensor – 要检查底层内存类型的 DLTensor 对象
- 返回值:
bool
- inline bool is_c_contiguous(DLManagedTensor *tensor)#
检查 DLManagedTensor 是否具有行主序 (c-contiguous) 布局。
- 参数:
tensor – 要检查的 DLManagedTensor 对象
- 返回值:
bool
- inline bool is_f_contiguous(DLManagedTensor *tensor)#
检查 DLManagedTensor 是否具有列主序 (f-contiguous) 布局。
- 参数:
tensor – 要检查的 DLManagedTensor 对象
- 返回值:
bool
- template<typename MdspanType, typename = raft::is_mdspan_t<MdspanType>>
inline MdspanType from_dlpack()#
- DLManagedTensor *managed_tensor
将 DLManagedTensor 转换为 mdspan 注意:此函数仅支持紧凑的行主序和列主序布局。
#include <raft/core/device_mdspan.hpp> #include <raft/core/interop.hpp> // We have a `DLManagedTensor` with `DLDeviceType == kDLCUDA`, // `DLDataType.code == kDLFloat` and `DLDataType.bits == 8` DLManagedTensor tensor; // declare the return type using mdpsan_type = raft::device_mdspan<float, int64_t, raft::row_major>; auto mds = raft::core::from_dlpack<mdspan_type>(&tensor);
- 模板参数:
MdspanType –
typename –
- 参数:
managed_tensor – [in]
- 返回值:
MdspanType