mexopencv  3.4.1
MEX interface for OpenCV library
Utils_.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
12 // HAVE_IPP, HAVE_OPENVX, HAVE_OPENCL, HAVE_CUDA, HAVE_TEGRA_OPTIMIZATION
13 #include "opencv2/cvconfig.h"
14 #include "opencv2/core/ocl.hpp"
15 #include "opencv2/core/cuda.hpp"
16 
17 namespace {
22 MxArray toMxArray(size_t i)
23 {
25  if (arr.isNull())
26  mexErrMsgIdAndTxt("mexopencv:error", "Allocation error");
27  arr.set(0, static_cast<uint64_t>(i));
28  return arr;
29 }
30 
36 {
38  if (arr.isNull())
39  mexErrMsgIdAndTxt("mexopencv:error", "Allocation error");
40  for (size_t i = 0; i < v.size(); ++i)
41  arr.set(i, static_cast<uint64_t>(v[i]));
42  return arr;
43 }
44 
50  (cv::ocl::Device::TYPE_ACCELERATOR, "Accelerator")
53 
56  (cv::ocl::Device::NO_CACHE, "NoCache")
57  (cv::ocl::Device::READ_ONLY_CACHE, "ReadOnlyCache")
58  (cv::ocl::Device::READ_WRITE_CACHE, "ReadWriteCache");
59 
62  (cv::ocl::Device::NO_LOCAL_MEM, "NoLocalMem")
63  (cv::ocl::Device::LOCAL_IS_LOCAL, "LocalIsLocal")
64  (cv::ocl::Device::LOCAL_IS_GLOBAL, "LocalIsGlobal");
65 
72 
79 
85 {
86  const char *fields[8] = {"Denorm", "InfNaN", "RoundToNearest",
87  "RoundToZero", "RoundToInf", "FMA", "SoftFloat",
88  "CorrectlyRoundedDivideSqrt"};
89  MxArray s = MxArray::Struct(fields, 8);
90  s.set(fields[0], (flags & cv::ocl::Device::FP_DENORM) != 0);
91  s.set(fields[1], (flags & cv::ocl::Device::FP_INF_NAN) != 0);
92  s.set(fields[2], (flags & cv::ocl::Device::FP_ROUND_TO_NEAREST) != 0);
93  s.set(fields[3], (flags & cv::ocl::Device::FP_ROUND_TO_ZERO) != 0);
94  s.set(fields[4], (flags & cv::ocl::Device::FP_ROUND_TO_INF) != 0);
95  s.set(fields[5], (flags & cv::ocl::Device::FP_FMA) != 0);
96  s.set(fields[6], (flags & cv::ocl::Device::FP_SOFT_FLOAT) != 0);
97  s.set(fields[7], (flags & cv::ocl::Device::FP_CORRECTLY_ROUNDED_DIVIDE_SQRT) != 0);
98  return s;
99 }
100 
106 {
107  const char *fields[2] = {"Kernel", "NativeKernel"};
108  MxArray s = MxArray::Struct(fields, 2);
109  s.set(fields[0], (flags & cv::ocl::Device::EXEC_KERNEL) != 0);
110  s.set(fields[1], (flags & cv::ocl::Device::EXEC_NATIVE_KERNEL) != 0);
111  return s;
112 }
113 
119 {
120  const char *fieldsP[4] = {"name", "vendor", "version", "device"};
121  const char *fieldsD[68] = {"name", "extensions", "version", "vendorName",
122  "OpenCL_C_Version", "OpenCLVersion", "deviceVersionMajor",
123  "deviceVersionMinor", "driverVersion", "type", "addressBits",
124  "available", "compilerAvailable", "linkerAvailable", "doubleFPConfig",
125  "singleFPConfig", "halfFPConfig", "endianLittle",
126  "errorCorrectionSupport", "executionCapabilities",
127  "globalMemCacheSize", "globalMemCacheType", "globalMemCacheLineSize",
128  "globalMemSize", "localMemSize", "localMemType", "hostUnifiedMemory",
129  "imageSupport", "imageFromBufferSupport", "imagePitchAlignment",
130  "imageBaseAddressAlignment", "image2DMaxWidth", "image2DMaxHeight",
131  "image3DMaxWidth", "image3DMaxHeight", "image3DMaxDepth",
132  "imageMaxBufferSize", "imageMaxArraySize", "vendorID",
133  "maxClockFrequency", "maxComputeUnits", "maxConstantArgs",
134  "maxConstantBufferSize", "maxMemAllocSize", "maxParameterSize",
135  "maxReadImageArgs", "maxWriteImageArgs", "maxSamplers",
136  "maxWorkGroupSize", "maxWorkItemDims", "maxWorkItemSizes",
137  "memBaseAddrAlign", "nativeVectorWidthChar", "nativeVectorWidthShort",
138  "nativeVectorWidthInt", "nativeVectorWidthLong",
139  "nativeVectorWidthFloat", "nativeVectorWidthDouble",
140  "nativeVectorWidthHalf", "preferredVectorWidthChar",
141  "preferredVectorWidthShort", "preferredVectorWidthInt",
142  "preferredVectorWidthLong", "preferredVectorWidthFloat",
143  "preferredVectorWidthDouble", "preferredVectorWidthHalf",
144  "printfBufferSize", "profilingTimerResolution"};
145  MxArray sp = MxArray::Struct(fieldsP, 4, 1, vpi.size());
146  for (size_t i = 0; i < vpi.size(); ++i) {
147  const cv::ocl::PlatformInfo &pi = vpi[i];
148  MxArray sd = MxArray::Struct(fieldsD, 68, 1, pi.deviceNumber());
149  for (int j = 0; j < pi.deviceNumber(); ++j) {
150  cv::ocl::Device di;
151  pi.getDevice(di, j);
152  sd.set(fieldsD[0], di.name(), j);
153  sd.set(fieldsD[1], di.extensions(), j);
154  sd.set(fieldsD[2], di.version(), j);
155  sd.set(fieldsD[3], di.vendorName(), j);
156  sd.set(fieldsD[4], di.OpenCL_C_Version(), j);
157  sd.set(fieldsD[5], di.OpenCLVersion(), j);
158  sd.set(fieldsD[6], di.deviceVersionMajor(), j);
159  sd.set(fieldsD[7], di.deviceVersionMinor(), j);
160  sd.set(fieldsD[8], di.driverVersion(), j);
161  sd.set(fieldsD[9], OCLTypeMap[di.type()], j);
162  sd.set(fieldsD[10], di.addressBits(), j);
163  sd.set(fieldsD[11], di.available(), j);
164  sd.set(fieldsD[12], di.compilerAvailable(), j);
165  sd.set(fieldsD[13], di.linkerAvailable(), j);
166  sd.set(fieldsD[14], toFPConfigStruct(di.doubleFPConfig()), j);
167  sd.set(fieldsD[15], toFPConfigStruct(di.singleFPConfig()), j);
168  sd.set(fieldsD[16], toFPConfigStruct(di.halfFPConfig()), j);
169  sd.set(fieldsD[17], di.endianLittle(), j);
170  sd.set(fieldsD[18], di.errorCorrectionSupport(), j);
171  sd.set(fieldsD[19], toExecCapStruct(di.executionCapabilities()), j);
172  sd.set(fieldsD[20], toMxArray(di.globalMemCacheSize()), j);
173  sd.set(fieldsD[21], OCLCacheMap[di.globalMemCacheType()], j);
174  sd.set(fieldsD[22], di.globalMemCacheLineSize(), j);
175  sd.set(fieldsD[23], toMxArray(di.globalMemSize()), j);
176  sd.set(fieldsD[24], toMxArray(di.localMemSize()), j);
177  sd.set(fieldsD[25], OCLMemMap[di.localMemType()], j);
178  sd.set(fieldsD[26], di.hostUnifiedMemory(), j);
179  sd.set(fieldsD[27], di.imageSupport(), j);
180  sd.set(fieldsD[28], di.imageFromBufferSupport(), j);
181  sd.set(fieldsD[29], static_cast<int>(di.imagePitchAlignment()), j);
182  sd.set(fieldsD[30], static_cast<int>(di.imageBaseAddressAlignment()), j);
183  sd.set(fieldsD[31], toMxArray(di.image2DMaxWidth()), j);
184  sd.set(fieldsD[32], toMxArray(di.image2DMaxHeight()), j);
185  sd.set(fieldsD[33], toMxArray(di.image3DMaxWidth()), j);
186  sd.set(fieldsD[34], toMxArray(di.image3DMaxHeight()), j);
187  sd.set(fieldsD[35], toMxArray(di.image3DMaxDepth()), j);
188  sd.set(fieldsD[36], toMxArray(di.imageMaxBufferSize()), j);
189  sd.set(fieldsD[37], toMxArray(di.imageMaxArraySize()), j);
190  sd.set(fieldsD[38], OCLVendorMap[di.vendorID()], j);
191  sd.set(fieldsD[39], di.maxClockFrequency(), j);
192  sd.set(fieldsD[40], di.maxComputeUnits(), j);
193  sd.set(fieldsD[41], di.maxConstantArgs(), j);
194  sd.set(fieldsD[42], toMxArray(di.maxConstantBufferSize()), j);
195  sd.set(fieldsD[43], toMxArray(di.maxMemAllocSize()), j);
196  sd.set(fieldsD[44], toMxArray(di.maxParameterSize()), j);
197  sd.set(fieldsD[45], di.maxReadImageArgs(), j);
198  sd.set(fieldsD[46], di.maxWriteImageArgs(), j);
199  sd.set(fieldsD[47], di.maxSamplers(), j);
200  sd.set(fieldsD[48], toMxArray(di.maxWorkGroupSize()), j);
201  sd.set(fieldsD[49], di.maxWorkItemDims(), j);
202  {
203  vector<size_t> mwis(32); // MAX_DIMS
204  di.maxWorkItemSizes(&mwis[0]);
205  mwis.resize(di.maxWorkItemDims());
206  sd.set(fieldsD[50], toMxArray(mwis), j);
207  }
208  sd.set(fieldsD[51], di.memBaseAddrAlign(), j);
209  sd.set(fieldsD[52], di.nativeVectorWidthChar(), j);
210  sd.set(fieldsD[53], di.nativeVectorWidthShort(), j);
211  sd.set(fieldsD[54], di.nativeVectorWidthInt(), j);
212  sd.set(fieldsD[55], di.nativeVectorWidthLong(), j);
213  sd.set(fieldsD[56], di.nativeVectorWidthFloat(), j);
214  sd.set(fieldsD[57], di.nativeVectorWidthDouble(), j);
215  sd.set(fieldsD[58], di.nativeVectorWidthHalf(), j);
216  sd.set(fieldsD[59], di.preferredVectorWidthChar(), j);
217  sd.set(fieldsD[60], di.preferredVectorWidthShort(), j);
218  sd.set(fieldsD[61], di.preferredVectorWidthInt(), j);
219  sd.set(fieldsD[62], di.preferredVectorWidthLong(), j);
220  sd.set(fieldsD[63], di.preferredVectorWidthFloat(), j);
221  sd.set(fieldsD[64], di.preferredVectorWidthDouble(), j);
222  sd.set(fieldsD[65], di.preferredVectorWidthHalf(), j);
223  sd.set(fieldsD[66], toMxArray(di.printfBufferSize()), j);
224  sd.set(fieldsD[67], toMxArray(di.profilingTimerResolution()), j);
225  }
226  sp.set(fieldsP[0], pi.name(), i);
227  sp.set(fieldsP[1], pi.vendor(), i);
228  sp.set(fieldsP[2], pi.version(), i);
229  sp.set(fieldsP[3], sd, i);
230  }
231  return sp;
232 }
233 
239 {
240  const char *fields[57] = {"deviceID", "name", "totalGlobalMem",
241  "sharedMemPerBlock", "regsPerBlock", "warpSize", "memPitch",
242  "maxThreadsPerBlock", "maxThreadsDim", "maxGridSize", "clockRate",
243  "totalConstMem", "majorVersion", "minorVersion", "textureAlignment",
244  "texturePitchAlignment", "multiProcessorCount",
245  "kernelExecTimeoutEnabled", "integrated", "canMapHostMemory",
246  "computeMode", "maxTexture1D", "maxTexture1DMipmap",
247  "maxTexture1DLinear", "maxTexture2D", "maxTexture2DMipmap",
248  "maxTexture2DLinear", "maxTexture2DGather", "maxTexture3D",
249  "maxTextureCubemap", "maxTexture1DLayered", "maxTexture2DLayered",
250  "maxTextureCubemapLayered", "maxSurface1D", "maxSurface2D",
251  "maxSurface3D", "maxSurface1DLayered", "maxSurface2DLayered",
252  "maxSurfaceCubemap", "maxSurfaceCubemapLayered", "surfaceAlignment",
253  "concurrentKernels", "ECCEnabled", "pciBusID", "pciDeviceID",
254  "pciDomainID", "tccDriver", "asyncEngineCount", "unifiedAddressing",
255  "memoryClockRate", "memoryBusWidth", "l2CacheSize",
256  "maxThreadsPerMultiProcessor", "freeMemory", "totalMemory",
257  "supports", "isCompatible"};
258  MxArray s = MxArray::Struct(fields, 57);
259  s.set(fields[0], di.deviceID());
260  s.set(fields[1], di.name());
261  s.set(fields[2], toMxArray(di.totalGlobalMem()));
262  s.set(fields[3], toMxArray(di.sharedMemPerBlock()));
263  s.set(fields[4], di.regsPerBlock());
264  s.set(fields[5], di.warpSize());
265  s.set(fields[6], toMxArray(di.memPitch()));
266  s.set(fields[7], di.maxThreadsPerBlock());
267  s.set(fields[8], di.maxThreadsDim());
268  s.set(fields[9], di.maxGridSize());
269  s.set(fields[10], di.clockRate());
270  s.set(fields[11], toMxArray(di.totalConstMem()));
271  s.set(fields[12], di.majorVersion());
272  s.set(fields[13], di.minorVersion());
273  s.set(fields[14], toMxArray(di.textureAlignment()));
274  s.set(fields[15], toMxArray(di.texturePitchAlignment()));
275  s.set(fields[16], di.multiProcessorCount());
276  s.set(fields[17], di.kernelExecTimeoutEnabled());
277  s.set(fields[18], di.integrated());
278  s.set(fields[19], di.canMapHostMemory());
279  s.set(fields[20], CUDAComputeModeMap[di.computeMode()]);
280  s.set(fields[21], di.maxTexture1D());
281  s.set(fields[22], di.maxTexture1DMipmap());
282  s.set(fields[23], di.maxTexture1DLinear());
283  s.set(fields[24], di.maxTexture2D());
284  s.set(fields[25], di.maxTexture2DMipmap());
285  s.set(fields[26], di.maxTexture2DLinear());
286  s.set(fields[27], di.maxTexture2DGather());
287  s.set(fields[28], di.maxTexture3D());
288  s.set(fields[29], di.maxTextureCubemap());
289  s.set(fields[30], di.maxTexture1DLayered());
290  s.set(fields[31], di.maxTexture2DLayered());
291  s.set(fields[32], di.maxTextureCubemapLayered());
292  s.set(fields[33], di.maxSurface1D());
293  s.set(fields[34], di.maxSurface2D());
294  s.set(fields[35], di.maxSurface3D());
295  s.set(fields[36], di.maxSurface1DLayered());
296  s.set(fields[37], di.maxSurface2DLayered());
297  s.set(fields[38], di.maxSurfaceCubemap());
298  s.set(fields[39], di.maxSurfaceCubemapLayered());
299  s.set(fields[40], toMxArray(di.surfaceAlignment()));
300  s.set(fields[41], di.concurrentKernels());
301  s.set(fields[42], di.ECCEnabled());
302  s.set(fields[43], di.pciBusID());
303  s.set(fields[44], di.pciDeviceID());
304  s.set(fields[45], di.pciDomainID());
305  s.set(fields[46], di.tccDriver());
306  s.set(fields[47], di.asyncEngineCount());
307  s.set(fields[48], di.unifiedAddressing());
308  s.set(fields[49], di.memoryClockRate());
309  s.set(fields[50], di.memoryBusWidth());
310  s.set(fields[51], di.l2CacheSize());
311  s.set(fields[52], di.maxThreadsPerMultiProcessor());
312  s.set(fields[53], toMxArray(di.freeMemory()));
313  s.set(fields[54], toMxArray(di.totalMemory()));
314  {
315  const char *fieldsFS[15] = {"Compute10", "Compute11", "Compute12",
316  "Compute13", "Compute20", "Compute21", "Compute30", "Compute32",
317  "Compute35", "Compute50", "GlobalAtomics", "SharedAtomics",
318  "NativeDouble", "WarpShuffleFunctions", "DynamicParallelism"};
319  MxArray sf = MxArray::Struct(fieldsFS, 15);
320  sf.set(fieldsFS[0], di.supports(cv::cuda::FEATURE_SET_COMPUTE_10));
321  sf.set(fieldsFS[1], di.supports(cv::cuda::FEATURE_SET_COMPUTE_11));
322  sf.set(fieldsFS[2], di.supports(cv::cuda::FEATURE_SET_COMPUTE_12));
323  sf.set(fieldsFS[3], di.supports(cv::cuda::FEATURE_SET_COMPUTE_13));
324  sf.set(fieldsFS[4], di.supports(cv::cuda::FEATURE_SET_COMPUTE_20));
325  sf.set(fieldsFS[5], di.supports(cv::cuda::FEATURE_SET_COMPUTE_21));
326  sf.set(fieldsFS[6], di.supports(cv::cuda::FEATURE_SET_COMPUTE_30));
327  sf.set(fieldsFS[7], di.supports(cv::cuda::FEATURE_SET_COMPUTE_32));
328  sf.set(fieldsFS[8], di.supports(cv::cuda::FEATURE_SET_COMPUTE_35));
329  sf.set(fieldsFS[9], di.supports(cv::cuda::FEATURE_SET_COMPUTE_50));
330  sf.set(fieldsFS[10], di.supports(cv::cuda::GLOBAL_ATOMICS));
331  sf.set(fieldsFS[11], di.supports(cv::cuda::SHARED_ATOMICS));
332  sf.set(fieldsFS[12], di.supports(cv::cuda::NATIVE_DOUBLE));
333  sf.set(fieldsFS[13], di.supports(cv::cuda::WARP_SHUFFLE_FUNCTIONS));
334  sf.set(fieldsFS[14], di.supports(cv::cuda::DYNAMIC_PARALLELISM));
335  s.set(fields[55], sf);
336  }
337  s.set(fields[56], di.isCompatible());
338  return s;
339 }
340 }
341 
349 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
350 {
351  // Check the number of arguments
352  nargchk((nrhs==1 || nrhs==2) && nlhs<=1);
353 
354  // Argument vector
355  vector<MxArray> rhs(prhs, prhs+nrhs);
356  string method(rhs[0].toString());
357 
358  // Operation switch
359  if (method == "checkHardwareSupport") {
360  nargchk(nrhs==1 && nlhs<=1);
361  const char *fields[24] = {"MMX", "SSE", "SSE2", "SSE3", "SSSE3",
362  "SSE4_1", "SSE4_2", "POPCNT", "FP16", "AVX", "AVX2", "FMA3",
363  "AVX_512F", "AVX_512BW", "AVX_512CD", "AVX_512DQ", "AVX_512ER",
364  "AVX_512IFMA", "AVX_512PF", "AVX_512VBMI", "AVX_512VL", "NEON",
365  "VSX", "AVX512_SKX"};
366  MxArray s = MxArray::Struct(fields, 24);
367  s.set(fields[0], checkHardwareSupport(CV_CPU_MMX));
368  s.set(fields[1], checkHardwareSupport(CV_CPU_SSE));
369  s.set(fields[2], checkHardwareSupport(CV_CPU_SSE2));
370  s.set(fields[3], checkHardwareSupport(CV_CPU_SSE3));
371  s.set(fields[4], checkHardwareSupport(CV_CPU_SSSE3));
372  s.set(fields[5], checkHardwareSupport(CV_CPU_SSE4_1));
373  s.set(fields[6], checkHardwareSupport(CV_CPU_SSE4_2));
374  s.set(fields[7], checkHardwareSupport(CV_CPU_POPCNT));
375  s.set(fields[8], checkHardwareSupport(CV_CPU_FP16));
376  s.set(fields[9], checkHardwareSupport(CV_CPU_AVX));
377  s.set(fields[10], checkHardwareSupport(CV_CPU_AVX2));
378  s.set(fields[11], checkHardwareSupport(CV_CPU_FMA3));
379  s.set(fields[12], checkHardwareSupport(CV_CPU_AVX_512F));
380  s.set(fields[13], checkHardwareSupport(CV_CPU_AVX_512BW));
381  s.set(fields[14], checkHardwareSupport(CV_CPU_AVX_512CD));
382  s.set(fields[15], checkHardwareSupport(CV_CPU_AVX_512DQ));
383  s.set(fields[16], checkHardwareSupport(CV_CPU_AVX_512ER));
385  s.set(fields[18], checkHardwareSupport(CV_CPU_AVX_512PF));
387  s.set(fields[20], checkHardwareSupport(CV_CPU_AVX_512VL));
388  s.set(fields[21], checkHardwareSupport(CV_CPU_NEON));
389  s.set(fields[22], checkHardwareSupport(CV_CPU_VSX));
391  plhs[0] = s;
392  }
393  else if (method == "getHardwareFeatureName") {
394  nargchk(nrhs==2 && nlhs<=1);
395  int feature = rhs[1].toInt();
396  string name = getHardwareFeatureName(feature);
397  plhs[0] = MxArray(name);
398  }
399  else if (method == "getBuildInformation") {
400  nargchk(nrhs==1 && nlhs<=1);
401  plhs[0] = MxArray(getBuildInformation());
402  }
403  else if (method == "version") {
404  nargchk(nrhs==1 && nlhs<=1);
405  plhs[0] = MxArray(string(CV_VERSION));
406  }
407  else if (method == "getNumberOfCPUs") {
408  nargchk(nrhs==1 && nlhs<=1);
409  plhs[0] = MxArray(getNumberOfCPUs());
410  }
411  else if (method == "getNumThreads") {
412  nargchk(nrhs==1 && nlhs<=1);
413  plhs[0] = MxArray(getNumThreads());
414  }
415  else if (method == "setNumThreads") {
416  nargchk(nrhs==2 && nlhs==0);
417  setNumThreads(rhs[1].toInt());
418  }
419  else if (method == "useOptimized") {
420  nargchk(nrhs==1 && nlhs<=1);
421  plhs[0] = MxArray(useOptimized());
422  }
423  else if (method == "setUseOptimized") {
424  nargchk(nrhs==2 && nlhs==0);
425  setUseOptimized(rhs[1].toBool());
426  }
427  else if (method == "getIppVersion") {
428  nargchk(nrhs==1 && nlhs<=1);
429  plhs[0] = MxArray(ipp::getIppVersion());
430  }
431  else if (method == "useIPP") {
432  nargchk(nrhs==1 && nlhs<=1);
433  plhs[0] = MxArray(ipp::useIPP());
434  }
435  else if (method == "setUseIPP") {
436  nargchk(nrhs==2 && nlhs==0);
437  ipp::setUseIPP(rhs[1].toBool());
438  }
439  else if (method == "useIPP_NE") {
440  nargchk(nrhs==1 && nlhs<=1);
441  plhs[0] = MxArray(ipp::useIPP_NE());
442  }
443  else if (method == "setUseIPP_NE") {
444  nargchk(nrhs==2 && nlhs==0);
445  ipp::setUseIPP_NE(rhs[1].toBool());
446  }
447  else if (method == "haveOpenVX") {
448  nargchk(nrhs==1 && nlhs<=1);
449  plhs[0] = MxArray(haveOpenVX());
450  }
451  else if (method == "useOpenVX") {
452  nargchk(nrhs==1 && nlhs<=1);
453  plhs[0] = MxArray(useOpenVX());
454  }
455  else if (method == "setUseOpenVX") {
456  nargchk(nrhs==2 && nlhs==0);
457  setUseOpenVX(rhs[1].toBool());
458  }
459  else if (method == "haveOpenCL") {
460  nargchk(nrhs==1 && nlhs<=1);
461  plhs[0] = MxArray(ocl::haveOpenCL());
462  }
463  else if (method == "haveAmdBlas") {
464  nargchk(nrhs==1 && nlhs<=1);
465  plhs[0] = MxArray(ocl::haveAmdBlas());
466  }
467  else if (method == "haveAmdFft") {
468  nargchk(nrhs==1 && nlhs<=1);
469  plhs[0] = MxArray(ocl::haveAmdFft());
470  }
471  else if (method == "haveSVM") {
472  nargchk(nrhs==1 && nlhs<=1);
473  plhs[0] = MxArray(ocl::haveSVM());
474  }
475  else if (method == "useOpenCL") {
476  nargchk(nrhs==1 && nlhs<=1);
477  plhs[0] = MxArray(ocl::useOpenCL());
478  }
479  else if (method == "setUseOpenCL") {
480  nargchk(nrhs==2 && nlhs==0);
481  ocl::setUseOpenCL(rhs[1].toBool());
482  }
483  else if (method == "getPlatfomsInfo") {
484  nargchk(nrhs==1 && nlhs<=1);
487  plhs[0] = toStruct(vpi);
488  }
489 #if 0
490  else if (method == "dumpOpenCLInformation") {
491  nargchk(nrhs==1 && nlhs==0);
492  dumpOpenCLInformation();
493  }
494 #endif
495  else if (method == "getCudaEnabledDeviceCount") {
496  nargchk(nrhs==1 && nlhs<=1);
498  }
499  else if (method == "getDevice") {
500  nargchk(nrhs==1 && nlhs<=1);
501  plhs[0] = MxArray(cuda::getDevice());
502  }
503  else if (method == "setDevice") {
504  nargchk(nrhs==2 && nlhs==0);
505  cuda::setDevice(rhs[1].toInt());
506  }
507  else if (method == "resetDevice") {
508  nargchk(nrhs==1 && nlhs==0);
510  }
511  else if (method == "deviceSupports") {
512  nargchk(nrhs==1 && nlhs<=1);
513  const char *fields[10] = {"Compute10", "Compute11", "Compute12",
514  "Compute13", "Compute20", "Compute21", "Compute30", "Compute32",
515  "Compute35", "Compute50"};
516  MxArray s = MxArray::Struct(fields, 10);
527  plhs[0] = s;
528  }
529  else if (method == "printCudaDeviceInfo") {
530  nargchk(nrhs==2 && nlhs==0);
531  cuda::printCudaDeviceInfo(rhs[1].toInt());
532  }
533  else if (method == "printShortCudaDeviceInfo") {
534  nargchk(nrhs==2 && nlhs==0);
535  cuda::printShortCudaDeviceInfo(rhs[1].toInt());
536  }
537  else if (method == "deviceInfo") {
538  nargchk(nrhs==2 && nlhs<=1);
539  cuda::DeviceInfo di(rhs[1].toInt());
540  plhs[0] = toStruct(di);
541  }
542  else if (method == "useTegra") {
543  nargchk(nrhs==1 && nlhs<=1);
544 #ifdef HAVE_TEGRA_OPTIMIZATION
545  plhs[0] = MxArray(tegra::useTegra());
546 #else
547  plhs[0] = MxArray(false);
548 #endif
549  }
550  else if (method == "setUseTegra") {
551  nargchk(nrhs==2 && nlhs==0);
552 #ifdef HAVE_TEGRA_OPTIMIZATION
553  tegra::setUseTegra(rhs[1].toBool());
554 #endif
555  }
556  else
557  mexErrMsgIdAndTxt("mexopencv:error",
558  "Unrecognized operation %s", method.c_str());
559 }
String extensions() const
#define CV_CPU_SSE4_1
bool ECCEnabled() const
MxArray toStruct(const cv::cuda::DeviceInfo &di)
Convert CUDA device info to struct array.
Definition: Utils_.cpp:238
bool useOpenCL()
#define CV_CPU_AVX_512DQ
void setDevice(int device)
int pciDeviceID() const
bool canMapHostMemory() const
FEATURE_SET_COMPUTE_11
size_t maxWorkGroupSize() const
void getPlatfomsInfo(std::vector< PlatformInfo > &platform_info)
Vec3i maxGridSize() const
#define CV_CPU_POPCNT
int preferredVectorWidthHalf() const
int deviceVersionMajor() const
size_t surfaceAlignment() const
String OpenCL_C_Version() const
int l2CacheSize() const
uint imageBaseAddressAlignment() const
bool unifiedAddressing() const
int preferredVectorWidthFloat() const
int memBaseAddrAlign() const
int nativeVectorWidthFloat() const
#define CV_CPU_AVX_512VL
Vec3i maxTexture3D() const
String name() const
MxArray toExecCapStruct(int flags)
Convert OpenCL execution capabilities bit-field to MxArray.
Definition: Utils_.cpp:105
size_t imageMaxArraySize() const
#define CV_CPU_AVX_512IFMA
static softfloat pi()
bool tccDriver() const
Vec3i maxTexture2DLayered() const
#define CV_VERSION
MxArray toFPConfigStruct(int flags)
Convert OpenCL FP config bit-field to MxArray.
Definition: Utils_.cpp:84
int maxSurfaceCubemap() const
size_t imageMaxBufferSize() const
#define CV_CPU_SSE2
bool available() const
#define CV_CPU_FMA3
const ConstMap< int, string > OCLTypeMap
OpenCL device type.
Definition: Utils_.cpp:46
Vec3i maxTexture2DLinear() const
int deviceVersionMinor() const
#define CV_CPU_MMX
Identifies a numeric mxArray whose data is stored as the type specified in the MATLAB Primitive Types...
Definition: matrix.h:306
int maxClockFrequency() const
const String & getBuildInformation()
size_t localMemSize() const
size_t image3DMaxDepth() const
bool haveAmdFft()
FEATURE_SET_COMPUTE_32
STL namespace.
bool hostUnifiedMemory() const
int vendorID() const
Vec2i maxSurface1DLayered() const
size_t freeMemory() const
int maxTexture1DMipmap() const
Vec2i maxTexture2DGather() const
Vec3i maxThreadsDim() const
int localMemType() const
int maxWorkItemDims() const
int maxThreadsPerBlock() const
bool linkerAvailable() const
size_t maxMemAllocSize() const
void setNumThreads(int nthreads)
size_t maxConstantBufferSize() const
#define CV_CPU_AVX_512PF
Vec2i maxSurfaceCubemapLayered() const
bool isCompatible() const
#define CV_CPU_AVX_512CD
String OpenCLVersion() const
int maxTexture1DLinear() const
int maxConstantArgs() const
int asyncEngineCount() const
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
int addressBits() const
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
Definition: MxArray.hpp:1310
bool supports(FeatureSet feature_set) const
int getCudaEnabledDeviceCount()
bool endianLittle() const
int getNumThreads()
size_t image2DMaxWidth() const
#define CV_CPU_SSE3
int preferredVectorWidthInt() const
const char * name() const
#define CV_CPU_AVX_512VBMI
Vec2i maxTexture2DMipmap() const
void setUseOpenVX(bool flag)
T resize(T... args)
size_t globalMemSize() const
int singleFPConfig() const
FEATURE_SET_COMPUTE_12
String version() const
int nativeVectorWidthHalf() const
FEATURE_SET_COMPUTE_35
const ConstMap< int, string > OCLVendorMap
OpenCL vendor name.
Definition: Utils_.cpp:67
size_t texturePitchAlignment() const
void printCudaDeviceInfo(int device)
void setUseOpenCL(bool flag)
bool haveOpenCL()
size_t image3DMaxHeight() const
size_t globalMemCacheSize() const
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: Utils_.cpp:349
int nativeVectorWidthInt() const
int type() const
FEATURE_SET_COMPUTE_20
bool useOpenVX()
int maxTexture1D() const
MxArray toMxArray(const std::vector< size_t > &v)
Convert vector of size type to MxArray.
Definition: Utils_.cpp:35
size_t totalMemory() const
int maxWriteImageArgs() const
int preferredVectorWidthChar() const
bool haveSVM()
int preferredVectorWidthLong() const
uint32_t v
void printShortCudaDeviceInfo(int device)
String vendorName() const
#define CV_CPU_AVX_512F
size_t textureAlignment() const
#define CV_CPU_SSE
int clockRate() const
int memoryBusWidth() const
Vec2i maxSurface2D() const
#define CV_CPU_AVX2
#define CV_CPU_SSSE3
size_t sharedMemPerBlock() const
size_t totalGlobalMem() const
bool compilerAvailable() const
int multiProcessorCount() const
int pciBusID() const
bool imageFromBufferSupport() const
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
int nativeVectorWidthShort() const
int getNumberOfCPUs()
FEATURE_SET_COMPUTE_30
#define mxCreateNumericMatrix
Definition: matrix.h:1516
size_t maxParameterSize() const
void setUseOptimized(bool onoff)
#define CV_CPU_AVX512_SKX
const ConstMap< int, string > CUDAComputeModeMap
CUDA device compute modes.
Definition: Utils_.cpp:74
int globalMemCacheLineSize() const
bool kernelExecTimeoutEnabled() const
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/output arguments number check.
Definition: mexopencv.hpp:181
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
Definition: MxArray.hpp:312
int executionCapabilities() const
size_t image2DMaxHeight() const
String driverVersion() const
int deviceID() const
bool errorCorrectionSupport() const
FEATURE_SET_COMPUTE_13
Vec2i maxTexture2D() const
int majorVersion() const
int maxTextureCubemap() const
T size(T... args)
#define CV_CPU_VSX
int doubleFPConfig() const
void maxWorkItemSizes(size_t *) const
int warpSize() const
ComputeMode computeMode() const
#define CV_CPU_NEON
bool checkHardwareSupport(int feature)
int nativeVectorWidthChar() const
int maxSurface1D() const
bool useOptimized()
Global constant definitions.
#define CV_CPU_FP16
size_t printfBufferSize() const
void resetDevice()
const ConstMap< int, string > OCLCacheMap
OpenCL type of global memory cache.
Definition: Utils_.cpp:55
int globalMemCacheType() const
size_t totalConstMem() const
#define CV_CPU_AVX
T c_str(T... args)
Vec2i maxTexture1DLayered() const
int maxReadImageArgs() const
int maxThreadsPerMultiProcessor() const
uint imagePitchAlignment() const
int preferredVectorWidthDouble() const
FEATURE_SET_COMPUTE_10
int maxComputeUnits() const
bool deviceSupports(FeatureSet feature_set)
int preferredVectorWidthShort() const
bool haveAmdBlas()
FEATURE_SET_COMPUTE_50
Vec2i maxTextureCubemapLayered() const
int minorVersion() const
#define CV_CPU_SSE4_2
FEATURE_SET_COMPUTE_21
bool imageSupport() const
int halfFPConfig() const
bool concurrentKernels() const
int regsPerBlock() const
size_t profilingTimerResolution() const
bool integrated() const
WARP_SHUFFLE_FUNCTIONS
int nativeVectorWidthDouble() const
bool isNull() const
Determine whether the array is initialized or not.
Definition: MxArray.hpp:606
int pciDomainID() const
Vec3i maxSurface2DLayered() const
int getDevice()
Vec3i maxSurface3D() const
int memoryClockRate() const
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
bool haveOpenVX()
int maxSamplers() const
#define CV_CPU_AVX_512BW
#define CV_CPU_AVX_512ER
size_t image3DMaxWidth() const
size_t memPitch() const
int nativeVectorWidthLong() const
String getHardwareFeatureName(int feature)
const ConstMap< int, string > OCLMemMap
OpenCL type of local memory.
Definition: Utils_.cpp:61
Identifies an mxArray with no imaginary components.
Definition: matrix.h:325