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 with USE_CUDNN = true #187

Closed
mmanco opened this issue Apr 1, 2016 · 20 comments
Closed

caffe with USE_CUDNN = true #187

mmanco opened this issue Apr 1, 2016 · 20 comments
Labels

Comments

@mmanco
Copy link
Contributor

mmanco commented Apr 1, 2016

When trying to build caffe with USE_CUDNN set to true the build will fail on compile phase with the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project caffe: Compilation failure: Compilation failure:
[ERROR] /workspace/javacpp-presets/caffe/src/main/java/org/bytedeco/javacpp/caffe.java:[21709,82] cannot find symbol
[ERROR] symbol:   class cudnnStatus_t
[ERROR] location: class org.bytedeco.javacpp.caffe
[ERROR] /workspace/javacpp-presets/caffe/src/main/java/org/bytedeco/javacpp/caffe.java:[21724,52] cannot find symbol
[ERROR] symbol:   class cudnnDataType_t
[ERROR] location: class org.bytedeco.javacpp.caffe.dataType
[ERROR] /workspace/javacpp-presets/caffe/src/main/java/org/bytedeco/javacpp/caffe.java:[21728,53] zero() in org.bytedeco.javacpp.caffe.dataType cannot override <P>zero() in org.bytedeco.javacpp.Pointer

The produced code looks like:

// #define CUDNN_CHECK(condition)
//   do {
//     cudnnStatus_t status = condition;
//     CHECK_EQ(status, CUDNN_STATUS_SUCCESS) << " "
//       << cudnnGetErrorString(status);
//   } while (0)

public static native @Cast("const char*") BytePointer cudnnGetErrorString(@ByVal cudnnStatus_t status);
@Name("caffe::cudnn::dataType<float>") public static class dataType extends Pointer {
    static { Loader.load(); }
    /** Default native constructor. */
    public dataType() { super((Pointer)null); allocate(); }
    /** Native array allocator. Access with {@link Pointer#position(long)}. */
    public dataType(long size) { super((Pointer)null); allocateArray(size); }
    /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
    public dataType(Pointer p) { super(p); }
    private native void allocate();
    private native void allocateArray(long size);
    @Override public dataType position(long position) {
        return (dataType)super.position(position);
    }

  @MemberGetter public static native @Const @ByRef cudnnDataType_t type();
  public static native float oneval(); public static native void oneval(float oneval);
  public static native float zeroval(); public static native void zeroval(float zeroval);
  @MemberGetter public static native @Const Pointer one();
  @MemberGetter public static native @Const Pointer zero();
}

As you can see cudnnGetErrorString method signature is not correct as cudnnStatus_t should be actually an int

I tried to add cuda preset as a dependency to the caffe preset which led to same build result.

Do I miss something here ?

@saudet saudet added the question label Apr 2, 2016
@saudet
Copy link
Member

saudet commented Apr 2, 2016

The following patch seems to work just fine here. No errors at all. (I had to fix the error for zero() in JavaCPP though, so make sure to get the latest SNAPSHOT.) What do you get?

diff --git a/caffe/cppbuild.sh b/caffe/cppbuild.sh
index 5514360..2632d31 100755
--- a/caffe/cppbuild.sh
+++ b/caffe/cppbuild.sh
@@ -150,7 +150,7 @@ export PATH=../bin:$PATH
 export CXXFLAGS="-I../include -I$OPENCV_PATH/include"
 export NVCCFLAGS="-I../include -I$OPENCV_PATH/include"
 export LINKFLAGS="-L../lib -L$OPENCV_PATH/lib"
-make -j $MAKEJ BLAS=$BLAS OPENCV_VERSION=3 DISTRIBUTE_DIR=.. lib
+make -j $MAKEJ BLAS=$BLAS OPENCV_VERSION=3 DISTRIBUTE_DIR=.. USE_CUDNN=1 lib
 # Manual deploy to avoid Caffe's python build
 mkdir -p ../include/caffe/proto
 cp -a include/caffe/* ../include/caffe/
diff --git a/caffe/pom.xml b/caffe/pom.xml
index 4546bc7..522de8b 100644
--- a/caffe/pom.xml
+++ b/caffe/pom.xml
@@ -22,6 +22,11 @@
   <dependencies>
     <dependency>
       <groupId>org.bytedeco.javacpp-presets</groupId>
+      <artifactId>cuda</artifactId>
+      <version>7.5-${project.parent.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.bytedeco.javacpp-presets</groupId>
       <artifactId>opencv</artifactId>
       <version>3.1.0-${project.parent.version}</version>
     </dependency>
@@ -58,6 +63,7 @@
             </property>
           </propertyKeysAndValues>
           <classPaths>
+            <classPath>${basedir}/../cuda/target/classes/</classPath>
             <classPath>${basedir}/../opencv/target/classes/</classPath>
             <classPath>${project.build.outputDirectory}</classPath>
           </classPaths>
diff --git a/caffe/src/main/java/org/bytedeco/javacpp/presets/caffe.java b/caffe/src/main/java/org/bytedeco/javacpp/presets/caffe.java
index a9073d2..fa1e5ab 100644
--- a/caffe/src/main/java/org/bytedeco/javacpp/presets/caffe.java
+++ b/caffe/src/main/java/org/bytedeco/javacpp/presets/caffe.java
@@ -36,7 +36,7 @@ import org.bytedeco.javacpp.tools.InfoMapper;
  *
  * @author Samuel Audet
  */
