本文整理汇总了C++中cl::Kernel::setArg方法的典型用法代码示例。如果您正苦于以下问题:C++ Kernel::setArg方法的具体用法?C++ Kernel::setArg怎么用?C++ Kernel::setArg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cl::Kernel
的用法示例。
在下文中一共展示了Kernel::setArg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: kernel
void kernel(cl::Buffer& devOut, cl::CommandQueue& queue)
{
static std::once_flag compileFlag;
static cl::Program prog;
static cl::Kernel kern;
std::call_once(compileFlag,
[queue]() {
prog = cl::Program(queue.getInfo<CL_QUEUE_CONTEXT>(), fractal_ocl_kernel, true);
kern = cl::Kernel(prog, "julia");
});
//auto juliaOp = cl::make_kernel<Buffer, unsigned, unsigned>(kern);
static const NDRange local(8, 8);
NDRange global(local[0] * divup(DIMX, local[0]),
local[1] * divup(DIMY, local[1]));
kern.setArg(0, devOut);
kern.setArg(1, DIMX);
kern.setArg(2, DIMY);
queue.enqueueNDRangeKernel(kern, cl::NullRange, global, local);
//juliaOp(EnqueueArgs(queue, global, local), devOut, DIMX, DIMY);
}
示例2: initSimulation
void initSimulation() {
// source: http://stackoverflow.com/questions/26517114/how-to-compile-opencl-project-with-kernels
try {
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
std::vector<cl::Device> devices;
platforms[PLATFORM_ID].getDevices(CL_DEVICE_TYPE_CPU | CL_DEVICE_TYPE_GPU, &devices);
context = cl::Context(devices);
queue = cl::CommandQueue(context, devices[DEVICE_ID]);
std::ifstream sourceFile{"kernels/programs.cl"};
std::string sourceCode(std::istreambuf_iterator<char>(sourceFile), (std::istreambuf_iterator<char>()));
cl::Program::Sources source(1, std::make_pair(sourceCode.c_str(), sourceCode.length()));
simulationProgram = cl::Program(context, source);
simulationProgram.build(devices);
visualizationBufferGPU = cl::Buffer(context, CL_MEM_WRITE_ONLY,
sizeof(unsigned char) * 4 * fieldWidth * fieldHeight,
nullptr, nullptr);
randomizeField();
stepKernel = cl::Kernel(simulationProgram, "tick");
stepKernel.setArg(0, fieldWidth);
stepKernel.setArg(1, fieldHeight);
stepKernel.setArg(3, visualizationBufferGPU);
} catch (cl::Error err) {
std::cout << "Error: " << err.what() << "(" << err.err() << ")" << std::endl;
exit(2);
}
}
示例3: DoBasicOp
inline ImageBuffer DoBasicOp(cl::Kernel& kernel, const ImageBuffer& i1,
ImageBuffer o) {
kernel.setArg(0, i1.mem());
kernel.setArg(1, o.mem());
Enqueue(kernel, o);
return o;
}
示例4: add_kernel_parameters
void CoreSersicProfile::add_kernel_parameters(unsigned int index, cl::Kernel &kernel) const {
kernel.setArg(index++, static_cast<FT>(re));
kernel.setArg(index++, static_cast<FT>(rb));
kernel.setArg(index++, static_cast<FT>(nser));
kernel.setArg(index++, static_cast<FT>(a));
kernel.setArg(index++, static_cast<FT>(b));
kernel.setArg(index++, static_cast<FT>(_bn));
}
示例5: initParticles
void initParticles(uint32_t num_particles)
{
m_geom = gl::Geometry::create();
m_geom->setPrimitiveType(GL_POINTS);
m_mesh = gl::Mesh::create(m_geom, m_pointMaterial);
m_numParticles = num_particles;
GLsizei numBytes = m_numParticles * sizeof(vec4);
m_geom->vertices().resize(m_numParticles, vec3(0));
m_geom->colors().resize(m_numParticles, vec4(1));
m_geom->point_sizes().resize(m_numParticles, 9.f);
m_geom->createGLBuffers();
m_mesh->material()->setPointSize(2.f);
scene().addObject(m_mesh);
try
{
// shared position buffer for OpenGL / OpenCL
m_positions = cl::BufferGL(m_context, CL_MEM_READ_WRITE, m_geom->vertexBuffer().id());
m_colors = cl::BufferGL(m_context, CL_MEM_READ_WRITE, m_geom->colorBuffer().id());
//create the OpenCL only arrays
m_velocities = cl::Buffer( m_context, CL_MEM_WRITE_ONLY, numBytes );
m_positionGen = cl::Buffer( m_context, CL_MEM_WRITE_ONLY, numBytes );
m_velocityGen = cl::Buffer( m_context, CL_MEM_WRITE_ONLY, numBytes );
vector<vec4> posGen, velGen;
for (int i = 0; i < m_numParticles; i++)
{
posGen.push_back( vec4(glm::ballRand(20.0f), 1.f) );
vec2 tmp = glm::linearRand(vec2(-100), vec2(100));
float life = kinski::random(2.f, 5.f);
float yVel = kinski::random<float>(5, 15);
velGen.push_back(vec4(tmp.x, yVel, tmp.y, life));
m_geom->point_sizes()[i] = kinski::random(5.f, 15.f);
}
m_geom->createGLBuffers();
m_queue.enqueueWriteBuffer(m_velocities, CL_TRUE, 0, numBytes, &velGen[0]);
m_queue.enqueueWriteBuffer(m_positionGen, CL_TRUE, 0, numBytes, &posGen[0]);
m_queue.enqueueWriteBuffer(m_velocityGen, CL_TRUE, 0, numBytes, &velGen[0]);
m_particleKernel.setArg(0, m_positions);
m_particleKernel.setArg(1, m_colors);
m_particleKernel.setArg(2, m_velocities);
m_particleKernel.setArg(3, m_positionGen);
m_particleKernel.setArg(4, m_velocityGen);
}
catch(cl::Error &error)
{
LOG_ERROR << error.what() << "(" << oclErrorString(error.err()) << ")";
}
}
示例6: randomUniform
void neo::randomUniform(cl::Image3D &image3D, sys::ComputeSystem &cs, cl::Kernel &randomUniform3DKernel, cl_int3 size, cl_float2 range, std::mt19937 &rng) {
int argIndex = 0;
std::uniform_int_distribution<int> seedDist;
cl_uint2 seed = { seedDist(rng), seedDist(rng) };
randomUniform3DKernel.setArg(argIndex++, image3D);
randomUniform3DKernel.setArg(argIndex++, seed);
randomUniform3DKernel.setArg(argIndex++, range);
cs.getQueue().enqueueNDRangeKernel(randomUniform3DKernel, cl::NullRange, cl::NDRange(size.x, size.y, size.z));
}
示例7: setupParticleKernel
void MetaBallsApp::setupParticleKernel()
{
auto program = ocl::createProgram( mClContext, loadAsset( "kernels/particles.cl" ), true );
mClParticleUpdate = ocl::Kernel( program, "particle_update" );
float maxLife = 60.0;
float minVelSqd = 0.5 * 0.5;
mClParticleUpdate.setArg( 0, mClParticleBuf );
mClParticleUpdate.setArg( 1, sizeof(float), &maxLife );
mClParticleUpdate.setArg( 2, sizeof(float), &minVelSqd );
mClParticleUpdate.setArg( 5, sizeof(cl_int), &NUM_PARTICLES );
}
示例8: updateParticles
void MetaBallsApp::updateParticles()
{
int random = rand();
float time = 1.0f / 60.0f;
mClParticleUpdate.setArg( 3, sizeof(float), &time );
mClParticleUpdate.setArg( 4, sizeof(int32_t), &random );
// Queue the kernel up for execution across the array
mClCommandQueue.enqueueNDRangeKernel( mClParticleUpdate,
cl::NullRange,
cl::NDRange( NUM_PARTICLES ) );
}
示例9: updateLevelSetFunction
void updateLevelSetFunction(
OpenCL &ocl,
cl::Kernel &kernel,
cl::Image3D &input,
cl::Buffer &positions,
int activeVoxels,
int numberOfThreads,
int groupSize,
cl::Memory * phi_read,
cl::Memory * phi_write,
float threshold,
float epsilon,
float alpha
) {
kernel.setArg(0, input);
kernel.setArg(1, positions);
kernel.setArg(2, activeVoxels);
kernel.setArg(3, *phi_read);
kernel.setArg(4, *phi_write);
kernel.setArg(5, threshold);
kernel.setArg(6, epsilon);
kernel.setArg(7, alpha);
ocl.queue.enqueueNDRangeKernel(
kernel,
cl::NullRange,
cl::NDRange(numberOfThreads),
cl::NDRange(groupSize)
);
}
示例10: 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);
}
示例11: setarg
void ParallelepipedalBorderHandler::setarg(int arg,cl::Kernel& ker, int dimx, int dimy,int dimz)
{
if (m_bufferMap.find(tri(dimx,dimy,dimz)) == m_bufferMap.end())
genBuffer(dimx,dimy,dimz);
ker.setArg(arg,m_bufferMap.at(tri(dimx,dimy,dimz)) ());
}
示例12: updateParticles
void updateParticles(float timeDelta)
{
try
{
vector<cl::Memory> glBuffers;
glBuffers.push_back(m_positions);
glBuffers.push_back(m_colors);
//this will update our system by calculating new velocity and updating the positions of our particles
//Make sure OpenGL is done using our VBOs
glFinish();
// map OpenGL buffer object for writing from OpenCL
// this passes in the vector of VBO buffer objects (position and color)
m_queue.enqueueAcquireGLObjects(&glBuffers);
m_particleKernel.setArg(5, timeDelta); //pass in the timestep
//execute the kernel
m_queue.enqueueNDRangeKernel(m_particleKernel, cl::NullRange, cl::NDRange(m_numParticles),
cl::NullRange);
//Release the VBOs so OpenGL can play with them
m_queue.enqueueReleaseGLObjects(&glBuffers, NULL);
m_queue.finish();
}
catch(cl::Error &error)
{
LOG_ERROR << error.what() << "(" << oclErrorString(error.err()) << ")";
}
}
示例13: addkernelarg
inline void OpenCL::addkernelarg(std::size_t i, T const & arg, cl::Kernel & kernel,std::vector<cl::Buffer> &outputbuffer,cl::CommandQueue &quene) const
{
kernel.setArg(i,arg);
// Push back a dummy since we actually dont need to allocate anything for a scalar
outputbuffer.push_back(cl::Buffer());
}
示例14: performReduction
cl::Buffer performReduction(const cl::Buffer & in,cl::Kernel & ker,cl::CommandQueue & q,int size)
{
if (size == 1) return in;
int newsize = std::max(1,size/4);
cl::Buffer tmp (CLContextLoader::getContext(),CL_MEM_READ_WRITE,sizeof(real)*newsize);
ker.setArg(0,in());
ker.setArg(1,tmp());
ker.setArg(2,size);
ker.setArg(3,4);
q.enqueueNDRangeKernel(ker,cl::NDRange(0),cl::NDRange(newsize),
getBestWorkspaceDim(cl::NDRange(newsize)));
return performReduction(tmp,ker,q,newsize);
}
示例15: findMinSeamVert
void findMinSeamVert(cl::Context &ctx,
cl::CommandQueue &cmdQueue,
cl::Event &event,
std::vector<cl::Event> &deps,
cl::Buffer &energyMatrix,
cl::Buffer &vertMinEnergy,
cl::Buffer &vertMinIdx,
int width,
int height,
int pitch,
int colsRemoved) {
cl_int errNum;
errNum = findMinSeamVertKernel.setArg(0, energyMatrix);
errNum |= findMinSeamVertKernel.setArg(1, vertMinEnergy);
errNum |= findMinSeamVertKernel.setArg(2, vertMinIdx);
errNum |= findMinSeamVertKernel.setArg(3, cl::__local(256 * sizeof(float)));
errNum |= findMinSeamVertKernel.setArg(4, cl::__local(256 * sizeof(float)));
errNum |= findMinSeamVertKernel.setArg(5, width);
errNum |= findMinSeamVertKernel.setArg(6, height);
errNum |= findMinSeamVertKernel.setArg(7, pitch);
errNum |= findMinSeamVertKernel.setArg(8, colsRemoved);
if (errNum != CL_SUCCESS) {
std::cerr << "Error setting findMinSeamVert arguments." << std::endl;
exit(-1);
}
// This kernel could be written to use more than one work group, but its probably not worth it.
cl::NDRange offset = cl::NDRange(0);
cl::NDRange localWorkSize = cl::NDRange(256);
cl::NDRange globalWorkSize = cl::NDRange(256);
errNum = cmdQueue.enqueueNDRangeKernel(findMinSeamVertKernel,
offset,
globalWorkSize,
localWorkSize,
&deps,
&event);
if (errNum != CL_SUCCESS) {
std::cerr << "Error enqueuing computeSeams kernel for execution." << std::endl;
exit(-1);
}
/** DEBUG **/
// int deviceResultIdx[1];
// float deviceResultEnergy[1];
// mem::read(ctx, cmdQueue, deviceResultIdx, vertMinIdx);
// mem::read(ctx, cmdQueue, deviceResultEnergy, vertMinEnergy);
// std::cout << "deviceResultIdx = " << deviceResultIdx[0] << std::endl;
// std::cout << "deviceResultEnergy = " << deviceResultEnergy[0] << std::endl;
}