Giter Club home page Giter Club logo

eazy-opencl's Introduction

eazy-opencl - Opencl Binding for Common Lisp

Development status:

  • basic CFFI binding, grovelling
  • proper error handling
  • integration to lisp GC
  • Minimally Viable API
  • extensive testing (https://travis-ci.org/guicho271828/eazy-opencl.svg, https://circleci.com/gh/guicho271828/eazy-opencl.svg)

TODOs:

  • lisp-to-C preprocessor -> work in progress at https://github.com/gos-k/oclcl
  • Loading external OpenCL library easily (like in quicklisp)
  • Really good way to handle complicated memory operation (e.g., generating operations automatically)

Perhaps, I should stop here, and leave these features to external libraries?

Installation

You have to install OpenCL ICD Loader and some OpenCL platform icd. On Debian/Ubuntu,

ICD loader: sudo apt-get install ocl-icd-opencl-dev

A Platform ICD provides an OpenCL implementation. Some are available from apt-get:

  • AMD (proprietary) : sudo apt-get install amd-opencl-icd
  • Nvidia (proprietary) : sudo apt-get install nvidia-opencl-icd
  • Intel (proprietary) : sudo apt-get install beignet-opencl-icd
  • Mesa (free) : sudo apt-get install mesa-opencl-icd
  • POCL (portable opencl) : sudo apt-get install pocl-opencl-icd — Tested on latest source (>=0.12) from Git. Older versions have several unimplemented features/arguments and does not pass all the test, but mostly working as long as you don’t use them.

However, note that these packages (both ICD loader and OpenCL implementation) are not up-to-date. My recommendation is to download the latest driver&icd from vendors’ websites.

As of 2015/11/04, it also requires the latest cffi installed from the git repositry.

cd $quicklisp_local_project ; git clone https://github.com/cffi/cffi.git

Once they are up, just load this library in the quicklisp local-project directory. Run the tests by:

(asdf:test-system :eazy-opencl)

Devices

OpenCL supports wide variety of hardware including CPU. The official, comprehensive device list is available here.

  • CPU with SSE2.X instruction (AMD APPSDK), SSE4.2 instruction (Intel driver)
  • Intel Xeon Phi (Intel driver)
  • ARM mobile CPUs (qualcomm snapdragon etc.)
  • CPU with embedded GPU (latest Intel, or AMD A-series)
  • FPGA, ASIC, DSP
  • GPGPU (Radeon, GeForce)

Note that AMD APPSDK can be installed on any CPUs supporting SSE2 (even on Intel).

Supported OpenCL Versions

This library supports opencl-1.0, 1.1, 1.2 and 2.0. They are automatically switched by grovelling the OpenCL header in the path.

This library is developped on machine with AMD APPSDK v3.0 (OpenCL 2.0), Radeon HD 5770 and PhenomII X6. Tests on CI runs with POCL 0.12 (OpenCL 1.2).

OpenCL has a specification independent from implementations, much like in ANSI Common Lisp. It maintains the backward-compatibility (any programs written with earlier versions of OpenCL should work.)

Bug/Trouble Reports should go to github issues page.

In this library, I do not support ANY OpenGL / Direct3D- related apis since I mostly target scientific use. I welcome any pullrequests as long as it comes with a minimal test.

Author

Masataro Asai ([email protected])

C source generator will be forked from Takagi@CL-CUDA if ever implemented.

CFFI-binding is forked from cl-opencl-3b, but largely extended to support OpenCL 2.0.

Motivation

Both cl-opencl and cl-opencl-3b look abandoned, so I’m trying to supersede it. In fact, no one seems using it, nor it is on Quicklisp.

Implementing Deep NN in lisp is one ambitious goal. However it is not really necessary, since external DL-NN OpenCL libraries are available. See https://github.com/hughperkins/DeepCL.

License

I’ll plan to license it under the LLGPL, but since this is a fork from cl-opencl-3b which lacks the license, I’m asking 3b to specify one.

eazy-opencl's People

Contributors

gos-k avatar guicho271828 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eazy-opencl's Issues

Failure loading package on Arch Linux

Trying to load the package on Arch Linux:

EAZY-OPENCL.GROVEL::--DEVICE-TYPE fell through ECASE expression.
Wanted one of (:CHAR :UNSIGNED-CHAR :UCHAR :SHORT
               :UNSIGNED-SHORT :USHORT :INT :UNSIGNED-INT :UINT
               :LONG :UNSIGNED-LONG :ULONG :LONG-LONG :LLONG
               :UNSIGNED-LONG-LONG :ULLONG :INT8 :UINT8 :INT16
               :UINT16 :INT32 :UINT32 :INT64 :UINT64).
   [Condition of type SB-KERNEL:CASE-FAILURE]

Versions:

$ pacman -Q opencl-headers opencl-nvidia
opencl-headers 2:2.0.20150827-1
opencl-nvidia 355.11-1

Stacktrace:

  0: (SB-KERNEL:CASE-FAILURE ECASE EAZY-OPENCL.GROVEL::--DEVICE-TYPE (:CHAR :UNSIGNED-CHAR :UCHAR :SHORT :UNSIGNED-SHORT :USHORT ...))
  1: (CFFI-GROVEL::FOREIGN-TYPE-TO-PRINTF-SPECIFICATION EAZY-OPENCL.GROVEL::--DEVICE-TYPE)
  2: ((:METHOD CFFI-GROVEL::%PROCESS-GROVEL-FORM ((EQL (QUOTE CFFI-GROVEL::BITFIELD)) T T)) #<unavailable argument> #<SB-SYS:FD-STREAM for "file /home/emartenson/.cache/common-lisp/sbcl-1.3.0.26-975b2e6-li..
  3: (CFFI-GROVEL::GENERATE-C-FILE #P"/home/emartenson/src/eazy-opencl/0.bindings-src/2-4-grovel-cl-enum.lisp" #P"/home/emartenson/.cache/common-lisp/sbcl-1.3.0.26-975b2e6-linux-x64/home/emartenson/src/eaz..
  4: ((LAMBDA NIL :IN CFFI-GROVEL:PROCESS-GROVEL-FILE))
  5: (SB-IMPL::%WITH-STANDARD-IO-SYNTAX #<CLOSURE (LAMBDA NIL :IN CFFI-GROVEL:PROCESS-GROVEL-FILE) {1005D4683B}>)
  6: ((:METHOD ASDF/ACTION:PERFORM (CFFI-GROVEL::PROCESS-OP CFFI-GROVEL:GROVEL-FILE)) #<CFFI-GROVEL::PROCESS-OP > #<CFFI-GROVEL:GROVEL-FILE "eazy-opencl.bindings" "0.bindings-src" "2-4-grovel-cl-enum">) [f..
  7: ((SB-PCL::EMF ASDF/ACTION:PERFORM) #<unavailable argument> #<unavailable argument> #<CFFI-GROVEL::PROCESS-OP > #<CFFI-GROVEL:GROVEL-FILE "eazy-opencl.bindings" "0.bindings-src" "2-4-grovel-cl-enum">)
  8: ((:METHOD ASDF/ACTION:PERFORM-WITH-RESTARTS :AROUND (T T)) #<CFFI-GROVEL::PROCESS-OP > #<CFFI-GROVEL:GROVEL-FILE "eazy-opencl.bindings" "0.bindings-src" "2-4-grovel-cl-enum">) [fast-method]
  9: ((:METHOD ASDF/PLAN:PERFORM-PLAN (LIST)) ((#1=#<ASDF/LISP-ACTION:COMPILE-OP > . #<ASDF/SYSTEM:SYSTEM "alexandria">) (#1# . #<ASDF/PACKAGE-INFERRED-SYSTEM:PACKAGE-SYSTEM "uiop">) (#1# . #<ASDF/COMPONEN..
 10: ((FLET SB-C::WITH-IT :IN SB-C::%WITH-COMPILATION-UNIT))
 11: ((:METHOD ASDF/PLAN:PERFORM-PLAN :AROUND (T)) ((#1=#<ASDF/LISP-ACTION:COMPILE-OP > . #<ASDF/SYSTEM:SYSTEM "alexandria">) (#1# . #<ASDF/PACKAGE-INFERRED-SYSTEM:PACKAGE-SYSTEM "uiop">) (#1# . #<ASDF/COM..
 12: ((FLET SB-C::WITH-IT :IN SB-C::%WITH-COMPILATION-UNIT))
 13: ((:METHOD ASDF/PLAN:PERFORM-PLAN :AROUND (T)) #<ASDF/PLAN:SEQUENTIAL-PLAN {1004E3EAC3}> :VERBOSE NIL) [fast-method]
 14: ((:METHOD ASDF/OPERATE:OPERATE (ASDF/OPERATION:OPERATION ASDF/COMPONENT:COMPONENT)) #<ASDF/LISP-ACTION:LOAD-OP :VERBOSE NIL> #<ASDF/SYSTEM:SYSTEM "eazy-opencl"> :VERBOSE NIL) [fast-method]
 15: ((SB-PCL::EMF ASDF/OPERATE:OPERATE) #<unused argument> #<unused argument> #<ASDF/LISP-ACTION:LOAD-OP :VERBOSE NIL> #<ASDF/SYSTEM:SYSTEM "eazy-opencl"> :VERBOSE NIL)
 16: ((LAMBDA NIL :IN ASDF/OPERATE:OPERATE))
 17: ((:METHOD ASDF/OPERATE:OPERATE :AROUND (T T)) #<ASDF/LISP-ACTION:LOAD-OP :VERBOSE NIL> #<ASDF/SYSTEM:SYSTEM "eazy-opencl"> :VERBOSE NIL) [fast-method]
 18: ((SB-PCL::EMF ASDF/OPERATE:OPERATE) #<unused argument> #<unused argument> ASDF/LISP-ACTION:LOAD-OP "eazy-opencl" :VERBOSE NIL)
 19: ((LAMBDA NIL :IN ASDF/OPERATE:OPERATE))
 20: (ASDF/CACHE:CALL-WITH-ASDF-CACHE #<CLOSURE (LAMBDA NIL :IN ASDF/OPERATE:OPERATE) {1004E39B3B}> :OVERRIDE NIL :KEY NIL)
 21: ((:METHOD ASDF/OPERATE:OPERATE :AROUND (T T)) ASDF/LISP-ACTION:LOAD-OP "eazy-opencl" :VERBOSE NIL) [fast-method]
 22: ((:METHOD ASDF/OPERATE:OPERATE :AROUND (T T)) ASDF/LISP-ACTION:LOAD-OP "eazy-opencl" :VERBOSE NIL) [fast-method]
 23: (QUICKLISP-CLIENT::CALL-WITH-MACROEXPAND-PROGRESS #<CLOSURE (LAMBDA NIL :IN QUICKLISP-CLIENT::APPLY-LOAD-STRATEGY) {1004E0E49B}>)
 24: (QUICKLISP-CLIENT::AUTOLOAD-SYSTEM-AND-DEPENDENCIES "eazy-opencl" :PROMPT NIL)
 25: ((:METHOD QL-IMPL-UTIL::%CALL-WITH-QUIET-COMPILATION (T T)) #<unavailable argument> #<CLOSURE (FLET QUICKLISP-CLIENT::QL :IN QUICKLISP-CLIENT:QUICKLOAD) {1004E02A1B}>) [fast-method]
 26: ((:METHOD QL-IMPL-UTIL::%CALL-WITH-QUIET-COMPILATION :AROUND (QL-IMPL:SBCL T)) #<QL-IMPL:SBCL {100785F723}> #<CLOSURE (FLET QUICKLISP-CLIENT::QL :IN QUICKLISP-CLIENT:QUICKLOAD) {1004E02A1B}>) [fast-me..
 27: ((:METHOD QUICKLISP-CLIENT:QUICKLOAD (T)) #<unavailable argument> :PROMPT NIL :SILENT NIL :VERBOSE NIL) [fast-method]
 28: (QL-DIST::CALL-WITH-CONSISTENT-DISTS #<CLOSURE (LAMBDA NIL :IN QUICKLISP-CLIENT:QUICKLOAD) {1004DDFCDB}>)
 29: (SB-INT:SIMPLE-EVAL-IN-LEXENV (QUICKLISP-CLIENT:QUICKLOAD "eazy-opencl") #<NULL-LEXENV>)
 30: (EVAL (QUICKLISP-CLIENT:QUICKLOAD "eazy-opencl"))
 31: (SWANK::EVAL-REGION "(ql:quickload \"eazy-opencl\") ..)
 32: ((LAMBDA NIL :IN SWANK-REPL::REPL-EVAL))
 33: (SWANK-REPL::TRACK-PACKAGE #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::REPL-EVAL) {1004DDFB5B}>)
 34: (SWANK::CALL-WITH-RETRY-RESTART "Retry SLIME REPL evaluation request." #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::REPL-EVAL) {1004DDFABB}>)
 35: (SWANK::CALL-WITH-BUFFER-SYNTAX NIL #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::REPL-EVAL) {1004DDFA9B}>)
 36: (SWANK-REPL::REPL-EVAL "(ql:quickload \"eazy-opencl\") ..)
 37: (SB-INT:SIMPLE-EVAL-IN-LEXENV (SWANK-REPL:LISTENER-EVAL "(ql:quickload \"eazy-opencl\") ..)
 38: (EVAL (SWANK-REPL:LISTENER-EVAL "(ql:quickload \"eazy-opencl\") ..)
 39: (SWANK:EVAL-FOR-EMACS (SWANK-REPL:LISTENER-EVAL "(ql:quickload \"eazy-opencl\") ..)
 40: (SWANK::PROCESS-REQUESTS NIL)
 41: ((LAMBDA NIL :IN SWANK::HANDLE-REQUESTS))
 42: ((LAMBDA NIL :IN SWANK::HANDLE-REQUESTS))
 43: (SWANK/SBCL::CALL-WITH-BREAK-HOOK #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<CLOSURE (LAMBDA NIL :IN SWANK::HANDLE-REQUESTS) {1004AE000B}>)
 44: ((FLET SWANK/BACKEND:CALL-WITH-DEBUGGER-HOOK :IN "/home/emartenson/quicklisp/dists/quicklisp/software/slime-2.14/swank/sbcl.lisp") #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<CLOSURE (LAMBDA NIL :IN SWANK..
 45: (SWANK::CALL-WITH-BINDINGS ((*STANDARD-OUTPUT* . #1=#<SWANK/GRAY::SLIME-OUTPUT-STREAM {1004ABE9D3}>) (*STANDARD-INPUT* . #2=#<SWANK/GRAY::SLIME-INPUT-STREAM {1003A10F63}>) (*TRACE-OUTPUT* . #1#) (*ERR..
 46: (SWANK::HANDLE-REQUESTS #<SWANK::MULTITHREADED-CONNECTION {1003E63B93}> NIL)
 47: ((FLET #:WITHOUT-INTERRUPTS-BODY-1016 :IN SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE))
 48: ((FLET SB-THREAD::WITH-MUTEX-THUNK :IN SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE))
 49: ((FLET #:WITHOUT-INTERRUPTS-BODY-339 :IN SB-THREAD::CALL-WITH-MUTEX))
 50: (SB-THREAD::CALL-WITH-MUTEX #<CLOSURE (FLET SB-THREAD::WITH-MUTEX-THUNK :IN SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE) {7FFFF0926D5B}> #<SB-THREAD:MUTEX "thread result lock" owner: #<SB-THREAD:THR..
 51: (SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE #<SB-THREAD:THREAD "repl-thread" RUNNING {1004AD8033}> NIL #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::SPAWN-REPL-THREAD) {1004AD7F9B}> (#<SB-THREAD:THREAD "re..
 52: ("foreign function: call_into_lisp")
 53: ("foreign function: new_thread_trampoline")

Testing and Examples

  • string ocl
    • hello world
    • naive matrix multiplication
  • lisp-written kernel
    • hello world
    • naive matrix multiplication
  • loading external ocl file
    • hello world
    • loading clblas
    • loading DLNN

host

  • platform
  • deviceid
  • program
  • kernel
  • context
  • commandqueue
  • event
  • memobject
  • buffer
  • image
  • sampler

Update

Fantastic repo! Is it still being maintained?

unified platform/device/ctx/queue querying interface

  • single query support
    • testing
  • multiple query support
    • testing

This would ease the effort of setting up the opencl objects.

Following script binds one platform, one device, one ctx and one queue, where the device should satisfy the test function. Unless specified explicitly with :many symbol, it acts as a constraint that if either there are multiple platforms, devices, contexts or queues that satisfy this query, then it should signal an error. (cf. class diagram in opencl 1.2 documentation)

  (with-easy-opencl-setup (platform               ; equiv: (platform (constantly t) :one)
                           (device (lambda (device)
                                     (eq (get-device-info device :device-type)
                                         :device-type-gpu)))
                           ctx
                           queue)
      body)

In what follows, there should be strictly more than 2 devices that satisfy the test, and the devices should be of the single platform. The context is bound to the result of (create-context devices :context-platform platform), since :one is implied by default.

  (with-easy-opencl-setup (platform
                           (devices (lambda (device)
                                     (eq (get-device-info device :device-type)
                                         :device-type-gpu))
                                     :many)
                           context
                           queue)
      body)

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.