Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caffe linking to caffe CPU only build (without GPU support) #219

Closed
bisher3 opened this issue May 13, 2016 · 13 comments
Closed

Caffe linking to caffe CPU only build (without GPU support) #219

bisher3 opened this issue May 13, 2016 · 13 comments

Comments

@bisher3
Copy link

bisher3 commented May 13, 2016

Hello,
I wanted to use javacpp presets for caffe on machines without a GPU. I had already successfully built and ran caffe in CPU only mode and now I'm trying to access it from java but the javacpp-presets downloads and links to a pre-built caffe with GPU support.
First I kept getting this error:

Caused by: java.lang.UnsatisfiedLinkError: /private/var/folders/g3/nyry1nsx6lg0vjb5nkbw7jt40000gn/T/javacpp143953538120369/libjnicaffe.dylib: dlopen(/private/var/folders/g3/nyry1nsx6lg0vjb5nkbw7jt40000gn/T/javacpp143953538120369/libjnicaffe.dylib, 1): Library not loaded: @rpath/libcudart.7.5.dylib

I then installed CUDA on the device and this error disappeared.
Now I get

F0513 19:49:44.501734 2203648 internal_thread.cpp:26] Check failed: error == cudaSuccess (35 vs. 0)  CUDA driver version is insufficient for CUDA runtime version.

This is obviously because the machine doesn't contain a GPU and the nVidia Cuda driver won't work on it.
Is there a way to link to the CPU only caffe built libraries ??
Thanks,
Bisher

@saudet
Copy link
Member

saudet commented May 14, 2016

Sure, you can make a build without CUDA support. It's probably easier to simply not use CUDA at runtime though.

@bisher3
Copy link
Author

bisher3 commented May 14, 2016

I set -gpu=-1 in the command line and solver_mode: CPU in the solver.prototxt file but still got this error.
Is there any other way to disable CUDA usage at runtime?

@saudet
Copy link
Member

saudet commented May 14, 2016 via email

@bisher3 bisher3 closed this as completed May 14, 2016
@saudet
Copy link
Member

saudet commented May 14, 2016

Anyway, if it doesn't for you, please report it upstream! Thanks

@bisher3
Copy link
Author

bisher3 commented May 16, 2016

Sorry to reopen issue, but the compilation isn't working correctly.

Please notice that if you build caffe with GPU support and then disable it at runtime only, it will still search for CUDA and CUDA driver but not use them. What I want to achieve is get a caffe build that doesn't search for the CUDA driver and can work on a machine without any GPU at all. (such as old macbook)

These are the steps I tried to recompile the javacpp-presets for caffe WITHOUT GPU support (CPU_ONLY=1):

  1. Pull javacpp and javacpp-presets from github
  2. Build javacpp correctly using maven. The javacpp-1.2-SNAPSHOT.jar is correctly deployed to Maven repository
  3. Modify cppbuild.sh in javacpp-presets/caffe
    on line 30:
    macosx-*) export CPU_ONLY=1
    and also line 145
    make -j $MAKEJ BLAS=$BLAS BLAS_INCLUDE=/usr/local/opt/openblas/include BLAS_LIB=/usr/local/opt/openblas/lib OPENCV_VERSION=3 DISTRIBUTE_DIR=.. # lib
    This is to use the openBlas libraries in my mac instead of default ones. OpenBlas is faster
  4. Run : mvn clean install --projects .,opencv,caffe
  5. After a while all jars are deployed correctly in Maven repository: caffe-rc3-1.2-SNAPSHOT.jar , opencv-3.1.0-1.2-SNAPSHOT.jar and caffe-rc3-1.2-SNAPSHOT-sources.jar that supposedly contains /org/bytedeco/javacpp/macosx-x86_64/libcaffe.so.1.0.0-rc3

I add
<dependency> <groupId>org.bytedeco.javacpp-presets</groupId> <artifactId>caffe</artifactId> <version>rc3-1.2-SNAPSHOT</version> </dependency>

