code format
This commit is contained in:
@@ -5,22 +5,22 @@
|
||||
* \~russian Классы OpenCL
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
OpenCL wrappers
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
OpenCL wrappers
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
//! \defgroup OpenCL OpenCL
|
||||
//! \~\brief
|
||||
@@ -63,7 +63,6 @@
|
||||
|
||||
class PIP_OPENCL_EXPORT PIOpenCL {
|
||||
public:
|
||||
|
||||
struct KernelArg;
|
||||
struct Device;
|
||||
struct Platform;
|
||||
@@ -90,8 +89,8 @@ public:
|
||||
};
|
||||
|
||||
enum Direction {
|
||||
Input = 0x01,
|
||||
Output = 0x02,
|
||||
Input = 0x01,
|
||||
Output = 0x02,
|
||||
InputOutput = Input | Output,
|
||||
};
|
||||
|
||||
@@ -128,6 +127,7 @@ public:
|
||||
bool is_pointer;
|
||||
ArgType arg_type;
|
||||
int dims;
|
||||
|
||||
private:
|
||||
friend class Kernel;
|
||||
void init(void * _k, uint index);
|
||||
@@ -135,9 +135,13 @@ public:
|
||||
|
||||
|
||||
struct PIP_OPENCL_EXPORT Device {
|
||||
Device() {id = platform_id = 0; max_compute_units = max_clock_frequency = 0; max_memory_size = 0;}
|
||||
bool isValid() const {return id != 0;}
|
||||
PIString displayText() const {return name.trimmed() + " (" + device_version.trimmed() + ")";}
|
||||
Device() {
|
||||
id = platform_id = 0;
|
||||
max_compute_units = max_clock_frequency = 0;
|
||||
max_memory_size = 0;
|
||||
}
|
||||
bool isValid() const { return id != 0; }
|
||||
PIString displayText() const { return name.trimmed() + " (" + device_version.trimmed() + ")"; }
|
||||
void * id;
|
||||
void * platform_id;
|
||||
PIString name;
|
||||
@@ -151,9 +155,9 @@ public:
|
||||
|
||||
|
||||
struct PIP_OPENCL_EXPORT Platform {
|
||||
Platform() {id = 0;}
|
||||
bool isValid() const {return id != 0;}
|
||||
PIString displayText() const {return name.trimmed() + " (" + version.trimmed() + ", " + profile.trimmed() + ")";}
|
||||
Platform() { id = 0; }
|
||||
bool isValid() const { return id != 0; }
|
||||
PIString displayText() const { return name.trimmed() + " (" + version.trimmed() + ", " + profile.trimmed() + ")"; }
|
||||
void * id;
|
||||
PIString name;
|
||||
PIString vendor;
|
||||
@@ -168,41 +172,46 @@ public:
|
||||
friend class Buffer;
|
||||
friend class Program;
|
||||
friend class Kernel;
|
||||
|
||||
public:
|
||||
~Context();
|
||||
void * handle();
|
||||
void * queue();
|
||||
static Context * create(const DeviceList & dl);
|
||||
static Context * create(const Device & d) {return create(DeviceList() << d);}
|
||||
static Context * create(const Device & d) { return create(DeviceList() << d); }
|
||||
static Context * create(const PIString & part_name);
|
||||
Program * createProgram(const PIString & source, const PIStringList & args = PIStringList(), PIString * error = 0);
|
||||
template <typename T> Buffer * createBuffer(PIOpenCL::Direction dir, PIVector <T> & container) {
|
||||
template<typename T>
|
||||
Buffer * createBuffer(PIOpenCL::Direction dir, PIVector<T> & container) {
|
||||
T def = T();
|
||||
return createBuffer(dir, &container, Buffer::cVector , PIByteArray(&def, sizeof(T)), container.size());
|
||||
return createBuffer(dir, &container, Buffer::cVector, PIByteArray(&def, sizeof(T)), container.size());
|
||||
}
|
||||
template <typename T> Buffer * createBuffer(PIOpenCL::Direction dir, PIDeque <T> & container) {
|
||||
template<typename T>
|
||||
Buffer * createBuffer(PIOpenCL::Direction dir, PIDeque<T> & container) {
|
||||
T def = T();
|
||||
return createBuffer(dir, &container, Buffer::cDeque , PIByteArray(&def, sizeof(T)), container.size());
|
||||
return createBuffer(dir, &container, Buffer::cDeque, PIByteArray(&def, sizeof(T)), container.size());
|
||||
}
|
||||
template <typename T> Buffer * createBuffer(PIOpenCL::Direction dir, PIVector2D<T> & container) {
|
||||
template<typename T>
|
||||
Buffer * createBuffer(PIOpenCL::Direction dir, PIVector2D<T> & container) {
|
||||
T def = T();
|
||||
return createBuffer(dir, &container, Buffer::cVector2D, PIByteArray(&def, sizeof(T)), container.size());
|
||||
}
|
||||
template <typename T> Buffer * createBuffer(PIOpenCL::Direction dir, uint elements) {
|
||||
T def = T();
|
||||
template<typename T>
|
||||
Buffer * createBuffer(PIOpenCL::Direction dir, uint elements) {
|
||||
T def = T();
|
||||
Buffer * ret = createBuffer(dir, 0, Buffer::cNone, PIByteArray(&def, sizeof(T)), elements);
|
||||
if (ret)
|
||||
ret->clear();
|
||||
if (ret) ret->clear();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private:
|
||||
Context();
|
||||
void zero();
|
||||
void deletePrograms();
|
||||
void deleteBuffers();
|
||||
Buffer * createBuffer(PIOpenCL::Direction dir, void * container, int type, PIByteArray def, uint elements);
|
||||
PIVector<Program * > programs_;
|
||||
PIVector<Buffer * > buffers_;
|
||||
PIVector<Program *> programs_;
|
||||
PIVector<Buffer *> buffers_;
|
||||
PRIVATE_DECLARATION(PIP_OPENCL_EXPORT)
|
||||
};
|
||||
|
||||
@@ -210,6 +219,7 @@ public:
|
||||
class PIP_OPENCL_EXPORT Buffer {
|
||||
friend class Context;
|
||||
friend class Kernel;
|
||||
|
||||
public:
|
||||
~Buffer();
|
||||
void * handle();
|
||||
@@ -221,7 +231,8 @@ public:
|
||||
void copyFromContainer();
|
||||
void copyFrom(void * data);
|
||||
void copyFrom(void * data, int elements_count, int elements_offset = 0);
|
||||
uint elementsCount() const {return elements;}
|
||||
uint elementsCount() const { return elements; }
|
||||
|
||||
private:
|
||||
enum Container {
|
||||
cNone,
|
||||
@@ -247,19 +258,21 @@ public:
|
||||
friend class Context;
|
||||
friend class Kernel;
|
||||
friend class Buffer;
|
||||
|
||||
public:
|
||||
~Program();
|
||||
Context * context() const {return context_;}
|
||||
const PIString & sourceCode() const {return source_;}
|
||||
Kernel * kernel(int index = 0) const {return kernels_[index];}
|
||||
const PIVector<Kernel * > & kernels() const {return kernels_;}
|
||||
Context * context() const { return context_; }
|
||||
const PIString & sourceCode() const { return source_; }
|
||||
Kernel * kernel(int index = 0) const { return kernels_[index]; }
|
||||
const PIVector<Kernel *> & kernels() const { return kernels_; }
|
||||
|
||||
private:
|
||||
Program();
|
||||
void zero();
|
||||
bool initKernels(PIVector<void*> kerns);
|
||||
bool initKernels(PIVector<void *> kerns);
|
||||
Context * context_;
|
||||
PIString source_;
|
||||
PIVector<Kernel * > kernels_;
|
||||
PIVector<Kernel *> kernels_;
|
||||
PRIVATE_DECLARATION(PIP_OPENCL_EXPORT)
|
||||
};
|
||||
|
||||
@@ -267,18 +280,26 @@ public:
|
||||
class PIP_OPENCL_EXPORT Kernel {
|
||||
friend class Program;
|
||||
friend class Buffer;
|
||||
|
||||
public:
|
||||
Program * program() const {return program_;}
|
||||
Program * program() const { return program_; }
|
||||
bool execute();
|
||||
void setExecuteRange(int size) {setExecuteRanges(PIVector<int>() << size);}
|
||||
void setExecuteRange(int size) { setExecuteRanges(PIVector<int>() << size); }
|
||||
void setExecuteRanges(const PIVector<int> & ranges);
|
||||
const PIString & name() const {return name_;}
|
||||
const PIVector<KernelArg> & args() const {return args_;}
|
||||
template <typename T> bool setArgValue(int index, const T & value) {return setArgValueS(index, PIVariant::fromValue(value));}
|
||||
template <typename T> bool setArgValue(const PIString & arg, const T & value) {return setArgValue(argIndex(arg), value);}
|
||||
bool setArgValue(const PIString & arg, const PIVariant & value) {return setArgValueS(argIndex(arg), value);}
|
||||
const PIString & name() const { return name_; }
|
||||
const PIVector<KernelArg> & args() const { return args_; }
|
||||
template<typename T>
|
||||
bool setArgValue(int index, const T & value) {
|
||||
return setArgValueS(index, PIVariant::fromValue(value));
|
||||
}
|
||||
template<typename T>
|
||||
bool setArgValue(const PIString & arg, const T & value) {
|
||||
return setArgValue(argIndex(arg), value);
|
||||
}
|
||||
bool setArgValue(const PIString & arg, const PIVariant & value) { return setArgValueS(argIndex(arg), value); }
|
||||
bool bindArgValue(int index, Buffer * buffer);
|
||||
bool bindArgValue(const PIString & arg, Buffer * buffer) {return bindArgValue(argIndex(arg), buffer);}
|
||||
bool bindArgValue(const PIString & arg, Buffer * buffer) { return bindArgValue(argIndex(arg), buffer); }
|
||||
|
||||
private:
|
||||
Kernel();
|
||||
~Kernel();
|
||||
@@ -304,7 +325,7 @@ public:
|
||||
|
||||
private:
|
||||
static PIString prog_header;
|
||||
PIOpenCL() {;}
|
||||
PIOpenCL() { ; }
|
||||
class PIP_OPENCL_EXPORT Initializer {
|
||||
public:
|
||||
Initializer();
|
||||
@@ -316,7 +337,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
PIP_OPENCL_EXPORT PICout operator <<(PICout s, const PIOpenCL::KernelArg & v);
|
||||
PIP_OPENCL_EXPORT PICout operator<<(PICout s, const PIOpenCL::KernelArg & v);
|
||||
|
||||
|
||||
#endif // PIOPENCL_H
|
||||
|
||||
Reference in New Issue
Block a user