PIOpenCL native handlers, custom compile arguments
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "piopencl.h"
|
||||
#include "piresources.h"
|
||||
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
|
||||
#define CL_USE_DEPRECATED_OPENCL_2_0_APIS
|
||||
#ifdef MAC_OS
|
||||
@@ -12,6 +13,7 @@ PRIVATE_DEFINITION_START(PIOpenCL::Context)
|
||||
cl_context context;
|
||||
cl_command_queue queue;
|
||||
PIVector<cl_device_id> devices;
|
||||
PIString complex_src;
|
||||
PRIVATE_DEFINITION_END(PIOpenCL::Context)
|
||||
|
||||
|
||||
@@ -139,6 +141,7 @@ void PIOpenCL::Initializer::init() {
|
||||
|
||||
|
||||
PIOpenCL::Context::Context() {
|
||||
PRIVATE->complex_src = PIResources::get("3rd/clcomplex.h") + "\n";
|
||||
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() {
|
||||
programs_.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 (source.isEmpty()) {
|
||||
if (error) (*error) = "Empty program!";
|
||||
return 0;
|
||||
}
|
||||
const char * csrc = source.dataAscii();
|
||||
size_t src_size = source.size();
|
||||
PIString src_text = PRIVATE->complex_src + source;
|
||||
const char * csrc = src_text.dataAscii();
|
||||
size_t src_size = src_text.size();
|
||||
cl_int ret = 0;
|
||||
cl_program prog = clCreateProgramWithSource(PRIVATE->context, 1, &csrc, &src_size, &ret);
|
||||
if (ret != 0) {
|
||||
@@ -238,7 +252,8 @@ PIOpenCL::Program * PIOpenCL::Context::createProgram(const PIString & source, PI
|
||||
if (error) (*error) << "clCreateProgramWithSource error " << ret;
|
||||
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];
|
||||
clGetProgramBuildInfo(prog, PRIVATE->devices[0], CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, 0);
|
||||
if (ret != 0) {
|
||||
@@ -325,6 +340,11 @@ PIOpenCL::Buffer::~Buffer() {
|
||||
}
|
||||
|
||||
|
||||
void * PIOpenCL::Buffer::handle() {
|
||||
return PRIVATE->buffer;
|
||||
}
|
||||
|
||||
|
||||
void PIOpenCL::Buffer::zero() {
|
||||
type = cNone;
|
||||
container = 0;
|
||||
@@ -375,7 +395,13 @@ void PIOpenCL::Buffer::clear() {
|
||||
|
||||
void PIOpenCL::Buffer::copyToContainer() {
|
||||
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) {
|
||||
piCout << "[PIOpenCL::Buffer]" << "clEnqueueReadBuffer error" << ret;
|
||||
}
|
||||
@@ -384,7 +410,13 @@ void PIOpenCL::Buffer::copyToContainer() {
|
||||
|
||||
void PIOpenCL::Buffer::copyFromContainer() {
|
||||
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) {
|
||||
piCout << "[PIOpenCL::Buffer]" << "clEnqueueWriteBuffer error" << ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user