PIOpenCL native handlers, custom compile arguments
This commit is contained in:
@@ -133,10 +133,12 @@ public:
|
|||||||
friend class Kernel;
|
friend class Kernel;
|
||||||
public:
|
public:
|
||||||
~Context();
|
~Context();
|
||||||
|
void * handle();
|
||||||
|
void * queue();
|
||||||
static Context * create(const DeviceList & dl);
|
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);
|
static Context * create(const PIString & part_name);
|
||||||
Program * createProgram(const PIString & source, PIString * error = 0);
|
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();
|
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());
|
||||||
@@ -173,10 +175,14 @@ public:
|
|||||||
friend class Kernel;
|
friend class Kernel;
|
||||||
public:
|
public:
|
||||||
~Buffer();
|
~Buffer();
|
||||||
|
void * handle();
|
||||||
bool resize(uint new_elements);
|
bool resize(uint new_elements);
|
||||||
void clear();
|
void clear();
|
||||||
void copyToContainer();
|
void copyToContainer();
|
||||||
|
void copyTo(void * data);
|
||||||
void copyFromContainer();
|
void copyFromContainer();
|
||||||
|
void copyFrom(void * data);
|
||||||
|
uint elementsCount() const {return elements;}
|
||||||
private:
|
private:
|
||||||
enum Container {
|
enum Container {
|
||||||
cNone,
|
cNone,
|
||||||
@@ -204,6 +210,7 @@ public:
|
|||||||
friend class Buffer;
|
friend class Buffer;
|
||||||
public:
|
public:
|
||||||
~Program();
|
~Program();
|
||||||
|
Context * context() const {return context_;}
|
||||||
const PIString & sourceCode() const {return source_;}
|
const PIString & sourceCode() const {return source_;}
|
||||||
Kernel * kernel(int index = 0) const {return kernels_[index];}
|
Kernel * kernel(int index = 0) const {return kernels_[index];}
|
||||||
const PIVector<Kernel * > & kernels() const {return kernels_;}
|
const PIVector<Kernel * > & kernels() const {return kernels_;}
|
||||||
@@ -222,6 +229,7 @@ public:
|
|||||||
friend class Program;
|
friend class Program;
|
||||||
friend class Buffer;
|
friend class Buffer;
|
||||||
public:
|
public:
|
||||||
|
Program * program() const {return program_;}
|
||||||
bool execute();
|
bool execute();
|
||||||
void setExecuteRange(int size) {setExecuteRanges(PIVector<int>() << size);}
|
void setExecuteRange(int size) {setExecuteRanges(PIVector<int>() << size);}
|
||||||
void setExecuteRanges(const PIVector<int> & ranges);
|
void setExecuteRanges(const PIVector<int> & ranges);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "piopencl.h"
|
#include "piopencl.h"
|
||||||
|
#include "piresources.h"
|
||||||
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
|
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
|
||||||
#define CL_USE_DEPRECATED_OPENCL_2_0_APIS
|
#define CL_USE_DEPRECATED_OPENCL_2_0_APIS
|
||||||
#ifdef MAC_OS
|
#ifdef MAC_OS
|
||||||
@@ -12,6 +13,7 @@ PRIVATE_DEFINITION_START(PIOpenCL::Context)
|
|||||||
cl_context context;
|
cl_context context;
|
||||||
cl_command_queue queue;
|
cl_command_queue queue;
|
||||||
PIVector<cl_device_id> devices;
|
PIVector<cl_device_id> devices;
|
||||||
|
PIString complex_src;
|
||||||
PRIVATE_DEFINITION_END(PIOpenCL::Context)
|
PRIVATE_DEFINITION_END(PIOpenCL::Context)
|
||||||
|
|
||||||
|
|
||||||
@@ -139,6 +141,7 @@ void PIOpenCL::Initializer::init() {
|
|||||||
|
|
||||||
|
|
||||||
PIOpenCL::Context::Context() {
|
PIOpenCL::Context::Context() {
|
||||||
|
PRIVATE->complex_src = PIResources::get("3rd/clcomplex.h") + "\n";
|
||||||
zero();
|
zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,6 +158,16 @@ PIOpenCL::Context::~Context() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void * PIOpenCL::Context::handle() {
|
||||||
|
return PRIVATE->context;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void * PIOpenCL::Context::queue() {
|
||||||
|
return PRIVATE->queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIOpenCL::Context::zero() {
|
void PIOpenCL::Context::zero() {
|
||||||
programs_.clear();
|
programs_.clear();
|
||||||
buffers_.clear();
|
buffers_.clear();
|
||||||
@@ -223,14 +236,15 @@ PIOpenCL::Context * PIOpenCL::Context::create(const PIString & part_name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIOpenCL::Program * PIOpenCL::Context::createProgram(const PIString & source, PIString * error) {
|
PIOpenCL::Program * PIOpenCL::Context::createProgram(const PIString & source, const PIStringList & args, PIString * error) {
|
||||||
if (error) error->clear();
|
if (error) error->clear();
|
||||||
if (source.isEmpty()) {
|
if (source.isEmpty()) {
|
||||||
if (error) (*error) = "Empty program!";
|
if (error) (*error) = "Empty program!";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const char * csrc = source.dataAscii();
|
PIString src_text = PRIVATE->complex_src + source;
|
||||||
size_t src_size = source.size();
|
const char * csrc = src_text.dataAscii();
|
||||||
|
size_t src_size = src_text.size();
|
||||||
cl_int ret = 0;
|
cl_int ret = 0;
|
||||||
cl_program prog = clCreateProgramWithSource(PRIVATE->context, 1, &csrc, &src_size, &ret);
|
cl_program prog = clCreateProgramWithSource(PRIVATE->context, 1, &csrc, &src_size, &ret);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
@@ -238,7 +252,8 @@ PIOpenCL::Program * PIOpenCL::Context::createProgram(const PIString & source, PI
|
|||||||
if (error) (*error) << "clCreateProgramWithSource error " << ret;
|
if (error) (*error) << "clCreateProgramWithSource error " << ret;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ret = clBuildProgram(prog, 0, 0, "-cl-kernel-arg-info", 0, 0);
|
PIString carg = (PIStringList(args) << "-cl-kernel-arg-info").join(' ');
|
||||||
|
ret = clBuildProgram(prog, 0, 0, carg.dataAscii(), 0, 0);
|
||||||
char buffer[10240];
|
char buffer[10240];
|
||||||
clGetProgramBuildInfo(prog, PRIVATE->devices[0], CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, 0);
|
clGetProgramBuildInfo(prog, PRIVATE->devices[0], CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, 0);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
@@ -325,6 +340,11 @@ PIOpenCL::Buffer::~Buffer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void * PIOpenCL::Buffer::handle() {
|
||||||
|
return PRIVATE->buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIOpenCL::Buffer::zero() {
|
void PIOpenCL::Buffer::zero() {
|
||||||
type = cNone;
|
type = cNone;
|
||||||
container = 0;
|
container = 0;
|
||||||
@@ -375,7 +395,13 @@ void PIOpenCL::Buffer::clear() {
|
|||||||
|
|
||||||
void PIOpenCL::Buffer::copyToContainer() {
|
void PIOpenCL::Buffer::copyToContainer() {
|
||||||
if (!PRIVATE->buffer || !container) return;
|
if (!PRIVATE->buffer || !container) return;
|
||||||
cl_int ret = clEnqueueReadBuffer(context_->PRIVATEWB->queue, PRIVATE->buffer, CL_TRUE, 0, elements * def.size(), containerData(), 0, 0, 0);
|
copyTo(containerData());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIOpenCL::Buffer::copyTo(void * data) {
|
||||||
|
if (!PRIVATE->buffer) return;
|
||||||
|
cl_int ret = clEnqueueReadBuffer(context_->PRIVATEWB->queue, PRIVATE->buffer, CL_TRUE, 0, elements * def.size(), data, 0, 0, 0);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
piCout << "[PIOpenCL::Buffer]" << "clEnqueueReadBuffer error" << ret;
|
piCout << "[PIOpenCL::Buffer]" << "clEnqueueReadBuffer error" << ret;
|
||||||
}
|
}
|
||||||
@@ -384,7 +410,13 @@ void PIOpenCL::Buffer::copyToContainer() {
|
|||||||
|
|
||||||
void PIOpenCL::Buffer::copyFromContainer() {
|
void PIOpenCL::Buffer::copyFromContainer() {
|
||||||
if (!PRIVATE->buffer || !container) return;
|
if (!PRIVATE->buffer || !container) return;
|
||||||
cl_int ret = clEnqueueWriteBuffer(context_->PRIVATEWB->queue, PRIVATE->buffer, CL_TRUE, 0, elements * def.size(), containerData(), 0, 0, 0);
|
copyFrom(containerData());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIOpenCL::Buffer::copyFrom(void * data) {
|
||||||
|
if (!PRIVATE->buffer) return;
|
||||||
|
cl_int ret = clEnqueueWriteBuffer(context_->PRIVATEWB->queue, PRIVATE->buffer, CL_TRUE, 0, elements * def.size(), data, 0, 0, 0);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
piCout << "[PIOpenCL::Buffer]" << "clEnqueueWriteBuffer error" << ret;
|
piCout << "[PIOpenCL::Buffer]" << "clEnqueueWriteBuffer error" << ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user