clBuildProgram always returns -11

Hi there,

I’ve been trying to get some simple OpenCL examples running for hours now. It always fails on clBuildProgram, as mentioned in the thread title. For example this one:

#include <iostream>

#include <cassert>

#include <cstring>

#include "CL/cl.h"

#include "textIO.h"

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

{

cl_int error = 0;   // Used to handle error codes

    cl_platform_id platforms;

    cl_uint num_platforms;

    cl_context context;

    cl_command_queue queue;

    cl_device_id device;

// Platform

    error = clGetPlatformIDs(1, &platforms, NULL);

    if (error != CL_SUCCESS) {

        std::cout << "Error getting platform id: " << error << std::endl;

        exit(error);

    } else {

        std::cout << "Platform found: " << platforms << std::endl;

    }

// Device

    cl_uint num_devices;

    error = clGetDeviceIDs(platforms, CL_DEVICE_TYPE_GPU, 1, &device, &num_devices);

    if (error != CL_SUCCESS) {

        std::cout << "Error getting device ids: " << error << std::endl;

       exit(error);

    } else {

        std::cout << "Using device ID " << device << std::endl;

        std::cout << "Devices found: " << num_devices << std::endl;

    }

// Context

    context = clCreateContext(0, 1, &device, NULL, NULL, &error);

    if (error != CL_SUCCESS) {

        std::cout << "Error creating context: " << error << std::endl;

       exit(error);

    }

// Command-queue

    queue = clCreateCommandQueue(context, device, 0, &error);

    if (error != CL_SUCCESS) {

        std::cout << "Error creating command queue: " << error << std::endl;

       exit(error);

    }

// Creates the program

//    const char* source = TextIO::read("addVecs.cl");

    const char* source = "__kernel void mul2(__global float * mem) { int i = get_global_id(0); mem[i] *= 2; }";

    cl_program program = clCreateProgramWithSource(context, 1, &source, NULL, &error);

    assert(error == CL_SUCCESS);

std::cout << "========== Program source" << std::endl << source << std::endl;

// Builds the program

    error = clBuildProgram(program, 1, &device, NULL, NULL, NULL);

//    error = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);

if (error != CL_SUCCESS) {

        std::cout << "Error building the program: " << error << std::endl;

        if (error == CL_INVALID_VALUE) {

            std::cout << "Invalid value" << std::endl;

        } else if (error == CL_INVALID_DEVICE) {

            std::cout << "Invalid device" << std::endl;

        } else if (error == CL_INVALID_BUILD_OPTIONS) {

            std::cout << "Invalid build options";

        }

//        char buffer[4096];

//        size_t length;

//        clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &length);

//        std::cout << "Program log: " << buffer;

    }

//    assert(error == CL_SUCCESS);

// Shows the log

    char* build_log;

    size_t log_size;

    // First call to know the proper size

    std::cout << "Length: " << strlen(source) << std::endl;

    clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);

    build_log = new char[log_size+1];

    // Second call to get the log

    clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, log_size, build_log, NULL);

    build_log[log_size] = '

#include

#include

#include

#include “CL/cl.h”

#include “textIO.h”

int main(int argc, char *argv)

{

cl_int error = 0; // Used to handle error codes

cl_platform_id platforms;

cl_uint num_platforms;

cl_context context;

cl_command_queue queue;

cl_device_id device;

// Platform

error = clGetPlatformIDs(1, &platforms, NULL);

if (error != CL_SUCCESS) {

    std::cout << "Error getting platform id: " << error << std::endl;

    exit(error);

} else {

    std::cout << "Platform found: " << platforms << std::endl;

}

// Device

cl_uint num_devices;

error = clGetDeviceIDs(platforms, CL_DEVICE_TYPE_GPU, 1, &device, &num_devices);

if (error != CL_SUCCESS) {

    std::cout << "Error getting device ids: " << error << std::endl;

   exit(error);

} else {

    std::cout << "Using device ID " << device << std::endl;

    std::cout << "Devices found: " << num_devices << std::endl;

}

// Context

context = clCreateContext(0, 1, &device, NULL, NULL, &error);

if (error != CL_SUCCESS) {

    std::cout << "Error creating context: " << error << std::endl;

   exit(error);

}

// Command-queue

queue = clCreateCommandQueue(context, device, 0, &error);

if (error != CL_SUCCESS) {

    std::cout << "Error creating command queue: " << error << std::endl;

   exit(error);

}

// Creates the program

// const char* source = TextIO::read(“addVecs.cl”);

const char* source = "__kernel void mul2(__global float * mem) { int i = get_global_id(0); mem[i] *= 2; }";

cl_program program = clCreateProgramWithSource(context, 1, &source, NULL, &error);

assert(error == CL_SUCCESS);

std::cout << “========== Program source” << std::endl << source << std::endl;

// Builds the program

error = clBuildProgram(program, 1, &device, NULL, NULL, NULL);

// error = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);

if (error != CL_SUCCESS) {

    std::cout << "Error building the program: " << error << std::endl;

    if (error == CL_INVALID_VALUE) {

        std::cout << "Invalid value" << std::endl;

    } else if (error == CL_INVALID_DEVICE) {

        std::cout << "Invalid device" << std::endl;

    } else if (error == CL_INVALID_BUILD_OPTIONS) {

        std::cout << "Invalid build options";

    }

// char buffer[4096];

// size_t length;

// clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &length);

// std::cout << "Program log: " << buffer;

}

// assert(error == CL_SUCCESS);

// Shows the log

char* build_log;

size_t log_size;

// First call to know the proper size

std::cout << "Length: " << strlen(source) << std::endl;

clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);

