Skip to content

Commit e340ff9

Browse files
pli2-intelalalek
authored andcommitted
Merge pull request opencv#9114 from pengli:dnn_rebase
add libdnn acceleration to dnn module (opencv#9114) * import libdnn code Signed-off-by: Li Peng <peng.li@intel.com> * add convolution layer ocl acceleration Signed-off-by: Li Peng <peng.li@intel.com> * add pooling layer ocl acceleration Signed-off-by: Li Peng <peng.li@intel.com> * add softmax layer ocl acceleration Signed-off-by: Li Peng <peng.li@intel.com> * add lrn layer ocl acceleration Signed-off-by: Li Peng <peng.li@intel.com> * add innerproduct layer ocl acceleration Signed-off-by: Li Peng <peng.li@intel.com> * add HAVE_OPENCL macro Signed-off-by: Li Peng <peng.li@intel.com> * fix for convolution ocl Signed-off-by: Li Peng <peng.li@intel.com> * enable getUMat() for multi-dimension Mat Signed-off-by: Li Peng <peng.li@intel.com> * use getUMat for ocl acceleration Signed-off-by: Li Peng <peng.li@intel.com> * use CV_OCL_RUN macro Signed-off-by: Li Peng <peng.li@intel.com> * set OPENCL target when it is available and disable fuseLayer for OCL target for the time being Signed-off-by: Li Peng <peng.li@intel.com> * fix innerproduct accuracy test Signed-off-by: Li Peng <peng.li@intel.com> * remove trailing space Signed-off-by: Li Peng <peng.li@intel.com> * Fixed tensorflow demo bug. Root cause is that tensorflow has different algorithm with libdnn to calculate convolution output dimension. libdnn don't calculate output dimension anymore and just use one passed in by config. * split gemm ocl file split it into gemm_buffer.cl and gemm_image.cl Signed-off-by: Li Peng <peng.li@intel.com> * Fix compile failure Signed-off-by: Li Peng <peng.li@intel.com> * check env flag for auto tuning Signed-off-by: Li Peng <peng.li@intel.com> * switch to new ocl kernels for softmax layer Signed-off-by: Li Peng <peng.li@intel.com> * update softmax layer on some platform subgroup extension may not work well, fallback to non subgroup ocl acceleration. Signed-off-by: Li Peng <peng.li@intel.com> * fallback to cpu path for fc layer with multi output Signed-off-by: Li Peng <peng.li@intel.com> * update output message Signed-off-by: Li Peng <peng.li@intel.com> * update fully connected layer fallback to gemm API if libdnn return false Signed-off-by: Li Peng <peng.li@intel.com> * Add ReLU OCL implementation * disable layer fusion for now Signed-off-by: Li Peng <peng.li@intel.com> * Add OCL implementation for concat layer Signed-off-by: Wu Zhiwen <zhiwen.wu@intel.com> * libdnn: update license and copyrights Also refine libdnn coding style Signed-off-by: Wu Zhiwen <zhiwen.wu@intel.com> Signed-off-by: Li Peng <peng.li@intel.com> * DNN: Don't link OpenCL library explicitly * DNN: Make default preferableTarget to DNN_TARGET_CPU User should set it to DNN_TARGET_OPENCL explicitly if want to use OpenCL acceleration. Also don't fusion when using DNN_TARGET_OPENCL * DNN: refine coding style * Add getOpenCLErrorString * DNN: Use int32_t/uint32_t instread of alias * Use namespace ocl4dnn to include libdnn things * remove extra copyTo in softmax ocl path Signed-off-by: Li Peng <peng.li@intel.com> * update ReLU layer ocl path Signed-off-by: Li Peng <peng.li@intel.com> * Add prefer target property for layer class It is used to indicate the target for layer forwarding, either the default CPU target or OCL target. Signed-off-by: Li Peng <peng.li@intel.com> * Add cl_event based timer for cv::ocl * Rename libdnn to ocl4dnn Signed-off-by: Li Peng <peng.li@intel.com> Signed-off-by: wzw <zhiwen.wu@intel.com> * use UMat for ocl4dnn internal buffer Remove allocateMemory which use clCreateBuffer directly Signed-off-by: Li Peng <peng.li@intel.com> Signed-off-by: wzw <zhiwen.wu@intel.com> * enable buffer gemm in ocl4dnn innerproduct Signed-off-by: Li Peng <peng.li@intel.com> * replace int_tp globally for ocl4dnn kernels. Signed-off-by: wzw <zhiwen.wu@intel.com> Signed-off-by: Li Peng <peng.li@intel.com> * create UMat for layer params Signed-off-by: Li Peng <peng.li@intel.com> * update sign ocl kernel Signed-off-by: Li Peng <peng.li@intel.com> * update image based gemm of inner product layer Signed-off-by: Li Peng <peng.li@intel.com> * remove buffer gemm of inner product layer call cv::gemm API instead Signed-off-by: Li Peng <peng.li@intel.com> * change ocl4dnn forward parameter to UMat Signed-off-by: Li Peng <peng.li@intel.com> * Refine auto-tuning mechanism. - Use OPENCV_OCL4DNN_KERNEL_CONFIG_PATH to set cache directory for fine-tuned kernel configuration. e.g. export OPENCV_OCL4DNN_KERNEL_CONFIG_PATH=/home/tmp, the cache directory will be /home/tmp/spatialkernels/ on Linux. - Define environment OPENCV_OCL4DNN_ENABLE_AUTO_TUNING to enable auto-tuning. - OPENCV_OPENCL_ENABLE_PROFILING is only used to enable profiling for OpenCL command queue. This fix basic kernel get wrong running time, i.e. 0ms. - If creating cache directory failed, disable auto-tuning. * Detect and create cache dir on windows Signed-off-by: Li Peng <peng.li@intel.com> * Refine gemm like convolution kernel. Signed-off-by: Li Peng <peng.li@intel.com> * Fix redundant swizzleWeights calling when use cached kernel config. * Fix "out of resource" bug when auto-tuning too many kernels. * replace cl_mem with UMat in ocl4dnnConvSpatial class * OCL4DNN: reduce the tuning kernel candidate. This patch could reduce 75% of the tuning candidates with less than 2% performance impact for the final result. Signed-off-by: Zhigang Gong <zhigang.gong@intel.com> * replace cl_mem with umat in ocl4dnn convolution Signed-off-by: Li Peng <peng.li@intel.com> * remove weight_image_ of ocl4dnn inner product Actually it is unused in the computation Signed-off-by: Li Peng <peng.li@intel.com> * Various fixes for ocl4dnn 1. OCL_PERFORMANCE_CHECK(ocl::Device::getDefault().isIntel()) 2. Ptr<OCL4DNNInnerProduct<float> > innerProductOp 3. Code comments cleanup 4. ignore check on OCL cpu device Signed-off-by: Li Peng <peng.li@intel.com> * add build option for log softmax Signed-off-by: Li Peng <peng.li@intel.com> * remove unused ocl kernels in ocl4dnn Signed-off-by: Li Peng <peng.li@intel.com> * replace ocl4dnnSet with opencv setTo Signed-off-by: Li Peng <peng.li@intel.com> * replace ALIGN with cv::alignSize Signed-off-by: Li Peng <peng.li@intel.com> * check kernel build options Signed-off-by: Li Peng <peng.li@intel.com> * Handle program compilation fail properly. * Use std::numeric_limits<float>::infinity() for large float number * check ocl4dnn kernel compilation result Signed-off-by: Li Peng <peng.li@intel.com> * remove unused ctx_id Signed-off-by: Li Peng <peng.li@intel.com> * change clEnqueueNDRangeKernel to kernel.run() Signed-off-by: Li Peng <peng.li@intel.com> * change cl_mem to UMat in image based gemm Signed-off-by: Li Peng <peng.li@intel.com> * check intel subgroup support for lrn and pooling layer Signed-off-by: Li Peng <peng.li@intel.com> * Fix convolution bug if group is greater than 1 Signed-off-by: Li Peng <peng.li@intel.com> * Set default layer preferableTarget to be DNN_TARGET_CPU Signed-off-by: Li Peng <peng.li@intel.com> * Add ocl perf test for convolution Signed-off-by: Li Peng <peng.li@intel.com> * Add more ocl accuracy test Signed-off-by: Li Peng <peng.li@intel.com> * replace cl_image with ocl::Image2D Signed-off-by: Li Peng <peng.li@intel.com> * Fix build failure in elementwise layer Signed-off-by: Li Peng <peng.li@intel.com> * use getUMat() to get blob data Signed-off-by: Li Peng <peng.li@intel.com> * replace cl_mem handle with ocl::KernelArg Signed-off-by: Li Peng <peng.li@intel.com> * dnn(build): don't use C++11, OPENCL_LIBRARIES fix * dnn(ocl4dnn): remove unused OpenCL kernels * dnn(ocl4dnn): extract OpenCL code into .cl files * dnn(ocl4dnn): refine auto-tuning Defaultly disable auto-tuning, set OPENCV_OCL4DNN_ENABLE_AUTO_TUNING environment variable to enable it. Use a set of pre-tuned configs as default config if auto-tuning is disabled. These configs are tuned for Intel GPU with 48/72 EUs, and for googlenet, AlexNet, ResNet-50 If default config is not suitable, use the first available kernel config from the candidates. Candidate priority from high to low is gemm like kernel, IDLF kernel, basick kernel. * dnn(ocl4dnn): pooling doesn't use OpenCL subgroups * dnn(ocl4dnn): fix perf test OpenCV has default 3sec time limit for each performance test. Warmup OpenCL backend outside of perf measurement loop. * use ocl::KernelArg as much as possible Signed-off-by: Li Peng <peng.li@intel.com> * dnn(ocl4dnn): fix bias bug for gemm like kernel * dnn(ocl4dnn): wrap cl_mem into UMat Signed-off-by: Li Peng <peng.li@intel.com> * dnn(ocl4dnn): Refine signature of kernel config - Use more readable string as signture of kernel config - Don't count device name and vendor in signature string - Default kernel configurations are tuned for Intel GPU with 24/48/72 EUs, and for googlenet, AlexNet, ResNet-50 net model. * dnn(ocl4dnn): swap width/height in configuration * dnn(ocl4dnn): enable configs for Intel OpenCL runtime only * core: make configuration helper functions accessible from non-core modules * dnn(ocl4dnn): update kernel auto-tuning behavior Avoid unwanted creation of directories * dnn(ocl4dnn): simplify kernel to workaround OpenCL compiler crash * dnn(ocl4dnn): remove redundant code * dnn(ocl4dnn): Add more clear message for simd size dismatch. * dnn(ocl4dnn): add const to const argument Signed-off-by: Li Peng <peng.li@intel.com> * dnn(ocl4dnn): force compiler use a specific SIMD size for IDLF kernel * dnn(ocl4dnn): drop unused tuneLocalSize() * dnn(ocl4dnn): specify OpenCL queue for Timer and convolve() method * dnn(ocl4dnn): sanitize file names used for cache * dnn(perf): enable Network tests with OpenCL * dnn(ocl4dnn/conv): drop computeGlobalSize() * dnn(ocl4dnn/conv): drop unused fields * dnn(ocl4dnn/conv): simplify ctor * dnn(ocl4dnn/conv): refactor kernelConfig localSize=NULL * dnn(ocl4dnn/conv): drop unsupported double / untested half types * dnn(ocl4dnn/conv): drop unused variable * dnn(ocl4dnn/conv): alignSize/divUp * dnn(ocl4dnn/conv): use enum values * dnn(ocl4dnn): drop unused innerproduct variable Signed-off-by: Li Peng <peng.li@intel.com> * dnn(ocl4dnn): add an generic function to check cl option support * dnn(ocl4dnn): run softmax subgroup version kernel first Signed-off-by: Li Peng <peng.li@intel.com>
1 parent f646f61 commit e340ff9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+8788
-63
lines changed

modules/core/include/opencv2/core/ocl.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ CV_EXPORTS const char* convertTypeStr(int sdepth, int ddepth, int cn, char* buf)
665665
CV_EXPORTS const char* typeToStr(int t);
666666
CV_EXPORTS const char* memopTypeToStr(int t);
667667
CV_EXPORTS const char* vecopTypeToStr(int t);
668+
CV_EXPORTS const char* getOpenCLErrorString(int errorCode);
668669
CV_EXPORTS String kernelToStr(InputArray _kernel, int ddepth = -1, const char * name = NULL);
669670
CV_EXPORTS void getPlatfomsInfo(std::vector<PlatformInfo>& platform_info);
670671

@@ -731,6 +732,21 @@ class CV_EXPORTS Image2D
731732
Impl* p;
732733
};
733734

