uncomplicate / neanderthal

Fast Clojure Matrix Library
http://neanderthal.uncomplicate.org
Eclipse Public License 1.0
1.06k stars 56 forks source link

Running without the MKL? #45

Closed kxygk closed 6 years ago

kxygk commented 6 years ago

I'm probably misunderstanding something :)

From reading the documentation it seems like you can run Neanderthal with different backends which correspond do different namespaces. The native ns being the Intel MKL backend and then there are OpenCL and CUDA backends (and the ATLAS one is gone..)

I'm looking to run on an ARM machine later, so I was trying to set myself up use OpenCL backend and my namespace doesn't require the neanderthal native namespace and yet it still searches for the MKL


(ns asparapiss.core
  (:require [uncomplicate.neanderthal.core :as nc]
                [uncomplicate.neanderthal.opencl :as no])

Is what I'm trying to do impossible?

blueberry commented 6 years ago

uncomplicate.neanderthal.opencl is a "convenience" namespace that sets you up for working with OpenCL on a "beefy" machine. It wires the OpenCL factory to use the MKL default factory.

Luckily, this is only the default configuration, and is not hardwired. The place where this is set (in default implementation config) is https://github.com/uncomplicate/neanderthal/blob/6c6f4bb6ca550aee57a46e0ce8c60a4ab8dddb92/src/clojure/uncomplicate/neanderthal/internal/device/clblast.clj#L2016

When default clblast-float is being created, it uses native-float from the native namespace. native-float is, by default mkl-float, but can be any other implementation, including the "dummy" one. In the context of OpenCL, the native factory (mkl) is only used for copying stuff, so even if you need to provide an implementation, you only need to implement a few methods for copying data to and from the GPU.

So, to stop neanderthal from trying to load MKL, do not use clblast-float (or opencl-float), but instantiate your own configuration of CLBlast factory and give it some other, non-mkl native factory instance.

The ideal solution would be, of course, if you could contribute an ARM-backed full blown implementation of the native engine that calls an ARM equivalent of MKL (possibly ATLAS compiled for ARM?).

kxygk commented 6 years ago

That makes a lot of sense. The CPU-side uses the MKL primitives through native-float and that can be swapped to something else. Unfortunately I started using Clojure quite recently, and I have very limited experience with OpenCL, so this might be a little beyond my abilities for now - but I appreciate the guidance

Speaking of which, I was hoping to go through OpenCL in Action using ClojureCL. I assume there I won't have the same issue? Maybe once I get through that, Ill revisit this problem.

Thanks for the detailed feedback

blueberry commented 6 years ago

Yes, ClojureCL is OpenCL-only. You'll be able to follow OpenCL in Action on any hardware/OS that supports OpenCL 1.2+. Note that there are ClojureCL versions of most of the examples from the book in the test folder.

(I'm closing this issue now, feel free to (re)open it if you decide to tackle this issue later).