本文整理汇总了C++中cl::CommandQueue::enqueueReadBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ CommandQueue::enqueueReadBuffer方法的具体用法?C++ CommandQueue::enqueueReadBuffer怎么用?C++ CommandQueue::enqueueReadBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cl::CommandQueue
的用法示例。
在下文中一共展示了CommandQueue::enqueueReadBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runTestType
bool runTestType(cl::Context context, cl::CommandQueue queue)
{
cl_uint size = 1024 * 2 + 15;
std::vector<T> input(size);
std::cout << "##Testing scan for " << input.size() << " elements and type "
<< magnet::CL::detail::traits<T>::kernel_type();
for(size_t i = 0; i < input.size(); ++i)
input[i] = i+1;
// create input buffer using pinned memory
cl::Buffer bufferIn(context, CL_MEM_ALLOC_HOST_PTR |
CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(T) * input.size(), &input[0])
;
magnet::CL::scan<T> scanFunctor;
scanFunctor.build(queue, context);
scanFunctor(bufferIn, bufferIn);
std::vector<T> output(size);
queue.enqueueReadBuffer(bufferIn, CL_TRUE, 0, input.size() *
sizeof(T), &output[0]);
bool failed = !testOutput(input, output);
std::cout << (failed ? " FAILED" : " PASSED") << std::endl;
return failed;
}
示例2: simulationStep
void simulationStep() {
try {
// copy
auto buffer = cl::Buffer(context, CL_MEM_READ_ONLY,
sizeof(unsigned char) * 4 * fieldWidth * fieldHeight,
nullptr, nullptr);
queue.enqueueWriteBuffer(buffer, CL_TRUE, 0,
sizeof(unsigned char) * 4 * fieldWidth * fieldHeight,
visualizationBufferCPU, NULL, NULL);
// enque
stepKernel.setArg(2, buffer);
cl::NDRange global((size_t) (fieldWidth * fieldHeight));
queue.enqueueNDRangeKernel(stepKernel, cl::NullRange, global, cl::NullRange);
// read back
queue.enqueueReadBuffer(visualizationBufferGPU, CL_TRUE, 0,
sizeof(unsigned char) * 4 * fieldWidth * fieldHeight,
visualizationBufferCPU, NULL, NULL);
// finish
queue.finish();
} catch (cl::Error err) {
std::cout << "Error: " << err.what() << "(" << err.err() << ")" << std::endl;
exit(3);
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fieldWidth, fieldHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
visualizationBufferCPU);
}
示例3: copyFromDevice
void copyFromDevice(cl::CommandQueue &queue)
{
if(m_pElts==NULL)
throw cl::Error(CL_INVALID_MEM_OBJECT, "copyFromDevice - Buffer is not initialised.");
queue.enqueueReadBuffer(m_buffer, CL_TRUE, 0, m_cb, m_pElts);
}
示例4: runTestType
void runTestType(cl::Context context, cl::CommandQueue queue)
{
cl_uint size = 2 << 10;
std::vector<T> input(size);
std::cout << "##Testing bitonic sort for " << input.size() << " elements and type "
<< magnet::CL::detail::traits<T>::kernel_type()
<< std::endl;
for(size_t i = 0; i < input.size(); ++i)
input[i] = input.size() - i - 1;
// create input buffer using pinned memory
cl::Buffer bufferIn(context, CL_MEM_ALLOC_HOST_PTR |
CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(T) * input.size(), &input[0])
;
magnet::CL::bitonicSort<T> bitonicSortFunctor;
bitonicSortFunctor.build(queue, context);
bitonicSortFunctor(bufferIn);
std::vector<T> output(size);
queue.enqueueReadBuffer(bufferIn, CL_TRUE, 0, input.size() *
sizeof(T), &output[0]);
if (!testOutput(input, output))
M_throw() << "Incorrect output for size "
<< input.size()
<< " and type "
<< magnet::CL::detail::traits<T>::kernel_type();
}
示例5: read
void read(const cl::CommandQueue &q, size_t offset, size_t size, T *host,
bool blocking = false) const
{
if (size)
q.enqueueReadBuffer(
buffer, blocking ? CL_TRUE : CL_FALSE,
sizeof(T) * offset, sizeof(T) * size, host
);
}
示例6: copyFromDeviceAsync
cl::Event copyFromDeviceAsync(cl::CommandQueue &queue)
{
if(m_pElts==NULL)
throw cl::Error(CL_INVALID_MEM_OBJECT, "copyFromDevice - Buffer is not initialised.");
cl::Event complete;
queue.enqueueReadBuffer(m_buffer, CL_FALSE, 0, m_cb, m_pElts, NULL, &complete);
return complete;
}
示例7: helper
void helper(uint32_t* out, int osize, uint8_t* in, int isize, int w, int h, int choice)
{
int set_size=8;
try {
cl::Buffer bufferIn = cl::Buffer(gContext, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
isize*sizeof(cl_uchar), in, NULL);
cl::Buffer bufferOut = cl::Buffer(gContext, CL_MEM_READ_WRITE, osize*sizeof(cl_uchar4));
cl::Buffer bufferOut2= cl::Buffer(gContext, CL_MEM_READ_WRITE, osize*sizeof(cl_uchar4));
gNV21Kernel.setArg(2,w);
gNV21Kernel.setArg(3,h);
gNV21Kernel.setArg(1,bufferIn);
gNV21Kernel.setArg(0,bufferOut);
gQueue.enqueueNDRangeKernel(gNV21Kernel,
cl::NullRange,
cl::NDRange( (int)ceil((float)w/16.0f)*16,(int)ceil((float)h/16.0f)*16),
cl::NDRange(set_size,set_size),
NULL,
NULL);
if (choice==1) {
gLaplacianK.setArg(2,w);
gLaplacianK.setArg(3,h);
gLaplacianK.setArg(1,bufferOut);
gLaplacianK.setArg(0,bufferOut2);
gQueue.enqueueNDRangeKernel(gLaplacianK,
cl::NullRange,
cl::NDRange( (int)ceil((float)w/16.0f)*16,(int)ceil((float)h/16.0f)*16),
cl::NDRange(set_size,set_size),
NULL,
NULL);
}
else if (choice>1) {
gNegative.setArg(2,w);
gNegative.setArg(3,h);
gNegative.setArg(1,bufferOut);
gNegative.setArg(0,bufferOut2);
gQueue.enqueueNDRangeKernel(gNegative,
cl::NullRange,
cl::NDRange( (int)ceil((float)w/16.0f)*16,(int)ceil((float)h/16.0f)*16),
cl::NDRange(set_size,set_size),
NULL,
NULL);
}
gQueue.enqueueReadBuffer(bufferOut2, CL_TRUE, 0, osize*sizeof(cl_uchar4), out);
}
catch (cl::Error e) {
LOGI("@oclDecoder: %s %d \n",e.what(),e.err());
}
}
示例8: uint_kernel
/**
* generate 64 bit unsigned random numbers in device global memory
*@param tinymt_status device global memories
*@param total_num total number of work items
*@param local_num number of local work items
*@param data_size number of data to generate
*/
static void generate_uint64(Buffer& tinymt_status,
int total_num,
int local_num,
int data_size)
{
#if defined(DEBUG)
cout << "generate_uint64 start" << endl;
#endif
int min_size = total_num;
if (data_size % min_size != 0) {
data_size = (data_size / min_size + 1) * min_size;
}
Kernel uint_kernel(program, "tinymt_uint64_kernel");
Buffer output_buffer(context,
CL_MEM_READ_WRITE,
data_size * sizeof(uint64_t));
uint_kernel.setArg(0, tinymt_status);
uint_kernel.setArg(1, output_buffer);
uint_kernel.setArg(2, data_size / total_num);
NDRange global(total_num);
NDRange local(local_num);
Event generate_event;
#if defined(DEBUG)
cout << "generate_uint64 enque kernel start" << endl;
#endif
queue.enqueueNDRangeKernel(uint_kernel,
NullRange,
global,
local,
NULL,
&generate_event);
uint64_t * output = new uint64_t[data_size];
generate_event.wait();
queue.enqueueReadBuffer(output_buffer,
CL_TRUE,
0,
data_size * sizeof(uint64_t),
output);
check_data(output, data_size, total_num);
#if defined(DEBUG)
print_uint64(output, data_size, total_num);
#endif
double time = get_time(generate_event);
cout << "generate time:" << time * 1000 << "ms" << endl;
delete[] output;
#if defined(DEBUG)
cout << "generate_uint64 end" << endl;
#endif
}
示例9: copyFromDevice
void CLArgument::copyFromDevice( cl::CommandQueue &queue )
{
assert( myBufferInitialized );
// If we own the memory, nobody else can read it anyways.
if ( myCopy )
return;
if ( !myCopyBack )
return;
queue.enqueueReadBuffer(
myBuffer,
CL_TRUE,
0,
mySize,
myPtr
);
}
示例10: L2Norm
real L2Norm(const Buffer3D & in,cl::CommandQueue & q)
{
cl::Buffer ans (CLContextLoader::getContext(),CL_MEM_READ_WRITE,sizeof(real)*in.width()*in.height()*in.depth());
CLContextLoader::getRedL2NormKer().setArg(0,in());
CLContextLoader::getRedL2NormKer().setArg(1,ans());
q.enqueueNDRangeKernel(CLContextLoader::getRedL2NormKer(),
cl::NDRange(0),
cl::NDRange(in.width()*in.height()*in.depth()),
getBestWorkspaceDim(cl::NDRange(in.width()*in.height()*in.depth())));
ans = performReduction(ans,CLContextLoader::getRedSumAllKer(),q,in.width()*in.height()*in.depth());
real res;
q.enqueueReadBuffer(ans,true,0,sizeof(real),&res);
return sqrt(res);
}
示例11: initialize_by_seed
/**
* initialize tinymt status in device global memory
* using 1 parameter for 1 generator.
*@param tinymt_status internal state of kernel side tinymt
*@param total total number of work items
*@param local_item number of local work items
*@param seed seed for initialization
*/
static void initialize_by_seed(Buffer& tinymt_status,
int total,
int local_item,
uint32_t seed)
{
#if defined(DEBUG)
cout << "initialize_by_seed start" << endl;
#endif
Kernel init_kernel(program, "tinymt_init_seed_kernel");
init_kernel.setArg(0, tinymt_status);
init_kernel.setArg(1, seed);
NDRange global(total);
NDRange local(local_item);
Event event;
#if defined(DEBUG)
cout << "global:" << dec << total << endl;
cout << "group:" << dec << (total / local_item) << endl;
cout << "local:" << dec << local_item << endl;
#endif
queue.enqueueNDRangeKernel(init_kernel,
NullRange,
global,
local,
NULL,
&event);
double time = get_time(event);
tinymt32j_t status[total];
queue.enqueueReadBuffer(tinymt_status,
CL_TRUE,
0,
sizeof(tinymt32j_t) * total,
status);
cout << "initializing time = " << time * 1000 << "ms" << endl;
#if defined(DEBUG)
cout << "status[0].s0:" << hex << status[0].s0 << endl;
cout << "status[0].s1:" << hex << status[0].s1 << endl;
cout << "status[0].s2:" << hex << status[0].s2 << endl;
cout << "status[0].s3:" << hex << status[0].s3 << endl;
#endif
check_status(status, total);
#if defined(DEBUG)
cout << "initialize_by_seed end" << endl;
#endif
}
示例12: initialize_by_array
/**
* initialize tinymt status in device global memory
* using 1 parameter for all generators.
*@param tinymt_status device global memories
*@param total total number of work items
*@param local_item number of local work items
*@param seed_array seeds for initialization
*@param seed_size size of seed_array
*/
static void initialize_by_array(Buffer& tinymt_status,
int total,
int local_item,
uint64_t seed_array[],
int seed_size)
{
#if defined(DEBUG)
cout << "initialize_by_array start" << endl;
#endif
Buffer seed_array_buffer(context,
CL_MEM_READ_WRITE,
seed_size * sizeof(uint64_t));
queue.enqueueWriteBuffer(seed_array_buffer,
CL_TRUE,
0,
seed_size * sizeof(uint64_t),
seed_array);
Kernel init_kernel(program, "tinymt_init_array_kernel");
init_kernel.setArg(0, tinymt_status);
init_kernel.setArg(1, seed_array_buffer);
init_kernel.setArg(2, seed_size);
NDRange global(total);
NDRange local(local_item);
Event event;
queue.enqueueNDRangeKernel(init_kernel,
NullRange,
global,
local,
NULL,
&event);
double time = get_time(event);
tinymt64j_t status[total];
queue.enqueueReadBuffer(tinymt_status,
CL_TRUE,
0,
sizeof(tinymt64j_t) * total,
status);
cout << "initializing time = " << time * 1000 << "ms" << endl;
check_status(status, total);
#if defined(DEBUG)
cout << "initialize_by_array end" << endl;
#endif
}
示例13: run
void run(T* buf)
{
cl_int err;
cl::Buffer outbuf(
m_context,
CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR,
N*N*sizeof(T),
buf,
&err);
checkErr(err, "Buffer::Buffer()");
err = m_kernel.setArg(0, outbuf);
checkErr(err, "Kernel::setArg(0)");
err = m_kernel.setArg(1, N);
checkErr(err, "Kernel::setArg(1)");
err = m_kernel.setArg(2, depth);
checkErr(err, "Kernel::setArg(2)");
err = m_kernel.setArg(3, escape2);
checkErr(err, "Kernel::setArg(3)");
cl::Event event;
err = m_cmdq.enqueueNDRangeKernel(
m_kernel,
cl::NullRange,
cl::NDRange(N*N),
cl::NDRange(N, 1),
NULL,
&event);
checkErr(err, "ComamndQueue::enqueueNDRangeKernel()");
event.wait();
err = m_cmdq.enqueueReadBuffer(
outbuf,
CL_TRUE,
0,
N*N*sizeof(T),
buf);
checkErr(err, "ComamndQueue::enqueueReadBuffer()");
}
示例14: double_kernel
/**
* generate double precision floating point numbers in the range [0, 1)
* in device global memory
*@param tinymt_status device global memories
*@param total_num total number of work items
*@param local_num number of local work items
*@param data_size number of data to generate
*/
static void generate_double01(Buffer& tinymt_status,
int total_num,
int local_num,
int data_size)
{
int min_size = total_num;
if (data_size % min_size != 0) {
data_size = (data_size / min_size + 1) * min_size;
}
Kernel double_kernel(program, "tinymt_double01_kernel");
Buffer output_buffer(context,
CL_MEM_READ_WRITE,
data_size * sizeof(double));
double_kernel.setArg(0, tinymt_status);
double_kernel.setArg(1, output_buffer);
double_kernel.setArg(2, data_size / total_num);
NDRange global(total_num);
NDRange local(local_num);
Event generate_event;
queue.enqueueNDRangeKernel(double_kernel,
NullRange,
global,
local,
NULL,
&generate_event);
double * output = new double[data_size];
generate_event.wait();
queue.enqueueReadBuffer(output_buffer,
CL_TRUE,
0,
data_size * sizeof(double),
&output[0]);
check_data01(output, data_size, total_num);
#if defined(DEBUG)
print_double(&output[0], data_size, local_num);
#endif
double time = get_time(generate_event);
delete[] output;
cout << "generate time:" << time * 1000 << "ms" << endl;
}
示例15: updateMarching
void MetaBallsApp::updateMarching()
{
static const cl_int3 size{ VOLUME_WIDTH, VOLUME_HEIGHT, VOLUME_DEPTH };
mClCommandQueue.enqueueNDRangeKernel( mKernWriteClear,
cl::NullRange,
cl::NDRange( VOLUME_SIZE ) );
/* Update volumes */
mClCommandQueue.enqueueNDRangeKernel( mKernWriteMetaballs,
cl::NullRange,
cl::NDRange( VOLUME_SIZE ) );
/* End */
int zero = 0;
auto kernelRange = (size.s[0]-1) * (size.s[1]-1) * (size.s[2]-1);
mClCommandQueue.enqueueWriteBuffer( mClVertIndex, true, 0, sizeof(int), &zero );
mClCommandQueue.enqueueNDRangeKernel( mKernConstructSurface,
cl::NullRange,
cl::NDRange( kernelRange ) );
mClCommandQueue.enqueueReadBuffer( mClVertIndex,
true, 0, sizeof(cl_int),
&mMarchingVertsWritten );
/* Generate Normals */
if (mMarchingVertsWritten > 0) {
bool smooth = true;
if( ! smooth )
mClCommandQueue.enqueueNDRangeKernel( mKernGenNormals,
cl::NullRange,
cl::NDRange( mMarchingVertsWritten ) );
else
mClCommandQueue.enqueueNDRangeKernel( mKernGenNormalsSmooth,
cl::NullRange,
cl::NDRange( mMarchingVertsWritten ) );
}
//if( mDebugDraw )
mClCommandQueue.enqueueNDRangeKernel( mKernWritePointColorBack,
cl::NullRange,
cl::NDRange( VOLUME_SIZE ) );
}