Apollo 11.0
自动驾驶开放平台
common.h
浏览该文件的文档.
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/*
18 * Copyright 2018-2019 Autoware Foundation. All rights reserved.
19 *
20 * Licensed under the Apache License, Version 2.0 (the "License");
21 * you may not use this file except in compliance with the License.
22 * You may obtain a copy of the License at
23 *
24 * http://www.apache.org/licenses/LICENSE-2.0
25 *
26 * Unless required by applicable law or agreed to in writing, software
27 * distributed under the License is distributed on an "AS IS" BASIS,
28 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 * See the License for the specific language governing permissions and
30 * limitations under the License.
31 */
32
40#pragma once
41
42// headers in STL
43#include <stdio.h>
44
45// headers in CUDA/HIP
46#if GPU_PLATFORM == NVIDIA
47 #include <cuda_runtime_api.h>
48#elif GPU_PLATFORM == AMD
49 #include <hip/hip_runtime_api.h>
50 #define cudaError_t hipError_t
51 #define cudaFree hipFree
52 #define cudaGetErrorString hipGetErrorString
53 #define cudaMalloc hipMalloc
54 #define cudaMemcpy hipMemcpy
55 #define cudaMemcpyAsync hipMemcpyAsync
56 #define cudaMemcpyDeviceToDevice hipMemcpyDeviceToDevice
57 #define cudaMemcpyDeviceToHost hipMemcpyDeviceToHost
58 #define cudaMemcpyHostToDevice hipMemcpyHostToDevice
59 #define cudaMemset hipMemset
60 #define cudaSetDevice hipSetDevice
61 #define cudaStream_t hipStream_t
62 #define cudaStreamCreate hipStreamCreate
63 #define cudaStreamDestroy hipStreamDestroy
64 #define cudaSuccess hipSuccess
65#endif
66
67namespace apollo {
68namespace perception {
69namespace lidar {
70
71// using MACRO to allocate memory inside CUDA kernel
72#define NUM_3D_BOX_CORNERS_MACRO 8
73#define NUM_2D_BOX_CORNERS_MACRO 4
74#define NUM_THREADS_MACRO 64 // need to be changed when num_threads_ is changed
75
76#define DIVUP(m, n) ((m) / (n) + ((m) % (n) > 0))
77
78#define GPU_CHECK(ans) \
79 { GPUAssert((ans), __FILE__, __LINE__); }
80inline void GPUAssert(cudaError_t code, const char* file, int line,
81 bool abort = true) {
82 if (code != cudaSuccess) {
83 fprintf(stderr, "GPUassert: %s %s %d\n", cudaGetErrorString(code), file,
84 line);
85 if (abort) exit(code);
86 }
87}
88
89} // namespace lidar
90} // namespace perception
91} // namespace apollo
void GPUAssert(cudaError_t code, const char *file, int line, bool abort=true)
Definition common.h:80
class register implement
Definition arena_queue.h:37