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

C++ clGetPlatformIDs函数代码示例

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

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



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

示例1: hwloc_opencl_discover

static int
hwloc_opencl_discover(struct hwloc_backend *backend)
{
  struct hwloc_topology *topology = backend->topology;
  cl_platform_id *platform_ids = NULL;
  cl_uint nr_platforms;
  cl_int clret;
  unsigned j, res = 0;

  if (!(hwloc_topology_get_flags(topology) & (HWLOC_TOPOLOGY_FLAG_IO_DEVICES|HWLOC_TOPOLOGY_FLAG_WHOLE_IO)))
    return 0;

  if (!hwloc_topology_is_thissystem(topology)) {
    hwloc_debug("%s", "\nno OpenCL detection (not thissystem)\n");
    return 0;
  }

  clret = clGetPlatformIDs(0, NULL, &nr_platforms);
  if (CL_SUCCESS != clret || !nr_platforms)
    return 0;
  hwloc_debug("%u OpenCL platforms\n", nr_platforms);
  platform_ids = malloc(nr_platforms * sizeof(*platform_ids));
  if (!platform_ids)
    return 0;
  clret = clGetPlatformIDs(nr_platforms, platform_ids, &nr_platforms);
  if (CL_SUCCESS != clret || !nr_platforms) {
    free(platform_ids);
    return 0;
  }

  for(j=0; j<nr_platforms; j++) {
    cl_device_id *device_ids = NULL;
    cl_uint nr_devices;
    unsigned i;

    clret = clGetDeviceIDs(platform_ids[j], CL_DEVICE_TYPE_ALL, 0, NULL, &nr_devices);
    if (CL_SUCCESS != clret)
      continue;
    device_ids = malloc(nr_devices * sizeof(*device_ids));
    clret = clGetDeviceIDs(platform_ids[j], CL_DEVICE_TYPE_ALL, nr_devices, device_ids, &nr_devices);
    if (CL_SUCCESS != clret) {
      free(device_ids);
      continue;
    }

    for(i=0; i<nr_devices; i++) {
      cl_platform_id platform_id = 0;
      cl_device_type type;
#ifdef CL_DEVICE_TOPOLOGY_AMD
      cl_device_topology_amd amdtopo;
#endif
      cl_ulong globalmemsize;
      cl_uint computeunits;
      hwloc_obj_t osdev, parent;
      char buffer[64];

      hwloc_debug("This is opencl%dd%d\n", j, i);

#ifdef CL_DEVICE_TOPOLOGY_AMD
      clret = clGetDeviceInfo(device_ids[i], CL_DEVICE_TOPOLOGY_AMD, sizeof(amdtopo), &amdtopo, NULL);
      if (CL_SUCCESS != clret) {
	hwloc_debug("no AMD-specific device information: %d\n", clret);
	continue;
      } else if (CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD != amdtopo.raw.type) {
	hwloc_debug("AMD-specific device topology reports non-PCIe device type: %u\n", amdtopo.raw.type);
	continue;
      }
#else
      continue;
#endif

      osdev = hwloc_alloc_setup_object(HWLOC_OBJ_OS_DEVICE, -1);
      snprintf(buffer, sizeof(buffer), "opencl%dd%d", j, i);
      osdev->name = strdup(buffer);
      osdev->depth = (unsigned) HWLOC_TYPE_DEPTH_UNKNOWN;
      osdev->attr->osdev.type = HWLOC_OBJ_OSDEV_COPROC;

      hwloc_obj_add_info(osdev, "CoProcType", "OpenCL");
      hwloc_obj_add_info(osdev, "Backend", "OpenCL");

      clGetDeviceInfo(device_ids[i], CL_DEVICE_TYPE, sizeof(type), &type, NULL);
      if (type == CL_DEVICE_TYPE_GPU)
	hwloc_obj_add_info(osdev, "OpenCLDeviceType", "GPU");
      else if (type == CL_DEVICE_TYPE_ACCELERATOR)
	hwloc_obj_add_info(osdev, "OpenCLDeviceType", "Accelerator");
      else if (type == CL_DEVICE_TYPE_CPU)
	hwloc_obj_add_info(osdev, "OpenCLDeviceType", "CPU");
      else if (type == CL_DEVICE_TYPE_CUSTOM)
	hwloc_obj_add_info(osdev, "OpenCLDeviceType", "Custom");
      else
	hwloc_obj_add_info(osdev, "OpenCLDeviceType", "Unknown");

      buffer[0] = '\0';
      clGetDeviceInfo(device_ids[i], CL_DEVICE_VENDOR, sizeof(buffer), buffer, NULL);
      if (buffer[0] != '\0')
	hwloc_obj_add_info(osdev, "GPUVendor", buffer);

      buffer[0] = '\0';
#ifdef CL_DEVICE_BOARD_NAME_AMD
      clGetDeviceInfo(device_ids[i], CL_DEVICE_BOARD_NAME_AMD, sizeof(buffer), buffer, NULL);
//.........这里部分代码省略.........
开发者ID:AlexeyAB,项目名称:hwloc,代码行数:101,代码来源:topology-opencl.c


示例2: print_platforms

//------------------------------------------------------------------------------
void print_platforms() {
    cl_uint numPlatforms = 0;
    cl_platform_id platform = 0;
    cl_int status = clGetPlatformIDs(0, 0, &numPlatforms);
    if(status != CL_SUCCESS) {
        std::cerr << "ERROR - clGetPlatformIDs()" << std::endl;
        exit(EXIT_FAILURE);
    }
    if(numPlatforms < 1) {
        std::cout << "No OpenCL platform detected" << std::endl;
        exit(EXIT_SUCCESS);
    }
    typedef std::vector< cl_platform_id > PlatformIds;
    PlatformIds platforms(numPlatforms);
    status = clGetPlatformIDs(platforms.size(), &platforms[0], 0);
    if(status != CL_SUCCESS) {
        std::cerr << "ERROR - clGetPlatformIDs()" << std::endl;
        exit(EXIT_FAILURE);
    }
    std::vector< char > buf(0x10000, char(0));
    int p = 0;
    std::cout << "\n***************************************************\n";  
    std::cout << "Number of platforms: " << platforms.size() << std::endl;
    for(PlatformIds::const_iterator i = platforms.begin();
        i != platforms.end(); ++i, ++p) {
        
        std::cout << "\n-----------\n"; 
        std::cout << "Platform " << p << std::endl;
        std::cout << "-----------\n";  
        status = ::clGetPlatformInfo(*i, CL_PLATFORM_VENDOR,
                                     buf.size(), &buf[ 0 ], 0 );
        if(status != CL_SUCCESS) {
            std::cerr << "ERROR - clGetPlatformInfo(): " << std::endl;
            exit(EXIT_FAILURE);    
        }
        std::cout << "Vendor: " << &buf[ 0 ] << '\n'; 
        status = ::clGetPlatformInfo(*i, CL_PLATFORM_PROFILE,
                                     buf.size(), &buf[ 0 ], 0 );
        if(status != CL_SUCCESS) {
            std::cerr << "ERROR - clGetPlatformInfo(): " << std::endl;
            exit(EXIT_FAILURE);
        }
        std::cout << "Profile: " << &buf[ 0 ] << '\n'; 
        status = ::clGetPlatformInfo(*i, CL_PLATFORM_VERSION,
                                     buf.size(), &buf[ 0 ], 0 );
        if(status != CL_SUCCESS) {
            std::cerr << "ERROR - clGetPlatformInfo(): " << std::endl;
            exit(EXIT_FAILURE);
        }
        std::cout << "Version: " << &buf[ 0 ] << '\n';     
        status = ::clGetPlatformInfo(*i, CL_PLATFORM_NAME,
                                     buf.size(), &buf[ 0 ], 0 );
        if(status != CL_SUCCESS) {
            std::cerr << "ERROR - clGetPlatformInfo(): " << std::endl;
            exit(EXIT_FAILURE);
        }
        std::cout << "Name: " << &buf[ 0 ] << '\n';  
        status = ::clGetPlatformInfo(*i, CL_PLATFORM_EXTENSIONS,
                                     buf.size(), &buf[ 0 ], 0 );
        if(status != CL_SUCCESS) {
            std::cerr << "ERROR - clGetPlatformInfo(): " << std::endl;
            exit(EXIT_FAILURE);
        }
        std::cout << "Extensions: " << &buf[ 0 ] << '\n';
        print_devices(*i);
        std::cout << "\n===================================================\n"; 

    }
}
开发者ID:candycode,项目名称:opencl-training,代码行数:70,代码来源:clutil.cpp


示例3: main

int main()
{
	int i,j,k;
	// nb of operations:
	const int dsize = 512;
	int nthreads = 1;
	int nbOfAverages = 1e4;
	int opsMAC = 2; // operations per MAC
	cl_float4 *in, *out;
	cl_float *ck;
	double tops; //total ops

#define NQUEUES 1
	cl_int err;
	cl_platform_id platform = 0;
	cl_device_id device = 0;
	cl_context_properties props[3] = { CL_CONTEXT_PLATFORM, 0, 0 };
	cl_context ctx = 0;
	cl_command_queue queues[NQUEUES];
	cl_mem bufin, bufck, bufout;
	cl_event event = NULL;
	cl_program program;
	cl_kernel kernel;
	size_t global[2], local[2];
	size_t param[5];
	char version[300];
  
	// allocate matrices
	
	in = (cl_float4 *) calloc(dsize*dsize, sizeof(*in));
	out = (cl_float4 *) calloc(dsize*dsize, sizeof(*out));
	ck = (cl_float *) calloc(9*9, sizeof(*ck));
	in[0].x = 2.0f;
	in[1].x = 3.0f;
	in[dsize].x = 1.0;
	ck[0] = 1.0f;
	ck[1] = 0.5f;
	ck[9] = 0.001f;

    /* Setup OpenCL environment. */
    err = clGetPlatformIDs( 1, &platform, NULL );
    err = clGetDeviceIDs( platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL );

    props[1] = (cl_context_properties)platform;
    ctx = clCreateContext( props, 1, &device, NULL, NULL, &err );
    for(i = 0; i < NQUEUES; i++)
    	queues[i] = clCreateCommandQueue( ctx, device, 0, &err );

	// Print some info about the system
	clGetDeviceInfo(device, CL_DEVICE_VERSION, sizeof(version), version, NULL);
	printf("CL_DEVICE_VERSION=%s\n", version);
	clGetDeviceInfo(device, CL_DRIVER_VERSION, sizeof(version), version, NULL);
	printf("CL_DRIVER_VERSION=%s\n", version);
	program = clCreateProgramWithSource(ctx, 1, (const char **)&source, NULL, &err);
	clGetDeviceInfo(device, CL_DEVICE_LOCAL_MEM_SIZE, sizeof(param[0]), param, NULL);
	printf("CL_DEVICE_LOCAL_MEM_SIZE=%d\n", (int)param[0]);
	clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(param[0]), param, NULL);
	printf("CL_DEVICE_MAX_WORK_GROUP_SIZE=%d\n", (int)param[0]);
	clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(param[0]), param, NULL);
	printf("CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS=%d\n", (int)param[0]);
	j = param[0];
	clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_SIZES, sizeof(param[0])*j, param, NULL);
	printf("CL_DEVICE_MAX_WORK_ITEM_SIZES=");
	for(i = 0; i < j; i++)
		printf("%d ", (int)param[i]);
	printf("\n");
        clGetDeviceInfo(device, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, sizeof(param[0]), param, NULL);
        printf("CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE=%d\n", (int)param[0]);
		
		
	program = clCreateProgramWithSource(ctx, 1, (const char **)&source, NULL, &err);
	if(!program)
	{
		printf("Error creating program\n");
		return -1;
	}
	err = clBuildProgram(program, 0, 0, 0, 0, 0);
	if(err != CL_SUCCESS)
	{
		char buffer[20000];
		size_t len;
		
		clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
		puts(buffer);
		return -1;
	}
	kernel = clCreateKernel(program, "conv9x9", &err);
	if(!kernel || err != CL_SUCCESS)
	{
		printf("Error creating kernel\n");
		return -1;
	}

    /* Prepare OpenCL memory objects and place matrices inside them. */
	cl_image_format fmt = {CL_RGBA, CL_FLOAT};
	cl_int rc;
	bufin = clCreateImage2D(ctx, CL_MEM_READ_ONLY, &fmt, dsize, dsize, 0, 0, &rc);
	bufout = clCreateImage2D(ctx, CL_MEM_WRITE_ONLY, &fmt, dsize, dsize, 0, 0, &rc);
    bufck = clCreateBuffer( ctx, CL_MEM_READ_ONLY, 9 * 9 * sizeof(*ck),
                          NULL, &err );
//.........这里部分代码省略.........
开发者ID:e-lab,项目名称:OpenCLconv,代码行数:101,代码来源:clconvimg_float4_pc.c


示例4: setup_opencl

void
setup_opencl(const char* cl_source_filename, const char* cl_source_main, cl_device_id* device_id,
             cl_kernel* kernel, cl_context* context, cl_command_queue* queue)
{
        cl_int err;					// error code returned from api calls

        cl_platform_id platform_id;			// compute device id
        cl_program program;				// compute program
        cl_device_id devices[MAX_RESOURCES];
        cl_platform_id platforms[MAX_RESOURCES];


        unsigned int best_platform = 0;
        unsigned int best_device = 0;
        print_devices(0);

        if(!get_best_device(&best_platform, &best_device)) {
                printf("No suitable device was found! Try using an OpenCL1.1 compatible device.\n");
                exit(1);
        }
        printf("Initiating platform-%d device-%d.\n", best_platform, best_device);



        // Platform
        err = clGetPlatformIDs(MAX_RESOURCES, platforms, NULL);
	ocl_error("Getting platform id", err);

        platform_id = platforms[best_platform];

        // Device
        err = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL, sizeof(devices), devices, NULL); //NULL, ignore number returned devices.
	ocl_error("Getting device ids", err);

        *device_id = devices[best_device];

        // Context
        *context = clCreateContext(0, 1, device_id, NULL, NULL, &err);
	ocl_error("Creating context", err);

        // Command-queue
        *queue = clCreateCommandQueue(*context, *device_id, 0, &err);
	ocl_error("Creating command queue", err);


        // Read .cl source into memory
        int cl_source_len = 0;
        char* cl_source = file_contents(cl_source_filename, &cl_source_len);


        // Create thes compute program from the source buffer
        program = clCreateProgramWithSource(*context, 1, (const char **) &cl_source, NULL, &err);
	ocl_error("Failed to create compute program", err);


        // Build the program executable
        err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
        if (err != CL_SUCCESS) {
                char* build_log;
                size_t log_size;
                // First call to know the proper size
                clGetProgramBuildInfo(program, *device_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);
                build_log = malloc(sizeof(char)*(log_size+1));
                if(log_size > 0 && build_log != NULL) {
	                // Second call to get the log
	                clGetProgramBuildInfo(program, *device_id, CL_PROGRAM_BUILD_LOG, log_size, build_log, NULL);
	                build_log[log_size] = '\0';
	                printf("%s\n", build_log);
	                free(build_log);
                }

                exit(err);
        }


        // Create the compute kernel in the program we wish to run
        *kernel = clCreateKernel(program, cl_source_main, &err);
	ocl_error("Failed to create compute kernel", err);
}
开发者ID:robertfoss,项目名称:opencl_c99_sample,代码行数:79,代码来源:opencl.c


