oclcl

https://github.com/gos-k/oclcl.git

git clone 'https://github.com/gos-k/oclcl.git'

(ql:quickload :oclcl)
13

oclcl

CircleCI Status TravisCI Status Quicklisp

oclcl is a library to use OpenCL in Common Lisp programs. It provides the kernel description language with which users can define OpenCL kernel functions in S-expression. The kernel description language also provides facilities to define kernel macros and kernel symbol macros in addition to kernel functions. oclcl's kernel macro and kernel symbol macro offer powerful abstraction that OpenCL C itself does not have and provide enormous advantage in resource-limited GPU programming.

Installation

oclcl is now available on Quicklisp.

(ql:quickload :oclcl)

Requirements

oclcl requires following:

Test

(ql:quickload :prove)
(prove:run :oclcl-test)

or

$ ros install prove
$ run-prove oclcl/oclcl-test.asd

Verification environments

oclcl is verified to work in following environments:

Environment 1

Environment 2

Environment 3

Kernel Description Language

Types

Support types.

IF statement

IF test-form then-form [else-form]

if allows the execution of a form to be dependent on a single test-form. First test-form is evaluated. If the result is true, then then-form is selected; otherwise else-form is selected. Whichever form is selected is then evaluated. If else-form is not provided, does nothing when else-form is selected.

Example:

(if (= a 0)
    (return 0)
    (return 1))

Compiled:

if (a == 0) {
  return 0;
} else {
  return 1;
}

LET statement

LET ({(var init-form)}*) statement*

let declares new variable bindings and set corresponding init-forms to them and execute a series of statements that use these bindings. let performs the bindings in parallel. For sequentially, use let* kernel macro instead.

Example:

(let ((i 0))
  (return i))

Compiled:

{
  int i = 0;
  return i;
}

SYMBOL-MACROLET statement

SYMBOL-MACROLET ({(symbol expansion)}*) statement*

symbol-macrolet establishes symbol expansion rules in the variable environment and execute a series of statements that use these rules. In cl-cuda's compilation process, the symbol macros found in a form are replaces by corresponding expansions.

Example:

(symbol-macrolet ((x 1.0))
  (return x))

Compiled:

{
  return 1.0;
}

DO statement

DO ({(var init-form step-form)}*) (test-form) statement*

do iterates over a group of statements while test-form holds. do accepts an arbitrary number of iteration vars and their initial values are supplied by init-forms. step-forms supply how the vars should be updated on succeeding iterations through the loop.

Example:

(do ((a 0 (+ a 1))
     (b 0 (+ b 1)))
    ((> a 15))
  (do-some-statement))

Compiled:

for ( int a = 0, int b = 0; ! (a > 15); a = a + 1, b = b + 1 )
{
  do_some_statement();
}

WITH-LOCAL-MEMORY statement

WITH-LOCAL-MEMORY ({(var type size*)}*) statement*

with-local-memory declares new variable bindings on local memory by adding __local variable specifiers. It allows to declare array variables if dimensions are provided. A series of statements are executed with these bindings.

Example:

(with-local-memory ((a int 16)
                    (b float 16 16))
  (return))

Compiled:

{
  __local int a[16];
  __local float b[16][16];
  return;
}

SET statement

SET reference expression

set provides simple variable assignment. It accepts one of variable, structure and array references as reference.

Example:

(set x 1.0)
(set (float4-x y 1.0)
(set (aref z 0) 1.0)

Compiled:

x = 1.0;
y.x = 1.0;
z[0] = 1.0;

PROGN statement

PROGN statement*

progn evaluates statements, in the order in which they are given.

Example:

(progn
  (do-some-statements)
  (do-more-statements))

Compiled:

do_some_statements();
do_more_statements();

RETURN statement

RETURN [return-form]

return returns control, with return-form if supplied, from a kernel function.

Example:

(return 0)

Compiled:

return 0;

Built in Functions

Implementation status of built in functions.

| Status | Functions | |:——:|:———-| | Yes | Work-Item | | Part | Math | | Part | Integer | | Part | Common | | Yes | Geometric | | No | Relational | | No | Vector Data Load and Store | | Yes | Synchronization | | Yes | Explicit Memory Fence | | No | Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch | | Yes | Atomic | | Part | Miscellaneous Vector | | Yes | printf | | No | Image Read and Write Functions |

Author

C source generator is forked from cl-cuda.

Copyright

2015 gos-k (mag4.elan@gmail.com)

cl-cuda

Copyright (c) 2012 Masayuki Takagi (kamonama@gmail.com)

License

Licensed under the LLGPL License.