Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 193 lines (168 sloc) 5.666 kB
5a8ba94 @cjang initial import into version control for GitHub
authored
1 // Copyright 2010 Chris Jang
2 //
3 // This file is part of GATLAS.
4 //
5 // GATLAS is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // GATLAS is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with GATLAS. If not, see <http://www.gnu.org/licenses/>.
17
18 template <typename X>
19 bool checkFail(const cl_int status,
20 const X msgX)
21 {
22 if (CL_SUCCESS != status)
23 {
24 std::cerr << msgX << " " << status << std::endl;
25 return true; // code was failure
26 }
27
28 return false; // did not fail
29 }
30
31 template <typename X, typename Y>
32 bool checkFail(const cl_int status,
33 const X msgX, const Y msgY)
34 {
35 if (CL_SUCCESS != status)
36 {
37 std::cerr << msgX << msgY << " " << status << std::endl;
38 return true; // code was failure
39 }
40
41 return false; // did not fail
42 }
43
44 template <typename X, typename Y, typename Z>
45 bool checkFail(const cl_int status,
46 const X msgX, const Y msgY, const Z msgZ)
47 {
48 if (CL_SUCCESS != status)
49 {
50 std::cerr << msgX << msgY << msgZ << " " << status << std::endl;
51 return true; // code was failure
52 }
53
54 return false; // did not fail
55 }
56
57 template <typename X, typename Y, typename Z,
58 typename A>
59 bool checkFail(const cl_int status,
60 const X msgX, const Y msgY, const Z msgZ,
61 const A msgA)
62 {
63 if (CL_SUCCESS != status)
64 {
65 std::cerr << msgX << msgY << msgZ
66 << msgA << " " << status << std::endl;
67 return true; // code was failure
68 }
69
70 return false; // did not fail
71 }
72
73 template <typename X, typename Y, typename Z,
74 typename A, typename B>
75 bool checkFail(const cl_int status,
76 const X msgX, const Y msgY, const Z msgZ,
77 const A msgA, const B msgB)
78 {
79 if (CL_SUCCESS != status)
80 {
81 std::cerr << msgX << msgY << msgZ
82 << msgA << msgB << " " << status << std::endl;
83 return true; // code was failure
84 }
85
86 return false; // did not fail
87 }
88
89 template <typename X, typename Y, typename Z,
90 typename A, typename B, typename C>
91 bool checkFail(const cl_int status,
92 const X msgX, const Y msgY, const Z msgZ,
93 const A msgA, const B msgB, const C msgC)
94 {
95 if (CL_SUCCESS != status)
96 {
97 std::cerr << msgX << msgY << msgZ
98 << msgA << msgB << msgC << " " << status << std::endl;
99 return true; // code was failure
100 }
101
102 return false; // did not fail
103 }
104
105 template <typename T>
106 std::string devinfovalue(const cl_device_info device_info,
107 const T value)
108 {
109 if (CL_DEVICE_SINGLE_FP_CONFIG == device_info)
110 {
111 std::string msg;
112 if (CL_FP_DENORM & value) msg += "denorm, ";
113 if (CL_FP_INF_NAN & value) msg += "inf and quiet NaNs, ";
114 if (CL_FP_ROUND_TO_NEAREST & value) msg += "round to nearest, ";
115 if (CL_FP_ROUND_TO_ZERO & value) msg += "round to zero, ";
116 if (CL_FP_ROUND_TO_INF & value) msg += "round to inf, ";
117 if (CL_FP_FMA & value) msg += "fused multiply-add, ";
118 return msg;
119 }
120
121 if (CL_DEVICE_GLOBAL_MEM_CACHE_TYPE == device_info)
122 {
123 switch (value)
124 {
125 case (CL_NONE) : return "none";
126 case (CL_READ_ONLY_CACHE) : return "read only cache";
127 case (CL_READ_WRITE_CACHE) : return "read write cache";
128 }
129 }
130
131 if (CL_DEVICE_LOCAL_MEM_TYPE == device_info)
132 {
133 switch (value)
134 {
135 case (CL_LOCAL) : return "local";
136 case (CL_GLOBAL) : return "global";
137 }
138 }
139
140 if (CL_DEVICE_EXECUTION_CAPABILITIES == device_info)
141 {
142 std::string msg;
143 if (CL_EXEC_KERNEL & value) msg += "kernel, ";
144 if (CL_EXEC_NATIVE_KERNEL & value) msg += "native kernel, ";
145 return msg;
146 }
147
148 if (CL_DEVICE_QUEUE_PROPERTIES == device_info)
149 {
150 std::string msg;
151 if (CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE & value) msg += "out of order execution, ";
152 if (CL_QUEUE_PROFILING_ENABLE & value) msg += "profiling, ";
153 return msg;
154 }
155
156 switch (device_info)
157 {
158 case (CL_DEVICE_TYPE) : return devtype(value);
159 case (CL_DEVICE_IMAGE_SUPPORT) : return value ? "true" : "false";
160 case (CL_DEVICE_ERROR_CORRECTION_SUPPORT) : return value ? "true" : "false";
161 case (CL_DEVICE_ENDIAN_LITTLE) : return value ? "true" : "false";
162 case (CL_DEVICE_AVAILABLE) : return value ? "true" : "false";
163 case (CL_DEVICE_COMPILER_AVAILABLE) : return value ? "true" : "value";
164 }
165
166 std::ostringstream msg;
167 msg << value;
168 return msg.str();
169 }
170
171 template <typename T>
172 T* alloc_memalign(const size_t n, const size_t ALIGNMENT)
173 {
174 T* ptr;
175
176 if (posix_memalign((void**)&ptr, ALIGNMENT, n * sizeof(T)))
177 return NULL; // failure, could not allocate aligned memory
178
179 return ptr;
180 }
181
182 template <typename T>
183 T* alloc_memalign(const size_t n)
184 {
185 return alloc_memalign<T>(n, Type<T>::ALIGNMENT);
186 }
187
188 template <typename SCALAR, size_t N>
189 SCALAR* alloc_memalign(const size_t n)
190 {
191 return alloc_memalign<SCALAR>(n, N * Type<SCALAR>::ALIGNMENT);
192 }
Something went wrong with that request. Please try again.