BioDynaMo  v1.05.120-25dc9790
cuda_error_chk.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_GPU_CUDA_ERROR_CHK_H_
16 #define CORE_GPU_CUDA_ERROR_CHK_H_
17 
18 #if !defined(__ROOTCLING__) && !defined(G__DICTIONARY)
19 #ifdef USE_CUDA
20 
21 #include <unistd.h>
22 #include <cstdio>
23 
24 #define GpuErrchk(ans) \
25  { GpuAssert((ans), __FILE__, __LINE__); }
26 inline void GpuAssert(cudaError_t code, const char *file, int line,
27  bool abort = true) {
28  if (code != cudaSuccess) {
29  fprintf(stderr, "GPUassert (error code %d): %s %s %d\n", code,
30  cudaGetErrorString(code), file, line);
31  if (code == cudaErrorInsufficientDriver) {
32  printf(
33  "This probably means that no CUDA-compatible GPU has been detected. "
34  "Consider setting the use_opencl flag to \"true\" in the bmd.toml "
35  "file to use OpenCL instead.\n");
36  }
37  if (abort)
38  exit(code);
39  }
40 }
41 
42 #endif // USE_CUDA
43 #endif // !__ROOTCLING__ && !G__DICTIONARY
44 #endif // CORE_GPU_CUDA_ERROR_CHK_H_