示例5: piglit_cl_test

PIGLIT_CL_API_TEST_CONFIG_END


enum piglit_result
piglit_cl_test(const int argc,
               const char** argv,
               const struct piglit_cl_api_test_config* config,
               const struct piglit_cl_api_test_env* env)
{
	enum piglit_result result = PIGLIT_PASS;

	int i;
	cl_int errNo;
	cl_uint num_platforms;
	cl_platform_id* platforms = NULL;

	/*** Normal usage ***/

	/* get number of platforms */
	errNo = clGetPlatformIDs(0, NULL, &num_platforms);
	if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
		piglit_cl_check_error(errNo, CL_SUCCESS);
		fprintf(stderr,
		        "Failed (error code: %s): Get size of platform list.\n",
		        piglit_cl_get_error_name(errNo));
		piglit_merge_result(&result, PIGLIT_FAIL);
	} else {
		/*
		 * Get platform list.
		 * Try returning from 1 to num_platforms platforms.
		 */
		for(i = 1; i <= num_platforms; i++) {
			platforms = malloc(i * sizeof(cl_platform_id));
			errNo = clGetPlatformIDs(i, platforms, NULL);
			if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
				fprintf(stderr,
				        "Failed (error code: %s): Get platform list.\n",
				        piglit_cl_get_error_name(errNo));
				piglit_merge_result(&result, PIGLIT_FAIL);
			}
			free(platforms);
		}
	}
	
	/*** Errors ***/

	/*
	 * CL_INVALID_VALUE if num_entries is equal
	 * to zero and platforms is not NULL, or if both num_platforms 
	 * and platforms are NULL.
	 */
	errNo = clGetPlatformIDs(0, platforms, NULL);
	if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
		fprintf(stderr,
		        "Failed (error code: %s): Trigger CL_INVALID_VALUE if num_entries is equeal to zero and platforms is not NULL.\n",
		        piglit_cl_get_error_name(errNo));
		piglit_merge_result(&result, PIGLIT_FAIL);
	}
	errNo = clGetPlatformIDs(100, NULL, NULL);
	if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
		fprintf(stderr,
		        "Failed (error code: %s): Trigger CL_INVALID_VALUE if both num_platforms and platforms are NULL.\n",
		        piglit_cl_get_error_name(errNo));
		piglit_merge_result(&result, PIGLIT_FAIL);
	}

	return result;
}
开发者ID:BNieuwenhuizen,项目名称:piglit,代码行数:68,代码来源:get-platform-ids.c