735+
class CV_EXPORTS Timer
736+
{
737+
public:
738+
Timer(const Queue& q);
739+
~Timer();
740+
void start();
741+
void stop();
742+
float milliSeconds();
743+
float microSeconds();
744+
float seconds();
745+
746+
protected:
747+
struct Impl;
748+
Impl* p;
749+
};
734750

735751
CV_EXPORTS MatAllocator* getOpenCLAllocator();
736752

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#ifndef OPENCV_CONFIGURATION_PRIVATE_HPP
6+
#define OPENCV_CONFIGURATION_PRIVATE_HPP
7+
8+
namespace cv { namespace utils {
9+
10+
CV_EXPORTS bool getConfigurationParameterBool(const char* name, bool defaultValue);
11+
CV_EXPORTS size_t getConfigurationParameterSizeT(const char* name, size_t defaultValue);
12+
CV_EXPORTS cv::String getConfigurationParameterString(const char* name, const char* defaultValue);
13+
14+
}} // namespace
15+
16+
#endif // OPENCV_CONFIGURATION_PRIVATE_HPP

modules/core/src/ocl.cpp

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@
5151
#include <inttypes.h>
5252
#endif
5353

54+
#include <opencv2/core/utils/configuration.private.hpp>
55+
5456
#include "opencv2/core/ocl_genbase.hpp"
57+
#include "opencl_kernels_core.hpp"
5558

