ClStatisticalOutlierFilter.cpp
Go to the documentation of this file.
1 
30 
31 namespace lvr2
32 {
33 
34 ClSOR::ClSOR(floatArr& points, size_t num_points, int k, int device) : m_k(k)
35 {
36 // this->init();
37 
38  this->getDeviceInformation(0, device);
39 
40  this->initCl();
41 
42  this->V.dim = 3;
43 
44  this->V.width = static_cast<unsigned int>(num_points);
45 
46  //mallocPointArray(V);
47 
48  this->V.elements = points.get();
49 
50  this->initKdTree();
51 
52 
53 }
54 
56 {
57 // this->finalizeCl();
58  // free(this->V.elements);
59  free(this->m_distances.elements);
60 }
61 
63 {
64  // Allocate Result Memory
65  // Is a plain malloc good enough TODO
66  generatePointArray(this->m_distances, this->V.width, 1);
67 
68 
69  // std::cout << "Allocate GPU Memory" << std::endl;
70  // tree and points and result normals to GPU
71  D_V = clCreateBuffer(m_context, CL_MEM_READ_WRITE,
72  this->V.width * this->V.dim * sizeof(float), NULL, &m_ret);
73  D_kd_tree_values = clCreateBuffer(m_context, CL_MEM_READ_WRITE,
74  this->kd_tree_values->width * this->kd_tree_values->dim * sizeof(float), NULL, &m_ret);
75  D_kd_tree_splits = clCreateBuffer(m_context, CL_MEM_READ_WRITE,
76  this->kd_tree_splits->width * this->kd_tree_splits->dim * sizeof(unsigned char),
77  NULL, &m_ret);
78  D_Distances = clCreateBuffer(m_context, CL_MEM_READ_WRITE,
79  this->V.width * this->V.dim * sizeof(float), NULL, &m_ret);
80 
81  // std::cout << "Copy Points and Kd Tree to Gpu Memory" << std::endl;
82  /* Copy input data to memory buffer */
83  m_ret = clEnqueueWriteBuffer(m_command_queue, D_V, CL_TRUE, 0,
84  this->V.width * this->V.dim * sizeof(float), V.elements, 0, NULL, NULL);
85  m_ret |= clEnqueueWriteBuffer(m_command_queue, D_kd_tree_values, CL_TRUE, 0,
86  this->kd_tree_values->width * this->kd_tree_values->dim * sizeof(float),
87  this->kd_tree_values->elements, 0, NULL, NULL);
88  m_ret |= clEnqueueWriteBuffer(m_command_queue, D_kd_tree_splits, CL_TRUE, 0,
89  this->kd_tree_splits->width * this->kd_tree_splits->dim * sizeof(unsigned char),
90  this->kd_tree_splits->elements, 0, NULL, NULL);
91 
92  if(m_ret != CL_SUCCESS)
93  std::cerr << getErrorString(m_ret) << std::endl;
94 
95  // KNNKernel
96 
97 
98  // unsigned int threadsPerBlock = this->m_threads_per_block;
99  unsigned int warpSize = 32;
100  //unsigned int threadsPerBlock = 16384;
101  unsigned int threadsPerBlock = this->m_threads_per_block;
102  //unsigned int blocksPerGrid = ( (V.width + threadsPerBlock-1) / threadsPerBlock) / warpSize;
103 
104  size_t local_item_size = static_cast<size_t>(warpSize);
105  size_t global_item_size = static_cast<size_t>(threadsPerBlock);
106  //size_t global_group_size = static_cast<size_t>(blocksPerGrid);
107 
108  // std::cout << "Set Kernel Arguments: Normal Estimation" << std::endl;
109 
110  m_ret = clSetKernelArg(m_kernel_sor, 0, sizeof(cl_mem), (void *)&D_V);
111  m_ret |= clSetKernelArg(m_kernel_sor, 1, sizeof(unsigned int), &V.width );
112  m_ret |= clSetKernelArg(m_kernel_sor, 2, sizeof(cl_mem),
113  (void *)&D_kd_tree_values);
114  m_ret |= clSetKernelArg(m_kernel_sor, 3, sizeof(unsigned int),
115  &kd_tree_values->width );
116  m_ret |= clSetKernelArg(m_kernel_sor, 4, sizeof(cl_mem),
117  (void *)&D_kd_tree_splits);
118  m_ret |= clSetKernelArg(m_kernel_sor, 5, sizeof(unsigned int),
119  &kd_tree_splits->width );
120  m_ret |= clSetKernelArg(m_kernel_sor, 6, sizeof(cl_mem), (void *)&D_Distances);
121 // m_ret |= clSetKernelArg(m_kernel_sor, 7, sizeof(unsigned int), &V.width );
122  m_ret |= clSetKernelArg(m_kernel_sor, 7, sizeof(unsigned int), &this->m_k);
123 
124 
125  if(m_ret != CL_SUCCESS)
126  std::cerr << getErrorString(m_ret) << std::endl;
127 
128  // std::cout << "Start Normal Estimation Kernel" << std::endl;
129  // std::cout << "local_item_size: "<< local_item_size << std::endl;
130  //std::cout << "global_item_size: " << global_item_size << std::endl;
131 
132  m_ret = clEnqueueNDRangeKernel(m_command_queue, m_kernel_sor, 1, NULL,
133  &global_item_size, &local_item_size, 0, NULL, NULL);
134 
135 
136  if(m_ret != CL_SUCCESS)
137  std::cerr << getErrorString(m_ret) << std::endl;
138 
139  // Normals back to host
140  m_ret = clEnqueueReadBuffer(m_command_queue, D_Distances, CL_TRUE, 0,
141  this->m_distances.width * this->m_distances.dim * sizeof(float),
142  this->m_distances.elements, 0, NULL, NULL);
143 
144  if(m_ret != CL_SUCCESS)
145  std::cerr << getErrorString(m_ret) << std::endl;
146 
147 }
148 
150 {
151  m_mean_ = 0.0;
152  m_std_dev_ = 0.0;
153 
154  double sum = 0.0;
155  double sq_sum = 0.0;
156  // TODO PARALLELIZE VARIANCE AND MEAN
157  for(int i = 0; i < (this->m_distances.dim * this->m_distances.width); i++)
158  {
159  sum += static_cast<double>(this->m_distances.elements[i]);
160  sq_sum += static_cast<double>(this->m_distances.elements[i]) * static_cast<double>(this->m_distances.elements[i]);
161  }
162  // does this need casts
163  std::cout << "sum " << sum << "sq_sum " << sq_sum << std::endl;
164  m_mean_ = sum/static_cast<double>(m_distances.width);
165  m_std_dev_ = (sq_sum - sum * sum / static_cast<double>(this->m_distances.width)) / static_cast<double>((this->m_distances.width - 1));
166  m_std_dev_ = std::sqrt(m_std_dev_);
167  std::cout << "Mean " << m_mean_ << "dev " << m_std_dev_ << std::endl;
168 }
169 
171 {
172  int j = 0;
173  for(int i = 0; i < (this->m_distances.dim * this->m_distances.width); i++)
174  {
175  if(this->m_distances.elements[i] <= (m_mean_ + m_mult_ * m_std_dev_))
176  {
177  inliers[j] = i;
178  j++;
179  }
180  }
181  return j;
182 }
183 
184 void ClSOR::setK(int k)
185 {
186  this->m_k = k;
187 }
188 
189 
190 
191 
193 {
194 
195 }
196 
198 
199 //void ClSOR::init(){
200 // // set default k
201 // this->m_k = 10;
202 //
203 // // set default ki
204 // this->m_ki = 10;
205 // this->m_kd = 5;
206 //
207 // // set default flippoint
208 // this->m_vx = 1000000.0;
209 // this->m_vy = 1000000.0;
210 // this->m_vz = 1000000.0;
211 //
212 // this->m_calc_method = 0;
213 //
214 // this->m_reconstruction_mode = false;
215 //}
216 
218 
219  kd_tree_gen = boost::shared_ptr<LBKdTree>(new LBKdTree(this->V, OpenMPConfig::getNumThreads() ) );
220  this->kd_tree_values = kd_tree_gen->getKdTreeValues().get();
221  this->kd_tree_splits = kd_tree_gen->getKdTreeSplits().get();
222 
223 }
224 
226 {
227 
228  this->m_context = clCreateContext(NULL, 1, &this->m_device_id, NULL, NULL, &this->m_ret);
229  if(m_ret != CL_SUCCESS)
230  std::cerr << getErrorString(m_ret) << std::endl;
231 
232  this->m_command_queue = clCreateCommandQueue(this->m_context, this->m_device_id, 0, &this->m_ret);
233  if(m_ret != CL_SUCCESS)
234  std::cerr << getErrorString(m_ret) << std::endl;
235 
236  this->loadSORKernel();
237 }
238 
240 {
241  m_ret = clFlush(m_command_queue);
242  m_ret = clFinish(m_command_queue);
243  m_ret = clReleaseKernel(m_kernel_sor);
244 
245  m_ret = clReleaseProgram(m_program_es);
246  m_ret = clReleaseProgram(m_program_in);
247 
248  m_ret = clReleaseMemObject(D_V);
249  m_ret = clReleaseMemObject(D_kd_tree_values);
250  m_ret = clReleaseMemObject(D_kd_tree_splits);
251  m_ret = clReleaseMemObject(D_Distances);
252 
253  m_ret = clReleaseCommandQueue(m_command_queue);
254  m_ret = clReleaseContext(m_context);
255 
256 }
257 
259 {
260  // std::cout << "Loading estimation Kernel ..." << std::endl;
261 
262  // create program
263  m_program_es = clCreateProgramWithSource(m_context, 1,
264  (const char **) &SOR_KERNEL_STRING , NULL, &m_ret);
265  if(m_ret != CL_SUCCESS)
266  {
267  std::cerr << "ClSOR::loadKernel() - Create Program " << getErrorString(m_ret) << std::endl;
268  }
269 
270  if (!m_program_es)
271  {
272  printf("Error: Failed to create compute program!\n");
273  exit(1);
274  }
275 
276  // Build the program executable
277  //
278  m_ret = clBuildProgram(m_program_es, 0, NULL, NULL, NULL, NULL);
279  if (m_ret != CL_SUCCESS)
280  {
281  size_t len;
282  char buffer[2048];
283 
284  printf("Error: Failed to build program executable!\n");
285  clGetProgramBuildInfo(m_program_es, m_device_id, CL_PROGRAM_BUILD_LOG, sizeof(buffer),
286  buffer, &len);
287  printf("%s\n", buffer);
288  exit(1);
289  }
290 
291  // create kernels
292  m_kernel_sor = clCreateKernel(m_program_es, "SORKernel", &m_ret);
293  if(m_ret != CL_SUCCESS)
294  {
295  std::cerr << "ClSOR::loadKernel() - Estimation " << getErrorString(m_ret) << std::endl;
296  exit(1);
297  }
298 
299 }
300 
301 const char *ClSOR::getErrorString(cl_int error)
302 {
303  switch(error){
304  // run-time and JIT compiler errors
305  case 0: return "CL_SUCCESS";
306  case -1: return "CL_DEVICE_NOT_FOUND";
307  case -2: return "CL_DEVICE_NOT_AVAILABLE";
308  case -3: return "CL_COMPILER_NOT_AVAILABLE";
309  case -4: return "CL_MEM_OBJECT_ALLOCATION_FAILURE";
310  case -5: return "CL_OUT_OF_RESOURCES";
311  case -6: return "CL_OUT_OF_HOST_MEMORY";
312  case -7: return "CL_PROFILING_INFO_NOT_AVAILABLE";
313  case -8: return "CL_MEM_COPY_OVERLAP";
314  case -9: return "CL_IMAGE_FORMAT_MISMATCH";
315  case -10: return "CL_IMAGE_FORMAT_NOT_SUPPORTED";
316  case -11: return "CL_BUILD_PROGRAM_FAILURE";
317  case -12: return "CL_MAP_FAILURE";
318  case -13: return "CL_MISALIGNED_SUB_BUFFER_OFFSET";
319  case -14: return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
320  case -15: return "CL_COMPILE_PROGRAM_FAILURE";
321  case -16: return "CL_LINKER_NOT_AVAILABLE";
322  case -17: return "CL_LINK_PROGRAM_FAILURE";
323  case -18: return "CL_DEVICE_PARTITION_FAILED";
324  case -19: return "CL_KERNEL_ARG_INFO_NOT_AVAILABLE";
325 
326  // compile-time errors
327  case -30: return "CL_INVALID_VALUE";
328  case -31: return "CL_INVALID_DEVICE_TYPE";
329  case -32: return "CL_INVALID_PLATFORM";
330  case -33: return "CL_INVALID_DEVICE";
331  case -34: return "CL_INVALID_CONTEXT";
332  case -35: return "CL_INVALID_QUEUE_PROPERTIES";
333  case -36: return "CL_INVALID_COMMAND_QUEUE";
334  case -37: return "CL_INVALID_HOST_PTR";
335  case -38: return "CL_INVALID_MEM_OBJECT";
336  case -39: return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR";
337  case -40: return "CL_INVALID_IMAGE_SIZE";
338  case -41: return "CL_INVALID_SAMPLER";
339  case -42: return "CL_INVALID_BINARY";
340  case -43: return "CL_INVALID_BUILD_OPTIONS";
341  case -44: return "CL_INVALID_PROGRAM";
342  case -45: return "CL_INVALID_PROGRAM_EXECUTABLE";
343  case -46: return "CL_INVALID_KERNEL_NAME";
344  case -47: return "CL_INVALID_KERNEL_DEFINITION";
345  case -48: return "CL_INVALID_KERNEL";
346  case -49: return "CL_INVALID_ARG_INDEX";
347  case -50: return "CL_INVALID_ARG_VALUE";
348  case -51: return "CL_INVALID_ARG_SIZE";
349  case -52: return "CL_INVALID_KERNEL_ARGS";
350  case -53: return "CL_INVALID_WORK_DIMENSION";
351  case -54: return "CL_INVALID_WORK_GROUP_SIZE";
352  case -55: return "CL_INVALID_WORK_ITEM_SIZE";
353  case -56: return "CL_INVALID_GLOBAL_OFFSET";
354  case -57: return "CL_INVALID_EVENT_WAIT_LIST";
355  case -58: return "CL_INVALID_EVENT";
356  case -59: return "CL_INVALID_OPERATION";
357  case -60: return "CL_INVALID_GL_OBJECT";
358  case -61: return "CL_INVALID_BUFFER_SIZE";
359  case -62: return "CL_INVALID_MIP_LEVEL";
360  case -63: return "CL_INVALID_GLOBAL_WORK_SIZE";
361  case -64: return "CL_INVALID_PROPERTY";
362  case -65: return "CL_INVALID_IMAGE_DESCRIPTOR";
363  case -66: return "CL_INVALID_COMPILER_OPTIONS";
364  case -67: return "CL_INVALID_LINKER_OPTIONS";
365  case -68: return "CL_INVALID_DEVICE_PARTITION_COUNT";
366 
367  // extension errors
368  case -1000: return "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR";
369  case -1001: return "CL_PLATFORM_NOT_FOUND_KHR";
370  case -1002: return "CL_INVALID_D3D10_DEVICE_KHR";
371  case -1003: return "CL_INVALID_D3D10_RESOURCE_KHR";
372  case -1004: return "CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR";
373  case -1005: return "CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR";
374  default: return "Unknown OpenCL error";
375  }
376 }
377 
378 
379 void ClSOR::getDeviceInformation(int platform_id, int device_id)
380 {
381 
382  char buffer[1024];
383 
384  cl_uint num_platforms;
385  checkOclErrors(clGetPlatformIDs(0, NULL, &num_platforms));
386 
387  if(platform_id >= num_platforms)
388  {
389  std::cerr << "Wrong platform id " << std::endl;
390  exit(1);
391  }
392 // printf("%d PLATFORMS FOUND\n", num_platforms);
393  cl_platform_id* platforms = (cl_platform_id*)malloc(sizeof(cl_platform_id) * num_platforms);
394  checkOclErrors(clGetPlatformIDs(num_platforms, platforms, NULL));
395 
396  cl_platform_id platform = platforms[platform_id];
397  this->m_platform_id = platform;
398  //printf("CL_PLATFORM: %d\n", k);
399  checkOclErrors(clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(buffer), buffer, NULL));
400  // printf("CL_PLATFORM_NAME: %s\n", buffer);
401  checkOclErrors(clGetPlatformInfo(platform, CL_PLATFORM_VENDOR, sizeof(buffer), buffer, NULL));
402  // printf("CL_PLATFORM_VENDOR: %s\n", buffer);
403  checkOclErrors(clGetPlatformInfo(platform, CL_PLATFORM_VERSION, sizeof(buffer), buffer, NULL));
404  // printf("CL_PLATFORM_VERSION: %s\n", buffer);
405  checkOclErrors(clGetPlatformInfo(platform, CL_PLATFORM_PROFILE, sizeof(buffer), buffer, NULL));
406  // printf("CL_PLATFORM_PROFILE: %s\n", buffer);
407  checkOclErrors(clGetPlatformInfo(platform, CL_PLATFORM_EXTENSIONS, sizeof(buffer), buffer, NULL));
408  // printf("CL_PLATFORM_EXTENSIONS: %s\n", buffer);
409  // printf("\n");
410 
411  cl_uint num_devices;
412  checkOclErrors(clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices));
413 // printf("%d DEVICES FOUND\n", num_devices);
414  if(device_id >= num_devices)
415  {
416  std::cerr << "Wrong device id " << std::endl;
417  exit(1);
418  }
419 
420  cl_device_id* devices = (cl_device_id*)malloc(sizeof(cl_device_id) * num_devices);
421  checkOclErrors(clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, num_devices, devices, NULL));
422 
423  cl_device_id device = devices[device_id];
424  // std::cout << "Device: " << device << std::endl;
425  this->m_device_id = device;
426  // printf("CL_DEVICE: %d\n", j);
427  cl_device_type type;
428  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof(type), &type, NULL));
429  // if (type & CL_DEVICE_TYPE_DEFAULT) printf("CL_DEVICE_TYPE: %s\n", "CL_DEVICE_TYPE_DEFAULT");
430  // if (type & CL_DEVICE_TYPE_CPU) printf("CL_DEVICE_TYPE: %s\n", "CL_DEVICE_TYPE_CPU");
431  // if (type & CL_DEVICE_TYPE_GPU) printf("CL_DEVICE_TYPE: %s\n", "CL_DEVICE_TYPE_GPU");
432  // if (type & CL_DEVICE_TYPE_CUSTOM) printf("CL_DEVICE_TYPE: %s\n", "CL_DEVICE_TYPE_CUSTOM");
433  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(buffer), buffer, NULL));
434  // printf("CL_DEVICE_NAME: %s\n", buffer);
435 
436 
437  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_VENDOR, sizeof(buffer), buffer, NULL));
438  // printf("CL_DEVICE_VENDOR: %s\n", buffer);
439  cl_uint vendor_id;
440  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_VENDOR_ID, sizeof(vendor_id), &vendor_id, NULL));
441  // printf("CL_DEVICE_VENDOR_ID: %d\n", vendor_id);
442  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_VERSION, sizeof(buffer), buffer, NULL));
443  // printf("CL_DEVICE_VERSION: %s\n", buffer);
444  checkOclErrors(clGetDeviceInfo(device, CL_DRIVER_VERSION, sizeof(buffer), buffer, NULL));
445  // printf("CL_DRIVER_VERSION: %s\n", buffer);
446  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_OPENCL_C_VERSION, sizeof(buffer), buffer, NULL));
447  // printf("CL_DEVICE_OPENCL_C_VERSION: %s\n", buffer);
448  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_PROFILE, sizeof(buffer), buffer, NULL));
449  // printf("CL_DEVICE_PROFILE: %s\n", buffer);
450  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, sizeof(buffer), buffer, NULL));
451  // printf("CL_DEVICE_EXTENSIONS: %s\n", buffer);
452  cl_uint max_compute_units;
453  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS,
454  sizeof(max_compute_units), &max_compute_units, NULL));
455  this->m_mps = max_compute_units;
456 
457  // printf("CL_DEVICE_MAX_COMPUTE_UNITS: %u\n", max_compute_units);
458  cl_uint max_work_item_dimensions;
459  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS,
460  sizeof(max_work_item_dimensions), &max_work_item_dimensions, NULL));
461  // printf("CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS: %u\n", max_work_item_dimensions);
462  size_t* max_work_item_sizes = (size_t*)malloc(sizeof(size_t) * max_work_item_dimensions);
463  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_SIZES,
464  sizeof(size_t) * max_work_item_dimensions, max_work_item_sizes, NULL));
465  this->m_threads_per_block = max_work_item_sizes[0];
466  free(max_work_item_sizes);
467  size_t max_work_group_size;
468  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_GROUP_SIZE,
469  sizeof(max_work_group_size), &max_work_group_size, NULL));
470  // printf("CL_DEVICE_MAX_WORK_GROUP_SIZE: %lu\n", max_work_group_size);
471 
472  // ?
473  //this->m_threads_per_block = max_work_group_size;
474 
475 
476  cl_uint preferred_vector_width_char;
477  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR,
478  sizeof(preferred_vector_width_char), &preferred_vector_width_char, NULL));
479  // printf("CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR: %u\n", preferred_vector_width_char);
480  cl_uint preferred_vector_width_short;
481  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT,
482  sizeof(preferred_vector_width_short), &preferred_vector_width_short, NULL));
483  // printf("CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT: %u\n", preferred_vector_width_short);
484  cl_uint preferred_vector_width_int;
485  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT,
486  sizeof(preferred_vector_width_int), &preferred_vector_width_int, NULL));
487  // printf("CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT: %u\n", preferred_vector_width_int);
488  cl_uint preferred_vector_width_long;
489  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG,
490  sizeof(preferred_vector_width_long), &preferred_vector_width_long, NULL));
491  // printf("CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG: %u\n", preferred_vector_width_long);
492  cl_uint preferred_vector_width_float;
493  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT,
494  sizeof(preferred_vector_width_float), &preferred_vector_width_float, NULL));
495  // printf("CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT: %u\n", preferred_vector_width_float);
496  cl_uint preferred_vector_width_double;
497  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE,
498  sizeof(preferred_vector_width_double), &preferred_vector_width_double, NULL));
499  // printf("CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE: %u\n", preferred_vector_width_double);
500  cl_uint preferred_vector_width_half;
501  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF,
502  sizeof(preferred_vector_width_half), &preferred_vector_width_half, NULL));
503  // printf("CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF: %u\n", preferred_vector_width_half);
504  cl_uint native_vector_width_char;
505  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR,
506  sizeof(native_vector_width_char), &native_vector_width_char, NULL));
507  // printf("CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR: %u\n", native_vector_width_char);
508  cl_uint native_vector_width_short;
509  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT,
510  sizeof(native_vector_width_short), &native_vector_width_short, NULL));
511  // printf("CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT: %u\n", native_vector_width_short);
512  cl_uint native_vector_width_int;
513  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT,
514  sizeof(native_vector_width_int), &native_vector_width_int, NULL));
515  // printf("CL_DEVICE_NATIVE_VECTOR_WIDTH_INT: %u\n", native_vector_width_int);
516  cl_uint native_vector_width_long;
517  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG,
518  sizeof(native_vector_width_long), &native_vector_width_long, NULL));
519  // printf("CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG: %u\n", native_vector_width_long);
520  cl_uint native_vector_width_float;
521  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT,
522  sizeof(native_vector_width_float), &native_vector_width_float, NULL));
523  // printf("CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT: %u\n", native_vector_width_float);
524  cl_uint native_vector_width_double;
525  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE,
526  sizeof(native_vector_width_double), &native_vector_width_double, NULL));
527  // printf("CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE: %u\n", native_vector_width_double);
528  cl_uint native_vector_width_half;
529  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF,
530  sizeof(native_vector_width_half), &native_vector_width_half, NULL));
531  // printf("CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF: %u\n", native_vector_width_half);
532  cl_uint max_clock_frequency;
533  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_MAX_CLOCK_FREQUENCY,
534  sizeof(max_clock_frequency), &max_clock_frequency, NULL));
535  // printf("CL_DEVICE_MAX_CLOCK_FREQUENCY: %u MHz\n", max_clock_frequency);
536  cl_uint address_bits;
537  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_ADDRESS_BITS,
538  sizeof(address_bits), &address_bits, NULL));
539  // printf("CL_DEVICE_ADDRESS_BITS: %u\n", address_bits);
540  cl_ulong max_mem_alloc_size;
541  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE,
542  sizeof(max_mem_alloc_size), &max_mem_alloc_size, NULL));
543  cl_bool image_support;
544  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT, sizeof(image_support),
545  &image_support, NULL));
546  // printf("CL_DEVICE_IMAGE_SUPPORT: %u\n", image_support);
547  size_t max_parameter_size;
548  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_MAX_PARAMETER_SIZE,
549  sizeof(max_parameter_size), &max_parameter_size, NULL));
550  // printf("CL_DEVICE_MAX_PARAMETER_SIZE: %lu B\n", max_parameter_size);
551  cl_device_mem_cache_type global_mem_cache_type;
552  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE,
553  sizeof(global_mem_cache_type), &global_mem_cache_type, NULL));
554  cl_uint global_mem_cacheline_size;
555  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE,
556  sizeof(global_mem_cacheline_size), &global_mem_cacheline_size, NULL));
557  cl_ulong global_mem_cache_size;
558  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE,
559  sizeof(global_mem_cache_size), &global_mem_cache_size, NULL));
560  cl_ulong global_mem_size;
561  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_SIZE,
562  sizeof(global_mem_size), &global_mem_size, NULL));
563  this->m_device_global_memory = global_mem_size;
564 
565  cl_ulong max_constant_buffer_size;
566  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE,
567  sizeof(max_constant_buffer_size), &max_constant_buffer_size, NULL));
568  cl_uint max_constant_args;
569  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_MAX_CONSTANT_ARGS, sizeof(max_constant_args),
570  &max_constant_args, NULL));
571  // printf("CL_DEVICE_MAX_CONSTANT_ARGS: %u\n", max_constant_args);
572  cl_device_local_mem_type local_mem_type;
573  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_LOCAL_MEM_TYPE, sizeof(local_mem_type),
574  &local_mem_type, NULL));
575  // if (local_mem_type == CL_NONE) printf("CL_DEVICE_LOCAL_MEM_TYPE: %s\n", "CL_NONE");
576  // if (local_mem_type == CL_LOCAL) printf("CL_DEVICE_LOCAL_MEM_TYPE: %s\n", "CL_LOCAL");
577  // if (local_mem_type == CL_GLOBAL) printf("CL_DEVICE_LOCAL_MEM_TYPE: %s\n", "CL_GLOBAL");
578  cl_ulong local_mem_size;
579  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_LOCAL_MEM_SIZE, sizeof(local_mem_size),
580  &local_mem_size, NULL));
581  // printf("CL_DEVICE_LOCAL_MEM_SIZE: %lu B = %lu KB\n", local_mem_size, local_mem_size / 1024);
582  cl_bool error_correction_support;
583  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_ERROR_CORRECTION_SUPPORT,
584  sizeof(error_correction_support), &error_correction_support, NULL));
585  // printf("CL_DEVICE_ERROR_CORRECTION_SUPPORT: %u\n", error_correction_support);
586  cl_bool host_unified_memory;
587  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_HOST_UNIFIED_MEMORY,
588  sizeof(host_unified_memory), &host_unified_memory, NULL));
589  // printf("CL_DEVICE_HOST_UNIFIED_MEMORY: %u\n", host_unified_memory);
590  size_t profiling_timer_resolution;
591  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_PROFILING_TIMER_RESOLUTION,
592  sizeof(profiling_timer_resolution), &profiling_timer_resolution, NULL));
593  // printf("CL_DEVICE_PROFILING_TIMER_RESOLUTION: %lu ns\n", profiling_timer_resolution);
594  cl_bool endian_little;
595  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_ENDIAN_LITTLE, sizeof(endian_little),
596  &endian_little, NULL));
597  // printf("CL_DEVICE_ENDIAN_LITTLE: %u\n", endian_little);
598  cl_bool available;
599  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_AVAILABLE, sizeof(available), &available, NULL));
600  // printf("CL_DEVICE_AVAILABLE: %u\n", available);
601  cl_bool compier_available;
602  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_COMPILER_AVAILABLE,
603  sizeof(compier_available), &compier_available, NULL));
604  // printf("CL_DEVICE_COMPILER_AVAILABLE: %u\n", compier_available);
605  cl_bool linker_available;
606  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_LINKER_AVAILABLE, sizeof(linker_available),
607  &linker_available, NULL));
608  // printf("CL_DEVICE_LINKER_AVAILABLE: %u\n", linker_available);
609  cl_device_exec_capabilities exec_capabilities;
610  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_EXECUTION_CAPABILITIES,
611  sizeof(exec_capabilities), &exec_capabilities, NULL));
612  cl_command_queue_properties queue_properties;
613  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_QUEUE_PROPERTIES, sizeof(queue_properties),
614  &queue_properties, NULL));
615  size_t printf_buffer_size;
616  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_PRINTF_BUFFER_SIZE,
617  sizeof(printf_buffer_size), &printf_buffer_size, NULL));
618  cl_bool preferred_interop_user_sync;
619  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC,
620  sizeof(preferred_interop_user_sync), &preferred_interop_user_sync, NULL));
621  // printf("CL_DEVICE_PREFERRED_INTEROP_USER_SYNC: %u\n", preferred_interop_user_sync);
622 // cl_device_id parent_device;
623 // printf("CL_DEVICE_PARENT_DEVICE: %u\n", parent_device);
624  cl_uint reference_count;
625  checkOclErrors(clGetDeviceInfo(device, CL_DEVICE_REFERENCE_COUNT, sizeof(reference_count),
626  &reference_count, NULL));
627  // printf("CL_DEVICE_REFERENCE_COUNT: %u\n", reference_count);
628  // printf("\n");
629 
630  free(devices);
631 
632  free(platforms);
633 
634 }
635 
636 } /* namespace lvr2 */
lvr2::generatePointArray
static void generatePointArray(LBPointArray< T > &m, int width, int dim)
lvr2::floatArr
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
lvr2::ClSOR::calcStatistics
void calcStatistics()
Definition: ClStatisticalOutlierFilter.cpp:149
lvr2::ClSOR::ClSOR
ClSOR(floatArr &points, size_t num_points, int k, int device=0)
Definition: ClStatisticalOutlierFilter.cpp:34
lvr2::ClSOR::m_mult_
double m_mult_
Definition: ClStatisticalOutlierFilter.hpp:105
lvr2::indexArray
boost::shared_array< unsigned int > indexArray
Definition: DataStruct.hpp:128
lvr2::ClSOR::D_kd_tree_splits
cl_mem D_kd_tree_splits
Definition: ClStatisticalOutlierFilter.hpp:136
lvr2::ClSOR::m_context
cl_context m_context
Definition: ClStatisticalOutlierFilter.hpp:127
lvr2::ClSOR::initKdTree
void initKdTree()
PRIVATE ///.
Definition: ClStatisticalOutlierFilter.cpp:217
lvr2::ClSOR::m_platform_id
cl_platform_id m_platform_id
Definition: ClStatisticalOutlierFilter.hpp:121
lvr2::ClSOR::m_ret
cl_int m_ret
Definition: ClStatisticalOutlierFilter.hpp:126
lvr2::ClSOR::kd_tree_gen
boost::shared_ptr< LBKdTree > kd_tree_gen
Definition: ClStatisticalOutlierFilter.hpp:115
lvr2::ClSOR::calcDistances
void calcDistances()
Definition: ClStatisticalOutlierFilter.cpp:62
lvr2::ClSOR::D_Distances
cl_mem D_Distances
Definition: ClStatisticalOutlierFilter.hpp:137
lvr2::ClSOR::~ClSOR
~ClSOR()
Definition: ClStatisticalOutlierFilter.cpp:55
lvr2::ClSOR::getInliers
int getInliers(lvr2::indexArray &inliers)
Definition: ClStatisticalOutlierFilter.cpp:170
lvr2::ClSOR::m_device_global_memory
cl_ulong m_device_global_memory
Definition: ClStatisticalOutlierFilter.hpp:125
lvr2::ClSOR::m_distances
LBPointArray< float > m_distances
Definition: ClStatisticalOutlierFilter.hpp:114
lvr2::ClSOR::getDeviceInformation
void getDeviceInformation(int platform_id=0, int device_id=0)
Definition: ClStatisticalOutlierFilter.cpp:379
lvr2::LBPointArray::elements
T * elements
Definition: LBPointArray.hpp:45
lvr2::ClSOR::m_command_queue
cl_command_queue m_command_queue
Definition: ClStatisticalOutlierFilter.hpp:128
checkOclErrors
#define checkOclErrors(err)
Definition: cl_helper.h:105
lvr2::ClSOR::m_kernel_sor
cl_kernel m_kernel_sor
Definition: ClStatisticalOutlierFilter.hpp:131
NULL
#define NULL
Definition: mydefs.hpp:141
lvr2::LBPointArray::dim
unsigned int dim
Definition: LBPointArray.hpp:44
lvr2::ClSOR::m_std_dev_
double m_std_dev_
Definition: ClStatisticalOutlierFilter.hpp:107
lvr2::ClSOR::setK
void setK(int k)
Set the number of k nearest neighbors k-neighborhood.
Definition: ClStatisticalOutlierFilter.cpp:184
lvr2::LBKdTree
The LBKdTree class implements a left-balanced array-based index kd-tree. Left-Balanced: minimum memor...
Definition: LBKdTree.hpp:51
lvr2::ClSOR::m_program_es
cl_program m_program_es
Definition: ClStatisticalOutlierFilter.hpp:129
lvr2::ClSOR::loadSORKernel
void loadSORKernel()
Definition: ClStatisticalOutlierFilter.cpp:258
lvr2::ClSOR::D_V
cl_mem D_V
Definition: ClStatisticalOutlierFilter.hpp:134
lvropenmp.hpp
lvr2::ClSOR::m_threads_per_block
cl_uint m_threads_per_block
Definition: ClStatisticalOutlierFilter.hpp:124
lvr2::ClSOR::m_k
int m_k
Definition: ClStatisticalOutlierFilter.hpp:104
lvr2::ClSOR::m_program_in
cl_program m_program_in
Definition: ClStatisticalOutlierFilter.hpp:130
lvr2::ClSOR::m_mean_
double m_mean_
Definition: ClStatisticalOutlierFilter.hpp:106
lvr2::ClSOR::initCl
void initCl()
Definition: ClStatisticalOutlierFilter.cpp:225
lvr2::ClSOR::kd_tree_values
LBPointArray< float > * kd_tree_values
Definition: ClStatisticalOutlierFilter.hpp:110
lvr2::ClSOR::m_device_id
cl_device_id m_device_id
Definition: ClStatisticalOutlierFilter.hpp:122
lvr2::ClSOR::SOR_KERNEL_STRING
const char * SOR_KERNEL_STRING
Definition: ClStatisticalOutlierFilter.hpp:140
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::ClSOR::freeGPU
void freeGPU()
Definition: ClStatisticalOutlierFilter.cpp:192
lvr2::LBPointArray::width
unsigned int width
Definition: LBPointArray.hpp:43
lvr2::ClSOR::finalizeCl
void finalizeCl()
Definition: ClStatisticalOutlierFilter.cpp:239
lvr2::ClSOR::kd_tree_splits
LBPointArray< unsigned char > * kd_tree_splits
Definition: ClStatisticalOutlierFilter.hpp:111
kfusion::cuda::error
KF_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func="")
Error handler. All GPU functions from this subsystem call the function to report an error....
Definition: device_memory.cpp:7
lvr2::ClSOR::D_kd_tree_values
cl_mem D_kd_tree_values
Definition: ClStatisticalOutlierFilter.hpp:135
lvr2::ClSOR::V
LBPointArray< float > V
Definition: ClStatisticalOutlierFilter.hpp:109
lvr2::ClSOR::m_mps
cl_uint m_mps
Definition: ClStatisticalOutlierFilter.hpp:123
ClStatisticalOutlierFilter.hpp
lvr2::OpenMPConfig::getNumThreads
static int getNumThreads()
Returns the number of supported threads (or 1 if OpenMP is not supported)
Definition: lvropenmp.cpp:70
lvr2::ClSOR::getErrorString
const char * getErrorString(cl_int error)
Definition: ClStatisticalOutlierFilter.cpp:301


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:23