示例6: releaseCL

  bool Filter::initCL(const Params& params,
                      const char *source, const char *options)
  {
    // Ensure no existing context
    releaseCL();

    cl_int err;
    cl_uint numPlatforms, numDevices;

    cl_platform_id platform, platforms[params.platformIndex+1];
    err = clGetPlatformIDs(params.platformIndex+1, platforms, &numPlatforms);
    CHECK_ERROR_OCL(err, "getting platforms", return false);
    if (params.platformIndex >= numPlatforms)
    {
      reportStatus("Platform index %d out of range (%d platforms found)",
        params.platformIndex, numPlatforms);
      return false;
    }
    platform = platforms[params.platformIndex];

    cl_device_id devices[params.deviceIndex+1];
    err = clGetDeviceIDs(platform, params.type,
                         params.deviceIndex+1, devices, &numDevices);
    CHECK_ERROR_OCL(err, "getting devices", return false);
    if (params.deviceIndex >= numDevices)
    {
      reportStatus("Device index %d out of range (%d devices found)",
        params.deviceIndex, numDevices);
      return false;
    }
    m_device = devices[params.deviceIndex];

    char name[64];
    clGetDeviceInfo(m_device, CL_DEVICE_NAME, 64, name, NULL);
    reportStatus("Using device: %s", name);

    m_context = clCreateContext(NULL, 1, &m_device, NULL, NULL, &err);
    CHECK_ERROR_OCL(err, "creating context", return false);

    m_queue = clCreateCommandQueue(m_context, m_device,
                                   CL_QUEUE_PROFILING_ENABLE, &err);
    CHECK_ERROR_OCL(err, "creating command queue", return false);

    m_program = clCreateProgramWithSource(m_context, 1, &source, NULL, &err);
    CHECK_ERROR_OCL(err, "creating program", return false);

    err = clBuildProgram(m_program, 1, &m_device, options, NULL, NULL);
    if (err == CL_BUILD_PROGRAM_FAILURE)
    {
      size_t sz;
      clGetProgramBuildInfo(
        m_program, m_device, CL_PROGRAM_BUILD_LOG, 0, NULL, &sz);
      char *log = (char*)malloc(++sz);
      clGetProgramBuildInfo(
        m_program, m_device, CL_PROGRAM_BUILD_LOG, sz, log, NULL);
      reportStatus(log);
      free(log);
    }
    CHECK_ERROR_OCL(err, "building program", return false);

    reportStatus("OpenCL context initialised.");
    return true;
  }
