• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ CHECK_OPENCL_ERROR函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中CHECK_OPENCL_ERROR函数的典型用法代码示例。如果您正苦于以下问题:C++ CHECK_OPENCL_ERROR函数的具体用法?C++ CHECK_OPENCL_ERROR怎么用?C++ CHECK_OPENCL_ERROR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了CHECK_OPENCL_ERROR函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
	}
}
开发者ID:matdander,项目名称:liboi,代码行数:41,代码来源:liboi.cpp


示例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;
}
开发者ID:bkloppenborg,项目名称:liboi,代码行数:16,代码来源:liboi.cpp


示例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];

}
开发者ID:bkloppenborg,项目名称:liboi,代码行数:17,代码来源:liboi.cpp


示例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 = "";
}
开发者ID:Soledad89,项目名称:learnOpenCL,代码行数:53,代码来源:OCL_Device.cpp


示例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;
}
开发者ID:xianggong,项目名称:m2c-llvm-devtools-host,代码行数:43,代码来源:BoxFilterSeparable.cpp


示例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;
}
开发者ID:JiniusResearch,项目名称:oclb,代码行数:18,代码来源:ComputeBench.cpp


示例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;
	}
}
开发者ID:deranen,项目名称:OpenCLTemplate,代码行数:19,代码来源:CLHelper.cpp


示例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;
}
开发者ID:xianggong,项目名称:m2s-bench-amdapp-2.9-si,代码行数:22,代码来源:AtomicCounters.cpp


示例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;
}
开发者ID:ChiahungTai,项目名称:OpenCL-playgorund,代码行数:42,代码来源:MatrixMulImage.cpp


示例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.");
	}
}
开发者ID:deranen,项目名称:OpenCLTemplate,代码行数:23,代码来源:CLHelper.cpp


示例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;
}
开发者ID:nico-mkhatvari,项目名称:OpenCL,代码行数:37,代码来源:motion_detection.cpp


示例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;
}
开发者ID:CryDevPortal,项目名称:amd-app-sdk-fixes,代码行数:36,代码来源:DwtHaar1DCPPKernel.cpp


示例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;
}
开发者ID:ChiahungTai,项目名称:OpenCL-playgorund,代码行数:40,代码来源:ConstantBandwidth.cpp


示例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;
}
开发者ID:morellid,项目名称:featureBasedScheduling,代码行数:37,代码来源:MersenneTwister.cpp


示例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");
//.........这里部分代码省略.........
开发者ID:xianggong,项目名称:m2s-bench-amdapp-2.9-si,代码行数:101,代码来源:AtomicCounters.cpp


示例16: clEnqueueWriteBuffer

