Skip to content

Commit efcf307

Browse files
committed
ocl: cleanup dead code in case of disabled OpenCL
1 parent 01324b0 commit efcf307

File tree

4 files changed

+379
-1328
lines changed

4 files changed

+379
-1328
lines changed

modules/core/src/ocl.cpp

Lines changed: 9 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
//M*/
4141

4242
#include "precomp.hpp"
43+
44+
#ifndef HAVE_OPENCL
45+
#include "ocl_disabled.impl.hpp"
46+
#else // HAVE_OPENCL
47+
4348
#include <list>
4449
#include <map>
4550
#include <deque>
@@ -106,23 +111,7 @@
106111
#include "opencv2/core/opencl/runtime/opencl_clamdblas.hpp"
107112
#include "opencv2/core/opencl/runtime/opencl_clamdfft.hpp"
108113

109-
#ifdef HAVE_OPENCL
110114
#include "opencv2/core/opencl/runtime/opencl_core.hpp"
111-
#else
112-
#if defined(_MSC_VER)
113-
#pragma warning(push)
114-
#pragma warning(disable : 4100)
115-
#pragma warning(disable : 4702)
116-
#elif defined(__clang__)
117-
#pragma clang diagnostic push
118-
#pragma clang diagnostic ignored "-Wunused-parameter"
119-
#elif defined(__GNUC__)
120-
#pragma GCC diagnostic push
121-
#pragma GCC diagnostic ignored "-Wunused-parameter"
122-
#endif
123-
// TODO FIXIT: This file can't be build without OPENCL
124-
#include "ocl_deprecated.hpp"
125-
#endif // HAVE_OPENCL
126115

127116
#ifdef HAVE_OPENCL_SVM
128117
#include "opencv2/core/opencl/runtime/opencl_svm_20.hpp"
@@ -147,31 +136,6 @@ cv::utils::AllocatorStatisticsInterface& getOpenCLAllocatorStatistics()
147136
return opencl_allocator_stats;
148137
}
149138

150-
#ifndef HAVE_OPENCL
151-
#define CV_OPENCL_NO_SUPPORT() CV_Error(cv::Error::OpenCLApiCallError, "OpenCV build without OpenCL support")
152-
namespace {
153-
struct DummyImpl
154-
{
155-
DummyImpl() { CV_OPENCL_NO_SUPPORT(); }
156-
~DummyImpl() { /* do not throw in desctructors */ }
157-
IMPLEMENT_REFCOUNTABLE();
158-
};
159-
} // namespace
160-
161-
// TODO Replace to empty body (without HAVE_OPENCL)
162-
#define CV_OCL_TRACE_CHECK_RESULT(status, message) /* nothing */
163-
#define CV_OCL_API_ERROR_MSG(check_result, msg) cv::String()
164-
#define CV_OCL_CHECK_RESULT(check_result, msg) (void)check_result
165-
#define CV_OCL_CHECK_(expr, check_result) expr; (void)check_result
166-
#define CV_OCL_CHECK(expr) do { cl_int __cl_result = (expr); CV_OCL_CHECK_RESULT(__cl_result, #expr); } while (0)
167-
#define CV_OCL_DBG_CHECK_RESULT(check_result, msg) (void)check_result
168-
#define CV_OCL_DBG_CHECK_(expr, check_result) expr; (void)check_result
169-
#define CV_OCL_DBG_CHECK(expr) do { cl_int __cl_result = (expr); CV_OCL_CHECK_RESULT(__cl_result, #expr); } while (0)
170-
171-
static const bool CV_OPENCL_DISABLE_BUFFER_RECT_OPERATIONS = false;
172-
173-
#else // HAVE_OPENCL
174-
175139
#ifndef _DEBUG
176140
static bool isRaiseError()
177141
{
@@ -270,7 +234,6 @@ static const String getBuildExtraOptions()
270234
static const bool CV_OPENCL_ENABLE_MEM_USE_HOST_PTR = utils::getConfigurationParameterBool("OPENCV_OPENCL_ENABLE_MEM_USE_HOST_PTR", true);
271235
static const size_t CV_OPENCL_ALIGNMENT_MEM_USE_HOST_PTR = utils::getConfigurationParameterSizeT("OPENCV_OPENCL_ALIGNMENT_MEM_USE_HOST_PTR", 4);
272236

273-
#endif // HAVE_OPENCL
274237

275238
struct UMat2D
276239
{
@@ -331,7 +294,7 @@ static uint64 crc64( const uchar* data, size_t size, uint64 crc0=0 )
331294
return ~crc;
332295
}
333296

334-
#if defined HAVE_OPENCL && OPENCV_HAVE_FILESYSTEM_SUPPORT
297+
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
335298
struct OpenCLBinaryCacheConfigurator
336299
{
337300
cv::String cache_path_;
@@ -872,7 +835,6 @@ static bool g_isOpenCVActivated = false;
872835
bool haveOpenCL()
873836
{
874837
CV_TRACE_FUNCTION();
875-
#ifdef HAVE_OPENCL
876838
static bool g_isOpenCLInitialized = false;
877839
static bool g_isOpenCLAvailable = false;
878840

@@ -902,9 +864,6 @@ bool haveOpenCL()
902864
g_isOpenCLInitialized = true;
903865
}
904866
return g_isOpenCLAvailable;
905-
#else
906-
return false;
907-
#endif
908867
}
909868

910869
bool useOpenCL()
@@ -924,14 +883,12 @@ bool useOpenCL()
924883
return data.useOpenCL > 0;
925884
}
926885

