本文整理汇总了C++中clCreateContextFromType函数的典型用法代码示例。如果您正苦于以下问题:C++ clCreateContextFromType函数的具体用法?C++ clCreateContextFromType怎么用?C++ clCreateContextFromType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了clCreateContextFromType函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: get_first_platform
cl_context get_first_platform(){
cl_uint num_platforms;
cl_platform_id platform;
cl_int err = clGetPlatformIDs(1, &platform, &num_platforms);
if (check_cl_err(err, "Failed to find a platform") || num_platforms < 1){
return NULL;
}
char name[64];
err = clGetPlatformInfo(platform, CL_PLATFORM_NAME, 64, name, NULL);
//This error probably shouldn't happen, but check anyway
check_cl_err(err, "Failed to get platform name");
printf("Selecting platform: %s\n", name);
//Try to get a GPU context on the platform
cl_context_properties properties[] = {
CL_CONTEXT_PLATFORM, (cl_context_properties)platform, 0
};
cl_context context = clCreateContextFromType(properties, CL_DEVICE_TYPE_GPU,
cl_err_callback, NULL, &err);
if (check_cl_err(err, "Failed to create GPU context, retrying CPU")){
context = clCreateContextFromType(properties, CL_DEVICE_TYPE_CPU,
NULL, NULL, &err);
if (check_cl_err(err, "Failed to create a GPU or CPU context")){
return NULL;
}
}
return context;
}
开发者ID:Twinklebear,项目名称:OpenCL-Practice,代码行数:28,代码来源:main.c
示例2: CreateContext
cl_context CreateContext() {
cl_int errNum;
cl_uint numPlatforms;
cl_platform_id firstPlatformId;
cl_context context = NULL;
//Select platform to run on
errNum = clGetPlatformIDs(1, &firstPlatformId, &numPlatforms);
if(errNum != CL_SUCCESS || numPlatforms <= 0) {
printf("Failed to find an OpenCL platform");
return NULL;
}
//Create context on platform (try GPU if fails then CPU)
cl_context_properties contextProperties[] = {
CL_CONTEXT_PLATFORM,
(cl_context_properties)firstPlatformId,
0
};
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU, NULL, NULL, &errNum);
if(errNum != CL_SUCCESS) {
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_CPU, NULL, NULL, &errNum);
if(errNum != CL_SUCCESS) {
printf("Failed to create an OpenCL context");
return NULL;
}
}
return context;
}
开发者ID:mirkokiefer,项目名称:opencl-test,代码行数:29,代码来源:cl_helpers.c
示例3: clGetPlatformIDs
cl_context QHoneycombWidget::CreateContext()
{
cl_int errNum;
cl_uint numPlatforms;
cl_platform_id firstPlatformId;
cl_context context = NULL;
// First, select an OpenCL platform to run on. For this example, we
// simply choose the first available platform. Normally, you would
// query for all available platforms and select the most appropriate one.
errNum = clGetPlatformIDs(1, &firstPlatformId, &numPlatforms);
if (errNum != CL_SUCCESS || numPlatforms <= 0)
{
std::cerr << "Failed to find any OpenCL platforms." << std::endl;
return NULL;
}
// Next, create an OpenCL context on the platform. Attempt to
// create a GPU-based context, and if that fails, try to create
// a CPU-based context.
cl_context_properties contextProperties[] =
{
#ifdef _WIN32
CL_CONTEXT_PLATFORM,
(cl_context_properties)firstPlatformId,
CL_GL_CONTEXT_KHR,
(cl_context_properties)wglGetCurrentContext(),
CL_WGL_HDC_KHR,
(cl_context_properties)wglGetCurrentDC(),
#elif defined( __GNUC__)
CL_CONTEXT_PLATFORM, (cl_context_properties)clSelectedPlatformID,
CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(),
#elif defined(__APPLE__)
//todo
#endif
0
};
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
NULL, NULL, &errNum);
if (errNum != CL_SUCCESS)
{
std::cout << "Could not create GPU context, trying CPU..." << std::endl;
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_CPU,
NULL, NULL, &errNum);
if (errNum != CL_SUCCESS)
{
std::cerr << "Failed to create an OpenCL GPU or CPU context." << std::endl;
return NULL;
}
}
return context;
}
开发者ID:MontanaN,项目名称:HoneycombOpenCL,代码行数:57,代码来源:QHoneycombWidget.cpp
示例4: CreateContext
cl_context CreateContext() {
cl_int errNum;
cl_uint numPlatforms;
cl_platform_id firstPlatformId;
cl_context context = NULL;
// First, select an OpenCL platform to run on. For this example, we
// simply choose the first available platform. Normally, you would
// query for all available platforms and select the most appropriate one.
errNum = clGetPlatformIDs(1, &firstPlatformId, &numPlatforms);
if (errNum != CL_SUCCESS || numPlatforms <= 0)
{
printf("Failed to find any OpenCL platforms.\n");
return NULL;
}
// Next, create an OpenCL context on the platform. Attempt to
// create a GPU-based context, and if that fails, try to create
// a CPU-based context.
cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)firstPlatformId, 0 };
if (CPUGPUFLAG == 1)
{
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU, NULL, NULL, &errNum);
if (errNum != CL_SUCCESS)
{
printf("Could not create GPU context.\n");
return NULL;
}
}
if (CPUGPUFLAG == 0)
{
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_CPU, NULL, NULL, &errNum);
if (errNum != CL_SUCCESS)
{
printf("Failed to create an OpenCL GPU or CPU context.\n");
return NULL;
}
}
return context;
}
开发者ID:stardica,项目名称:MatrixMultiply,代码行数:55,代码来源:MatrixMultiply.c
示例5: 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
示例6: createContext
bool createContext()
{
cl_int err = 0;
cl_uint numberOfPlatforms = 0;
cl_platform_id firstPlatformID = 0;
/* Retrieve a single platform ID. */
err = clGetPlatformIDs(1, &firstPlatformID, &numberOfPlatforms);
if(err != CL_SUCCESS)
{
printf("Error: Failed clGetPlatformIds\n");
return false;
}
if (numberOfPlatforms <= 0)
{
printf("No OpenCL platforms found.\n");
return false;
}
/* Get a context with a GPU device from the platform found above. */
cl_context_properties contextProperties [] = {CL_CONTEXT_PLATFORM, (cl_context_properties)firstPlatformID, 0};
ocl.context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU, NULL, NULL, &err);
if (err != CL_SUCCESS)
{
printf("Creating an OpenCL context failed.\n");
return false;
}
return true;
}
开发者ID:DennisJung,项目名称:SCWS2016,代码行数:32,代码来源:refer.cpp
示例7: getOclHardware
oclHardware getOclHardware(cl_device_type type)
{
oclHardware hardware = {0, 0, 0, 0, 0, 0};
cl_platform_id platforms[16] = { 0 };
cl_device_id devices[16];
char platformName[256];
char deviceName[256];
cl_uint platformCount = 0;
cl_int err = clGetPlatformIDs(0, 0, &platformCount);
err = clGetPlatformIDs(16, platforms, &platformCount);
if (err != CL_SUCCESS) {
std::cout << oclErrorCode(err) << "\n";
return hardware;
}
for (cl_uint i = 0; i < platformCount; i++) {
err = clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 256, platformName, 0);
if (err != CL_SUCCESS) {
std::cout << oclErrorCode(err) << "\n";
return hardware;
}
cl_uint deviceCount = 0;
err = clGetDeviceIDs(platforms[i], type, 16, devices, &deviceCount);
//err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_CPU, 16, devices, &deviceCount);
if ((err != CL_SUCCESS) || (deviceCount == 0)) {
continue;
}
err = clGetDeviceInfo(devices[0], CL_DEVICE_NAME, 256, deviceName, 0);
if (err != CL_SUCCESS) {
std::cout << oclErrorCode(err) << "\n";
return hardware;
}
cl_context_properties contextData[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[i], 0};
cl_context context = clCreateContextFromType(contextData, type, 0, 0, &err);
if (err != CL_SUCCESS) {
continue;
}
cl_command_queue queue = clCreateCommandQueue(context, devices[0], 0, &err);
if (err != CL_SUCCESS) {
std::cout << oclErrorCode(err) << "\n";
return hardware;
}
hardware.mPlatform = platforms[i];
hardware.mContext = context;
hardware.mDevice = devices[0];
hardware.mQueue = queue;
getDeviceVersion(hardware);
std::cout << "Platform = " << platformName << "\n";
std::cout << "Device = " << deviceName << "\n";
std::cout << "OpenCL Version = " << hardware.mMajorVersion << '.' << hardware.mMinorVersion << "\n";
return hardware;
}
return hardware;
}
开发者ID:L30nardoSV,项目名称:sda20153,代码行数:60,代码来源:oclHelper.cpp
示例8: 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
示例9: 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
示例10: context
context(cl_device_type t, cl_context_properties *props = 0)
{
cl_int status;
impl_ = clCreateContextFromType(props, t, context::callback, this, &status);
if (status < 0)
OVXX_DO_THROW(exception("clCreateContextFromType", status));
}
开发者ID:fsheikh,项目名称:openvsip,代码行数:7,代码来源:context.hpp
示例11: 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
示例12: clCreateContextFromType
cl_context OCLContexts::GetContextByPlatformName(
const std::string &platName, OCLContextProperties ctx_props) {
OCLErrorExp clerr;
cl_context found_ctx = m_contextMap[platName];
if ( found_ctx != NULL ) {
return found_ctx;
}
cl_platform_id platform = NULL;
for (size_t i=0; i<get_num_platforms(); i++) {
if (get_platform_name(i) == platName ) {
platform = m_platforms[i];
break;
}
}
ctx_props.AddProperty(CL_CONTEXT_PLATFORM, (cl_context_properties) platform);
found_ctx = clCreateContextFromType(ctx_props, CL_DEVICE_TYPE_ALL,
NULL, NULL, clerr);
clerr.CheckError();
if ( platform != NULL ) {
m_contextMap[platName] = found_ctx;
}
return found_ctx;
}
开发者ID:otaviog,项目名称:UdToolkit,代码行数:27,代码来源:oclcontexts.cpp
示例13: kernelObject
JNIContext::JNIContext(JNIEnv *jenv, jobject _kernelObject, jobject _openCLDeviceObject, jint _flags):
kernelObject(jenv->NewGlobalRef(_kernelObject)),
kernelClass((jclass)jenv->NewGlobalRef(jenv->GetObjectClass(_kernelObject))),
openCLDeviceObject(jenv->NewGlobalRef(_openCLDeviceObject)),
flags(_flags),
profileBaseTime(0),
passes(0),
exec(NULL),
deviceType(((flags&com_amd_aparapi_internal_jni_KernelRunnerJNI_JNI_FLAG_USE_GPU)==com_amd_aparapi_internal_jni_KernelRunnerJNI_JNI_FLAG_USE_GPU)?CL_DEVICE_TYPE_GPU:CL_DEVICE_TYPE_CPU),
profileFile(NULL),
valid(JNI_FALSE){
cl_int status = CL_SUCCESS;
jobject platformInstance = OpenCLDevice::getPlatformInstance(jenv, openCLDeviceObject);
cl_platform_id platformId = OpenCLPlatform::getPlatformId(jenv, platformInstance);
deviceId = OpenCLDevice::getDeviceId(jenv, openCLDeviceObject);
cl_device_type returnedDeviceType;
clGetDeviceInfo(deviceId, CL_DEVICE_TYPE, sizeof(returnedDeviceType), &returnedDeviceType, NULL);
//fprintf(stderr, "device[%d] CL_DEVICE_TYPE = %x\n", deviceId, returnedDeviceType);
cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platformId, 0 };
cl_context_properties* cprops = (NULL == platformId) ? NULL : cps;
context = clCreateContextFromType( cprops, returnedDeviceType, NULL, NULL, &status);
CLException::checkCLError(status, "clCreateContextFromType()");
if (status == CL_SUCCESS){
valid = JNI_TRUE;
}
}
开发者ID:RoshanGerard,项目名称:aparapi,代码行数:28,代码来源:JNIContext.cpp
示例14: get_platform
cl_context get_platform(cl_device_type type){
cl_uint num_platforms;
cl_int err = clGetPlatformIDs(0, NULL, &num_platforms);
cl_platform_id *platforms = malloc(sizeof(cl_platform_id) * num_platforms);
err = clGetPlatformIDs(num_platforms, platforms, NULL);
if (check_cl_err(err, "Failed to find platforms") || num_platforms < 1){
return NULL;
}
cl_context_properties properties[] = {
CL_CONTEXT_PLATFORM, 0, 0
};
cl_context context = NULL;
for (size_t i = 0; i < num_platforms; ++i){
properties[1] = (cl_context_properties)platforms[i];
context = clCreateContextFromType(properties, type, cl_err_callback, NULL, &err);
if (err == CL_SUCCESS){
char name[64];
clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 64, name, NULL);
printf("Selected platform: %s\n", name);
break;
}
}
free(platforms);
return context;
}
开发者ID:Twinklebear,项目名称:OpenCL-Practice,代码行数:25,代码来源:main.c
示例15: 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
示例16: create_opencl_context
static cl_int create_opencl_context(cl_context *context, cl_platform_id *platform)
{
cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)*platform, 0 };
cl_int status;
*context = clCreateContextFromType(cps, CL_DEVICE_TYPE_GPU, NULL, NULL, &status);
return status;
}
开发者ID:Elbandi,项目名称:sgminer,代码行数:8,代码来源:ocl.c
示例17: mContext
ClHelper::ClHelper()
: mContext((cl_context)0), mDeviceId((cl_device_id)0),
mCommandQueue((cl_command_queue)0), mProgram((cl_program)0),
mKernel((cl_kernel)0)
{
cl_int status;
// 플랫폼
cl_platform_id platforms[10];
cl_uint num_platforms;
status = clGetPlatformIDs(sizeof(platforms) / sizeof(platforms[0]),
platforms,
&num_platforms);
if (status != CL_SUCCESS || num_platforms <= 0) {
fprintf(stderr, "clGetPlatformIDs failed.\n");
printError(status);
throw MyError("failed to get platform IDs.", __FUNCTION__);
}
cl_context_properties properties[]
= {CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[0], 0};
// 디바이스에 따른 컨텍스트 취득
mContext = clCreateContextFromType(properties,
// CL_DEVICE_TYPE_CPU, // CPUを使用
CL_DEVICE_TYPE_GPU, // GPUを使用
NULL,
NULL,
&status);
if (status != CL_SUCCESS) {
printError(status);
throw MyError("failed to create context.", __FUNCTION__);
}
// 디바이스 아이디 취득
cl_device_id devices[10];
status = clGetContextInfo(mContext,
CL_CONTEXT_DEVICES,
sizeof(devices),
devices,
NULL);
if (status != CL_SUCCESS) {
printError(status);
throw MyError("failed to get device id.", __FUNCTION__);
}
mDeviceId = devices[0];
// 커맨드 큐 생성
mCommandQueue = clCreateCommandQueue(mContext,
devices[0],
0,
&status);
if (status != CL_SUCCESS) {
printError(status);
throw MyError("failed to create command queue.", __FUNCTION__);
}
}
开发者ID:datakun,项目名称:SourceCodeReading,代码行数:57,代码来源:ClHelper.cpp
示例18: createContextFromType
SEXP createContextFromType(SEXP deviceType){
//We need to look at this, because this does not seem to work...
std::string deviceString = Rcpp::as<std::string>(deviceType);
cl_context *context = new cl_context;
if(deviceString == "CL_DEVICE_TYPE_GPU"){
*context = clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU, NULL, NULL, NULL);
}
Rcpp::XPtr<cl_context> tempXPtr(context);
return tempXPtr;
}
开发者ID:RyanHope,项目名称:ROpenCL,代码行数:10,代码来源:createContext.cpp
示例19: CreateContext
///
// functions for preparing create opencl program, contains CreateContext, CreateProgram, CreateCommandQueue, CreateMemBuffer, and Cleanup
// Create an OpenCL context on the first available GPU platform.
cl_context CreateContext()
{
cl_context context = NULL;
cl_uint platformIdCount = 0;
cl_int errNum;
#ifndef POCL_HSA
// get number of platforms
clGetPlatformIDs (0, NULL, &platformIdCount);
std::vector<cl_platform_id> platformIds(platformIdCount);
clGetPlatformIDs (platformIdCount, platformIds.data(), NULL);
// In this example, first platform is a CPU, the second one is a GPU. we just choose the first available device.
cl_context_properties contextProperties[] =
{
CL_CONTEXT_PLATFORM,
(cl_context_properties)platformIds[1],
0
};
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
NULL, NULL, &errNum);
if (errNum != CL_SUCCESS)
{
std::cout << "Could not create GPU context, trying CPU..." << std::endl;
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_CPU,
NULL, NULL, &errNum);
if (errNum != CL_SUCCESS)
{
std::cerr << "Failed to create an OpenCL GPU or CPU context." << std::endl;
return NULL;
}
}
#else
context = poclu_create_any_context();
#endif
return context;
}
开发者ID:zwang4,项目名称:dividend,代码行数:43,代码来源:main.cpp
示例20: CreateContext
cl_context CreateContext()
{
cl_int error_number;
cl_uint number_platforms;
cl_platform_id first_platform_id;
cl_context context = NULL;
error_number = clGetPlatformIDs(1, &first_platform_id, &number_platforms);
if (error_number != CL_SUCCESS || number_platforms <= 0)
{
std::cerr << "Failed to find any OpenCL platforms." << std::endl;
return NULL;
}
cl_context_properties context_properties[] = {
CL_CONTEXT_PLATFORM,
(cl_context_properties)first_platform_id,
0
};
context = clCreateContextFromType(context_properties,
CL_DEVICE_TYPE_GPU,
NULL,
NULL,
&error_number);
if (error_number != CL_SUCCESS)
{
std::cout << "Could not create GPU context, trying CPU..." << std::endl;
context = clCreateContextFromType(context_properties,
CL_DEVICE_TYPE_CPU,
NULL,
NULL,
&error_number);
if (error_number != CL_SUCCESS)
{
std::cerr << "Failed to create an OpenCL GPU or CPU context." << std::endl;
return NULL;
}
}
return context;
}
开发者ID:liubingjun,项目名称:mpiopencl,代码行数:40,代码来源:mpiOCL.cpp
注:本文中的clCreateContextFromType函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论