to my pom file and it imports the correct libraries into my project.
When I run caffe.java I get this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jnicaffe in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1122) at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:654) at org.bytedeco.javacpp.Loader.load(Loader.java:492) at org.bytedeco.javacpp.Loader.load(Loader.java:409) at org.bytedeco.javacpp.caffe.<clinit>(caffe.java:16) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at org.bytedeco.javacpp.Loader.load(Loader.java:464) at org.bytedeco.javacpp.Loader.load(Loader.java:409) at org.bytedeco.javacpp.caffe$MessageLite.<clinit>(caffe.java:2967) at conpanna.caffe$2.command(caffe.java:182) at conpanna.caffe.main(caffe.java:396) Caused by: java.lang.UnsatisfiedLinkError: /private/var/folders/g3/nyry1nsx6lg0vjb5nkbw7jt40000gn/T/javacpp206074640320495/libjnicaffe.dylib: dlopen(/private/var/folders/g3/nyry1nsx6lg0vjb5nkbw7jt40000gn/T/javacpp206074640320495/libjnicaffe.dylib, 1): Library not loaded: libcaffe.so.1.0.0-rc3 Referenced from: /private/var/folders/g3/nyry1nsx6lg0vjb5nkbw7jt40000gn/T/javacpp206074640320495/libjnicaffe.dylib Reason: image not found at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824) at java.lang.Runtime.load0(Runtime.java:809) at java.lang.System.load(System.java:1086) at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:637) ... 10 more

Sorry for long message, I just want to explain exactly what I did.
Thank you.

@bisher3 bisher3 reopened this May 16, 2016
@saudet
Copy link
Member

saudet commented May 19, 2016

Please try to follow the instructions here to build on OS X:
https://github.com/bytedeco/javacpp-presets/wiki/Build-Environments#mac-os-x-x86_64

@saudet saudet added the bug label Jun 5, 2016
@saudet
Copy link
Member

saudet commented Jun 5, 2016

I just found out that is should be possible to get rid of that issue by linking with --cudart=static. Could you try this out and let me know what that gives? Let me know if you still have issues building.

@saudet
Copy link
Member

saudet commented Jul 31, 2016

I've just released an update that works well on machines without GPU as well. It has version "master-1.2":
https://github.com/bytedeco/javacpp-presets/tree/master/caffe
http://search.maven.org/#search%7Cga%7C1%7Cbytedeco%20caffe

We still need CUDA 7.5 installed, but I've tested it with Mac OS X (Yosemite) on a machine that has no GPU and it works fine. Just make sure that your code never calls either Caffe.SetDevice(gpu) or Caffe.set_mode(Caffe.GPU). Enjoy!

@saudet saudet closed this as completed Jul 31, 2016
@bisher3
Copy link
Author

bisher3 commented Aug 3, 2016

Thank you Saudet! I can confirm this is working on a Mac without a GPU

@shiqin-zhang
Copy link

shiqin-zhang commented Jul 13, 2017

@saudet thanks for your https://github.com/bytedeco/javacpp-presets/tree/master/caffe , but I can not import the following dependence:

<dependency>
       <groupId>org.bytedeco.javacpp-presets</groupId>
       <artifactId>caffe-platform</artifactId>
       <version>1.0-1.3.3-SNAPSHOT</version>
</dependency>

I don't know weather it is out of date or some other reason, can you give a useful dependency?

@saudet
Copy link
Member

saudet commented Jul 13, 2017

@shiqin-zhang Make sure to enable the SNAPSHOT repository by adding something like the following in your pom.xml or settings.xml file:
https://github.com/bytedeco/javacpp-presets/blob/master/pom.xml#L118-L130

@saudet
Copy link
Member

saudet commented Jul 13, 2017

CUDA needs to be installed, even if you don't use or have a GPU.

@saudet
Copy link
Member

saudet commented Dec 20, 2017

FYI, separate CPU-only and GPU-enabled builds are now a reality! In addition to caffe-platform, adding something like the following will download and use the binaries for CUDA:

        <dependency>
            <groupId>org.bytedeco.javacpp-presets</groupId>
            <artifactId>caffe</artifactId>
            <version>1.0-1.3.4-SNAPSHOT</version>
            <classifier>linux-x86_64-gpu</classifier>
        </dependency>

If not, the CPU-only binaries are used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants