|
| 1 | +# Building and contributing to TensorFlow Java |
| 2 | + |
| 3 | +## Building |
| 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 |
| 7 | +`mvn install -Djavacpp.platform.extension=-mkl` or CUDA with `mvn install -Djavacpp.platform.extension=-gpu` |
| 8 | +or both with `mvn install -Djavacpp.platform.extension=-mkl-gpu`. |
| 9 | + |
| 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/) |
| 13 | +build tool and a few Python dependencies (please read [TensorFlow documentation](https://www.tensorflow.org/install/source) |
| 14 | +for more details). |
| 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 |
| 19 | +(e.g. `mvn install -Pdev`). |
| 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. |
| 23 | + |
| 24 | + |
| 25 | +## Running Tests |
| 26 | + |
| 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`. |
| 30 | + |
| 31 | +## Contributing |
| 32 | + |
| 33 | +### Formatting |
| 34 | + |
| 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 |
| 37 | +[Eclipse](https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml). |
| 38 | +[Google's C++ style guide](https://google.github.io/styleguide/cppguide.html) should also be used for C++ code. |
| 39 | + |
| 40 | +### Working with Bazel generation |
| 41 | + |
| 42 | +`tensorflow-core-api` uses C++ code generation that is built with Bazel. To get it to build, you will likely need to clone the |
| 43 | +`tensorflow` project, run its configuration script (`./configure`), and copy the resulting `.tf_configure.bazelrc` to `tensorflow-core-api`. |
| 44 | + |
| 45 | +To run the code generation, use the `//:java_op_generator` target. The resulting binary has good help text (viewable in |
| 46 | +[op_gen_main.cc](tensorflow-core/tensorflow-core-api/src/bazel/op_generator/op_gen_main.cc#L31-L48)). |
| 47 | +Generally, it should be called with arguments that are something like `bazel-out/k8-opt/bin/external/org_tensorflow/tensorflow/libtensorflow_cc.so |
| 48 | +--output_dir=src/gen/java --api_dirs=bazel-tensorflow-core-api/external/org_tensorflow/tensorflow/core/api_def/base_api,src/bazel/api_def` |
| 49 | +(from `tensorflow-core-api`). |
0 commit comments