Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: OpenCL initialisation problem on Ubuntu 12.04 (NVIDIA GS 7100 card)

Threaded View

  1. #1
    Member Regular Contributor
    Join Date
    Jan 2011
    Location
    Paris, France
    Posts
    250

    OpenCL initialisation problem on Ubuntu 12.04 (NVIDIA GS 7100 card)

    Hi, I have a problem with OpenCL on my Ubuntu 12.04 box and a NVIDIA 7100 GS card

    I use this very basic source :
    Code :
    #define CL_USE_DEPRECATED_OPENCL_1_1_APIS
    #include <CL/cl.h>
    #include <CL/cl.hpp>
     
     
    int main(int argc, char *argv[])
    {
        int err;
        cl_uint platforms;
        cl_platform_id platform = NULL;
        char cBuffer[1024];
     
     
        err = clGetPlatformIDs( 1, &platform, &platforms );
        if (err != CL_SUCCESS)
        {
            printf("Error in OpenCL call!\n");
            return EXIT_FAILURE;
        }
        printf("Number of platforms: %d\n", platforms);
     
     
        err = clGetPlatformInfo( platform, CL_PLATFORM_NAME, sizeof(cBuffer), cBuffer, NULL );
        if (err != CL_SUCCESS)
        {
            printf("Error in OpenCL call!\n");
            return EXIT_FAILURE;
        }
        printf("CL_PLATFORM_NAME :\t %s\n", cBuffer);
     
     
        err = clGetPlatformInfo( platform, CL_PLATFORM_VERSION,     sizeof(cBuffer), cBuffer, NULL );
        if (err != CL_SUCCESS)
        {
            printf("Error in OpenCL call!\n");
            return EXIT_FAILURE;
        }
        printf("CL_PLATFORM_VERSION :\t %s\n", cBuffer);
    }

    And compile it using this makefile :
    Code :
    all : test1
     
     
    test1 : test1.cpp
        g++ test1.cpp -L/etc/alternatives -lOpenCL -o test1
     
     
    clean : test1
        rm test1


    This compile "fine" (cf. only the CL_USE_DEPRECATED_OPENCL_1_1_APIS warning, but I have a lot of compilations errors without this ...)
    Code :
    yannoo@Ubuntoo:~/OPENCL/v2$ make
    g++ test1.cpp -L/etc/alternatives -lOpenCL -o test1
    In file included from /usr/include/CL/opencl.h:43:0,
                     from /usr/include/CL/cl.hpp:164,
                     from test1.cpp:6:
    /usr/include/CL/cl_gl.h:107:2: attention : #warning CL_USE_DEPRECATED_OPENCL_1_1_APIS is defined. These APIs are unsupported and untested in OpenCL 1.2! [-Wcpp]

    But when I run the executable, it's like it cannot find a valid OpenCL context
    Code :
    yannoo@Ubuntoo:~/OPENCL/v2$ ./test1
    Error in OpenCL call!

    => so the problem is here
    Code :
    err = clGetPlatformIDs( 1, &platform, &platforms );
     
    if (err != CL_SUCCESS)
    {
        printf("Error in OpenCL call!\n");
        return EXIT_FAILURE;
    }


    Note that I have the same type of error with another source lesson1.cpp :
    Code :
    #include <utility>
     
     
    #define __NO_STD_VECTOR // Use cl::vector instead of STL version
    #define CL_USE_DEPRECATED_OPENCL_1_1_APIS
    #include <CL/cl.h>
    #include <CL/cl.hpp>
     
     
    #include <cstdio>
    #include <cstdlib>
    #include <fstream>
    #include <iostream>
    #include <string>
    #include <iterator>
     
     
    const std::string hw("Hello World\n");
     
     
    inline void
    checkErr(cl_int err, const char * name)
    {
        if (err != CL_SUCCESS) {
            std::cerr << "ERROR : " << name
                     << " (" << err << ")" << std::endl;
            exit(EXIT_FAILURE);
        }
    }
     
     
    int
    main(void)
    {
        cl_int err;
        cl::vector< cl::Platform > platformList;
        cl::Platform::get(&platformList);
        checkErr(platformList.size()!=0 ? CL_SUCCESS : -1, "cl::Platform::get");
        std::cerr << "Platform number is: " << platformList.size() << std::endl;
     
        std::string platformVendor;
        platformList[0].getInfo((cl_platform_info)CL_PLATFORM_VENDOR, &platformVendor);
        std::cerr << "Platform is by: " << platformVendor << "\n";
        cl_context_properties cprops[3] = 
            {CL_CONTEXT_PLATFORM, (cl_context_properties)(platformList[0])(), 0};
     
        cl::Context context(
           CL_DEVICE_TYPE_CPU, 
           cprops,
           NULL,
           NULL,
           &err);
        checkErr(err, "Conext::Context()");   
     
     
     
     
     
     
     
     
     char * outH = new char[hw.length()+1];
        cl::Buffer outCL(
            context,
            CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR,
            hw.length()+1,
            outH,
            &err);
            checkErr(err, "Buffer::Buffer()");
     
     
     
     
     
     
     cl::vector<cl::Device> devices;
        devices = context.getInfo<CL_CONTEXT_DEVICES>();
        checkErr(
            devices.size() > 0 ? CL_SUCCESS : -1, "devices.size() > 0");
     
     
     
     
     
     
      std::ifstream file("lesson1_kernels.cl");
        checkErr(file.is_open() ? CL_SUCCESS:-1, "lesson1_kernel.cl");
     
        std::string prog(
            std::istreambuf_iterator<char>(file),
            (std::istreambuf_iterator<char>()));
     
        cl::Program::Sources source(
     
            1,
            std::make_pair(prog.c_str(), prog.length()+1));
     
        cl::Program program(context, source);
        err = program.build(devices,"");
        checkErr(file.is_open() ? CL_SUCCESS : -1, "Program::build()");
     
     
     
     
    cl::Kernel kernel(program, "hello", &err);
        checkErr(err, "Kernel::Kernel()");
     
        err = kernel.setArg(0, outCL);
        checkErr(err, "Kernel::setArg()");
     
     
     
     
    cl::CommandQueue queue(context, devices[0], 0, &err);
        checkErr(err, "CommandQueue::CommandQueue()");
     
     
     
        cl::Event event;
        err = queue.enqueueNDRangeKernel(
            kernel, 
            cl::NullRange,
            cl::NDRange(hw.length()+1),
             cl::NDRange(1, 1), 
            NULL, 
            &event);
        checkErr(err, "ComamndQueue::enqueueNDRangeKernel()");
     
     
     
     
     
     
      event.wait();    
        err = queue.enqueueReadBuffer(
            outCL,
            CL_TRUE,
            0,
            hw.length()+1,
            outH);
        checkErr(err, "ComamndQueue::enqueueReadBuffer()");
        std::cout << outH;
        return EXIT_SUCCESS;
    }

    lesson1_kernel.cl
    Code :
    #pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable
     
     
    __constant char hw[] = "Hello World\n";
     
     
    __kernel void hello(__global char * out)
    {
        size_t tid = get_global_id(0);
        out[tid] = hw[tid];
    }



    Using this makefile :
    Code :
    all : lesson1
     
     
    lesson1 : lesson1.cpp
        g++ lesson1.cpp -L/etc/alternatives -lOpenCL -o lesson1
     
     
    clean : lesson1
        rm lesson1





    That give at the execution :
    Code :
    yannoo@Ubuntoo:~/OPENCL$ make
    g++ lesson1.cpp -L/etc/alternatives -lOpenCL -o lesson1
    In file included from /usr/include/CL/opencl.h:43:0,
                     from /usr/include/CL/cl.hpp:164,
                     from lesson1.cpp:6:
    /usr/include/CL/cl_gl.h:107:2: attention : #warning CL_USE_DEPRECATED_OPENCL_1_1_APIS is defined. These APIs are unsupported and untested in OpenCL 1.2! [-Wcpp]
    yannoo@Ubuntoo:~/OPENCL$ ./lesson1
    *ERROR : cl::Platform::get (-1)

    And a third code test :
    Code :
    #include <stdio.h>
    #include <stdlib.h>
     
    #ifdef __APPLE__
    #include <OpenCL/opencl.h>
    #else
    #include <CL/cl.h>
    #endif
     
     
     
     
    int main(void) {
     
        // Get platform and device information
        cl_platform_id platform_id = NULL;
        cl_device_id device_id = NULL;   
        cl_uint ret_num_devices;
        cl_uint ret_num_platforms;
        cl_int ret;
     
     
        ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
        printf("plateform_id=%x, ret_num_plareform=%d, ret=%d \n", (int)platform_id, ret_num_platforms, ret); 
     
     
        ret = clGetDeviceIDs( platform_id, CL_DEVICE_TYPE_DEFAULT, 1, &device_id, &ret_num_devices);
       printf("platform_id=%x, device_id=%x , ret_num_devices=%x, ret=%d \n", (int)platform_id, (int)device_id, ret_num_devices, ret);
     
        return(0);
    }

    That give at execution :
    Code :
    plateform_id=0, ret_num_plareform=0, ret=-1001 
    platform_id=0, device_id=0 , ret_num_devices=1, ret=-32



    My graphic card is not compatible with OpenCL or it's another thing ?
    Code :
    yannoo@Ubuntoo:~/OPENCL$ lspci | grep VGA
    01:00.0 VGA compatible controller: NVIDIA Corporation NV44 [GeForce 7100 GS] (rev a1)
    Last edited by The Little Body; 12-06-2012 at 06:59 PM.
    @+
    Yannoo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •