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

C++ clGetContextInfo函数代码示例

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

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



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

示例1: clCreateContextFromType

nsresult dpoCContext::InitContext(cl_platform_id platform)
{
	cl_int err_code;
	cl_device_id *devices;
	size_t cb;

	cl_context_properties context_properties[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties)platform, NULL};
	
	context = clCreateContextFromType(context_properties, CL_DEVICE_TYPE_CPU, ReportCLError, this, &err_code);
	if (err_code != CL_SUCCESS) {
		DEBUG_LOG_ERROR("InitContext", err_code);
		return NS_ERROR_NOT_AVAILABLE;
	}

	err_code = clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &cb);
	if (err_code != CL_SUCCESS) {
		DEBUG_LOG_ERROR("InitContext", err_code);
		return NS_ERROR_NOT_AVAILABLE;
	}

	devices = (cl_device_id *)nsMemory::Alloc(sizeof(cl_device_id)*cb);
	if (devices == NULL) {
		DEBUG_LOG_STATUS("InitContext", "Cannot allocate device list");
		return NS_ERROR_OUT_OF_MEMORY;
	}

	err_code = clGetContextInfo(context, CL_CONTEXT_DEVICES, cb, devices, NULL);
	if (err_code != CL_SUCCESS) {
		DEBUG_LOG_ERROR("InitContext", err_code);
		nsMemory::Free(devices);
		return NS_ERROR_NOT_AVAILABLE;
	}

	cmdQueue = clCreateCommandQueue(context, devices[0], 
#ifdef CLPROFILE 
		CL_QUEUE_PROFILING_ENABLE |
#endif /* CLPROFILE */
#ifdef OUTOFORDERQUEUE
		CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE |
#endif /* OUTOFORDERQUEUE */
		0,
		&err_code);
	if (err_code != CL_SUCCESS) {
		DEBUG_LOG_ERROR("InitContext", err_code);
		nsMemory::Free(devices);
		return NS_ERROR_NOT_AVAILABLE;
	}

	DEBUG_LOG_STATUS("InitContext", "queue is " << cmdQueue);

	nsMemory::Free(devices);

	kernelFailureMem = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int), NULL, &err_code);
	if (err_code != CL_SUCCESS) {
		DEBUG_LOG_ERROR("InitContext", err_code);
		return NS_ERROR_NOT_AVAILABLE;
	}

	return NS_OK;
}
开发者ID:csvurt,项目名称:RiverTrail,代码行数:60,代码来源:dpoCContext.cpp


示例2: initialize

static int initialize(int use_gpu)
{
	cl_int result;
	size_t size;

#ifndef POCL_HSA
	// create OpenCL context
	cl_platform_id platform_id;
	if (clGetPlatformIDs(1, &platform_id, NULL) != CL_SUCCESS) { printf("ERROR: clGetPlatformIDs(1,*,0) failed\n"); return -1; }
	cl_context_properties ctxprop[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platform_id, 0};
	device_type = use_gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU;
	context = clCreateContextFromType( ctxprop, device_type, NULL, NULL, NULL );
#else
	context = poclu_create_any_context();
#endif
	if( !context ) { printf("ERROR: clCreateContextFromType(%s) failed\n", use_gpu ? "GPU" : "CPU"); return -1; }

	// get the list of GPUs
	result = clGetContextInfo( context, CL_CONTEXT_DEVICES, 0, NULL, &size );
	num_devices = (int) (size / sizeof(cl_device_id));
	
	if( result != CL_SUCCESS || num_devices < 1 ) { printf("ERROR: clGetContextInfo() failed\n"); return -1; }
	device_list = new cl_device_id[num_devices];
	if( !device_list ) { printf("ERROR: new cl_device_id[] failed\n"); return -1; }
	result = clGetContextInfo( context, CL_CONTEXT_DEVICES, size, device_list, NULL );
	if( result != CL_SUCCESS ) { printf("ERROR: clGetContextInfo() failed\n"); return -1; }

	// create command queue for the first device
	cmd_queue = clCreateCommandQueue( context, device_list[0], 0, NULL );
	if( !cmd_queue ) { printf("ERROR: clCreateCommandQueue() failed\n"); return -1; }

	return 0;
}
开发者ID:zwang4,项目名称:dividend,代码行数:33,代码来源:kmeans.cpp


示例3: getDeviceIDs

bool getDeviceIDs()
{
    cl_int err = 0;
    size_t deviceBufferSize = -1;

    /* Retrieve the size of the buffer needed to contain information about the devices in this OpenCL context. */
    err = clGetContextInfo(ocl.context, CL_CONTEXT_DEVICES, 0, NULL, &deviceBufferSize);
    if (err != CL_SUCCESS)
    {
        printf("Failed to get OpenCL context information.\n");
        return false;
    }

    if(deviceBufferSize == 0)
    {
        printf("No OpenCL devices found.\n");
        return false;
    }

    /* Retrieve the list of devices available in this context. */
    DeviceCount = deviceBufferSize / sizeof(cl_device_id);;

    printf("Device Count %d\n", DeviceCount);

    ocl.device = new cl_device_id[DeviceCount];
    err = clGetContextInfo(ocl.context, CL_CONTEXT_DEVICES, deviceBufferSize, ocl.device, NULL);
    if (err != CL_SUCCESS)
    {
        printf("Failed to get the OpenCL context information.\n");
        delete [] ocl.device;
        return false;
    }

    return true;
}
开发者ID:DennisJung,项目名称:SCWS2016,代码行数:35,代码来源:refer.cpp


示例4: oclObject

oclContext::oclContext(cl_context iContext, cl_platform_id iPlatform, char* iVendor)
: oclObject("")
, mContext(iContext)
, mVendor(VENDOR_UNKNOWN)
, mPlatform(iPlatform)
{
    if (!strcmp(iVendor, VENDOR_NVIDIA))
    {
        mVendor = VENDOR_NVIDIA;
    }
    else if (!strcmp(iVendor, VENDOR_AMD))
    {
        mVendor = VENDOR_AMD;
    }
    else if (!strncmp(iVendor, VENDOR_INTEL, 5))
    {
        mVendor = VENDOR_INTEL;
    }

    setName(mVendor);

    size_t lDeviceCount;
    sStatusCL = clGetContextInfo(mContext, CL_CONTEXT_DEVICES, 0, NULL, &lDeviceCount);
    oclSuccess("clGetContextInfo", this);

    cl_device_id* lDevice = new cl_device_id[lDeviceCount];
    clGetContextInfo(mContext, CL_CONTEXT_DEVICES, lDeviceCount, lDevice, NULL);
    for (cl_uint i=0; i<lDeviceCount/sizeof(cl_device_id); i++)
    {
        mDevices.push_back(new oclDevice(*this, lDevice[i]));
    }
    delete [] lDevice;
};
开发者ID:jochenstier,项目名称:libcl,代码行数:33,代码来源:oclContext.cpp


示例5: createCommandQueue

int createCommandQueue(cl_context context, cl_command_queue* commandQueue, cl_device_id* device)
{
    cl_int errorNumber = 0;
    size_t deviceBufferSize = 8;
    size_t deviceNum = 0;
    /* Retrieve the size of the buffer needed to contain information about the devices in this OpenCL context. */
    clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &deviceBufferSize);

    /* Retrieve the list of devices available in this context. */
    cl_device_id devices[2];
    clGetContextInfo(context, CL_CONTEXT_DEVICES, deviceBufferSize, devices, &deviceNum);
    LOGD("deviceNum %d",deviceNum);
    /* Use the first available device in this context. */
    *device = devices[0];

    /* Set up the command queue with the selected device. */
    *commandQueue = clCreateCommandQueue(context, *device, CL_QUEUE_PROFILING_ENABLE, &errorNumber);

    LOGD("createCommandQueue code %d",errorNumber);
    char str[25];
    size_t str_size = 0;
    clGetDeviceInfo(*device,CL_DEVICE_NAME,25,str,&str_size);
    LOGD("device name %s",str);
    return 1;
}
开发者ID:ustcanycall,项目名称:Android_driver,代码行数:25,代码来源:hello-jni.c


示例6: ocl_create_context_and_comm_queue

void ocl_create_context_and_comm_queue(){
    // Create a context to run OpenCL on the OCL-enabled Device
    cl_int err;

#if BE_OCL_VERBOSE
    printf("--- Creating OpenCL context");
#endif

    device_context = clCreateContext(0, 1, &ocl_device, NULL, NULL, &err);

    ocl_error_check(OCL_CREATE_CONTEXT, err);

    // Get the list of OCL_ devices associated with this context
    size_t ParmDataBytes;
    clGetContextInfo(device_context, CL_CONTEXT_DEVICES, 0, NULL, &ParmDataBytes);
    cl_device_id* OCL_Devices = (cl_device_id*)malloc(ParmDataBytes);
    clGetContextInfo(device_context, CL_CONTEXT_DEVICES, ParmDataBytes, OCL_Devices, NULL);

    // Create a command-queue on the first OCL_ device
#if BE_OCL_VERBOSE
    printf("--- Creating OpenCL command queue");
#endif

    device_comm_queue = clCreateCommandQueue(device_context,
        OCL_Devices[0], 0, &err);

    ocl_error_check(OCL_CREATE_COMMAND_QUEUE, err);

    free(OCL_Devices);
}
开发者ID:adeas31,项目名称:OMCompiler,代码行数:30,代码来源:omc_ocl_util.cpp


