1 /* See LICENSE file in the root OpenCV directory */
2 
3 #ifndef OPENCV_CORE_OPENCL_SVM_HPP
4 #define OPENCV_CORE_OPENCL_SVM_HPP
5 
6 //
7 // Internal usage only (binary compatibility is not guaranteed)
8 //
9 #ifndef __OPENCV_BUILD
10 #error Internal header file
11 #endif
12 
13 #if defined(HAVE_OPENCL) && defined(HAVE_OPENCL_SVM)
14 #include "runtime/opencl_core.hpp"
15 #include "runtime/opencl_svm_20.hpp"
16 #include "runtime/opencl_svm_hsa_extension.hpp"
17 
18 namespace cv { namespace ocl { namespace svm {
19 
20 struct SVMCapabilities
21 {
22     enum Value
23     {
24         SVM_COARSE_GRAIN_BUFFER = (1 << 0),
25         SVM_FINE_GRAIN_BUFFER = (1 << 1),
26         SVM_FINE_GRAIN_SYSTEM = (1 << 2),
27         SVM_ATOMICS = (1 << 3),
28     };
29     int value_;
30 
SVMCapabilitiescv::ocl::svm::SVMCapabilities31     SVMCapabilities(int capabilities = 0) : value_(capabilities) { }
operator intcv::ocl::svm::SVMCapabilities32     operator int() const { return value_; }
33 
isNoSVMSupportcv::ocl::svm::SVMCapabilities34     inline bool isNoSVMSupport() const { return value_ == 0; }
isSupportCoarseGrainBuffercv::ocl::svm::SVMCapabilities35     inline bool isSupportCoarseGrainBuffer() const { return (value_ & SVM_COARSE_GRAIN_BUFFER) != 0; }
isSupportFineGrainBuffercv::ocl::svm::SVMCapabilities36     inline bool isSupportFineGrainBuffer() const { return (value_ & SVM_FINE_GRAIN_BUFFER) != 0; }
isSupportFineGrainSystemcv::ocl::svm::SVMCapabilities37     inline bool isSupportFineGrainSystem() const { return (value_ & SVM_FINE_GRAIN_SYSTEM) != 0; }
isSupportAtomicscv::ocl::svm::SVMCapabilities38     inline bool isSupportAtomics() const { return (value_ & SVM_ATOMICS) != 0; }
39 };
40 
41 CV_EXPORTS const SVMCapabilities getSVMCapabilitites(const ocl::Context& context);
42 
43 struct SVMFunctions
44 {
45     clSVMAllocAMD_fn fn_clSVMAlloc;
46     clSVMFreeAMD_fn fn_clSVMFree;
47     clSetKernelArgSVMPointerAMD_fn fn_clSetKernelArgSVMPointer;
48     //clSetKernelExecInfoAMD_fn fn_clSetKernelExecInfo;
49     //clEnqueueSVMFreeAMD_fn fn_clEnqueueSVMFree;
50     clEnqueueSVMMemcpyAMD_fn fn_clEnqueueSVMMemcpy;
51     clEnqueueSVMMemFillAMD_fn fn_clEnqueueSVMMemFill;
52     clEnqueueSVMMapAMD_fn fn_clEnqueueSVMMap;
53     clEnqueueSVMUnmapAMD_fn fn_clEnqueueSVMUnmap;
54 
SVMFunctionscv::ocl::svm::SVMFunctions55     inline SVMFunctions()
56         : fn_clSVMAlloc(NULL), fn_clSVMFree(NULL),
57           fn_clSetKernelArgSVMPointer(NULL), /*fn_clSetKernelExecInfo(NULL),*/
58           /*fn_clEnqueueSVMFree(NULL),*/ fn_clEnqueueSVMMemcpy(NULL), fn_clEnqueueSVMMemFill(NULL),
59           fn_clEnqueueSVMMap(NULL), fn_clEnqueueSVMUnmap(NULL)
60     {
61         // nothing
62     }
63 
isValidcv::ocl::svm::SVMFunctions64     inline bool isValid() const
65     {
66         return fn_clSVMAlloc != NULL && fn_clSVMFree && fn_clSetKernelArgSVMPointer &&
67                 /*fn_clSetKernelExecInfo && fn_clEnqueueSVMFree &&*/ fn_clEnqueueSVMMemcpy &&
68                 fn_clEnqueueSVMMemFill && fn_clEnqueueSVMMap && fn_clEnqueueSVMUnmap;
69     }
70 };
71 
72 // We should guarantee that SVMFunctions lifetime is not less than context's lifetime
73 CV_EXPORTS const SVMFunctions* getSVMFunctions(const ocl::Context& context);
74 
75 CV_EXPORTS bool useSVM(UMatUsageFlags usageFlags);
76 
77 }}} //namespace cv::ocl::svm
78 #endif
79 
80 #endif // OPENCV_CORE_OPENCL_SVM_HPP
81 /* End of file. */
82