Skip to content

Instantly share code, notes, and snippets.

@ohpauleez
Last active December 14, 2015 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohpauleez/5119032 to your computer and use it in GitHub Desktop.
Save ohpauleez/5119032 to your computer and use it in GitHub Desktop.
(ns com.ndensity.clclj.example
(:require [com.ndensity.clclj :as clclj :refer [clfn]]))
(defn cube [n] ; if you don't type hint, it assumes int32 for all args & return types
(* n n n))
(def cube_cl (clfn* cube))
(def square-cl
(clfn [n]
(let [a (inc n)
b (- n 5)]
;; If you return a vector, it'll be typed as an int32 array
[(* (b + a) n n) (* n n) (clclj/cl* "a*a") (clclj/call :cube_cl n)])))
(def cube-elems-cl
(clfn [n-vec]
(clclj/clfor-map :cube_cl n-vec))) ;; this restructures the map statement into a for statement in OCL
;; Easy data parallelism
(def res1 (clclj/map square-cl (range 40))) ;; By default, will choose "best context"
(def res2 (clclj/map square-cl (clclj/wrap (range 40) :int32)
:context (first (clclj/available-gpu-devices))))
(def res3 (clclj/map square-cl (vec (range 40))
:context (first (clclj/available-cpu-devices))))
;; Support for all of the functions found in core.reducers
;; Easy task parallelism
(def res4 (clclj/data-map [1 2 3 4] (repeat 10 cube-elems-cl)))
;; * jBLAS for OCL via JavaCL
;; * incanter-core that uses the OCL jBLAS
;; * all other JavaCL goodies
@ztellman
Copy link

ztellman commented Mar 9, 2013

Hey, cool, I was going to ask if you went ahead and did this without me. Is there a repo anywhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment