4

I'm trying to use the Neanderthal library in Clojure but I keep getting an error when executing any rand-normal! and rand-uniform!. I've installed the Intel MKL library, executed the mklvars.bat as mklvars intel64 file to set the environment variables, but then I checked the env. variables and since it didn't add anything new, I've added them manually. What can I do to make it to work?

I'm using Windows 10 64 bits.

This is my code:

(ns testing-grounds.neanderthal.core
  (:gen-class)
  (:require [uncomplicate.neanderthal
             [native :refer [dv dge fv fge native-float]]
             [core :refer [submatrix native dot mm ge]]
             [math :refer [sqrt log sin pi sqr]]
             [random :refer [rand-normal! rand-uniform! rng-state]]]))

(def x (dv 1 2 3))
;; => #'testing-grounds.neanderthal.core/x

(def y (dv 10 20 30))
;; => #'testing-grounds.neanderthal.core/y

(dot x y)
;; => 140.0

(def a (dge 3 2 [1 2 3 4 5 6]))
;; => #'testing-grounds.neanderthal.core/a

(def b (dge 2 3 [10 20 30 40 50 60]))
;; => #'testing-grounds.neanderthal.core/b

(mm a b)
;; => #RealGEMatrix[double, mxn:3x3, layout:column, offset:0]
;;    ▥       ↓       ↓       ↓       ┓
;;    →      90.00  190.00  290.00
;;    →     120.00  260.00  400.00
;;    →     150.00  330.00  510.00
;;    ┗                               ┛

(def x
  "Define an empty float vector"
  (fv 5))
;; => #'testing-grounds.neanderthal.core/x

(rand-uniform! x) 
; Error

(def a (fge 3 2))
;; => #'testing-grounds.neanderthal.core/a

(rand-normal! 33 2.5 a) 
; Error

The project.clj

(defproject testing-grounds "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "LATEST"]
                 [uncomplicate/neanderthal "LATEST"]
                 [incanter "LATEST"]
                 [org.clojure/tools.nrepl "LATEST"]
                 [nrepl "LATEST"]
                 [cider/cider-nrepl "LATEST"]
                 ]
  :plugins [[cider/cider-nrepl "LATEST"]]
  :java-cmd "C:/Users/user/Downloads/jdk-12.0.1/bin/java"
  :jvm-opts ["--add-opens=java.base/jdk.internal.ref=ALL-UNNAMED"]
  :main ^:skip-aot testing-grounds.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})

The error:

  Show: Project-Only All 
  Hide: Clojure Java REPL Tooling Duplicates  (0 frames hidden)

1. Unhandled clojure.lang.ExceptionInfo
   MKL error.
   {:error-code -1140}
                   mkl.clj:  823  uncomplicate.neanderthal.internal.host.mkl.FloatVectorEngine/rand_uniform
                random.clj:   42  uncomplicate.neanderthal.random/rand-uniform!
                random.clj:   37  uncomplicate.neanderthal.random/rand-uniform!
                      REPL:   28  testing-grounds.neanderthal.core/eval33584
                      REPL:   28  testing-grounds.neanderthal.core/eval33584
             Compiler.java: 7177  clojure.lang.Compiler/eval
             Compiler.java: 7132  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
                  main.clj:  437  clojure.main/repl/read-eval-print/fn
                  main.clj:  437  clojure.main/repl/read-eval-print
                  main.clj:  458  clojure.main/repl/fn
                  main.clj:  458  clojure.main/repl
                  main.clj:  368  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   79  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   55  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  142  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  171  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  170  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  835  java.lang.Thread/run

Edit: I've tried this script on another computer and it worked. It must be something wrong with my computer.

Vasco Ferreira
  • 2,151
  • 2
  • 15
  • 21

2 Answers2

2

Intel MKL error code -1140 is VSL_RNG_ERROR_ARS5_NOT_SUPPORTED.

You can look up error codes by grepping the header files in your installation. On my macOS computer it was this file: /opt/intel/oneapi/mkl/2021.1.1/include/mkl_vsl_defines.h

jamesd3142
  • 21
  • 3
0

ARS-5 is available only on microarchitectures with AES-NI instructions, and in case if the application would be launched on microarchitecture which doesn’t support AES-NI instructions, then VSL RNG routines will return VSL_RNG_ERROR_ARS5_NOT_SUPPORTED status code.

Gennady.F
  • 571
  • 2
  • 7