示例7: initialize

static int initialize(int use_device)
{
	cl_int result;
	size_t size;

	// create OpenCL context
	cl_platform_id platform_id;
	if (clGetPlatformIDs(1, &platform_id, NULL) != CL_SUCCESS) { printf("ERROR: clGetPlatformIDs(1,*,0) failed\n"); return -1; }
	cl_context_properties ctxprop[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platform_id, 0};
	//device_type = use_device ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU;
        switch(use_device) {
            case 0: device_type = CL_DEVICE_TYPE_CPU; break;
            case 1: device_type = CL_DEVICE_TYPE_GPU; break;
            case 2: device_type = CL_DEVICE_TYPE_ACCELERATOR; break;
        }
	context = clCreateContextFromType( ctxprop, device_type, NULL, NULL, NULL );
	if( !context ) { printf("ERROR: clCreateContextFromType(%s) failed\n", use_device ? "GPU" : "CPU"); return -1; }

	// get the list of GPUs
	result = clGetContextInfo( context, CL_CONTEXT_DEVICES, 0, NULL, &size );
	num_devices = (int) (size / sizeof(cl_device_id));
	printf("num_devices = %d\n", num_devices);
	
	if( result != CL_SUCCESS || num_devices < 1 ) { printf("ERROR: clGetContextInfo() failed\n"); return -1; }
	device_list = new cl_device_id[num_devices];
	//device_list = (cl_device_id *)malloc(sizeof(cl_device_id)*num_devices);
	if( !device_list ) { printf("ERROR: new cl_device_id[] failed\n"); return -1; }
	result = clGetContextInfo( context, CL_CONTEXT_DEVICES, size, device_list, NULL );
	if( result != CL_SUCCESS ) { printf("ERROR: clGetContextInfo() failed\n"); return -1; }

	// create command queue for the first device
	cmd_queue = clCreateCommandQueue( context, device_list[0], 0, NULL );
	if( !cmd_queue ) { printf("ERROR: clCreateCommandQueue() failed\n"); return -1; }
	return 0;
}
开发者ID:shvo,项目名称:Rodinia-FPGA,代码行数:35,代码来源:backprop_ocl_fpga.cpp


示例8: get_cl_context

bool get_cl_context(cl_context *context, cl_device_id **devices, int num_platform)
{
    if (context == NULL || devices == NULL) return false;
    cl_platform_id *platforms = NULL;
    // The iteration variable
    int i;

    cl_uint num;
    check_err(clGetPlatformIDs(0, 0, &num), "Unable to get platforms");

    platforms = (cl_platform_id *)malloc(sizeof(cl_platform_id) * num);
    check_err(clGetPlatformIDs(num, platforms, NULL), "Unable to get platform ID");

    check_err(clGetPlatformIDs(0, 0, &num), "Unable to get platforms");

    printf("Found %d platforms:\n", num);
    for (i = 0; i < num; i++) {
        char str[1024];
        clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 1024, str, NULL);
        printf("\t%d: %s\n", i, str);
    }

    cl_context_properties prop[3];
    prop[0] = CL_CONTEXT_PLATFORM;
    prop[1] = (cl_context_properties)platforms[num_platform];
    prop[2] = 0;
    cl_int err;
    *context = clCreateContextFromType(prop, CL_DEVICE_TYPE_ALL, NULL, NULL, &err);
    if (err != CL_SUCCESS) {
        printf("Can't create OpenCL context\n");
        return false;
    }

    size_t size_b;
    int    num_total_devices;
    clGetContextInfo(*context, CL_CONTEXT_DEVICES, 0, NULL, &size_b);
    *devices = (cl_device_id *)malloc(size_b);
    clGetContextInfo(*context, CL_CONTEXT_DEVICES, size_b, *devices, 0);
    if (size_b == 0) {
        printf("Can't get devices\n");
        return false;
    }
    num_total_devices = size_b / sizeof(cl_device_id);

    printf("Found %d devices:\n", num_total_devices);
    for (i = 0; i < num_total_devices; i++) {
        char devname[16][256] = {};
        clGetDeviceInfo(*devices[i], CL_DEVICE_NAME, 256, devname[i], 0);
        printf("\t%d: %s", i, devname[i]);
        clGetDeviceInfo(*devices[i], // Set the device info
                        CL_DEVICE_MAX_COMPUTE_UNITS,
                        sizeof(int),
                        &size_b,
                        0);
        printf("  - %d\n", (int)size_b);
    }

    return true;
}
开发者ID:MedicineYeh,项目名称:vector_add_sample,代码行数:59,代码来源:main.c


