本文整理汇总了C++中cl::Kernel类的典型用法代码示例。如果您正苦于以下问题:C++ Kernel类的具体用法?C++ Kernel怎么用?C++ Kernel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Kernel类的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: 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;
}
示例3: 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);
}
}
示例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: 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 ) );
}
示例7: loadAsset
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: 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));
}
示例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: 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());
}
示例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: setarg
void RectangularBorderHandler::setarg(int arg,cl::Kernel& ker, int dimx, int dimy)
{
if (m_bufferMap.find(std::make_pair(dimx,dimy)) == m_bufferMap.end())
genBuffer(dimx,dimy);
ker.setArg(arg,m_bufferMap.at(std::make_pair(dimx,dimy)) ());
}
示例14: const
inline void OpenCL::addkernelarg(std::size_t i, T const (& arg)[N], cl::Kernel & kernel,cl::CommandQueue &quene) const
{
cl::Buffer buffer(this->context,CL_MEM_READ_WRITE,N*sizeof(T));
// std::cout << "enqeue\n";
quene.enqueueWriteBuffer(buffer,CL_FALSE,0,sizeof(T)*N,&arg);
kernel.setArg(i,buffer);
}
示例15: 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);
}