当前位置: 首页>>代码示例>>C++>>正文


C++ clGetDeviceInfo函数代码示例

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


在下文中一共展示了clGetDeviceInfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main (){
	cl_platform_id clPlatform;
	cl_device_id clDevice;
	cl_context clContext;
	cl_command_queue clQueue;
	cl_program clProgram;
	int isMic=0;
	cl_uint numDevices;
	cl_platform_id platform;
	clGetPlatformIDs(1, &platform, NULL);
	cl_int err;
	err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
	//Check for MIC if GPU is not found
	if (err != CL_SUCCESS) {
		err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ACCELERATOR, 0, NULL, &numDevices);
		isMic = 1;
	}
	if (err != CL_SUCCESS) {
		fprintf(stderr, "[ERROR in OpenCLDriver::HI_get_num_devices()] Failed to get device IDs  for type \n");
	}
	
	
	cl_device_id devices[numDevices];
	clGetPlatformIDs(1, &clPlatform, NULL);
	if(isMic)
		clGetDeviceIDs(clPlatform, CL_DEVICE_TYPE_ACCELERATOR, numDevices, devices, NULL);
	else
		clGetDeviceIDs(clPlatform, CL_DEVICE_TYPE_GPU, numDevices, devices, NULL);
	
	for(int i=0; i< numDevices; i++) {
		clDevice = devices[i];
		
		FILE *fp;
		char *source_str;
		size_t source_size;
		char filename[] = "openarc_kernel.cl";
		fp = fopen(filename, "r");
		if (!fp) {
			fprintf(stderr, "[INFO: in OpenCL binary creation] Failed to read the kernel file %s, so skipping binary generation for OpenCL devices %d\n", filename, i);
			break;
		}
		source_str = (char*)malloc(MAX_SOURCE_SIZE);
		source_size = fread( source_str, 1, MAX_SOURCE_SIZE, fp);
		fclose( fp );

		cl_int err;
		clContext = clCreateContext( NULL, 1, &clDevice, NULL, NULL, &err);
		if(err != CL_SUCCESS) {
				fprintf(stderr, "[ERROR in OpenCL binary creation] failed to create OPENCL context with error %d (OPENCL GPU)\n", err);
		}

		clQueue = clCreateCommandQueue(clContext, clDevice, 0, &err);
		if(err != CL_SUCCESS) {
				fprintf(stderr, "[ERROR in OpenCL binary creation] failed to create OPENCL queue with error %d (OPENCL GPU)\n", err);
		}
		
		char cBuffer[1024];
		char *cBufferN;
		clGetDeviceInfo(clDevice, CL_DEVICE_NAME, sizeof(cBuffer), &cBuffer, NULL);
		cBufferN = deblank(cBuffer);
		
		std::string binaryName = std::string("openarc_kernel_") + cBufferN + std::string(".ptx");
		
		clProgram = clCreateProgramWithSource(clContext, 1, (const char **)&source_str, (const size_t *)&source_size, &err);
		if(err != CL_SUCCESS) {
				fprintf(stderr, "[ERROR in OpenCL binary creation] failed to create OPENCL program with error %d (OPENCL GPU)\n", err);
		}
		
		char *envVar;
		envVar = getenv("OPENARC_JITOPTION");
		err = clBuildProgram(clProgram, 1, &clDevice, envVar, NULL, NULL);
#if PRINT_LOG == 0
		if(err != CL_SUCCESS)
		{
				printf("[ERROR in OpenCL binary creation] Error in clBuildProgram, Line %u in file %s : %d!!!\n\n", __LINE__, __FILE__, err);
				if (err == CL_BUILD_PROGRAM_FAILURE)
				{
						// Determine the size of the log
						size_t log_size;
						clGetProgramBuildInfo(clProgram, clDevice, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);

						// Allocate memory for the log
						char *log = (char *) malloc(log_size);

						// Get the log
						clGetProgramBuildInfo(clProgram, clDevice, CL_PROGRAM_BUILD_LOG, log_size, log, NULL);

						// Print the log
						printf("%s\n", log);
				}
				exit(1);
		}
#else
		// Determine the size of the log
		size_t log_size;
		clGetProgramBuildInfo(clProgram, clDevice, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);

		// Allocate memory for the log
		char *log = (char *) malloc(log_size);

//.........这里部分代码省略.........
开发者ID:lidonggit,项目名称:fault_injection_research,代码行数:101,代码来源:binBuilder.cpp

示例2: main

int main(){
    cl_platform_id *platforms;
    cl_uint platforms_n;
    clGetPlatformIDs(0, NULL, &platforms_n);
    platforms = (cl_platform_id*)malloc(sizeof(cl_platform_id)*platforms_n);
    clGetPlatformIDs(platforms_n, platforms, &platforms_n);
    printf("There are %d platforms\n", platforms_n);

    int i = 0;
    char re[1024];

    for(i=0; i<platforms_n; i++){
        printf("Platform: %d\n", i);

        clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, 1024, re, NULL);
        printf("CL_PLATFORM_VENDOR: %s\n", re);

        clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 1024, re, NULL);
        printf("CL_PLATFORM_NAME: %s\n", re);

        clGetPlatformInfo(platforms[i], CL_PLATFORM_VERSION, 1024, re, NULL);
        printf("CL_PLATFORM_VERSION: %s\n", re);

        clGetPlatformInfo(platforms[i], CL_PLATFORM_PROFILE, 1024, re, NULL);
        printf("CL_PLATFORM_PROFILE: %s\n", re);

        clGetPlatformInfo(platforms[i], CL_PLATFORM_EXTENSIONS, 1024, re, NULL);
        printf("CL_PLATFORM_EXTENSIONS: %s\n", re);

        cl_device_id *devices;
        cl_uint devices_n;
        clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &devices_n);
        cl_uint uint;
        cl_ulong ulong;
        devices = (cl_device_id*)malloc(sizeof(cl_device_id)*devices_n);
        clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, devices_n, devices, &devices_n);

        for(int j = 0; j < devices_n; j++ ){
            char string[1024];
            printf("\tPlatform: %d, devices: %d\n", i, j);

            clGetDeviceInfo(devices[j], CL_DEVICE_NAME, 1024, string, NULL);
            printf("\tCL_DEVICE_NAME: %s\n", string);

            clGetDeviceInfo(devices[j], CL_DEVICE_VENDOR, 1024, string, NULL);
            printf("\tCL_DEVICE_VENDOR: %s\n", string);

            clGetDeviceInfo(devices[j], CL_DEVICE_EXTENSIONS, 1024, string, NULL);
            printf("\tCL_DEVICE_EXTENSIONS: %s\n", string);

            clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(uint), &uint, NULL);
            printf("\tCL_DEVICE_MAX_COMPUTE_UNITS: %d\n", uint);

            clGetDeviceInfo(devices[j], CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(uint), &uint, NULL);
            printf("\tCL_DEVICE_MAX_CLOCK_FREQUENCY: %d\n", uint);

            clGetDeviceInfo(devices[j], CL_DEVICE_LOCAL_MEM_SIZE, sizeof(ulong), &ulong, NULL);
            printf("\tCL_Device_LOCAL_MEM_SIZE: %lu\n", ulong);

            clGetDeviceInfo(devices[j], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(ulong), &ulong, NULL);
            printf("\tCL_DEVICE_GLOBAL_MEM_SIZE: %lu\n", ulong);
        }
        free(devices);

    }


    free(platforms);

    return EXIT_SUCCESS;
}
开发者ID:RigobertoCanseco,项目名称:opencl,代码行数:71,代码来源:number_of_platforms.c

