Code Monkey home page Code Monkey logo

clutils's Introduction

CLUtils

CLUtils offers utilities that help setup and manage an OpenCL environment. It aims to allow rapid prototyping by hiding away all the boilerplate code necessary for establishing an OpenCL environment.

This meant to be an exercise on how I would go about containing the OpenCL entities, and developing an API to interface them all. But since I didn't have a solid idea of what I needed, I started writing the code and ended up adapting the API around it. The result was an API that made use of indices to refer to OpenCL objects which only makes it efficient to use under a known environment. Nonetheless, the library works pretty robustly.

If you would like something more general and complete, take a look at boost.compute or AMD APP SDK's CLUtil.

Utilities offered by the library involve procedures like compiling source files, sharing OpenCL environment configurations, setting up OpenCL-OpenGL interoperability, profiling host and device code, and getting summarizing results on profiling data.

New on version 0.2:

  • Updated CLEnv API to support command queue profiling
  • Added support in CLEnv for OpenCL-OpenGL interoperability
  • Added CLEnvInfo to support conveyance of OpenCL env configurations
  • Added CPUTimer for profiling host code
  • Added GPUTimer for profiling device code
  • Added ProfilingInfo for manipulating profiling data

API

api

The simplest case handled by the library is one where a context is created for the first platform returned by the OpenCL API and a command queue is created for the first device in that platform. Programs are built for all devices in the associated context. This case is realized automatically when a kernel filename is provided on the definition of a CLEnv instance. Omitting the kernel filename in the CLEnv constructor allows to later specify exactly the OpenCL environment configuration to set up.

#include <CLUtils.hpp>

using namespace clutils;

int main ()
{
    CLEnv clEnv ("myKernels.cl");
    cl::Context &context (clEnv.getContext ());
    cl::CommandQueue &queue (clEnv.getQueue ());
    cl::Kernel &kernel (clEnv.getKernel ("myKernel"));
    cl::NDRange global (1024), local (256);

    cl::Buffer dBuf (context, CL_MEM_READ_WRITE, 1024 * sizeof (int));
    kernel.setArg (0, dBuf);

    queue.enqueueNDRangeKernel (kernel, cl::NullRange, global, local);

    return 0;
}

Having defined all the necessary OpenCL entities in CLEnv, an OpenCL configuration can now be specified with CLEnvInfo and communicated to a class that manages and executes some kind of algorithm.

#include <CLUtils.hpp>

using namespace clutils;

class PrefixSum;

int main ()
{
    CLEnv clEnv ("myKernels.cl");
    cl::Context &context (clEnv.getContext ());
    cl::CommandQueue &queue (clEnv.getQueue ());

    CLEnvInfo<1> info (0, 0, 0, { 0 }, 0);
    PrefixSum scan (clEnv, info);

    scan.run ();

    return 0;
}

The complete documentation is available here.

Build & Install

git clone https://github.com/nlamprian/CLUtils.git
cd CLUtils

mkdir build
cd build

cmake -DBUILD_EXAMPLES=ON ..
# or to build the tests too
cmake -DBUILD_EXAMPLES=ON -DBUILD_TESTS=ON ..

make

# to run the example (from the build directory!)
./bin/clutils_vecAdd

# to run the tests
./bin/clutils_tests

# to install the library
sudo make install

# to build the docs
make doxygen
firefox docs/html/index.html

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.