开发者ID:jrprice,项目名称:improsa,代码行数:63,代码来源:Filter.cpp


示例7: main

int main(int argc, char *argv[])
{
    cl_platform_id platform;
    cl_device_id device;
    cl_context context;
    cl_command_queue queue;
    cl_program program;
    cl_kernel kernel_one, kernel_path;
    cl_mem d_mt_state, d_mt_emit, d_max_prob_old;
    cl_mem d_max_prob_new, d_path, v_prob, v_path;

    int wg_size = 256;
    int n_state = 256*16;
    int n_emit = 128;
    int n_obs = 100;

    size_t init_prob_size = sizeof(float) * n_state;
    size_t mt_state_size = sizeof(float) * n_state * n_state;
    size_t mt_emit_size = sizeof(float) * n_emit * n_state;

    float *init_prob = (float *) malloc(init_prob_size);
    float *mt_state = (float *) malloc(mt_state_size);
    float *mt_emit = (float *) malloc(mt_emit_size);
    int *obs = (int *) malloc(sizeof(int) * n_obs);
    int *viterbi_gpu = (int *) malloc(sizeof(int) * n_obs);

    srand(2012);
    initHMM(init_prob, mt_state, mt_emit, n_state, n_emit);

    int i;
    for (i = 0; i < n_obs; i++) {
        obs[i] = i % 15;
    }

    const char *source = load_program_source("Viterbi.cl");
    size_t source_len = strlen(source);;
    cl_uint err = 0;

    char *flags = "-cl-fast-relaxed-math";

    clGetPlatformIDs(1, &platform, NULL);
    printf("platform %p err %d\n", platform, err);

    clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, 1, &device, &err);
    printf("device %p err %d\n", device, err);

    context = clCreateContext(0, 1, &device, NULL, NULL, &err);
    printf("context %p err %d\n", context, err);

    queue = clCreateCommandQueue(context, device, 0, &err);
    printf("queue %p err %d\n", queue, err);

    program = clCreateProgramWithSource(context, 1, &source, &source_len, &err);
    printf("program %p err %d\n", program, err);

    err = clBuildProgram(program, 0, NULL, flags, NULL, NULL);
    printf("err %d\n", err);

    /*
    char tmp[102400];
    clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, sizeof(tmp),
        tmp, NULL);

    printf("error %s\n", tmp);
    */

    kernel_one = clCreateKernel(program, "ViterbiOneStep", &err);
    printf("kernel %p err %d\n", kernel_one, err);

    kernel_path = clCreateKernel(program, "ViterbiPath", &err);
    printf("kernel %p err %d\n", kernel_path, err);

    d_mt_state = clCreateBuffer(context, CL_MEM_READ_ONLY, mt_state_size, 
        NULL, &err);
    printf("buffer %p\n", d_mt_state);

    d_mt_emit = clCreateBuffer(context, CL_MEM_READ_ONLY, mt_emit_size, 
        NULL, &err);
    printf("buffer %p\n", d_mt_emit);

    d_max_prob_new = clCreateBuffer(context, CL_MEM_READ_WRITE, 
        init_prob_size, NULL, &err);
    printf("buffer %p\n", d_max_prob_new);

    d_max_prob_old = clCreateBuffer(context, CL_MEM_READ_WRITE, 
        init_prob_size, NULL, &err);
    printf("buffer %p\n", d_max_prob_old);

    d_path = clCreateBuffer(context, CL_MEM_READ_WRITE, 
        sizeof(int)*(n_obs-1)*n_state, NULL, &err);
    printf("buffer %p\n", d_path);

    v_prob = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(float),
        NULL, &err);
    printf("buffer %p\n", v_prob);

    v_path = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*n_obs,
        NULL, &err);
    printf("buffer %p\n", v_prob);

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


示例8: SetupComputeDevices

