Home | History | Annotate | Download | only in opencl
      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 
     31     SVMCapabilities(int capabilities = 0) : value_(capabilities) { }
     32     operator int() const { return value_; }
     33 
     34     inline bool isNoSVMSupport() const { return value_ == 0; }
     35     inline bool isSupportCoarseGrainBuffer() const { return (value_ & SVM_COARSE_GRAIN_BUFFER) != 0; }
     36     inline bool isSupportFineGrainBuffer() const { return (value_ & SVM_FINE_GRAIN_BUFFER) != 0; }
     37     inline bool isSupportFineGrainSystem() const { return (value_ & SVM_FINE_GRAIN_SYSTEM) != 0; }
     38     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 
     55     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 
     64     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