Last active
December 14, 2015 16:59
-
-
Save ohpauleez/5119032 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, cool, I was going to ask if you went ahead and did this without me. Is there a repo anywhere?