示例3: OpenCLDeviceSplitKernel

	OpenCLDeviceSplitKernel(DeviceInfo& info, Stats &stats, bool background_)
	: OpenCLDeviceBase(info, stats, background_)
	{
		background = background_;

		/* Initialize cl_mem variables. */
		kgbuffer = NULL;
		sd = NULL;
		sd_DL_shadow = NULL;

		rng_coop = NULL;
		throughput_coop = NULL;
		L_transparent_coop = NULL;
		PathRadiance_coop = NULL;
		Ray_coop = NULL;
		PathState_coop = NULL;
		Intersection_coop = NULL;
		ray_state = NULL;

		AOAlpha_coop = NULL;
		AOBSDF_coop = NULL;
		AOLightRay_coop = NULL;
		BSDFEval_coop = NULL;
		ISLamp_coop = NULL;
		LightRay_coop = NULL;
		Intersection_coop_shadow = NULL;

#ifdef WITH_CYCLES_DEBUG
		debugdata_coop = NULL;
#endif

		work_array = NULL;

		/* Queue. */
		Queue_data = NULL;
		Queue_index = NULL;
		use_queues_flag = NULL;

		per_sample_output_buffers = NULL;

		per_thread_output_buffer_size = 0;
		hostRayStateArray = NULL;
		PathIteration_times = PATH_ITER_INC_FACTOR;
#ifdef __WORK_STEALING__
		work_pool_wgs = NULL;
		max_work_groups = 0;
#endif
		current_max_closure = -1;
		first_tile = true;

		/* Get device's maximum memory that can be allocated. */
		ciErr = clGetDeviceInfo(cdDevice,
		                        CL_DEVICE_MAX_MEM_ALLOC_SIZE,
		                        sizeof(size_t),
		                        &total_allocatable_memory,
		                        NULL);
		assert(ciErr == CL_SUCCESS);
		if(platform_name == "AMD Accelerated Parallel Processing") {
			/* This value is tweak-able; AMD platform does not seem to
			 * give maximum performance when all of CL_DEVICE_MAX_MEM_ALLOC_SIZE
			 * is considered for further computation.
			 */
			total_allocatable_memory /= 2;
		}
	}
开发者ID:diekev,项目名称:blender,代码行数:65,代码来源:opencl_split.cpp

示例4: COM_startReadHighlights

void WorkScheduler::initialize(bool use_opencl, int num_cpu_threads)
{
	/* initialize highlighting */
	if (!g_highlightInitialized) {
		if (g_highlightedNodesRead) MEM_freeN(g_highlightedNodesRead);
		if (g_highlightedNodes)     MEM_freeN(g_highlightedNodes);

		g_highlightedNodesRead = NULL;
		g_highlightedNodes = NULL;

		COM_startReadHighlights();

		g_highlightInitialized = true;
	}

#if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE
	/* deinitialize if number of threads doesn't match */
	if (g_cpudevices.size() != num_cpu_threads) {
		Device *device;

		while (g_cpudevices.size() > 0) {
			device = g_cpudevices.back();
			g_cpudevices.pop_back();
			device->deinitialize();
			delete device;
		}

		g_cpuInitialized = false;
	}

	/* initialize CPU threads */
	if (!g_cpuInitialized) {
		for (int index = 0; index < num_cpu_threads; index++) {
			CPUDevice *device = new CPUDevice();
			device->initialize();
			g_cpudevices.push_back(device);
		}

		g_cpuInitialized = true;
	}

#ifdef COM_OPENCL_ENABLED
	/* deinitialize OpenCL GPU's */
	if (use_opencl && !g_openclInitialized) {
		g_context = NULL;
		g_program = NULL;

		if (!OCL_init()) /* this will check for errors and skip if already initialized */
			return;

		if (clCreateContextFromType) {
			cl_uint numberOfPlatforms = 0;
			cl_int error;
			error = clGetPlatformIDs(0, 0, &numberOfPlatforms);
			if (error == -1001) { }   /* GPU not supported */
			else if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error));  }
			if (G.f & G_DEBUG) printf("%d number of platforms\n", numberOfPlatforms);
			cl_platform_id *platforms = (cl_platform_id *)MEM_mallocN(sizeof(cl_platform_id) * numberOfPlatforms, __func__);
			error = clGetPlatformIDs(numberOfPlatforms, platforms, 0);
			unsigned int indexPlatform;
			for (indexPlatform = 0; indexPlatform < numberOfPlatforms; indexPlatform++) {
				cl_platform_id platform = platforms[indexPlatform];
				cl_uint numberOfDevices = 0;
				clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, 0, &numberOfDevices);
				if (numberOfDevices <= 0)
					continue;

				cl_device_id *cldevices = (cl_device_id *)MEM_mallocN(sizeof(cl_device_id) * numberOfDevices, __func__);
				clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numberOfDevices, cldevices, 0);

				g_context = clCreateContext(NULL, numberOfDevices, cldevices, clContextError, NULL, &error);
				if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error));  }
				const char *cl_str[2] = {datatoc_COM_OpenCLKernels_cl, NULL};
				g_program = clCreateProgramWithSource(g_context, 1, cl_str, 0, &error);
				error = clBuildProgram(g_program, numberOfDevices, cldevices, 0, 0, 0);
				if (error != CL_SUCCESS) {
					cl_int error2;
					size_t ret_val_size = 0;
					printf("CLERROR[%d]: %s\n", error, clewErrorString(error));
					error2 = clGetProgramBuildInfo(g_program, cldevices[0], CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);
					if (error2 != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); }
					char *build_log = (char *)MEM_mallocN(sizeof(char) * ret_val_size + 1, __func__);
					error2 = clGetProgramBuildInfo(g_program, cldevices[0], CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
					if (error2 != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); }
					build_log[ret_val_size] = '\0';
					printf("%s", build_log);
					MEM_freeN(build_log);
				}
				else {
					unsigned int indexDevices;
					for (indexDevices = 0; indexDevices < numberOfDevices; indexDevices++) {
						cl_device_id device = cldevices[indexDevices];
						cl_int vendorID = 0;
						cl_int error2 = clGetDeviceInfo(device, CL_DEVICE_VENDOR_ID, sizeof(cl_int), &vendorID, NULL);
						if (error2 != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error2, clewErrorString(error2)); }
						OpenCLDevice *clDevice = new OpenCLDevice(g_context, device, g_program, vendorID);
						clDevice->initialize();
						g_gpudevices.push_back(clDevice);
					}
				}