927-
#ifdef HAVE_OPENCL
928886
bool isOpenCLActivated()
929887
{
930888
if (!g_isOpenCVActivated)
931889
return false; // prevent unnecessary OpenCL activation via useOpenCL()->haveOpenCL() calls
932890
return useOpenCL();
933891
}
934-
#endif
935892

936893
void setUseOpenCL(bool flag)
937894
{
@@ -1958,7 +1915,6 @@ static unsigned int getSVMCapabilitiesMask()
19581915
} // namespace
19591916
#endif
19601917

1961-
#ifdef HAVE_OPENCL
19621918
static size_t getProgramCountLimit()
19631919
{
19641920
static bool initialized = false;
@@ -1970,7 +1926,6 @@ static size_t getProgramCountLimit()
19701926
}
19711927
return count;
19721928
}
1973-
#endif
19741929

19751930
struct Context::Impl
19761931
{
@@ -3553,8 +3508,6 @@ internal::ProgramEntry::operator ProgramSource&() const
35533508

35543509
/////////////////////////////////////////// Program /////////////////////////////////////////////
35553510

3556-
#ifdef HAVE_OPENCL
3557-
35583511
static
35593512
cv::String joinBuildOptions(const cv::String& a, const cv::String& b)
35603513
{
@@ -3968,10 +3921,6 @@ struct Program::Impl
39683921
String sourceName_;
39693922
};
39703923

3971-
#else // HAVE_OPENCL
3972-
struct Program::Impl : public DummyImpl {};
3973-
#endif // HAVE_OPENCL
3974-
39753924

39763925
Program::Program() { p = 0; }
39773926

@@ -4014,26 +3963,18 @@ bool Program::create(const ProgramSource& src,
40143963
p->release();
40153964
p = NULL;
40163965
}
4017-
#ifdef HAVE_OPENCL
40183966
p = new Impl(src, buildflags, errmsg);
40193967
if(!p->handle)
40203968
{
40213969
p->release();
40223970
p = 0;
40233971
}
40243972
return p != 0;
4025-
#else
4026-
CV_OPENCL_NO_SUPPORT();
4027-
#endif
40283973
}
40293974

40303975
void* Program::ptr() const
40313976
{
4032-
#ifdef HAVE_OPENCL
40333977
return p ? p->handle : 0;
4034-
#else
4035-
CV_OPENCL_NO_SUPPORT();
4036-
#endif
40373978
}
40383979

40393980
#ifndef OPENCV_REMOVE_DEPRECATED_API
@@ -4056,44 +3997,30 @@ bool Program::write(String& bin) const
40563997

