A cuRAND wrapper for Clojure.
Inspired by (and built using)
uncomplicate/clojurecuda. This library intends to be an idiomatic wrapper of the JCurand API, itself being a 1-to-1 mapping of the cuRAND C/C++ API.
(require 'com.dedovic.curand [core :as curand])
(require 'uncomplicate.clojurecuda [core :as cuda])
(require 'uncomplicate.commons.core :refer [with-release])
(with-release [;; CUDA setup. See uncomplicate/clojurecuda.
ctx (cuda/context device)
;; cuRAND RNG setup
;; Note: cuRAND-clj objects are releasable,
;; implementing the protocols defined
;; in the uncomplicate/commons library
rng-buffer (cuda/mem-alloc (* 1000 Float/BYTES))
;; Generate some random values and place them in the buffer
rng-buffer (curand/generate-uniform rng rng-buffer 1000)]
;; copy from GPU (device) memory to CPU (host) memory
(let [random-numbers (cuda/memcpy-host! (float-array 1000) rng-buffer)]
;; Because we used the with-release macro, all resources are cleaned up once out of scope
... is severely lacking. Read the source code.
The biggest changes were to wrap things using the utilities provided in
uncomplicate/commons for thread-safety and automatic release of GPU resources. See the above example.
Copyright © 2020 Stevan Dedovic
Distributed under the Eclipse Public License v2.0.