GithubHelp home page GithubHelp logo

hughperkins / clew Goto Github PK

View Code? Open in Web Editor NEW

This project forked from martijnberger/clew

0.0 3.0 4.0 92 KB

The OpenCL Extension Wrangler Library

License: Other

CMake 1.87% C++ 0.40% C 97.73%

clew's Introduction

clew

The OpenCL Extension Wrangler Library

This basically works like glew, but for OpenCL

  • you can build opencl code without needing any opencl library or include files!
  • at runtime, even if there is no opencl-enabled device present, your code will still run! Of course, you wont be able to do anything opencl-related, but you wont get any errors about missing dlls and stuff, no linker errors (at least, not until you try to use a non-existent opencl-enabled device of course)

Code history

  • The code was originally part of a larger project, then was factorized out into a standalone github project

To use in your code

Include it

#include "clew.h"

Initialize it

bool clpresent = 0 == clewInit();
if( !clpresent ) {
    throw std::runtime_error("OpenCL library not found");
}

Use standard OpenCL method calls, as though you were linking directly with OpenCL:

context = new cl_context();
*context = clCreateContext(0, 1, &device, NULL, NULL, &error);
if (error != CL_SUCCESS) {
   throw std::runtime_error( "Error creating context: " + errorMessage(error) );
}
// Command-queue
queue = new cl_command_queue;
*queue = clCreateCommandQueue(*context, device, 0, &error);
if (error != CL_SUCCESS) {
   throw std::runtime_error( "Error creating command queue: " + errorMessage(error) );
}
// etc ...
  • link with libclew.so/.a/.dll/.lib (as appropriate, according to platform and build options)

To build

On linux

You'll need:

  • cmake
  • gcc, g++

Procedure:

mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=../dist
make -j 4 install

To test it works ok. You'll need at least one OpenCL-enabled device to do this bit:

LD_LIBRARY_PATH=../dist/lib ../dist/bin/clewTest

=> should see something like 'num platforms: 1'

On Windows

You'll need:

  • cmake
  • Visual Studio 2010 (actually, can probably use any version, but this was tested with this version)

Procedure:

  • first do the cmake part:
    • open cmake, set the source directory to the location of this source code
    • set the build directory to new subdirectory 'build'
    • click 'configure'
    • choose a generator, eg visual studio 2010
    • change the CMAKE_INSTALL_PREFIX to new sub-directory 'dist'
    • click 'configure' then 'generate'
  • now open visual studio, and open the solution from the build directory
  • change build type from 'Debug' to 'Release'
  • build the solution
  • build the project 'INSTALL'

To test it works ok. You'll need at least one OpenCL-enabled device to do this bit:

  • open a cmd
  • change into the 'dist' directory you created
  • type 'clewTest' => should see something like 'num platforms: 1'

Build options

  • BUILD_TESTS: build test executable, default ON
  • BUILD_SHARED_LIBRARY: build dll/so, instead of .lib/.a. default OFF
  • INSTALL_CL_HEADER: creates include files directory proxy-opencl, which you can give eg to clBLAS during build, and it will build ok, without needing opencl headers installed

clew's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.