5659
#define CV_OPENCL_ALWAYS_SHOW_BUILD_LOG 0
5760
#define CV_OPENCL_SHOW_RUN_ERRORS 0
@@ -4718,6 +4721,102 @@ const char* convertTypeStr(int sdepth, int ddepth, int cn, char* buf)
47184721
return buf;
47194722
}
47204723

4724+
const char* getOpenCLErrorString(int errorCode)
4725+
{
4726+
switch (errorCode)
4727+
{
4728+
case 0: return "CL_SUCCESS";
4729+
case -1: return "CL_DEVICE_NOT_FOUND";
4730+
case -2: return "CL_DEVICE_NOT_AVAILABLE";
4731+
case -3: return "CL_COMPILER_NOT_AVAILABLE";
4732+
case -4: return "CL_MEM_OBJECT_ALLOCATION_FAILURE";
4733+
case -5: return "CL_OUT_OF_RESOURCES";
4734+
case -6: return "CL_OUT_OF_HOST_MEMORY";
4735+
case -7: return "CL_PROFILING_INFO_NOT_AVAILABLE";
4736+
case -8: return "CL_MEM_COPY_OVERLAP";
4737+
case -9: return "CL_IMAGE_FORMAT_MISMATCH";
4738+
case -10: return "CL_IMAGE_FORMAT_NOT_SUPPORTED";
4739+
case -11: return "CL_BUILD_PROGRAM_FAILURE";
4740+
case -12: return "CL_MAP_FAILURE";
4741+
case -13: return "CL_MISALIGNED_SUB_BUFFER_OFFSET";
4742+
case -14: return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
4743+
case -15: return "CL_COMPILE_PROGRAM_FAILURE";
4744+
case -16: return "CL_LINKER_NOT_AVAILABLE";
4745+
case -17: return "CL_LINK_PROGRAM_FAILURE";
4746+
case -18: return "CL_DEVICE_PARTITION_FAILED";
4747+
case -19: return "CL_KERNEL_ARG_INFO_NOT_AVAILABLE";
4748+
case -30: return "CL_INVALID_VALUE";
4749+
case -31: return "CL_INVALID_DEVICE_TYPE";
4750+
case -32: return "CL_INVALID_PLATFORM";
4751+
case -33: return "CL_INVALID_DEVICE";
4752+
case -34: return "CL_INVALID_CONTEXT";
4753+
case -35: return "CL_INVALID_QUEUE_PROPERTIES";
4754+
case -36: return "CL_INVALID_COMMAND_QUEUE";
4755+
case -37: return "CL_INVALID_HOST_PTR";
4756+
case -38: return "CL_INVALID_MEM_OBJECT";
4757+
case -39: return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR";
4758+
case -40: return "CL_INVALID_IMAGE_SIZE";
4759+
case -41: return "CL_INVALID_SAMPLER";
4760+
case -42: return "CL_INVALID_BINARY";
4761+
case -43: return "CL_INVALID_BUILD_OPTIONS";
4762+
case -44: return "CL_INVALID_PROGRAM";
4763+
case -45: return "CL_INVALID_PROGRAM_EXECUTABLE";
4764+
case -46: return "CL_INVALID_KERNEL_NAME";
4765+
case -47: return "CL_INVALID_KERNEL_DEFINITION";
4766+
case -48: return "CL_INVALID_KERNEL";
4767+
case -49: return "CL_INVALID_ARG_INDEX";
4768+
case -50: return "CL_INVALID_ARG_VALUE";
4769+
case -51: return "CL_INVALID_ARG_SIZE";
4770+
case -52: return "CL_INVALID_KERNEL_ARGS";
4771+
case -53: return "CL_INVALID_WORK_DIMENSION";
4772+
case -54: return "CL_INVALID_WORK_GROUP_SIZE";
4773+
case -55: return "CL_INVALID_WORK_ITEM_SIZE";
4774+
case -56: return "CL_INVALID_GLOBAL_OFFSET";
4775+
case -57: return "CL_INVALID_EVENT_WAIT_LIST";
4776+
case -58: return "CL_INVALID_EVENT";
4777+
case -59: return "CL_INVALID_OPERATION";
4778+
case -60: return "CL_INVALID_GL_OBJECT";
4779+
case -61: return "CL_INVALID_BUFFER_SIZE";
4780+
case -62: return "CL_INVALID_MIP_LEVEL";
4781+
case -63: return "CL_INVALID_GLOBAL_WORK_SIZE";
4782+
case -64: return "CL_INVALID_PROPERTY";
4783+
case -65: return "CL_INVALID_IMAGE_DESCRIPTOR";
4784+
case -66: return "CL_INVALID_COMPILER_OPTIONS";
4785+
case -67: return "CL_INVALID_LINKER_OPTIONS";
4786+
case -68: return "CL_INVALID_DEVICE_PARTITION_COUNT";
4787+
case -69: return "CL_INVALID_PIPE_SIZE";
4788+
case -70: return "CL_INVALID_DEVICE_QUEUE";
4789+
case -1000: return "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR";
4790+
case -1001: return "CL_PLATFORM_NOT_FOUND_KHR";
4791+
case -1002: return "CL_INVALID_D3D10_DEVICE_KHR";
4792+
case -1003: return "CL_INVALID_D3D10_RESOURCE_KHR";
4793+
case -1004: return "CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR";
4794+
case -1005: return "CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR";
4795+
case -1024: return "clBLAS: Functionality is not implemented";
4796+
case -1023: return "clBLAS: Library is not initialized yet";
4797+
case -1022: return "clBLAS: Matrix A is not a valid memory object";
4798+
case -1021: return "clBLAS: Matrix B is not a valid memory object";
4799+
case -1020: return "clBLAS: Matrix C is not a valid memory object";
4800+
case -1019: return "clBLAS: Vector X is not a valid memory object";
4801+
case -1018: return "clBLAS: Vector Y is not a valid memory object";
4802+
case -1017: return "clBLAS: An input dimension (M:N:K) is invalid";
4803+
case -1016: return "clBLAS: Leading dimension A must not be less than the "
4804+
"size of the first dimension";
4805+
case -1015: return "clBLAS: Leading dimension B must not be less than the "
4806+
"size of the second dimension";
4807+
case -1014: return "clBLAS: Leading dimension C must not be less than the "
4808+
"size of the third dimension";
4809+
case -1013: return "clBLAS: The increment for a vector X must not be 0";
4810+
case -1012: return "clBLAS: The increment for a vector Y must not be 0";
4811+
case -1011: return "clBLAS: The memory object for Matrix A is too small";
4812+
case -1010: return "clBLAS: The memory object for Matrix B is too small";
4813+
case -1009: return "clBLAS: The memory object for Matrix C is too small";
4814+
case -1008: return "clBLAS: The memory object for Vector X is too small";
4815+
case -1007: return "clBLAS: The memory object for Vector Y is too small";
4816+
default: return "Unknown OpenCL error";
4817+
}
4818+
}
4819+
47214820
template <typename T>
47224821
static std::string kerToStr(const Mat & k)
47234822
{
@@ -5134,4 +5233,175 @@ bool internal::isCLBuffer(UMat& u)
51345233
return true;
51355234
}
51365235

