Holidays

Hello,

I write this blog post from a wonderful chalet in the south of France, close to the Mont Blanc. The landscape is beautiful, the days hot and sunny, all is really good. For information, here is where my computer is, where I work on my GSoC project :

It’s not very comfortable, but I already managed to do interesting things on Clover. I committed yesterday a few changes :

  • The first and biggest is the implementation of clGetProgramInfo. This function allows the client application to retrieve a binary form of a program. Clover returns LLVM bitcode. This new functions also allows me to test the implementation of clCreateProgramWithBinary. It took a few hours to implement that because I had to install LLVM, and it’s tricky on openSUSE (you need to install llvm, llvm-devel, llvm-clang and llvm-clang-devel from devel:tools, and only this repository works. If you install another version, you get a broken llvm-config, or not all the needed libs).
  • Another one is just a cleanup : it removes all the trailing spaces Kate keeps in the files (spaces at the end of lines and lines made only of spaces). My Kate being broken, I now use Geany which I recommend to everyone (who can’t use Kate). Geany removes trailing spaces, and I decided to do that for every file in Clover.
  • Doing this put me in “cleanup mode”, so I decided to write my C++ code in … C++. I replaced all the C functions like memcpy by the C++ equivalents, that’s to say std::memcpy and friends. I also removed all the printf I put here and there to debug tricky problems, so the code is clean and silent.

During my holidays, I can work about 4 to 5 hours a day, I’m very happy, Clover will advance ! I have planned for today the implementation of clGetProgramBuildInfo and the OpenCL C compiler’s options. I could also begin some sort of standard library, but I have yet to decide if I will implement it in LLVM bitcode (compiled from a C file by Clang), good for interprocedural optimizations and very fast LLVM IR, or if I only code C headers and let the function calls unresolved in the LLVM IR. The last solution is the slowest (no inlining, no optimization), but the easiest to implement for hardware accelerated devices (just find all the unresolved calls and replace them with an intrinsic of the device). For a CPU device, the LLVM JIT has a wonderful function : InstallLazyFunctionCreator. This function lets me register a callback that is given a function name (like get_global_id) and returns a function pointer. I will use that to implement functions like get_global_id, barrier and fences.

I think I will do the two : code the headers, and let the device choose if it wants the binary be linked to a standard library IR, or not.

I’m very happy and very motivated : the interesting part of my project begins and it will be even more interesting than I expected. OpenCL is a good spec, but with small challenges that make work event more enjoyable.

Advertisements

4 responses to “Holidays

  • Alexey Shvtsov

    Hi!

    Seems your latest changes to clover doesnt builds.

    [ 95%] Building CXX object src/CMakeFiles/OpenCL.dir/core/compiler.cpp.o
    ../../clover-9999/src/api/api_enqueue.cpp: In function ‘cl_int clEnqueueWriteBuffer(cl_command_queue, cl_mem, cl_bool, size_t, size_t, const void*, cl_uint, _cl_event* const*, _cl_event**)’:
    ../../clover-9999/src/api/api_enqueue.cpp:75:29: warning: cast from type ‘const void*’ to type ‘void*’ casts away qualifiers [-Wcast-qual]
    ../../clover-9999/src/core/compiler.cpp: In member function ‘bool Coal::Compiler::setOptions(const string&)’:
    ../../clover-9999/src/core/compiler.cpp:50:15: error: ‘class clang::DiagnosticOptions’ has no member named ‘DiagnosticLogFile’
    make[2]: *** [src/CMakeFiles/OpenCL.dir/core/compiler.cpp.o] Error 1
    make[2]: *** Waiting for unfinished jobs….
    ../../clover-9999/src/core/program.cpp: In member function ‘cl_int Coal::Program::loadBinary(const unsigned char*, size_t, cl_int*, cl_uint, _cl_device_id* const*)’:
    ../../clover-9999/src/core/program.cpp:114:72: error: no matching function for call to ‘llvm::MemoryBuffer::getMemBuffer(const llvm::StringRef&, const llvm::StringRef&, bool)’
    ../../clover-9999/src/core/program.cpp:114:72: note: candidate is:
    /usr/include/llvm/Support/MemoryBuffer.h:79:24: note: static llvm::MemoryBuffer* llvm::MemoryBuffer::getMemBuffer(llvm::StringRef, llvm::StringRef)
    /usr/include/llvm/Support/MemoryBuffer.h:79:24: note: candidate expects 2 arguments, 3 provided
    make[2]: *** [src/CMakeFiles/OpenCL.dir/core/program.cpp.o] Error 1
    make[1]: *** [src/CMakeFiles/OpenCL.dir/all] Error 2

    • steckdenis

      Hum, I use LLVM and Clang head (not an up-to-date head, but more recent that the latest stable release). It seems that some functions and fields I use aren’t available in your version of LLVM.

      You can simply remove the line with DiagnosticLogFile (or git pull), it isn’t used. For the MemoryBuffer one, the third argument is a new one and I need it not to have Clover crashing. You can try to remove the “false” and change “length” to “length + 1” on lines 108 and 110. It should work for programs giving Clover a null-terminated string (the vast majority of programs), but it doesn’t match the spec.

      • Alexey Shvtsov

        Now there is another errror with llvm-2.9 and clang-2.9

        Building CXX object src/CMakeFiles/OpenCL.dir/core/events.cpp.o
        ../../clover-9999/src/api/api_enqueue.cpp: In function ‘cl_int clEnqueueWriteBuffer(cl_command_queue, cl_mem, cl_bool, size_t, size_t, const void*, cl_uint, _cl_event* const*, _cl_event**)’:
        ../../clover-9999/src/api/api_enqueue.cpp:75:29: warning: cast from type ‘const void*’ to type ‘void*’ casts away qualifiers [-Wcast-qual]
        ../../clover-9999/src/core/program.cpp: In member function ‘cl_int Coal::Program::loadBinary(const unsigned char*, size_t, cl_int*, cl_uint, _cl_device_id* const*)’:
        ../../clover-9999/src/core/program.cpp:118:72: error: no matching function for call to ‘llvm::MemoryBuffer::getMemBuffer(const llvm::StringRef&, const llvm::StringRef&, bool)’
        ../../clover-9999/src/core/program.cpp:118:72: note: candidate is:
        /usr/include/llvm/Support/MemoryBuffer.h:79:24: note: static llvm::MemoryBuffer* llvm::MemoryBuffer::getMemBuffer(llvm::StringRef, llvm::StringRef)
        /usr/include/llvm/Support/MemoryBuffer.h:79:24: note: candidate expects 2 arguments, 3 provided
        make[2]: *** [src/CMakeFiles/OpenCL.dir/core/program.cpp.o] Error 1

  • and

    Hi Dennis,

    to get rid of trailing white space you may also run

    find -name “*.[ch]” -exec sed -i ‘s/\s\+$//’ “{}” “;”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: