1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

ocl: low-level API to support OpenCL binary programs

This commit is contained in:
Alexander Alekhin
2017-12-02 17:48:30 +00:00
parent 4d721e368a
commit 13c4a02157
4 changed files with 566 additions and 122 deletions
+66 -8
View File
@@ -606,17 +606,26 @@ public:
bool create(const ProgramSource& src,
const String& buildflags, String& errmsg);
bool read(const String& buf, const String& buildflags);
bool write(String& buf) const;
bool read(const String& buf, const String& buildflags); // deprecated
bool write(String& buf) const; // deprecated
const ProgramSource& source() const;
const ProgramSource& source() const; // deprecated
void* ptr() const;
String getPrefix() const;
static String getPrefix(const String& buildflags);
String getPrefix() const; // deprecated
static String getPrefix(const String& buildflags); // deprecated
struct Impl;
/**
* @brief Query device-specific program binary.
*
* @sa ProgramSource::fromBinary
*
* @param[out] binary output buffer
*/
void getBinary(std::vector<char>& binary) const;
struct Impl; friend struct Impl;
inline Impl* getImpl() const { return (Impl*)p; }
protected:
Impl* p;
@@ -636,10 +645,59 @@ public:
ProgramSource(const ProgramSource& prog);
ProgramSource& operator = (const ProgramSource& prog);
const String& source() const;
const String& source() const; // deprecated
hash_t hash() const; // deprecated
struct Impl;
/** @brief Describe OpenCL program binary.
* Do not call clCreateProgramWithBinary() and/or clBuildProgram().
*
* Caller should guarantee binary buffer lifetime greater than ProgramSource object (and any of its copies).
*
* This kind of binary is not portable between platforms in general - it is specific to OpenCL vendor / device / driver version.
*
* @param module name of program owner module
* @param name unique name of program (module+name is used as key for OpenCL program caching)
* @param binary buffer address. See buffer lifetime requirement in description.
* @param size buffer size
* @param buildOptions additional program-related build options passed to clBuildProgram()
* @return created ProgramSource object
*/
static ProgramSource fromBinary(const String& module, const String& name,
const unsigned char* binary, const size_t size,
const cv::String& buildOptions = cv::String());
/** @brief Describe OpenCL program in SPIR format.
* Do not call clCreateProgramWithBinary() and/or clBuildProgram().
*
* Supports SPIR 1.2 by default (pass '-spir-std=X.Y' in buildOptions to override this behavior)
*
* Caller should guarantee binary buffer lifetime greater than ProgramSource object (and any of its copies).
*
* Programs in this format are portable between OpenCL implementations with 'khr_spir' extension:
* https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/cl_khr_spir.html
* (but they are not portable between different platforms: 32-bit / 64-bit)
*
* Note: these programs can't support vendor specific extensions, like 'cl_intel_subgroups'.
*
* @param module name of program owner module
* @param name unique name of program (module+name is used as key for OpenCL program caching)
* @param binary buffer address. See buffer lifetime requirement in description.
* @param size buffer size
* @param buildOptions additional program-related build options passed to clBuildProgram()
* (these options are added automatically: '-x spir' and '-spir-std=1.2')
* @return created ProgramSource object.
*/
static ProgramSource fromSPIR(const String& module, const String& name,
const unsigned char* binary, const size_t size,
const cv::String& buildOptions = cv::String());
//OpenCL 2.1+ only
//static Program fromSPIRV(const String& module, const String& name,
// const unsigned char* binary, const size_t size,
// const cv::String& buildOptions = cv::String());
struct Impl; friend struct Impl;
inline Impl* getImpl() const { return (Impl*)p; }
protected:
Impl* p;