20 #ifdef BUILD_CUDA_MODULE
24 #include <cuda_runtime.h>
29 #define CLOUDVIEWER_FORCE_INLINE __forceinline__
30 #define CLOUDVIEWER_HOST_DEVICE __host__ __device__
31 #define CLOUDVIEWER_DEVICE __device__
32 #define CLOUDVIEWER_ASSERT_HOST_DEVICE_LAMBDA(type) \
33 static_assert(__nv_is_extended_host_device_lambda_closure_type(type), \
34 #type " must be a __host__ __device__ lambda")
35 #define CLOUDVIEWER_CUDA_CHECK(err) \
36 cloudViewer::core::__CLOUDVIEWER_CUDA_CHECK(err, __FILE__, __LINE__)
37 #define CLOUDVIEWER_GET_LAST_CUDA_ERROR(message) \
38 __CLOUDVIEWER_GET_LAST_CUDA_ERROR(message, __FILE__, __LINE__)
39 #define CUDA_CALL(cuda_function, ...) cuda_function(__VA_ARGS__);
43 #define CLOUDVIEWER_FORCE_INLINE inline
44 #define CLOUDVIEWER_HOST_DEVICE
45 #define CLOUDVIEWER_DEVICE
46 #define CLOUDVIEWER_ASSERT_HOST_DEVICE_LAMBDA(type)
47 #define CLOUDVIEWER_CUDA_CHECK(err)
48 #define CLOUDVIEWER_GET_LAST_CUDA_ERROR(message)
49 #define CUDA_CALL(cuda_function, ...) \
50 cloudViewer::utility::LogError( \
51 "Not built with CUDA, cannot call " #cuda_function);
58 #ifdef BUILD_CUDA_MODULE
83 class CUDAScopedDevice {
137 class CUDAScopedStream {
139 struct CreateNewStreamTag {
140 CreateNewStreamTag(
const CreateNewStreamTag&) =
delete;
141 CreateNewStreamTag& operator=(
const CreateNewStreamTag&) =
delete;
142 CreateNewStreamTag(CreateNewStreamTag&&) =
delete;
143 CreateNewStreamTag& operator=(CreateNewStreamTag&&) =
delete;
147 constexpr
static CreateNewStreamTag CreateNewStream = {};
149 explicit CUDAScopedStream(
const CreateNewStreamTag&);
151 explicit CUDAScopedStream(cudaStream_t stream);
155 CUDAScopedStream(
const CUDAScopedStream&) =
delete;
156 CUDAScopedStream& operator=(
const CUDAScopedStream&) =
delete;
159 cudaStream_t prev_stream_;
160 cudaStream_t new_stream_;
161 bool owns_new_stream_ =
false;
181 CUDAState(
const CUDAState&) =
delete;
182 CUDAState& operator=(
const CUDAState&) =
delete;
186 bool IsP2PEnabled(
int src_id,
int tar_id)
const;
190 bool IsP2PEnabled(
const Device& src,
const Device& tar)
const;
194 void ForceDisableP2PForTesting();
199 std::vector<std::vector<bool>> p2p_enabled_;
203 int GetCUDACurrentWarpSize();
206 int GetCUDACurrentDeviceTextureAlignment();
209 size_t GetCUDACurrentTotalMemSize();
264 #ifdef BUILD_CUDA_MODULE
267 cudaStream_t GetStream();
268 cudaStream_t GetDefaultStream();
277 #ifdef BUILD_CUDA_MODULE
282 void __CLOUDVIEWER_CUDA_CHECK(cudaError_t err,
286 void __CLOUDVIEWER_GET_LAST_CUDA_ERROR(
const char* message,
When CUDA is not enabled, this is a dummy class.
CUDAScopedDevice(int device_id)
CUDAScopedDevice & operator=(const CUDAScopedDevice &)=delete
CUDAScopedDevice(const Device &device)
CUDAScopedDevice(const CUDAScopedDevice &)=delete
ccGuiPythonInstance * GetInstance() noexcept
void AssertCUDADeviceAvailable(int device_id)
bool SupportsMemoryPools(const Device &device)
void ReleaseCache()
Releases CUDA memory manager cache. This is typically used for debugging.
Generic file read and write utility for python interface.