42
#ifndef OPENCV_OPENCL_HPP
43
#define OPENCV_OPENCL_HPP
45
#include "opencv2/core.hpp"
49
namespace
cv
{
namespace
ocl {
54CV_EXPORTS_W
bool
haveOpenCL();
55CV_EXPORTS_W
bool
useOpenCL();
56CV_EXPORTS_W
bool
haveAmdBlas();
57CV_EXPORTS_W
bool
haveAmdFft();
58CV_EXPORTS_W
void
setUseOpenCL(
bool
flag);
59CV_EXPORTS_W
void
finish();
61CV_EXPORTS
bool
haveSVM();
63
class
CV_EXPORTS Context;
64
class
CV_EXPORTS_W_SIMPLE Device;
65
class
CV_EXPORTS Kernel;
66
class
CV_EXPORTS Program;
67
class
CV_EXPORTS ProgramSource;
68
class
CV_EXPORTS Queue;
69
class
CV_EXPORTS PlatformInfo;
70
class
CV_EXPORTS Image2D;
75
CV_WRAP
Device() CV_NOEXCEPT;
87
TYPE_DEFAULT = (1 << 0),
90
TYPE_ACCELERATOR = (1 << 3),
91
TYPE_DGPU = TYPE_GPU + (1 << 16),
92
TYPE_IGPU = TYPE_GPU + (1 << 17),
96
CV_WRAP String name()
const;
97
CV_WRAP String extensions()
const;
98
CV_WRAP
bool
isExtensionSupported(
const
String& extensionName)
const;
99
CV_WRAP String version()
const;
100
CV_WRAP String vendorName()
const;
101
CV_WRAP String OpenCL_C_Version()
const;
102
CV_WRAP String OpenCLVersion()
const;
103
CV_WRAP
int
deviceVersionMajor()
const;
104
CV_WRAP
int
deviceVersionMinor()
const;
105
CV_WRAP String driverVersion()
const;
108
CV_WRAP
int
type()
const;
110
CV_WRAP
int
addressBits()
const;
111
CV_WRAP
bool
available()
const;
112
CV_WRAP
bool
compilerAvailable()
const;
113
CV_WRAP
bool
linkerAvailable()
const;
119
FP_ROUND_TO_NEAREST=(1 << 2),
120
FP_ROUND_TO_ZERO=(1 << 3),
121
FP_ROUND_TO_INF=(1 << 4),
123
FP_SOFT_FLOAT=(1 << 6),
124
FP_CORRECTLY_ROUNDED_DIVIDE_SQRT=(1 << 7)
126
CV_WRAP
int
doubleFPConfig()
const;
127
CV_WRAP
int
singleFPConfig()
const;
128
CV_WRAP
int
halfFPConfig()
const;
130
CV_WRAP
bool
endianLittle()
const;
131
CV_WRAP
bool
errorCorrectionSupport()
const;
135
EXEC_KERNEL=(1 << 0),
136
EXEC_NATIVE_KERNEL=(1 << 1)
138
CV_WRAP
int
executionCapabilities()
const;
140
CV_WRAP
size_t
globalMemCacheSize()
const;
148
CV_WRAP
int
globalMemCacheType()
const;
149
CV_WRAP
int
globalMemCacheLineSize()
const;
150
CV_WRAP
size_t
globalMemSize()
const;
152
CV_WRAP
size_t
localMemSize()
const;
159
CV_WRAP
int
localMemType()
const;
160
CV_WRAP
bool
hostUnifiedMemory()
const;
162
CV_WRAP
bool
imageSupport()
const;
164
CV_WRAP
bool
imageFromBufferSupport()
const;
165
uint imagePitchAlignment()
const;
166
uint imageBaseAddressAlignment()
const;
169
CV_WRAP
bool
intelSubgroupsSupport()
const;
171
CV_WRAP
size_t
image2DMaxWidth()
const;
172
CV_WRAP
size_t
image2DMaxHeight()
const;
174
CV_WRAP
size_t
image3DMaxWidth()
const;
175
CV_WRAP
size_t
image3DMaxHeight()
const;
176
CV_WRAP
size_t
image3DMaxDepth()
const;
178
CV_WRAP
size_t
imageMaxBufferSize()
const;
179
CV_WRAP
size_t
imageMaxArraySize()
const;
188
CV_WRAP
int
vendorID()
const;
193
CV_WRAP
inline
bool
isAMD()
const
{
return
vendorID() == VENDOR_AMD; }
194
CV_WRAP
inline
bool
isIntel()
const
{
return
vendorID() == VENDOR_INTEL; }
195
CV_WRAP
inline
bool
isNVidia()
const
{
return
vendorID() == VENDOR_NVIDIA; }
197
CV_WRAP
int
maxClockFrequency()
const;
198
CV_WRAP
int
maxComputeUnits()
const;
199
CV_WRAP
int
maxConstantArgs()
const;
200
CV_WRAP
size_t
maxConstantBufferSize()
const;
202
CV_WRAP
size_t
maxMemAllocSize()
const;
203
CV_WRAP
size_t
maxParameterSize()
const;
205
CV_WRAP
int
maxReadImageArgs()
const;
206
CV_WRAP
int
maxWriteImageArgs()
const;
207
CV_WRAP
int
maxSamplers()
const;
209
CV_WRAP
size_t
maxWorkGroupSize()
const;
210
CV_WRAP
int
maxWorkItemDims()
const;
211
void
maxWorkItemSizes(
size_t*)
const;
213
CV_WRAP
int
memBaseAddrAlign()
const;
215
CV_WRAP
int
nativeVectorWidthChar()
const;
216
CV_WRAP
int
nativeVectorWidthShort()
const;
217
CV_WRAP
int
nativeVectorWidthInt()
const;
218
CV_WRAP
int
nativeVectorWidthLong()
const;
219
CV_WRAP
int
nativeVectorWidthFloat()
const;
220
CV_WRAP
int
nativeVectorWidthDouble()
const;
221
CV_WRAP
int
nativeVectorWidthHalf()
const;
223
CV_WRAP
int
preferredVectorWidthChar()
const;
224
CV_WRAP
int
preferredVectorWidthShort()
const;
225
CV_WRAP
int
preferredVectorWidthInt()
const;
226
CV_WRAP
int
preferredVectorWidthLong()
const;
227
CV_WRAP
int
preferredVectorWidthFloat()
const;
228
CV_WRAP
int
preferredVectorWidthDouble()
const;
229
CV_WRAP
int
preferredVectorWidthHalf()
const;
231
CV_WRAP
size_t
printfBufferSize()
const;
232
CV_WRAP
size_t
profilingTimerResolution()
const;
234
CV_WRAP
static
const
Device& getDefault();
242
inline
Impl* getImpl()
const
{
return
(Impl*)p; }
243
inline
bool
empty()
const
{
return
!p; }
265
size_t
ndevices()
const;
266
Device& device(
size_t
idx)
const;
268
const
String& buildopt, String& errmsg);
269
void
unloadProg(
Program& prog);
290
void
setUseSVM(
bool
enabled);
297
static
Context
create(
const
std::string& configuration);
305
template
<
typename
T>
306
inline
void
setUserContext(
const
std::shared_ptr<T>& userContext) {
307
setUserContext(
typeid(T), userContext);
309
template
<
typename
T>
310
inline
std::shared_ptr<T> getUserContext() {
311
return
std::dynamic_pointer_cast<T>(getUserContext(
typeid(T)));
313
void
setUserContext(std::type_index typeId,
const
std::shared_ptr<UserContext>& userContext);
314
std::shared_ptr<UserContext> getUserContext(std::type_index typeId);
317
inline
Impl* getImpl()
const
{
return
(Impl*)p; }
318
inline
bool
empty()
const
{
return
!p; }
341
inline
Impl* getImpl()
const
{
return
(Impl*)p; }
342
inline
bool
empty()
const
{
return
!p; }
357
CV_EXPORTS
void
attachContext(
const
String& platformName,
void* platformID,
void* context,
void* deviceID);
400
static
Queue& getDefault();
405
struct
Impl;
friend
struct
Impl;
406
inline
Impl* getImpl()
const
{
return
p; }
407
inline
bool
empty()
const
{
return
!p; }
416
enum
{ LOCAL=1, READ_ONLY=2, WRITE_ONLY=4, READ_WRITE=6, CONSTANT=8, PTR_ONLY = 16, NO_SIZE=256 };
417
KernelArg(
int
_flags,
UMat* _m,
int
wscale=1,
int
iwscale=1,
const
void* _obj=0,
size_t
_sz=0);
420
static
KernelArg
Local(
size_t
localMemSize)
421
{
return
KernelArg(LOCAL, 0, 1, 1, 0, localMemSize); }
428
static
KernelArg
ReadWrite(
const
UMat& m,
int
wscale=1,
int
iwscale=1)
429
{
return
KernelArg(READ_WRITE, (
UMat*)&m, wscale, iwscale); }
430
static
KernelArg
ReadWriteNoSize(
const
UMat& m,
int
wscale=1,
int
iwscale=1)
431
{
return
KernelArg(READ_WRITE+NO_SIZE, (
UMat*)&m, wscale, iwscale); }
432
static
KernelArg
ReadOnly(
const
UMat& m,
int
wscale=1,
int
iwscale=1)
434
static
KernelArg
WriteOnly(
const
UMat& m,
int
wscale=1,
int
iwscale=1)
435
{
return
KernelArg(WRITE_ONLY, (
UMat*)&m, wscale, iwscale); }
436
static
KernelArg
ReadOnlyNoSize(
const
UMat& m,
int
wscale=1,
int
iwscale=1)
437
{
return
KernelArg(READ_ONLY+NO_SIZE, (
UMat*)&m, wscale, iwscale); }
438
static
KernelArg
WriteOnlyNoSize(
const
UMat& m,
int
wscale=1,
int
iwscale=1)
439
{
return
KernelArg(WRITE_ONLY+NO_SIZE, (
UMat*)&m, wscale, iwscale); }
441
template<
typename
_Tp>
static
KernelArg
Constant(
const
_Tp* arr,
size_t
n)
442
{
return
KernelArg(CONSTANT, 0, 1, 1, (
void*)arr, n); }
458
const
String& buildopts = String(), String* errmsg=0);
466
bool
create(
const
char* kname,
const
Program& prog);
468
const
String& buildopts, String* errmsg=0);
470
int
set(
int
i,
const
void* value,
size_t
sz);
471
int
set(
int
i,
const
Image2D& image2D);
472
int
set(
int
i,
const
UMat& m);
474
template<
typename
_Tp>
int
set(
int
i,
const
_Tp& value)
475
{
return
set(i, &value,
sizeof(value)); }
479
template<
typename
_Tp0>
inline
480
int
set_args_(
int
i,
const
_Tp0& a0) {
return
set(i, a0); }
481
template<
typename
_Tp0,
typename... _Tps>
inline
482
int
set_args_(
int
i,
const
_Tp0& a0,
const
_Tps&... rest_args) { i = set(i, a0);
return
set_args_(i, rest_args...); }
495
template<
typename... _Tps>
inline
496
Kernel&
args(
const
_Tps&... kernel_args) { set_args_(0, kernel_args...);
return
*
this; }
509
bool
run(
int
dims,
size_t
globalsize[],
510
size_t
localsize[],
bool
sync,
const
Queue& q=
Queue());
511
bool
runTask(
bool
sync,
const
Queue& q=
Queue());
519
size_t
workGroupSize()
const;
520
size_t
preferedWorkGroupSizeMultiple()
const;
521
bool
compileWorkGroupSize(
size_t
wsz[])
const;
522
size_t
localMemSize()
const;
536
const
String& buildflags, String& errmsg);
544
const
String& buildflags, String& errmsg);
559
struct
Impl;
friend
struct
Impl;
560
inline
Impl* getImpl()
const
{
return
(Impl*)p; }
561
inline
bool
empty()
const
{
return
!p; }
565
#ifndef OPENCV_REMOVE_DEPRECATED_API
567
CV_DEPRECATED
bool
read(
const
String& buf,
const
String& buildflags);
568
CV_DEPRECATED
bool
write(String& buf)
const;
569
CV_DEPRECATED
const
ProgramSource& source()
const;
570
CV_DEPRECATED String getPrefix()
const;
571
CV_DEPRECATED
static
String getPrefix(
const
String& buildflags);
579
typedef
uint64 hash_t;
582
explicit
ProgramSource(
const
String& module,
const
String& name,
const
String& codeStr,
const
String& codeHash);
591
const
String& source()
const;
610
const
unsigned
char* binary,
const
size_t
size,
611
const
cv::String& buildOptions = cv::String());
635
const
unsigned
char* binary,
const
size_t
size,
636
const
cv::String& buildOptions = cv::String());
643
struct
Impl;
friend
struct
Impl;
644
inline
Impl* getImpl()
const
{
return
(Impl*)p; }
645
inline
bool
empty()
const
{
return
!p; }
666
String vendor()
const;
670
int
versionMajor()
const;
671
int
versionMinor()
const;
673
int
deviceNumber()
const;
677
bool
empty()
const
{
return
!p; }
682CV_EXPORTS
const
char* convertTypeStr(
int
sdepth,
int
ddepth,
int
cn,
char* buf);
683CV_EXPORTS
const
char* typeToStr(
int
t);
684CV_EXPORTS
const
char* memopTypeToStr(
int
t);
685CV_EXPORTS
const
char* vecopTypeToStr(
int
t);
686CV_EXPORTS
const
char* getOpenCLErrorString(
int
errorCode);
687CV_EXPORTS String kernelToStr(InputArray _kernel,
int
ddepth = -1,
const
char
* name = NULL);
688CV_EXPORTS
void
getPlatfomsInfo(std::vector<PlatformInfo>& platform_info);
691
enum
OclVectorStrategy
700
OCL_VECTOR_DEFAULT = OCL_VECTOR_OWN
703CV_EXPORTS
int
predictOptimalVectorWidth(InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(),
704
InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(),
705
InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray(),
706
OclVectorStrategy strat = OCL_VECTOR_DEFAULT);
708CV_EXPORTS
int
checkOptimalVectorWidth(
const
int
*vectorWidths,
709
InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(),
710
InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(),
711
InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray(),
712
OclVectorStrategy strat = OCL_VECTOR_DEFAULT);
715CV_EXPORTS
int
predictOptimalVectorWidthMax(InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(),
716
InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(),
717
InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray());
719CV_EXPORTS
void
buildOptionsAddMatrixDescription(String& buildOptions,
const
String& name, InputArray _m);
743
static
bool
canCreateAlias(const
UMat
&u);
747
static
bool
isFormatSupported(
int
depth,
int
cn,
bool
norm);
763
uint64 durationNS()
const;
798
bool
useOpenCL()
const;
799
void
setUseOpenCL(
bool
flag);
853
inline
bool
empty()
const
{
return
!p; }
856
std::shared_ptr<Impl> p;
879
#ifdef __OPENCV_BUILD
882CV_EXPORTS
bool
isOpenCLForced();
883
#define OCL_FORCE_CHECK(condition) (cv::ocl::internal::isOpenCLForced() || (condition))
885CV_EXPORTS
bool
isPerformanceCheckBypassed();
886
#define OCL_PERFORMANCE_CHECK(condition) (cv::ocl::internal::isPerformanceCheckBypassed() || (condition))
888CV_EXPORTS
bool
isCLBuffer(
UMat& u);
Custom array allocator
Definition:
mat.hpp:470
n-dimensional dense array class
Definition:
mat.hpp:802
void * getOpenCLContextProperty(int propertyId) const
Get OpenCL context property specified on context creation
static Context & getDefault(bool initialize=true)
static Context fromHandle(void *context)
static Device fromHandle(void *d)
Image2D(const UMat &src, bool norm=false, bool alias=false)
bool run(int dims, size_t globalsize[], size_t localsize[], bool sync, const Queue &q=Queue())
Run the OpenCL kernel.
int64 runProfiling(int dims, size_t globalsize[], size_t localsize[], const Queue &q=Queue())
Similar to synchronized run() call with returning of kernel execution time Separate OpenCL command qu...
Kernel & args(const _Tps &... kernel_args)
Setup OpenCL Kernel arguments. Avoid direct using of set(i, ...) methods.
Definition:
ocl.hpp:496
OpenCLExecutionContext cloneWithNewQueue() const
static OpenCLExecutionContext create(const std::string &platformName, void *platformID, void *context, void *deviceID)
Creates OpenCL execution context OpenCV will check if available OpenCL platform has platformName name...
static OpenCLExecutionContext create(const Context &context, const Device &device)
static OpenCLExecutionContext create(const Context &context, const Device &device, const ocl::Queue &queue)
Creates OpenCL execution context
OpenCLExecutionContext cloneWithNewQueue(const ocl::Queue &q) const
static OpenCLExecutionContext & getCurrentRef()
static OpenCLExecutionContext & getCurrent()
Device & getDevice() const
Context & getContext() const
void getBinary(std::vector< char > &binary) const
Query device-specific program binary.
static ProgramSource fromBinary(const String &module, const String &name, const unsigned char *binary, const size_t size, const cv::String &buildOptions=cv::String())
Describe OpenCL program binary. Do not call clCreateProgramWithBinary() and/or clBuildProgram().
static ProgramSource fromSPIR(const String &module, const String &name, const unsigned char *binary, const size_t size, const cv::String &buildOptions=cv::String())
Describe OpenCL program in SPIR format. Do not call clCreateProgramWithBinary() and/or clBuildProgram...
const Queue & getProfilingQueue() const
Returns OpenCL command queue with enable profiling mode support
CV_EXPORTS_W double norm(InputArray src1, int normType=NORM_L2, InputArray mask=noArray())
Calculates the absolute norm of an array.
void initializeContextFromHandle(Context &ctx, void *platform, void *context, void *device)
CV_EXPORTS void convertFromImage(void *cl_mem_image, UMat &dst)
Convert OpenCL image2d_t to UMat
CV_EXPORTS void attachContext(const String &platformName, void *platformID, void *context, void *deviceID)
Attaches OpenCL context to OpenCV
CV_EXPORTS void convertFromBuffer(void *cl_mem_buffer, size_t step, int rows, int cols, int type, UMat &dst)
Convert OpenCL buffer to UMat
#define CV_Assert(expr)
Checks a condition at runtime and throws exception if it fails
Definition:
base.hpp:342
CV_EXPORTS_W int getDevice()
Returns the current device index set by cuda::setDevice or initialized by default.
"black box" representation of the file storage associated with a file on disk.
Definition:
aruco.hpp:75