5236+
struct Timer::Impl
5237+
{
5238+
const Queue queue;
5239+
5240+
Impl(const Queue& q)
5241+
: queue(q)
5242+
, initted_(false)
5243+
, running_(false)
5244+
, has_run_at_least_once_(false)
5245+
{
5246+
init();
5247+
}
5248+
5249+
~Impl()
5250+
{
5251+
clWaitForEvents(1, &start_gpu_cl_);
5252+
clWaitForEvents(1, &stop_gpu_cl_);
5253+
clReleaseEvent(start_gpu_cl_);
5254+
clReleaseEvent(stop_gpu_cl_);
5255+
}
5256+
5257+
void start()
5258+
{
5259+
#ifdef HAVE_OPENCL
5260+
if (!running())
5261+
{
5262+
clWaitForEvents(1, &start_gpu_cl_);
5263+
clReleaseEvent(start_gpu_cl_);
5264+
ocl::Kernel kernel("null_kernel_float", ocl::core::benchmark_oclsrc);
5265+
float arg = 0;
5266+
clSetKernelArg((cl_kernel)kernel.ptr(), 0, sizeof(arg), &arg);
5267+
clEnqueueTask((cl_command_queue)queue.ptr(), (cl_kernel)kernel.ptr(), 0,
5268+
NULL, &start_gpu_cl_);
5269+
clFinish((cl_command_queue)queue.ptr());
5270+
running_ = true;
5271+
has_run_at_least_once_ = true;
5272+
}
5273+
#endif
5274+
}
5275+
5276+
void stop()
5277+
{
5278+
#ifdef HAVE_OPENCL
5279+
if (running())
5280+
{
5281+
clWaitForEvents(1, &stop_gpu_cl_);
5282+
clReleaseEvent(stop_gpu_cl_);
5283+
ocl::Kernel kernel("null_kernel_float", ocl::core::benchmark_oclsrc);
5284+
float arg = 0;
5285+
clSetKernelArg((cl_kernel)kernel.ptr(), 0, sizeof(arg), &arg);
5286+
clEnqueueTask((cl_command_queue)queue.ptr(), (cl_kernel)kernel.ptr(), 0,
5287+
NULL, &stop_gpu_cl_);
5288+
clFinish((cl_command_queue)queue.ptr());
5289+
running_ = false;
5290+
}
5291+
#endif
5292+
}
5293+
5294+
float microSeconds()
5295+
{
5296+
#ifdef HAVE_OPENCL
5297+
if (!has_run_at_least_once())
5298+
{
5299+
return 0;
5300+
}
5301+
if (running())
5302+
{
5303+
stop();
5304+
}
5305+
cl_ulong startTime, stopTime;
5306+
clWaitForEvents(1, &stop_gpu_cl_);
5307+
clGetEventProfilingInfo(start_gpu_cl_, CL_PROFILING_COMMAND_END,
5308+
sizeof startTime, &startTime, NULL);
5309+
clGetEventProfilingInfo(stop_gpu_cl_, CL_PROFILING_COMMAND_START,
5310+
sizeof stopTime, &stopTime, NULL);
5311+
double us = static_cast<double>(stopTime - startTime) / 1000.0;
5312+
elapsed_microseconds_ = static_cast<float>(us);
5313+
return elapsed_microseconds_;
5314+
#else
5315+
return 0;
5316+
#endif
5317+
}
5318+
5319+
float milliSeconds()
5320+
{
5321+
#ifdef HAVE_OPENCL
5322+
if (!has_run_at_least_once())
5323+
{
5324+
return 0;
5325+
}
5326+
if (running())
5327+
{
5328+
stop();
5329+
}
5330+
cl_ulong startTime = 0, stopTime = 0;
5331+
clGetEventProfilingInfo(start_gpu_cl_, CL_PROFILING_COMMAND_END,
5332+
sizeof startTime, &startTime, NULL);
5333+
clGetEventProfilingInfo(stop_gpu_cl_, CL_PROFILING_COMMAND_START,
5334+
sizeof stopTime, &stopTime, NULL);
5335+
double ms = static_cast<double>(stopTime - startTime) / 1000000.0;
5336+
elapsed_milliseconds_ = static_cast<float>(ms);
5337+
return elapsed_milliseconds_;
5338+
#else
5339+
return 0;
5340+
#endif
5341+
}
5342+
5343+
float seconds()
5344+
{
5345+
return milliSeconds() / 1000.f;
5346+
}
5347+
5348+
void init()
5349+
{
5350+
CV_Assert(queue.getImpl() && queue.getImpl()->isProfilingQueue_);
5351+
if (!initted())
5352+
{
5353+
start_gpu_cl_ = 0;
5354+
stop_gpu_cl_ = 0;
5355+
initted_ = true;
5356+
}
5357+
}
5358+
5359+
inline bool initted() { return initted_; }
5360+
inline bool running() { return running_; }
5361+
inline bool has_run_at_least_once() { return has_run_at_least_once_; }
5362+
5363+
bool initted_;
5364+
bool running_;
5365+
bool has_run_at_least_once_;
5366+
float elapsed_milliseconds_;
5367+
float elapsed_microseconds_;
5368+
cl_event start_gpu_cl_;
5369+
cl_event stop_gpu_cl_;
5370+
};
5371+
5372+
Timer::Timer(const Queue& q)
5373+
{
5374+
p = new Impl(q);
5375+
}
5376+
5377+
Timer::~Timer()
5378+
{
5379+
if(p)
5380+
{
5381+
delete p;
5382+
p = 0;
5383+
}
5384+
}
5385+
5386+
void Timer::start()
5387+
{
5388+
if(p)
5389+
p->start();
5390+
}
5391+
5392+
void Timer::stop()
5393+
{
5394+
if(p)
5395+
p->stop();
5396+
}
5397+
5398+
float Timer::microSeconds()
5399+
{ return p ? p->microSeconds() : 0; }
5400+
5401+
float Timer::milliSeconds()
5402+
{ return p ? p->milliSeconds() : 0; }
5403+
5404+
float Timer::seconds()
5405+
{ return p ? p->seconds() : 0; }
5406+
51375407
}}