40573998
String Program::getPrefix() const
40583999
{
4059-
#ifdef HAVE_OPENCL
40604000
if(!p)
40614001
return String();
40624002
Context::Impl* ctx_ = Context::getDefault().getImpl();
40634003
CV_Assert(ctx_);
40644004
return cv::format("opencl=%s\nbuildflags=%s", ctx_->getPrefixString().c_str(), p->buildflags.c_str());
4065-
#else
4066-
CV_OPENCL_NO_SUPPORT();
4067-
#endif
40684005
}
40694006

40704007
String Program::getPrefix(const String& buildflags)
40714008
{
4072-
#ifdef HAVE_OPENCL
40734009
Context::Impl* ctx_ = Context::getDefault().getImpl();
40744010
CV_Assert(ctx_);
40754011
return cv::format("opencl=%s\nbuildflags=%s", ctx_->getPrefixString().c_str(), buildflags.c_str());
4076-
#else
4077-
CV_OPENCL_NO_SUPPORT();
4078-
#endif
40794012
}
4080-
#endif
4013+
#endif // OPENCV_REMOVE_DEPRECATED_API
40814014

40824015
void Program::getBinary(std::vector<char>& binary) const
40834016
{
4084-
#ifdef HAVE_OPENCL
40854017
CV_Assert(p && "Empty program");
40864018
p->getProgramBinary(binary);
4087-
#else
4088-
binary.clear();
4089-
CV_OPENCL_NO_SUPPORT();
4090-
#endif
40914019
}
40924020

40934021
Program Context::Impl::getProg(const ProgramSource& src,
40944022
const String& buildflags, String& errmsg)
40954023
{
4096-
#ifdef HAVE_OPENCL
40974024
size_t limit = getProgramCountLimit();
40984025
const ProgramSource::Impl* src_ = src.getImpl();
40994026
CV_Assert(src_);
@@ -4145,9 +4072,6 @@ Program Context::Impl::getProg(const ProgramSource& src,
41454072
cacheList.push_front(key);
41464073
}
41474074
return prog;
4148-
#else
4149-
CV_OPENCL_NO_SUPPORT();
4150-
#endif
41514075
}
41524076

41534077

@@ -4707,9 +4631,6 @@ class OpenCLAllocator CV_FINAL : public MatAllocator
47074631

47084632
bool allocate(UMatData* u, int accessFlags, UMatUsageFlags usageFlags) const CV_OVERRIDE
47094633
{
4710-
#ifndef HAVE_OPENCL
4711-
return false;
4712-
#else
47134634
if(!u)
47144635
return false;
47154636

@@ -4828,7 +4749,6 @@ class OpenCLAllocator CV_FINAL : public MatAllocator
48284749
u->markHostCopyObsolete(true);
48294750
opencl_allocator_stats.onAllocate(u->size);
48304751
return true;
4831-
#endif // HAVE_OPENCL
48324752
}
48334753

48344754
/*void sync(UMatData* u) const
@@ -6699,27 +6619,19 @@ struct Timer::Impl
66996619

67006620
void start()
67016621
{
6702-
#ifdef HAVE_OPENCL
67036622
CV_OCL_DBG_CHECK(clFinish((cl_command_queue)queue.ptr()));
67046623
timer.start();
6705-
#endif
67066624
}
67076625

67086626
void stop()
67096627
{
6710-
#ifdef HAVE_OPENCL
67116628
CV_OCL_DBG_CHECK(clFinish((cl_command_queue)queue.ptr()));
67126629
timer.stop();
6713-
#endif
67146630
}
67156631

67166632
uint64 durationNS() const
67176633
{
6718-
#ifdef HAVE_OPENCL
67196634
return (uint64)(timer.getTimeSec() * 1e9);
6720-
#else
6721-
return 0;
6722-
#endif
67236635
}
67246636

67256637
TickMeter timer;
@@ -6746,13 +6658,6 @@ uint64 Timer::durationNS() const
67466658
return p->durationNS();
67476659
}
67486660

6749-
#ifndef HAVE_OPENCL
6750-
#if defined(_MSC_VER)
6751-
#pragma warning(pop)
6752-
#elif defined(__clang__)
6753-
#pragma clang diagnostic pop
6754-
#elif defined(__GNUC__)
6755-
#pragma GCC diagnostic pop
6756-
#endif
6757-
#endif
67586661
}} // namespace
6662+
6663+
#endif // HAVE_OPENCL

0 commit comments

Comments
 (0)