static int 
SetupComputeDevices(int gpu)
{
	int err;
	size_t returned_size;
	ComputeDeviceType = gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU;

#if (USE_GL_ATTACHMENTS)

	printf(SEPARATOR);
	printf("Using active OpenGL context...\n");

	// Bind to platform
	cl_platform_id platform_id;

	cl_uint numPlatforms;
	cl_int status = clGetPlatformIDs(0, NULL, &numPlatforms);
	if (status != CL_SUCCESS)
	{
		printf("clGetPlatformIDs Failed\n");
		return EXIT_FAILURE;
	}

	if (0 < numPlatforms)
	{
		cl_platform_id* platforms = (cl_platform_id*)calloc(numPlatforms, sizeof(cl_platform_id));

		status = clGetPlatformIDs(numPlatforms, platforms, NULL);

		char platformName[100];
		for (unsigned i = 0; i < numPlatforms; ++i)
		{
			status = clGetPlatformInfo(platforms[i],
				CL_PLATFORM_VENDOR,
				sizeof(platformName),
				platformName,
				NULL);
			platform_id = platforms[i];
			if (!strcmp(platformName, "Advanced Micro Devices, Inc."))
			{
				break;
			}
		}
		printf("Platform found : %s\n", platformName);
		free(platforms);
	}
	if(NULL == platform_id)
	{
		printf("NULL platform found so Exiting Application.\n");
		return EXIT_FAILURE;
	}

	// Get ID for the device
	err = clGetDeviceIDs(platform_id, ComputeDeviceType, 1, &ComputeDeviceId, NULL);
	if (err != CL_SUCCESS)
	{
		printf("Error: Failed to locate compute device!\n");
		return EXIT_FAILURE;
	}

	// Create a context  
	cl_context_properties properties[] =
	{
		CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
		CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(),
		CL_CONTEXT_PLATFORM, (cl_context_properties)(platform_id),
		0
	};

	// Create a context from a CGL share group
	//
	ComputeContext = clCreateContext(properties, 1, &ComputeDeviceId, NULL, 0, 0);
	if (!ComputeContext)
	{
		printf("Error: Failed to create a compute context!\n");
		return EXIT_FAILURE;
	}

#else

	// Bind to platform
	cl_platform_id platform_id;

	cl_uint numPlatforms;
	cl_int status = clGetPlatformIDs(0, NULL, &numPlatforms);
	if (status != CL_SUCCESS)
	{
		printf("clGetPlatformIDs Failed\n");
		return EXIT_FAILURE;
	}

	if (0 < numPlatforms)
	{
		cl_platform_id* platforms = (cl_platform_id*)calloc(numPlatforms, sizeof(cl_platform_id));

		status = clGetPlatformIDs(numPlatforms, platforms, NULL);

		char platformName[100];
		for (unsigned i = 0; i < numPlatforms; ++i)
		{
//.........这里部分代码省略.........
开发者ID:hominidclint,项目名称:cl-gl-benchmark,代码行数:101,代码来源:FFT.cpp


示例9: main

int main(int argc, char*argv[]) {

	if (argc != 4) {
		printf("Usage: %s #m #n #k\n", argv[0]);
		exit(1);
	}
	int *m,*n,*k,i;
	m = (int *) malloc(sizeof(int));
	n = (int *) malloc(sizeof(int));
	k = (int *) malloc(sizeof(int));

	//Initilizing the matrix dimensions
	m[0] = atoi(argv[1]);
	n[0] = atoi(argv[2]);
	k[0] = atoi(argv[3]);

	double time = 0;

	clock_t begin = clock();
	cl_device_id deviceId = NULL;
	cl_context context = NULL;
	cl_command_queue commandQueue = NULL;

	double *alpha, *beta;

	//allocating memory for the vectors
	
	alpha = (double *) malloc(sizeof(double));
	beta = (double *) malloc(sizeof(double));

    double *A, *B, *C;
	
    A = (double *) malloc(m[0]*k[0]*sizeof(double));
    B = (double *) malloc(k[0]*n[0]*sizeof(double));
    C = (double *) malloc(m[0]*n[0]*sizeof(double));

	//initializing values of alpha and beta
	alpha[0] = 1.0;
	beta[0] = 0.0;

	clock_t end = clock();

	time += (double)(end - begin) * 1000 / CLOCKS_PER_SEC;

	//printf (" Intializing matrix data \n\n");
	begin = clock();
	for (i = 0; i < (m[0]*k[0]); i++) {
		A[i] = (double)(i+1);
	}

	for (i = 0; i < (k[0]*n[0]); i++) {
		B[i] = (double)(-i-1);
	}

	for (i = 0; i < (m[0]*n[0]); i++) {
		C[i] = 0.0;
	}

	//Memory objects for kernel parameters
	cl_mem AMemobj = NULL;
	cl_mem BMemobj = NULL;
	cl_mem CMemobj = NULL;
	cl_mem mMemobj = NULL;
	cl_mem nMemobj = NULL;
	cl_mem kMemobj = NULL;
	cl_mem alphaMemobj = NULL;
	cl_mem betaMemobj = NULL;

	//Some opencl objects
	cl_program program = NULL;
	cl_kernel kernel = NULL;
	cl_platform_id platformId = NULL;
	cl_uint numDevices;
	cl_uint numPlatforms;
	cl_int ret;
	size_t contextDescriptorSize;

	//reading kernel from file
	FILE *file;
	char fileName[] = "./dgemm.cl";
	char *kernelSource;
	size_t sourceSize;
	
	//Load the source code from file
	file = fopen(fileName, "r");
	if(!file) {
		printf("Failed to load the kernel file. \n");
		exit(1);
	}

	kernelSource = (char *) malloc(SOURCE_SIZE_MAX);
	sourceSize = fread(kernelSource, 1, SOURCE_SIZE_MAX, file);
	fclose(file);

	//Get platform information
	ret = clGetPlatformIDs(1, &platformId, &numPlatforms);

	//get list of devices
	ret = clGetDeviceIDs(platformId, CL_DEVICE_TYPE_DEFAULT, 1, &deviceId, &numDevices);
	
//.........这里部分代码省略.........
开发者ID:STEllAR-GROUP,项目名称:hpxcl,代码行数:101,代码来源:dgemmCL.c


示例10: Rprintf

void OCL_base::init_kernel(const char* kernel_source, const char* kernel_name, 
			   std::string define_statements, bool compile_source)
{
  if(!compile_source){
    Rprintf("Binary sources not supported yet\n");
    return;
  }  

  char* kernel_buffer = 0;
  size_t k_buffer_size=0;
  // if the kernel source has been predefined in "../oCL_Kernels/oCL_Kernels.h"
  // then use that.
  if(!strcmp(kernel_source, "move_deltoids")){  // strcmp returns 0 for equal
    kernel_buffer = make_source(define_statements, move_deltoids, k_buffer_size);
  }
  if(!strcmp(kernel_source, "move_deltoids_2")){
    kernel_buffer = make_source(define_statements, move_deltoids_2, k_buffer_size);
  }
  if(!strcmp(kernel_source, "move_deltoids_dummy")){
    kernel_buffer = make_source(define_statements, move_deltoids_dummy, k_buffer_size);
  }
    

  // if kernel buffer is not defined yet, try to read it from a file
  if(!kernel_buffer){
    std::ifstream in(kernel_source, std::ios::binary);
    if(!in){
      Rprintf("Unable to open kernel source file\n");
      return;
    }
    in.seekg(0, std::ios::end);
    ssize_t end_pos = in.tellg();
    Rprintf("in.tellg() reports : %d\n", end_pos);
    in.seekg(0, std::ios::beg);
    if(!end_pos){
      Rprintf("Unable to read from kernel source file\n");
      return;
    }
    // prepend #define statements to the kernal source.
    // add one extra \n to the 
    
    k_buffer_size = 1 + define_statements.size() + (size_t)end_pos + 1;
    kernel_buffer = new char[ k_buffer_size ];
    memset((void*)kernel_buffer, 0, sizeof(char) * k_buffer_size);
    //  kernel_buffer[k_buffer_size] = 0;  // this may not be needed.
    
    size_t copied_bytes = define_statements.copy(kernel_buffer, define_statements.size());
    if(copied_bytes != define_statements.size()){
      Rprintf("Unable to copy the full define statements\n");
      delete []kernel_buffer;
      return;
    }

    kernel_buffer[ define_statements.size() ] = '\n'; // add a new line for safety

    in.read((kernel_buffer + 1 + define_statements.size()), end_pos);
    if(in.gcount() != end_pos){
      Rprintf("Unable to read to end of kernel source file: %d != %d\n",
	      end_pos, in.gcount());
      delete []kernel_buffer;
      return;
    }
  }
  // at this point kernel_buffer should be defined.
  // and we can use it to compile the kernel.

  cl_int ret = 0; // return value. Use the same for all.
  
  ret = clGetPlatformIDs(1, &platform_id, &num_platforms);
  if(ret) report_error_pf("clGetPlatformIDs", ret);
  ret = clGetDeviceIDs( platform_id, CL_DEVICE_TYPE_GPU, 1,
			&device_id, &num_devices );
  if(ret) report_error_pf("clGetDeviceIDs", ret);
  if(ret != CL_SUCCESS){
    Rprintf("clGetDevice returned with error: %d\n", (int)ret);
    return;
  }

  context = clCreateContext(NULL, 1, &device_id, NULL, NULL, &ret);
  report_error_pf("clCreateContext", ret);

  command_que = clCreateCommandQueue(context, device_id, CL_QUEUE_PROFILING_ENABLE, &ret);
  report_error_pf("clCreateCommandQueue", ret);

  program = clCreateProgramWithSource(context, 1, (const char**)&kernel_buffer, 
				      (const size_t*)&k_buffer_size, &ret);
  report_error_pf("clCreateProgramWithSource", ret);

  
  clBuildProgram(program, 1, &device_id, NULL, NULL, NULL);
  report_error_pf("clBuildProgram", ret);

  char* build_log = NULL;
  size_t log_size = 1000;
  ret = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, 0, build_log, &log_size);
  report_error_pf("clGetProgramBuildInfo", ret);
  build_log = new char[log_size+1];
  ret = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, log_size, build_log, NULL);
  report_error_pf("clGetProgramBuildInfo", ret);
  
//.........这里部分代码省略.........
开发者ID:cran,项目名称:SOD,代码行数:101,代码来源:oCL_base.cpp


示例11: clcontext_create

LIBSTDCL_API CONTEXT* 
clcontext_create( 
	const char* platform_name, 
	int devtyp, 
	size_t ndevmax,
	cl_context_properties* ctxprop_ext, 
	int lock_key
)
{

	int n;
	int err = 0;
	int i;
	size_t devlist_sz;
	CONTEXT* cp = 0;
	cl_platform_id* platforms = 0;
	cl_uint nplatforms;
	char info[1024];
	cl_platform_id platformid;
	int nctxprop = 0;
	cl_context_properties* ctxprop;
	size_t sz;
	cl_uint ndev = 0;
	cl_command_queue_properties prop = 0;

	DEBUG(__FILE__,__LINE__,"clcontext_create() called");


//	if (ndevmax) 
//		WARN(__FILE__,__LINE__,"__clcontext_create(): ndevmax argument ignored");


	/***
	 *** allocate CONTEXT struct
	 ***/

	DEBUG(__FILE__,__LINE__,
		"clcontext_create: sizeof CONTEXT %d",sizeof(CONTEXT));

//	cp = (CONTEXT*)malloc(sizeof(CONTEXT));
	assert(sizeof(CONTEXT)<getpagesize());
#ifdef _WIN64
	cp = (CONTEXT*)_aligned_malloc(sizeof(CONTEXT),getpagesize());
	if (!cp) {
		WARN(__FILE__,__LINE__,"memalign failed");
	}
#else
	if (posix_memalign((void**)&cp,getpagesize(),sizeof(CONTEXT))) {
		WARN(__FILE__,__LINE__,"posix_memalign failed");
	}
#endif

	DEBUG(__FILE__,__LINE__,"clcontext_create: context_ptr=%p",cp);
	
	if ((intptr_t)cp & (getpagesize()-1)) {
		ERROR(__FILE__,__LINE__,
			"clcontext_create: fatal error: unaligned context_ptr");
		exit(-1);
	}

	if (!cp) { errno=ENOMEM; return(0); }

	

   /***
    *** get platform id
    ***/



   clGetPlatformIDs(0,0,&nplatforms);

//	printf("XXX %d\n",nplatforms);

   if (nplatforms) {

      platforms = (cl_platform_id*)malloc(nplatforms*sizeof(cl_platform_id));
      clGetPlatformIDs(nplatforms,platforms,0);

      for(i=0;i<nplatforms;i++) { 

         char info[1024];

         DEBUG(__FILE__,__LINE__,"_libstdcl_init: available platform:");

         clGetPlatformInfo(platforms[i],CL_PLATFORM_PROFILE,1024,info,0);
         DEBUG(__FILE__,__LINE__,
            "_libstdcl_init: [%p]CL_PLATFORM_PROFILE=%s",platforms[i],info);

         clGetPlatformInfo(platforms[i],CL_PLATFORM_VERSION,1024,info,0);
         DEBUG(__FILE__,__LINE__,
            "_libstdcl_init: [%p]CL_PLATFORM_VERSION=%s",platforms[i],info);

         clGetPlatformInfo(platforms[i],CL_PLATFORM_NAME,1024,info,0);
         DEBUG(__FILE__,__LINE__,
            "_libstdcl_init: [%p]CL_PLATFORM_NAME=%s",platforms[i],info);

         clGetPlatformInfo(platforms[i],CL_PLATFORM_VENDOR,1024,info,0);
         DEBUG(__FILE__,__LINE__,
            "_libstdcl_init: [%p]CL_PLATFORM_VENDOR=%s",platforms[i],info);
//.........这里部分代码省略.........
开发者ID:jdekozak,项目名称:coprthr,代码行数:101,代码来源:clcontext.c


示例12: OCL_LoadLibrary

cl_int OCL_Environment::init(OCL_Environment_Desc desc)
{

	OCL_LoadLibrary();

	// Get number of  available platforms
	OCL_RETURN_ON_ERR( clGetPlatformIDs( 0, NULL, &uiNumPlatforms ) );

	if( !(uiNumPlatforms > 0) )
	{
		printf("No available platform!");
		abort();
	}

	// Create platforms
	cl_platform_id*	pPlatformIDs = (cl_platform_id*)calloc( sizeof(cl_platform_id), uiNumPlatforms );
	
	OCL_RETURN_ON_ERR( clGetPlatformIDs( uiNumPlatforms, pPlatformIDs, NULL ) );

	// Alloc OCL_Platforms
	if( desc.sPlatformName )
		mpPlatforms = new OCL_Platform[1];
	else
		mpPlatforms = new OCL_Platform[uiNumPlatforms];
	
	bool founddev = false;

	for( cl_uint i=0; i<uiNumPlatforms; i++ )
	{
		char* sPlatname;
		size_t nameSize;
		OCL_RETURN_ON_ERR( clGetPlatformInfo( pPlatformIDs[i], CL_PLATFORM_NAME, 0, NULL, &nameSize ) );

		sPlatname = new char[nameSize];
		OCL_RETURN_ON_ERR( clGetPlatformInfo( pPlatformIDs[i], CL_PLATFORM_NAME, nameSize, sPlatname, NULL ) );

		if( desc.sPlatformName )
		{
			if( strcmp(sPlatname,desc.sPlatformName ) == 0 )
			{
				uiNumPlatforms = 1;
				OCL_RETURN_ON_ERR( mpPlatforms[0].init(pPlatformIDs[i],desc) );
                founddev = true;
                break;
			}
		}
		else
		{
			OCL_RETURN_ON_ERR( mpPlatforms[i].init(pPlatformIDs[i],desc) );
			if(mpPlatforms[i].uiNumDevices > 0)
				founddev = true;//at least 1 compatible device found
		}
	}

	delete pPlatformIDs;
	//if no device found return the error
	if(!founddev)
		OCL_RETURN_ON_ERR(CL_DEVICE_NOT_FOUND);

	return CL_SUCCESS;
}
开发者ID:ChiahungTai,项目名称:OpenCL-playgorund,代码行数:61,代码来源:OCL_Environment.cpp


示例13: PlatformContext

static cl::Context PlatformContext(cl_device_type device_type, char* platform_vendor_name, bool enable_gl_interop = false)
    {
        cl_uint numPlatforms;
        cl_platform_id platform = NULL;
        clGetPlatformIDs(0, NULL, &numPlatforms);
        if (numPlatforms > 0)
        {
            cl_platform_id* platforms = new cl_platform_id[numPlatforms];
            clGetPlatformIDs(numPlatforms, platforms, NULL);
            for (unsigned i = 0; i < numPlatforms; ++i)
            {
                char pbuf[100];
                clGetPlatformInfo(platforms[i],
                                   CL_PLATFORM_VENDOR,
                                   sizeof(pbuf),
                                   pbuf,
                                   NULL);

                platform = platforms[i];
                std::cout << "platform: " << pbuf << std::endl;
                if (!strcmp(pbuf, platform_vendor_name))
                {
                    break;
                }
            }
            delete[] platforms;
        }

        if (enable_gl_interop)
        {
        // Define OS-specific context properties and create the OpenCL context
        #if defined (__APPLE__)
            CGLContextObj kCGLContext = CGLGetCurrentContext();
            CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);
            cl_context_properties cps[] =
            {
                CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)kCGLShareGroup,
                0
            };
        #else
            #if defined(linux)
                cl_context_properties cps[] =
                {
                    CL_GL_CONTEXT_KHR, cl_context_properties(glXGetCurrentContext()),
                    CL_GLX_DISPLAY_KHR, cl_context_properties(glXGetCurrentDisplay()),
                    CL_CONTEXT_PLATFORM, cl_context_properties(platform),
                    0
                };
            #else // Win32
                cl_context_properties cps[] =
                {
                    CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(),
                    CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(),
                    CL_CONTEXT_PLATFORM, (cl_context_properties)platform,
                    0
                };
            #endif
        #endif

        cl::Platform _platform(platform);
        cl::vector<cl::Device> *_devices = new cl::vector<cl::Device>();
        _platform.getDevices(CL_DEVICE_TYPE_GPU, _devices);

        if(_devices->size() > 1)
            _devices->pop_back();
        if (platform == NULL)
            return cl::Context(device_type, NULL);
        else
            return cl::Context(*_devices,cps);

        return (NULL == platform) ? cl::Context(device_type, NULL) :  cl::Context(*_devices, cps);

        }else //no opengl interoperability
        {
            cl_context_properties cps[] =
            {
                CL_CONTEXT_PLATFORM, cl_context_properties(platform),
                0
            };
            return (NULL == platform) ? cl::Context(device_type, NULL) : cl::Context(device_type, cps);
        }
    }
开发者ID:bobbyblues,项目名称:Iwao,代码行数:82,代码来源:clm.cpp


示例14: main

int main() {
    // This code executes on the OpenCL host
    
    // Host data
    int *A = NULL;  // Input array
    int *B = NULL;  // Input array
    int *C = NULL;  // Output array
    
    // Elements in each array
    const int elements = 2048;   
    
    // Compute the size of the data 
    size_t datasize = sizeof(int)*elements;

    // Allocate space for input/output data
    A = (int*)malloc(datasize);
    B = (int*)malloc(datasize);
    C = (int*)malloc(datasize);

    // Initialize the input data
    int i;
    for(i = 0; i < elements; i++) {
        A[i] = i;
        B[i] = i;
    }

    // Use this to check the output of each API call
    cl_int status;  
     
    // Retrieve the number of platforms
    cl_uint numPlatforms = 0;
    status = clGetPlatformIDs(0, NULL, &numPlatforms);

    // Allocate enough space for each platform
    cl_platform_id *platforms = NULL;
    platforms = (cl_platform_id*)malloc(
        numPlatforms*sizeof(cl_platform_id));
 
    // Fill in the platforms
    status = clGetPlatformIDs(numPlatforms, platforms, NULL);

	cl_int platform_index = -1;
	char cBuffer[1024];
	for (i=0; i<numPlatforms; i++) {
		clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, sizeof(cBuffer), cBuffer, NULL);
		if (strstr(cBuffer, "Intel") != NULL) {
			platform_index = i;
			break;
		}
	}
	if (platform_index < 0) {
		printf("Cannot find platforms support OpenCL.\n");
		return -1;
	}
	else {
		printf("Selected platform '%s'. %d\n", cBuffer, platform_index);
	}

    // Retrieve the number of devices
    cl_uint numDevices = 0;
    status = clGetDeviceIDs(platforms[platform_index], CL_DEVICE_TYPE_CPU, 0, 
        NULL, &numDevices);

    // Allocate enough space for each device
    cl_device_id *devices;
    devices = (cl_device_id*)malloc(
        numDevices*sizeof(cl_device_id));

    // Fill in the devices 
    status = clGetDeviceIDs(platforms[platform_index], CL_DEVICE_TYPE_ALL,        
        numDevices, devices, NULL);

    // Create a context and associate it with the devices
    cl_context context;
    context = clCreateContext(NULL, numDevices, devices, NULL, 
        NULL, &status);

    // Create a command queue and associate it with the device 
    cl_command_queue cmdQueue;
    cmdQueue = clCreateCommandQueue(context, devices[0], 0, 
        &status);

    // Create a buffer object that will contain the data 
    // from the host array A
    cl_mem bufA;
    bufA = clCreateBuffer(context, CL_MEM_READ_ONLY, datasize,                       
       NULL, &status);

    // Create a buffer object that will contain the data 
    // from the host array B
    cl_mem bufB;
    bufB = clCreateBuffer(context, CL_MEM_READ_ONLY, datasize,                        
        NULL, &status);

    // Create a buffer object that will hold the output data
    cl_mem bufC;
    bufC = clCreateBuffer(context, CL_MEM_WRITE_ONLY, datasize,
        NULL, &status); 
    
    // Write input array A to the device buffer bufferA
//.........这里部分代码省略.........
开发者ID:asanciangco,项目名称:CS133,代码行数:101,代码来源:vectoradd.c


示例15: initFPGA

struct cl_package initFPGA( const char* xclbin, const char* kernel_name )
{
	/*****************************************/
	/* Initialize OpenCL */
	/*****************************************/

	// Retrieve the number of platforms
    cl_uint numPlatforms = 0;
    cl_int status = clGetPlatformIDs(0, NULL, &numPlatforms);

	//printf("Found %d platforms support OpenCL, return code %d.\n", numPlatforms, status);
 
    // Allocate enough space for each platform
    cl_platform_id *platforms = (cl_platform_id*)malloc( numPlatforms*sizeof(cl_platform_id));
 
    status = clGetPlatformIDs(numPlatforms, platforms, NULL);
	if (status != CL_SUCCESS)
		printf("clGetPlatformIDs error(%d)\n", status);
	
	// Retrieve the number of devices
    cl_uint numDevices = 0;
#ifndef FPGA_DEVICE
    status = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_ALL, 0, NULL, &numDevices);
#else
    status = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_ACCELERATOR, 0, NULL, &numDevices);
#endif
	printf("Found %d devices support OpenCL.\n", numDevices);

    // Allocate enough space for each device
    cl_device_id *devices = (cl_device_id*)malloc( numDevices*sizeof(cl_device_id));

    // Fill in the devices 
#ifndef FPGA_DEVICE
    status = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_ALL, numDevices, devices, NULL);
#else
    status = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_ACCELERATOR, numDevices, devices, NULL);
#endif
	
	if (status != CL_SUCCESS)
		printf("clGetDeviceIDs error(%d)\n", status);

    // Create a context and associate it with the devices
    cl_context context;
    context = clCreateContext(NULL, numDevices, devices, NULL, NULL, &status);
	if (status != CL_SUCCESS)
		printf("clCreateContext error(%d)\n", status);


	//Create a command-queue
	cl_command_queue clCommandQue = clCreateCommandQueue(context, devices[0], 0, &status);

	if (status != CL_SUCCESS)
		printf("clCreateCommandQueue error(%d)\n", status);

	// 6. Load and build OpenCL kernel
	
#ifndef FPGA_D 

鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ clGetPlatformInfo函数代码示例发布时间:2022-05-30
下一篇:
C++ clGetDeviceInfo函数代码示例发布时间: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