int AtomicCounters::runGlobalAtomicKernel() {
  cl_int status = CL_SUCCESS;
  // Set Global and Local work items
  size_t globalWorkItems = length;
  size_t localWorkItems = globalWorkGroupSize;
  // Initialize the counter value
  cl_event writeEvt;
  status =
      clEnqueueWriteBuffer(commandQueue, globalOutBuf, CL_FALSE, 0,
                           sizeof(cl_uint), &initValue, 0, NULL, &writeEvt);
  CHECK_OPENCL_ERROR(status, "clEnqueueWriteBuffer(globalOutBuf) failed.");
  status = clFlush(commandQueue);
  CHECK_OPENCL_ERROR(status, "clFlush() failed.");
  // Wait for event and release event
  status = waitForEventAndRelease(&writeEvt);
  CHECK_OPENCL_ERROR(status, "waitForEventAndRelease(writeEvt) failed.");
  // Set kernel arguments
  status = clSetKernelArg(globalKernel, 0, sizeof(cl_mem), &inBuf);
  CHECK_OPENCL_ERROR(status, "clSetKernelArg(inBuf) failed.");
  status = clSetKernelArg(globalKernel, 1, sizeof(cl_uint), &value);
  CHECK_OPENCL_ERROR(status, "clSetKernelArg(value) failed.");
  status = clSetKernelArg(globalKernel, 2, sizeof(cl_mem), &globalOutBuf);
  CHECK_OPENCL_ERROR(status, "clSetKernelArg(globalOutBuf) failed.");
  // Run Kernel
  cl_event ndrEvt;
  status = clEnqueueNDRangeKernel(commandQueue, globalKernel, 1, NULL,
                                  &globalWorkItems, &localWorkItems, 0, NULL,
                                  &ndrEvt);
  CHECK_OPENCL_ERROR(status, "clEnqueueNDRangeKernel(globalKernel) failed.");
  status = clFlush(commandQueue);
  CHECK_OPENCL_ERROR(status, "clFlush(commandQueue) failed.");
  cl_int eventStatus = CL_QUEUED;
  while (eventStatus != CL_COMPLETE) {
    status = clGetEventInfo(ndrEvt, CL_EVENT_COMMAND_EXECUTION_STATUS,
                            sizeof(cl_int), &eventStatus, NULL);
    CHECK_OPENCL_ERROR(status, "clGetEventInfo(ndrEvt) failed.");
  }
  cl_ulong startTime;
  cl_ulong endTime;
  // Get profiling information
  status = clGetEventProfilingInfo(ndrEvt, CL_PROFILING_COMMAND_START,
                                   sizeof(cl_ulong), &startTime, NULL);
  CHECK_OPENCL_ERROR(
      status, "clGetEventProfilingInfo(CL_PROFILING_COMMAND_START) failed.");
  status = clGetEventProfilingInfo(ndrEvt, CL_PROFILING_COMMAND_END,
                                   sizeof(cl_ulong), &endTime, NULL);
  CHECK_OPENCL_ERROR(
      status, "clGetEventProfilingInfo(CL_PROFILING_COMMAND_END) failed.");
  double sec = 1e-9 * (endTime - startTime);
  kTimeAtomGlobal += sec;
  status = clReleaseEvent(ndrEvt);
  CHECK_OPENCL_ERROR(status, "clReleaseEvent(ndrEvt) failed.");
  // Get the occurrences of Value from atomicKernel
  cl_event readEvt;
  status = clEnqueueReadBuffer(commandQueue, globalOutBuf, CL_FALSE, 0,
                               sizeof(cl_uint), &globalOut, 0, NULL, &readEvt);
  CHECK_OPENCL_ERROR(status, "clEnqueueReadBuffer(globalOutBuf) failed.");
  status = clFlush(commandQueue);
  CHECK_OPENCL_ERROR(status, "clFlush() failed.");
  // Wait for event and release event
  status = waitForEventAndRelease(&readEvt);
  CHECK_OPENCL_ERROR(status, "waitForEventAndRelease(readEvt) failed.");
  return SDK_SUCCESS;
}
开发者ID:xianggong,项目名称:m2s-bench-amdapp-2.9-si,代码行数:64,代码来源:AtomicCounters.cpp


示例17: clGetDeviceInfo

