GeNN  2.2.3
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 <iostream>
25 #include <string>
26 #ifndef CPU_ONLY
27 #include <cuda.h>
28 #include <cuda_runtime.h>
29 #endif
30 
31 using namespace std;
32 
33 
34 #ifndef CPU_ONLY
35 //--------------------------------------------------------------------------
38 //--------------------------------------------------------------------------
39 
40 #if CUDA_VERSION >= 6050
41 #define CHECK_CU_ERRORS(call) \
42  { \
43  CUresult error = call; \
44  if (error != CUDA_SUCCESS) \
45  { \
46  const char *errStr; \
47  cuGetErrorName(error, &errStr); \
48  cerr << __FILE__ << ": " << __LINE__; \
49  cerr << ": cuda driver error " << error << ": "; \
50  cerr << errStr << endl; \
51  exit(EXIT_FAILURE); \
52  } \
53  }
54 #else
55 #define CHECK_CU_ERRORS(call) call
56 #endif
57 
58 // comment below and uncomment here when using CUDA that does not support cugetErrorName
59 //#define CHECK_CU_ERRORS(call) call
60 #define CHECK_CUDA_ERRORS(call) \
61  { \
62  cudaError_t error = call; \
63  if (error != cudaSuccess) \
64  { \
65  cerr << __FILE__ << ": " << __LINE__; \
66  cerr << ": cuda runtime error " << error << ": "; \
67  cerr << cudaGetErrorString(error) << endl; \
68  exit(EXIT_FAILURE); \
69  } \
70  }
71 #endif
72 
73 
74 //--------------------------------------------------------------------------
77 //--------------------------------------------------------------------------
78 
79 #define B(x,i) ((x) & (0x80000000 >> (i)))
80 
81 #define setB(x,i) x= ((x) | (0x80000000 >> (i)))
82 
83 #define delB(x,i) x= ((x) & (~(0x80000000 >> (i))))
84 
85 
86 #ifndef CPU_ONLY
87 //--------------------------------------------------------------------------
90 //--------------------------------------------------------------------------
91 
92 CUresult cudaFuncGetAttributesDriver(cudaFuncAttributes *attr, CUfunction kern);
93 #endif
94 
95 
96 //--------------------------------------------------------------------------
99 //--------------------------------------------------------------------------
100 
101 void gennError(string error);
102 
103 
104 //--------------------------------------------------------------------------
106 //--------------------------------------------------------------------------
107 
108 unsigned int theSize(string type);
109 
110 
111 //--------------------------------------------------------------------------
114 //--------------------------------------------------------------------------
115 
116 void writeHeader(ostream &os);
117 
118 
119 #endif // _UTILS_H_
void gennError(string error)
Function called upon the detection of an error. Outputs an error message and then exits...
Definition: utils.cc:83
CUresult cudaFuncGetAttributesDriver(cudaFuncAttributes *attr, CUfunction kern)
Function for getting the capabilities of a CUDA device via the driver API.
Definition: utils.cc:36
unsigned int theSize(string type)
Tool for determining the size of variable types on the current architecture.
Definition: utils.cc:112
void writeHeader(ostream &os)
Function to write the comment header denoting file authorship and contact details into the generated ...
Definition: utils.cc:95