Open3D (C++ API)  0.12.0
Helper.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2020 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
29 
30 #pragma once
31 
32 #ifdef BUILD_CUDA_MODULE
33 
34 #include <cuda.h>
35 #include <cuda_runtime.h>
36 
37 #endif // #ifdef BUILD_CUDA_MODULE
38 
39 #include <stdio.h>
40 
41 #include <stdexcept>
42 #include <string>
43 
44 #ifdef BUILD_CUDA_MODULE
45 #define OPEN3D_ML_CUDA_CHECK(err) \
47  { open3d::ml::__OPEN3D_ML_CUDA_CHECK((err), __FILE__, __LINE__); }
48 #endif
49 
50 namespace open3d {
51 namespace ml {
52 
53 #ifdef BUILD_CUDA_MODULE
54 inline int GetCUDACurrentDeviceTextureAlignment() {
56  int device = 0;
57  cudaError_t err = cudaGetDevice(&device);
58  if (err != cudaSuccess) {
59  throw std::runtime_error(
60  "GetCUDACurrentDeviceTextureAlignment(): cudaGetDevice failed "
61  "with {}" +
62  std::string(cudaGetErrorString(err)));
63  }
64 
65  int value = 0;
66  err = cudaDeviceGetAttribute(&value, cudaDevAttrTextureAlignment, device);
67  if (err != cudaSuccess) {
68  throw std::runtime_error(
69  "GetCUDACurrentDeviceTextureAlignment(): cudaGetDevice failed "
70  "with {}" +
71  std::string(cudaGetErrorString(err)));
72  }
73  return value;
74 }
75 
77 inline void __OPEN3D_ML_CUDA_CHECK(cudaError_t err,
78  const char *file,
79  int line,
80  bool abort = true) {
81  if (err != cudaSuccess) {
82  fprintf(stderr, "%s:%d CUDA runtime error: %s\n", file, line,
83  cudaGetErrorString(err));
84  if (abort) {
85  exit(err);
86  }
87  }
88 }
89 #endif
90 
91 } // namespace ml
92 } // namespace open3d
Definition: PinholeCameraIntrinsic.cpp:35