common.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /******************************************************************************
  2. * Copyright 2020 The Apollo Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *****************************************************************************/
  16. /*
  17. * Copyright 2018-2019 Autoware Foundation. All rights reserved.
  18. *
  19. * Licensed under the Apache License, Version 2.0 (the "License");
  20. * you may not use this file except in compliance with the License.
  21. * You may obtain a copy of the License at
  22. *
  23. * http://www.apache.org/licenses/LICENSE-2.0
  24. *
  25. * Unless required by applicable law or agreed to in writing, software
  26. * distributed under the License is distributed on an "AS IS" BASIS,
  27. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  28. * See the License for the specific language governing permissions and
  29. * limitations under the License.
  30. */
  31. /**
  32. * @file common.h
  33. * @brief MACRO for CUDA codes
  34. * @author Kosuke Murakami
  35. * @date 2019/02/26
  36. */
  37. #pragma once
  38. // headers in STL
  39. #include <stdio.h>
  40. // headers in CUDA
  41. #include <cuda_runtime_api.h>
  42. namespace apollo {
  43. namespace perception {
  44. namespace lidar {
  45. // using MACRO to allocate memory inside CUDA kernel
  46. #define NUM_3D_BOX_CORNERS_MACRO 8
  47. #define NUM_2D_BOX_CORNERS_MACRO 4
  48. #define NUM_THREADS_MACRO 64 // need to be changed when num_threads_ is changed
  49. #define DIVUP(m, n) ((m) / (n) + ((m) % (n) > 0))
  50. #define GPU_CHECK(ans) \
  51. { GPUAssert((ans), __FILE__, __LINE__); }
  52. inline void GPUAssert(cudaError_t code, const char* file, int line,
  53. bool abort = true) {
  54. if (code != cudaSuccess) {
  55. fprintf(stderr, "GPUassert: %s %s %d\n", cudaGetErrorString(code), file,
  56. line);
  57. if (abort) exit(code);
  58. }
  59. }
  60. } // namespace lidar
  61. } // namespace perception
  62. } // namespace apollo