build_log = new char[log_size+1];

// Second call to get the log

clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, log_size, build_log, NULL);

build_log[log_size] = '\0';

std::cout << build_log << std::endl;

delete[] build_log;

// Extracting the kernel

cl_kernel vector_add_kernel = clCreateKernel(program, "addVectors", &error);

assert(error == CL_SUCCESS);

}

';

    std::cout << build_log << std::endl;

    delete[] build_log;

// Extracting the kernel

    cl_kernel vector_add_kernel = clCreateKernel(program, "addVectors", &error);

    assert(error == CL_SUCCESS);

}

(clGetProgramBuildInfo is deactivated since it just segfaults when calling.)

I took the example from here.

Can anyone tell me what is going on here? Or how to find out? I’ve got the same problems with the SDK examples:

I’m on Linux, 64-bit, with a 9800 GT.

thanks

Simon

I remember having such problems with “0-linebreak-programs” when I forgot to re-add the line breaks removed by the std::getline (asides the problems a preprocessor has with macros etc. then).

That was quite some time ago, perhaps even on the Apple platform, but you could just give it a try and we can look into the problem further if it does not work.

const char* source = "__kernel void mul2(__global float * mem) { \nint i = get_global_id(0); mem[i] *= 2; \n}\n";

Unfortunately this did not help. Still the -11 error.
Isn’t it strange that I even receive the -11 when running SDK example code?

Simon

I just run your codes on my machine and it works fine. No error is produced. So I guess there are problems of your development environment。
Mine is as follow: OpenSUSE 11.4, GTX 570, Driver 270.41.06, CUDA Toolkit 4.0 RC2, GCC 4.5.1, eclipse 3.6.2 for c/cpp.

oclDeviceQuery, Platform Name = NVIDIA CUDA, Platform Version = OpenCL 1.0 CUDA 4.0.1, SDK Revision = 7027912, NumDevs = 1, Device = GeForce 9800 GT
CL_DEVICE_NAME: GeForce 9800 GT
CL_DEVICE_VENDOR: NVIDIA Corporation
CL_DRIVER_VERSION: 270.30
CL_DEVICE_VERSION: OpenCL 1.0 CUDA
CL_DEVICE_TYPE: CL_DEVICE_TYPE_GPU

This is my machine. Toolkit: latest 3.x version.

Maybe you can try other version drivers like 260.xx or latest 270.xx.

Updated to:
CL_DRIVER_VERSION: 270.41.06

Exactly the same problem. Error -11. I re-compiled the SDK examples (make clean && make -j3), all failed with -11 as well.

Try older version 260.xx? If it is not driver problem, I can not tell any other advice. :confused:

Can’t I get more information from OpenCL than just the -11? Like some reason why it fails?

Or, why would clGetProgramBuildInfo segfault? I don’t understand this either.

Have you tried drivers 260.xx? The drivers 270.xx are major updates with support of CUDA 4.0 and many functions need fermi cards. Maybe there are bugs for the support of older card. Anyway just try. :smile:

Tried now, but it also failed. :-/

OK, I give up. Your codes run fine on my machine. So I have no idea about what happen. :wallbash:

What I can do now is to wish you good luck! :smile:

Is there really no looking «behind the scenes»? Like a debugger or so?
I’m using the 270.xx libraries, 270.xx header files, 270.xx drivers (again now), so this should not be the reason. The graphics card should not be either. GCC neither.

PS: And, thanks for your help.

I now managed to get OpenCL running.

By installing a fresh Ubuntu 10.10 on a broken external (former Laptop) 2.5" HD and compiling/running it there.

Not exactly the solution I was looking for.