GeNN  3.3.0
GPU enhanced Neuronal Networks (GeNN)
utils.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------
2  Author/Modifier: Thomas Nowotny
3 
4  Institute: Center for Computational Neuroscience and Robotics
5  University of Sussex
6  Falmer, Brighton BN1 9QJ, UK
7 
8  email to: T.Nowotny@sussex.ac.uk
9 
10  initial version: 2010-02-07
11 
12  --------------------------------------------------------------------------*/
13 
14 //--------------------------------------------------------------------------
19 //--------------------------------------------------------------------------
20 
21 #ifndef _UTILS_H_
22 #define _UTILS_H_
23 
24 #include <cstdlib>
25 #include <iostream>
26 #include <string>
27 
28 #ifndef CPU_ONLY
29 #include <cuda.h>
30 #include <cuda_runtime.h>
31 #endif
32 
33 using namespace std;
34 
35 // Forward declarations
36 class CodeStream;
37 
38 #ifndef CPU_ONLY
39 //--------------------------------------------------------------------------
42 //--------------------------------------------------------------------------
43 
44 #if CUDA_VERSION >= 6050
45 #define CHECK_CU_ERRORS(call) \
46  { \
47  CUresult error = call; \
48  if (error != CUDA_SUCCESS) \
49  { \
50  const char *errStr; \
51  cuGetErrorName(error, &errStr); \
52  cerr << __FILE__ << ": " << __LINE__; \
53  cerr << ": cuda driver error " << error << ": "; \
54  cerr << errStr << endl; \
55  exit(EXIT_FAILURE); \
56  } \
57  }
58 #else
59 #define CHECK_CU_ERRORS(call) call
60 #endif
61 
62 // comment below and uncomment here when using CUDA that does not support cugetErrorName
63 //#define CHECK_CU_ERRORS(call) call
64 #define CHECK_CUDA_ERRORS(call) \
65  { \
66  cudaError_t error = call; \
67  if (error != cudaSuccess) \
68  { \
69  cerr << __FILE__ << ": " << __LINE__; \
70  cerr << ": cuda runtime error " << error << ": "; \
71  cerr << cudaGetErrorString(error) << endl; \
72  exit(EXIT_FAILURE); \
73  } \
74  }
75 #endif
76 
77 
78 //--------------------------------------------------------------------------
81 //--------------------------------------------------------------------------
82 
83 #define B(x,i) ((x) & (0x80000000 >> (i)))
84 
85 #define setB(x,i) x= ((x) | (0x80000000 >> (i)))
86 
87 #define delB(x,i) x= ((x) & (~(0x80000000 >> (i))))
88 
89 //--------------------------------------------------------------------------
92 //--------------------------------------------------------------------------
93 
94 #define USE(expr) do { (void)(expr); } while (0)
95 
96 #ifndef CPU_ONLY
97 //--------------------------------------------------------------------------
100 //--------------------------------------------------------------------------
101 
102 CUresult cudaFuncGetAttributesDriver(cudaFuncAttributes *attr, CUfunction kern);
103 #endif
104 
105 
106 //--------------------------------------------------------------------------
109 //--------------------------------------------------------------------------
110 
111 inline void gennError(const string &error)
112 {
113  cerr << "GeNN error: " << error << endl;
114  exit(EXIT_FAILURE);
115 }
116 
117 //--------------------------------------------------------------------------
119 //--------------------------------------------------------------------------
120 
121 size_t theSize(const string &type);
122 
123 
124 //--------------------------------------------------------------------------
127 //--------------------------------------------------------------------------
128 
129 void writeHeader(CodeStream &os);
130 
131 
132 #endif // _UTILS_H_
void writeHeader(CodeStream &os)
Function to write the comment header denoting file authorship and contact details into the generated ...
Definition: utils.cc:87
type
Definition: generate_swig_interfaces.py:680
size_t theSize(const string &type)
Tool for determining the size of variable types on the current architecture.
Definition: utils.cc:104
Helper class for generating code - automatically inserts brackets, indents etc.
Definition: codeStream.h:14
void gennError(const string &error)
Function called upon the detection of an error. Outputs an error message and then exits...
Definition: utils.h:111
CUresult cudaFuncGetAttributesDriver(cudaFuncAttributes *attr, CUfunction kern)
Function for getting the capabilities of a CUDA device via the driver API.
Definition: utils.cc:41