Scanner C++ API
cuda.h
1 /* Copyright 2016 Carnegie Mellon University, NVIDIA Corporation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #ifdef HAVE_CUDA
19 #include <cuda.h>
20 #include <cuda_runtime_api.h>
21 #endif
22 
23 #include <glog/logging.h>
24 
25 #ifdef HAVE_CUDA
26 #define CUDA_PROTECT(s) (s);
27 #else
28 #define CUDA_PROTECT(s) \
29  { LOG(FATAL) << "Cuda not enabled."; }
30 #endif
31 
32 #ifdef HAVE_CUDA
33 
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <sys/prctl.h>
37 #include <sys/wait.h>
38 #include <unistd.h>
39 
40 #define CU_CHECK(ans) \
41  { cuAssert((ans), __FILE__, __LINE__); }
42 
43 inline void cuAssert(cudaError_t code, const char* file, int line) {
44  if (code != cudaSuccess) {
45  LOG(FATAL) << "GPUassert: " << cudaGetErrorString(code) << " " << file
46  << " " << line;
47  }
48 }
49 
50 #define CUD_CHECK(ans) \
51  { cudAssert((ans), __FILE__, __LINE__); }
52 
53 inline void cudAssert(CUresult code, const char* file, int line) {
54  if (code != CUDA_SUCCESS) {
55  const char* err_str;
56  cuGetErrorString(code, &err_str);
57  LOG(FATAL) << "GPUassert: " << err_str << " " << file << " " << line;
58  }
59 }
60 
61 #endif