uncomplicate / neanderthal

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

Ubuntu ATLAS installation and setup challenges (SOLVED) (NOT RELEVANT SINCE 2017) #12

Closed mobius-eng closed 7 years ago

mobius-eng commented 8 years ago

On Ubuntu 15.10 with BLAS and ATLAS installed from reps (ATLAS was not custom built). Neanderthal loads correctly, dv works OK. But the attempt to (copy (dv 1 2 3)) fails with

java: symbol lookup error: /tmp/libneanderthal-atlas-0.2.1-SNAPSHOT5638624967954043829.so: undefined symbol: cblas_dcopy
Subprocess failed

It also fails on asum, and I would guess on all BLAS functions...

The following packages are definitely installed:

libblas3 (apt-cache show 's version 1.2.20110419-10), libblas-dev, libblas-common, libatlas3-base, libatlas-dev.

The following shared libraries are available in /usr/lib:

libblas.so, libblas.so.3, libblas.so.3.0, libatlas.so, libatlas.so.3, libatlas.so.3gf, libcblas.so, libcblas.so.3 and libcblas.so.3gf.

Is there something missing?

blueberry commented 8 years ago

EDIT 2017: ATLAS is not used by Neanderthal since the beginning of 2017, so this thread is not relevant any more.

I've just tried the following and could not reproduce this problem:

  1. I've deleted ~/.mv/repository/uncomplicate to make sure that my system pulls the same jars from clojars as you'd get
  2. I started the hello-world project https://github.com/uncomplicate/neanderthal/tree/master/examples/hello-world
  3. copy worked fine, as well as mm from the hello-world example

Please make sure to:

  1. try it with hello world (whick uses neanderthal 0.5.0)
  2. use neanderthal 0.5.0 from clojars and NOT build your own from 0.5.1-SNAPSHOT from github

Does it help?

mobius-eng commented 8 years ago

I have an error with the Hello World project: cblas_dgemm symbol is undefined. Neanderthal is installed from Clojars ("0.5.0").

I start doubting that my BLAS/CBLAS/ATLAS setup is correct...

mobius-eng commented 8 years ago

Just a note: I am running the project from CIDER if it makes any difference.

blueberry commented 8 years ago

First a quick workaround copied from leiningen's sample project:

;; Note that this ;; is not where to look for existing native libraries; use :jvm-opts with

;; -Djava.library.path=... instead for that.

So, you can try to add the path where your atlas is to :jvm-opts in your leiningen build just to be completely sure that JVM sees it. If it works, the problem is the visibility of your /usr/lib (or wherever libatlas.so is) from java apps on Ubuntu. If it doesn't work, it might be that the default atlas build is not a shared library - in this case I'd build ATLAS from the source.

Now, the rest: I am using CIDER too, but it should not matter, because I am also running tests from terminal during the build and everything is fine. Since neanderthal is working fine for non-blas functions, I think that ubuntu's ATLAS setup might be the problem.

Maybe they build libatlas.so without --shared flag, or they configured it in a weird way, or your java projects cannot see it for some reason.

As I have written in the docs, I have tried Neanderthal from the default packages provided by arch and nixos, and it worked with no additional configuration. I also built an optimized build from the source with almost the default configuration from atlas-math site and, apart from having to manually create the link libatlas.so in /usr/lib, did not do anything special there.

On the other hand, Ubuntu usually customizes packages quite a bit, I didn't try it there.

mobius-eng commented 8 years ago

The workaround didn't work. I will try it again in the morning with custom built ATLAS.

blueberry commented 8 years ago

I googled a bit, and it seems that Ubuntu frequently had problems with its ATLAS build. These links might give you a clue to the solution: https://bugs.launchpad.net/ubuntu/+source/atlas/+bug/1005219 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=624318 http://stackoverflow.com/questions/29923533/java-symbol-lookup-error-usr-lib-liblapack-so-3-undefined-symbol-atl-dgetnb

mobius-eng commented 8 years ago

Building ATLAS from scratch seems to be a problem: so far my attempts to disable CPU throttling on my machine were not successful, and without it throttling disabled, ATLAS won't even configure. Will need to re-think how to move forward...

blueberry commented 8 years ago

Did you try with this (I did this on Arch, but should be the same on Ubuntu)?

cpupower frequency-set -g performance

You need it only for the building phase, It is not necessary for ATLAS to work later. This link gives another variant of the same command but used through ubuntu configuration: http://askubuntu.com/questions/523640/how-i-can-disable-cpu-frequency-scaling-and-set-the-system-to-performance Arch Wiki is always an excellent resource for distribution-agnostic information: https://wiki.archlinux.org/index.php/CPU_frequency_scaling

and, please, don't forget to use --shared in your atlas build

mobius-eng commented 8 years ago

I've tried Ubuntu version of this: setting governor to "performance" doesn't disable the throttling for whatever reason. cpufreq-set allows setting constant frequency, but only if "userspace" governor is used. On my machine (Lenovo Y500 with Core i5-5200U) this is not available: only "performance" and "powersave". Maybe it something to do with the kernel configuration.

Anyway, at this point this is not Neanderthal's problem. I have an old Macbook laptop: will try it there.

blueberry commented 8 years ago

Yeah, I know this problem is not strictly in Neanderthal, but would like if we could find a solution for Ubuntu, to help other Ubuntu users.

This Ubuntu user seems to had the same problem as you, but there is a detailed post which seems to offer the solution: http://askubuntu.com/questions/631796/14-04-i-have-disabled-cpu-throttling-but-installing-atlas-says-cpu-throttlin

blueberry commented 8 years ago

BTW, I used the latest STABLE atlas: 3.10.2

blueberry commented 8 years ago

Since this issue seems to be abandoned, and I have reports from other users that Ubuntu works fine, I'll close this. If you still have problems with this, please feel free to reopen it.

bpiel commented 8 years ago

@mobius-eng Ever figure this out? I'm seeing the same issue.

java: symbol lookup error: /tmp/libneanderthal-atlas-0.3.1236060653264501117.so: undefined symbol: cblas_dcopy

blueberry commented 8 years ago

@bpiel Did you follow the guide at neanderthal.uncomplicate.org/articles/getting_started.html and can you please tell me at which step exactly it fails? Also, please give me more details about the Ubuntu and ATLAS versions that you have. Did you also try with http://packages.ubuntu.com/search?keywords=libatlas-base-dev&searchon=names or you built the ATLAS yourself? Was ATLAS built with --shared flag?

This is almost certainly an issue with how ATLAS is installed, and only way I can help you identify the solution is to have all exact steps of the process, to spot what's missing.

I build and test Neanderthal with the latest stable ATLAS, which now is 3.10.3

bpiel commented 8 years ago

@blueberry

Ubuntu 15.04 I apt-get installed libatlas-base-dev -- nothing else. I understand that's not recommended, but that's all I had time for. The failure occurred when I attempted to call copy.

Sorry, for not posting more details originally, but they seemed similar enough to the original post that I was lazy about it.

blueberry commented 8 years ago

According to this page, http://askubuntu.com/questions/719538/libatlas-package the package you installed contains static atlas, so you need to install libatlas3-base, which contains shared libraries.

The version I'm using is 3.10.3, while ubuntu 15.04 comes with 3.10.1, but they should be compatible. Please also make sure that you uninstall the old package properly, and that the shared libatlas is used. The libary should be called libatlas, so if you only have lib_s_atlas and lib_t_atlas, create the needed symbolic link to one of them.

Does it work now?

bpiel commented 8 years ago

No, same issue.

I removed and purged the previously installed package. I installed libatlas3-base. The package created /usr/lib/libatlas.so.3, so I made a symlink from libatlas.so to that file.

Still getting this:

lstm-neaderthal.core=> java: symbol lookup error: /tmp/libneanderthal-atlas-0.3.15431726502681031123.so: undefined symbol: cblas_dcopy
Exception in thread "Thread-3" clojure.lang.ExceptionInfo: Subprocess failed {:exit-code 127}
    at clojure.core$ex_info.invokeStatic(core.clj:4617)
    at clojure.core$ex_info.invoke(core.clj:4617)
    at leiningen.core.eval$fn__5625.invokeStatic(eval.clj:271)
    at leiningen.core.eval$fn__5625.invoke(eval.clj:267)
...
blueberry commented 8 years ago

I'm assuming you use Neanderthal 0.8.0, right?

One approach that you might try, is that you obtain libatlas.so, and copy/paste it directly into your clojure project's root. Java should pick it up there (but, who knows...)

On the other hand, it seems that Ubuntu has some peculiarities there, since it maintains some additional layer to accomodate both 64-bit and 32-bit libraries. According to this thread, it seems that the cache was not updated, and you can do it easily: http://askubuntu.com/questions/350068/where-does-ubuntu-look-for-shared-libraries

Again, I checked with a friend, and he couldn't recall that he had a problem when he installed it on ubuntu...

If nothing of this works, I'll sent you a pre-built libsatlas.so, so you can manually put it wherever Java can find it on your machine, so we can at least narrow the problem source.

blueberry commented 8 years ago

And, this might also be relevant for your case http://unix.stackexchange.com/questions/67781/use-shared-libraries-in-usr-local-lib

goranjovic commented 7 years ago

Short version: I had the same issue with ATLAS from the repo. It turns out that Ubuntu ships atlas as two separate so files. This is incorrect on the Ubuntu side, but luckily there is a workaround - we can inject the other so file with LD_PRELOAD, e.g. like this:

LD_PRELOAD=/usr/lib/liblapack_atlas.so lein repl

So, just prefix your java command with this and it should work.

Long version (my blog): https://bigsolutions.io/2017/02/01/how-to-run-neanderthal-with-atlas-blas-from-ubuntu-repositories/

blueberry commented 7 years ago

Goran, thank you very much for straightening this issue out. This bugged many people who wanted to start quickly on Ubuntu using Atlas from apt-get. I'll link to your detailed post on the main site right away!

blueberry commented 7 years ago

@mobius-eng @bpiel I hope that Goran's solution work for you?

bpiel commented 7 years ago

@blueberry Thanks for checking in, but the project I was using this for is shelved for now.

blueberry commented 7 years ago

Some more useful info about setting this in leiningen's project.clj can be found in the comments here: https://www.reddit.com/r/Clojure/comments/5rfu2n/how_to_run_neanderthal_with_atlas_blas_from/

Of course, it is still better (IMO) to just grab libatlas.so (or dll) from whatever trusted source and put it in the PATH of your OS. It is one standalone file, no additional config needed.

blueberry commented 6 years ago

I have just seen that there is lots of traffic to this page. This thread is no longer relevant since Neanderthal does not use ATLAS any more. Now it uses Intel MKL.