Code Monkey home page Code Monkey logo

llvm-cbe's Introduction

LLVM-OpenCL

LLVM to OpenCL C Translator.

Installation instructions

This version of the LLVM-OpenCL library works with LLVM 9.0. You will have to compile this version of LLVM before you try to use LLVM-OpenCL. This guide will walk you through the compilation and installation of both tools and show usage statements to verify that the LLVM-OpenCL library is compiled correctly.

Building LLVM and Clang

LLVM-OpenCL relies on specific LLVM internals, and so it is best to use it with a specific revision of the LLVM development tree. Currently, LLVM-OpenCL works with the LLVM 9.0 release version and autotools.

Note: to convert OpenCL C to LLVM IR to run the tests, you will also need a OpenCL-to-LLVM compiler such as Clang. It is recommended to use Clang from the same LLVM repository revision in order to have compatible LLVM IR code.

The first step is to compile LLVM and Clang on your machine (this assumes an in-tree build, but out-of-tree will also work):

git clone https://github.com/llvm/llvm-project.git -b release/9.x
mkdir llvm/build
cd llvm/build
cmake .. -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_PROJECTS=clang
make

Building LLVM-OpenCL

Next, download and compile LLVM-OpenCL from the same folder:

cd llvm-project/llvm/projects
git clone https://github.com/agerasev/llvm-opencl
cd ../build
cmake ..
make llvm-opencl

Usage Examples

If LLVM-OpenCL compiles, you should be able to run example with the following commands.

# Add previously built LLVM-OpenCL and Clang to PATH
export PATH=$PWD/llvm-project/llvm/build/bin:$PATH

# Go to example program directory
cd llvm-opencl/test/examples/mandelbrot

# Generate LLVM IR code from OpenCL kernel source
clang-9 -S -emit-llvm \
  --target=spir-unknown-unknown \
  -x cl -std=cl1.2 \
  -Xclang -finclude-default-header \
  -O3 \
  kernel.cl -o kernel.ll

# Translate LLVM IR code back to OpenCL C
llvm-opencl kernel.ll -o kernel.gen.cl

# Run translated code with OpenCL
python3 run.py kernel.gen.cl
# The rendered image should appear in the current directory

Running tests

cd llvm-project/llvm/projects/llvm-opencl
python3 -m test

TODO

  • Images
  • Atomics and memory fences

Known issues

  • OpenCL 1.2 has no support for generic address space introduced in OpenCL 2.x. So generic address space pointers are treated as __private address space pointers, other address spaces should be explicitly specified.

llvm-cbe's People

Contributors

twalters25 avatar vtjnash avatar agerasev avatar sapir avatar jorickert avatar dipietroai avatar michaelstorm avatar gregorysimpson13 avatar rtc-draper avatar aguinet avatar dnmiller avatar dfrankland avatar jimmyw avatar spektom avatar certik avatar stephand avatar lyh-kernel-mcw avatar woachk avatar

Watchers

James Cloos 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.