GGEMS  1.1
GPU GEant4-based Monte Carlo Simulations
GGEMSOpenCLManager.cc
Go to the documentation of this file.
1 // ************************************************************************
2 // * This file is part of GGEMS. *
3 // * *
4 // * GGEMS is free software: you can redistribute it and/or modify *
5 // * it under the terms of the GNU General Public License as published by *
6 // * the Free Software Foundation, either version 3 of the License, or *
7 // * (at your option) any later version. *
8 // * *
9 // * GGEMS is distributed in the hope that it will be useful, *
10 // * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 // * GNU General Public License for more details. *
13 // * *
14 // * You should have received a copy of the GNU General Public License *
15 // * along with GGEMS. If not, see <https://www.gnu.org/licenses/>. *
16 // * *
17 // ************************************************************************
18 
37 #include "GGEMS/global/GGEMS.hh"
39 
43 
45 {
46  GGcout("GGEMSOpenCLManager", "GGEMSOpenCLManager", 3) << "GGEMSOpenCLManager creating..." << GGendl;
47 
48  GGcout("GGEMSOpenCLManager", "GGEMSOpenCLManager", 1) << "Retrieving OpenCL platform(s)..." << GGendl;
49  CheckOpenCLError(cl::Platform::get(&platforms_), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
50 
51  // Prevent cache kernel in OpenCL
52  #ifndef OPENCL_CACHE_KERNEL_COMPILATION
53  #ifdef _MSC_VER
54  _putenv("CUDA_CACHE_DISABLE=1");
55  #else
56  std::string disable_cache("CUDA_CACHE_DISABLE=1");
57  putenv(&disable_cache[0]);
58  #endif
59  #endif
60 
61  // Parameters reading infos from platform and device
62  std::string info_string("");
63  cl_device_type device_type;
64  cl_device_fp_config device_fp_config;
65  cl_device_exec_capabilities device_exec_capabilities;
66  cl_device_mem_cache_type device_mem_cache_type;
67  cl_device_local_mem_type device_local_mem_type;
68  cl_device_affinity_domain device_affinity_domain;
69  GGuint info_uint = 0;
70  GGulong info_ulong = 0;
71  GGsize info_size = 0;
72  GGbool info_bool = false;
73  char char_data[1024];
74  GGsize size_data[3] = {0, 0, 0};
75 
76  // Getting infos about platform
77  for (auto& p : platforms_) {
78  CheckOpenCLError(p.getInfo(CL_PLATFORM_PROFILE, &info_string), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
79  platform_profile_.push_back(info_string);
80 
81  CheckOpenCLError(p.getInfo(CL_PLATFORM_VERSION, &info_string), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
82  platform_version_.push_back(info_string);
83 
84  CheckOpenCLError(p.getInfo(CL_PLATFORM_NAME, &info_string), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
85  platform_name_.push_back(info_string);
86 
87  CheckOpenCLError(p.getInfo(CL_PLATFORM_VENDOR, &info_string), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
88  platform_vendor_.push_back(info_string);
89 
90  CheckOpenCLError(p.getInfo(CL_PLATFORM_EXTENSIONS, &info_string), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
91  platform_extensions_.push_back(info_string);
92  }
93 
94  // Retrieve all the available devices
95  GGcout("GGEMSOpenCLManager", "GGEMSOpenCLManager", 1) << "Retrieving OpenCL device(s)..." << GGendl;
96  for (GGsize i = 0; i < platforms_.size(); ++i) {
97  std::vector<cl::Device> all_devices;
98 
99  // Getting device from platform
100  platforms_[i].getDevices(CL_DEVICE_TYPE_ALL, &all_devices);
101 
102  // Storing all devices from platform
103  for (auto& d : all_devices) devices_.emplace_back(new cl::Device(d));
104  }
105 
106  // Getting infos about device
107  for (GGsize i = 0; i < devices_.size(); ++i) {
108  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_TYPE, &device_type), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
109  device_type_.push_back(device_type);
110 
111  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_NAME, &info_string), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
112  device_name_.push_back(info_string);
113 
114  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_VENDOR, &info_string), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
115  device_vendor_.push_back(info_string);
116 
117  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_VENDOR_ID, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
118  device_vendor_id_.push_back(info_uint);
119 
120  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_PROFILE, &info_string), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
121  device_profile_.push_back(info_string);
122 
123  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_VERSION, &char_data), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
124  device_version_.push_back(std::string(char_data));
125 
126  CheckOpenCLError(devices_[i]->getInfo(CL_DRIVER_VERSION, &char_data), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
127  device_driver_version_.push_back(std::string(char_data));
128 
129  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_OPENCL_C_VERSION, &char_data), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
130  device_opencl_c_version_.push_back(std::string(char_data));
131 
132  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
133  device_native_vector_width_char_.push_back(info_uint);
134 
135  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
136  device_native_vector_width_short_.push_back(info_uint);
137 
138  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
139  device_native_vector_width_int_.push_back(info_uint);
140 
141  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
142  device_native_vector_width_long_.push_back(info_uint);
143 
144  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
145  device_native_vector_width_half_.push_back(info_uint);
146 
147  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
148  device_native_vector_width_float_.push_back(info_uint);
149 
150  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
151  device_native_vector_width_double_.push_back(info_uint);
152 
153  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
154  device_preferred_vector_width_char_.push_back(info_uint);
155 
156  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
157  device_preferred_vector_width_short_.push_back(info_uint);
158 
159  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
160  device_preferred_vector_width_int_.push_back(info_uint);
161 
162  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
163  device_preferred_vector_width_long_.push_back(info_uint);
164 
165  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
166  device_preferred_vector_width_half_.push_back(info_uint);
167 
168  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
169  device_preferred_vector_width_float_.push_back(info_uint);
170 
171  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
172  device_preferred_vector_width_double_.push_back(info_uint);
173 
174  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_ADDRESS_BITS, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
175  device_address_bits_.push_back(info_uint);
176 
177  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_AVAILABLE, &info_bool), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
178  device_available_.push_back(info_bool);
179 
180  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_COMPILER_AVAILABLE, &info_bool), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
181  device_compiler_available_.push_back(info_bool);
182 
183  if (device_native_vector_width_half_[i] != 0) {
184  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_HALF_FP_CONFIG, &device_fp_config), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
185  device_half_fp_config_.push_back(device_fp_config);
186  }
187 
188  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_SINGLE_FP_CONFIG, &device_fp_config), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
189  device_single_fp_config_.push_back(device_fp_config);
191  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_DOUBLE_FP_CONFIG, &device_fp_config), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
192  device_double_fp_config_.push_back(device_fp_config);
193  }
194 
195  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_ENDIAN_LITTLE, &info_bool), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
196  device_endian_little_.push_back(info_bool);
197 
198  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_EXTENSIONS, &info_string), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
199  device_extensions_.push_back(info_string);
200 
201  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_ERROR_CORRECTION_SUPPORT, &info_bool), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
202  device_error_correction_support_.push_back(info_bool);
203 
204  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_EXECUTION_CAPABILITIES, &device_exec_capabilities), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
205  device_execution_capabilities_.push_back(device_exec_capabilities);
206 
207  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, &info_ulong), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
208  device_global_mem_cache_size_.push_back(info_ulong);
209 
210  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, &device_mem_cache_type), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
211  device_global_mem_cache_type_.push_back(device_mem_cache_type);
212 
213  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
214  device_global_mem_cacheline_size_.push_back(info_uint);
215 
216  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_GLOBAL_MEM_SIZE, &info_ulong), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
217  device_global_mem_size_.push_back(info_ulong);
218 
219  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_LOCAL_MEM_SIZE, &info_ulong), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
220  device_local_mem_size_.push_back(info_ulong);
221 
222  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_LOCAL_MEM_TYPE, &device_local_mem_type), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
223  device_local_mem_type_.push_back(device_local_mem_type);
224 
225  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_HOST_UNIFIED_MEMORY, &info_bool), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
226  device_host_unified_memory_.push_back(info_bool);
227 
228  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_IMAGE_SUPPORT, &info_bool), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
229  device_image_support_.push_back(info_bool);
230 
231  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, &info_size), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
232  device_image_max_array_size_.push_back(info_size);
233 
234  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_IMAGE_MAX_BUFFER_SIZE, &info_size), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
235  device_image_max_buffer_size_.push_back(info_size);
236 
237  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_IMAGE2D_MAX_WIDTH, &info_size), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
238  device_image2D_max_width_.push_back(info_size);
239 
240  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_IMAGE2D_MAX_HEIGHT, &info_size), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
241  device_image2D_max_height_.push_back(info_size);
242 
243  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_IMAGE3D_MAX_WIDTH, &info_size), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
244  device_image3D_max_width_.push_back(info_size);
245 
246  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_IMAGE3D_MAX_HEIGHT, &info_size), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
247  device_image3D_max_height_.push_back(info_size);
248 
249  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_IMAGE3D_MAX_DEPTH, &info_size), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
250  device_image3D_max_depth_.push_back(info_size);
251 
252  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_MAX_READ_IMAGE_ARGS, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
253  device_max_read_image_args_.push_back(info_uint);
254 
255  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_MAX_WRITE_IMAGE_ARGS, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
256  device_max_write_image_args_.push_back(info_uint);
257 
258  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_MAX_CLOCK_FREQUENCY, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
259  device_max_clock_frequency_.push_back(info_uint);
260 
261  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_MAX_COMPUTE_UNITS, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
262  device_max_compute_units_.push_back(info_uint);
263 
264  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_MAX_CONSTANT_ARGS, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
265  device_max_constant_args_.push_back(info_uint);
266 
267  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, &info_ulong), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
268  device_max_constant_buffer_size_.push_back(info_ulong);
269 
270  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_MAX_MEM_ALLOC_SIZE, &info_ulong), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
271  device_max_mem_alloc_size_.push_back(info_ulong);
272 
273  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_MAX_PARAMETER_SIZE, &info_size), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
274  device_max_parameter_size_.push_back(info_size);
275 
276  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_MAX_WORK_GROUP_SIZE, &info_size), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
277  device_max_work_group_size_.push_back(info_size);
278 
279  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
280  device_max_work_item_dimensions_.push_back(info_uint);
281 
282  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_MEM_BASE_ADDR_ALIGN, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
283  device_mem_base_addr_align_.push_back(info_uint);
284 
285  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_MAX_WORK_ITEM_SIZES, &size_data), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
286  for (GGsize j = 0; j < 3; ++j) device_max_work_item_sizes_.push_back(size_data[j]);
287 
288  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_PRINTF_BUFFER_SIZE, &info_size), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
289  device_printf_buffer_size_.push_back(info_size);
290 
291  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_MAX_SAMPLERS, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
292  device_max_samplers_.push_back(info_uint);
293 
294  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_PARTITION_AFFINITY_DOMAIN, &device_affinity_domain), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
295  device_partition_affinity_domain_.push_back(device_affinity_domain);
296 
297  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_PARTITION_MAX_SUB_DEVICES, &info_uint), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
298  device_partition_max_sub_devices_.push_back(info_uint);
299 
300  CheckOpenCLError(devices_[i]->getInfo(CL_DEVICE_PROFILING_TIMER_RESOLUTION, &info_size), "GGEMSOpenCLManager", "GGEMSOpenCLManager");
301  device_profiling_timer_resolution_.push_back(info_size);
302  }
303 
304  // Custom work group size, 64 seems a good trade-off
305  work_group_size_ = 64;
306 
307  // Define the compilation options by default for OpenCL
308  build_options_ = "-cl-std=CL1.2 -w -Werror -cl-fast-relaxed-math";
309 
310  // Give precision for dosimetry
311  #ifdef DOSIMETRY_DOUBLE_PRECISION
312  build_options_ += " -DDOSIMETRY_DOUBLE_PRECISION";
313  #endif
314 
315  // Add auxiliary function path to OpenCL options
316  #ifdef GGEMS_PATH
317  build_options_ += " -I";
318  build_options_ += GGEMS_PATH;
319  build_options_ += "/include";
320  #elif
321  GGEMSMisc::ThrowException("GGEMSOpenCLManager","GGEMSOpenCLManager", "OPENCL_KERNEL_PATH not defined or not find!!!");
322  #endif
323 
324  // Filling umap of vendors
325  vendors_.insert(std::make_pair("nvidia", "NVIDIA Corporation"));
326  vendors_.insert(std::make_pair("intel", "Intel(R) Corporation"));
327  vendors_.insert(std::make_pair("amd", "Advanced Micro Devices, Inc."));
328 
329  // Create buffer of kernels for all devices
330  kernels_.clear();
332 
333  GGcout("GGEMSOpenCLManager", "GGEMSOpenCLManager", 3) << "GGEMSOpenCLManager created!!!" << GGendl;
334 }
335 
339 
341 {
342  GGcout("GGEMSOpenCLManager", "~GGEMSOpenCLManager", 3) << "GGEMSOpenCLManager erasing..." << GGendl;
343 
344  GGcout("GGEMSOpenCLManager", "~GGEMSOpenCLManager", 3) << "GGEMSOpenCLManager erased!!!" << GGendl;
345 }
346 
350 
352 {
353  GGcout("GGEMSOpenCLManager", "Clean", 3) << "GGEMSOpenCLManager cleaning..." << GGendl;
354 
355  // Cleaning all singletons
364 
365  // Freeing platforms, and platform infos
366  platform_profile_.clear();
367  platform_version_.clear();
368  platform_name_.clear();
369  platform_vendor_.clear();
370  platform_extensions_.clear();
371  platforms_.clear();
372 
373  // Freeing devices
374  for (auto d : devices_) delete d;
375  devices_.clear();
376  device_indices_.clear();
377  device_type_.clear();
378  device_name_.clear();
379  device_vendor_.clear();
380  device_vendor_id_.clear();
381  device_profile_.clear();
382  device_version_.clear();
383  device_driver_version_.clear();
384  device_opencl_c_version_.clear();
399  device_address_bits_.clear();
400  device_available_.clear();
402  device_half_fp_config_.clear();
403  device_single_fp_config_.clear();
404  device_double_fp_config_.clear();
405  device_endian_little_.clear();
406  device_extensions_.clear();
412  device_global_mem_size_.clear();
413  device_local_mem_size_.clear();
414  device_local_mem_type_.clear();
418  device_image_support_.clear();
432  device_max_samplers_.clear();
441 
442  // Freeing contexts, queues and events
443  for (auto c : contexts_) delete c;
444  contexts_.clear();
445  for (auto q : queues_) delete q;
446  queues_.clear();
447  for (auto e : events_) delete e;
448  events_.clear();
449 
450  // Deleting kernel
451  for (auto k : kernels_) delete k;
452  kernels_.clear();
453 
454  GGcout("GGEMSOpenCLManager", "Clean", 3) << "GGEMSOpenCLManager cleaned!!!" << GGendl;
455 }
456 
460 
462 {
463  for (GGsize i = 0; i < platforms_.size(); ++i) {
464  GGcout("GGEMSOpenCLManager", "PrintPlatformInfos", 0) << GGendl;
465  GGcout("GGEMSOpenCLManager", "PrintPlatformInfos", 0) << "#### PLATFORM: " << i << " ####" << GGendl;
466  GGcout("GGEMSOpenCLManager", "PrintPlatformInfos", 0) << " + Platform: " << platform_profile_[i] << GGendl;
467  GGcout("GGEMSOpenCLManager", "PrintPlatformInfos", 0) << " + Version: " << platform_version_[i] << GGendl;
468  GGcout("GGEMSOpenCLManager", "PrintPlatformInfos", 0) << " + Name: " << platform_name_[i] << GGendl;
469  GGcout("GGEMSOpenCLManager", "PrintPlatformInfos", 0) << " + Vendor: " << platform_vendor_[i] << GGendl;
470  GGcout("GGEMSOpenCLManager", "PrintPlatformInfos", 0) << " + Extensions: " << platform_extensions_[i] << GGendl;
471  }
472  GGcout("GGEMSOpenCLManager", "PrintPlatformInfos", 0) << GGendl;
473 }
474 
478 
480 {
481  for (GGsize i = 0; i < devices_.size(); ++i) {
482  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << GGendl;
483  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << "#### DEVICE: " << i << " ####" << GGendl;
484  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Name: " << device_name_[i] << GGendl;
485  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Vendor: " << device_vendor_[i] << GGendl;
486  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Vendor ID: " << device_vendor_id_[i] << GGendl;
487  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Version: " << device_version_[i] << GGendl;
488  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Driver Version: " << device_driver_version_[i] << GGendl;
489  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + OpenCL C Version: " << device_opencl_c_version_[i] << GGendl;
490  if (device_type_[i] == CL_DEVICE_TYPE_CPU) {
491  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Device Type: " << "CL_DEVICE_TYPE_CPU" << GGendl;
492  }
493  else if (device_type_[i] == CL_DEVICE_TYPE_GPU) {
494  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Device Type: " << "CL_DEVICE_TYPE_GPU" << GGendl;
495  }
496  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Profile: " << device_profile_[i] << GGendl;
497  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Native Vector Width Char: " << device_native_vector_width_char_[i] << GGendl;
498  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Native Vector Width Short: " << device_native_vector_width_short_[i] << GGendl;
499  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Native Vector Width Int: " << device_native_vector_width_int_[i] << GGendl;
500  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Native Vector Width Long: " << device_native_vector_width_long_[i] << GGendl;
501  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Native Vector Width Half: " << device_native_vector_width_half_[i] << GGendl;
502  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Native Vector Width Float: " << device_native_vector_width_float_[i] << GGendl;
503  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Native Vector Width Double: " << device_native_vector_width_double_[i] << GGendl;
504  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Preferred Vector Width Char: " << device_preferred_vector_width_char_[i] << GGendl;
505  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Preferred Vector Width Short: " << device_preferred_vector_width_short_[i] << GGendl;
506  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Preferred Vector Width Int: " << device_preferred_vector_width_int_[i] << GGendl;
507  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Preferred Vector Width Long: " << device_preferred_vector_width_long_[i] << GGendl;
508  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Preferred Vector Width Half: " << device_preferred_vector_width_half_[i] << GGendl;
509  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Preferred Vector Width Float: " << device_preferred_vector_width_float_[i] << GGendl;
510  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Preferred Vector Width Double: " << device_preferred_vector_width_double_[i] << GGendl;
511  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Address Bits: " << device_address_bits_[i] << " bits" << GGendl;
512  if (device_available_[i] == static_cast<GGbool>(true)) {
513  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Device Available: ON" << GGendl;
514  }
515  else {
516  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Device Available: OFF" << GGendl;
517  }
518  if (device_compiler_available_[i] == static_cast<GGbool>(true)) {
519  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Compiler Available: ON" << GGendl;
520  }
521  else {
522  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Compiler Available: OFF" << GGendl;
523  }
524  if (device_native_vector_width_half_[i] != 0) {
525  std::string half_fp_capability("");
526  half_fp_capability += device_half_fp_config_[i] & CL_FP_DENORM ? "DENORM " : "";
527  half_fp_capability += device_half_fp_config_[i] & CL_FP_INF_NAN ? "INF_NAN " : "";
528  half_fp_capability += device_half_fp_config_[i] & CL_FP_ROUND_TO_NEAREST ? "ROUND_TO_NEAREST " : "";
529  half_fp_capability += device_half_fp_config_[i] & CL_FP_ROUND_TO_ZERO ? "ROUND_TO_ZERO " : "";
530  half_fp_capability += device_half_fp_config_[i] & CL_FP_ROUND_TO_INF ? "ROUND_TO_INF " : "";
531  half_fp_capability += device_half_fp_config_[i] & CL_FP_FMA ? "FMA " : "";
532  half_fp_capability += device_half_fp_config_[i] & CL_FP_SOFT_FLOAT ? "SOFT_FLOAT " : "";
533  half_fp_capability += device_half_fp_config_[i] & CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT ? "CORRECTLY_ROUNDED_DIVIDE_SQRT" : "";
534  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Half Precision Capability: " << half_fp_capability << GGendl;
535  }
536  std::string single_fp_capability("");
537  single_fp_capability += device_single_fp_config_[i] & CL_FP_DENORM ? "DENORM " : "";
538  single_fp_capability += device_single_fp_config_[i] & CL_FP_INF_NAN ? "INF_NAN " : "";
539  single_fp_capability += device_single_fp_config_[i] & CL_FP_ROUND_TO_NEAREST ? "ROUND_TO_NEAREST " : "";
540  single_fp_capability += device_single_fp_config_[i] & CL_FP_ROUND_TO_ZERO ? "ROUND_TO_ZERO " : "";
541  single_fp_capability += device_single_fp_config_[i] & CL_FP_ROUND_TO_INF ? "ROUND_TO_INF " : "";
542  single_fp_capability += device_single_fp_config_[i] & CL_FP_FMA ? "FMA " : "";
543  single_fp_capability += device_single_fp_config_[i] & CL_FP_SOFT_FLOAT ? "SOFT_FLOAT " : "";
544  single_fp_capability += device_single_fp_config_[i] & CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT ? "CORRECTLY_ROUNDED_DIVIDE_SQRT" : "";
545  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Single Precision Capability: " << single_fp_capability << GGendl;
547  std::string double_fp_capability("");
548  double_fp_capability += device_double_fp_config_[i] & CL_FP_DENORM ? "DENORM " : "";
549  double_fp_capability += device_double_fp_config_[i] & CL_FP_INF_NAN ? "INF_NAN " : "";
550  double_fp_capability += device_double_fp_config_[i] & CL_FP_ROUND_TO_NEAREST ? "ROUND_TO_NEAREST " : "";
551  double_fp_capability += device_double_fp_config_[i] & CL_FP_ROUND_TO_ZERO ? "ROUND_TO_ZERO " : "";
552  double_fp_capability += device_double_fp_config_[i] & CL_FP_ROUND_TO_INF ? "ROUND_TO_INF " : "";
553  double_fp_capability += device_double_fp_config_[i] & CL_FP_FMA ? "FMA " : "";
554  double_fp_capability += device_double_fp_config_[i] & CL_FP_SOFT_FLOAT ? "SOFT_FLOAT " : "";
555  double_fp_capability += device_double_fp_config_[i] & CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT ? "CORRECTLY_ROUNDED_DIVIDE_SQRT" : "";
556  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Double Precision Capability: " << double_fp_capability << GGendl;
557  }
558  if (device_endian_little_[i] == static_cast<GGbool>(true)) {
559  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Endian Little: ON" << GGendl;
560  }
561  else {
562  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Endian Little: OFF" << GGendl;
563  }
564  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Extensions: " << device_extensions_[i] << GGendl;
565  if (device_error_correction_support_[i] == static_cast<GGbool>(true)) {
566  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Error Correction Support: ON" << GGendl;
567  }
568  else {
569  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Error Correction Support: OFF" << GGendl;
570  }
571  std::string execution_capabilities("");
572  execution_capabilities += device_execution_capabilities_[i] & CL_EXEC_KERNEL ? "KERNEL " : "";
573  execution_capabilities += device_execution_capabilities_[i] & CL_EXEC_NATIVE_KERNEL ? "NATIVE_KERNEL " : "";
574  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Execution Capabilities: " << execution_capabilities << GGendl;
575  if (device_global_mem_cache_type_[i] == CL_NONE) {
576  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Global Mem. Cache Type: " << "CL_NONE" << GGendl;
577  }
578  else if (device_global_mem_cache_type_[i] == CL_READ_ONLY_CACHE) {
579  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Global Mem. Cache Type: " << "CL_READ_ONLY_CACHE" << GGendl;
580  }
581  else if (device_global_mem_cache_type_[i] == CL_READ_WRITE_CACHE) {
582  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Global Mem. Cache Type: " << "CL_READ_WRITE_CACHE" << GGendl;
583  }
584  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Global Mem. Cache Size: " << device_global_mem_cache_size_[i] << " bytes" << GGendl;
585  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Global Mem. Line Cache Size: " << device_global_mem_cacheline_size_[i] << " bytes" << GGendl;
586  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Global Mem. Size: " << device_global_mem_size_[i] << " bytes" << GGendl;
587  if (device_local_mem_type_[i] == CL_LOCAL) {
588  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Local Mem. Type: " << "CL_LOCAL" << GGendl;
589  }
590  else if (device_local_mem_type_[i] == CL_GLOBAL) {
591  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Local Mem. Type: " << "CL_GLOBAL" << GGendl;
592  }
593  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Local Mem. Size: " << device_local_mem_size_[i] << " bytes" << GGendl;
594  if (device_host_unified_memory_[i] == static_cast<GGbool>(true)) {
595  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Host Unified Memory: ON" << GGendl;
596  }
597  else {
598  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Host Unified Memory: OFF" << GGendl;
599  }
600  if (device_image_support_[i] == static_cast<GGbool>(true)) {
601  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Image Support: ON" << GGendl;
602  }
603  else {
604  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Image Support: OFF" << GGendl;
605  }
606  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Image Max Array Size: " << device_image_max_array_size_[i] << GGendl;
607  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Image Max Buffer Size: " << device_image_max_buffer_size_[i] << GGendl;
608  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Image 2D Max Width: " << device_image2D_max_width_[i] << GGendl;
609  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Image 2D Max Height: " << device_image2D_max_height_[i] << GGendl;
610  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Image 3D Max Width: " << device_image3D_max_width_[i] << GGendl;
611  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Image 3D Max Height: " << device_image3D_max_height_[i] << GGendl;
612  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Image 3D Max Depth: " << device_image3D_max_depth_[i] << GGendl;
613  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Max Simultaneous Read Image: " << device_max_read_image_args_[i] << GGendl;
614  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Max Simultaneous Write Image: " << device_max_write_image_args_[i] << GGendl;
615  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Max Clock Frequency: " << device_max_clock_frequency_[i] << " MHz" << GGendl;
616  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Max Compute Units: " << device_max_compute_units_[i] << GGendl;
617  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Max Constant Argument In Kernel: " << device_max_constant_args_[i] << GGendl;
618  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Max Constant Buffer Size: " << device_max_constant_buffer_size_[i] << " bytes" << GGendl;
619  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Mem. Alloc. Size: " << device_max_mem_alloc_size_[i] << " bytes" << GGendl;
620  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Max Parameters Size In Kernel: " << device_max_parameter_size_[i] << " bytes" << GGendl;
621  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Mem. Base Addr. Align.: " << device_mem_base_addr_align_[i] << " bytes" << GGendl;
622  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Max Work Group Size: " << device_max_work_group_size_[i] << GGendl;
623  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Max Work Item Dimensions: " << device_max_work_item_dimensions_[i] << GGendl;
624  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Max Work Item Sizes: " << device_max_work_item_sizes_[0+i*3] << " " << device_max_work_item_sizes_[1+i*3] << " " << device_max_work_item_sizes_[2+i*3] << GGendl;
625  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Printf Buffer Size: " << device_printf_buffer_size_[i] << " bytes" << GGendl;
626  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Max Samplers: " << device_max_samplers_[i] << GGendl;
627  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Partition Max Sub-Devices: " << device_partition_max_sub_devices_[i] << GGendl;
628  std::string partition_affinity("");
629  partition_affinity += device_single_fp_config_[i] & CL_DEVICE_AFFINITY_DOMAIN_NUMA ? "NUMA " : "";
630  partition_affinity += device_single_fp_config_[i] & CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE ? "L4_CACHE " : "";
631  partition_affinity += device_single_fp_config_[i] & CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE ? "L3_CACHE " : "";
632  partition_affinity += device_single_fp_config_[i] & CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE ? "L2_CACHE " : "";
633  partition_affinity += device_single_fp_config_[i] & CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE ? "L1_CACHE " : "";
634  partition_affinity += device_single_fp_config_[i] & CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE ? "NEXT_PARTITIONABLE " : "";
635  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Partition Affinity: " << partition_affinity << GGendl;
636  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + Timer Resolution: " << device_profiling_timer_resolution_[i] << " ns" << GGendl;
637  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << " + GGEMS Custom Work Group Size: " << work_group_size_ << GGendl;
638  }
639  GGcout("GGEMSOpenCLManager", "PrintDeviceInfos", 0) << GGendl;
640 }
641 
645 
647 {
648  GGcout("GGEMSOpenCLManager", "PrintBuildOptions", 0) << "OpenCL building options: " << build_options_ << GGendl;
649 }
650 
654 
656 {
657  // Checking if activated context
658  GGcout("GGEMSOpenCLManager", "PrintActivatedDevices", 3) << "Printing activated devices for GGEMS..." << GGendl;
659 
660  GGcout("GGEMSOpenCLManager", "PrintActivatedDevices", 0) << GGendl;
661  GGcout("GGEMSOpenCLManager", "PrintActivatedDevices", 0) << "ACTIVATED DEVICES:" << GGendl;
662  GGcout("GGEMSOpenCLManager", "PrintActivatedDevices", 0) << "------------------" << GGendl;
663 
664  // Loop over activated devices
665  for (GGsize i = 0; i < device_indices_.size(); ++i) {
666  GGcout("GGEMSOpenCLManager", "PrintActivatedDevices", 0) << GGendl;
667  GGcout("GGEMSOpenCLManager", "PrintActivatedDevices", 0) << "#### DEVICE: " << device_indices_[i] << " ####" << GGendl;
668  GGcout("GGEMSOpenCLManager", "PrintActivatedDevices", 0) << " -> Name: " << GetDeviceName(device_indices_[i]) << " ####" << GGendl;
669  if (GetDeviceType(device_indices_[i]) == CL_DEVICE_TYPE_CPU)
670  GGcout("GGEMSOpenCLManager", "PrintActivatedDevices", 0) << " -> Type: CL_DEVICE_TYPE_CPU " << GGendl;
671  else if (GetDeviceType(device_indices_[i]) == CL_DEVICE_TYPE_GPU)
672  GGcout("GGEMSOpenCLManager", "PrintActivatedDevices", 0) << " -> Type: CL_DEVICE_TYPE_GPU " << GGendl;
673  }
674 
675  GGcout("GGEMSOpenCLManager", "PrintActivatedDevice", 0) << GGendl;
676 }
677 
681 
682 void GGEMSOpenCLManager::DeviceToActivate(std::string const& device_type, std::string const& device_vendor)
683 {
684  // Transform all parameters in lower caracters
685  std::string type = device_type;
686  std::string vendor = device_vendor;
687  std::transform(type.begin(), type.end(), type.begin(), ::tolower);
688  std::transform(vendor.begin(), vendor.end(), vendor.begin(), ::tolower);
689 
690  // Checking if there is a number in type
691  bool is_index_device = false;
692  for (GGsize i = 0; i < type.size(); ++i) {
693  if (isdigit(type[i]) != 0) {
694  is_index_device = true;
695  break;
696  }
697  }
698 
699  // Analyze all cases
700  if (type == "all") { // Activating all available OpenCL devices
701  for (GGsize i = 0; i < devices_.size(); ++i) DeviceToActivate(i);
702  }
703  else if (type == "cpu") { // Activating all CPU devices
704  for (GGsize i = 0; i < devices_.size(); ++i) {
705  if (device_type_[i] == CL_DEVICE_TYPE_CPU) DeviceToActivate(i);
706  }
707  }
708  else if (type == "gpu") { // Activating all GPU devices or GPU by vendor name
709  for (GGsize i = 0; i < devices_.size(); ++i) {
710  if (device_type_[i] == CL_DEVICE_TYPE_GPU) {
711  if (vendor.empty()) DeviceToActivate(i); // If vendor not specified, take all the GPUs
712  else if (device_vendor_[i].find(vendors_[vendor]) != std::string::npos) DeviceToActivate(i); // Specify a vendor
713  }
714  }
715  }
716  else if (is_index_device) { // Activating device using index of device
717  GGsize pos = 0;
718  GGsize index = 0;
719  std::string delimiter = ";";
720  while ((pos = type.find(delimiter)) != std::string::npos) {
721  index = static_cast<GGsize>(std::stoi(type.substr(0, pos)));
722  DeviceToActivate(index);
723  type.erase(0, pos + delimiter.length());
724  }
725  index = static_cast<GGsize>(std::stoi(type));
726  DeviceToActivate(index);
727  }
728  else {
729  std::ostringstream oss(std::ostringstream::out);
730  oss << "Unknown type of device '"<< type << "' !!!";
731  GGEMSMisc::ThrowException("GGEMSOpenCLManager", "DeviceToActivate", oss.str());
732  }
733 }
734 
738 
740 {
741  GGcout("GGEMSOpenCLManager", "DeviceToActivate", 3) << "Activating a device for GGEMS..." << GGendl;
742 
743  // Checking range of the index
744  if (device_id >= devices_.size()) {
745  std::ostringstream oss(std::ostringstream::out);
746  oss << "Your device index is out of range!!! " << devices_.size() << " device(s) detected. Index must be in the range [" << 0 << ";" << devices_.size() - 1 << "]!!!";
747  GGEMSMisc::ThrowException("GGEMSOpenCLManager", "DeviceToActivate", oss.str());
748  }
749 
750  // Checking if OpenCL device is CPU or GPU
751  if (GetDeviceType(device_id) != CL_DEVICE_TYPE_CPU && GetDeviceType(device_id) != CL_DEVICE_TYPE_GPU) {
752  std::ostringstream oss(std::ostringstream::out);
753  oss << "Your device is not a GPU or CPU, please activate another device!!!";
754  GGEMSMisc::ThrowException("GGEMSOpenCLManager", "DeviceToActivate", oss.str());
755  }
756 
757  // Checking if device already activated
758  if (std::find(device_indices_.begin(), device_indices_.end(), device_id) != device_indices_.end()) return;
759 
760  // Storing index of activated device
761  device_indices_.push_back(device_id);
762 
763  // Checking double precision for dosimetry
764  #ifdef DOSIMETRY_DOUBLE_PRECISION
765  if (!IsDoublePrecision(device_id)) {
766  std::ostringstream oss(std::ostringstream::out);
767  oss << "Your OpenCL device '" << GetDeviceName(device_id) << "' does not support double precision!!! Please recompile GGEMS setting DOSIMETRY_DOUBLE_PRECISION to OFF.";
768  GGEMSMisc::ThrowException("GGEMSOpenCLManager", "ContextToActivate", oss.str());
769  }
770  #endif
771 
772  // Printing name of activated device
773  GGcout("GGEMSOpenCLManager", "DeviceToActivate", 2) << "Activated device: " << GetDeviceName(device_id) << GGendl;
774 
775  // Creating context, command queue and event
776  contexts_.push_back(new cl::Context(*devices_.at(device_id)));
777  queues_.push_back(new cl::CommandQueue(*contexts_.back(), *devices_.at(device_id), CL_QUEUE_PROFILING_ENABLE));
778  events_.push_back(new cl::Event());
779 }
780 
784 
785 void GGEMSOpenCLManager::DeviceBalancing(std::string const& device_balancing)
786 {
787  std::string tmp_device_load = device_balancing;
788  GGsize pos = 0;
789  GGfloat balancing = 0;
790  std::string delimiter = ";";
791  GGsize i = 0;
792  GGfloat incr_balancing = 0.0f;
793  while ((pos = tmp_device_load.find(delimiter)) != std::string::npos) {
794  balancing = std::stof(tmp_device_load.substr(0, pos));
795  device_balancing_.push_back(balancing);
796  incr_balancing += balancing;
797  tmp_device_load.erase(0, pos + delimiter.length());
798  ++i;
799  }
800  balancing = std::stof(tmp_device_load.substr(0, pos));
801  incr_balancing += balancing;
802  device_balancing_.push_back(balancing);
803 
804  // Checking sum of balancing = 1;
805  if (incr_balancing != 1.0f) {
806  std::ostringstream oss(std::ostringstream::out);
807  oss << "Device balancing has to be 1 !!! Please change your value. Current value is " << incr_balancing;
808  GGEMSMisc::ThrowException("GGEMSOpenCLManager", "DeviceBalancing", oss.str());
809  }
810 
811  // Checking number of device balancing value
812  if (device_balancing_.size() != device_indices_.size()) {
813  std::ostringstream oss(std::ostringstream::out);
814  oss << "Mismatch between number of device balancing values and number of activated devices!!!";
815  GGEMSMisc::ThrowException("GGEMSOpenCLManager", "DeviceBalancing", oss.str());
816  }
817 
818  // Printing device balancing
819  for (GGsize i = 0; i < device_balancing_.size(); ++i) {
820  GGcout("GGEMSOpenCLManager", "DeviceBalancing", 0) << "Balance on device " << GetDeviceName(device_indices_[i]) << ": " << device_balancing_[i]*100.0f << "%" << GGendl;
821  }
822 }
823 
827 
828 GGsize GGEMSOpenCLManager::CheckKernel(std::string const& kernel_name, std::string const& compilation_options) const
829 {
830  GGcout("GGEMSOpenCLManager","CheckKernel", 3) << "Checking if kernel has already been compiled..." << GGendl;
831 
832  // Parameters for kernel infos
833  std::string registered_kernel_name("");
834 
835  // Loop over registered kernels
836  for (GGsize i = 0; i < kernels_.size(); ++i) {
837  CheckOpenCLError(kernels_.at(i)->getInfo(CL_KERNEL_FUNCTION_NAME, &registered_kernel_name), "GGEMSOpenCLManager", "CheckKernel");
838  registered_kernel_name.erase(registered_kernel_name.end()-1); // Remove '\0' char from previous function
839  if (kernel_name == registered_kernel_name && compilation_options == kernel_compilation_options_.at(i)) return i;
840  }
841 
842  return KERNEL_NOT_COMPILED;
843 }
844 
848 
849 void GGEMSOpenCLManager::CompileKernel(std::string const& kernel_filename, std::string const& kernel_name, cl::Kernel** kernel_list, char* const p_custom_options, char* const p_additional_options)
850 {
851  GGcout("GGEMSOpenCLManager","CompileKernel", 3) << "Compiling a kernel on OpenCL activated context..." << GGendl;
852 
853  // Checking the compilation options
854  if (p_custom_options && p_additional_options) {
855  std::ostringstream oss(std::ostringstream::out);
856  oss << "Custom and additional options can not by set in same time!!!";
857  GGEMSMisc::ThrowException("GGEMSOpenCLManager", "CompileKernel", oss.str());
858  }
859 
860  // Handling options to OpenCL compilation kernel
861  char kernel_compilation_option[1024];
862  if (p_custom_options) {
863  #if defined _MSC_VER
864  ::strcpy_s(kernel_compilation_option, p_custom_options);
865  #else
866  ::strcpy(kernel_compilation_option, p_custom_options);
867  #endif
868  }
869  else if (p_additional_options) {
870  #if defined _MSC_VER
871  ::strcpy_s(kernel_compilation_option, build_options_.c_str());
872  ::strcat_s(kernel_compilation_option, " ");
873  ::strcat_s(kernel_compilation_option, p_additional_options);
874  #else
875  ::strcpy(kernel_compilation_option, build_options_.c_str());
876  ::strcat(kernel_compilation_option, " ");
877  ::strcat(kernel_compilation_option, p_additional_options);
878  #endif
879  }
880  else {
881  #if defined _MSC_VER
882  ::strcpy_s(kernel_compilation_option, build_options_.c_str());
883  #else
884  ::strcpy(kernel_compilation_option, build_options_.c_str());
885  #endif
886  }
887 
888  // Checking if kernel already compiled
889  GGsize kernel_index = CheckKernel(kernel_name, kernel_compilation_option);
890 
891  // if kernel already compiled return it
892  if (kernel_index != KERNEL_NOT_COMPILED) {
893  for (GGsize i = 0; i < device_indices_.size(); ++i) {
894  kernel_list[i] = kernels_[kernel_index+i];
895  }
896  }
897  else {
898  // Check if the source kernel file exists
899  std::ifstream source_file_stream(kernel_filename.c_str(), std::ios::in);
900  GGEMSFileStream::CheckInputStream(source_file_stream, kernel_filename);
901 
902  // Store kernel in a std::string buffer
903  std::string source_code(std::istreambuf_iterator<char>(source_file_stream), (std::istreambuf_iterator<char>()));
904 
905  // Creating an OpenCL program
906  cl::Program::Sources program_source(1, std::make_pair(source_code.c_str(), source_code.length() + 1));
907 
908  // Loop over activated device
909  for (GGsize i = 0; i < device_indices_.size(); ++i) {
910  // Make program from source code in context
911  cl::Program program = cl::Program(*contexts_[i], program_source);
912 
913  // Get device associated to context, in our case 1 context = 1 device
914  std::vector<cl::Device> device;
915  CheckOpenCLError(contexts_[i]->getInfo(CL_CONTEXT_DEVICES, &device), "GGEMSOpenCLManager", "CompileKernel");
916 
917  GGcout("GGEMSOpenCLManager", "CompileKernel", 2) << "Compile a new kernel '" << kernel_name << "' from file: " << kernel_filename << " on device: " << GetDeviceName(device_indices_[i]) << " with options: " << kernel_compilation_option << GGendl;
918 
919  // Compile source code on device
920  GGint build_status = program.build(device, kernel_compilation_option);
921  if (build_status != CL_SUCCESS) {
922  std::ostringstream oss(std::ostringstream::out);
923  std::string log;
924  program.getBuildInfo(device[0], CL_PROGRAM_BUILD_LOG, &log);
925  oss << ErrorType(build_status) << std::endl;
926  oss << log;
927  GGEMSMisc::ThrowException("GGEMSOpenCLManager", "CompileKernel", oss.str());
928  }
929 
930  // Storing the kernel in the singleton
931  kernels_.push_back(new cl::Kernel(program, kernel_name.c_str(), &build_status));
932  kernel_list[i] = kernels_.back();
933  CheckOpenCLError(build_status, "GGEMSOpenCLManager", "CompileKernel");
934 
935  // Storing the compilation options
936  kernel_compilation_options_.push_back(kernel_compilation_option);
937  }
938  }
939 }
940 
944 
945 cl::Buffer* GGEMSOpenCLManager::Allocate(void* host_ptr, GGsize const& size, GGsize const& thread_index, cl_mem_flags flags, std::string const& class_name)
946 {
947  GGcout("GGEMSOpenCLManager","Allocate", 3) << "Allocating memory on OpenCL device memory..." << GGendl;
948 
949  // Get the RAM manager and check memory
951 
952  // Get index of the device
953  GGsize device_index = GetIndexOfActivatedDevice(thread_index);
954 
955  // Check if buffer size depending on device parameters
956  if (!ram_manager.IsBufferSizeCorrect(device_index, size)) {
957  std::ostringstream oss(std::ostringstream::out);
958  oss << "Size of buffer: " << size << " bytes, is too big!!! The maximum size is " << GetMaxBufferAllocationSize(device_index) << " bytes";
959  GGEMSMisc::ThrowException("GGEMSOpenCLManager", "Allocate", oss.str());
960  }
961 
962  // Check if enough space on device
963  if (!ram_manager.IsEnoughAvailableRAMMemory(device_index, size)) {
964  GGEMSMisc::ThrowException("GGEMSOpenCLManager", "Allocate", "Not enough RAM memory for buffer allocation!!!");
965  }
966 
967  GGint error = 0;
968  cl::Buffer* buffer = new cl::Buffer(*contexts_[thread_index], flags, size, host_ptr, &error);
969  CheckOpenCLError(error, "GGEMSOpenCLManager", "Allocate");
970 
971  // Increment RAM memory
972  ram_manager.IncrementRAMMemory(class_name, thread_index, size);
973 
974  return buffer;
975 }
976 
980 
981 void GGEMSOpenCLManager::Deallocate(cl::Buffer* buffer, GGsize size, GGsize const& thread_index, std::string const& class_name)
982 {
983  GGcout("GGEMSOpenCLManager","Deallocate", 3) << "Deallocating memory on OpenCL device memory..." << GGendl;
984 
985  // Get the RAM manager and check memory
987 
988  // Decrement RAM memory
989  ram_manager.DecrementRAMMemory(class_name, thread_index, size);
990 
991  delete buffer;
992 }
993 
997 
998 void GGEMSOpenCLManager::CleanBuffer(cl::Buffer* buffer, GGsize const& size, GGsize const& thread_index)
999 {
1000  GGcout("GGEMSOpenCLManager","CleanBuffer", 3) << "Cleaning OpenCL buffer..." << GGendl;
1001 
1002  GGint error = queues_[thread_index]->enqueueFillBuffer(*buffer, 0, 0, size, nullptr, nullptr);
1003  CheckOpenCLError(error, "GGEMSOpenCLManager", "CleanBuffer");
1004 }
1005 
1009 
1010 bool GGEMSOpenCLManager::IsDoublePrecision(GGsize const& device_index) const
1011 {
1012  if (device_extensions_[device_index].find("cl_khr_fp64") == std::string::npos) return false;
1013  else return true;
1014 }
1015 
1019 
1021 {
1022  if (device_extensions_[device_index].find("cl_khr_int64_base_atomics") == std::string::npos) return false;
1023  else return true;
1024 }
1025 
1029 
1030 GGsize GGEMSOpenCLManager::GetBestWorkItem(GGsize const& number_of_elements) const
1031 {
1032  if (number_of_elements%work_group_size_ == 0) {
1033  return number_of_elements;
1034  }
1035  else if (number_of_elements <= work_group_size_) {
1036  return work_group_size_;
1037  }
1038  else {
1039  return number_of_elements + (work_group_size_ - number_of_elements%work_group_size_);
1040  }
1041  return 0;
1042 }
1043 
1047 
1048 void GGEMSOpenCLManager::CheckOpenCLError(GGint const& error, std::string const& class_name, std::string const& method_name) const
1049 {
1050  if (error != CL_SUCCESS) {
1051  GGEMSMisc::ThrowException(class_name, method_name, ErrorType(error));
1052  }
1053 }
1054 
1058 
1059 std::string GGEMSOpenCLManager::ErrorType(GGint const& error) const
1060 {
1061  // Error description storing in a ostringstream
1062  std::ostringstream oss(std::ostringstream::out);
1063  oss << std::endl;
1064 
1065  // Case 0 -> -19: Run-time and JIT Compiler Errors (driver-dependent)
1066  // Case -30 -> -70: Compile-time Errors (driver-dependent)
1067  // Case -1000 -> -1009: Errors thrown by extensions
1068  // Case -9999: Errors thrown by Vendors
1069  switch (error) {
1070  case -1: {
1071  oss << "CL_DEVICE_NOT_FOUND:" << std::endl;
1072  oss << " * if no OpenCL devices that matched device_type were found." << std::endl;
1073  return oss.str();
1074  }
1075  case -2: {
1076  oss << "CL_DEVICE_NOT_AVAILABLE:" << std::endl;
1077  oss << " * if a device in devices is currently not available even though the device was returned by clGetDeviceIDs." << std::endl;
1078  return oss.str();
1079  }
1080  case -3: {
1081  oss << "CL_COMPILER_NOT_AVAILABLE:" << std::endl;
1082  oss << " * if program is created with clCreateProgramWithSource and a compiler is not available i.e. CL_DEVICE_COMPILER_AVAILABLE specified in the table of OpenCL Device Queries for clGetDeviceInfo is set to CL_FALSE." << std::endl;
1083  return oss.str();
1084  }
1085  case -4: {
1086  oss << "CL_MEM_OBJECT_ALLOCATION_FAILURE:" << std::endl;
1087  oss << " * if there is a failure to allocate memory for buffer object." << std::endl;
1088  return oss.str();
1089  }
1090  case -5: {
1091  oss << "CL_OUT_OF_RESOURCES:" << std::endl;
1092  oss << " * if there is a failure to allocate resources required by the OpenCL implementation on the device." << std::endl;
1093  return oss.str();
1094  }
1095  case -6: {
1096  oss << "CL_OUT_OF_HOST_MEMORY:" << std::endl;
1097  oss << " * if there is a failure to allocate resources required by the OpenCL implementation on the host." << std::endl;
1098  return oss.str();
1099  }
1100  case -7: {
1101  oss << "CL_PROFILING_INFO_NOT_AVAILABLE:" << std::endl;
1102  oss << " * if the CL_QUEUE_PROFILING_ENABLE flag is not set for the command-queue, if the execution status of the command identified by event is not CL_COMPLETE or if event is a user event object." << std::endl;
1103  return oss.str();
1104  }
1105  case -8: {
1106  oss << "CL_MEM_COPY_OVERLAP:" << std::endl;
1107  oss << " * if src_buffer and dst_buffer are the same buffer or subbuffer object and the source and destination regions overlap or if src_buffer and dst_buffer are different sub-buffers of the same associated buffer object and they overlap. The regions overlap if src_offset <= to dst_offset <= to src_offset + size – 1, or if dst_offset <= to src_offset <= to dst_offset + size – 1." << std::endl;
1108  return oss.str();
1109  }
1110  case -9: {
1111  oss << "CL_IMAGE_FORMAT_MISMATCH:" << std::endl;
1112  oss << " * if src_image and dst_image do not use the same image format." << std::endl;
1113  return oss.str();
1114  }
1115  case -10: {
1116  oss << "CL_IMAGE_FORMAT_NOT_SUPPORTED:" << std::endl;
1117  oss << " * if the image_format is not supported." << std::endl;
1118  return oss.str();
1119  }
1120  case -11: {
1121  oss << "CL_BUILD_PROGRAM_FAILURE:" << std::endl;
1122  oss << " * if there is a failure to build the program executable. This error will be returned if clBuildProgram does not return until the build has completed." << std::endl;
1123  return oss.str();
1124  }
1125  case -12: {
1126  oss << "CL_MAP_FAILURE:" << std::endl;
1127  oss << " * if there is a failure to map the requested region into the host address space. This error cannot occur for image objects created with CL_MEM_USE_HOST_PTR or CL_MEM_ALLOC_HOST_PTR." << std::endl;
1128  return oss.str();
1129  }
1130  case -13: {
1131  oss << "CL_MISALIGNED_SUB_BUFFER_OFFSET:" << std::endl;
1132  oss << " * if a sub-buffer object is specified as the value for an argument that is a buffer object and the offset specified when the sub-buffer object is created is not aligned to CL_DEVICE_MEM_BASE_ADDR_ALIGN value for device associated with queue." << std::endl;
1133  return oss.str();
1134  }
1135  case -14: {
1136  oss << "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST:" << std::endl;
1137  oss << " * if the execution status of any of the events in event_list is a negative integer value." << std::endl;
1138  return oss.str();
1139  }
1140  case -15: {
1141  oss << "CL_COMPILE_PROGRAM_FAILURE:" << std::endl;
1142  oss << " * if there is a failure to compile the program source. This error will be returned if clCompileProgram does not return until the compile has completed." << std::endl;
1143  return oss.str();
1144  }
1145  case -16: {
1146  oss << "CL_LINKER_NOT_AVAILABLE:" << std::endl;
1147  oss << " * if a linker is not available i.e. CL_DEVICE_LINKER_AVAILABLE specified in the table of allowed values for param_name for clGetDeviceInfo is set to CL_FALSE." << std::endl;
1148  return oss.str();
1149  }
1150  case -17: {
1151  oss << "CL_LINK_PROGRAM_FAILURE:" << std::endl;
1152  oss << " * if there is a failure to link the compiled binaries and/or libraries." << std::endl;
1153  return oss.str();
1154  }
1155  case -18: {
1156  oss << "CL_DEVICE_PARTITION_FAILED:" << std::endl;
1157  oss << " * if the partition name is supported by the implementation but in_device could not be further partitioned." << std::endl;
1158  return oss.str();
1159  }
1160  case -19: {
1161  oss << "CL_KERNEL_ARG_INFO_NOT_AVAILABLE:" << std::endl;
1162  oss << " * if the argument information is not available for kernel." << std::endl;
1163  return oss.str();
1164  }
1165  case -30: {
1166  oss << "CL_INVALID_VALUE:" << std::endl;
1167  oss << " * This depends on the function: two or more coupled parameters had errors." << std::endl;
1168  return oss.str();
1169  }
1170  case -31: {
1171  oss << "CL_INVALID_DEVICE_TYPE:" << std::endl;
1172  oss << " * if an invalid device_type is given" << std::endl;
1173  return oss.str();
1174  }
1175  case -32: {
1176  oss << "CL_INVALID_PLATFORM:" << std::endl;
1177  oss << " * if an invalid platform was given" << std::endl;
1178  return oss.str();
1179  }
1180  case -33: {
1181  oss << "CL_INVALID_DEVICE:" << std::endl;
1182  oss << " * if devices contains an invalid device or are not associated with the specified platform." << std::endl;
1183  return oss.str();
1184  }
1185  case -34: {
1186  oss << "CL_INVALID_CONTEXT:" << std::endl;
1187  oss << " * if context is not a valid context." << std::endl;
1188  return oss.str();
1189  }
1190  case -35: {
1191  oss << "CL_INVALID_QUEUE_PROPERTIES:" << std::endl;
1192  oss << " * if specified command-queue-properties are valid but are not supported by the device." << std::endl;
1193  return oss.str();
1194  }
1195  case -36: {
1196  oss << "CL_INVALID_COMMAND_QUEUE:" << std::endl;
1197  oss << " * if command_queue is not a valid command-queue." << std::endl;
1198  return oss.str();
1199  }
1200  case -37: {
1201  oss << "CL_INVALID_HOST_PTR:" << std::endl;
1202  oss << " * This flag is valid only if host_ptr is not NULL. If specified, it indicates that the application wants the OpenCL implementation to allocate memory for the memory object and copy the data from memory referenced by host_ptr.CL_MEM_COPY_HOST_PTR and CL_MEM_USE_HOST_PTR are mutually exclusive.CL_MEM_COPY_HOST_PTR can be used with CL_MEM_ALLOC_HOST_PTR to initialize the contents of the cl_mem object allocated using host-accessible (e.g. PCIe) memory." << std::endl;
1203  return oss.str();
1204  }
1205  case -38: {
1206  oss << "CL_INVALID_MEM_OBJECT:" << std::endl;
1207  oss << " * if memobj is not a valid OpenCL memory object." << std::endl;
1208  return oss.str();
1209  }
1210  case -39: {
1211  oss << "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR:" << std::endl;
1212  oss << " * if the OpenGL/DirectX texture internal format does not map to a supported OpenCL image format." << std::endl;
1213  return oss.str();
1214  }
1215  case -40: {
1216  oss << "CL_INVALID_IMAGE_SIZE:" << std::endl;
1217  oss << " * if an image object is specified as an argument value and the image dimensions (image width, height, specified or compute row and/or slice pitch) are not supported by device associated with queue." << std::endl;
1218  return oss.str();
1219  }
1220  case -41: {
1221  oss << "CL_INVALID_SAMPLER:" << std::endl;
1222  oss << " * if sampler is not a valid sampler object." << std::endl;
1223  return oss.str();
1224  }
1225  case -42: {
1226  oss << "CL_INVALID_BINARY:" << std::endl;
1227  oss << " * The provided binary is unfit for the selected device.if program is created with clCreateProgramWithBinary and devices listed in device_list do not have a valid program binary loaded." << std::endl;
1228  return oss.str();
1229  }
1230  case -43: {
1231  oss << "CL_INVALID_BUILD_OPTIONS:" << std::endl;
1232  oss << " * if the build options specified by options are invalid." << std::endl;
1233  return oss.str();
1234  }
1235  case -44: {
1236  oss << "CL_INVALID_PROGRAM:" << std::endl;
1237  oss << " * if program is a not a valid program object." << std::endl;
1238  return oss.str();
1239  }
1240  case -45: {
1241  oss << "CL_INVALID_PROGRAM_EXECUTABLE:" << std::endl;
1242  oss << " * if there is no successfully built program executable available for device associated with command_queue." << std::endl;
1243  return oss.str();
1244  }
1245  case -46: {
1246  oss << "CL_INVALID_KERNEL_NAME:" << std::endl;
1247  oss << " * if kernel_name is not found in program." << std::endl;
1248  return oss.str();
1249  }
1250  case -47: {
1251  oss << "CL_INVALID_KERNEL_DEFINITION:" << std::endl;
1252  oss << " * if the function definition for __kernel function given by kernel_name such as the number of arguments, the argument types are not the same for all devices for which the program executable has been built." << std::endl;
1253  return oss.str();
1254  }
1255  case -48: {
1256  oss << "CL_INVALID_KERNEL:" << std::endl;
1257  oss << " * if kernel is not a valid kernel object." << std::endl;
1258  return oss.str();
1259  }
1260  case -49: {
1261  oss << "CL_INVALID_ARG_INDEX:" << std::endl;
1262  oss << " * if arg_index is not a valid argument index." << std::endl;
1263  return oss.str();
1264  }
1265  case -50: {
1266  oss << "CL_INVALID_ARG_VALUE:" << std::endl;
1267  oss << " * if arg_value specified is not a valid value." << std::endl;
1268  return oss.str();
1269  }
1270  case -51: {
1271  oss << "CL_INVALID_ARG_SIZE:" << std::endl;
1272  oss << " * if arg_size does not match the size of the data type for an argument that is not a memory object or if the argument is a memory object and arg_size != sizeof(cl_mem) or if arg_size is zero and the argument is declared with the __local qualifier or if the argument is a sampler and arg_size != sizeof(cl_sampler)." << std::endl;
1273  return oss.str();
1274  }
1275  case -52: {
1276  oss << "CL_INVALID_KERNEL_ARGS:" << std::endl;
1277  oss << " * if the kernel argument values have not been specified." << std::endl;
1278  return oss.str();
1279  }
1280  case -53: {
1281  oss << "CL_INVALID_WORK_DIMENSION:" << std::endl;
1282  oss << " * if work_dim is not a valid value (i.e. a value between 1 and 3)." << std::endl;
1283  return oss.str();
1284  }
1285  case -54: {
1286  oss << "CL_INVALID_WORK_GROUP_SIZE:" << std::endl;
1287  oss << " * if local_work_size is specified and number of work-items specified by global_work_size is not evenly divisable by size of work-group given by local_work_size or does not match the work-group size specified for kernel using the __attribute__((reqd_work_group_size(X, Y, Z))) qualifier in program source.if local_work_size is specified and the total number of work-items in the work-group computed as local_work_size[0] *... local_work_size[work_dim – 1] is greater than the value specified by CL_DEVICE_MAX_WORK_GROUP_SIZE in the table of OpenCL Device Queries for clGetDeviceInfo. if local_work_size is NULL and the __attribute__ ((reqd_work_group_size(X, Y, Z))) qualifier is used to declare the work-group size for kernel in the program source." << std::endl;
1288  return oss.str();
1289  }
1290  case -55: {
1291  oss << "CL_INVALID_WORK_ITEM_SIZE:" << std::endl;
1292  oss << " * if the number of work-items specified in any of local_work_size[0], … local_work_size[work_dim – 1] is greater than the corresponding values specified by CL_DEVICE_MAX_WORK_ITEM_SIZES[0], ... CL_DEVICE_MAX_WORK_ITEM_SIZES[work_dim – 1]" << std::endl;
1293  return oss.str();
1294  }
1295  case -56: {
1296  oss << "CL_INVALID_GLOBAL_OFFSET:" << std::endl;
1297  oss << " * if the value specified in global_work_size + the corresponding values in global_work_offset for any dimensions is greater than the sizeof(size_t) for the device on which the kernel execution will be enqueued." << std::endl;
1298  return oss.str();
1299  }
1300  case -57: {
1301  oss << "CL_INVALID_EVENT_WAIT_LIST:" << std::endl;
1302  oss << " * if event_wait_list is NULL and num_events_in_wait_list > 0, or event_wait_list is not NULL and num_events_in_wait_list is 0, or if event objects in event_wait_list are not valid events." << std::endl;
1303  return oss.str();
1304  }
1305  case -58: {
1306  oss << "CL_INVALID_EVENT:" << std::endl;
1307  oss << " * if event objects specified in event_list are not valid event objects." << std::endl;
1308  return oss.str();
1309  }
1310  case -59: {
1311  oss << "CL_INVALID_OPERATION:" << std::endl;
1312  oss << " * if interoperability is specified by setting CL_CONTEXT_ADAPTER_D3D9_KHR, CL_CONTEXT_ADAPTER_D3D9EX_KHR or CL_CONTEXT_ADAPTER_DXVA_KHR to a non-NULL value, and interoperability with another graphics API is also specified. (only if the cl_khr_dx9_media_sharing extension is supported)." << std::endl;
1313  return oss.str();
1314  }
1315  case -60: {
1316  oss << "CL_INVALID_GL_OBJECT:" << std::endl;
1317  oss << " * if texture is not a GL texture object whose type matches texture_target, if the specified miplevel of texture is not defined, or if the width or height of the specified miplevel is zero." << std::endl;
1318  return oss.str();
1319  }
1320  case -61: {
1321  oss << "CL_INVALID_BUFFER_SIZE:" << std::endl;
1322  oss << " * if size is 0.Implementations may return CL_INVALID_BUFFER_SIZE if size is greater than the CL_DEVICE_MAX_MEM_ALLOC_SIZE value specified in the table of allowed values for param_name for clGetDeviceInfo for all devices in context." << std::endl;
1323  return oss.str();
1324  }
1325  case -62: {
1326  oss << "CL_INVALID_MIP_LEVEL:" << std::endl;
1327  oss << " * if miplevel is greater than zero and the OpenGL implementation does not support creating from non-zero mipmap levels." << std::endl;
1328  return oss.str();
1329  }
1330  case -63: {
1331  oss << "CL_INVALID_GLOBAL_WORK_SIZE:" << std::endl;
1332  oss << " * if global_work_size is NULL, or if any of the values specified in global_work_size[0], ... global_work_size [work_dim – 1] are 0 or exceed the range given by the sizeof(size_t) for the device on which the kernel execution will be enqueued." << std::endl;
1333  return oss.str();
1334  }
1335  case -64: {
1336  oss << "CL_INVALID_PROPERTY:" << std::endl;
1337  oss << " * Vague error, depends on the function" << std::endl;
1338  return oss.str();
1339  }
1340  case -65: {
1341  oss << "CL_INVALID_IMAGE_DESCRIPTOR:" << std::endl;
1342  oss << " * if values specified in image_desc are not valid or if image_desc is NULL." << std::endl;
1343  return oss.str();
1344  }
1345  case -66: {
1346  oss << "CL_INVALID_COMPILER_OPTIONS:" << std::endl;
1347  oss << " * if the compiler options specified by options are invalid." << std::endl;
1348  return oss.str();
1349  }
1350  case -67: {
1351  oss << "CL_INVALID_LINKER_OPTIONS:" << std::endl;
1352  oss << " * if the linker options specified by options are invalid." << std::endl;
1353  return oss.str();
1354  }
1355  case -68: {
1356  oss << "CL_INVALID_DEVICE_PARTITION_COUNT:" << std::endl;
1357  oss << " * if the partition name specified in properties is CL_DEVICE_PARTITION_BY_COUNTS and the number of sub-devices requested exceeds CL_DEVICE_PARTITION_MAX_SUB_DEVICES or the total number of compute units requested exceeds CL_DEVICE_PARTITION_MAX_COMPUTE_UNITS for in_device, or the number of compute units requested for one or more sub-devices is less than zero or the number of sub-devices requested exceeds CL_DEVICE_PARTITION_MAX_COMPUTE_UNITS for in_device." << std::endl;
1358  return oss.str();
1359  }
1360  case -69: {
1361  oss << "CL_INVALID_PIPE_SIZE:" << std::endl;
1362  oss << " * if pipe_packet_size is 0 or the pipe_packet_size exceeds CL_DEVICE_PIPE_MAX_PACKET_SIZE value for all devices in context or if pipe_max_packets is 0." << std::endl;
1363  return oss.str();
1364  }
1365  case -70: {
1366  oss << "CL_INVALID_DEVICE_QUEUE:" << std::endl;
1367  oss << " * when an argument is of type queue_t when it’s not a valid device queue object." << std::endl;
1368  return oss.str();
1369  }
1370  case -1000: {
1371  oss << "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR:" << std::endl;
1372  oss << " * CL and GL not on the same device (only when using a GPU)." << std::endl;
1373  return oss.str();
1374  }
1375  case -1001: {
1376  oss << "CL_PLATFORM_NOT_FOUND_KHR:" << std::endl;
1377  oss << " * No valid ICDs found" << std::endl;
1378  return oss.str();
1379  }
1380  case -1002: {
1381  oss << "CL_INVALID_D3D10_DEVICE_KHR:" << std::endl;
1382  oss << " * if the Direct3D 10 device specified for interoperability is not compatible with the devices against which the context is to be created." << std::endl;
1383  return oss.str();
1384  }
1385  case -1003: {
1386  oss << "CL_INVALID_D3D10_RESOURCE_KHR:" << std::endl;
1387  oss << " * If the resource is not a Direct3D 10 buffer or texture object" << std::endl;
1388  return oss.str();
1389  }
1390  case -1004: {
1391  oss << "CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR:" << std::endl;
1392  oss << " * If a mem_object is already acquired by OpenCL" << std::endl;
1393  return oss.str();
1394  }
1395  case -1005: {
1396  oss << "CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR:" << std::endl;
1397  oss << " * If a mem_object is not acquired by OpenCL" << std::endl;
1398  return oss.str();
1399  }
1400  case -1006: {
1401  oss << "CL_INVALID_D3D11_DEVICE_KHR:" << std::endl;
1402  oss << " * if the Direct3D 11 device specified for interoperability is not compatible with the devices against which the context is to be created." << std::endl;
1403  return oss.str();
1404  }
1405  case -1007: {
1406  oss << "CL_INVALID_D3D11_RESOURCE_KHR:" << std::endl;
1407  oss << " * If the resource is not a Direct3D 11 buffer or texture object" << std::endl;
1408  return oss.str();
1409  }
1410  case -1008: {
1411  oss << "CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR:" << std::endl;
1412  oss << " * If a mem_object is already acquired by OpenCL" << std::endl;
1413  return oss.str();
1414  }
1415  case -1009: {
1416  oss << "CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR:" << std::endl;
1417  oss << " * If a mem_object is not acquired by OpenCL" << std::endl;
1418  return oss.str();
1419  }
1420  case -9999: {
1421  oss << "NVidia:" << std::endl;
1422  oss << " * Illegal read or write to a buffer" << std::endl;
1423  return oss.str();
1424  }
1425  default: {
1426  oss << "Unknown OpenCL error" << std::endl;
1427  return oss.str();
1428  }
1429  }
1430 }
1431 
1435 
1437 {
1439 }
1440 
1444 
1446 {
1447  opencl_manager->PrintPlatformInfos();
1448  opencl_manager->PrintDeviceInfos();
1449  opencl_manager->PrintBuildOptions();
1450  opencl_manager->PrintActivatedDevices();
1451 }
1452 
1456 
1458 {
1459  opencl_manager->DeviceToActivate(device_id);
1460 }
1461 
1465 
1466 void set_device_to_activate_opencl_manager(GGEMSOpenCLManager* opencl_manager, char const* device_type, char const* device_vendor)
1467 {
1468  opencl_manager->DeviceToActivate(device_type, device_vendor);
1469 }
1470 
1474 
1476 {
1477  opencl_manager->Clean();
1478 }
1479 
1483 
1484 void set_device_balancing_opencl_manager(GGEMSOpenCLManager* opencl_manager, char const* device_balancing)
1485 {
1486  opencl_manager->DeviceBalancing(device_balancing);
1487 }
GGEMSSourceManager::GetInstance
static GGEMSSourceManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSSourceManager.hh:67
GGEMSRAMManager.hh
GGEMS class handling RAM memory.
GGEMSOpenCLManager::device_preferred_vector_width_int_
std::vector< GGuint > device_preferred_vector_width_int_
Definition: GGEMSOpenCLManager.hh:413
GGEMSRangeCutsManager.hh
GGEMS class managing the range cuts in GGEMS simulation.
GGEMSNavigatorManager.hh
GGEMS class handling the navigators (detector + phantom) in GGEMS.
GGEMSOpenCLManager::device_partition_affinity_domain_
std::vector< cl_device_affinity_domain > device_partition_affinity_domain_
Definition: GGEMSOpenCLManager.hh:457
GGEMSOpenCLManager::IsDoublePrecision
bool IsDoublePrecision(GGsize const &device_index) const
checking double precision on OpenCL device
Definition: GGEMSOpenCLManager.cc:1010
GGEMSOpenCLManager::device_native_vector_width_char_
std::vector< GGuint > device_native_vector_width_char_
Definition: GGEMSOpenCLManager.hh:404
GGEMSOpenCLManager::IsDoublePrecisionAtomicAddition
bool IsDoublePrecisionAtomicAddition(GGsize const &device_index) const
checking double precision atomic addition on OpenCL device
Definition: GGEMSOpenCLManager.cc:1020
GGEMSOpenCLManager::platform_extensions_
std::vector< std::string > platform_extensions_
Definition: GGEMSOpenCLManager.hh:388
GGEMSSourceManager::Clean
void Clean(void)
clean OpenCL data
Definition: GGEMSSourceManager.cc:69
GGEMSOpenCLManager::device_host_unified_memory_
std::vector< GGbool > device_host_unified_memory_
Definition: GGEMSOpenCLManager.hh:434
GGulong
#define GGulong
Definition: GGEMSTypes.hh:245
GGEMSOpenCLManager::vendors_
VendorUMap vendors_
Definition: GGEMSOpenCLManager.hh:394
GGEMSOpenCLManager::PrintDeviceInfos
void PrintDeviceInfos(void) const
print all informations about devices
Definition: GGEMSOpenCLManager.cc:479
GGEMSOpenCLManager::device_max_samplers_
std::vector< GGuint > device_max_samplers_
Definition: GGEMSOpenCLManager.hh:451
GGEMSVolumeCreatorManager::GetInstance
static GGEMSVolumeCreatorManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSVolumeCreatorManager.hh:67
GGEMSOpenCLManager::device_preferred_vector_width_half_
std::vector< GGuint > device_preferred_vector_width_half_
Definition: GGEMSOpenCLManager.hh:415
GGEMSRangeCutsManager::GetInstance
static GGEMSRangeCutsManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSRangeCutsManager.hh:65
GGEMSProfilerManager::GetInstance
static GGEMSProfilerManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSProfilerManager.hh:66
GGEMSOpenCLManager::DeviceBalancing
void DeviceBalancing(std::string const &device_balancing)
change the device balancing, by default device balancing is the same for each device
Definition: GGEMSOpenCLManager.cc:785
GGEMSRAMManager
GGEMS class handling RAM memory.
Definition: GGEMSRAMManager.hh:51
GGEMSOpenCLManager::devices_
std::vector< cl::Device * > devices_
Definition: GGEMSOpenCLManager.hh:391
print_infos_opencl_manager
void print_infos_opencl_manager(GGEMSOpenCLManager *opencl_manager)
Print information about OpenCL.
Definition: GGEMSOpenCLManager.cc:1445
GGEMSProcessesManager.hh
GGEMS class managing the processes in GGEMS simulation.
GGEMSOpenCLManager::device_max_mem_alloc_size_
std::vector< GGulong > device_max_mem_alloc_size_
Definition: GGEMSOpenCLManager.hh:449
GGEMSOpenCLManager::PrintActivatedDevices
void PrintActivatedDevices(void) const
print infos about activated devices
Definition: GGEMSOpenCLManager.cc:655
GGEMSOpenCLManager::device_preferred_vector_width_char_
std::vector< GGuint > device_preferred_vector_width_char_
Definition: GGEMSOpenCLManager.hh:411
GGEMSOpenCLManager::GetDeviceType
cl_device_type GetDeviceType(GGsize const &device_index) const
Get the type of the activated device.
Definition: GGEMSOpenCLManager.hh:153
GGEMSOpenCLManager::GetMaxBufferAllocationSize
GGsize GetMaxBufferAllocationSize(GGsize const &device_index) const
Get the max buffer size in bytes on activated OpenCL device.
Definition: GGEMSOpenCLManager.hh:183
GGEMSOpenCLManager::device_native_vector_width_float_
std::vector< GGuint > device_native_vector_width_float_
Definition: GGEMSOpenCLManager.hh:409
GGEMSRAMManager::GetInstance
static GGEMSRAMManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSRAMManager.hh:69
GGEMSOpenCLManager::device_image_max_array_size_
std::vector< GGsize > device_image_max_array_size_
Definition: GGEMSOpenCLManager.hh:435
GGEMSOpenCLManager::device_native_vector_width_long_
std::vector< GGuint > device_native_vector_width_long_
Definition: GGEMSOpenCLManager.hh:407
GGEMSOpenCLManager::CheckOpenCLError
void CheckOpenCLError(GGint const &error, std::string const &class_name, std::string const &method_name) const
check the OpenCL error
Definition: GGEMSOpenCLManager.cc:1048
GGEMSOpenCLManager::device_native_vector_width_int_
std::vector< GGuint > device_native_vector_width_int_
Definition: GGEMSOpenCLManager.hh:406
GGEMSRangeCutsManager::Clean
void Clean(void)
clean OpenCL data if necessary
Definition: GGEMSRangeCutsManager.cc:61
GGEMSOpenCLManager::ErrorType
std::string ErrorType(GGint const &error) const
get the error description
Definition: GGEMSOpenCLManager.cc:1059
GGEMSOpenCLManager::~GGEMSOpenCLManager
~GGEMSOpenCLManager(void)
Unable the destructor for the user.
Definition: GGEMSOpenCLManager.cc:340
GGEMSOpenCLManager::PrintPlatformInfos
void PrintPlatformInfos(void) const
print all the informations about the platform
Definition: GGEMSOpenCLManager.cc:461
GGEMSOpenCLManager::GetBestWorkItem
GGsize GetBestWorkItem(GGsize const &number_of_elements) const
get the best number of work item
Definition: GGEMSOpenCLManager.cc:1030
GGEMSOpenCLManager::device_preferred_vector_width_long_
std::vector< GGuint > device_preferred_vector_width_long_
Definition: GGEMSOpenCLManager.hh:414
GGEMSOpenCLManager::device_error_correction_support_
std::vector< GGbool > device_error_correction_support_
Definition: GGEMSOpenCLManager.hh:426
GGEMSOpenCLManager::Deallocate
void Deallocate(cl::Buffer *buffer, GGsize size, GGsize const &thread_index, std::string const &class_name="Undefined")
Deallocation of OpenCL memory.
Definition: GGEMSOpenCLManager.cc:981
GGEMSOpenCLManager::PrintBuildOptions
void PrintBuildOptions(void) const
print global build options used during kernel compilation
Definition: GGEMSOpenCLManager.cc:646
GGEMSOpenCLManager::device_double_fp_config_
std::vector< cl_device_fp_config > device_double_fp_config_
Definition: GGEMSOpenCLManager.hh:423
GGEMSNavigatorManager::Clean
void Clean(void)
clean OpenCL data if necessary
Definition: GGEMSNavigatorManager.cc:69
GGEMSOpenCLManager::device_max_work_item_dimensions_
std::vector< GGuint > device_max_work_item_dimensions_
Definition: GGEMSOpenCLManager.hh:453
GGEMSOpenCLManager::device_profile_
std::vector< std::string > device_profile_
Definition: GGEMSOpenCLManager.hh:400
GGEMSOpenCLManager::device_address_bits_
std::vector< GGuint > device_address_bits_
Definition: GGEMSOpenCLManager.hh:418
GGEMSOpenCLManager::device_max_constant_buffer_size_
std::vector< GGulong > device_max_constant_buffer_size_
Definition: GGEMSOpenCLManager.hh:448
GGEMSOpenCLManager::device_compiler_available_
std::vector< GGbool > device_compiler_available_
Definition: GGEMSOpenCLManager.hh:420
GGEMSOpenCLManager::device_single_fp_config_
std::vector< cl_device_fp_config > device_single_fp_config_
Definition: GGEMSOpenCLManager.hh:422
GGEMSNavigatorManager::GetInstance
static GGEMSNavigatorManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSNavigatorManager.hh:60
GGEMSOpenCLManager::device_half_fp_config_
std::vector< cl_device_fp_config > device_half_fp_config_
Definition: GGEMSOpenCLManager.hh:421
GGEMSOpenCLManager::work_group_size_
GGsize work_group_size_
Definition: GGEMSOpenCLManager.hh:393
GGEMSOpenCLManager::device_type_
std::vector< cl_device_type > device_type_
Definition: GGEMSOpenCLManager.hh:396
GGsize
#define GGsize
Definition: GGEMSTypes.hh:252
GGEMSOpenCLManager::device_max_read_image_args_
std::vector< GGuint > device_max_read_image_args_
Definition: GGEMSOpenCLManager.hh:443
GGEMSOpenCLManager::platform_version_
std::vector< std::string > platform_version_
Definition: GGEMSOpenCLManager.hh:385
GGEMSVolumeCreatorManager::Clean
void Clean(void)
clean OpenCL data
Definition: GGEMSVolumeCreatorManager.cc:74
GGEMSOpenCLManager::device_global_mem_size_
std::vector< GGulong > device_global_mem_size_
Definition: GGEMSOpenCLManager.hh:431
GGEMSOpenCLManager::device_native_vector_width_short_
std::vector< GGuint > device_native_vector_width_short_
Definition: GGEMSOpenCLManager.hh:405
GGint
#define GGint
Definition: GGEMSTypes.hh:224
GGEMSOpenCLManager::device_vendor_id_
std::vector< GGuint > device_vendor_id_
Definition: GGEMSOpenCLManager.hh:399
GGEMSOpenCLManager::CleanBuffer
void CleanBuffer(cl::Buffer *buffer, GGsize const &size, GGsize const &thread_index)
Cleaning buffer on OpenCL device.
Definition: GGEMSOpenCLManager.cc:998
GGEMSOpenCLManager::device_opencl_c_version_
std::vector< std::string > device_opencl_c_version_
Definition: GGEMSOpenCLManager.hh:403
GGEMSOpenCLManager::device_vendor_
std::vector< std::string > device_vendor_
Definition: GGEMSOpenCLManager.hh:398
GGEMSOpenCLManager::device_max_compute_units_
std::vector< GGuint > device_max_compute_units_
Definition: GGEMSOpenCLManager.hh:446
set_device_balancing_opencl_manager
void set_device_balancing_opencl_manager(GGEMSOpenCLManager *opencl_manager, char const *device_balancing)
change the device balancing, by default device balancing is the same for each device
Definition: GGEMSOpenCLManager.cc:1484
GGEMSOpenCLManager::device_preferred_vector_width_double_
std::vector< GGuint > device_preferred_vector_width_double_
Definition: GGEMSOpenCLManager.hh:417
GGEMSOpenCLManager::device_printf_buffer_size_
std::vector< GGsize > device_printf_buffer_size_
Definition: GGEMSOpenCLManager.hh:456
GGEMSOpenCLManager::device_max_constant_args_
std::vector< GGuint > device_max_constant_args_
Definition: GGEMSOpenCLManager.hh:447
GGEMSOpenCLManager::device_max_work_item_sizes_
std::vector< GGsize > device_max_work_item_sizes_
Definition: GGEMSOpenCLManager.hh:454
GGEMSOpenCLManager::Allocate
cl::Buffer * Allocate(void *host_ptr, GGsize const &size, GGsize const &thread_index, cl_mem_flags flags, std::string const &class_name="Undefined")
Allocation of OpenCL memory.
Definition: GGEMSOpenCLManager.cc:945
GGEMSOpenCLManager::device_indices_
std::vector< GGsize > device_indices_
Definition: GGEMSOpenCLManager.hh:392
GGEMSOpenCLManager::device_global_mem_cache_size_
std::vector< GGulong > device_global_mem_cache_size_
Definition: GGEMSOpenCLManager.hh:428
GGEMSOpenCLManager::device_image_support_
std::vector< GGbool > device_image_support_
Definition: GGEMSOpenCLManager.hh:437
GGEMSOpenCLManager::queues_
std::vector< cl::CommandQueue * > queues_
Definition: GGEMSOpenCLManager.hh:467
GGEMSVolumeCreatorManager.hh
Singleton class generating voxelized volume from analytical volume.
set_device_index_ggems_opencl_manager
void set_device_index_ggems_opencl_manager(GGEMSOpenCLManager *opencl_manager, GGsize const device_id)
Set the device index to activate.
Definition: GGEMSOpenCLManager.cc:1457
GGEMSOpenCLManager::platform_vendor_
std::vector< std::string > platform_vendor_
Definition: GGEMSOpenCLManager.hh:387
GGEMSOpenCLManager::device_preferred_vector_width_short_
std::vector< GGuint > device_preferred_vector_width_short_
Definition: GGEMSOpenCLManager.hh:412
GGEMSOpenCLManager::device_endian_little_
std::vector< GGbool > device_endian_little_
Definition: GGEMSOpenCLManager.hh:424
GGEMSOpenCLManager::device_max_parameter_size_
std::vector< GGsize > device_max_parameter_size_
Definition: GGEMSOpenCLManager.hh:450
get_instance_ggems_opencl_manager
GGEMSOpenCLManager * get_instance_ggems_opencl_manager(void)
Get the GGEMSOpenCLManager pointer for python user.
Definition: GGEMSOpenCLManager.cc:1436
GGEMSMaterialsDatabaseManager::GetInstance
static GGEMSMaterialsDatabaseManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSMaterialsDatabaseManager.hh:97
GGEMSOpenCLManager::kernels_
std::vector< cl::Kernel * > kernels_
Definition: GGEMSOpenCLManager.hh:471
GGEMSOpenCLManager::CompileKernel
void CompileKernel(std::string const &kernel_filename, std::string const &kernel_name, cl::Kernel **kernel_list, char *const custom_options=nullptr, char *const additional_options=nullptr)
Compile the OpenCL kernel on the activated device.
Definition: GGEMSOpenCLManager.cc:849
GGEMSOpenCLManager::device_native_vector_width_half_
std::vector< GGuint > device_native_vector_width_half_
Definition: GGEMSOpenCLManager.hh:408
GGEMSOpenCLManager::device_max_clock_frequency_
std::vector< GGuint > device_max_clock_frequency_
Definition: GGEMSOpenCLManager.hh:445
GGEMSOpenCLManager::Clean
void Clean(void)
clean OpenCL data
Definition: GGEMSOpenCLManager.cc:351
GGEMSOpenCLManager::device_preferred_vector_width_float_
std::vector< GGuint > device_preferred_vector_width_float_
Definition: GGEMSOpenCLManager.hh:416
GGEMSRAMManager::IsEnoughAvailableRAMMemory
bool IsEnoughAvailableRAMMemory(GGsize const &index, GGsize const &size) const
Checking available RAM memory on device.
Definition: GGEMSRAMManager.hh:116
GGEMSOpenCLManager::GGEMSOpenCLManager
GGEMSOpenCLManager(void)
Unable the constructor for the user.
Definition: GGEMSOpenCLManager.cc:44
GGcout
GGEMSStream GGcout
Definition: GGEMSPrint.cc:34
GGEMSOpenCLManager::device_image3D_max_width_
std::vector< GGsize > device_image3D_max_width_
Definition: GGEMSOpenCLManager.hh:440
GGEMSOpenCLManager::device_available_
std::vector< GGbool > device_available_
Definition: GGEMSOpenCLManager.hh:419
GGEMSOpenCLManager::CheckKernel
GGsize CheckKernel(std::string const &kernel_name, std::string const &compilation_options) const
check if a kernel has been already compiled
Definition: GGEMSOpenCLManager.cc:828
GGEMSSourceManager.hh
GGEMS class handling the source(s)
GGEMSOpenCLManager::device_image3D_max_depth_
std::vector< GGsize > device_image3D_max_depth_
Definition: GGEMSOpenCLManager.hh:442
GGEMSOpenCLManager::build_options_
std::string build_options_
Definition: GGEMSOpenCLManager.hh:463
GGEMSOpenCLManager::device_global_mem_cacheline_size_
std::vector< GGuint > device_global_mem_cacheline_size_
Definition: GGEMSOpenCLManager.hh:430
GGEMSOpenCLManager::device_native_vector_width_double_
std::vector< GGuint > device_native_vector_width_double_
Definition: GGEMSOpenCLManager.hh:410
GGEMSMaterialsDatabaseManager::Clean
void Clean(void)
clean OpenCL data
Definition: GGEMSMaterialsDatabaseManager.cc:65
GGEMSProcessesManager::Clean
void Clean(void)
clean OpenCL data if necessary
Definition: GGEMSProcessesManager.hh:171
set_device_to_activate_opencl_manager
void set_device_to_activate_opencl_manager(GGEMSOpenCLManager *opencl_manager, char const *device_type, char const *device_vendor)
Set the device index to activate.
Definition: GGEMSOpenCLManager.cc:1466
GGEMSOpenCLManager::device_profiling_timer_resolution_
std::vector< GGsize > device_profiling_timer_resolution_
Definition: GGEMSOpenCLManager.hh:459
GGEMSOpenCLManager::device_partition_max_sub_devices_
std::vector< GGuint > device_partition_max_sub_devices_
Definition: GGEMSOpenCLManager.hh:458
GGEMSOpenCLManager::platforms_
std::vector< cl::Platform > platforms_
Definition: GGEMSOpenCLManager.hh:382
GGEMSOpenCLManager::device_execution_capabilities_
std::vector< cl_device_exec_capabilities > device_execution_capabilities_
Definition: GGEMSOpenCLManager.hh:427
GGEMSProfilerManager::Clean
void Clean(void)
clean OpenCL data
Definition: GGEMSProfilerManager.cc:64
GGendl
#define GGendl
overload C++ std::endl
Definition: GGEMSPrint.hh:60
GGEMSOpenCLManager::device_image2D_max_width_
std::vector< GGsize > device_image2D_max_width_
Definition: GGEMSOpenCLManager.hh:438
GGEMSOpenCLManager::device_local_mem_size_
std::vector< GGulong > device_local_mem_size_
Definition: GGEMSOpenCLManager.hh:432
GGEMSOpenCLManager
Singleton class storing all informations about OpenCL and managing GPU/CPU devices,...
Definition: GGEMSOpenCLManager.hh:54
GGEMSOpenCLManager::platform_profile_
std::vector< std::string > platform_profile_
Definition: GGEMSOpenCLManager.hh:384
GGEMSOpenCLManager::device_version_
std::vector< std::string > device_version_
Definition: GGEMSOpenCLManager.hh:401
GGEMSFileStream::CheckInputStream
void CheckInputStream(std::ifstream const &input_stream, std::string const &filename)
check the input stream during the opening
Definition: GGEMSTools.cc:42
GGEMSOpenCLManager::contexts_
std::vector< cl::Context * > contexts_
Definition: GGEMSOpenCLManager.hh:466
GGEMSOpenCLManager::device_mem_base_addr_align_
std::vector< GGuint > device_mem_base_addr_align_
Definition: GGEMSOpenCLManager.hh:455
GGEMSRAMManager::DecrementRAMMemory
void DecrementRAMMemory(std::string const &class_name, GGsize const &index, GGsize const &size)
decrement the size of the global allocated buffer
Definition: GGEMSRAMManager.cc:134
GGEMSOpenCLManager::device_driver_version_
std::vector< std::string > device_driver_version_
Definition: GGEMSOpenCLManager.hh:402
GGEMSOpenCLManager::device_global_mem_cache_type_
std::vector< cl_device_mem_cache_type > device_global_mem_cache_type_
Definition: GGEMSOpenCLManager.hh:429
GGEMSOpenCLManager::device_name_
std::vector< std::string > device_name_
Definition: GGEMSOpenCLManager.hh:397
GGEMSOpenCLManager::device_balancing_
std::vector< GGfloat > device_balancing_
Definition: GGEMSOpenCLManager.hh:460
GGEMSRAMManager::Clean
void Clean(void)
clean OpenCL data if necessary
Definition: GGEMSRAMManager.cc:99
GGEMSOpenCLManager::GetDeviceName
std::string GetDeviceName(GGsize const &device_index) const
Get the name of the activated device.
Definition: GGEMSOpenCLManager.hh:145
GGEMSProfilerManager.hh
GGEMS class managing profiler data.
clean_opencl_manager
void clean_opencl_manager(GGEMSOpenCLManager *opencl_manager)
Clean OpenCL manager for python user.
Definition: GGEMSOpenCLManager.cc:1475
GGEMSOpenCLManager::device_image3D_max_height_
std::vector< GGsize > device_image3D_max_height_
Definition: GGEMSOpenCLManager.hh:441
GGEMS.hh
GGEMS class managing the GGEMS simulation.
GGEMSOpenCLManager::events_
std::vector< cl::Event * > events_
Definition: GGEMSOpenCLManager.hh:468
GGEMSOpenCLManager::device_extensions_
std::vector< std::string > device_extensions_
Definition: GGEMSOpenCLManager.hh:425
GGEMSRAMManager::IsBufferSizeCorrect
bool IsBufferSizeCorrect(GGsize const &index, GGsize const &size) const
Check the size of buffer depending on device limit, false if buffer size if too big.
Definition: GGEMSRAMManager.hh:129
GGEMSOpenCLManager::GetIndexOfActivatedDevice
GGsize GetIndexOfActivatedDevice(GGsize const &thread_index) const
get the index of activated device
Definition: GGEMSOpenCLManager.hh:175
GGEMSOpenCLManager::platform_name_
std::vector< std::string > platform_name_
Definition: GGEMSOpenCLManager.hh:386
GGEMSOpenCLManager::device_image_max_buffer_size_
std::vector< GGsize > device_image_max_buffer_size_
Definition: GGEMSOpenCLManager.hh:436
GGuint
#define GGuint
Definition: GGEMSTypes.hh:231
GGEMSOpenCLManager::device_max_work_group_size_
std::vector< GGsize > device_max_work_group_size_
Definition: GGEMSOpenCLManager.hh:452
GGbool
#define GGbool
Definition: GGEMSTypes.hh:194
GGEMSOpenCLManager::kernel_compilation_options_
std::vector< std::string > kernel_compilation_options_
Definition: GGEMSOpenCLManager.hh:472
GGEMSProcessesManager::GetInstance
static GGEMSProcessesManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSProcessesManager.hh:60
KERNEL_NOT_COMPILED
#define KERNEL_NOT_COMPILED
Definition: GGEMSOpenCLManager.hh:47
GGEMSOpenCLManager::device_max_write_image_args_
std::vector< GGuint > device_max_write_image_args_
Definition: GGEMSOpenCLManager.hh:444
GGEMSOpenCLManager::device_image2D_max_height_
std::vector< GGsize > device_image2D_max_height_
Definition: GGEMSOpenCLManager.hh:439
GGEMSMisc::ThrowException
void ThrowException(std::string const &class_name, std::string const &method_name, std::string const &message)
Throw a C++ exception.
Definition: GGEMSTools.cc:61
GGEMSRAMManager::IncrementRAMMemory
void IncrementRAMMemory(std::string const &class_name, GGsize const &index, GGsize const &size)
increment the size of the global allocated buffer
Definition: GGEMSRAMManager.cc:110
GGfloat
#define GGfloat
Definition: GGEMSTypes.hh:273
GGEMSOpenCLManager::GetInstance
static GGEMSOpenCLManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSOpenCLManager.hh:72
GGEMSOpenCLManager::device_local_mem_type_
std::vector< cl_device_local_mem_type > device_local_mem_type_
Definition: GGEMSOpenCLManager.hh:433
GGEMSOpenCLManager::DeviceToActivate
void DeviceToActivate(GGsize const &device_id)
set the index of the device to activate
Definition: GGEMSOpenCLManager.cc:739