PIOpenCL::Buffer::copyTo() with Buffer
This commit is contained in:
@@ -228,9 +228,11 @@ public:
|
|||||||
void copyToContainer();
|
void copyToContainer();
|
||||||
void copyTo(void * data);
|
void copyTo(void * data);
|
||||||
void copyTo(void * data, int elements_count, int elements_offset = 0);
|
void copyTo(void * data, int elements_count, int elements_offset = 0);
|
||||||
|
void copyTo(Buffer * buffer, int elements_count = -1, int elements_from_offset = 0, int elements_to_offset = 0);
|
||||||
void copyFromContainer();
|
void copyFromContainer();
|
||||||
void copyFrom(void * data);
|
void copyFrom(void * data);
|
||||||
void copyFrom(void * data, int elements_count, int elements_offset = 0);
|
void copyFrom(void * data, int elements_count, int elements_offset = 0);
|
||||||
|
void copyFrom(Buffer * buffer, int elements_count = -1, int elements_from_offset = 0, int elements_to_offset = 0);
|
||||||
uint elementsCount() const { return elements; }
|
uint elementsCount() const { return elements; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -244,6 +246,7 @@ public:
|
|||||||
void zero();
|
void zero();
|
||||||
bool init();
|
bool init();
|
||||||
void * containerData();
|
void * containerData();
|
||||||
|
static void copy(Buffer * buffer_from, Buffer * buffer_to, int elements_count, int elements_from_offset, int elements_to_offset);
|
||||||
Context * context_;
|
Context * context_;
|
||||||
Direction dir;
|
Direction dir;
|
||||||
Container type;
|
Container type;
|
||||||
|
|||||||
@@ -240,11 +240,17 @@ PIOpenCL::Program * PIOpenCL::Context::createProgram(const PIString & source, co
|
|||||||
if (error) (*error) = "Empty program!";
|
if (error) (*error) = "Empty program!";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
PIString src_text = PRIVATE->complex_src + source;
|
static PIString double_ext = "#ifdef cl_khr_fp64\n\
|
||||||
const char * csrc = src_text.dataAscii();
|
#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n\
|
||||||
size_t src_size = src_text.size();
|
#elif defined(cl_amd_fp64)\n\
|
||||||
cl_int ret = 0;
|
#pragma OPENCL EXTENSION cl_amd_fp64 : enable\n\
|
||||||
cl_program prog = clCreateProgramWithSource(PRIVATE->context, 1, &csrc, &src_size, &ret);
|
#else\n\
|
||||||
|
#endif\n";
|
||||||
|
PIString src_text = PRIVATE->complex_src + double_ext + 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) {
|
if (ret != 0) {
|
||||||
piCout << "[PIOpenCL::Context]"
|
piCout << "[PIOpenCL::Context]"
|
||||||
<< "clCreateProgramWithSource error" << ret;
|
<< "clCreateProgramWithSource error" << ret;
|
||||||
@@ -429,6 +435,11 @@ void PIOpenCL::Buffer::copyTo(void * data, int elements_count, int elements_offs
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIOpenCL::Buffer::copyTo(Buffer * buffer, int elements_count, int elements_from_offset, int elements_to_offset) {
|
||||||
|
copy(this, buffer, elements_count, elements_from_offset, elements_to_offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIOpenCL::Buffer::copyFromContainer() {
|
void PIOpenCL::Buffer::copyFromContainer() {
|
||||||
if (!PRIVATE->buffer || !container) return;
|
if (!PRIVATE->buffer || !container) return;
|
||||||
copyFrom(containerData());
|
copyFrom(containerData());
|
||||||
@@ -445,12 +456,12 @@ void PIOpenCL::Buffer::copyFrom(void * data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIOpenCL::Buffer::copyFrom(void * data, int elements_count, int elements_offset) {
|
void PIOpenCL::Buffer::copyFrom(void * data, int elements_count, int elements_from_offset) {
|
||||||
if (!PRIVATE->buffer) return;
|
if (!PRIVATE->buffer) return;
|
||||||
cl_int ret = clEnqueueWriteBuffer(context_->PRIVATEWB->queue,
|
cl_int ret = clEnqueueWriteBuffer(context_->PRIVATEWB->queue,
|
||||||
PRIVATE->buffer,
|
PRIVATE->buffer,
|
||||||
CL_TRUE,
|
CL_TRUE,
|
||||||
elements_offset * def.size(),
|
elements_from_offset * def.size(),
|
||||||
elements_count * def.size(),
|
elements_count * def.size(),
|
||||||
data,
|
data,
|
||||||
0,
|
0,
|
||||||
@@ -463,6 +474,35 @@ void PIOpenCL::Buffer::copyFrom(void * data, int elements_count, int elements_of
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIOpenCL::Buffer::copyFrom(Buffer * buffer, int elements_count, int elements_from_offset, int elements_to_offset) {
|
||||||
|
copy(buffer, this, elements_count, elements_to_offset, elements_from_offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIOpenCL::Buffer::copy(Buffer * buffer_from,
|
||||||
|
Buffer * buffer_to,
|
||||||
|
int elements_count,
|
||||||
|
int elements_from_offset,
|
||||||
|
int elements_to_offset) {
|
||||||
|
if (!buffer_from || !buffer_to) return;
|
||||||
|
if (!buffer_from->PRIVATEWB->buffer || !buffer_to->PRIVATEWB->buffer) return;
|
||||||
|
if (elements_count < 0) elements_count = piMini(buffer_from->elements, buffer_to->elements);
|
||||||
|
cl_int ret = clEnqueueCopyBuffer(buffer_from->context_->PRIVATEWB->queue,
|
||||||
|
buffer_from->PRIVATEWB->buffer,
|
||||||
|
buffer_to->PRIVATEWB->buffer,
|
||||||
|
elements_from_offset * buffer_from->def.size(),
|
||||||
|
elements_to_offset * buffer_to->def.size(),
|
||||||
|
elements_count * buffer_from->def.size(),
|
||||||
|
0,
|
||||||
|
nullptr,
|
||||||
|
nullptr);
|
||||||
|
if (ret != 0) {
|
||||||
|
piCout << "[PIOpenCL::Buffer]"
|
||||||
|
<< "clEnqueueCopyBuffer error" << ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PIOpenCL::Program::Program() {
|
PIOpenCL::Program::Program() {
|
||||||
// piCout << "new program" << this;
|
// piCout << "new program" << this;
|
||||||
zero();
|
zero();
|
||||||
|
|||||||
Reference in New Issue
Block a user