本文整理汇总了C++中CHECK_OPENCL_ERROR函数的典型用法代码示例。如果您正苦于以下问题:C++ CHECK_OPENCL_ERROR函数的具体用法?C++ CHECK_OPENCL_ERROR怎么用?C++ CHECK_OPENCL_ERROR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CHECK_OPENCL_ERROR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
/// Tells LibOI that the image source is located in OpenGL device memory at the location
/// specified. You must also indicate whether the OpenGL location is a
/// OPENGL_FRAMEBUFFER | OPENGL_TEXTUREBUFFER
/// All subsequent CopyImageToBuffer commands will read from this location.
void CLibOI::SetImageSource(GLuint gl_device_memory, LibOIEnums::ImageTypes type)
{
mImageType = type;
int status = CL_SUCCESS;
switch(type)
{
case LibOIEnums::OPENGL_FRAMEBUFFER:
mImage_gl = clCreateFromGLBuffer(mOCL->GetContext(), CL_MEM_READ_ONLY, gl_device_memory, &status);
CHECK_OPENCL_ERROR(status, "clCreateFromGLBuffer failed.");
break;
case LibOIEnums::OPENGL_TEXTUREBUFFER:
#if defined(DETECTED_OPENCL_1_0) || defined(DETECTED_OPENCL_1_1) || defined(DETECTED_OPENCL_UNKNOWN_VERSION)
mImage_gl = clCreateFromGLTexture3D(mOCL->GetContext(), CL_MEM_READ_ONLY, GL_TEXTURE_3D, 0, gl_device_memory, &status);
#else
mImage_gl = clCreateFromGLTexture(mOCL->GetContext(), CL_MEM_READ_ONLY, GL_TEXTURE_2D_ARRAY, 0, gl_device_memory, &status);
#endif // defined(DETECTED_OPENCL_1_0) || defined(DETECTED_OPENCL_1_1)
CHECK_OPENCL_ERROR(status, "clCreateFromGLTexture failed.");
break;
case LibOIEnums::OPENGL_RENDERBUFFER:
// TODO: note that the clCreateFromGLTexture2D was depreciated in the OpenCL 1.2 specifications.
mImage_gl = clCreateFromGLRenderbuffer(mOCL->GetContext(), CL_MEM_READ_ONLY, gl_device_memory, &status);
CHECK_OPENCL_ERROR(status, "clCreateFromGLRenderbuffer failed.");
break;
default:
// We don't know what type of image this is!
assert(false);
break;
}
}
示例2: clEnqueueWriteBuffer
/// Copies host memory to a cl_mem buffer
void CLibOI::CopyImageToBuffer(float * host_mem, cl_mem cl_buffer, int width, int height, int layer)
{
int status = CL_SUCCESS;
int size = width * height;
cl_float * tmp = new cl_float[size];
for(int i = 0; i < size; i++)
tmp[i] = host_mem[i];
// Enqueue a blocking write
status = clEnqueueWriteBuffer(mOCL->GetQueue(), cl_buffer, CL_TRUE, 0, sizeof(cl_float) * size, tmp, 0, NULL, NULL);
CHECK_OPENCL_ERROR(status, "clEnqueueWriteBuffer failed.");
delete[] tmp;
}
示例3: clEnqueueReadBuffer
/// Copies the current image in mCLImage to the floating point buffer, image, iff the sizes match exactly.
void CLibOI::ExportImage(float * image, unsigned int width, unsigned int height, unsigned int depth)
{
if(width != mImageWidth || height != mImageHeight || depth != mImageDepth)
return;
int status = CL_SUCCESS;
size_t num_elements = mImageWidth * mImageHeight * mImageDepth;
cl_float tmp[num_elements];
status |= clEnqueueReadBuffer(mOCL->GetQueue(), mImage_cl, CL_TRUE, 0, num_elements * sizeof(cl_float), tmp, 0, NULL, NULL);
CHECK_OPENCL_ERROR(status, "clEnqueueReadBuffer failed.");
// Copy to the output buffer, converting as we go.
for(size_t i = 0; i < num_elements; i++)
image[i] = tmp[i];
}
示例4: clGetPlatformIDs
OCL_Device::OCL_Device(int iPlatformNum, int iDeviceNum)
{
// For error checking
cl_int err;
// Get Platfom Info
cl_uint iNumPlatforms = 0;
err = clGetPlatformIDs(NULL, NULL, &iNumPlatforms);
CHECK_OPENCL_ERROR(err);
cl_platform_id* vPlatformIDs =
(cl_platform_id *) new cl_platform_id[iNumPlatforms];
err = clGetPlatformIDs(iNumPlatforms, vPlatformIDs, NULL);
CHECK_OPENCL_ERROR(err);
if (iPlatformNum >= iNumPlatforms)
{
printf("Platform index must me between 0 and %d.\n",iNumPlatforms-1);
delete[] vPlatformIDs;
return;
}
m_platform_id = vPlatformIDs[iPlatformNum];
delete[] vPlatformIDs;
// Get Device Info
cl_uint iNumDevices = 0;
err = clGetDeviceIDs(m_platform_id, CL_DEVICE_TYPE_ALL, NULL, NULL,
&iNumDevices);
CHECK_OPENCL_ERROR(err);
cl_device_id* vDeviceIDs = (cl_device_id*) new cl_device_id[iNumDevices];
err = clGetDeviceIDs(m_platform_id, CL_DEVICE_TYPE_ALL, iNumDevices,
vDeviceIDs, &iNumDevices);
CHECK_OPENCL_ERROR(err);
if (iDeviceNum >= iNumDevices)
{
printf("Device index must me between 0 and %d.\n", iNumDevices-1);
delete[] vDeviceIDs;
return;
}
m_device_id = vDeviceIDs[iDeviceNum];
delete[] vDeviceIDs;
cl_context_properties vProprieties[3] = {CL_CONTEXT_PLATFORM,
(cl_context_properties)m_platform_id, 0};
m_context = clCreateContext(vProprieties, 1, &m_device_id, NULL, NULL,
&err);
CHECK_OPENCL_ERROR(err);
m_queue = clCreateCommandQueue(m_context, m_device_id, NULL, &err);
CHECK_OPENCL_ERROR(err);
char* m_sBuildOptions = "";
}
示例5: clReleaseKernel
int
BoxFilterSeparable::cleanup()
{
if(!byteRWSupport)
{
return SDK_SUCCESS;
}
// Releases OpenCL resources (Context, Memory etc.)
cl_int status;
status = clReleaseKernel(verticalKernel);
CHECK_OPENCL_ERROR(status, "clReleaseKernel failed.(vertical)");
status = clReleaseKernel(horizontalKernel);
CHECK_OPENCL_ERROR(status, "clReleaseKernel failed.(Horizontal)");
status = clReleaseProgram(program);
CHECK_OPENCL_ERROR(status, "clReleaseProgram failed.");
status = clReleaseMemObject(inputImageBuffer);
CHECK_OPENCL_ERROR(status, "clReleaseMemObject failed.");
status = clReleaseMemObject(outputImageBuffer);
CHECK_OPENCL_ERROR(status, "clReleaseMemObject failed.");
status = clReleaseMemObject(tempImageBuffer);
CHECK_OPENCL_ERROR(status, "clReleaseMemObject failed.");
status = clReleaseCommandQueue(commandQueue);
CHECK_OPENCL_ERROR(status, "clReleaseCommandQueue failed.");
status = clReleaseContext(context);
CHECK_OPENCL_ERROR(status, "clReleaseContext failed.");
// release program resources (input memory etc.)
FREE(inputImageData);
FREE(outputImageData);
FREE(verificationOutput);
FREE(devices);
return SDK_SUCCESS;
}
示例6: clEnqueueMapBuffer
int ComputeBench::mapBuffer(cl_mem deviceBuffer, T* &hostPointer,
size_t sizeInBytes, cl_map_flags flags)
{
cl_int status;
hostPointer = (T*) clEnqueueMapBuffer(commandQueue,
deviceBuffer,
CL_TRUE,
flags,
0,
sizeInBytes,
0,
NULL,
NULL,
&status);
CHECK_OPENCL_ERROR(status, "clEnqueueMapBuffer failed");
return SDK_SUCCESS;
}
示例7: CHECK_OPENCL_ERROR
void CLHelper::printAllPlatformsAndDevices()
{
cl_int err;
std::vector<cl::Platform> platforms;
err = cl::Platform::get(&platforms);
CHECK_OPENCL_ERROR(err, "cl::Platform::get() failed.");
std::cout << std::endl;
std::cout << "Listing platform vendors and devices" << std::endl;
std::cout << "===========================================" << std::endl;
std::vector<cl::Platform>::iterator platform;
for(platform = platforms.begin(); platform != platforms.end(); platform++) {
CLHelper::printVendor(*platform);
CLHelper::printDevices(*platform, CL_DEVICE_TYPE_ALL);
std::cout << "===========================================" << std::endl;
}
}
示例8: clReleaseMemObject
int AtomicCounters::cleanup() {
// Releases OpenCL resources (Context, Memory etc.)
cl_int status;
status = clReleaseMemObject(inBuf);
CHECK_OPENCL_ERROR(status, "clReleaseMemObject(inBuf) failed.");
status = clReleaseMemObject(counterOutBuf);
CHECK_OPENCL_ERROR(status, "clReleaseMemObject(counterOutBuf) failed.");
status = clReleaseMemObject(globalOutBuf);
CHECK_OPENCL_ERROR(status, "clReleaseMemObject(globalOutBuf) failed.");
status = clReleaseKernel(counterKernel);
CHECK_OPENCL_ERROR(status, "clReleaseKernel(counterKernel) failed.");
status = clReleaseKernel(globalKernel);
CHECK_OPENCL_ERROR(status, "clReleaseKernel(globalKernel) failed.");
status = clReleaseProgram(program);
CHECK_OPENCL_ERROR(status, "clReleaseProgram(program) failed.");
status = clReleaseCommandQueue(commandQueue);
CHECK_OPENCL_ERROR(status, "clReleaseCommandQueue(commandQueue) failed.");
status = clReleaseContext(context);
CHECK_OPENCL_ERROR(status, "clReleaseContext(context) failed.");
free(input);
return SDK_SUCCESS;
}
示例9: clReleaseKernel
int
MatrixMulImage::cleanup()
{
// Releases OpenCL resources (Context, Memory etc.
cl_int status;
status = clReleaseKernel(kernel);
CHECK_OPENCL_ERROR(status, "clReleaseKernel failed.(kernel)");
status = clReleaseProgram(program);
CHECK_OPENCL_ERROR(status, "clReleaseProgram failed.(program)");
status = clReleaseMemObject(inputBuffer0);
CHECK_OPENCL_ERROR(status, "clReleaseMemObject failed.(inputBuffer0)");
status = clReleaseMemObject(inputBuffer1);
CHECK_OPENCL_ERROR(status, "clReleaseMemObject failed.(inputBuffer1)");
status = clReleaseMemObject(outputBuffer);
CHECK_OPENCL_ERROR(status, "clReleaseCommandQueue failed.(outputBuffer)");
status = clReleaseCommandQueue(commandQueue);
CHECK_OPENCL_ERROR(status, "clReleaseCommandQueue failed.(commandQueue)");
status = clReleaseContext(context);
CHECK_OPENCL_ERROR(status, "clReleaseContext failed.(context)");
// release program resources (input memory etc.)
FREE(input0);
FREE(input1);
FREE(output);
FREE(verificationOutput);
// release device list
FREE(devices);
return SDK_SUCCESS;
}
示例10: void
void CLHelper::compileProgram(
cl::Program& program,
std::vector<cl::Device>& devices,
const char* options,
void (CL_CALLBACK * notifyFptr)(cl_program, void *),
void* data)
{
cl_int err;
err = program.build(devices, options, NULL, NULL);
if(err != CL_SUCCESS) {
std::cout << "Build error! Showing build log:" << std::endl << std::endl;
std::string errorLog;
std::vector<cl::Device>::iterator device;
for(device = devices.begin(); device != devices.end(); device++)
{
errorLog = program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(*device);
std::cout << errorLog << std::endl;
}
CHECK_OPENCL_ERROR(err, "cl::Program::build() failed.");
}
}
示例11: buildOpenCLProgram
int MotionDetector::setupKernel(std::string name){
cl_int status = CL_SUCCESS;
// create a CL program using the kernel source
buildProgramData buildData;
buildData.kernelName = std::string(name+"_Kernel.cl");
buildData.devices = devices;
buildData.deviceId = sampleArgs->deviceId;
buildData.flagsStr = std::string("");
if (sampleArgs->isLoadBinaryEnabled())
{
buildData.binaryName = std::string(sampleArgs->loadBinary.c_str());
}
if (sampleArgs->isComplierFlagsSpecified())
{
buildData.flagsFileName = std::string(sampleArgs->flags.c_str());
}
int retValue = buildOpenCLProgram(program, context, buildData);
CHECK_ERROR(retValue, 0, "buildOpenCLProgram() failed");
// get a kernel object handle for a kernel with the given name
char* charname = &name[0];
kernl = clCreateKernel(
program,
charname,
&status);
CHECK_OPENCL_ERROR(status, "clCreateKernel failed.");
status = kernelInfo.setKernelWorkGroupInfo(kernl, devices[sampleArgs->deviceId]);
CHECK_ERROR(status, SDK_SUCCESS, "kernelInfo.setKernelWorkGroupInfo() failed");
return SDK_SUCCESS;
}
示例12: clReleaseMemObject
int DwtHaar1D::cleanup()
{
// Releases OpenCL resources (Context, Memory etc.)
cl_int status;
status = clReleaseMemObject(inDataBuf);
CHECK_OPENCL_ERROR(status, "clReleaseMemObject failed.(inDataBuf)");
status = clReleaseMemObject(dOutDataBuf);
CHECK_OPENCL_ERROR(status, "clReleaseMemObject failed.(dOutDataBuf)");
status = clReleaseMemObject(dPartialOutDataBuf);
CHECK_OPENCL_ERROR(status, "clReleaseMemObject failed.(dPartialOutDataBuf)");
status = clReleaseKernel(kernel);
CHECK_OPENCL_ERROR(status, "clReleaseKernel failed.(kernel)");
status = clReleaseProgram(program);
CHECK_OPENCL_ERROR(status, "clReleaseProgram failed.(program)");
status = clReleaseCommandQueue(commandQueue);
CHECK_OPENCL_ERROR(status, "clReleaseCommandQueue failed.(commandQueue)");
status = clReleaseContext(context);
CHECK_OPENCL_ERROR(status, "clReleaseContext failed.(context)");
// Release program resources (input memory etc.)
FREE(inData);
FREE(dOutData);
FREE(dPartialOutData);
FREE(hOutData);
FREE(devices);
return SDK_SUCCESS;
}
示例13: clReleaseKernel
int
ConstantBandwidth::cleanup()
{
// Releases OpenCL resources (Context, Memory etc.)
cl_int status;
for(int i = 0; i < NUM_KERNELS; i++)
{
status = clReleaseKernel(kernel[i]);
CHECK_OPENCL_ERROR(status, "clReleaseKernel failed.");
}
status = clReleaseProgram(program);
CHECK_OPENCL_ERROR(status, "clReleaseProgram failed.");
status = clReleaseMemObject(constantBuffer);
CHECK_OPENCL_ERROR(status, "clReleaseMemObject failed.");
status = clReleaseMemObject(outputBuffer);
CHECK_OPENCL_ERROR(status, "clReleaseMemObject failed.");
status = clReleaseCommandQueue(commandQueue);
CHECK_OPENCL_ERROR(status, "clReleaseCommandQueue failed.");
status = clReleaseContext(context);
CHECK_OPENCL_ERROR(status, "clReleaseContext failed.");
// release program resources (input memory etc.)
FREE(input);
FREE(output);
FREE(verificationOutput);
// release device list
FREE(devices);
return SDK_SUCCESS;
}
示例14: clReleaseMemObject
int
MersenneTwister::cleanup()
{
// Releases OpenCL resources
cl_int status;
status = clReleaseMemObject(seedsBuf);
CHECK_OPENCL_ERROR(status, "clReleaseMemObject failed.(seedsBuf)");
status = clReleaseMemObject(resultBuf);
CHECK_OPENCL_ERROR(status, "clReleaseMemObject failed.(resultBuf)");
status = clReleaseKernel(kernel);
CHECK_OPENCL_ERROR(status, "clReleaseKernel failed.(kernel)");
status = clReleaseProgram(program);
CHECK_OPENCL_ERROR(status, "clReleaseProgram failed.(program)");
status = clReleaseCommandQueue(commandQueue);
CHECK_OPENCL_ERROR(status, "clReleaseCommandQueue failed.(commandQueue)");
status = clReleaseContext(context);
CHECK_OPENCL_ERROR(status, "clReleaseContext failed.(context)");
// Release program resources
FREE(deviceResult);
#if defined (_WIN32)
ALIGNED_FREE(seeds);
#else
FREE(seeds);
#endif
FREE(devices);
return SDK_SUCCESS;
}
示例15: getPlatform
int AtomicCounters::setupCL(void) {
cl_int status = 0;
cl_device_type dType;
if (sampleArgs->deviceType.compare("cpu") == 0) {
dType = CL_DEVICE_TYPE_CPU;
} else // deviceType = "gpu"
{
dType = CL_DEVICE_TYPE_GPU;
if (sampleArgs->isThereGPU() == false) {
std::cout << "GPU not found. Falling back to CPU" << std::endl;
dType = CL_DEVICE_TYPE_CPU;
}
}
cl_platform_id platform = NULL;
int retValue = getPlatform(platform, sampleArgs->platformId,
sampleArgs->isPlatformEnabled());
CHECK_ERROR(retValue, SDK_SUCCESS, "getPlatform() failed.");
// Display available devices.
retValue = displayDevices(platform, dType);
CHECK_ERROR(retValue, SDK_SUCCESS, "displayDevices() failed.");
cl_context_properties cps[3] = {CL_CONTEXT_PLATFORM,
(cl_context_properties)platform, 0};
context = clCreateContextFromType(cps, dType, NULL, NULL, &status);
CHECK_OPENCL_ERROR(status, "clCreateContextFromType failed.");
// getting device on which to run the sample
status = getDevices(context, &devices, sampleArgs->deviceId,
sampleArgs->isDeviceIdEnabled());
CHECK_ERROR(status, SDK_SUCCESS, "getDevices() failed ");
// Set device info of given cl_device_id
retValue = deviceInfo.setDeviceInfo(devices[sampleArgs->deviceId]);
CHECK_ERROR(retValue, SDK_SUCCESS, "SDKDeviceInfo::setDeviceInfo() failed");
// Check device extensions
if (!strstr(deviceInfo.extensions, "cl_ext_atomic_counters_32")) {
OPENCL_EXPECTED_ERROR(
"Device does not support cl_ext_atomic_counters_32 extension!");
}
if (!strstr(deviceInfo.extensions, "cl_khr_local_int32_base_atomics")) {
OPENCL_EXPECTED_ERROR(
"Device does not support cl_khr_local_int32_base_atomics extension!");
}
// Get OpenCL device version
std::string deviceVersionStr = std::string(deviceInfo.deviceVersion);
size_t vStart = deviceVersionStr.find(" ", 0);
size_t vEnd = deviceVersionStr.find(" ", vStart + 1);
std::string vStrVal = deviceVersionStr.substr(vStart + 1, vEnd - vStart - 1);
// Check of OPENCL_C_VERSION if device version is 1.1 or later
#ifdef CL_VERSION_1_1
if (deviceInfo.openclCVersion) {
// Exit if OpenCL C device version is 1.0
deviceVersionStr = std::string(deviceInfo.openclCVersion);
vStart = deviceVersionStr.find(" ", 0);
vStart = deviceVersionStr.find(" ", vStart + 1);
vEnd = deviceVersionStr.find(" ", vStart + 1);
vStrVal = deviceVersionStr.substr(vStart + 1, vEnd - vStart - 1);
if (vStrVal.compare("1.0") <= 0) {
OPENCL_EXPECTED_ERROR(
"Unsupported device! Required CL_DEVICE_OPENCL_C_VERSION as 1.1");
}
} else {
OPENCL_EXPECTED_ERROR(
"Unsupported device! Required CL_DEVICE_OPENCL_C_VERSION as 1.1");
}
#else
OPENCL_EXPECTED_ERROR(
"Unsupported device! Required CL_DEVICE_OPENCL_C_VERSION as 1.1");
#endif
// Setup application data
if (setupAtomicCounters() != SDK_SUCCESS) {
return SDK_FAILURE;
}
cl_command_queue_properties props = CL_QUEUE_PROFILING_ENABLE;
commandQueue = clCreateCommandQueue(context, devices[sampleArgs->deviceId],
props, &status);
CHECK_OPENCL_ERROR(status, "clCreateCommandQueue failed(commandQueue)");
// Set Persistent memory only for AMD platform
cl_mem_flags inMemFlags = CL_MEM_READ_ONLY;
if (sampleArgs->isAmdPlatform()) {
inMemFlags |= CL_MEM_USE_PERSISTENT_MEM_AMD;
}
// Create buffer for input array
inBuf = clCreateBuffer(context, inMemFlags, length * sizeof(cl_uint), NULL,
&status);
CHECK_OPENCL_ERROR(status, "clCreateBuffer failed.(inBuf)");
// Set up data for input array
cl_event writeEvt;
status =
clEnqueueWriteBuffer(commandQueue, inBuf, CL_FALSE, 0,
length * sizeof(cl_uint), input, 0, NULL, &writeEvt);
CHECK_OPENCL_ERROR(status, "clEnqueueWriteBuffer(inBuf) failed..");
status = clFlush(commandQueue);
CHECK_OPENCL_ERROR(status, "clFlush(commandQueue) failed.");
counterOutBuf = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_uint),
NULL, &status);
CHECK_OPENCL_ERROR(status, "clCreateBuffer failed.(counterOutBuf).");
globalOutBuf = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_uint),
NULL, &status);
CHECK_OPENCL_ERROR(status, "clCreateBuffer failed.(globalOutBuf).");
// create a CL program using the kernel source
buildProgramData buildData;
buildData.kernelName = std::string("AtomicCounters_Kernels.cl");
//.........这里部分代码省略.........