Merge branch 'master' of https://git.shs.tools/SHS/pip
This commit is contained in:
@@ -661,6 +661,7 @@ template<> inline PIVariantTypes::Color PIVariant::value() const {return toColor
|
||||
template<> inline PIVariantTypes::IODevice PIVariant::value() const {return toIODevice();}
|
||||
template<> inline PIPointd PIVariant::value() const {return toPoint();}
|
||||
template<> inline PIRectd PIVariant::value() const {return toRect();}
|
||||
template<> inline PIVariant PIVariant::value() const {return *this;}
|
||||
|
||||
template<> inline PIVariant PIVariant::fromValue(const bool & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const char & v) {return PIVariant(v);}
|
||||
@@ -691,6 +692,7 @@ template<> inline PIVariant PIVariant::fromValue(const PIPointd & v) {return PIV
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIRectd & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIMathVectord & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIMathMatrixd & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIVariant & v) {return PIVariant(v);}
|
||||
|
||||
template<> inline PIVariant::Type PIVariant::getType<bool>() {return PIVariant::pivBool;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<char>() {return PIVariant::pivChar;}
|
||||
|
||||
@@ -709,7 +709,16 @@ int PISerial::readDevice(void * read_to, int max_size) {
|
||||
return PRIVATE->readed;
|
||||
#else
|
||||
if (!canRead()) return -1;
|
||||
return ::read(fd, read_to, max_size);
|
||||
int ret = ::read(fd, read_to, max_size);
|
||||
if (ret < 0) {
|
||||
int err = errno;
|
||||
if (err == EBADF || err == EFAULT || err == EINVAL || err == EIO) {
|
||||
PIThread::stop(false);
|
||||
close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -31,11 +31,13 @@ public:
|
||||
struct Device;
|
||||
struct Platform;
|
||||
class Context;
|
||||
class Buffer;
|
||||
class Program;
|
||||
class Kernel;
|
||||
|
||||
typedef PIVector<Device> DeviceList;
|
||||
|
||||
|
||||
enum AddressQualifier {
|
||||
AddressGlobal,
|
||||
AddressLocal,
|
||||
@@ -76,6 +78,7 @@ public:
|
||||
Double,
|
||||
};
|
||||
|
||||
|
||||
struct PIP_OPENCL_EXPORT KernelArg {
|
||||
KernelArg();
|
||||
AddressQualifier address_qualifier;
|
||||
@@ -91,10 +94,9 @@ public:
|
||||
private:
|
||||
friend class Kernel;
|
||||
void init(void * _k, uint index);
|
||||
int bytes;
|
||||
void * buffer, * data;
|
||||
};
|
||||
|
||||
|
||||
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;}
|
||||
@@ -110,6 +112,7 @@ public:
|
||||
ullong max_memory_size;
|
||||
};
|
||||
|
||||
|
||||
struct PIP_OPENCL_EXPORT Platform {
|
||||
Platform() {id = 0;}
|
||||
bool isValid() const {return id != 0;}
|
||||
@@ -123,7 +126,9 @@ public:
|
||||
PIVector<Device> devices;
|
||||
};
|
||||
|
||||
|
||||
class PIP_OPENCL_EXPORT Context {
|
||||
friend class Buffer;
|
||||
friend class Program;
|
||||
friend class Kernel;
|
||||
public:
|
||||
@@ -132,17 +137,71 @@ public:
|
||||
static Context * create(const Device & d) {return create(DeviceList() << d);}
|
||||
static Context * create(const PIString & part_name);
|
||||
Program * createProgram(const PIString & source, PIString * error = 0);
|
||||
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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
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();
|
||||
Buffer * ret = createBuffer(dir, 0, Buffer::cNone, PIByteArray(&def, sizeof(T)), elements);
|
||||
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_;
|
||||
PRIVATE_DECLARATION(PIP_OPENCL_EXPORT)
|
||||
};
|
||||
|
||||
|
||||
class PIP_OPENCL_EXPORT Buffer {
|
||||
friend class Context;
|
||||
friend class Kernel;
|
||||
public:
|
||||
~Buffer();
|
||||
bool resize(uint new_elements);
|
||||
void clear();
|
||||
void copyToContainer();
|
||||
void copyFromContainer();
|
||||
private:
|
||||
enum Container {
|
||||
cNone,
|
||||
cVector,
|
||||
cDeque,
|
||||
cVector2D,
|
||||
};
|
||||
Buffer();
|
||||
void zero();
|
||||
bool init();
|
||||
void * containerData();
|
||||
Context * context_;
|
||||
Direction dir;
|
||||
Container type;
|
||||
void * container;
|
||||
PIByteArray def;
|
||||
uint elements;
|
||||
PRIVATE_DECLARATION(PIP_OPENCL_EXPORT)
|
||||
};
|
||||
|
||||
|
||||
class PIP_OPENCL_EXPORT Program {
|
||||
friend class Context;
|
||||
friend class Kernel;
|
||||
friend class Buffer;
|
||||
public:
|
||||
~Program();
|
||||
const PIString & sourceCode() const {return source_;}
|
||||
@@ -158,8 +217,10 @@ public:
|
||||
PRIVATE_DECLARATION(PIP_OPENCL_EXPORT)
|
||||
};
|
||||
|
||||
|
||||
class PIP_OPENCL_EXPORT Kernel {
|
||||
friend class Program;
|
||||
friend class Buffer;
|
||||
public:
|
||||
bool execute();
|
||||
void setExecuteRange(int size) {setExecuteRanges(PIVector<int>() << size);}
|
||||
@@ -168,45 +229,26 @@ public:
|
||||
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);}
|
||||
template <typename T> bool bindArgValue(int index, PIVector<T> & value, PIOpenCL::Direction dir) {
|
||||
T def;
|
||||
return bindArgValueV(index, value.size() * sizeof(T), value.data(), sizeof(def), &def, dir);
|
||||
}
|
||||
template <typename T> bool bindArgValue(const PIString & arg, PIVector<T> & value, PIOpenCL::Direction dir) {
|
||||
return bindArgValue(argIndex(arg), value, dir);
|
||||
}
|
||||
template <typename T> bool bindArgValue(int index, PIDeque<T> & value, PIOpenCL::Direction dir) {
|
||||
T def;
|
||||
return bindArgValueV(index, value.size() * sizeof(T), value.data(), sizeof(def), &def, dir);
|
||||
}
|
||||
template <typename T> bool bindArgValue(const PIString & arg, PIDeque<T> & value, PIOpenCL::Direction dir) {
|
||||
return bindArgValue(argIndex(arg), value, dir);
|
||||
}
|
||||
template <typename T> bool bindArgValue(int index, PIVector2D<T> & value, PIOpenCL::Direction dir) {
|
||||
T def;
|
||||
return bindArgValueV(index, value.size() * sizeof(T), value.data(), sizeof(def), &def, dir);
|
||||
}
|
||||
template <typename T> bool bindArgValue(const PIString & arg, PIVector2D<T> & value, PIOpenCL::Direction dir) {
|
||||
return bindArgValue(argIndex(arg), value, dir);
|
||||
}
|
||||
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);}
|
||||
private:
|
||||
Kernel();
|
||||
~Kernel();
|
||||
void zero();
|
||||
bool init();
|
||||
bool setArgValueS(int index, const PIVariant & value);
|
||||
bool bindArgValueV(int index, uint bytes, void * value, uint def_bytes, void * def_data, PIOpenCL::Direction dir);
|
||||
int argIndex(const PIString & an) const;
|
||||
KernelArg argByName(const PIString & an) const;
|
||||
Context * context_;
|
||||
Program * program_;
|
||||
PIString name_;
|
||||
PIVector<KernelArg> args_;
|
||||
PIVector<void*> buffers_;
|
||||
PIVector<size_t> dims;
|
||||
PRIVATE_DECLARATION(PIP_OPENCL_EXPORT)
|
||||
};
|
||||
|
||||
|
||||
static void init();
|
||||
static const PIVector<Platform> & platforms();
|
||||
static const PIVector<Device> devices();
|
||||
|
||||
Reference in New Issue
Block a user