Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
update everything to be reasonably current before officially abandoni…
Browse files Browse the repository at this point in the history
…ng it
  • Loading branch information
ztellman committed Aug 8, 2012
1 parent 1a7494f commit 59deea0
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ lib
classes
push
autodoc
*DS_Store
*DS_Store
.lein*
6 changes: 4 additions & 2 deletions README.textile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
*This project is not under active development.*

Calx is an idiomatic wrapper for OpenCL, which is an abstraction layer for parallel computation. Using a C-variant language, a programmer can target CPUs, GPUs, and more exotic hardware (the Cell processor used in the PS3, for instance).

The OpenCL API is not known for its terseness; consider this "'Hello World' example":http://developer.apple.com/mac/library/samplecode/OpenCL_Hello_World_Example/Listings/hello_c.html#//apple_ref/doc/uid/DTS40008187-hello_c-DontLinkElementID_4 example demonstrating the necessary steps to square a list of floating point numbers. Using Calx, the same result can be achieved like so:

<pre><code>(use 'calx)

(def source
"__kernel void square (
__global const float *a,
Expand All @@ -19,7 +21,7 @@ The OpenCL API is not known for its terseness; consider this "'Hello World' exam
(enqueue-kernel :square 3 a b)
(enqueue-read b))))
</code></pre>

This is very much a work in progress, but still can be immediately useful for some purposes. Anyone using it is encouraged to give feedback.

The complete documentation can be found "here":http://ztellman.github.com/calx/calx-api.html.
10 changes: 5 additions & 5 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(defproject calx "0.2.1-SNAPSHOT"
(defproject calx "0.2.1"
:description "An idiomatic wrapper for OpenCL."
:dependencies [[calx/javacl "1.0.4b"]
[gloss "0.1.1-SNAPSHOT"]
[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
])
[gloss "0.2.1"]
[potemkin "0.1.5"]
[org.clojure/clojure "1.4.0"]
])
24 changes: 8 additions & 16 deletions src/calx.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
:doc "An idiomatic wrapper for OpenCL."}
calx
(:use
[clojure.contrib.def :only (defmacro- defvar-)])
[potemkin])
(:require
[calx
[core :as core]
Expand All @@ -22,14 +22,6 @@

;;;

(defmacro- import-fn [sym]
(let [m (meta (eval sym))
m (meta (intern (:ns m) (:name m)))
n (:name m)
arglists (:arglists m)
doc (:doc m)]
(list `def (with-meta n {:doc doc :arglists (list 'quote arglists)}) (eval sym))))

(import-fn core/available-platforms)
(import-fn core/available-devices)
(import-fn core/available-cpu-devices)
Expand Down Expand Up @@ -58,12 +50,12 @@
(import-fn data/to-buffer)
(import-fn data/from-buffer)
(import-fn data/wrap)
(import-fn #'data/mimic)
(import-fn #'data/release!)
(import-fn #'data/acquire!)
(import-fn #'data/enqueue-read)
(import-fn #'data/enqueue-copy)
(import-fn #'data/enqueue-overwrite)
(import-fn data/mimic)
(import-fn data/release!)
(import-fn data/acquire!)
(import-fn data/enqueue-read)
(import-fn data/enqueue-copy)
(import-fn data/enqueue-overwrite)
(import-fn data/create-buffer)

;;;
Expand Down Expand Up @@ -130,7 +122,7 @@

;;;

(defvar- event-type-map
(def ^:private event-type-map
{CLEvent$CommandType/CopyBuffer :copy-buffer
CLEvent$CommandType/CopyBufferToImage :copy-buffer-to-image
CLEvent$CommandType/CopyImageToBuffer :copy-image-to-buffer
Expand Down
19 changes: 8 additions & 11 deletions src/calx/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
(ns
^{:skip-wiki true}
calx.core
(:use
[clojure.contrib.def :only (defvar defvar-)]
[clojure.contrib.seq :only (indexed)])
(:import
[com.nativelibs4java.opencl
JavaCL CLContext CLPlatform
Expand All @@ -28,13 +25,13 @@

;;;

(defvar *platform* nil "The current platform.")
(defvar *context* nil "The current context.")
(defvar *queue* nil "The current queue.")
(defvar *program* nil "The current program")
(defvar *workgroup-size* nil "The size of the workgroup")
(defvar *params* nil "The params given to a kernel")
(defvar *program-template* nil "A function which will return a program, given the current params.")
(def ^{:doc "The current platform."} ^:dynamic *platform* nil)
(def ^{:doc "The current context."} ^:dynamic *context* nil)
(def ^{:doc "The current queue."} ^:dynamic *queue* nil)
(def ^{:doc "The current program"} ^:dynamic *program* nil)
(def ^{:doc "The size of the workgroup"} ^:dynamic *workgroup-size* nil)
(def ^{:doc "The params given to a kernel"} ^:dynamic *params* nil)
(def ^{:doc "A function which will return a program, given the current params."} ^:dynamic *program-template* nil)

(defn platform
"Returns the current platform, or throws an exception if it's not defined."
Expand Down Expand Up @@ -214,6 +211,6 @@
(defn enqueue-kernel
([kernel global-size & args]
(let [kernel ^CLKernel ((program) kernel)]
(doseq [[idx arg] (indexed (map get-cl-object args))]
(doseq [[idx arg] (map vector (iterate inc 0) (map get-cl-object args))]
(.setArg kernel idx arg))
(.enqueueNDRange kernel (queue) (to-dim-array global-size) *workgroup-size* (make-array CLEvent 0)))))
3 changes: 1 addition & 2 deletions src/calx/data.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
^{:skip-wiki true}
calx.data
(:use
[clojure.contrib.def :only (defmacro- defvar- defvar)]
[gloss core io]
[calx.core])
(:import [com.nativelibs4java.opencl CLContext CLByteBuffer CLMem CLMem$Usage CLEvent]
Expand All @@ -19,7 +18,7 @@

;;;

(defvar- usage-types
(def usage-types
{:in CLMem$Usage/Input
:out CLMem$Usage/Output
:in-out CLMem$Usage/InputOutput})
Expand Down
2 changes: 1 addition & 1 deletion test/calx/test/mixed_datatype.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
b[gid] = m;
}")

(def frame [:int16 :byte])
(def frame [:int16-le :byte])

(deftest invert
(let [value (with-cl
Expand Down
6 changes: 3 additions & 3 deletions test/calx/test/simple_addition.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
(deftest simple-addition
(let [value (with-cl
(with-program (compile-program source)
(let [a (wrap [1 2 3] :float32)
b (wrap [1 2 3] :float32)
(let [a (wrap [1 2 3] :float32-le)
b (wrap [1 2 3] :float32-le)
c (mimic a)]
(enqueue-kernel :vec-add 3 a b c)
(enqueue-read c))))]
(is (= [2 4 6] @value))))
(is (= [2.0 4.0 6.0] @value))))

0 comments on commit 59deea0

Please sign in to comment.