CudaRuntime.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_CudaRuntime_H
21 #define MIRTK_CudaRuntime_H
22 
23 
24 #ifdef HAVE_CUDA
25 # include <cuda_runtime.h>
26 #endif
27 
28 
29 namespace mirtk {
30 
31 
32 // =============================================================================
33 // vector_types.h substitutes in mirtk namespace
34 // =============================================================================
35 
36 typedef unsigned char uchar;
37 typedef unsigned int uint;
38 typedef unsigned short ushort;
39 
40 #if defined(__VECTOR_TYPES_H__)
41 
42 #define __vector1_type__(tag, type) using tag
43 #define __vector2_type__(tag, type) using tag
44 #define __vector3_type__(tag, type) using tag
45 #define __vector4_type__(tag, type) using tag
46 
47 #else // __VECTOR_TYPES_H__
48 
49 #define __vector1_type__(tag, type) \
50  struct tag { type x; }; \
51  typedef struct tag tag
52 #define __vector2_type__(tag, type) \
53  struct tag { type x; type y; }; \
54  typedef struct tag tag
55 #define __vector3_type__(tag, type) \
56  struct tag { type x; type y; type z; }; \
57  typedef struct tag tag
58 #define __vector4_type__(tag, type) \
59  struct tag { type x; type y; type z; type w; }; \
60  typedef struct tag tag
61 
62 #endif // __VECTOR_TYPES_H__
63 
64 
65 #define __vector_type__(type) \
66  __vector1_type__(type##1, type); \
67  __vector2_type__(type##2, type); \
68  __vector3_type__(type##3, type); \
69  __vector4_type__(type##4, type)
70 
71 __vector_type__(char);
72 __vector_type__(uchar);
73 __vector_type__(short);
74 __vector_type__(ushort);
75 __vector_type__(int);
76 __vector_type__(uint);
77 __vector_type__(float);
78 __vector_type__(double);
79 
80 #undef __vector_type__
81 #undef __vector1_type__
82 #undef __vector2_type__
83 #undef __vector3_type__
84 #undef __vector4_type__
85 
86 
87 #if defined(__VECTOR_TYPES_H__)
88 using dim3;
89 #else
90 struct dim3
91 {
92  uint x, y, z;
93  dim3(uint vx = 1, uint vy = 1, uint vz = 1) : x(vx), y(vy), z(vz) {}
94  dim3(uint3 v) : x(v.x), y(v.y), z(v.z) {}
95  operator uint3() { uint3 t; t.x = x; t.y = y; t.z = z; return t; }
96 };
97 typedef struct dim3 dim3;
98 #endif // !defined(__VECTOR_TYPES_H__)
99 
100 // =============================================================================
101 // vector_functions.h substitutes in mirtk namespace
102 // =============================================================================
103 
104 #define __vector1_func__(type) \
105  inline type##1 make_##type##1(type x) \
106  { \
107  type##1 t; t.x = x; return t; \
108  }
109 
110 #define __vector2_func__(type) \
111  inline type##2 make_##type##2(type x, type y) \
112  { \
113  type##2 t; t.x = x, t.y = y; return t; \
114  }
115 
116 #define __vector3_func__(type) \
117  inline type##3 make_##type##3(type x, type y, type z) \
118  { \
119  type##3 t; t.x = x, t.y = y, t.z = z; return t; \
120  }
121 
122 #define __vector4_func__(type) \
123  inline type##4 make_##type##4(type x, type y, type z, type w) \
124  { \
125  type##4 t; t.x = x, t.y = y, t.z = z, t.w = w; return t; \
126  }
127 
128 #define __vector_func__(type) \
129  __vector1_func__(type); \
130  __vector2_func__(type); \
131  __vector3_func__(type); \
132  __vector4_func__(type)
133 
134 __vector_func__(char);
135 __vector_func__(uchar);
136 __vector_func__(short);
137 __vector_func__(ushort);
138 __vector_func__(int);
139 __vector_func__(uint);
140 __vector_func__(float);
141 __vector_func__(double);
142 
143 #undef __vector_func__
144 #undef __vector1_func__
145 #undef __vector2_func__
146 #undef __vector3_func__
147 #undef __vector4_func__
148 
149 
150 } // namespace mirtk
151 
152 #endif // MIRTK_CudaRuntime_H
Definition: IOConfig.h:41