Fehler CL_DEVICE_NOT_AVAILABLE beim Aufrufen von clCreateContext (Intel Core2Duo, Intel OCL SDK 3.0 Beta)

Ich versuche, mit OpenCL (Intel opencl-1.2-3.0.56860) zu beginnen. Ich habe es geschafft, das OpenCL SDK von Intel unter Ubuntu 12.05 zu installieren (unter Verwendung von "alien", um die rpm-Pakete in * .deb-Pakete zu konvertieren). Jetzt versuche ich, mein erstes einfaches OpenCL-Programm zum Laufen zu bringen ... Um das Programm auszuführen, muss LD_LIBRARY_PATH gesetzt werden:

export LD_LIBRARY_PATH=/opt/intel/opencl/lib64/

Mein Problem ist, dass ich beim Aufruf von clCreateContext (...) immer den Fehler "CL_DEVICE_NOT_AVAILABLE" erhalte.

Hier ist mein Quellcode:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <CL/cl.h>
#include <CL/cl_platform.h>
#include <string.h>

// Enable double precision values
#pragma OPENCL EXTENSION cl_khr_fp64 : enable

// OpenCL kernel. Each work item takes care of one element of c
const char *kernelSource =                                      "\n" \
"__kernel void vecAdd(  __global double *a,                       \n" \
"                       __global double *b,                       \n" \
"                       __global double *c,                       \n" \
"                       const unsigned int n)                    \n" \
"{                                                               \n" \
"    //Get our global thread ID                                  \n" \
"    int id = get_global_id(0);                                  \n" \
"                                                                \n" \
"    //Make sure we do not go out of bounds                      \n" \
"    if (id < n)                                                 \n" \
"        c[id] = a[id] + b[id];                                  \n" \
"}                                                               \n" \
                                                                "\n" ;

const char* err2str(cl_int err) {
  switch(err) {
  case CL_SUCCESS: return "CL_SUCCESS";
  case CL_INVALID_PROGRAM: return "CL_INVALID_PROGRAM";
  case CL_INVALID_VALUE: return "CL_INVALID_VALUE";
  case CL_INVALID_DEVICE: return "CL_INVALID_DEVICE";
  case CL_INVALID_BINARY: return "CL_INVALID_BINARY";
  case CL_INVALID_BUILD_OPTIONS: return "CL_INVALID_BUILD_OPTIONS";
  case CL_INVALID_OPERATION: return "CL_INVALID_OPERATION";
  case CL_DEVICE_NOT_AVAILABLE: return "CL_DEVICE_NOT_AVAILABLE";
  default: return "unknown";
  }
}

void pfn_notify(const char *errinfo, const void *private_info, size_t cb, void *user_data)
{
  fprintf(stderr, "OpenCL Error (via pfn_notify): %s\n", errinfo);
}

cl_platform_id GetIntelOCLPlatform()
{
    cl_platform_id pPlatforms[10] = { 0 };
    char pPlatformName[128] = { 0 };

    cl_uint uiPlatformsCount = 0;
    cl_int err = clGetPlatformIDs(10, pPlatforms, &uiPlatformsCount);
    for (cl_uint ui = 0; ui < uiPlatformsCount; ++ui)
    {
        err = clGetPlatformInfo(pPlatforms[ui], CL_PLATFORM_NAME, 128 * sizeof(char), pPlatformName, NULL);
        if ( err != CL_SUCCESS )
        {
            printf("ERROR: Failed to retreive platform vendor name.\n", ui);
            return NULL;
        }

        if (!strcmp(pPlatformName, "Intel(R) OpenCL"))
            return pPlatforms[ui];
    }

    return NULL;
}

int main( int argc, char* argv[] )
{
    cl_platform_id cpPlatform;        // OpenCL platform
    cl_device_id device_id;           // device ID
    cl_context context;               // context
    cl_command_queue queue;           // command queue
    cl_program program;               // program
    cl_kernel kernel;                 // kernel
    size_t cb;
    cl_device_id devices[100];
    cl_uint devices_n = 0;
    cl_int err;


    cl_platform_id intel_platform_id = GetIntelOCLPlatform();
    if( intel_platform_id == NULL ) {
      printf("ERROR: Failed to find Intel OpenCL platform.\n");
      return -1;
    }

    // Get Device Info...
    err = clGetDeviceIDs(intel_platform_id, CL_DEVICE_TYPE_ALL, 100, devices, &devices_n);
    printf("ERR(clGetDeviceIDs) = %d\n", err);
    printf("#DEVICES: %d\n", devices_n);


    for (int i=0; i<devices_n; i++) {
       char buffer[10240];
       cl_uint buf_uint;
       cl_ulong buf_ulong;
       printf("  -- %d --\n", i);
       err = clGetDeviceInfo(devices[i], CL_DEVICE_NAME, sizeof(buffer), buffer, NULL);
       printf("  DEVICE_NAME = %s\n", buffer);
       err = clGetDeviceInfo(devices[i], CL_DEVICE_VENDOR, sizeof(buffer), buffer, NULL);
       printf("  DEVICE_VENDOR = %s\n", buffer);
       err = clGetDeviceInfo(devices[i], CL_DEVICE_VERSION, sizeof(buffer), buffer, NULL);
       printf("  DEVICE_VERSION = %s\n", buffer);
       err = clGetDeviceInfo(devices[i], CL_DRIVER_VERSION, sizeof(buffer), buffer, NULL);
       printf("  DRIVER_VERSION = %s\n", buffer);
       err = clGetDeviceInfo(devices[i], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(buf_uint), &buf_uint, NULL);
       printf("  DEVICE_MAX_COMPUTE_UNITS = %u\n", (unsigned int)buf_uint);
       err = clGetDeviceInfo(devices[i], CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(buf_uint), &buf_uint, NULL);
       printf("  DEVICE_MAX_CLOCK_FREQUENCY = %u\n", (unsigned int)buf_uint);
       err = clGetDeviceInfo(devices[i], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(buf_ulong), &buf_ulong, NULL);
       printf("  DEVICE_GLOBAL_MEM_SIZE = %llu\n", (unsigned long long)buf_ulong);
    }

    context = clCreateContext(NULL, 1, devices, &pfn_notify, NULL, &err);
    printf("ERR(clCreateContext) = %d [%s]\n", err, err2str(err));


    // Create a context
    cl_context_properties context_properties[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties)intel_platform_id, (cl_context_properties)NULL };

//    context = clCreateContext(0, 1, &device_id, NULL, NULL, &err);
    context = clCreateContextFromType(context_properties, CL_DEVICE_TYPE_CPU, NULL, NULL, &err);
    printf("ERR(clCreateContextFromType) = %d [%s]\n", err, err2str(err));
    if (err != CL_SUCCESS) exit(0);

    if (context == (cl_context)0) {
      printf("Illegal context?");
      exit(0);
    }

    return 0;
}

Die Ausgabe ist:

ERR(clGetDeviceIDs) = 0
#DEVICES: 1
  -- 0 --
  DEVICE_NAME = Intel(R) Core(TM)2 Duo CPU     P7450  @ 2.13GHz
  DEVICE_VENDOR = Intel(R) Corporation
  DEVICE_VERSION = OpenCL 1.2 (Build 56860)
  DRIVER_VERSION = 1.2
  DEVICE_MAX_COMPUTE_UNITS = 2
  DEVICE_MAX_CLOCK_FREQUENCY = 2130
  DEVICE_GLOBAL_MEM_SIZE = 3152510976
ERR(clCreateContext) = -2 [CL_DEVICE_NOT_AVAILABLE]
ERR(clCreateContextFromType) = -2 [CL_DEVICE_NOT_AVAILABLE]

Irgendwelche Ideen, wie man das löst?

Grüße, Stefan

---- EDIT -----

Die CPU hat das Flag sse4_1 (auch: sse, sse2, sss3).

cat / proc / cpuinfo

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 23
model name      : Intel(R) Core(TM)2 Duo CPU     P7450  @ 2.13GHz
stepping        : 6
microcode       : 0x60c
cpu MHz         : 800.000
cache size      : 3072 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 10
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good nopl aperfmperf pni dtes64 monitor ds_cpl est tm2 ssse3 cx16 xtpr pdcm sse4_1 lahf_lm dtherm
bogomips        : 4255.56
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

[ same for the other core]

Antworten auf die Frage(1)

Ihre Antwort auf die Frage