22 #define CL_USE_DEPRECATED_OPENCL_1_2_APIS 23 #define CL_USE_DEPRECATED_OPENCL_2_0_APIS 25 #ifdef KINECT2_OPENCL_ICD_LOADER_IS_OLD 26 #define CL_USE_DEPRECATED_OPENCL_1_1_APIS 30 #endif //CL_VERSION_1_2 31 #endif //LIBFREENECT2_OPENCL_ICD_LOADER_IS_OLD 35 #ifndef REG_OPENCL_FILE 36 #define REG_OPENCL_FILE "" 43 #define CL_FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) 44 #define PRINT_CL_ERROR(expr, err) OUT_ERROR(FG_BLUE "[" << CL_FILENAME << "]" FG_CYAN "(" << __LINE__ << ") " FG_YELLOW << expr << FG_RED " failed: " << err) 46 #define CHECK_CL_PARAM(expr) do { cl_int err = CL_SUCCESS; (expr); if (err != CL_SUCCESS) { PRINT_CL_ERROR(#expr, err); return false; } } while(0) 47 #define CHECK_CL_RETURN(expr) do { cl_int err = (expr); if (err != CL_SUCCESS) { PRINT_CL_ERROR(#expr, err); return false; } } while(0) 48 #define CHECK_CL_ON_FAIL(expr, on_fail) do { cl_int err = (expr); if (err != CL_SUCCESS) { PRINT_CL_ERROR(#expr, err); on_fail; return false; } } while(0) 84 #ifdef ENABLE_PROFILING_CL 85 std::vector<double> timings;
101 void getDevices(
const std::vector<cl::Platform> &platforms, std::vector<cl::Device> &devices)
104 for(
size_t i = 0; i < platforms.size(); ++i)
108 std::vector<cl::Device> devs;
109 if(platform.
getDevices(CL_DEVICE_TYPE_ALL, &devs) != CL_SUCCESS)
114 devices.insert(devices.end(), devs.begin(), devs.end());
120 std::string devName, devVendor, devType;
121 cl_device_type devTypeID;
122 dev.
getInfo(CL_DEVICE_NAME, &devName);
123 dev.
getInfo(CL_DEVICE_VENDOR, &devVendor);
124 dev.
getInfo(CL_DEVICE_TYPE, &devTypeID);
128 case CL_DEVICE_TYPE_CPU:
131 case CL_DEVICE_TYPE_GPU:
134 case CL_DEVICE_TYPE_ACCELERATOR:
135 devType =
"ACCELERATOR";
138 devType =
"CUSTOM/UNKNOWN";
141 return devName +
" (" + devType +
")[" + devVendor +
']';
146 if(deviceId != -1 && devices.size() > (size_t)deviceId)
148 device = devices[deviceId];
152 bool selected =
false;
153 cl_device_type selectedType = 0;
155 for(
size_t i = 0; i < devices.size(); ++i)
158 cl_device_type devTypeID;
159 dev.
getInfo(CL_DEVICE_TYPE, &devTypeID);
161 if(!selected || (selectedType != CL_DEVICE_TYPE_GPU && devTypeID == CL_DEVICE_TYPE_GPU))
163 selectedType = devTypeID;
173 std::string sourceCode;
179 std::vector<cl::Platform> platforms;
182 if(platforms.empty())
188 std::vector<cl::Device> devices;
192 for(
size_t i = 0; i < devices.size(); ++i)
199 OUT_ERROR(
"could not find any suitable device");
213 OUT_ERROR(
"failed to build program: " << err);
218 #ifdef ENABLE_PROFILING_CL 279 std::vector<cl::Event> eventZero(2), eventRemap(1), eventProject(1), eventCheckDepth1(1), eventCheckDepth2(1);
299 #ifdef ENABLE_PROFILING_CL 302 data->timings.clear();
303 data->timings.resize(7, 0.0);
306 data->timings[0] += eventZero[0].getProfilingInfo<CL_PROFILING_COMMAND_END>() - eventZero[0].getProfilingInfo<CL_PROFILING_COMMAND_START>();
307 data->timings[1] += eventZero[1].getProfilingInfo<CL_PROFILING_COMMAND_END>() - eventZero[1].getProfilingInfo<CL_PROFILING_COMMAND_START>();
308 data->timings[2] += eventRemap[0].getProfilingInfo<CL_PROFILING_COMMAND_END>() - eventRemap[0].getProfilingInfo<CL_PROFILING_COMMAND_START>();
309 data->timings[3] += eventProject[0].getProfilingInfo<CL_PROFILING_COMMAND_END>() - eventProject[0].getProfilingInfo<CL_PROFILING_COMMAND_START>();
310 data->timings[4] += eventCheckDepth1[0].getProfilingInfo<CL_PROFILING_COMMAND_END>() - eventCheckDepth1[0].getProfilingInfo<CL_PROFILING_COMMAND_START>();
311 data->timings[5] += eventCheckDepth2[0].getProfilingInfo<CL_PROFILING_COMMAND_END>() - eventCheckDepth2[0].getProfilingInfo<CL_PROFILING_COMMAND_START>();
314 if(++
data->count == 100)
316 double sum =
data->timings[0] +
data->timings[1] +
data->timings[2] +
data->timings[3] +
data->timings[4] +
data->timings[5] +
data->timings[6];
317 OUT_INFO(
"writing depth: " <<
data->timings[0] / 100000000.0 <<
" ms.");
318 OUT_INFO(
"setting zero: " <<
data->timings[1] / 100000000.0 <<
" ms.");
319 OUT_INFO(
"remap: " <<
data->timings[2] / 100000000.0 <<
" ms.");
320 OUT_INFO(
"project: " <<
data->timings[3] / 100000000.0 <<
" ms.");
321 OUT_INFO(
"check depth 1: " <<
data->timings[4] / 100000000.0 <<
" ms.");
322 OUT_INFO(
"check depth 2: " <<
data->timings[5] / 100000000.0 <<
" ms.");
323 OUT_INFO(
"read registered: " <<
data->timings[6] / 100000000.0 <<
" ms.");
324 OUT_INFO(
"overall: " << sum / 100000000.0 <<
" ms.");
333 std::ostringstream oss;
335 oss << std::scientific;
338 oss <<
" -D r00=" <<
rotation.at<
double>(0, 0) <<
"f";
339 oss <<
" -D r01=" <<
rotation.at<
double>(0, 1) <<
"f";
340 oss <<
" -D r02=" <<
rotation.at<
double>(0, 2) <<
"f";
341 oss <<
" -D r10=" <<
rotation.at<
double>(1, 0) <<
"f";
342 oss <<
" -D r11=" <<
rotation.at<
double>(1, 1) <<
"f";
343 oss <<
" -D r12=" <<
rotation.at<
double>(1, 2) <<
"f";
344 oss <<
" -D r20=" <<
rotation.at<
double>(2, 0) <<
"f";
345 oss <<
" -D r21=" <<
rotation.at<
double>(2, 1) <<
"f";
346 oss <<
" -D r22=" <<
rotation.at<
double>(2, 2) <<
"f";
349 oss <<
" -D tx=" <<
translation.at<
double>(0, 0) <<
"f";
350 oss <<
" -D ty=" <<
translation.at<
double>(1, 0) <<
"f";
351 oss <<
" -D tz=" <<
translation.at<
double>(2, 0) <<
"f";
362 oss <<
" -D zNear=" << (uint16_t)(
zNear * 1000);
363 oss <<
" -D zFar=" << (uint16_t)(
zFar * 1000);
370 oss <<
" -D heightD=" <<
sizeDepth.height;
385 source = std::string((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
Class interface for cl_event.
cl_int getInfo(cl_device_info name, T *param) const
Wrapper for clGetDeviceInfo().
cl_int enqueueNDRangeKernel(const Kernel &kernel, const NDRange &offset, const NDRange &global, const NDRange &local=NullRange, const VECTOR_CLASS< Event > *events=NULL, Event *event=NULL) const
Class interface for specifying NDRange values.
cl_int enqueueReadBuffer(const Buffer &buffer, cl_bool blocking,::size_t offset,::size_t size, void *ptr, const VECTOR_CLASS< Event > *events=NULL, Event *event=NULL) const
unsigned char * dataOutput
cl_int getBuildInfo(const Device &device, cl_program_build_info name, T *param) const
#define CHECK_CL_PARAM(expr)
~DepthRegistrationOpenCL()
Class interface for Buffer Memory Objects.
CommandQueue interface for cl_command_queue.
cl_int wait() const
Blocks the calling thread until this event completes.
C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33) and OpenCL 1.2 (rev 15) ...
bool selectDevice(std::vector< cl::Device > &devices, cl::Device &device, const int deviceId=-1)
cl_int setArg(cl_uint index, const T &value)
void * enqueueMapBuffer(const Buffer &buffer, cl_bool blocking, cl_map_flags flags,::size_t offset,::size_t size, const VECTOR_CLASS< Event > *events=NULL, Event *event=NULL, cl_int *err=NULL) const
cv::Mat cameraMatrixRegistered
cl::Buffer bufferRegistered
DepthRegistrationOpenCL()
cl_int build(const VECTOR_CLASS< Device > &devices, const char *options=NULL, void(CL_CALLBACK *notifyFptr)(cl_program, void *)=NULL, void *data=NULL) const
Class interface for cl_kernel.
Program interface that implements cl_program.
void getDevices(const std::vector< cl::Platform > &platforms, std::vector< cl::Device > &devices)
VECTOR_CLASS< std::pair< const char *,::size_t > > Sources
static const NDRange NullRange
A zero-dimensional range.
cl_int enqueueWriteBuffer(const Buffer &buffer, cl_bool blocking,::size_t offset,::size_t size, const void *ptr, const VECTOR_CLASS< Event > *events=NULL, Event *event=NULL) const
#define CHECK_CL_RETURN(expr)
cl::Kernel kernelCheckDepth
void generateOptions(std::string &options) const
bool init(const int deviceId)
Class interface for cl_device_id.
#define CHECK_CL_ON_FAIL(expr, on_fail)
bool readProgram(std::string &source) const
Class interface for cl_context.
cl_int getProfilingInfo(cl_profiling_info name, T *param) const
Wrapper for clGetEventProfilingInfo().
bool registerDepth(const cv::Mat &depth, cv::Mat ®istered)
std::string deviceString(cl::Device &dev)