示例9: getMaxFlopsDev

///
/// Gets the id of device with maximal FLOPS from the context (from NVIDIA SDK)
///
static cl_device_id getMaxFlopsDev(cl_context cxGPUContext)
{
    size_t szParmDataBytes;
    cl_device_id* cdDevices;

    // get the list of GPU devices associated with context
    clGetContextInfo(cxGPUContext, CL_CONTEXT_DEVICES, 0, NULL,
            &szParmDataBytes);
    cdDevices = (cl_device_id*) malloc(szParmDataBytes);
    size_t device_count = szParmDataBytes / sizeof(cl_device_id);

    clGetContextInfo(cxGPUContext, CL_CONTEXT_DEVICES, szParmDataBytes,
            cdDevices, NULL);

    cl_device_id max_flops_device = cdDevices[0];
    int max_flops = 0;

    size_t current_device = 0;

    // CL_DEVICE_MAX_COMPUTE_UNITS
    cl_uint compute_units;
    clGetDeviceInfo(cdDevices[current_device], CL_DEVICE_MAX_COMPUTE_UNITS,
            sizeof(compute_units), &compute_units, NULL);

    // CL_DEVICE_MAX_CLOCK_FREQUENCY
    cl_uint clock_frequency;
    clGetDeviceInfo(cdDevices[current_device], CL_DEVICE_MAX_CLOCK_FREQUENCY,
            sizeof(clock_frequency), &clock_frequency, NULL);

    max_flops = compute_units * clock_frequency;
    ++current_device;

    while (current_device < device_count)
    {
        // CL_DEVICE_MAX_COMPUTE_UNITS
        cl_uint compute_units;
        clGetDeviceInfo(cdDevices[current_device], CL_DEVICE_MAX_COMPUTE_UNITS,
                sizeof(compute_units), &compute_units, NULL);

        // CL_DEVICE_MAX_CLOCK_FREQUENCY
        cl_uint clock_frequency;
        clGetDeviceInfo(cdDevices[current_device],
                CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(clock_frequency),
                &clock_frequency, NULL);

        int flops = compute_units * clock_frequency;
        if (flops > max_flops)
        {
            max_flops = flops;
            max_flops_device = cdDevices[current_device];
        }
        ++current_device;
    }

    free(cdDevices);

    return max_flops_device;
}
开发者ID:AswinMohanASU,项目名称:opencl-book-samples,代码行数:61,代码来源:oclDijkstra.cpp


示例10: main

int main() {
  
   /* Host/device data structures */
   cl_platform_id platform;
   cl_device_id device;
   cl_context context;
   cl_int err;
   cl_uint ref_count;

   /* Access the first installed platform */
   err = clGetPlatformIDs(1, &platform, NULL);
   if(err < 0) {
      perror("Couldn't find any platforms");
      exit(1);
   }

   /* Access the first available device */
   err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL);
   if(err == CL_DEVICE_NOT_FOUND) {
      err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, 1, &device, NULL);
   }
   if(err < 0) {
      perror("Couldn't find any devices");
      exit(1);
   }

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

   /* Determine the reference count */
   err = clGetContextInfo(context, CL_CONTEXT_REFERENCE_COUNT, 	
         sizeof(ref_count), &ref_count, NULL);			
   if(err < 0) {		
      perror("Couldn't read the reference count.");
      exit(1);
   }
   printf("Initial reference count: %u\n", ref_count);

   /* Update and display the reference count */
   clRetainContext(context);						
   clGetContextInfo(context, CL_CONTEXT_REFERENCE_COUNT, 		
         sizeof(ref_count), &ref_count, NULL);			
   printf("Reference count: %u\n", ref_count);			
   
   clReleaseContext(context);						
   clGetContextInfo(context, CL_CONTEXT_REFERENCE_COUNT, 		
         sizeof(ref_count), &ref_count, NULL);			
   printf("Reference count: %u\n", ref_count);			

   clReleaseContext(context);						
   return 0;
}
开发者ID:dashmoment,项目名称:opencl_in_action,代码行数:56,代码来源:context_count.c


示例11: OCL_RETURN_ON_ERR