modules/core/src/opencl/benchmark.cl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*M///////////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4+
//
5+
// By downloading, copying, installing or using the software you agree to this license.
6+
// If you do not agree to this license, do not download, install,
7+
// copy or use the software.
8+
//
9+
//
10+
// License Agreement
11+
// For Open Source Computer Vision Library
12+
//
13+
// Copyright (C) 2017, Intel Corporation, all rights reserved.
14+
// Copyright (c) 2016-2017 Fabian David Tschopp, all rights reserved.
15+
// Third party copyrights are property of their respective owners.
16+
//
17+
// Redistribution and use in source and binary forms, with or without modification,
18+
// are permitted provided that the following conditions are met:
19+
//
20+
// * Redistribution's of source code must retain the above copyright notice,
21+
// this list of conditions and the following disclaimer.
22+
//
23+
// * Redistribution's in binary form must reproduce the above copyright notice,
24+
// this list of conditions and the following disclaimer in the documentation
25+
// and/or other materials provided with the distribution.
26+
//
27+
// * The name of the copyright holders may not be used to endorse or promote products
28+
// derived from this software without specific prior written permission.
29+
//
30+
// This software is provided by the copyright holders and contributors "as is" and
31+
// any express or implied warranties, including, but not limited to, the implied
32+
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33+
// In no event shall the Intel Corporation or contributors be liable for any direct,
34+
// indirect, incidental, special, exemplary, or consequential damages
35+
// (including, but not limited to, procurement of substitute goods or services;
36+
// loss of use, data, or profits; or business interruption) however caused
37+
// and on any theory of liability, whether in contract, strict liability,
38+
// or tort (including negligence or otherwise) arising in any way out of
39+
// the use of this software, even if advised of the possibility of such damage.
40+
//
41+
//M*/
42+
43+
__kernel void null_kernel_float(float arg) {
44+
float out = arg;
45+
}

modules/core/src/precomp.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,6 @@ TLSData<CoreTLSData>& getCoreTlsData();
297297
#define CL_RUNTIME_EXPORT
298298
#endif
299299

300-
namespace utils {
301-
bool getConfigurationParameterBool(const char* name, bool defaultValue);
302-
size_t getConfigurationParameterSizeT(const char* name, size_t defaultValue);
303-
cv::String getConfigurationParameterString(const char* name, const char* defaultValue);
304-
}
305-
306300
extern bool __termination; // skip some cleanups, because process is terminating
307301
// (for example, if ExitProcess() was already called)
308302

0 commit comments

Comments
 (0)