Skip to content

Sync Clarke fork #1

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

Merged
merged 5 commits into from
Sep 18, 2020
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 13 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
linux-x86_64:
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'CI build')
runs-on: ubuntu-latest
container: nvidia/cuda:10.1-cudnn7-devel-centos7
container: centos:7
strategy:
matrix:
ext: ["", -mkl, -gpu, -mkl-gpu]
Expand All @@ -39,6 +39,17 @@ jobs:
echo Downloading Bazel
curl -L https://github.com/bazelbuild/bazel/releases/download/2.0.0/bazel-2.0.0-installer-linux-x86_64.sh -o bazel.sh --retry 10
bash bazel.sh
echo Installing CUDA
curl -L https://developer.download.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda-repo-rhel7-10-1-local-10.1.243-418.87.00-1.0-1.x86_64.rpm -o $HOME/cuda.rpm
curl -L https://developer.download.nvidia.com/compute/redist/cudnn/v7.6.5/cudnn-10.1-linux-x64-v7.6.5.32.tgz -o $HOME/cudnn.tgz
curl -L https://developer.download.nvidia.com/compute/redist/nccl/v2.4/nccl_2.4.8-1+cuda10.1_x86_64.txz -o $HOME/nccl.txz
rpm -i $HOME/cuda.rpm
cd /var/cuda-repo-10-1-local-10.1.243-418.87.00/; rpm -i --nodeps cuda*.rpm libc*.rpm
ln -sf /usr/local/cuda/lib64/stubs/libcuda.so /usr/local/cuda/lib64/libcuda.so
ln -sf /usr/local/cuda/lib64/stubs/libnvidia-ml.so /usr/local/cuda/lib64/libnvidia-ml.so
tar hxvf $HOME/cudnn.tgz -C /usr/local/
tar hxvf $HOME/nccl.txz --strip-components=1 -C /usr/local/cuda/
mv /usr/local/cuda/lib/* /usr/local/cuda/lib64/
- name: Checkout repository
uses: actions/checkout@v1
- name: Build project
Expand Down Expand Up @@ -110,7 +121,7 @@ jobs:
curl.exe -L https://github.com/bazelbuild/bazel/releases/download/2.0.0/bazel-2.0.0-windows-x86_64.exe -o C:/bazel/bazel.exe --retry 10
echo Installing CUDA
curl.exe -L http://developer.download.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda_10.1.243_426.00_windows.exe -o cuda.exe
curl.exe -L https://developer.download.nvidia.com/compute/redist/cudnn/v7.6.4/cudnn-10.1-windows7-x64-v7.6.4.38.zip -o cudnn.zip
curl.exe -L https://developer.download.nvidia.com/compute/redist/cudnn/v7.6.5/cudnn-10.1-windows7-x64-v7.6.5.32.zip -o cudnn.zip
cuda.exe -s
mkdir cuda
unzip.exe cudnn.zip
Expand Down
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,29 @@ migrated from Bazel to Maven, which is more familiar for most Java developers.
The following describes the layout of the repository and its different artifacts:

* `tensorflow-core`
* All artifacts that build up the core language bindings of TensorFlow for Java.
* Those artifacts provide the minimal support required to use the TensorFlow runtime on a JVM.
* All artifacts that build up the core language bindings of TensorFlow for Java
* Intended audience: projects that provide their own APIs or frameworks on top of
TensorFlow and just want a thin layer to access the TensorFlow runtime from the JVM

* `tensorflow-framework`
* High-level APIs built on top of the core libraries to simplify neural network training and inference
using TensorFlow.
* Complete but fairly primitive API for building and training neural networks with TensorFlow
* Intended audience: expert neural network developers who prefer to make explicit, detailed decisions
about their models and training algorithms

* `tensorflow-keras` (early WIP; only defined in `dev` profile)
* Partially covers the framework API to allow simpler definition of models and training algorithms
* Intended to be familiar if you know the Python Keras API, but prioritizes clean, idiomatic Java
over fidelity to Python
* Provides defaults based on common best practices
* Allows developers to selectively be more explicit by overriding defaults or dipping into the framework API
* Intended audience: neural network developers across the spectrum from beginner to expert who prefer to
rely mostly on best-practice defaults and then selectively fine-tune

* `ndarray`
* Generic utility library for n-dimensional data I/O operations. It is used by TensorFlow without depending
on it, making its usage eligible to any type of projects, using TensorFlow or not.
* Generic utility library for n-dimensional data I/O operations
* Used by TensorFlow but does not depend on TensorFlow
* Intended audience: any developer who needs a Java n-dimensional array implementation, whether or not they
use it with TensorFlow

## Building Sources

Expand Down
2 changes: 1 addition & 1 deletion tensorflow-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<javacpp.platform.macosx-x86_64.extension>macosx-x86_64${javacpp.platform.extension}</javacpp.platform.macosx-x86_64.extension>
<javacpp.platform.windows-x86.extension>windows-x86${javacpp.platform.extension}</javacpp.platform.windows-x86.extension>
<javacpp.platform.windows-x86_64.extension>windows-x86_64${javacpp.platform.extension}</javacpp.platform.windows-x86_64.extension>
<javacpp.version>1.5.4-SNAPSHOT</javacpp.version>
<javacpp.version>1.5.4</javacpp.version>
<mkl-dnn.version>0.21.5-${javacpp.version}</mkl-dnn.version>
</properties>

Expand Down
23 changes: 12 additions & 11 deletions tensorflow-core/tensorflow-core-api/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fi

if [[ "${EXTENSION:-}" == *gpu* ]]; then
export BUILD_FLAGS="$BUILD_FLAGS --config=cuda"
export TF_CUDA_COMPUTE_CAPABILITIES="3.5,7.0"
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 @@ -35,9 +36,9 @@ BUILD_FLAGS="$BUILD_FLAGS --experimental_repo_remote_exec --python_path="$PYTHON
# Always allow distinct host configuration since we rely on the host JVM for a few things (this was disabled by default on windows)
BUILD_FLAGS="$BUILD_FLAGS --distinct_host_configuration=true"

# Build C API of TensorFlow itself including a target to generate ops for Java
# Build C/C++ API of TensorFlow itself including a target to generate ops for Java
bazel build $BUILD_FLAGS \
@org_tensorflow//tensorflow:tensorflow \
@org_tensorflow//tensorflow:tensorflow_cc \
@org_tensorflow//tensorflow/tools/lib_package:jnilicenses_generate \
:java_proto_gen_sources \
:java_op_generator \
Expand All @@ -49,23 +50,23 @@ export BAZEL_BIN=$(pwd -P)/bazel-bin
export TENSORFLOW_BIN=$BAZEL_BIN/external/org_tensorflow/tensorflow

# Normalize some paths with symbolic links
TENSORFLOW_SO=($TENSORFLOW_BIN/libtensorflow.so.?.?.?)
TENSORFLOW_SO=($TENSORFLOW_BIN/libtensorflow_cc.so.?.?.?)
if [[ -f $TENSORFLOW_SO ]]; then
export TENSORFLOW_LIB=$TENSORFLOW_SO
ln -sf $(basename $TENSORFLOW_SO) $TENSORFLOW_BIN/libtensorflow.so
ln -sf $(basename $TENSORFLOW_SO) $TENSORFLOW_BIN/libtensorflow.so.2
ln -sf $(basename $TENSORFLOW_SO) $TENSORFLOW_BIN/libtensorflow_cc.so
ln -sf $(basename $TENSORFLOW_SO) $TENSORFLOW_BIN/libtensorflow_cc.so.2
fi
TENSORFLOW_DYLIB=($TENSORFLOW_BIN/libtensorflow.?.?.?.dylib)
TENSORFLOW_DYLIB=($TENSORFLOW_BIN/libtensorflow_cc.?.?.?.dylib)
if [[ -f $TENSORFLOW_DYLIB ]]; then
export TENSORFLOW_LIB=$TENSORFLOW_DYLIB
ln -sf $(basename $TENSORFLOW_DYLIB) $TENSORFLOW_BIN/libtensorflow.dylib
ln -sf $(basename $TENSORFLOW_DYLIB) $TENSORFLOW_BIN/libtensorflow.2.dylib
ln -sf $(basename $TENSORFLOW_DYLIB) $TENSORFLOW_BIN/libtensorflow_cc.dylib
ln -sf $(basename $TENSORFLOW_DYLIB) $TENSORFLOW_BIN/libtensorflow_cc.2.dylib
fi
TENSORFLOW_DLLS=($TENSORFLOW_BIN/tensorflow.dll.if.lib $TENSORFLOW_BIN/libtensorflow.dll.ifso)
TENSORFLOW_DLLS=($TENSORFLOW_BIN/tensorflow_cc.dll.if.lib $TENSORFLOW_BIN/libtensorflow_cc.dll.ifso)
for TENSORFLOW_DLL in ${TENSORFLOW_DLLS[@]}; do
if [[ -f $TENSORFLOW_DLL ]]; then
export TENSORFLOW_LIB=$TENSORFLOW_BIN/tensorflow.dll
ln -sf $(basename $TENSORFLOW_DLL) $TENSORFLOW_BIN/tensorflow.lib
export TENSORFLOW_LIB=$TENSORFLOW_BIN/tensorflow_cc.dll
ln -sf $(basename $TENSORFLOW_DLL) $TENSORFLOW_BIN/tensorflow_cc.lib
fi
done
echo "Listing $TENSORFLOW_BIN:" && ls -l $TENSORFLOW_BIN
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
op {
graph_op_name: "SoftmaxCrossEntropyWithLogits"
endpoint {
name: "nn.SoftmaxCrossEntropyWithLogits"
name: "nn.raw.SoftmaxCrossEntropyWithLogits"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
op {
graph_op_name: "SparseSoftmaxCrossEntropyWithLogits"
endpoint {
name: "nn.SparseSoftmaxCrossEntropyWithLogits"
name: "nn.raw.SparseSoftmaxCrossEntropyWithLogits"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,20 @@ void GenerateOp(const OpSpec& op, const EndpointSpec& endpoint,
RenderInterfaceImpl(op, mode, &writer);
}
writer.EndLine();
for (const ArgumentSpec& output : op.outputs()) {
writer.WriteField(output.var(), PRIVATE);

Variable nameVariable = Variable::Create("OP_NAME", Type::Class("String"));
Javadoc name_javadoc = Javadoc::Create("The name of this op, as known by TensorFlow core engine");
string quoted_string = "\"" + op.graph_op_name() + "\"";
writer.WriteFieldWithInitializer(nameVariable, PUBLIC|STATIC|FINAL, &name_javadoc, quoted_string );


if(!op.outputs().empty()) {
writer.EndLine();
for (const ArgumentSpec& output : op.outputs()) {
writer.WriteField(output.var(), PRIVATE);
}
}

RenderConstructor(op, op_class, &writer);
writer.EndType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,22 @@ SourceWriter& SourceWriter::WriteField(const Variable& field, int modifiers,
return *this;
}

SourceWriter& SourceWriter::WriteFieldWithInitializer(const Variable& field,
int modifiers, const Javadoc* javadoc, const string& initializer) {
// If present, write field javadoc only as one brief line
if (javadoc != nullptr && !javadoc->brief().empty()) {
Append("/** ").Append(javadoc->brief()).Append(" */").EndLine();
}
WriteModifiers(modifiers);
if (!initializer.empty())
AppendType(field.type()).Append(" ").Append(field.name()).
Append(" = ").Append(initializer).Append(";");
else
AppendType(field.type()).Append(" ").Append(field.name()).Append(";");
EndLine();
return *this;
}

SourceWriter& SourceWriter::WriteModifiers(int modifiers) {
if (modifiers & PUBLIC) {
Append("public ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ class SourceWriter {
SourceWriter& WriteField(const Variable& field, int modifiers,
const Javadoc* javadoc = nullptr);

SourceWriter& WriteFieldWithInitializer(const Variable& field,
int modifiers, const Javadoc* javadoc = nullptr, const string& initializer = nullptr);

protected:
virtual void DoAppend(const StringPiece& str) = 0;

Expand All @@ -161,7 +164,7 @@ class SourceWriter {
class TypeVisitor {
public:
virtual ~TypeVisitor() = default;
void Visit(const Type& type);
void Visit(const Type& type);

protected:
virtual void DoVisit(const Type& type) = 0;
Expand Down
Loading