|
1 |
| -# Building and contributing to TensorFlow Java |
| 1 | +# Building and Contributing to TensorFlow Java |
2 | 2 |
|
3 | 3 | ## Building
|
4 | 4 |
|
5 |
| -To build all the artifacts, simply invoke the command `mvn install` at the root of this repository (or |
6 |
| -the Maven command of your choice). It is also possible to build artifacts with support for MKL enabled with |
| 5 | +To build all the artifacts, simply invoke the command `mvn install` at the root of this repository (or the Maven command of your choice). It is also |
| 6 | +possible to build artifacts with support for MKL enabled with |
7 | 7 | `mvn install -Djavacpp.platform.extension=-mkl` or CUDA with `mvn install -Djavacpp.platform.extension=-gpu`
|
8 | 8 | or both with `mvn install -Djavacpp.platform.extension=-mkl-gpu`.
|
9 | 9 |
|
10 | 10 | When building this project for the first time in a given workspace, the script will attempt to download
|
11 |
| -the [TensorFlow runtime library sources](https://github.com/tensorflow/tensorflow) and build of all the native code |
12 |
| -for your platform. This requires a valid environment for building TensorFlow, including the [bazel](https://bazel.build/) |
| 11 | +the [TensorFlow runtime library sources](https://github.com/tensorflow/tensorflow) and build of all the native code for your platform. This requires a |
| 12 | +valid environment for building TensorFlow, including the [bazel](https://bazel.build/) |
13 | 13 | build tool and a few Python dependencies (please read [TensorFlow documentation](https://www.tensorflow.org/install/source)
|
14 | 14 | for more details).
|
15 | 15 |
|
16 |
| -This step can take multiple hours on a regular laptop. It is possible though to skip completely the native build if you are |
17 |
| -working on a version that already has pre-compiled native artifacts for your platform [available on Sonatype OSS Nexus repository](#Snapshots). |
18 |
| -You just need to activate the `dev` profile in your Maven command to use those artifacts instead of building them from scratch |
| 16 | +This step can take multiple hours on a regular laptop. It is possible though to skip completely the native build if you are working on a version that |
| 17 | +already has pre-compiled native artifacts for your platform [available on Sonatype OSS Nexus repository](#Snapshots). You just need to activate |
| 18 | +the `dev` profile in your Maven command to use those artifacts instead of building them from scratch |
19 | 19 | (e.g. `mvn install -Pdev`).
|
20 | 20 |
|
21 |
| -Note that modifying any source files under `tensorflow-core` may impact the low-level TensorFlow bindings, in which case a |
22 |
| -complete build could be required to reflect the changes. |
| 21 | +Modifying the native op generation code (not the annotation processor) or the JavaCPP configuration (not the abstract Pointers) will require a |
| 22 | +complete build could be required to reflect the changes, otherwise `-Pdev` should be fine. |
23 | 23 |
|
| 24 | +### GPU Support |
| 25 | + |
| 26 | +Currently, due to build time constraints, the GPU binaries only support compute capacities 3.5 and 7.0. |
| 27 | +To use with un-supported GPUs, change the value [here](tensorflow-core/tensorflow-core-api/build.sh#L27) and build the binaries yourself. While this |
| 28 | +is far from ideal, we are working on getting more build resources, and for now this is the best option. |
| 29 | + |
| 30 | +To build for GPU, pass `-Djavacpp.platform.extension=-gpu` to maven. By default, the CI options are used for the bazel build. |
| 31 | +Using Tensorflow's configure script and copying the resulting `.tf_configure.bazelrc` to `tensorflow-core-api` can be used to override these options ( |
| 32 | +like cuda locations). See the [Working with Bazel generation](#working-with-bazel-generation) section for details. If you do this, make sure |
| 33 | +the `TF_CUDA_COMPUTE_CAPABILITIES` value in your `.tf_configure.bazelrc` matches the value set in `build.sh`. |
24 | 34 |
|
25 | 35 | ## Running Tests
|
26 | 36 |
|
27 |
| -`ndarray` can be tested using the maven `test` target. `tensorflow-core` and `tensorflow-framework`, however, |
28 |
| -should be tested using the `integration-test` target, due to the need to include native binaries. |
29 |
| -It will **not** be ran when using the `test` target of parent projects, but will be ran by `install` or `integration-test`. |
| 37 | +`ndarray` can be tested using the maven `test` target. `tensorflow-core` and `tensorflow-framework`, however, should be tested using |
| 38 | +the `integration-test` target, due to the need to include native binaries. It will **not** be ran when using the `test` target of parent projects, but |
| 39 | +will be ran by `install` or `integration-test`. If you see a `no jnitensorflow in java.library.path` error from tests it is likely because you're |
| 40 | +running the wrong test target. |
| 41 | + |
| 42 | +### Native Crashes |
| 43 | + |
| 44 | +Occasionally tests will fail with a message like: |
| 45 | + |
| 46 | +``` |
| 47 | +Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.0:test(default-test)on project tensorflow-core-api:There are test failures. |
| 48 | +
|
| 49 | + Please refer to C:\mpicbg\workspace\tensorflow\java\tensorflow-core\tensorflow-core-api\target\surefire-reports for the individual test results. |
| 50 | + Please refer to dump files(if any exist)[date]-jvmRun[N].dump,[date].dumpstream and[date]-jvmRun[N].dumpstream. |
| 51 | + The forked VM terminated without properly saying goodbye.VM crash or System.exit called? |
| 52 | + Command was cmd.exe/X/C"C:\Users\me\.jdks\adopt-openj9-1.8.0_275\jre\bin\java -jar C:\Users\me\AppData\Local\Temp\surefire236563113746082396\surefirebooter5751859365434514212.jar C:\Users\me\AppData\Local\Temp\surefire236563113746082396 2020-12-18T13-57-26_766-jvmRun1 surefire2445852067572510918tmp surefire_05950149004635894208tmp" |
| 53 | + Error occurred in starting fork,check output in log |
| 54 | + Process Exit Code:-1 |
| 55 | + Crashed tests: |
| 56 | + org.tensorflow.TensorFlowTest |
| 57 | + org.apache.maven.surefire.booter.SurefireBooterForkException:The forked VM terminated without properly saying goodbye.VM crash or System.exit called? |
| 58 | + Command was cmd.exe/X/C"C:\Users\me\.jdks\adopt-openj9-1.8.0_275\jre\bin\java -jar C:\Users\me\AppData\Local\Temp\surefire236563113746082396\surefirebooter5751859365434514212.jar C:\Users\me\AppData\Local\Temp\surefire236563113746082396 2020-12-18T13-57-26_766-jvmRun1 surefire2445852067572510918tmp surefire_05950149004635894208tmp" |
| 59 | + Error occurred in starting fork,check output in log |
| 60 | + Process Exit Code:-1 |
| 61 | + Crashed tests: |
| 62 | + org.tensorflow.TensorFlowTest |
| 63 | + at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:671) |
| 64 | + at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:533) |
| 65 | + at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:278) |
| 66 | + at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:244) |
| 67 | +``` |
| 68 | + |
| 69 | +This is because the native code crashed (i.e. because of a segfault), and it should have created a dump file somewhere in the project that you can use |
| 70 | +to tell what caused the issue. |
30 | 71 |
|
31 | 72 | ## Contributing
|
32 | 73 |
|
33 | 74 | ### Formatting
|
34 | 75 |
|
35 |
| -Java sources should be formatted according to the [Google style guide](https://google.github.io/styleguide/javaguide.html). |
36 |
| -It can be included in [IntelliJ](https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml) and |
| 76 | +Java sources should be formatted according to the [Google style guide](https://google.github.io/styleguide/javaguide.html). It can be included |
| 77 | +in [IntelliJ](https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml) and |
37 | 78 | [Eclipse](https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml).
|
38 | 79 | [Google's C++ style guide](https://google.github.io/styleguide/cppguide.html) should also be used for C++ code.
|
39 | 80 |
|
40 | 81 | ### Code generation
|
41 | 82 |
|
42 |
| -Code generation for `Ops` and related classes is done during `tensorflow-core-api`'s `install`, using the annotation processor in |
43 |
| -`tensorflow-core-generator`. If you change or add any operator classes (annotated with `org.tensorflow.op.annotation.Operator`), |
44 |
| -endpoint methods (annotated with `org.tensorflow.op.annotation.Endpoint`), or change the annotation processor, be sure to re-run a |
45 |
| -full `mvn install` in `tensorflow-core-api`. |
| 83 | +Code generation for `Ops` and related classes is done during `tensorflow-core-api`'s `compile` phase, using the annotation processor in |
| 84 | +`tensorflow-core-generator`. If you change or add any operator classes (annotated with `org.tensorflow.op.annotation.Operator`), endpoint methods ( |
| 85 | +annotated with `org.tensorflow.op.annotation.Endpoint`), or change the annotation processor, be sure to re-run a |
| 86 | +`mvn install` in `tensorflow-core-api` (`-Pdev` is fine for this, it just needs to run the annotation processor). |
46 | 87 |
|
47 | 88 | ### Working with Bazel generation
|
48 | 89 |
|
49 |
| -`tensorflow-core-api` uses Bazel-built C++ code generation to generate most of the `@Operator` classes. To get it to build, you will likely need to |
50 |
| -clone the [tensorflow](https://github.com/tensorflow/tensorflow) project, run its configuration script (`./configure`), and copy the resulting |
| 90 | +`tensorflow-core-api` uses Bazel-built C++ code generation to generate most of the `@Operator` classes. |
| 91 | +By default, the bazel build is configured for the [CI](.github/workflows/ci.yml), so if you're building locally, you may need to clone |
| 92 | +the [tensorflow](https://github.com/tensorflow/tensorflow) project, run its configuration script (`./configure`), and copy the resulting |
51 | 93 | `.tf_configure.bazelrc` to `tensorflow-core-api`.
|
52 | 94 |
|
53 |
| -To run the code generation, use the `//:java_op_generator` target. The resulting binary has good help text (viewable in |
54 |
| -[op_gen_main.cc](tensorflow-core/tensorflow-core-api/src/bazel/op_generator/op_gen_main.cc#L31-L48)). |
55 |
| -Genrally, it should be called with arguments that are something like `bazel-out/k8-opt/bin/external/org_tensorflow/tensorflow/libtensorflow_cc.so |
56 |
| ---output_dir=src/gen/java --api_dirs=bazel-tensorflow-core-api/external/org_tensorflow/tensorflow/core/api_def/base_api,src/bazel/api_def` |
| 95 | +To run the code generation, use the `//:java_op_generator` target. The resulting binary has good help text (viewable in |
| 96 | +[op_gen_main.cc](tensorflow-core/tensorflow-core-api/src/bazel/op_generator/op_gen_main.cc#L31-L48)). Generally, it should be called with arguments |
| 97 | +that are something |
| 98 | +like `bazel-out/k8-opt/bin/external/org_tensorflow/tensorflow/libtensorflow_cc.so --output_dir=src/gen/java --api_dirs=bazel-tensorflow-core-api/external/org_tensorflow/tensorflow/core/api_def/base_api,src/bazel/api_def` |
57 | 99 | (from `tensorflow-core-api`).
|
0 commit comments