-@Properties(inherit = opencv_highgui.class, target = "org.bytedeco.javacpp.caffe", value = {
+@Properties(inherit = {opencv_highgui.class, cudnn.class}, target = "org.bytedeco.javacpp.caffe", value = {
     @Platform(value = {"linux", "macosx"}, define = {"CPU_ONLY", "SHARED_PTR_NAMESPACE boost", "USE_LEVELDB", "USE_LMDB", "USE_OPENCV"}, include = {"caffe/caffe.hpp", "caffe/util/device_alternate.hpp",
         "caffe/common.hpp", "caffe/proto/caffe.pb.h", "caffe/util/blocking_queue.hpp", "caffe/data_reader.hpp", "caffe/util/math_functions.hpp", "caffe/syncedmem.hpp",
         "caffe/blob.hpp", "caffe/data_transformer.hpp", "caffe/filler.hpp", "caffe/internal_thread.hpp", "caffe/util/hdf5.hpp", "caffe/layers/base_data_layer.hpp", "caffe/layers/data_layer.hpp",
@@ -56,12 +56,12 @@ import org.bytedeco.javacpp.tools.InfoMapper;
         "caffe/util/db_lmdb.hpp", "caffe/util/io.hpp", "caffe/util/rng.hpp", "caffe/util/im2col.hpp", "caffe/util/insert_splits.hpp", "caffe/util/mkl_alternate.hpp",
         "caffe/util/upgrade_proto.hpp", "caffe/util/cudnn.hpp"}, link = "caffe@.1.0.0-rc3", includepath = {"/usr/local/cuda/include/",
         "/System/Library/Frameworks/vecLib.framework/", "/System/Library/Frameworks/Accelerate.framework/"}, linkpath = "/usr/local/cuda/lib/"),
-    @Platform(value = {"linux-x86_64", "macosx-x86_64"}, define = {"SHARED_PTR_NAMESPACE boost", "USE_LEVELDB", "USE_LMDB", "USE_OPENCV"}) })
+    @Platform(value = {"linux-x86_64", "macosx-x86_64"}, define = {"SHARED_PTR_NAMESPACE boost", "USE_LEVELDB", "USE_LMDB", "USE_OPENCV", "USE_CUDNN"}) })
 public class caffe implements InfoMapper {
     public void map(InfoMap infoMap) {
         infoMap.put(new Info("NOT_IMPLEMENTED", "NO_GPU", "CUDA_POST_KERNEL_CHECK").cppTypes().annotations())
                .put(new Info("CPU_ONLY", "GFLAGS_GFLAGS_H_", "SWIG").define())
-               .put(new Info("USE_CUDNN").define(false))
+               .put(new Info("USE_CUDNN").define())
                .put(new Info("cublasHandle_t", "curandGenerator_t").cast().valueTypes("Pointer"))
                .put(new Info("CBLAS_TRANSPOSE", "cublasStatus_t", "curandStatus_t", "hid_t").cast().valueTypes("int"))
                .put(new Info("std::string").annotations("@StdString").valueTypes("BytePointer", "String").pointerTypes("@Cast({\"char*\", \"std::string*\"}) BytePointer"))
@@ -100,7 +100,7 @@ public class caffe implements InfoMapper {
                 "BatchReindexLayer", "ConcatLayer", "EltwiseLayer", "EmbedLayer", "FilterLayer", "FlattenLayer", "InnerProductLayer", "MVNLayer", "ReshapeLayer", "ReductionLayer",
                 "SilenceLayer", "SoftmaxLayer", "SplitLayer", "SliceLayer", "TileLayer", "Net", "Solver", "WorkerSolver", "SolverRegistry", "SolverRegisterer", "SGDSolver", "NesterovSolver",
                 "AdaGradSolver", "RMSPropSolver", "AdaDeltaSolver", "AdamSolver",  "BaseConvolutionLayer", "ConvolutionLayer", "DeconvolutionLayer", "Im2colLayer", "LRNLayer", "PoolingLayer",
-                /* "SPPLayer", "CuDNNReLULayer", "CuDNNSigmoidLayer", "CuDNNTanHLayer", "CuDNNSoftmaxLayer", "CuDNNConvolutionLayer", "CuDNNPoolingLayer" */ };
+                "SPPLayer", "CuDNNReLULayer", "CuDNNSigmoidLayer", "CuDNNTanHLayer", "CuDNNSoftmaxLayer", "CuDNNConvolutionLayer", "CuDNNPoolingLayer" };
         for (String t : classTemplates) {
             boolean purify = t.equals("BaseDataLayer") || t.equals("LossLayer") || t.equals("NeuronLayer");
             boolean virtualize = t.endsWith("Layer") || t.endsWith("Solver");

@saudet saudet closed this as completed Apr 2, 2016
@mmanco
Copy link
Contributor Author

mmanco commented Apr 2, 2016

@saudet Thank you for the patch and the fix. The build passed successfully.

@mmanco
Copy link
Contributor Author

mmanco commented Apr 7, 2016

@saudet should we somehow apply your patch on caffe preset ?
caffe with cudnn is used together for many use-cases.
may be we can create another caffe-cudnn preset.

@saudet
Copy link
Member

saudet commented Apr 8, 2016

So, could we say that most people using Caffe with CUDA also use cuDNN? I'm wondering about that because Caffe does not enable cuDNN by default...

@mmanco
Copy link
Contributor Author

mmanco commented Apr 8, 2016

I can't say that most people uses it as sometimes using cuDNN will be efficient and sometimes not.
but, having the ability to easily control it through the preset will be perfect.

@saudet
Copy link
Member

saudet commented Apr 8, 2016

I mean, even if it's not efficient, we can always decide to use those layers or not at runtime, but does it matter that the presets require cuDNN to build?

@mmanco
Copy link
Contributor Author

mmanco commented Apr 8, 2016

I may be missing something. How would you switch between the layer types at runtime ? currently we are building caffe with USE_CUDNN in order to utilize it.

@saudet
Copy link
Member

saudet commented Apr 8, 2016

Oh, I thought there was a runtime switch. There isn't? Well, that complicates things... Some people also want binaries that can run entirely without CUDA to have it work on nodes that are not GPU-enabled. That's something of concern for @cypof and @danwexler as well, so we could discuss it all together about what we should do:
https://groups.google.com/forum/#!searchin/javacpp-project/wexler/javacpp-project/g88kCrBlAPQ/kr0lCorWJwAJ
I guess in the end the easiest most general solution would be to offer different sets of binaries. That's what I'm already doing for FFTW to support both float and double, for example:
https://github.com/bytedeco/javacpp-presets/blob/master/fftw/src/main/java/org/bytedeco/javacpp/presets/fftw3.java

@danwexler
Copy link

I can confirm that the current code runs fine on OSX machines that do NOT contain a CUDA-capable GPU. You do need to install the CUDA libs to avoid a runtime link failure, but the Caffe code already does an internal runtime check and you can force CPU-only with a Caffe API call. My first goal is to bundle the CUDA libs with the OSX binary bundle since that works on all Macs, whereas the current binaries fail if the target machine does not have those libs.

@saudet
Copy link
Member

saudet commented Apr 9, 2016

@danwexler So you are saying that it runs fine on machines where CUDA is installed, even if no GPU drivers are installed? Interesting. Could you try to bundle the CUDA files as well and see what happens? We can do that by first removing <copyLibs>false</copyLibs> from the pom.xml file of the CUDA presets, and by adding the required CUDA wrapper classes to the @Properties(inherit=... value in the Caffe presets.

@saudet
Copy link
Member

saudet commented Jun 8, 2016

@danwexler BTW, I found out that it 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?

@sebastianlutter
Copy link

I try to build a version of javacpp-presets caffe with CUDNN6 and CUDA8 on Ubuntu 16.04

I applied the above mentioned patch on my source, only difference is I use Cuda 8.0, so in caffe/pom.xml:

<dependency>
      <groupId>org.bytedeco.javacpp-presets</groupId>
      <artifactId>cuda</artifactId>
      <version>8.0-${project.parent.version}</version>
 </dependency>
  • I build with
javacpp-presets$ ./cppbuild.sh install opencv
javacpp-presets$ ./cppbuild.sh install caffe
javacpp-presets$ mvn clean && mvn -U install --projects .,opencv,caffe
  • The native build are successful, but the mvn install ends with
javacpp/javacpp-presets-tmpfs$ mvn -e -X install --projects .,caffe
[ ... ]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-compiler-plugin:3.3:compile' with basic configurator -->
[DEBUG]   (f) basedir = /home/gpuslave/workspace/javacpp/javacpp-presets-tmpfs/caffe
[DEBUG]   (f) buildDirectory = /home/gpuslave/workspace/javacpp/javacpp-presets-tmpfs/caffe/target
[DEBUG]   (f) classpathElements = [/home/gpuslave/workspace/javacpp/javacpp-presets-tmpfs/caffe/target/classes, /home/gpuslave/.m2/repository/org/bytedeco/javacpp-presets/cuda/8.0-1.2/cuda-8.0-1.2.jar, /home/gpuslave/.m2/repository/org/bytedeco/javacpp-presets/opencv/3.1.0-1.2/opencv-3.1.0-1.2.jar, /home/gpuslave/.m2/repository/org/bytedeco/javacpp/1.2/javacpp-1.2.jar]
[DEBUG]   (f) compileSourceRoots = [/home/gpuslave/workspace/javacpp/javacpp-presets-tmpfs/caffe/src/main/java]
[DEBUG]   (f) compilerId = javac
[DEBUG]   (f) debug = true
[DEBUG]   (f) encoding = UTF-8
[DEBUG]   (f) failOnError = true
[DEBUG]   (f) forceJavacCompilerUse = false
[DEBUG]   (f) fork = false
[DEBUG]   (f) generatedSourcesDirectory = /home/gpuslave/workspace/javacpp/javacpp-presets-tmpfs/caffe/target/generated-sources/annotations
[DEBUG]   (f) includes = [org/bytedeco/javacpp/presets/*.java]
[DEBUG]   (f) mojoExecution = org.apache.maven.plugins:maven-compiler-plugin:3.3:compile {execution: javacpp.parser}
[DEBUG]   (f) optimize = false
[DEBUG]   (f) outputDirectory = /home/gpuslave/workspace/javacpp/javacpp-presets-tmpfs/caffe/target/classes
[DEBUG]   (f) project = MavenProject: org.bytedeco.javacpp-presets:caffe:1.0-1.2CUDA8_CUDNN6 @ /home/gpuslave/workspace/javacpp/javacpp-presets-tmpfs/caffe/pom.xml
[DEBUG]   (f) projectArtifact = org.bytedeco.javacpp-presets:caffe:jar:1.0-1.2CUDA8_CUDNN6
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@5176d279
[DEBUG]   (f) showDeprecation = false
[DEBUG]   (f) showWarnings = false
[DEBUG]   (f) skipMain = false
[DEBUG]   (f) skipMultiThreadWarning = false
[DEBUG]   (f) source = 1.7
[DEBUG]   (f) staleMillis = 0
[DEBUG]   (f) target = 1.7
[DEBUG]   (f) useIncrementalCompilation = true
[DEBUG]   (f) verbose = false
[DEBUG] -- end configuration --
[DEBUG] Using compiler 'javac'.
[ ... ]
[INFO] Detected platform "linux-x86_64"
[INFO] Building for platform "linux-x86_64"
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] JavaCPP Presets .................................... SUCCESS [  0.428 s]
[INFO] JavaCPP Presets for Caffe .......................... FAILURE [02:37 min]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:38 min
[INFO] Finished at: 2017-07-22T14:38:38+02:00
[INFO] Final Memory: 26M/380M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.bytedeco:javacpp:1.2:build (javacpp.parser) on project caffe: Execution javacpp.parser of goal org.bytedeco:javacpp:1.2:build failed: sun.reflect.annotation.TypeNotPresentExceptionProxy -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.bytedeco:javacpp:1.2:build (javacpp.parser) on project caffe: Execution javacpp.parser of goal org.bytedeco:javacpp:1.2:build failed: sun.reflect.annotation.TypeNotPresentExceptionProxy
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution javacpp.parser of goal org.bytedeco:javacpp:1.2:build failed: sun.reflect.annotation.TypeNotPresentExceptionProxy
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
	... 20 more
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
	at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)
	at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531)
	at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355)
	at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
	at java.lang.Class.createAnnotationData(Class.java:3521)
	at java.lang.Class.annotationData(Class.java:3510)
	at java.lang.Class.getAnnotation(Class.java:3415)
	at java.lang.reflect.AnnotatedElement.isAnnotationPresent(AnnotatedElement.java:258)
	at java.lang.Class.isAnnotationPresent(Class.java:3425)
	at org.bytedeco.javacpp.ClassProperties.load(ClassProperties.java:134)
	at org.bytedeco.javacpp.Loader.loadProperties(Loader.java:235)
	at org.bytedeco.javacpp.tools.Builder.build(Builder.java:645)
	at org.bytedeco.javacpp.tools.BuildMojo.execute(BuildMojo.java:235)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	... 21 more

So obviously there is a class definition missing (TypeNotPresentExceptionProxy). I successfully builded a version 1.2 with CUDA8 (and no CUDNN6 hacks) before, so I assume my build environment does not cause the error.

The error message however is not very informative, can anyone give me a hint what I can do to debug/solve the problem? Thanks :)

@saudet
Copy link
Member

saudet commented Jul 22, 2017

You're using an old version of JavaCPP. Try again with JavaCPP 1.3.3-SNAPSHOT.

@sebastianlutter
Copy link

Ok.

When I look at remote branches and tags of javacpp and javacpp-preset I only find javacpp-1.3.2 and javacpp-presets-1.3. What should I checkout and build together?

@saudet
Copy link
Member

saudet commented Jul 22, 2017

@sebastianlutter
Copy link

sebastianlutter commented Jul 22, 2017

Building master (1.3.3-snapshot) on Ubuntu 16.04 x86_64

  • clean local maven jars
~$ rm -R .m2/repository/org/bytedeco
  • build and install javacpp master
git clone https://github.com/bytedeco/javacpp
cd javacpp
mvn install
  • build javacpp-presets opencv native
./cppbuild.sh install opencv
  • Patch for javacpp-presets (applied changes from patch above by hand)
diff --git a/caffe/cppbuild.sh b/caffe/cppbuild.sh
index 32444cb..704195e 100755
--- a/caffe/cppbuild.sh
+++ b/caffe/cppbuild.sh
@@ -156,7 +156,7 @@ export PATH=../bin:$PATH
 export CXXFLAGS="-I../include -I$OPENCV_PATH/include -I$HDF5_PATH/include"
 export NVCCFLAGS="-I../include -I$OPENCV_PATH/include -I$HDF5_PATH/include $CUDAFLAGS"
 export LINKFLAGS="-L../lib -L$OPENCV_PATH/lib -L$HDF5_PATH/lib"
-make -j $MAKEJ BLAS=$BLAS OPENCV_VERSION=3 DISTRIBUTE_DIR=.. lib
+make -j $MAKEJ BLAS=$BLAS OPENCV_VERSION=3 DISTRIBUTE_DIR=.. USE_CUDNN=1 lib
 # Manual deploy to avoid Caffe's python build
 mkdir -p ../include/caffe/proto
 cp -a include/caffe/* ../include/caffe/

diff --git a/caffe/pom.xml b/caffe/pom.xml
index 45675ba..73c5f79 100644
--- a/caffe/pom.xml
+++ b/caffe/pom.xml
@@ -11,7 +11,7 @@
 
   <groupId>org.bytedeco.javacpp-presets</groupId>
   <artifactId>caffe</artifactId>
-  <version>1.0-${project.parent.version}</version>
+  <version>1.0-${project.parent.version}CUDA8_CUDNN6</version>
   <name>JavaCPP Presets for Caffe</name>
 
   <properties>
@@ -21,6 +21,11 @@
   <dependencies>
     <dependency>
       <groupId>org.bytedeco.javacpp-presets</groupId>
+      <artifactId>cuda</artifactId>
+      <version>8.0-${project.parent.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.bytedeco.javacpp-presets</groupId>
       <artifactId>opencv</artifactId>
       <version>3.2.0-${project.parent.version}</version>
     </dependency>
@@ -98,6 +103,7 @@
             </property>
           </propertyKeysAndValues>
           <classPaths>
+           <classPath>${basedir}/../cuda/target/classes/</classPath>
             <classPath>${basedir}/../opencv/target/classes/</classPath>
             <classPath>${basedir}/../hdf5/target/classes/</classPath>
             <classPath>${basedir}/../openblas/target/classes/</classPath>

diff --git a/caffe/src/main/java/org/bytedeco/javacpp/presets/caffe.java b/caffe/src/main/java/org/bytedeco/javacpp/presets/caffe.java
index a0d2624..4d2444c 100644
--- a/caffe/src/main/java/org/bytedeco/javacpp/presets/caffe.java
+++ b/caffe/src/main/java/org/bytedeco/javacpp/presets/caffe.java
@@ -36,7 +36,7 @@ import org.bytedeco.javacpp.tools.InfoMapper;
  *
  * @author Samuel Audet
  */
-@Properties(inherit = {opencv_highgui.class, hdf5.class, openblas.class}, target = "org.bytedeco.javacpp.caffe", value = {
+@Properties(inherit = {opencv_highgui.class, hdf5.class, openblas.class, cudnn.class}, target = "org.bytedeco.javacpp.caffe", value = {
     @Platform(value = {"linux-x86", "macosx"}, define = {"NDEBUG", "CPU_ONLY", "SHARED_PTR_NAMESPACE boost", "USE_LEVELDB", "USE_LMDB", "USE_OPENCV"}, include = {"caffe/caffe.hpp",
         "caffe/util/device_alternate.hpp", "google/protobuf/stubs/common.h", "google/protobuf/descriptor.h", "google/protobuf/message_lite.h", "google/protobuf/message.h", "caffe/common.hpp",
         "google/protobuf/generated_message_table_driven.h", "caffe/proto/caffe.pb.h", "caffe/util/blocking_queue.hpp", /*"caffe/data_reader.hpp",*/ "caffe/util/math_functions.hpp", "caffe/syncedmem.hpp",
@@ -58,13 +58,13 @@ import org.bytedeco.javacpp.tools.InfoMapper;
         "caffe/util/db_leveldb.hpp", "caffe/util/db_lmdb.hpp", "caffe/util/io.hpp", "caffe/util/rng.hpp", "caffe/util/im2col.hpp", "caffe/util/insert_splits.hpp", "caffe/util/mkl_alternate.hpp",
         "caffe/util/upgrade_proto.hpp", "caffe/util/cudnn.hpp"}, link = "caffe@.1.0.0", resource = {"include", "lib"}, includepath = {"/usr/local/cuda/include/",
         "/System/Library/Frameworks/vecLib.framework/", "/System/Library/Frameworks/Accelerate.framework/"}, linkpath = "/usr/local/cuda/lib/"),
-    @Platform(value = {"linux-x86_64", "macosx-x86_64"}, define = {"SHARED_PTR_NAMESPACE boost", "USE_LEVELDB", "USE_LMDB", "USE_OPENCV"}) })
+    @Platform(value = {"linux-x86_64", "macosx-x86_64"}, define = {"SHARED_PTR_NAMESPACE boost", "USE_LEVELDB", "USE_LMDB", "USE_OPENCV", "USE_CUDNN"}) })
 public class caffe implements InfoMapper {
     public void map(InfoMap infoMap) {
         infoMap.put(new Info("LIBPROTOBUF_EXPORT", "LIBPROTOC_EXPORT", "GOOGLE_PROTOBUF_VERIFY_VERSION", "GOOGLE_ATTRIBUTE_ALWAYS_INLINE", "GOOGLE_ATTRIBUTE_DEPRECATED",
                              "GOOGLE_DLOG", "NOT_IMPLEMENTED", "NO_GPU", "CUDA_POST_KERNEL_CHECK", "PROTOBUF_CONSTEXPR", "PROTOBUF_CONSTEXPR_VAR").cppTypes().annotations())
                .put(new Info("NDEBUG", "CPU_ONLY", "GFLAGS_GFLAGS_H_", "SWIG").define())
-               .put(new Info("USE_CUDNN", "defined(_WIN32) && defined(GetMessage)", "LANG_CXX11").define(false))
+               .put(new Info("USE_CUDNN", "defined(_WIN32) && defined(GetMessage)", "LANG_CXX11").define())
                .put(new Info("cublasHandle_t", "curandGenerator_t").cast().valueTypes("Pointer"))
                .put(new Info("CBLAS_TRANSPOSE", "cublasStatus_t", "curandStatus_t", "hid_t").cast().valueTypes("int"))
                .put(new Info("std::string").annotations("@StdString").valueTypes("BytePointer", "String").pointerTypes("@Cast({\"char*\", \"std::string*\"}) BytePointer"))
@@ -123,7 +123,7 @@ public class caffe implements InfoMapper {
                 "SilenceLayer", "SoftmaxLayer", "SplitLayer", "SliceLayer", "TileLayer", "Net", "Solver", "WorkerSolver", "SolverRegistry", "SolverRegisterer", "SGDSolver", "NesterovSolver",
                 "AdaGradSolver", "RMSPropSolver", "AdaDeltaSolver", "AdamSolver",  "InputLayer", "ParameterLayer", "BaseConvolutionLayer", "ConvolutionLayer", "CropLayer", "DeconvolutionLayer",
                 "Im2colLayer", "LRNLayer", "PoolingLayer", "SPPLayer", "RecurrentLayer", "LSTMLayer", "RNNLayer"
-                /* "CuDNNReLULayer", "CuDNNSigmoidLayer", "CuDNNTanHLayer", "CuDNNSoftmaxLayer", "CuDNNConvolutionLayer", "CuDNNPoolingLayer" */ };
+               , "CuDNNReLULayer", "CuDNNSigmoidLayer", "CuDNNTanHLayer", "CuDNNSoftmaxLayer", "CuDNNConvolutionLayer", "CuDNNPoolingLayer" };
         for (String t : classTemplates) {
             boolean purify = t.equals("BaseDataLayer") || t.equals("LossLayer") || t.equals("NeuronLayer");
             boolean virtualize = t.endsWith("Layer") || t.endsWith("Solver");
  • build javacpp-presets caffe natives
javacpp-presets-tmpfs$ ./cppbuild.sh install caffe
  • Failed with error of missing caffe.pb.h
[ ... ]
patching file include/caffe/util/device_alternate.hpp
PROTOC src/caffe/proto/caffe.proto
CXX src/caffe/util/upgrade_proto.cpp
CXX src/caffe/util/signal_handler.cpp
CXX src/caffe/util/math_functions.cpp
In file included from src/caffe/util/signal_handler.cpp:7:0:
./include/caffe/util/signal_handler.h:4:34: fatal error: caffe/proto/caffe.pb.h: Datei oder Verzeichnis nicht gefunden
compilation terminated.
Makefile:581: die Regel für Ziel „.build_release/src/caffe/util/signal_handler.o“ scheiterte
make: *** [.build_release/src/caffe/util/signal_handler.o] Fehler 1
make: *** Auf noch nicht beendete Prozesse wird gewartet …
In file included from ./include/caffe/util/device_alternate.hpp:40:0,
                 from ./include/caffe/common.hpp:19,
                 from src/caffe/util/upgrade_proto.cpp:8:
./include/caffe/util/cudnn.hpp:8:34: fatal error: caffe/proto/caffe.pb.h: Datei oder Verzeichnis nicht gefunden
compilation terminated.
Makefile:581: die Regel für Ziel „.build_release/src/caffe/util/upgrade_proto.o“ scheiterte
make: *** [.build_release/src/caffe/util/upgrade_proto.o] Fehler 1
  • Fixed it by manually create protobuf file
$ cd caffe/cppbuild/linux-x86_64/caffe-1.0/src
$ protoc caffe/proto/caffe.proto --cpp_out=../include/
  • Continue javacpp-presets caffe native build
javacpp-presets-tmpfs$ ./cppbuild.sh install caffe
  • Failed with hdf5 error
[ ... ]
patching file include/caffe/util/device_alternate.hpp
CXX .build_release/src/caffe/proto/caffe.pb.cc
CXX src/caffe/syncedmem.cpp
CXX src/caffe/solver.cpp
CXX src/caffe/parallel.cpp
CXX src/caffe/net.cpp
src/caffe/net.cpp:8:18: fatal error: hdf5.h: Datei oder Verzeichnis nicht gefunden
compilation terminated.
Makefile:581: die Regel für Ziel „.build_release/src/caffe/net.o“ scheiterte
make: *** [.build_release/src/caffe/net.o] Fehler 1
make: *** Auf noch nicht beendete Prozesse wird gewartet …
In file included from src/caffe/solver.cpp:8:0:
./include/caffe/util/hdf5.hpp:6:18: fatal error: hdf5.h: Datei oder Verzeichnis nicht gefunden
compilation terminated.
Makefile:581: die Regel für Ziel „.build_release/src/caffe/solver.o“ scheiterte
make: *** [.build_release/src/caffe/solver.o] Fehler 1
  • The hdf5.h is available on my ubuntu 16.04
gpuslave@gpuslave:~/workspace/javacpp/javacpp-presets-tmpfs$ dpkg -l | grep libhdf5-dev
ii  libhdf5-dev                                 1.8.16+docs-4ubuntu1                           amd64        Hierarchical Data Format 5 (HDF5) - development files - serial version
gpuslave@gpuslave:~/workspace/javacpp/javacpp-presets-tmpfs$ dpkg -L libhdf5-dev  | egrep "hdf5.h$"
/usr/include/hdf5/serial/hdf5.h
  • The include folder seems to be wrong (hdf5.h instead of hdf5/serial/hdf5.h) on ubuntu
  • Patched cppbuild.sh to add include and library path as needed into caffe Makefile.config
diff --git a/caffe/cppbuild.sh b/caffe/cppbuild.sh
index 32444cb..6a1d6dd 100755
--- a/caffe/cppbuild.sh
+++ b/caffe/cppbuild.sh
@@ -152,11 +152,13 @@ export LIBRARY_PATH="$OPENBLAS_PATH/lib/"
 cd caffe-$CAFFE_VERSION
 patch -Np1 < ../../../caffe-nogpu.patch
 cp Makefile.config.example Makefile.config
+sed -i "s|\(INCLUDE_DIRS.*/usr/local/include\)|\1 /usr/include/hdf5/serial/|" $INSTALL_PATH/caffe-$CAFFE_VERSION/Makefile.config
+sed -i "s|\(LIBRARY_DIRS.*/usr/lib\)|\1  /usr/lib/x86_64-linux-gnu/hdf5/serial/|" $INSTALL_PATH/caffe-$CAFFE_VERSION/Makefile.config
 export PATH=../bin:$PATH
 export CXXFLAGS="-I../include -I$OPENCV_PATH/include -I$HDF5_PATH/include"
 export NVCCFLAGS="-I../include -I$OPENCV_PATH/include -I$HDF5_PATH/include $CUDAFLAGS"
 export LINKFLAGS="-L../lib -L$OPENCV_PATH/lib -L$HDF5_PATH/lib"
-make -j $MAKEJ BLAS=$BLAS OPENCV_VERSION=3 DISTRIBUTE_DIR=.. lib
+make -j $MAKEJ BLAS=$BLAS OPENCV_VERSION=3 DISTRIBUTE_DIR=.. USE_CUDNN=1 lib
 # Manual deploy to avoid Caffe's python build
 mkdir -p ../include/caffe/proto
 cp -a include/caffe/* ../include/caffe/
  • start caffe native build again and it finished successfully
javacpp-presets-tmpfs$ ./cppbuild.sh install caffe
  • Build and install javacpp-preset artifacts
gpuslave@gpuslave:~/workspace/javacpp/javacpp-presets-tmpfs$ mvn install --projects .,opencv,caffe
[ ... ]
855-391.jar (116 KB at 109.7 KB/sec)
Downloaded: https://oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp-presets/hdf5/1.10.1-1.3.3-SNAPSHOT/hdf5-1.10.1-1.3.3-20170720.134900-153.jar (170 KB at 150.1 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] JavaCPP Presets .................................... SUCCESS [  0.474 s]
[INFO] JavaCPP Presets for OpenCV ......................... SUCCESS [04:59 min]
[INFO] JavaCPP Presets for Caffe .......................... FAILURE [  3.503 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:03 min
[INFO] Finished at: 2017-07-22T16:23:00+02:00
[INFO] Final Memory: 56M/1375M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project caffe: Could not resolve dependencies for project org.bytedeco.javacpp-presets:caffe:jar:1.0-1.3.3-SNAPSHOTCUDA8_CUDNN6: Could not find artifact org.bytedeco.javacpp-presets:cuda:jar:8.0-1.3.3-SNAPSHOT in sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :caffe
  • Modify caffe/pom.xml to set fixed cuda dependency version 8.0-1.3
diff --git a/caffe/pom.xml b/caffe/pom.xml
index 45675ba..40a2dfb 100644
--- a/caffe/pom.xml
+++ b/caffe/pom.xml
@@ -11,7 +11,7 @@
 
   <groupId>org.bytedeco.javacpp-presets</groupId>
   <artifactId>caffe</artifactId>
-  <version>1.0-${project.parent.version}</version>
+  <version>1.0-${project.parent.version}CUDA8_CUDNN6</version>
   <name>JavaCPP Presets for Caffe</name>
 
   <properties>
@@ -21,6 +21,11 @@
   <dependencies>
     <dependency>
       <groupId>org.bytedeco.javacpp-presets</groupId>
+      <artifactId>cuda</artifactId>
+      <version>8.0-1.3</version>
+    </dependency>
+    <dependency>
+      <groupId>org.bytedeco.javacpp-presets</groupId>
       <artifactId>opencv</artifactId>
       <version>3.2.0-${project.parent.version}</version>
     </dependency>
@@ -98,6 +103,7 @@
             </property>
           </propertyKeysAndValues>
           <classPaths>
+           <classPath>${basedir}/../cuda/target/classes/</classPath>
             <classPath>${basedir}/../opencv/target/classes/</classPath>
             <classPath>${basedir}/../hdf5/target/classes/</classPath>
             <classPath>${basedir}/../openblas/target/classes/</classPath>
  • Retry to build and install artifacts, but failes again
javacpp-presets-tmpfs$ mvn install  --projects .,opencv,caffe -e -X
[ ... ]
[INFO] Detected platform "linux-x86_64"
[INFO] Building for platform "linux-x86_64"
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] JavaCPP Presets .................................... SUCCESS [  0.441 s]
[INFO] JavaCPP Presets for OpenCV ......................... SUCCESS [05:00 min]
[INFO] JavaCPP Presets for Caffe .......................... FAILURE [02:47 min]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 07:48 min
[INFO] Finished at: 2017-07-22T16:50:26+02:00
[INFO] Final Memory: 52M/1264M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.bytedeco:javacpp:1.3.3-SNAPSHOT:build (javacpp.parser) on project caffe: Execution javacpp.parser of goal org.bytedeco:javacpp:1.3.3-SNAPSHOT:build failed: sun.reflect.annotation.TypeNotPresentExceptionProxy -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.bytedeco:javacpp:1.3.3-SNAPSHOT:build (javacpp.parser) on project caffe: Execution javacpp.parser of goal org.bytedeco:javacpp:1.3.3-SNAPSHOT:build failed: sun.reflect.annotation.TypeNotPresentExceptionProxy
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution javacpp.parser of goal org.bytedeco:javacpp:1.3.3-SNAPSHOT:build failed: sun.reflect.annotation.TypeNotPresentExceptionProxy
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
	... 20 more
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
	at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)
	at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531)
	at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355)
	at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
	at java.lang.Class.createAnnotationData(Class.java:3521)
	at java.lang.Class.annotationData(Class.java:3510)
	at java.lang.Class.getAnnotation(Class.java:3415)
	at java.lang.reflect.AnnotatedElement.isAnnotationPresent(AnnotatedElement.java:258)
	at java.lang.Class.isAnnotationPresent(Class.java:3425)
	at org.bytedeco.javacpp.ClassProperties.load(ClassProperties.java:135)
	at org.bytedeco.javacpp.Loader.loadProperties(Loader.java:253)
	at org.bytedeco.javacpp.tools.Builder.build(Builder.java:757)
	at org.bytedeco.javacpp.tools.BuildMojo.execute(BuildMojo.java:334)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	... 21 more

A equal looking error as for 1.2 :(

Any idea what I can try next?

@sebastianlutter
Copy link

Missed to build javacpp-presets cuda

  • Instead of modify the cuda version to 8.0-1.3 I now build and installed it so I get a cuda 8.0-6.0-1.3.3-SNAPSHOT

  • But again ended up with an error (see below)

  • In short I did the following steps (javacpp-presets master):

./cppbuild.sh install opencv
./cppbuild.sh install cuda
./cppbuild.sh install caffe
mvn -U install --projects .,cuda
mvn -U install --projects .,opencv,caffe
  • These are the diffs to git master of the files I changed
diff --git a/caffe/cppbuild.sh b/caffe/cppbuild.sh
index 32444cb..6a1d6dd 100755
--- a/caffe/cppbuild.sh
+++ b/caffe/cppbuild.sh
@@ -152,11 +152,13 @@ export LIBRARY_PATH="$OPENBLAS_PATH/lib/"
 cd caffe-$CAFFE_VERSION
 patch -Np1 < ../../../caffe-nogpu.patch
 cp Makefile.config.example Makefile.config
+sed -i "s|\(INCLUDE_DIRS.*/usr/local/include\)|\1 /usr/include/hdf5/serial/|" $INSTALL_PATH/caffe-$CAFFE_VERSION/Makefile.config
+sed -i "s|\(LIBRARY_DIRS.*/usr/lib\)|\1  /usr/lib/x86_64-linux-gnu/hdf5/serial/|" $INSTALL_PATH/caffe-$CAFFE_VERSION/Makefile.config
 export PATH=../bin:$PATH
 export CXXFLAGS="-I../include -I$OPENCV_PATH/include -I$HDF5_PATH/include"
 export NVCCFLAGS="-I../include -I$OPENCV_PATH/include -I$HDF5_PATH/include $CUDAFLAGS"
 export LINKFLAGS="-L../lib -L$OPENCV_PATH/lib -L$HDF5_PATH/lib"
-make -j $MAKEJ BLAS=$BLAS OPENCV_VERSION=3 DISTRIBUTE_DIR=.. lib
+make -j $MAKEJ BLAS=$BLAS OPENCV_VERSION=3 DISTRIBUTE_DIR=.. USE_CUDNN=1 lib
 # Manual deploy to avoid Caffe's python build
 mkdir -p ../include/caffe/proto
 cp -a include/caffe/* ../include/caffe/

diff --git a/caffe/pom.xml b/caffe/pom.xml
index 45675ba..1587b94 100644
--- a/caffe/pom.xml
+++ b/caffe/pom.xml
@@ -11,7 +11,7 @@
 
   <groupId>org.bytedeco.javacpp-presets</groupId>
   <artifactId>caffe</artifactId>
-  <version>1.0-${project.parent.version}</version>
+  <version>1.0-${project.parent.version}CUDA8_CUDNN6</version>
   <name>JavaCPP Presets for Caffe</name>
 
   <properties>
@@ -21,6 +21,11 @@
   <dependencies>
     <dependency>
       <groupId>org.bytedeco.javacpp-presets</groupId>
+      <artifactId>cuda</artifactId>
+      <version>8.0-6.0-${project.parent.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.bytedeco.javacpp-presets</groupId>
       <artifactId>opencv</artifactId>
       <version>3.2.0-${project.parent.version}</version>
     </dependency>
@@ -98,6 +103,7 @@
             </property>
           </propertyKeysAndValues>
           <classPaths>
+           <classPath>${basedir}/../cuda/target/classes/</classPath>
             <classPath>${basedir}/../opencv/target/classes/</classPath>
             <classPath>${basedir}/../hdf5/target/classes/</classPath>
             <classPath>${basedir}/../openblas/target/classes/</classPath>

diff --git a/caffe/src/main/java/org/bytedeco/javacpp/presets/caffe.java b/caffe/src/main/java/org/bytedeco/javacpp/presets/caffe.java
index a0d2624..888dfd4 100644
--- a/caffe/src/main/java/org/bytedeco/javacpp/presets/caffe.java
+++ b/caffe/src/main/java/org/bytedeco/javacpp/presets/caffe.java
@@ -36,7 +36,7 @@ import org.bytedeco.javacpp.tools.InfoMapper;
  *
  * @author Samuel Audet
  */
-@Properties(inherit = {opencv_highgui.class, hdf5.class, openblas.class}, target = "org.bytedeco.javacpp.caffe", value = {
+@Properties(inherit = {opencv_highgui.class, hdf5.class, openblas.class, cudnn.class}, target = "org.bytedeco.javacpp.caffe", value = {
     @Platform(value = {"linux-x86", "macosx"}, define = {"NDEBUG", "CPU_ONLY", "SHARED_PTR_NAMESPACE boost", "USE_LEVELDB", "USE_LMDB", "USE_OPENCV"}, include = {"caffe/caffe.hpp",
         "caffe/util/device_alternate.hpp", "google/protobuf/stubs/common.h", "google/protobuf/descriptor.h", "google/protobuf/message_lite.h", "google/protobuf/message.h", "caffe/common.hpp",
         "google/protobuf/generated_message_table_driven.h", "caffe/proto/caffe.pb.h", "caffe/util/blocking_queue.hpp", /*"caffe/data_reader.hpp",*/ "caffe/util/math_functions.hpp", "caffe/syncedmem.hpp",
@@ -58,13 +58,13 @@ import org.bytedeco.javacpp.tools.InfoMapper;
         "caffe/util/db_leveldb.hpp", "caffe/util/db_lmdb.hpp", "caffe/util/io.hpp", "caffe/util/rng.hpp", "caffe/util/im2col.hpp", "caffe/util/insert_splits.hpp", "caffe/util/mkl_alternate.hpp",
         "caffe/util/upgrade_proto.hpp", "caffe/util/cudnn.hpp"}, link = "caffe@.1.0.0", resource = {"include", "lib"}, includepath = {"/usr/local/cuda/include/",
         "/System/Library/Frameworks/vecLib.framework/", "/System/Library/Frameworks/Accelerate.framework/"}, linkpath = "/usr/local/cuda/lib/"),
-    @Platform(value = {"linux-x86_64", "macosx-x86_64"}, define = {"SHARED_PTR_NAMESPACE boost", "USE_LEVELDB", "USE_LMDB", "USE_OPENCV"}) })
+    @Platform(value = {"linux-x86_64", "macosx-x86_64"}, define = {"SHARED_PTR_NAMESPACE boost", "USE_LEVELDB", "USE_LMDB", "USE_OPENCV", "USE_CUDNN"}) })
 public class caffe implements InfoMapper {
     public void map(InfoMap infoMap) {
         infoMap.put(new Info("LIBPROTOBUF_EXPORT", "LIBPROTOC_EXPORT", "GOOGLE_PROTOBUF_VERIFY_VERSION", "GOOGLE_ATTRIBUTE_ALWAYS_INLINE", "GOOGLE_ATTRIBUTE_DEPRECATED",
                              "GOOGLE_DLOG", "NOT_IMPLEMENTED", "NO_GPU", "CUDA_POST_KERNEL_CHECK", "PROTOBUF_CONSTEXPR", "PROTOBUF_CONSTEXPR_VAR").cppTypes().annotations())
                .put(new Info("NDEBUG", "CPU_ONLY", "GFLAGS_GFLAGS_H_", "SWIG").define())
-               .put(new Info("USE_CUDNN", "defined(_WIN32) && defined(GetMessage)", "LANG_CXX11").define(false))
+               .put(new Info("USE_CUDNN", "defined(_WIN32) && defined(GetMessage)", "LANG_CXX11").define())
                .put(new Info("cublasHandle_t", "curandGenerator_t").cast().valueTypes("Pointer"))
                .put(new Info("CBLAS_TRANSPOSE", "cublasStatus_t", "curandStatus_t", "hid_t").cast().valueTypes("int"))
                .put(new Info("std::string").annotations("@StdString").valueTypes("BytePointer", "String").pointerTypes("@Cast({\"char*\", \"std::string*\"}) BytePointer"))
@@ -123,7 +123,7 @@ public class caffe implements InfoMapper {
                 "SilenceLayer", "SoftmaxLayer", "SplitLayer", "SliceLayer", "TileLayer", "Net", "Solver", "WorkerSolver", "SolverRegistry", "SolverRegisterer", "SGDSolver", "NesterovSolver",
                 "AdaGradSolver", "RMSPropSolver", "AdaDeltaSolver", "AdamSolver",  "InputLayer", "ParameterLayer", "BaseConvolutionLayer", "ConvolutionLayer", "CropLayer", "DeconvolutionLayer",
                 "Im2colLayer", "LRNLayer", "PoolingLayer", "SPPLayer", "RecurrentLayer", "LSTMLayer", "RNNLayer"
-                /* "CuDNNReLULayer", "CuDNNSigmoidLayer", "CuDNNTanHLayer", "CuDNNSoftmaxLayer", "CuDNNConvolutionLayer", "CuDNNPoolingLayer" */ };
+                ,"CuDNNReLULayer", "CuDNNSigmoidLayer", "CuDNNTanHLayer", "CuDNNSoftmaxLayer", "CuDNNConvolutionLayer", "CuDNNPoolingLayer" };
         for (String t : classTemplates) {
             boolean purify = t.equals("BaseDataLayer") || t.equals("LossLayer") || t.equals("NeuronLayer");
             boolean virtualize = t.endsWith("Layer") || t.endsWith("Solver");
  • I get the following error when building and install the artifacts
javacpp-presets-tmpfs$ mvn install --projects .,caffe -X -e
[ . . . ]
[INFO] Parsing /usr/local/cuda-8.0/targets/x86_64-linux/include/cuda.h
[INFO] Parsing /usr/local/cuda-8.0/targets/x86_64-linux/include/host_defines.h
[INFO] Parsing /usr/local/cuda-8.0/targets/x86_64-linux/include/device_types.h
[INFO] Parsing /usr/local/cuda-8.0/targets/x86_64-linux/include/driver_types.h
[INFO] Parsing /usr/local/cuda-8.0/targets/x86_64-linux/include/surface_types.h
[INFO] Parsing /usr/local/cuda-8.0/targets/x86_64-linux/include/texture_types.h
[INFO] Parsing /usr/local/cuda-8.0/targets/x86_64-linux/include/vector_types.h
[INFO] Parsing /usr/local/cuda-8.0/targets/x86_64-linux/include/builtin_types.h
[INFO] Parsing /usr/local/cuda-8.0/targets/x86_64-linux/include/cuda_runtime_api.h
[INFO] Parsing /usr/local/cuda-8.0/targets/x86_64-linux/include/driver_functions.h
[INFO] Parsing /usr/local/cuda-8.0/targets/x86_64-linux/include/vector_functions.h
[INFO] Parsing /usr/local/cuda-8.0/targets/x86_64-linux/include/cuComplex.h
[INFO] Parsing /usr/local/cuda-8.0/targets/x86_64-linux/include/cuda_fp16.h
[INFO] Parsing /usr/local/cuda-8.0/targets/x86_64-linux/include/library_types.h
[INFO] Parsing /usr/local/cuda-8.0/targets/x86_64-linux/include/cudnn.h
[INFO] Parsing /home/gpuslave/workspace/javacpp/javacpp-presets-tmpfs/caffe/cppbuild/linux-x86_64/include/caffe/caffe.hpp
[INFO] Parsing /home/gpuslave/workspace/javacpp/javacpp-presets-tmpfs/caffe/cppbuild/linux-x86_64/include/caffe/util/device_alternate.hpp
[INFO] Parsing /home/gpuslave/workspace/javacpp/javacpp-presets-tmpfs/caffe/cppbuild/linux-x86_64/include/google/protobuf/stubs/common.h
[INFO] Parsing /home/gpuslave/workspace/javacpp/javacpp-presets-tmpfs/caffe/cppbuild/linux-x86_64/include/google/protobuf/descriptor.h
[INFO] Parsing /home/gpuslave/workspace/javacpp/javacpp-presets-tmpfs/caffe/cppbuild/linux-x86_64/include/google/protobuf/message_lite.h
[INFO] Parsing /home/gpuslave/workspace/javacpp/javacpp-presets-tmpfs/caffe/cppbuild/linux-x86_64/include/google/protobuf/message.h
[INFO] Parsing /home/gpuslave/workspace/javacpp/javacpp-presets-tmpfs/caffe/cppbuild/linux-x86_64/include/caffe/common.hpp
[INFO] Parsing /home/gpuslave/workspace/javacpp/javacpp-presets-tmpfs/caffe/cppbuild/linux-x86_64/include/google/protobuf/generated_message_table_driven.h
[ERROR] Failed to execute JavaCPP Builder: null:0: Unexpected token 'EOF'
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] JavaCPP Presets .................................... SUCCESS [  0.450 s]
[INFO] JavaCPP Presets for Caffe .......................... FAILURE [03:34 min]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:35 min
[INFO] Finished at: 2017-07-22T19:01:27+02:00
[INFO] Final Memory: 35M/824M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.bytedeco:javacpp:1.3.3-SNAPSHOT:build (javacpp.parser) on project caffe: Failed to execute JavaCPP Builder: null:0: Unexpected token 'EOF' -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.bytedeco:javacpp:1.3.3-SNAPSHOT:build (javacpp.parser) on project caffe: Failed to execute JavaCPP Builder
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to execute JavaCPP Builder
	at org.bytedeco.javacpp.tools.BuildMojo.execute(BuildMojo.java:340)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
	... 20 more
Caused by: org.bytedeco.javacpp.tools.ParserException: null:0: Unexpected token 'EOF'
	at org.bytedeco.javacpp.tools.Token.expect(Token.java:106)
	at org.bytedeco.javacpp.tools.Parser.parameters(Parser.java:1569)
	at org.bytedeco.javacpp.tools.Parser.function(Parser.java:1590)
	at org.bytedeco.javacpp.tools.Parser.declarations(Parser.java:2923)
	at org.bytedeco.javacpp.tools.Parser.namespace(Parser.java:2825)
	at org.bytedeco.javacpp.tools.Parser.declarations(Parser.java:2921)
	at org.bytedeco.javacpp.tools.Parser.namespace(Parser.java:2825)
	at org.bytedeco.javacpp.tools.Parser.declarations(Parser.java:2921)
	at org.bytedeco.javacpp.tools.Parser.namespace(Parser.java:2825)
	at org.bytedeco.javacpp.tools.Parser.declarations(Parser.java:2921)
	at org.bytedeco.javacpp.tools.Parser.parse(Parser.java:3004)
	at org.bytedeco.javacpp.tools.Parser.parse(Parser.java:3114)
	at org.bytedeco.javacpp.tools.Builder.parse(Builder.java:80)
	at org.bytedeco.javacpp.tools.Builder.build(Builder.java:764)
	at org.bytedeco.javacpp.tools.BuildMojo.execute(BuildMojo.java:334)
	... 22 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :caffe

@saudet
Copy link
Member

saudet commented Jul 22, 2017 via email

@saudet
Copy link
Member

saudet commented Jul 23, 2017

Since pretty much everything should be faster with cuDNN these days, I've enabled cuDNN in the default build as per the commit above. We'll be getting SNAPSHOT binaries from Travis CI shortly so please just use those: https://travis-ci.org/bytedeco/javacpp-presets/builds/256539390 Enjoy!

@sebastianlutter
Copy link

With your commit it now works on Ubuntu 16.04 x86_64 as well.

Only one change is needed to let caffe build with hdf5

diff --git a/caffe/cppbuild.sh b/caffe/cppbuild.sh
index 88ea463..8352004 100755
--- a/caffe/cppbuild.sh
+++ b/caffe/cppbuild.sh
@@ -155,6 +155,8 @@ export LIBRARY_PATH="$OPENBLAS_PATH/lib/"
 cd caffe-$CAFFE_VERSION
 patch -Np1 < ../../../caffe-nogpu.patch
 cp Makefile.config.example Makefile.config
+sed -i "s|\(INCLUDE_DIRS.*/usr/local/include\)|\1 /usr/include/hdf5/serial/|" $INSTALL_PATH/caffe-$CAFFE_VERSION/Makefile.config
+sed -i "s|\(LIBRARY_DIRS.*/usr/lib\)|\1  /usr/lib/x86_64-linux-gnu/hdf5/serial/|" $INSTALL_PATH/caffe-$CAFFE_VERSION/Makefile.config
 export PATH=../bin:$PATH
 export CXXFLAGS="-I../include -I$OPENCV_PATH/include -I$HDF5_PATH/include"
 export NVCCFLAGS="-I../include -I$OPENCV_PATH/include -I$HDF5_PATH/include $CUDAFLAGS"

So, thanks a lot for your help :)

Btw: I also tried the centOS7 build environment, but found it not easier to get all needed dependencies (i.e. hdf5, glog, lmdb etc) up and running in my docker container. However, before reporting the next issue I'll try the centOS build as well.

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

No branches or pull requests

4 participants