Skip to content

Commit 13c4a02

Browse files
committed
ocl: low-level API to support OpenCL binary programs
1 parent 4d721e3 commit 13c4a02

File tree

4 files changed

+565
-121
lines changed

4 files changed

+565
-121
lines changed

modules/core/include/opencv2/core/ocl.hpp

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -606,17 +606,26 @@ class CV_EXPORTS Program
606606

607607
bool create(const ProgramSource& src,
608608
const String& buildflags, String& errmsg);
609-
bool read(const String& buf, const String& buildflags);
610-
bool write(String& buf) const;
609+
bool read(const String& buf, const String& buildflags); // deprecated
610+
bool write(String& buf) const; // deprecated
611611

612-
const ProgramSource& source() const;
612+
const ProgramSource& source() const; // deprecated
613613
void* ptr() const;
614614

615-
String getPrefix() const;
616-
static String getPrefix(const String& buildflags);
615+
String getPrefix() const; // deprecated
616+
static String getPrefix(const String& buildflags); // deprecated
617617

618618

619-
struct Impl;
619+
/**
620+
* @brief Query device-specific program binary.
621+
*
622+
* @sa ProgramSource::fromBinary
623+
*
624+
* @param[out] binary output buffer
625+
*/
626+
void getBinary(std::vector<char>& binary) const;
627+
628+
struct Impl; friend struct Impl;
620629
inline Impl* getImpl() const { return (Impl*)p; }
621630
protected:
622631
Impl* p;
@@ -636,10 +645,59 @@ class CV_EXPORTS ProgramSource
636645
ProgramSource(const ProgramSource& prog);
637646
ProgramSource& operator = (const ProgramSource& prog);
638647

639-
const String& source() const;
648+
const String& source() const; // deprecated
640649
hash_t hash() const; // deprecated
641650

642-
struct Impl;
651+
652+
/** @brief Describe OpenCL program binary.
653+
* Do not call clCreateProgramWithBinary() and/or clBuildProgram().
654+
*
655+
* Caller should guarantee binary buffer lifetime greater than ProgramSource object (and any of its copies).
656+
*
657+
* This kind of binary is not portable between platforms in general - it is specific to OpenCL vendor / device / driver version.
658+
*
659+
* @param module name of program owner module
660+
* @param name unique name of program (module+name is used as key for OpenCL program caching)
661+
* @param binary buffer address. See buffer lifetime requirement in description.
662+
* @param size buffer size
663+
* @param buildOptions additional program-related build options passed to clBuildProgram()
664+
* @return created ProgramSource object
665+
*/
666+
static ProgramSource fromBinary(const String& module, const String& name,
667+
const unsigned char* binary, const size_t size,
668+
const cv::String& buildOptions = cv::String());
669+
670+
/** @brief Describe OpenCL program in SPIR format.
671+
* Do not call clCreateProgramWithBinary() and/or clBuildProgram().
672+
*
673+
* Supports SPIR 1.2 by default (pass '-spir-std=X.Y' in buildOptions to override this behavior)
674+
*
675+
* Caller should guarantee binary buffer lifetime greater than ProgramSource object (and any of its copies).
676+
*
677+
* Programs in this format are portable between OpenCL implementations with 'khr_spir' extension:
678+
* https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/cl_khr_spir.html
679+
* (but they are not portable between different platforms: 32-bit / 64-bit)
680+
*
681+
* Note: these programs can't support vendor specific extensions, like 'cl_intel_subgroups'.
682+
*
683+
* @param module name of program owner module
684+
* @param name unique name of program (module+name is used as key for OpenCL program caching)
685+
* @param binary buffer address. See buffer lifetime requirement in description.
686+
* @param size buffer size
687+
* @param buildOptions additional program-related build options passed to clBuildProgram()
688+
* (these options are added automatically: '-x spir' and '-spir-std=1.2')
689+
* @return created ProgramSource object.
690+
*/
691+
static ProgramSource fromSPIR(const String& module, const String& name,
692+
const unsigned char* binary, const size_t size,
693+
const cv::String& buildOptions = cv::String());
694+
695+
//OpenCL 2.1+ only
696+
//static Program fromSPIRV(const String& module, const String& name,
697+
// const unsigned char* binary, const size_t size,
698+
// const cv::String& buildOptions = cv::String());
699+
700+
struct Impl; friend struct Impl;
643701
inline Impl* getImpl() const { return (Impl*)p; }
644702
protected:
645703
Impl* p;

0 commit comments

Comments
 (0)