Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 38 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- master
- staging
- r[0-9]+.*
pull_request:
branches:
Expand All @@ -11,6 +12,7 @@ on:
env:
STAGING_PROFILE_ID: 46f80d0729c92d
NATIVE_BUILD_PROJECTS: tensorflow-core/tensorflow-core-generator,tensorflow-core/tensorflow-core-api
GCP_CREDS: ${{ secrets.GCP_CREDS }}
jobs:
quick-build:
if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'CI build')
Expand Down Expand Up @@ -76,8 +78,9 @@ jobs:
tar hxvf $HOME/nccl.txz --strip-components=1 -C /usr/local/cuda/
mv /usr/local/cuda/lib/* /usr/local/cuda/lib64/
echo Removing downloaded archives and unused libraries to avoid running out of disk space
rm -f *.rpm *.tgz *.txz *.tar.*
rm -f $HOME/*.rpm $HOME/*.tgz $HOME/*.txz $HOME/*.tar.*
rm -f $(find /usr/local/cuda/ -name '*.a' -and -not -name libcudart_static.a -and -not -name libcudadevrt.a)
rm -rf /usr/local/cuda/doc* /usr/local/cuda/libnvvp* /usr/local/cuda/nsight* /usr/local/cuda/samples*
fi
- name: Checkout repository
uses: actions/checkout@v1
Expand All @@ -94,8 +97,14 @@ jobs:
mkdir -p $HOME/.m2
[[ "${{ github.event_name }}" == "push" ]] && MAVEN_PHASE=deploy || MAVEN_PHASE=install
echo "<settings><servers><server><id>ossrh</id><username>${{ secrets.CI_DEPLOY_USERNAME }}</username><password>${{ secrets.CI_DEPLOY_PASSWORD }}</password></server></servers></settings>" > $HOME/.m2/settings.xml
if [[ "${{ github.event_name }}" == "push" && "${{ github.repository }}" == "tensorflow/java" ]]; then
printf '%s\n' "${GCP_CREDS}" > $HOME/gcp_creds.json
export BAZEL_CACHE="--remote_cache=https://storage.googleapis.com/tensorflow-sigs-jvm --remote_upload_local_results=true --google_credentials=$HOME/gcp_creds.json"
else
export BAZEL_CACHE="--remote_cache=https://storage.googleapis.com/tensorflow-sigs-jvm --remote_upload_local_results=false"
fi
echo Executing Maven $MAVEN_PHASE
mvn clean $MAVEN_PHASE -B -U -e -Djavacpp.platform=linux-x86_64 -Djavacpp.platform.extension=${{ matrix.ext }} -pl $NATIVE_BUILD_PROJECTS -am -DstagingRepositoryId=${{ needs.prepare.outputs.stagingRepositoryId }}
mvn clean $MAVEN_PHASE -B -U -e -Djavacpp.platform=linux-x86_64 -Djavacpp.platform.extension=${{ matrix.ext }} -pl $NATIVE_BUILD_PROJECTS -am -DstagingRepositoryId=${{ needs.prepare.outputs.stagingRepositoryId }} "-Dnative.build.flags=$BAZEL_CACHE"
df -h
macosx-x86_64:
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'CI build')
Expand Down Expand Up @@ -123,17 +132,23 @@ jobs:
mkdir -p $HOME/.m2
[[ "${{ github.event_name }}" == "push" ]] && MAVEN_PHASE=deploy || MAVEN_PHASE=install
echo "<settings><servers><server><id>ossrh</id><username>${{ secrets.CI_DEPLOY_USERNAME }}</username><password>${{ secrets.CI_DEPLOY_PASSWORD }}</password></server></servers></settings>" > $HOME/.m2/settings.xml
if [[ "${{ github.event_name }}" == "push" && "${{ github.repository }}" == "tensorflow/java" ]]; then
printf '%s\n' "${GCP_CREDS}" > $HOME/gcp_creds.json
export BAZEL_CACHE="--remote_cache=https://storage.googleapis.com/tensorflow-sigs-jvm --remote_upload_local_results=true --google_credentials=$HOME/gcp_creds.json"
else
export BAZEL_CACHE="--remote_cache=https://storage.googleapis.com/tensorflow-sigs-jvm --remote_upload_local_results=false"
fi
df -h
echo Executing Maven $MAVEN_PHASE
mvn clean $MAVEN_PHASE -B -U -e -Djavacpp.platform=macosx-x86_64 -Djavacpp.platform.extension=${{ matrix.ext }} -pl $NATIVE_BUILD_PROJECTS -am -DstagingRepositoryId=${{ needs.prepare.outputs.stagingRepositoryId }}
mvn clean $MAVEN_PHASE -B -U -e -Djavacpp.platform=macosx-x86_64 -Djavacpp.platform.extension=${{ matrix.ext }} -pl $NATIVE_BUILD_PROJECTS -am -DstagingRepositoryId=${{ needs.prepare.outputs.stagingRepositoryId }} "-Dnative.build.flags=$BAZEL_CACHE"
df -h
windows-x86_64:
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'CI build')
runs-on: windows-latest
needs: prepare
strategy:
matrix:
ext: ["", -mkl] # -gpu, -mkl-gpu]
ext: ["", -gpu, -mkl] #, -mkl-gpu]
steps:
- name: Configure page file
uses: al-cheb/configure-pagefile-action@v1.2
Expand All @@ -154,16 +169,16 @@ jobs:
mkdir C:\bazel
curl.exe -L https://github.com/bazelbuild/bazel/releases/download/3.1.0/bazel-3.1.0-windows-x86_64.exe -o C:/bazel/bazel.exe --retry 10
set "EXT=${{ matrix.ext }}"
if "%EXT:~-4%"=="-gpu" (
echo Removing some unused stuff to avoid running out of disk space
rm.exe -Rf "C:/Program Files (x86)/Android" "C:/Program Files/dotnet" "%CONDA%" "%GOROOT_1_10_X64%" "%GOROOT_1_11_X64%" "%GOROOT_1_12_X64%" "%GOROOT_1_13_X64%" "C:\hostedtoolcache\windows\Ruby" "C:\Rust"
echo Installing CUDA
curl.exe -L https://developer.download.nvidia.com/compute/cuda/11.0.3/local_installers/cuda_11.0.3_451.82_win10.exe -o cuda.exe
curl.exe -L https://developer.download.nvidia.com/compute/redist/cudnn/v8.0.3/cudnn-11.0-windows-x64-v8.0.3.33.zip -o cudnn.zip
cuda.exe -s
mkdir cuda
unzip.exe cudnn.zip
cp.exe -a cuda/include cuda/lib cuda/bin "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/"
if "%EXT:~-4%" == "-gpu" (
echo Removing some unused stuff to avoid running out of disk space
rm.exe -Rf "C:/Program Files (x86)/Android" "C:/Program Files/dotnet" "%CONDA%" "%GOROOT_1_10_X64%" "%GOROOT_1_11_X64%" "%GOROOT_1_12_X64%" "%GOROOT_1_13_X64%" "C:\hostedtoolcache\windows\Ruby" "C:\Rust"
echo Installing CUDA
curl.exe -L https://developer.download.nvidia.com/compute/cuda/11.0.3/local_installers/cuda_11.0.3_451.82_win10.exe -o cuda.exe
curl.exe -L https://developer.download.nvidia.com/compute/redist/cudnn/v8.0.3/cudnn-11.0-windows-x64-v8.0.3.33.zip -o cudnn.zip
cuda.exe -s
mkdir cuda
unzip.exe cudnn.zip
cp.exe -a cuda/include cuda/lib cuda/bin "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/"
)
echo %JAVA_HOME%
- name: Checkout repository
Expand All @@ -187,12 +202,19 @@ jobs:
call mvn -version
bazel version
mkdir %USERPROFILE%\.m2
if "${{ github.event_name }}"=="push" (set MAVEN_PHASE=deploy) else (set MAVEN_PHASE=install)
if "${{ github.event_name }}" == "push" (set MAVEN_PHASE=deploy) else (set MAVEN_PHASE=install)
echo ^<settings^>^<servers^>^<server^>^<id^>ossrh^</id^>^<username^>${{ secrets.CI_DEPLOY_USERNAME }}^</username^>^<password^>${{ secrets.CI_DEPLOY_PASSWORD }}^</password^>^</server^>^</servers^>^</settings^> > %USERPROFILE%\.m2\settings.xml
set "BAZEL_CACHE=--remote_cache=https://storage.googleapis.com/tensorflow-sigs-jvm --remote_upload_local_results=false"
if "${{ github.event_name }}" == "push" (
if "${{ github.repository }}" == "tensorflow/java" (
printenv GCP_CREDS > %USERPROFILE%\gcp_creds.json
set "BAZEL_CACHE=--remote_cache=https://storage.googleapis.com/tensorflow-sigs-jvm --remote_upload_local_results=true --google_credentials=%USERPROFILE%\gcp_creds.json"
)
)
df -h
wmic pagefile list /format:list
echo Executing Maven %MAVEN_PHASE%
call mvn clean %MAVEN_PHASE% -B -U -e -Djavacpp.platform=windows-x86_64 -Djavacpp.platform.extension=${{ matrix.ext }} -pl %NATIVE_BUILD_PROJECTS% -am -DstagingRepositoryId=${{ needs.prepare.outputs.stagingRepositoryId }}
call mvn clean %MAVEN_PHASE% -B -U -e -Djavacpp.platform=windows-x86_64 -Djavacpp.platform.extension=${{ matrix.ext }} -pl %NATIVE_BUILD_PROJECTS% -am -DstagingRepositoryId=${{ needs.prepare.outputs.stagingRepositoryId }} "-Dnative.build.flags=%BAZEL_CACHE%"
if ERRORLEVEL 1 exit /b
df -h
wmic pagefile list /format:list
Expand Down
71 changes: 71 additions & 0 deletions MIGRATING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Migrating Between TensorFlow Java Releases

TensorFlow Java is still in an alpha stage, therefore is subject to contain breaking changes between the different releases. This guide explain in detail
how to migrate your code from a previous version to a new one that includes some changes that are not backward compatible.

## Migrating to 0.3.0

### Non-parameterized Typed Tensors

In previous versions, the `Tensor` class was parameterized with its tensor type interface, which is part of the `TType` family. To access directly the memory
tensor from the JVM, an explicit conversion between `Tensor` and its tensor type was required by calling `tensor.data()`.

In 0.3.0, tensors are always typed, making this generic parameter and explicit mapping obsolete. As soon as you get a handle to a tensor, you are able to
access directly its memory for reading (or writing for most tensor types) and no convertion is required. Any instances of a class in the `TType` family
can also now be manipulated directly as a `Tensor` (e.g. to be passed to a session for inference).

Steps:
1. Replace a parameterized `Tensor` by its parameter (e.g. `Tensor<TFloat32>` -> `TFloat32`)
2. Replace instance of `Tensor<?>` with unknown parameter by `Tensor`
3. Remove any invocation to `Tensor.data()` (e.g. `tensor.data().getFloat()` -> `tensor.getFloat()`)
4. Replace any invocation to `Operand.data()` by `Operand.asTensor()`

### Use of Java Type System instead of DataType

In previous versions, the `DataType` class was used to carry information about the type of a `Tensor`, that can then be converted back to a tensor of that
type (see previous section). Since there were a exact parity between interfaces of the `TType` family and an instance of `DataType`, the latter has been dropped
in 0.3.0 to leverage instead the standard type system in Java, for a better idiomatic experience.

Steps:
1. Replace all accesses to the `DTYPE` field of a `TType` interface by its class (e.g. `TFloat32.DTYPE` -> `TFloat32.class`)
2. Use Java type system for checking tensor types at runtime (e.g. using `instanceof` or `isAssignableFrom`)
3. Replace any invocation to `Tensor.expect()` by an explicit cast (e.g. `tensor.expect(TFloat32.DTYPE)` -> `(TFloat32)tensor`)

### Example

0.2.0:
```
Session session = ...;

try (Tensor<TFloat32> tensor = TFloat32.tensorOf(Shape.of(1, 2))) {
TFloat32 tensorData = tensor.data();
tensorData.setFloat(10.0f, 0);
tensorData.setFloat(20.0f, 1);

try (Tensor<?> result = session.runner().feed("x", tensor).fetch("y").run().get(0)) {
if (result.dataType() == TFloat32.DTYPE) {
Tensor<TFloat32> typedResult = result.expect(TFloat32.DTYPE);
TFloat32 resultData = typedResult.data();
System.out.println("Result is " + resultData.getFloat());
}
}
}
```

0.3.0:
```
Session session = ...;

try (TFloat32 tensor = TFloat32.tensorOf(Shape.of(1, 2))) {
tensor.setFloat(10.0f, 0);
tensor.setFloat(20.0f, 1);

try (Tensor result = session.runner().feed("x", tensor).fetch("y").run().get(0)) {
if (result instanceof TFloat32) {
TFloat32 typedResult = (TFloat32)result;
System.out.println("Result is " + typedResult.getFloat());
}
}
}
```

19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ systems, you should add the following dependencies:
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-api</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-api</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
<classifier>linux-x86_64${javacpp.platform.extension}</classifier>
</dependency>
```
Expand All @@ -77,24 +77,24 @@ native dependencies as follows:
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-api</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-api</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
<classifier>linux-x86_64${javacpp.platform.extension}</classifier>
</dependency>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-api</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
<classifier>macosx-x86_64${javacpp.platform.extension}</classifier>
</dependency>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-api</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
<classifier>windows-x86_64${javacpp.platform.extension}</classifier>
</dependency>
```
Expand All @@ -107,7 +107,7 @@ artifact includes transitively all the artifacts above as a single dependency:
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-platform${javacpp.platform.extension}</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
</dependency>
```

Expand Down Expand Up @@ -137,7 +137,7 @@ to add Sonatype OSS repository in your pom.xml, like the following
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-platform</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>0.4.0-SNAPSHOT</version>
</dependency>
</dependencies>
```
Expand All @@ -149,7 +149,8 @@ This table shows the mapping between different version of TensorFlow for Java an
| TensorFlow Java Version | TensorFlow Version |
| ------------- | ------------- |
| 0.2.0 | 2.3.1 |
| 0.3.0-SNAPSHOT | 2.3.1 |
| 0.3.0 | 2.4.1 |
| 0.4.0-SNAPSHOT | 2.4.1

## How to Contribute?

Expand Down
2 changes: 1 addition & 1 deletion ndarray/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To import the NdArray library in your project, simply add the following dependen
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>ndarray</artifactId>
<version>0.2.0-SNAPSHOT</version>
<version>0.3.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion ndarray/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-java</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>0.4.0-SNAPSHOT</version>
</parent>
<artifactId>ndarray</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-java</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>0.4.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>TensorFlow Java Parent</name>
Expand Down
2 changes: 1 addition & 1 deletion tensorflow-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-java</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>0.4.0-SNAPSHOT</version>
</parent>
<artifactId>tensorflow-core</artifactId>
<packaging>pom</packaging>
Expand Down
4 changes: 2 additions & 2 deletions tensorflow-core/tensorflow-core-api/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi

if [[ "${EXTENSION:-}" == *gpu* ]]; then
export BUILD_FLAGS="$BUILD_FLAGS --config=cuda"
export TF_CUDA_COMPUTE_CAPABILITIES="${TF_CUDA_COMPUTE_CAPABILITIES:-"3.5,7.0"}"
export TF_CUDA_COMPUTE_CAPABILITIES="${TF_CUDA_COMPUTE_CAPABILITIES:-"sm_35,sm_50,sm_60,sm_70,sm_75,compute_80"}"
if [[ -z ${TF_CUDA_PATHS:-} ]] && [[ -d ${CUDA_PATH:-} ]]; then
# Work around some issue with Bazel preventing it from detecting CUDA on Windows
export TF_CUDA_PATHS="$CUDA_PATH"
Expand All @@ -33,7 +33,7 @@ BUILD_FLAGS="$BUILD_FLAGS --experimental_repo_remote_exec --python_path="$PYTHON
BUILD_FLAGS="$BUILD_FLAGS --distinct_host_configuration=true"

# Build C/C++ API of TensorFlow itself including a target to generate ops for Java
bazel build $BUILD_FLAGS \
bazel build $BUILD_FLAGS ${BUILD_USER_FLAGS:-} \
@org_tensorflow//tensorflow:tensorflow_cc \
@org_tensorflow//tensorflow/tools/lib_package:jnilicenses_generate \
:java_proto_gen_sources \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
diff -ruN tensorflow-1.14.0-rc1/third_party/mkl/mkl.BUILD tensorflow-1.14.0-rc1-windows/third_party/mkl/mkl.BUILD
--- tensorflow-1.14.0-rc1/third_party/mkl/mkl.BUILD 2019-06-08 11:23:20.000000000 +0900
+++ tensorflow-1.14.0-rc1-windows/third_party/mkl/mkl.BUILD 2019-06-12 08:30:41.232683854 +0900
@@ -35,11 +35,23 @@
diff --git a/third_party/mkl/BUILD b/third_party/mkl/BUILD
index aa65b585b85..4e6546eac34 100644
--- a/third_party/mkl/BUILD
+++ b/third_party/mkl/BUILD
@@ -91,10 +91,23 @@ cc_library(
visibility = ["//visibility:public"],
)

Expand All @@ -20,11 +21,24 @@ diff -ruN tensorflow-1.14.0-rc1/third_party/mkl/mkl.BUILD tensorflow-1.14.0-rc1-
cc_library(
name = "mkl_libs_windows",
- srcs = [
- "lib/libiomp5md.lib",
- "lib/mklml.lib",
- "@llvm_openmp//:libiomp5md.dll",
+ deps = [
+ "iomp5",
+ "mklml",
+ "mklml"
],
linkopts = ["/FORCE:MULTIPLE"],
visibility = ["//visibility:public"],
)
diff --git a/third_party/llvm_openmp/BUILD b/third_party/llvm_openmp/BUILD
index 099a84dcbaa..f7f9d44118f 100644
--- a/third_party/llvm_openmp/BUILD
+++ b/third_party/llvm_openmp/BUILD
@@ -71,7 +71,7 @@ omp_vars_linux = {

# Windows Cmake vars to expand.
omp_vars_win = {
- "MSVC": 1,
+ "MSVC": 0,
}

omp_all_cmake_vars = select({

3 changes: 2 additions & 1 deletion tensorflow-core/tensorflow-core-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>0.4.0-SNAPSHOT</version>
</parent>
<artifactId>tensorflow-core-api</artifactId>
<packaging>jar</packaging>
Expand Down Expand Up @@ -260,6 +260,7 @@
</buildCommand>
<environmentVariables>
<EXTENSION>${javacpp.platform.extension}</EXTENSION>
<BUILD_USER_FLAGS>${native.build.flags}</BUILD_USER_FLAGS>
</environmentVariables>
<workingDirectory>${project.basedir}</workingDirectory>
</configuration>
Expand Down
Loading