//.........这里部分代码省略.........
开发者ID:BlueLabelStudio,项目名称:blender,代码行数:101,代码来源:COM_WorkScheduler.cpp

示例5: opencl_info

void opencl_info() {
  cl_int           err_code;

  cl_platform_id  *platforms;
  cl_device_type   device_type;
  cl_uint          num_devices;
  cl_device_id    *devices;

  // Get OpenCL platforms
  // - Get the number of available platforms
  cl_uint num_platforms;
  err_code = clGetPlatformIDs(0, NULL, &num_platforms);
  clu_CheckError(err_code, "clGetPlatformIDs() for num_platforms");
  if (num_platforms == 0) {
    fprintf(stderr, "No OpenCL platform!\n");
    exit(EXIT_FAILURE);
  }
  // - Get platform IDs
  platforms = (cl_platform_id *)malloc(num_platforms*sizeof(cl_platform_id));
  err_code = clGetPlatformIDs(num_platforms, platforms, NULL);
  clu_CheckError(err_code, "clGetPlatformIDs()");

  // Get platform informations
  printf("\nNumber of platforms: %u\n\n", num_platforms);
  char tmp_buf[1024];
  for (cl_uint i = 0; i < num_platforms; i++) {
    printf("platform: %u\n", i);

    err_code = clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 1024,
                                 &tmp_buf, NULL);
    clu_CheckError(err_code, "clGetPlatformInfo() for CL_PLATFORM_NAME");
    printf("- CL_PLATFORM_NAME      : %s\n", tmp_buf);

    err_code = clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, 1024,
                                 &tmp_buf, NULL);
    clu_CheckError(err_code, "clGetPlatformInfo() for CL_PLATFORM_VENDOR");
    printf("- CL_PLATFORM_VENDOR    : %s\n", tmp_buf);

    err_code = clGetPlatformInfo(platforms[i], CL_PLATFORM_PROFILE, 1024,
                                 &tmp_buf, NULL);
    clu_CheckError(err_code, "clGetPlatformInfo() for CL_PLATFORM_PROFILE");
    printf("- CL_PLATFORM_PROFILE   : %s\n", tmp_buf);

    err_code = clGetPlatformInfo(platforms[i], CL_PLATFORM_VERSION, 1024,
                                 &tmp_buf, NULL);
    clu_CheckError(err_code, "clGetPlatformInfo() for CL_PLATFORM_VERSION");
    printf("- CL_PLATFORM_VERSION   : %s\n", tmp_buf);

    err_code = clGetPlatformInfo(platforms[i], CL_PLATFORM_EXTENSIONS, 1024,
                                 &tmp_buf, NULL);
    clu_CheckError(err_code,"clGetPlatformInfo() for CL_PLATFORM_EXTENSIONS");
    printf("- CL_PLATFORM_EXTENSIONS: %s\n", tmp_buf);
    printf("\n");


    // Get the number of devices
    err_code = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL,
                              &num_devices);
    clu_CheckError(err_code, "clGetDeviceIDs for num_devices");
    if (num_devices == 0) {
      fprintf(stderr, "No OpenCL device in this platform!\n");
      exit(EXIT_FAILURE);
    }
    printf("Number of devices: %u\n", num_devices);

    // Get the default device
    cl_device_id default_device;
    cl_uint num_defaults;
    err_code = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_DEFAULT, 
                              1, &default_device, &num_defaults);
    clu_CheckError(err_code, "clGetDeviceIDs() for CL_DEVICE_TYPE_DEFAULT");
    if (num_defaults != 1) {
      printf("- # of default devices: %u\n", num_defaults);
    }

    // Get device IDs
    devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id));
    err_code = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, num_devices,
                              devices, NULL);
    clu_CheckError(err_code, "clGetDeviceIDs()");
    for (cl_uint k = 0; k < num_devices; k++) {
      printf("device: %u (", k);
      err_code = clGetDeviceInfo(devices[k], CL_DEVICE_TYPE, 
                                 sizeof(cl_device_type), &device_type, NULL);
      if (device_type & CL_DEVICE_TYPE_CPU)
        printf("CL_DEVICE_TYPE_CPU");
      if (device_type & CL_DEVICE_TYPE_GPU)
        printf("CL_DEVICE_TYPE_GPU");
      if (device_type & CL_DEVICE_TYPE_ACCELERATOR)
        printf("CL_DEVICE_TYPE_ACCELERATOR");
      if (device_type & CL_DEVICE_TYPE_DEFAULT)
        printf("CL_DEVICE_TYPE_DEFAULT");
      printf(")");
      if (default_device == devices[k]) printf(" default");
      printf("\n");

      err_code = clGetDeviceInfo(devices[k], CL_DEVICE_NAME,
                                 1024, tmp_buf, NULL);
      printf(" - CL_DEVICE_NAME                         : %s\n", tmp_buf);

//.........这里部分代码省略.........
开发者ID:Sangil-Lee,项目名称:RefCode,代码行数:101,代码来源:opencl_info_ans.c

示例6: check_error

int OpenCLDevice::getMaxWorkItemDimensions() {
	cl_uint value;
	check_error(clGetDeviceInfo(my_id, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, (sizeof(cl_uint)), &value, NULL));
	return value;
}
开发者ID:girino,项目名称:xptMiner,代码行数:5,代码来源:OpenCLObjects.cpp

示例7: main

int main() {

   /* Host/device data structures */
   cl_device_id device;
   cl_context context;
   cl_command_queue queue;
   cl_program program;
   cl_kernel init_kernel, stage_kernel, scale_kernel;
   cl_int err, i;
   size_t global_size, local_size;
   cl_ulong local_mem_size;

   /* Data and buffer */
   int direction;
   unsigned int num_points, points_per_group, stage;
   float data[NUM_POINTS*2];
   double error, check_input[NUM_POINTS][2], check_output[NUM_POINTS][2];
   cl_mem data_buffer;

   /* Initialize data */
   srand((unsigned int)time(0));
   for(i=0; i<NUM_POINTS; i++) {
      data[2*i] = (float)rand();
      data[2*i+1] = (float)rand();
      check_input[i][0] = (float)data[2*i];
      check_input[i][1] = (float)data[2*i+1];
   }

   /* Create a device and context */
   device = create_device();
   context = clCreateContext(NULL, 1, &device, NULL, NULL, &err);
   if(err < 0) {
      perror("Couldn't create a context");
      exit(1);   
   }

   /* Build the program */
   program = build_program(context, device, PROGRAM_FILE);

   /* Create kernels for the FFT */
   init_kernel = clCreateKernel(program, INIT_FUNC, &err);
   if(err < 0) {
      printf("Couldn't create the initial kernel: %d", err);
      exit(1);
   };
   stage_kernel = clCreateKernel(program, STAGE_FUNC, &err);
   if(err < 0) {
      printf("Couldn't create the stage kernel: %d", err);
      exit(1);
   };
   scale_kernel = clCreateKernel(program, SCALE_FUNC, &err);
   if(err < 0) {
      printf("Couldn't create the scale kernel: %d", err);
      exit(1);
   };

   /* Create buffer */
   data_buffer = clCreateBuffer(context, 
         CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, 
         2*NUM_POINTS*sizeof(float), data, &err);
   if(err < 0) {
      perror("Couldn't create a buffer");
      exit(1);
   };

   /* Determine maximum work-group size */
   err = clGetKernelWorkGroupInfo(init_kernel, device, 
      CL_KERNEL_WORK_GROUP_SIZE, sizeof(local_size), &local_size, NULL);
   if(err < 0) {
      perror("Couldn't find the maximum work-group size");
      exit(1);   
   };

   /* Determine local memory size */
   err = clGetDeviceInfo(device, CL_DEVICE_LOCAL_MEM_SIZE, 
      sizeof(local_mem_size), &local_mem_size, NULL);
   if(err < 0) {
      perror("Couldn't determine the local memory size");
      exit(1);   
   };

   /* Initialize kernel arguments */
   direction = DIRECTION;
   num_points = NUM_POINTS;
   points_per_group = (unsigned int)(local_mem_size/(2*sizeof(float)));
   if(points_per_group > num_points)
      points_per_group = num_points;

   /* Set kernel arguments */
   err = clSetKernelArg(init_kernel, 0, sizeof(cl_mem), &data_buffer);
   err |= clSetKernelArg(init_kernel, 1, (size_t)local_mem_size, NULL);
   err |= clSetKernelArg(init_kernel, 2, sizeof(points_per_group), &points_per_group);
   err |= clSetKernelArg(init_kernel, 3, sizeof(num_points), &num_points);
   err |= clSetKernelArg(init_kernel, 4, sizeof(direction), &direction);
   if(err < 0) {
      printf("Couldn't set a kernel argument");
      exit(1);   
   };

   /* Create a command queue */
//.........这里部分代码省略.........
开发者ID:sunlianqiang,项目名称:openclDemo,代码行数:101,代码来源:fft.c

示例8: initOpenCL

bool
initOpenCL(ComputeEnv *env)
{
        int r = cllib_init();
        if (r < 0) {
                return false;
        }

        cl_uint num_plt;
        cl_platform_id plts[16];
        clGetPlatformIDs(16, plts, &num_plt);
        bool found = false;
        cl_int err;

        cl_platform_id platform;
        cl_context context;
        cl_device_id dev;
        cl_command_queue queue;
        cl_kernel ker_filter, ker_filter_in1_out32, ker_filter_in128_out1;
        cl_kernel ker_filter_in3_out32, ker_filter_in128_out3;
        cl_program program = 0;

        for (unsigned int i=0; i<num_plt; i++) {
                size_t sz;
                cl_uint num_dev;

                clGetPlatformInfo(plts[i], CL_PLATFORM_NAME, 0, nullptr, &sz);
                std::vector<char> name(sz);
                clGetPlatformInfo(plts[i], CL_PLATFORM_NAME, sz, &name[0], &sz);

                bool is_amd = strstr(&name[0], "AMD") != NULL;
                bool is_apple = strstr(&name[0], "Apple") != NULL;
                //bool is_intel = strstr(&name[0], "Intel") != NULL;
                //bool is_nvidia = strstr(&name[0], "NVIDIA") != NULL;

                if (!is_amd && !is_apple) {
                        continue;
                }

                clGetDeviceIDs(plts[i], CL_DEVICE_TYPE_GPU, 0, nullptr, &num_dev);
                if (num_dev == 0) {
                        continue;
                }

                std::vector<cl_device_id> devs(num_dev);
                clGetDeviceIDs(plts[i], CL_DEVICE_TYPE_GPU, num_dev, &devs[0], &num_dev);

                platform = plts[i];
                dev = devs[0];

                cl_context_properties props[] =
                        {CL_CONTEXT_PLATFORM, (cl_context_properties)(plts[i]), 0};
                cl_context ctxt = clCreateContext(props, 1, &devs[0], NULL, NULL, &err);
                if (err != CL_SUCCESS) {
                        continue;
                }

                context = ctxt;

                found = true;
                break;
        }

        if (!found) {
                return false;
        }

        size_t dev_name_len;
        clGetDeviceInfo(dev, CL_DEVICE_NAME, 0, nullptr, &dev_name_len);
        std::vector<char> dev_name(dev_name_len+1);
        clGetDeviceInfo(dev, CL_DEVICE_NAME, dev_name_len, &dev_name[0], &dev_name_len);

        bool bin_avaiable = false;

#if defined __linux || _WIN32

#ifdef __linux
        ssize_t path_len = 4;
        char *self_path = (char*)malloc(path_len+1);
        while (1) {
                ssize_t r = readlink("/proc/self/exe", self_path, path_len);
                if (r < path_len) {
                        self_path[r] = '\0';
                        break;
                }

                path_len *= 2;
                self_path = (char*)realloc(self_path, path_len+1);
        }

        struct stat self_st;
        stat(self_path, &self_st);
        self_path = dirname(self_path);
#else
        size_t path_len = 4;
        char *self_path = (char*)malloc(path_len+1);
	DWORD len;
        while (1) {
		len = GetModuleFileName(NULL, self_path, path_len);
		if (len > 0 && len != path_len) {
//.........这里部分代码省略.........
开发者ID:freeyang,项目名称:waifu2x-converter-cpp,代码行数:101,代码来源:modelHandler_OpenCL.cpp

示例9: main


//.........这里部分代码省略.........
#if version == 3
	sparsedot_kernel = clCreateKernel(vecops, "sparsedot3_kernel", &err);
#endif
	if (err != CL_SUCCESS)
	{
		printf("Kernel creation failed:\n%d\n", (err));
		return -1;
	}
	
	 
	// allocate memory on the devices
	cl_mem px_d, py_d, result_d, pyLength_d;
	
#if version == 1
	px_d = clCreateBuffer(context1,
							 CL_MEM_READ_ONLY,
							 (x+1) * sizeof(struct svm_node),
							 0, &err);
#endif
#if version == 2 || version == 3
	//unpack px
	int size = px[x-1].index+1;

	for(size_t i = 0; i < y; ++i)
		size = size > pyLength[i] ? size : pyLength[i];

	dtype* px_u = (dtype*)calloc(size, sizeof(dtype));

	unpack(px, px_u);
	printf("px size: %d\n", size);
#endif
#if version == 3
	size_t height, width;
	clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_HEIGHT, sizeof(size_t), &height, 0);
	clGetDeviceInfo(Device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof(size_t), &width, 0);

	size_t region[3];
	region[2] = 1;

	region[0] = min(4, size);
	region[1] = (size+2-1) / 4;
		

	cl_image_format px_format;
	px_format.image_channel_order = CL_R;
	px_format.image_channel_data_type = CL_FLOAT;
#endif
#if version == 2
	px_d = clCreateBuffer(context1,
				 CL_MEM_READ_ONLY,
				 size * sizeof(dtype),
				 0, &err);
#endif
#if version == 3
	 px_d = clCreateImage2D(context1, CL_MEM_READ_ONLY, &px_format,
				  region[0], region[1], 0, 0, &err);

#endif
	if(err != CL_SUCCESS)
	{
		printf("Failed to allocate px:\n%d\n", (err));
		return -1;
	}
	py_d = clCreateBuffer(context1,
		 CL_MEM_READ_ONLY,
		 (x+1) * y * sizeof(struct svm_node),
开发者ID:8l,项目名称:insieme,代码行数:67,代码来源:sparsevec.c

示例10: clGetDeviceInfo

//Maybe somebody could tell me how to use template when exporting a class from a dll. Probably not possible?
cl_uint OclHost::getDeviceInfoInt(cl_device_info info) {
    cl_uint value = 0;
    clGetDeviceInfo(oclDevice, info, sizeof(value), &value, 0);
    return value;
}
开发者ID:Cibiv,项目名称:NextGenMap,代码行数:6,代码来源:OclHost.cpp

示例11: devType

OclHost::OclHost(int const device_type, int gpu_id, int const cpu_cores) :
    devType(device_type), maxGlobalMem(0), maxLocalMem(0) {
//		if (!isGPU()) {
//				gpu_id = 0;
//		}

    cl_int ciErrNum = CL_SUCCESS;
    Log.Verbose("Using device number %d", gpu_id);
//#pragma omp critical
//	{
    if (contextUserCount == 0) {
        Log.Verbose("Creating ocl context.");
//		cl_uint ciDeviceCount = 0;
        cl_platform_id cpPlatform = NULL;

        cpPlatform = getPlatform();
        //Get the devices

        //Get number of devices
        ciErrNum = clGetDeviceIDs(cpPlatform, devType, 0, NULL, &ciDeviceCount);
        checkClError("Couldn't get number of OpenCl devices. Error: ",
                     ciErrNum);

        if (isGPU()) {
            //Getting device ids
            devices = (cl_device_id *) malloc(
                          ciDeviceCount * sizeof(cl_device_id));
            ciErrNum = clGetDeviceIDs(cpPlatform, devType, ciDeviceCount,
                                      devices, NULL);
            checkClError("Couldn't get OpenCl device ids. Error: ", ciErrNum);

            //Create context
            oclGpuContext = clCreateContext(0, ciDeviceCount, devices, NULL,
                                            NULL, &ciErrNum);
            checkClError("Couldn't create context. Error: ", ciErrNum);
            Log.Message("Context for GPU devices created.");

            Log.Message("%d GPU device(s) found: ", ciDeviceCount);
            for (int i = 0; i < ciDeviceCount; ++i) {
                char device_string[1024];
                char driver_string[1024];
                clGetDeviceInfo(devices[i], CL_DEVICE_NAME,
                                sizeof(device_string), &device_string, NULL);
                clGetDeviceInfo(devices[i], CL_DRIVER_VERSION,
                                sizeof(driver_string), &driver_string, NULL);
                Log.Message("Device %d: %s (Driver: %s)", i, device_string, driver_string);
            }

        } else {
            if (ciDeviceCount > 1) {
                Log.Error("More than one CPU device found.");
                exit(-1);
            }

            cl_device_id device_id;
            ciErrNum = clGetDeviceIDs(cpPlatform, CL_DEVICE_TYPE_CPU, 1,
                                      &device_id, NULL);
            checkClError("Couldn't get CPU device id. Error: ", ciErrNum);

            Log.Message("%d CPU device found.", ciDeviceCount);
            char device_string[1024];
            char driver_string[1024];
            clGetDeviceInfo(device_id, CL_DEVICE_NAME, sizeof(device_string),
                            &device_string, NULL);
            clGetDeviceInfo(device_id, CL_DRIVER_VERSION, sizeof(driver_string),
                            &driver_string, NULL);
            Log.Message("Device %d: %s (Driver: %s)", 0, device_string, driver_string);

            cl_device_partition_property props[3];

            props[0] = CL_DEVICE_PARTITION_EQUALLY; // Equally
            props[1] = 1; // 4 compute units per sub-device
            props[2] = 0;

            devices = (cl_device_id *) malloc(256 * sizeof(cl_device_id));
            ciErrNum = clCreateSubDevices(device_id, props, 256, devices,
                                          &ciDeviceCount);
            if (ciErrNum == -18) {
                ciDeviceCount = 1;
                devices[0] = device_id;
            } else {
                checkClError("Couldn't create sub-devices. Error: ", ciErrNum);
            }

            Log.Message("%d CPU cores available.", ciDeviceCount);

            //Create context
            oclGpuContext = clCreateContext(0, ciDeviceCount, devices, NULL,
                                            NULL, &ciErrNum);
            checkClError("Couldn't create context. Error: ", ciErrNum);

        }
    }
    contextUserCount += 1;
    //}

    if (!isGPU()) {
        gpu_id = gpu_id % ciDeviceCount;
    }
    oclDevice = devices[gpu_id];
//.........这里部分代码省略.........
开发者ID:Cibiv,项目名称:NextGenMap,代码行数:101,代码来源:OclHost.cpp

示例12: clDevicesNum

int clDevicesNum(void) {
	cl_int status;
	char pbuff[256];
	cl_uint numDevices;
	cl_uint numPlatforms;
	int most_devices = -1;
	cl_platform_id *platforms;
	cl_platform_id platform = NULL;
	unsigned int i, mdplatform = 0;

	status = clGetPlatformIDs(0, NULL, &numPlatforms);
	/* If this fails, assume no GPUs. */
	if (status != CL_SUCCESS) {
		applog(LOG_ERR, "Error %d: clGetPlatformsIDs failed (no OpenCL SDK installed?)", status);
		return -1;
	}

	if (numPlatforms == 0) {
		applog(LOG_ERR, "clGetPlatformsIDs returned no platforms (no OpenCL SDK installed?)");
		return -1;
	}

	platforms = (cl_platform_id *)alloca(numPlatforms*sizeof(cl_platform_id));
	status = clGetPlatformIDs(numPlatforms, platforms, NULL);
	if (status != CL_SUCCESS) {
		applog(LOG_ERR, "Error %d: Getting Platform Ids. (clGetPlatformsIDs)", status);
		return -1;
	}

	for (i = 0; i < numPlatforms; i++) {
		if (opt_platform_id >= 0 && (int)i != opt_platform_id)
			continue;

		status = clGetPlatformInfo( platforms[i], CL_PLATFORM_VENDOR, sizeof(pbuff), pbuff, NULL);
		if (status != CL_SUCCESS) {
			applog(LOG_ERR, "Error %d: Getting Platform Info. (clGetPlatformInfo)", status);
			return -1;
		}
		platform = platforms[i];
		applog(LOG_INFO, "CL Platform %d vendor: %s", i, pbuff);
		status = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(pbuff), pbuff, NULL);
		if (status == CL_SUCCESS)
			applog(LOG_INFO, "CL Platform %d name: %s", i, pbuff);
		status = clGetPlatformInfo(platform, CL_PLATFORM_VERSION, sizeof(pbuff), pbuff, NULL);
		if (status == CL_SUCCESS)
			applog(LOG_INFO, "CL Platform %d version: %s", i, pbuff);
		status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
		if (status != CL_SUCCESS) {
			applog(LOG_INFO, "Error %d: Getting Device IDs (num)", status);
			continue;
		}
		applog(LOG_INFO, "Platform %d devices: %d", i, numDevices);
		if ((int)numDevices > most_devices) {
			most_devices = numDevices;
			mdplatform = i;
		}
		if (numDevices) {
			unsigned int j;
			cl_device_id *devices = (cl_device_id *)malloc(numDevices*sizeof(cl_device_id));

			clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numDevices, devices, NULL);
			for (j = 0; j < numDevices; j++) {
				clGetDeviceInfo(devices[j], CL_DEVICE_NAME, sizeof(pbuff), pbuff, NULL);
				applog(LOG_INFO, "\t%i\t%s", j, pbuff);
			}
			free(devices);
		}
	}

	if (opt_platform_id < 0)
		opt_platform_id = mdplatform;;

	return most_devices;
}
开发者ID:NateChambers,项目名称:cgminer,代码行数:74,代码来源:ocl.c

示例13: calloc

_clState *initCl(unsigned int gpu, char *name, size_t nameSize)
{
	_clState *clState = calloc(1, sizeof(_clState));
	bool patchbfi = false, prog_built = false;
	struct cgpu_info *cgpu = &gpus[gpu];
	cl_platform_id platform = NULL;
	char pbuff[256], vbuff[255];
	cl_platform_id* platforms;
	cl_uint preferred_vwidth;
	cl_device_id *devices;
	cl_uint numPlatforms;
	cl_uint numDevices;
	cl_int status;

	status = clGetPlatformIDs(0, NULL, &numPlatforms);
	if (status != CL_SUCCESS) {
		applog(LOG_ERR, "Error %d: Getting Platforms. (clGetPlatformsIDs)", status);
		return NULL;
	}

	platforms = (cl_platform_id *)alloca(numPlatforms*sizeof(cl_platform_id));
	status = clGetPlatformIDs(numPlatforms, platforms, NULL);
	if (status != CL_SUCCESS) {
		applog(LOG_ERR, "Error %d: Getting Platform Ids. (clGetPlatformsIDs)", status);
		return NULL;
	}

	if (opt_platform_id >= (int)numPlatforms) {
		applog(LOG_ERR, "Specified platform that does not exist");
		return NULL;
	}

	status = clGetPlatformInfo(platforms[opt_platform_id], CL_PLATFORM_VENDOR, sizeof(pbuff), pbuff, NULL);
	if (status != CL_SUCCESS) {
		applog(LOG_ERR, "Error %d: Getting Platform Info. (clGetPlatformInfo)", status);
		return NULL;
	}
	platform = platforms[opt_platform_id];

	if (platform == NULL) {
		perror("NULL platform found!\n");
		return NULL;
	}

	applog(LOG_INFO, "CL Platform vendor: %s", pbuff);
	status = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(pbuff), pbuff, NULL);
	if (status == CL_SUCCESS)
		applog(LOG_INFO, "CL Platform name: %s", pbuff);
	status = clGetPlatformInfo(platform, CL_PLATFORM_VERSION, sizeof(vbuff), vbuff, NULL);
	if (status == CL_SUCCESS)
		applog(LOG_INFO, "CL Platform version: %s", vbuff);

	status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
	if (status != CL_SUCCESS) {
		applog(LOG_ERR, "Error %d: Getting Device IDs (num)", status);
		return NULL;
	}

	if (numDevices > 0 ) {
		devices = (cl_device_id *)malloc(numDevices*sizeof(cl_device_id));

		/* Now, get the device list data */

		status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numDevices, devices, NULL);
		if (status != CL_SUCCESS) {
			applog(LOG_ERR, "Error %d: Getting Device IDs (list)", status);
			return NULL;
		}

		applog(LOG_INFO, "List of devices:");

		unsigned int i;
		for (i = 0; i < numDevices; i++) {
			status = clGetDeviceInfo(devices[i], CL_DEVICE_NAME, sizeof(pbuff), pbuff, NULL);
			if (status != CL_SUCCESS) {
				applog(LOG_ERR, "Error %d: Getting Device Info", status);
				return NULL;
			}

			applog(LOG_INFO, "\t%i\t%s", i, pbuff);
		}

		if (gpu < numDevices) {
			status = clGetDeviceInfo(devices[gpu], CL_DEVICE_NAME, sizeof(pbuff), pbuff, NULL);
			if (status != CL_SUCCESS) {
				applog(LOG_ERR, "Error %d: Getting Device Info", status);
				return NULL;
			}

			applog(LOG_INFO, "Selected %i: %s", gpu, pbuff);
			strncpy(name, pbuff, nameSize);
		} else {
			applog(LOG_ERR, "Invalid GPU %i", gpu);
			return NULL;
		}

	} else return NULL;

	cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platform, 0 };

//.........这里部分代码省略.........
开发者ID:NateChambers,项目名称:cgminer,代码行数:101,代码来源:ocl.c

示例14: QueryHWinfo

int QueryHWinfo(size_t *maxCmptUnits)
{
    cl_ulong globalmemSize, localmemSize, maxConstBufSize;
    size_t maxWGroupSize;
    size_t maxWIdims;
    size_t maxWItemSize3D[3];
    char device_str[100];
    char local_plat_buf[100];
    char local_dev_buf[100];
    int i;
     
  // Get & Set OpenCL Platforms
    // get Platform numbers
    cl_int ret = clGetPlatformIDs(1, NULL, &numPlatforms);
    cl_errChk(ret,"Error 0>> clGetPlatformIDs");
    
    printf(">> Get Platform num = %d\n\n", numPlatforms);
    
    // get memory to store platform IDs
    platforms = (cl_platform_id*)malloc(numPlatforms * sizeof(cl_platform_id));
    // store IDs into memory
    ret = clGetPlatformIDs(numPlatforms, platforms, NULL);
    cl_errChk(ret,"Error 1>> clGetPlatformIDs");
	
// Get OpenCL Platforms & Devices Info.
    for (i = 0; i < numPlatforms; i++)
    {
    // Get Platform Info.
        ret = clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR,
              sizeof(local_plat_buf), local_plat_buf, NULL);
        cl_errChk(ret,"Error >> clGetPlatformInfo");
        // Vendor Info.
        printf(">> Platform #%d: Vendor => %s\n", i, local_plat_buf);
                
        // get Devices numbers
        ret = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 
          0, NULL, &numDevices);
        cl_errChk(ret,"Error >> clGetDeviceIDs");
        
        // get memory to store device IDs
        Devices = (cl_device_id*)malloc(sizeof(cl_device_id)* numDevices);
        if (numDevices == 0)
        {
            printf("!! There is no device in platform #%d\n", i);
            exit(0);
        }
        else
        {
            ret = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 
                  numDevices, Devices, NULL);
            printf(">> %d Device(s) in platform #%d\n", numDevices, i);
        }

        // Get Devices info.
        int j = 0;
       // cl_device_svm_capabilities caps;
        
        for (j=0; j< numDevices; j++)
        {
            printf("\n>> [ Device: %d ]\n", j);

         /*   // Get SVM support
            ret = clGetDeviceInfo(Devices[j], CL_DEVICE_SVM_CAPABILITIES,
                     sizeof(caps), &caps, 0);
            cl_errChk(ret,"Error >> clGetDeviceInfo_dev_svm");
              printf("\t>> SVM Capabilities:\n");
            if (ret == CL_SUCCESS){
              if (caps & CL_DEVICE_SVM_COARSE_GRAIN_BUFFER)
                 printf("\t\t>> CL_DEVICE_SVM_COARSE_GRAIN_BUFFER\n");
              if (caps & CL_DEVICE_SVM_FINE_GRAIN_BUFFER)
                 printf("\t\t>> CL_DEVICE_SVM_FINE_GRAIN_BUFFER\n");
              if (caps & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM)
                 printf("\t\t>> CL_DEVICE_SVM_FINE_GRAIN_SYSTEM\n");
              if (caps & CL_DEVICE_SVM_ATOMICS)
                 printf("\t\t>> CL_DEVICE_SVM_ATOMICS\n");
             }
         */
            // Get Vendor info.
            ret = clGetDeviceInfo(Devices[j], CL_DEVICE_VENDOR, 
                    sizeof(device_str), device_str, NULL);
            cl_errChk(ret,"Error >> clGetDeviceInfo_dev_vendor");
            printf("\t>> Vendor: %s\n", device_str);

            // Get Name info.
            ret = clGetDeviceInfo(Devices[j], CL_DEVICE_NAME, 
                    sizeof(local_dev_buf), local_dev_buf, NULL);
            cl_errChk(ret,"Error >> clGetDeviceInfo_dev_name");
            printf("\t>> Model: %s\n", local_dev_buf);

            // Get Max Work Group Size
            ret = clGetDeviceInfo(Devices[j], 
                    CL_DEVICE_MAX_WORK_GROUP_SIZE, 
                    sizeof(maxWGroupSize), &maxWGroupSize, NULL);
            cl_errChk(ret,"Error >> clGetDeviceInfo_maxWGroupSize");
            printf("\t>> CL_DEVICE_MAX_WORK_GROUP_SIZE (WIs/WG): %d\n", (int)maxWGroupSize);

            // Get Max Compute Units Size
            ret = clGetDeviceInfo(Devices[j], 
                    CL_DEVICE_MAX_COMPUTE_UNITS, 
                    sizeof(*maxCmptUnits), maxCmptUnits, NULL);
//.........这里部分代码省略.........
开发者ID:chang-enron,项目名称:MCML,代码行数:101,代码来源:cl_util.c

示例15: vxTargetInit

vx_status vxTargetInit(vx_target_t *target)
{
    vx_status status = VX_ERROR_NO_RESOURCES;
    cl_int err = 0;
    vx_context context = target->base.context;
    cl_uint p, d, k;
    char *vx_incs = getenv("VX_CL_INCLUDE_DIR");
    char *cl_dirs = getenv("VX_CL_SOURCE_DIR");
    char cl_args[1024];

    snprintf(cl_args, sizeof(cl_args), "-D VX_CL_KERNEL -I %s -I %s %s %s", (vx_incs?vx_incs:"C:\\Users\\Eric\\Desktop\\VS_OpenVX2\\example_multinode_graph\\cl_code"), cl_dirs,
//#if !defined(__APPLE__)
//        "-D CL_USE_LUMINANCE",
//#else
        "",
//#endif
#if defined(VX_INCLUDE_DIR)
    "-I "VX_INCLUDE_DIR" "
#else
    " "
#endif
    );

    if (cl_dirs == NULL) {
#ifdef VX_CL_SOURCE_DIR
        const char *sdir = VX_CL_SOURCE_DIR;
        int len = strlen(sdir);
        cl_dirs = malloc(len);
        strncpy(cl_dirs, sdir, len);
#else
        return status;
#endif
    }

    strncpy(target->name, name, VX_MAX_TARGET_NAME);
    target->priority = VX_TARGET_PRIORITY_OPENCL;

    context->num_platforms = CL_MAX_PLATFORMS;
    err = clGetPlatformIDs(CL_MAX_PLATFORMS, context->platforms, NULL);
    if (err != CL_SUCCESS)
        goto exit;

    for (p = 0; p < context->num_platforms; p++) {
        err = clGetDeviceIDs(context->platforms[p], CL_DEVICE_TYPE_ALL,
            0, NULL, &context->num_devices[p]);
        err = clGetDeviceIDs(context->platforms[p], CL_DEVICE_TYPE_ALL,
            context->num_devices[p] > CL_MAX_DEVICES ? CL_MAX_DEVICES : context->num_devices[p],
            context->devices[p], NULL);
        if (err == CL_SUCCESS) {
            cl_context_properties props[] = {
                (cl_context_properties)CL_CONTEXT_PLATFORM,
                (cl_context_properties)context->platforms[p],
                (cl_context_properties)0,
            };
            for (d = 0; d < context->num_devices[p]; d++) {
                char deviceName[64];
                cl_bool compiler = CL_FALSE;
                cl_bool available = CL_FALSE;
                cl_bool image_support = CL_FALSE;
                err = clGetDeviceInfo(context->devices[p][d], CL_DEVICE_NAME, sizeof(deviceName), deviceName, NULL);
                CL_ERROR_MSG(err, "clGetDeviceInfo");
                err = clGetDeviceInfo(context->devices[p][d], CL_DEVICE_COMPILER_AVAILABLE, sizeof(cl_bool), &compiler, NULL);
                CL_ERROR_MSG(err, "clGetDeviceInfo");
                err = clGetDeviceInfo(context->devices[p][d], CL_DEVICE_AVAILABLE, sizeof(cl_bool), &available, NULL);
                CL_ERROR_MSG(err, "clGetDeviceInfo");
                err = clGetDeviceInfo(context->devices[p][d], CL_DEVICE_IMAGE_SUPPORT, sizeof(cl_bool), &image_support, NULL);
                CL_ERROR_MSG(err, "clGetDeviceInfo");
                VX_PRINT(VX_ZONE_INFO, "Device %s (compiler=%s) (available=%s) (images=%s)\n", deviceName, (compiler?"TRUE":"FALSE"), (available?"TRUE":"FALSE"), (image_support?"TRUE":"FALSE"));
            }
            context->global[p] = clCreateContext(props,
                                                 context->num_devices[p],
                                                 context->devices[p],
                                                 vxcl_platform_notifier,
                                                 target,
                                                 &err);
            if (err != CL_SUCCESS)
                break;

            /* check for supported formats */
            if (err == CL_SUCCESS) {
                cl_uint f,num_entries = 0u;
                cl_image_format *formats = NULL;
                cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;
                cl_mem_object_type type = CL_MEM_OBJECT_IMAGE2D;

                err = clGetSupportedImageFormats(context->global[p], flags, type, 0, NULL, &num_entries);
                formats = (cl_image_format *)malloc(num_entries * sizeof(cl_image_format));
                err = clGetSupportedImageFormats(context->global[p], flags, type, num_entries, formats, NULL);
                for (f = 0; f < num_entries; f++) {
                    char order[256];
                    char datat[256];
    #define CASE_STRINGERIZE2(value, string) case value: strcpy(string, #value); break
                    switch(formats[f].image_channel_order) {
                        CASE_STRINGERIZE2(CL_R, order);
                        CASE_STRINGERIZE2(CL_A, order);
                        CASE_STRINGERIZE2(CL_RG, order);
                        CASE_STRINGERIZE2(CL_RA, order);
                        CASE_STRINGERIZE2(CL_RGB, order);
                        CASE_STRINGERIZE2(CL_RGBA, order);
                        CASE_STRINGERIZE2(CL_BGRA, order);
//.........这里部分代码省略.........
开发者ID:eric100lin,项目名称:My-OpenVX-1.0.1,代码行数:101,代码来源:vx_interface.c


注:本文中的clGetDeviceInfo函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。