19#ifdef BUILD_CUDA_MODULE
22#include <cuda_runtime.h>
28#define OPEN3D_FORCE_INLINE __forceinline__
29#define OPEN3D_HOST_DEVICE __host__ __device__
30#define OPEN3D_DEVICE __device__
31#define OPEN3D_ASSERT_HOST_DEVICE_LAMBDA(type) \
32 static_assert(__nv_is_extended_host_device_lambda_closure_type(type), \
33 #type " must be a __host__ __device__ lambda")
34#define OPEN3D_CUDA_CHECK(err) \
35 open3d::core::__OPEN3D_CUDA_CHECK(err, __FILE__, __LINE__)
36#define OPEN3D_GET_LAST_CUDA_ERROR(message) \
37 __OPEN3D_GET_LAST_CUDA_ERROR(message, __FILE__, __LINE__)
38#define CUDA_CALL(cuda_function, ...) cuda_function(__VA_ARGS__);
42#define OPEN3D_FORCE_INLINE inline
43#define OPEN3D_HOST_DEVICE
45#define OPEN3D_ASSERT_HOST_DEVICE_LAMBDA(type)
46#define OPEN3D_CUDA_CHECK(err)
47#define OPEN3D_GET_LAST_CUDA_ERROR(message)
48#define CUDA_CALL(cuda_function, ...) \
49 open3d::utility::LogError( \
50 "Not built with CUDA, cannot call " #cuda_function);
57#ifdef BUILD_CUDA_MODULE
82class CUDAScopedDevice {
84 explicit CUDAScopedDevice(
int device_id);
86 explicit CUDAScopedDevice(
const Device& device);
90 CUDAScopedDevice(
const CUDAScopedDevice&) =
delete;
91 CUDAScopedDevice&
operator=(
const CUDAScopedDevice&) =
delete;
136class CUDAScopedStream {
138 struct CreateNewStreamTag {
139 CreateNewStreamTag(
const CreateNewStreamTag&) =
delete;
140 CreateNewStreamTag& operator=(
const CreateNewStreamTag&) =
delete;
141 CreateNewStreamTag(CreateNewStreamTag&&) =
delete;
142 CreateNewStreamTag& operator=(CreateNewStreamTag&&) =
delete;
146 constexpr static CreateNewStreamTag CreateNewStream = {};
148 explicit CUDAScopedStream(
const CreateNewStreamTag&);
150 explicit CUDAScopedStream(cudaStream_t stream);
154 CUDAScopedStream(
const CUDAScopedStream&) =
delete;
155 CUDAScopedStream& operator=(
const CUDAScopedStream&) =
delete;
158 cudaStream_t prev_stream_;
159 cudaStream_t new_stream_;
160 bool owns_new_stream_ =
false;
178 static CUDAState& GetInstance();
180 CUDAState(
const CUDAState&) =
delete;
181 CUDAState& operator=(
const CUDAState&) =
delete;
185 bool IsP2PEnabled(
int src_id,
int tar_id)
const;
189 bool IsP2PEnabled(
const Device& src,
const Device& tar)
const;
193 void ForceDisableP2PForTesting();
198 std::vector<std::vector<bool>> p2p_enabled_;
202int GetCUDACurrentWarpSize();
205int GetCUDACurrentDeviceTextureAlignment();
208size_t GetCUDACurrentTotalMemSize();
264#ifdef BUILD_CUDA_MODULE
267cudaStream_t GetStream();
268cudaStream_t GetDefaultStream();
277#ifdef BUILD_CUDA_MODULE
282void __OPEN3D_CUDA_CHECK(cudaError_t err,
const char* file,
const int line);
284void __OPEN3D_GET_LAST_CUDA_ERROR(
const char* message,
When CUDA is not enabled, this is a dummy class.
Definition CUDAUtils.h:213
CUDAScopedDevice(const Device &device)
Definition CUDAUtils.h:216
CUDAScopedDevice(const CUDAScopedDevice &)=delete
CUDAScopedDevice(int device_id)
Definition CUDAUtils.h:215
~CUDAScopedDevice()
Definition CUDAUtils.h:217
CUDAScopedDevice & operator=(const CUDAScopedDevice &)=delete
void ReleaseCache()
Releases CUDA memory manager cache. This is typically used for debugging.
Definition CUDAUtils.cpp:40
bool IsAvailable()
Definition CUDAUtils.cpp:38
bool SupportsMemoryPools(const Device &device)
Definition CUDAUtils.cpp:111
int DeviceCount()
Definition CUDAUtils.cpp:21
void Synchronize()
Definition CUDAUtils.cpp:58
void AssertCUDADeviceAvailable(int device_id)
Definition CUDAUtils.cpp:75
Definition PinholeCameraIntrinsic.cpp:16