cl_int OCL_Platform::init(cl_platform_id id)
{
	cl_int err;
	mID = id;

	// store name
	size_t nameSize;
	OCL_RETURN_ON_ERR( clGetPlatformInfo( mID, CL_PLATFORM_NAME, 0, NULL, &nameSize ) );

	sPlatformName = new char[nameSize];
	OCL_RETURN_ON_ERR( clGetPlatformInfo( mID, CL_PLATFORM_NAME, nameSize, sPlatformName, NULL ) );

	// store extensions
	size_t extensionsSize;
	OCL_RETURN_ON_ERR( clGetPlatformInfo( mID, CL_PLATFORM_EXTENSIONS, 0, NULL, &extensionsSize ) );

	sPlatformExtensions = new char[extensionsSize];
	OCL_RETURN_ON_ERR( clGetPlatformInfo( mID, CL_PLATFORM_EXTENSIONS, extensionsSize, sPlatformExtensions, NULL ) );

	// default device type 
	cl_device_type deviceType = CL_DEVICE_TYPE_ALL;

	cl_context_properties ctxProps[] = 
	{
		CL_CONTEXT_PLATFORM, 
		(cl_context_properties)mID, 
		0 
	};

	OCL_RETURN_ON_ERR( ( mContext = clCreateContextFromType( ctxProps, deviceType, NULL, NULL, &err ), err));

	// Create array of devices
	size_t dev_ids_size;
	OCL_RETURN_ON_ERR( clGetContextInfo( mContext, CL_CONTEXT_DEVICES, 0, NULL, &dev_ids_size ) );

	uiNumDevices = (cl_uint)dev_ids_size/sizeof(cl_device_id);
	cl_device_id* pDeviceIDs = (cl_device_id*)calloc(1,dev_ids_size);

	mpDevices = new OCL_DeviceAndQueue[uiNumDevices];

	OCL_RETURN_ON_ERR( clGetContextInfo( mContext, CL_CONTEXT_DEVICES, dev_ids_size, pDeviceIDs, NULL ) );

	for( cl_uint j=0; j<uiNumDevices; j++ )
	{
		OCL_RETURN_ON_ERR( mpDevices[j].init( mContext, pDeviceIDs[j] ) );
		OCL_RETURN_ON_ERR( 
			(mpDevices[j].mContext = clCreateContextFromType( ctxProps, deviceType, NULL, NULL, &err )
			,err ));
	}

	delete pDeviceIDs;

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


示例12: snprintf

bool
OsdCLKernelBundle::Compile(cl_context clContext,
                           int numVertexElements, int numVaryingElements) {

    cl_int ciErrNum;

    _numVertexElements = numVertexElements;
    _numVaryingElements = numVaryingElements;

    char constantDefine[256];
    snprintf(constantDefine, sizeof(constantDefine),
             "#define NUM_VERTEX_ELEMENTS %d\n"
             "#define NUM_VARYING_ELEMENTS %d\n",
             numVertexElements, numVaryingElements);

    const char *sources[] = { constantDefine, clSource };

    _clProgram = clCreateProgramWithSource(clContext, 2, sources, 0, &ciErrNum);
    CL_CHECK_ERROR(ciErrNum, "clCreateProgramWithSource\n");

    ciErrNum = clBuildProgram(_clProgram, 0, NULL, NULL, NULL, NULL);
    if (ciErrNum != CL_SUCCESS) {
        OsdError(OSD_CL_PROGRAM_BUILD_ERROR, "CLerr=%d", ciErrNum);

        cl_int numDevices = 0;
        clGetContextInfo(clContext, CL_CONTEXT_NUM_DEVICES,
                         sizeof(cl_uint), &numDevices, NULL);
        cl_device_id *devices = new cl_device_id[numDevices];
        clGetContextInfo(clContext, CL_CONTEXT_DEVICES,
                         sizeof(cl_device_id)*numDevices, devices, NULL);
        for (int i = 0; i < numDevices; ++i) {
            char cBuildLog[10240];
            clGetProgramBuildInfo(_clProgram, devices[i], CL_PROGRAM_BUILD_LOG,
                                  sizeof(cBuildLog), cBuildLog, NULL);
            OsdError(OSD_CL_PROGRAM_BUILD_ERROR, cBuildLog);
        }
        delete[] devices;
        return false;
    }

    _clBilinearEdge   = buildKernel(_clProgram, "computeBilinearEdge");
    _clBilinearVertex = buildKernel(_clProgram, "computeBilinearVertex");
    _clCatmarkFace    = buildKernel(_clProgram, "computeFace");
    _clCatmarkEdge    = buildKernel(_clProgram, "computeEdge");
    _clCatmarkVertexA = buildKernel(_clProgram, "computeVertexA");
    _clCatmarkVertexB = buildKernel(_clProgram, "computeVertexB");
    _clLoopEdge       = buildKernel(_clProgram, "computeEdge");
    _clLoopVertexA    = buildKernel(_clProgram, "computeVertexA");
    _clLoopVertexB    = buildKernel(_clProgram, "computeLoopVertexB");
    _clVertexEditAdd  = buildKernel(_clProgram, "editVertexAdd");

    return true;
}
开发者ID:DonjuanChu,项目名称:OpenSubdiv,代码行数:53,代码来源:clKernelBundle.cpp


示例13: START_TEST

END_TEST

START_TEST (test_object_tree)
{
    cl_device_id device;
    cl_context ctx;
    cl_command_queue queue;
    cl_int result;
    cl_uint refcount;

    cl_platform_id platform      = 0;
    cl_uint        num_platforms = 0;
    clGetPlatformIDs(1, &platform, &num_platforms);

    result = clGetDeviceIDs(platform, CL_DEVICE_TYPE_DEFAULT, 1, &device, 0);
    fail_if(
        result != CL_SUCCESS,
        "unable to get the default device"
    );

    ctx = clCreateContext(0, 1, &device, 0, 0, &result);
    fail_if(
        result != CL_SUCCESS || ctx == 0,
        "unable to create a valid context"
    );

    queue = clCreateCommandQueue(ctx, device, 0, &result);
    fail_if(
        result != CL_SUCCESS || queue == 0,
        "cannot create a command queue"
    );

    result = clGetContextInfo(ctx, CL_CONTEXT_REFERENCE_COUNT, sizeof(cl_uint),
                              (void *)&refcount, 0);
    fail_if(
        result != CL_SUCCESS || refcount != 2,
        "the queue must increment the refcount of its context"
    );

    clReleaseCommandQueue(queue);

    result = clGetContextInfo(ctx, CL_CONTEXT_REFERENCE_COUNT, sizeof(cl_uint),
                              (void *)&refcount, 0);
    fail_if(
        result != CL_SUCCESS || refcount != 1,
        "the queue must decrement the refcount of its context when it's destroyed"
    );

    clReleaseContext(ctx);
}
开发者ID:yukke-fj,项目名称:shamrock,代码行数:50,代码来源:test_commandqueue.cpp


示例14: TEST_P

TEST_P(ocl_engine_test, BasicInteropC) {
    auto p = GetParam();
    cl_device_id ocl_dev = (p.adev_kind == dev_kind::gpu) ?
            gpu_ocl_dev :
            (p.adev_kind == dev_kind::cpu) ? cpu_ocl_dev : nullptr;

    cl_context ocl_ctx = (p.actx_kind == ctx_kind::gpu) ?
            gpu_ocl_ctx :
            (p.actx_kind == ctx_kind::cpu) ? cpu_ocl_ctx : nullptr;

    SKIP_IF(p.adev_kind != dev_kind::null && !ocl_dev,
            "Required OpenCL device not found.");
    SKIP_IF(p.actx_kind != ctx_kind::null && !ocl_ctx,
            "Required OpenCL context not found.");
    SKIP_IF(cpu_ocl_dev == gpu_ocl_dev
                    && (p.adev_kind == dev_kind::cpu
                               || p.actx_kind == ctx_kind::cpu),
            "OpenCL CPU-only device not found.");

    mkldnn_engine_t eng;
    mkldnn_status_t s
            = mkldnn_engine_create_ocl(&eng, mkldnn_gpu, ocl_dev, ocl_ctx);

    EXPECT_EQ(s, p.expected_status);

    if (s == mkldnn_success) {

        cl_device_id dev;
        cl_context ctx;

        MKLDNN_CHECK(mkldnn_engine_get_ocl_device(eng, &dev));
        MKLDNN_CHECK(mkldnn_engine_get_ocl_context(eng, &ctx));

        EXPECT_EQ(dev, ocl_dev);
        EXPECT_EQ(ctx, ocl_ctx);

        cl_uint ref_count;
        OCL_CHECK(clGetContextInfo(ocl_ctx, CL_CONTEXT_REFERENCE_COUNT,
                sizeof(ref_count), &ref_count, nullptr));
        int i_ref_count = int(ref_count);
        EXPECT_EQ(i_ref_count, 2);

        MKLDNN_CHECK(mkldnn_engine_destroy(eng));

        OCL_CHECK(clGetContextInfo(ocl_ctx, CL_CONTEXT_REFERENCE_COUNT,
                sizeof(ref_count), &ref_count, nullptr));
        i_ref_count = int(ref_count);
        EXPECT_EQ(i_ref_count, 1);
    }
}
开发者ID:zeno40,项目名称:convnet,代码行数:50,代码来源:test_engine.cpp


示例15: CreateCommandQueue

cl_command_queue CreateCommandQueue(cl_context context, cl_device_id *device)
{
    cl_int error_number;
    cl_device_id *devices;
    cl_command_queue command_queue = NULL;
    size_t device_buffer_size = -1;

    error_number = clGetContextInfo(context,
                                    CL_CONTEXT_DEVICES,
                                    0,
                                    NULL,
                                    &device_buffer_size);
    if (error_number != CL_SUCCESS)
    {
        std::cerr << "Failed call to clGetContextInfo(..., CL_CONTEXT_DEVICES,...)";
        return NULL;
    }

    if (device_buffer_size <= 0)
    {
        std::cerr << "No devices available.";
        return NULL;
    }

    devices = new cl_device_id[device_buffer_size / sizeof(cl_device_id)];
    error_number = clGetContextInfo(context,
                                    CL_CONTEXT_DEVICES,
                                    device_buffer_size,
                                    devices,
                                    NULL);
    if (error_number != CL_SUCCESS)
    {
        delete []devices;
        std::cerr << "Failed to get device IDs!";
        return NULL;
    }

    command_queue = clCreateCommandQueue(context, devices[0], 0, NULL);
    if (command_queue == NULL)
    {
        delete []devices;
        std::cerr << "Failed to create commandQueue for device 0.";
        return NULL;
    }

    *device = devices[0];
    delete []devices;
    return command_queue;
}
开发者ID:liubingjun,项目名称:mpiopencl,代码行数:49,代码来源:mpiOCL.cpp


示例16: ScriptValue

ScriptValue WebCLContext::getInfo(ScriptState* scriptState, int paramName, ExceptionState& es)
{
    v8::Handle<v8::Object> creationContext = scriptState->context()->Global();
    v8::Isolate* isolate = scriptState->isolate();

    if (isReleased()) {
        es.throwWebCLException(WebCLException::InvalidContext, WebCLException::invalidContextMessage);
        return ScriptValue(scriptState, v8::Null(isolate));
    }

    cl_int err = CL_SUCCESS;
    cl_uint uintUnits = 0;
    Vector<RefPtr<WebCLDevice>> result;
    switch (paramName) {
    case CL_CONTEXT_NUM_DEVICES:
        err = clGetContextInfo(m_clContext, CL_CONTEXT_NUM_DEVICES, sizeof(cl_uint), &uintUnits, nullptr);
        if (err == CL_SUCCESS)
            return ScriptValue(scriptState, v8::Integer::NewFromUnsigned(isolate, static_cast<unsigned>(uintUnits)));
        WebCLException::throwException(err, es);
        return ScriptValue(scriptState, v8::Null(isolate));
    case CL_CONTEXT_DEVICES:
        return ScriptValue(scriptState, toV8(m_devices, creationContext, isolate));
    default:
        es.throwWebCLException(WebCLException::InvalidValue, WebCLException::invalidValueMessage);
        return ScriptValue(scriptState, v8::Null(isolate));
    }
}
开发者ID:astojilj,项目名称:chromium-crosswalk,代码行数:27,代码来源:WebCLContext.cpp


示例17: btOclGetFirstDev

//////////////////////////////////////////////////////////////////////////////
//! Gets the id of the first device from the context
//!
//! @return the id 
//! @param cxMainContext         OpenCL context
//////////////////////////////////////////////////////////////////////////////
cl_device_id btOclGetFirstDev(cl_context cxMainContext)
{
    size_t szParmDataBytes;
    cl_device_id* cdDevices;

    // get the list of GPU devices associated with context
    clGetContextInfo(cxMainContext, CL_CONTEXT_DEVICES, 0, NULL, &szParmDataBytes);
    cdDevices = (cl_device_id*) malloc(szParmDataBytes);

    clGetContextInfo(cxMainContext, CL_CONTEXT_DEVICES, szParmDataBytes, cdDevices, NULL);

    cl_device_id first = cdDevices[0];
    free(cdDevices);

    return first;
}
开发者ID:KTaskn,项目名称:MMDAgent,代码行数:22,代码来源:btOclUtils.cpp


示例18: CreateCommandQueue

///
//  Create a command queue on the first device available on the
//  context
//
cl_command_queue CreateCommandQueue(cl_context context, cl_device_id *device)
{
    cl_int errNum;
    cl_device_id *devices;
    cl_command_queue commandQueue = NULL;
    size_t deviceBufferSize = -1;

    // First get the size of the devices buffer
    errNum = clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &deviceBufferSize);
    if (errNum != CL_SUCCESS)
    {
        std::cerr << "Failed call to clGetContextInfo(...,GL_CONTEXT_DEVICES,...)";
        return NULL;
    }

    if (deviceBufferSize <= 0)
    {
        std::cerr << "No devices available.";
        return NULL;
    }

    // Allocate memory for the devices buffer
    devices = new cl_device_id[deviceBufferSize / sizeof(cl_device_id)];
    errNum = clGetContextInfo(context, CL_CONTEXT_DEVICES, deviceBufferSize, devices, NULL);
    if (errNum != CL_SUCCESS)
    {
        delete [] devices;
        std::cerr << "Failed to get device IDs";
        return NULL;
    }

    // In this example, we just choose the first available device.  In a
    // real program, you would likely use all available devices or choose
    // the highest performance device based on OpenCL device queries
    commandQueue = clCreateCommandQueue(context, devices[0], 0, NULL);
    if (commandQueue == NULL)
    {
        delete [] devices;
        std::cerr << "Failed to create commandQueue for device 0";
        return NULL;
    }

    *device = devices[0];
    delete [] devices;
    return commandQueue;
}
开发者ID:mc-imperial,项目名称:gvki,代码行数:50,代码来源:CreateKernelsInProgram.cpp