void CLHelper::DeviceInfo::setDeviceInfo(cl::Device device) {
    cl_int err = CL_SUCCESS;

    //Get device type
    err = clGetDeviceInfo(
                    device(),
                    CL_DEVICE_TYPE,
                    sizeof(cl_device_type),
                    &dType,
                    NULL);
    CHECK_OPENCL_ERROR(err, "clGetDeviceIDs(CL_DEVICE_TYPE) failed");

    //Get vender ID
    err = clGetDeviceInfo(
                    device(),
                    CL_DEVICE_VENDOR_ID,
                    sizeof(cl_uint),
                    &venderId,
                    NULL);
    CHECK_OPENCL_ERROR(err, "clGetDeviceIDs(CL_DEVICE_VENDOR_ID) failed");

    //Get max compute units
    err = clGetDeviceInfo(
                    device(),
                    CL_DEVICE_MAX_COMPUTE_UNITS,
                    sizeof(cl_uint),
                    &maxComputeUnits,
                    NULL);
    CHECK_OPENCL_ERROR(err, "clGetDeviceIDs(CL_DEVICE_MAX_COMPUTE_UNITS) failed");

    //Get max work item dimensions
    err = clGetDeviceInfo(
                    device(),
                    CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS,
                    sizeof(cl_uint),
                    &maxWorkItemDims,
                    NULL);
    CHECK_OPENCL_ERROR(err, "clGetDeviceIDs(CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS) failed");

    //Get max work item sizes
    delete maxWorkItemSizes;
    maxWorkItemSizes = new size_t[maxWorkItemDims];

    err = clGetDeviceInfo(
                    device(),
                    CL_DEVICE_MAX_WORK_ITEM_SIZES,
                    maxWorkItemDims * sizeof(size_t),
                    maxWorkItemSizes,
                    NULL);
    CHECK_OPENCL_ERROR(err, "clGetDeviceIDs(CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS) failed");

    // Maximum work group size
    err = clGetDeviceInfo(
                    device(),
                    CL_DEVICE_MAX_WORK_GROUP_SIZE,
                    sizeof(size_t),
                    &maxWorkGroupSize,
                    NULL);
   CHECK_OPENCL_ERROR(err, "clGetDeviceIDs(CL_DEVICE_MAX_WORK_GROUP_SIZE) failed");

    // Preferred vector sizes of all data types
    err = clGetDeviceInfo(
                    device(),
                    CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR,
                    sizeof(cl_uint),
                    &preferredCharVecWidth,
                    NULL);
    CHECK_OPENCL_ERROR(err, "clGetDeviceIDs(CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR) failed");

    err = clGetDeviceInfo(
                    device(),
                    CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT,
                    sizeof(cl_uint),
                    &preferredShortVecWidth,
                    NULL);
    CHECK_OPENCL_ERROR(err, "clGetDeviceIDs(CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT) failed");

    err = clGetDeviceInfo(
                    device(),
                    CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT,
                    sizeof(cl_uint),
                    &preferredIntVecWidth,
                    NULL);
    CHECK_OPENCL_ERROR(err, "clGetDeviceIDs(CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT) failed");

    err = clGetDeviceInfo(
                    device(),
                    CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG,
                    sizeof(cl_uint),
                    &preferredLongVecWidth,
                    NULL);
    CHECK_OPENCL_ERROR(err, "clGetDeviceIDs(CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG) failed");

    err = clGetDeviceInfo(
                    device(),
                    CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT,
                    sizeof(cl_uint),
                    &preferredFloatVecWidth,
                    NULL);
    CHECK_OPENCL_ERROR(err, "clGetDeviceIDs(CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT) failed");
//.........这里部分代码省略.........
开发者ID:deranen,项目名称:OpenCLTemplate,代码行数:101,代码来源:CLHelper.cpp


示例18: CHECK_ERROR

int DwtHaar1D::runDwtHaar1DKernel()
{
	
    cl_int status;
	
    status = this->setWorkGroupSize();
    CHECK_ERROR(status, SDK_SUCCESS, "setWorkGroupSize failed");

    // Force write to inData Buf to update its values 
    cl_event writeEvt;
    status = clEnqueueWriteBuffer(
                commandQueue,
                inDataBuf,
                CL_FALSE,
                0,
                curSignalLength * sizeof(cl_float),
                inData,
                0,
                NULL,
                &writeEvt);
    CHECK_OPENCL_ERROR(status, "clEnqueueWriteBuffer failed. (inDataBuf)");

    status = clFlush(commandQueue);
    CHECK_OPENCL_ERROR(status, "clFlush failed.");

    status = sampleCommon->waitForEventAndRelease(&writeEvt);
    CHECK_ERROR(status, SDK_SUCCESS, "WaitForEventAndRelease(writeEvt1) Failed");

	ParaClass *paraClass = new ParaClass;//new a paraclass

	this->classObj = clCreateBuffer(context,CL_MEM_USE_HOST_PTR,sizeof(ParaClass),paraClass,&status);
	 CHECK_OPENCL_ERROR(status, "clclCreateBuffer failed. (inDataBuf)");

	cl_event mapEvt;

	paraClass=(ParaClass *)clEnqueueMapBuffer(commandQueue,this->classObj,CL_FALSE,CL_MAP_WRITE,0,sizeof(ParaClass),0,NULL,&mapEvt,&status);

	 CHECK_OPENCL_ERROR(status, "clEnqueueMapBuffer failed. (classObj)");

    status = clFlush(commandQueue);
    CHECK_OPENCL_ERROR(status, "clFlush failed.");

    status = sampleCommon->waitForEventAndRelease(&mapEvt);
    CHECK_ERROR(status, SDK_SUCCESS, "WaitForEventAndRelease(mapEvt1) Failed");

	paraClass->setValue(this->totalLevels,this->curSignalLength,this->levelsDone,this->maxLevelsOnDevice);
	
	 cl_event unmapEvt;
	 status=clEnqueueUnmapMemObject(commandQueue,this->classObj,paraClass,0,NULL,&unmapEvt);//class is passed to the Device

	  CHECK_OPENCL_ERROR(status, "clEnqueueunMapBuffer failed. (classObj)");

    status = clFlush(commandQueue);
    CHECK_OPENCL_ERROR(status, "clFlush failed.");

    status = sampleCommon->waitForEventAndRelease(&unmapEvt);
    CHECK_ERROR(status, SDK_SUCCESS, "WaitForEventAndRelease(mapEvt1) Failed");


    // Whether sort is to be in increasing order. CL_TRUE implies increasing 
    status = clSetKernelArg(kernel, 
                            0, 
                            sizeof(cl_mem), 
                            (void*)&inDataBuf); 
    CHECK_OPENCL_ERROR(status, "clSetKernelArg failed. (inDataBuf)");

    status = clSetKernelArg(kernel, 
                            1, 
                            sizeof(cl_mem), 
                            (void*)&dOutDataBuf); 
    CHECK_OPENCL_ERROR(status, "clSetKernelArg failed. (dOutDataBuf)");

    status = clSetKernelArg(kernel, 
                            2, 
                            sizeof(cl_mem), 
                            (void*)&dPartialOutDataBuf); 
    CHECK_OPENCL_ERROR(status, "clSetKernelArg failed. (dPartialOutData)");

    status = clSetKernelArg(kernel, 
                            3, 
                            (localThreads * 2 * sizeof(cl_float)),
                            NULL); 
    CHECK_OPENCL_ERROR(status, "clSetKernelArg failed. (local memory)");

	status = clSetKernelArg(kernel, 
                            4, 
                            sizeof(cl_mem),
							(void*)&this->classObj); 
    CHECK_OPENCL_ERROR(status, "clSetKernelArg failed. (global memory)");

    /* 
    * Enqueue a kernel run call.
    */
    cl_event ndrEvt;
    status = clEnqueueNDRangeKernel(
                commandQueue,
                kernel,
                1,
                NULL,
                &globalThreads,
//.........这里部分代码省略.........
开发者ID:CryDevPortal,项目名称:amd-app-sdk-fixes,代码行数:101,代码来源:DwtHaar1DCPPKernel.cpp


示例19: isPlatformEnabled

int
MatrixMulImage::setupCL(void)
{
    cl_int status = 0;
    cl_device_type dType;
    
    if(deviceType.compare("cpu") == 0)
    {
        dType = CL_DEVICE_TYPE_CPU;
    }
    else //deviceType = "gpu" 
    {
        dType = CL_DEVICE_TYPE_GPU;
        if(isThereGPU() == false)
        {
            std::cout << "GPU not found. Falling back to CPU device" << std::endl;
            dType = CL_DEVICE_TYPE_CPU;
        }
    }

    /*
     * Have a look at the available platforms and pick either
     * the AMD one if available or a reasonable default.
     */

    cl_platform_id platform = NULL;
    int retValue = sampleCommon->getPlatform(platform, platformId, isPlatformEnabled());
    CHECK_ERROR(retValue, SDK_SUCCESS, "sampleCommon::getPlatform() failed");

    // Display available devices.
    retValue = sampleCommon->displayDevices(platform, dType);
    CHECK_ERROR(retValue, SDK_SUCCESS, "sampleCommon::displayDevices() failed");

    /*
     * If we could find our platform, use it. Otherwise use just available platform.
     */

    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 = sampleCommon->getDevices(context, &devices, deviceId, isDeviceIdEnabled());
    CHECK_ERROR(status, 0, "sampleCommon::getDevices() failed");

    //Set device info of given cl_device_id
    retValue = deviceInfo.setDeviceInfo(devices[deviceId]);
    CHECK_ERROR(retValue, SDK_SUCCESS, "deviceInfo.setDeviceInfo. failed");

    {
        // The block is to move the declaration of prop closer to its use
        cl_command_queue_properties prop = 0;
        prop |= CL_QUEUE_PROFILING_ENABLE;

        commandQueue = clCreateCommandQueue(
                           context, 
                           devices[deviceId], 
                           prop, 
                           &status);
        CHECK_ERROR(retValue, SDK_SUCCESS, "clCreateCommandQueue. failed");
    }

    cl_image_format imageFormat;
    imageFormat.image_channel_data_type = CL_FLOAT;
    imageFormat.image_channel_order = CL_RGBA;

    if(!deviceInfo.imageSupport)
    {
        std::cout << "Expected Error: Image is not supported on the Device" << std::endl;
        return SDK_EXPECTED_FAILURE;
    }

    cl_image_desc imageDesc;
    memset(&imageDesc, '\0', sizeof(cl_image_desc));
    imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;

    // Create image for matrix A
    imageDesc.image_width = width0 / 4;
    imageDesc.image_height = height0;
    inputBuffer0 = clCreateImage(context,
                                 CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
                                 &imageFormat,
                                 &imageDesc,
                                 input0,
                                 &status);
    CHECK_OPENCL_ERROR(status, "clCreateImage failed. (inputBuffer0)");
   
    // Create image for matrix B
    imageDesc.image_width = width1 / 4;
//.........这里部分代码省略.........
开发者ID:ChiahungTai,项目名称:OpenCL-playgorund,代码行数:101,代码来源:MatrixMulImage.cpp


示例20: isPlatformEnabled

int
DwtHaar1D::setupCL(void)
{
    cl_int status = 0;
    cl_device_type dType;

    if(deviceType.compare("cpu") == 0)
    {
        dType = CL_DEVICE_TYPE_CPU;
    }
    else //deviceType = "gpu" 
    {
        dType = CL_DEVICE_TYPE_GPU;
        if(isThereGPU() == false)
        {
            std::cout << "GPU not found. Falling back to CPU device" << std::endl;
            dType = CL_DEVICE_TYPE_CPU;
        }
    }

    /*
     * Have a look at the available platforms and pick either
     * the AMD one if available or a reasonable default.
     */
    cl_platform_id platform = NULL;
    int retValue = sampleCommon->getPlatform(platform, platformId, isPlatformEnabled());
    CHECK_ERROR(retValue, SDK_SUCCESS, "sampleCommon::getPlatform() failed");

    // Display available devices.
    retValue = sampleCommon->displayDevices(platform, dType);
    CHECK_ERROR(retValue, SDK_SUCCESS, "sampleCommon::displayDevices() failed");

    // If we could find our platform, use it. Otherwise use just available platform.

    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 = sampleCommon->getDevices(context, &devices, deviceId, isDeviceIdEnabled());
    CHECK_ERROR(status, SDK_SUCCESS, "sampleCommon::getDevices() failed");


    commandQueue = clCreateCommandQueue(context, 
        devices[deviceId], 
        0, 
        &status);
    CHECK_OPENCL_ERROR(status, "clCreateCommandQueue failed.");

    //Set device info of given cl_device_id
    retValue = deviceInfo.setDeviceInfo(devices[deviceId]);
    CHECK_ERROR(retValue, 0, "SDKDeviceInfo::setDeviceInfo() failed");

    // Set Presistent memory only for AMD platform
    cl_mem_flags inMemFlags = CL_MEM_READ_ONLY;
    if(isAmdPlatform())
        inMemFlags |= CL_MEM_USE_PERSISTENT_MEM_AMD;

    inDataBuf = clCreateBuffer(context,
        inMemFlags,
        sizeof(cl_float) * signalLength,
        NULL,
        &status);
    CHEC 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ CHECK_PACKET_SIZE函数代码示例发布时间:2022-05-30
下一篇:
C++ CHECK_OP函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap