Liking cljdoc? Tell your friends :D


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.

[clojure-curand "0.11.1"]


Basic Example (Generate 1000 Floats)

(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.
               device (cuda/device)
               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))
               rng (curand/set-pseudo-random-generator-seed 

               ;; 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

More Examples and Documentation

... is severely lacking. Read the source code.

The biggest changes were to wrap things using the utilities provided in uncomplicate/clojurecuda and 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.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close