示例19: init

void init() {
	cl_uint n;
	cl_platform_id *ids,id=NULL;
	int i,status;
	char s[MAXCHAR];
	/*  choose AMD platform if possible, otherwise just pick one */
	if(CL_SUCCESS!=clGetPlatformIDs(0,NULL,&n))
		error("error getting platforms 1");
	if(NULL==(ids=malloc(sizeof(cl_platform_id)*n))) error("out of memory");
	if(CL_SUCCESS!=clGetPlatformIDs(n,ids,NULL))
		error("error getting platforms 2");
	for(i=0;i<n;i++) {
		if(CL_SUCCESS!=clGetPlatformInfo(ids[i],CL_PLATFORM_VENDOR,MAXCHAR,s,NULL))
			error("error getting platform 3");
		if(!strcmp(s,"Advanced Micro Devices, Inc.")) {
			id=ids[i];
			break;
		}
	}
	if(i==n) id=ids[0];
	free(ids);
	/* get context stuff */
	cl_context_properties cps[3]={CL_CONTEXT_PLATFORM,(cl_context_properties)id,0};
	context=clCreateContextFromType(cps,CL_DEVICE_TYPE_CPU,NULL,NULL,&status);
	if(CL_SUCCESS!=status) error("couldn't create context");
	if(CL_SUCCESS!=clGetContextInfo(context,CL_CONTEXT_DEVICES,0,NULL,(size_t *)&n))
		error("error getting context info 1");
	if(!n) error("no devices!");
	if(NULL==(devices=malloc(n))) error("out of memory");
	if(CL_SUCCESS!=clGetContextInfo(context,CL_CONTEXT_DEVICES,n,devices,NULL))
		error("error getting context info 2");
	/* create opencl command queue */
	cmdq=clCreateCommandQueue(context,devices[0],0,&status);
	if(CL_SUCCESS!=status) error("error creating command queue");
	/* create memory buffers */
	initmem();
	/* copy contents of in to inbuffer */
	inbuffer=clCreateBuffer(context,CL_MEM_READ_WRITE|CL_MEM_USE_HOST_PTR,
		MAXP,in,&status);
	if(CL_SUCCESS!=status) {
		printf("max alloc %d\n",(int)CL_DEVICE_MAX_MEM_ALLOC_SIZE);
		printf("status %d\n",status);
		error("error creating input buffer");
	}
	loadkernel("sieve.cl");
}
开发者ID:manish05,项目名称:TCR,代码行数:46,代码来源:sieve.c


示例20: vmd_cl_context_num_devices

int vmd_cl_context_num_devices(cl_context clctx) {
  size_t parmsz;
  cl_int clerr = clGetContextInfo(clctx, CL_CONTEXT_DEVICES, 0, NULL, &parmsz);
  if (clerr != CL_SUCCESS)
    return 0;
  
  return (int) (parmsz / sizeof(size_t));
}
开发者ID:VictorMion,项目名称:vmd-cvs-github,代码行数:8,代码来源:OpenCLUtils.C



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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