Skip to content

OCL: cleanup unused code in case of undef HAVE_OPENCL#4102

Closed
alalek wants to merge 3 commits intoopencv:masterfrom
alalek:ocl_fix_noocl_code
Closed

OCL: cleanup unused code in case of undef HAVE_OPENCL#4102
alalek wants to merge 3 commits intoopencv:masterfrom
alalek:ocl_fix_noocl_code

Conversation

@alalek
Copy link
Copy Markdown
Member

@alalek alalek commented Jun 8, 2015

WIP

Related issue: http://code.opencv.org/issues/4409 #5022

Binary size reduced for ~1.2Mb (world, Linux-64, without IPP optimizations: ~8%)

@vpisarev vpisarev self-assigned this Jun 16, 2015
@vpisarev
Copy link
Copy Markdown
Contributor

@alalek, this is useful patch, but I would suggest to decrease the amount of conditional branches. Basically, since each OpenCL runtime call is cdecl function (i.e. it leaves it to the caller side to clean the stack) it would be enough to redirect each OpenCL call to a stub function that would throw an exception. But there is very little chance that we even get to one of those functions, since useOpenCL() would give you false. I would probably also add special protection in ocl::Kernel::run() and few other functions. All the other #ifdef's are unnecessary and just make the code maintenance more difficult.

@alalek
Copy link
Copy Markdown
Member Author

alalek commented Jun 16, 2015

The main idea is to completely disable any OpenCL code to:

  • eliminate any possible wrong logic;
  • not call unused/useless code;
  • and to reduce binary code (it is actual for embedded platforms).

I know "#if" decision for this as presented here (I tried do not use multi-line macros because they are very bad things for debugging). This way is used widely in OpenCV.
Another way is to create separate file (or split file into 2 parts) with stubs only for shared public interfaces, I tried this but there is a problem with code logic synchronization and it looks strange.

@vpisarev
Copy link
Copy Markdown
Contributor

@alalek,
this code takes very little space comparing to, say, IPP or even comparing to all the "cv::norm" and arithmetic functions. I would not worry about space overhead here at all.

there can not be in principle any wrong logic until you actually call "clSomething".
the code will only be called if useOpenCL() returns true.

In principle, I would like to eliminate most of conditional branches in OpenCV code. This is one of the goal of the universal intrinsics BTW. And in fact I do not link the idea to have #ifdef HAVE_OPENCL everywhere in OpenCV code, but at least it's hidden inside a macro. Here explicit #ifdef's look very ugly. So, please, refactor it.

@alalek alalek mentioned this pull request Sep 13, 2015
@alalek alalek mentioned this pull request Nov 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants