Skip to content

Commit cc3e816

Browse files
committed
First draft for Bazelcism
1 parent d39cbb9 commit cc3e816

File tree

75 files changed

+744
-388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+744
-388
lines changed

tensorflow-core/pom.xml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@
3838
<properties>
3939
<!--
4040
Match version used by TensorFlow, in
41-
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/workspace2.bzl#L567
41+
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/workspace2.bzl
4242
(but for the currently used release, not master)
43-
44-
Bumped to newer version to patch a CVE only present in protobuf-java
4543
-->
46-
<protobuf.version>3.19.4</protobuf.version>
44+
<protobuf.version>3.21.9</protobuf.version>
4745

4846
<native.classifier>${javacpp.platform}${javacpp.platform.extension}</native.classifier>
4947
<javacpp.build.skip>false</javacpp.build.skip> <!-- To skip execution of build.sh: -Djavacpp.build.skip=true -->
@@ -69,7 +67,10 @@
6967
<javacpp.platform.macosx-x86_64.extension>macosx-x86_64${javacpp.platform.extension}</javacpp.platform.macosx-x86_64.extension>
7068
<javacpp.platform.windows-x86.extension>windows-x86${javacpp.platform.extension}</javacpp.platform.windows-x86.extension>
7169
<javacpp.platform.windows-x86_64.extension>windows-x86_64${javacpp.platform.extension}</javacpp.platform.windows-x86_64.extension>
72-
<javacpp.version>1.5.8</javacpp.version>
70+
<javacpp.version>1.5.9</javacpp.version>
71+
72+
<native.wheel.url/>
73+
<native.wheel.url.macosx-arm64>https://files.pythonhosted.org/packages/d2/e6/94748fedae940a7095ac3acb821e613f72513cf9fa8ea0cf6fe734ef8c8f/tensorflow_macos-2.12.0-cp311-cp311-macosx_12_0_arm64.whl</native.wheel.url.macosx-arm64>
7374
</properties>
7475

7576
<profiles>
@@ -882,6 +883,18 @@
882883
<os.name>macosx</os.name>
883884
</properties>
884885
</profile>
886+
<profile>
887+
<id>macosx-arm64</id>
888+
<activation>
889+
<os>
890+
<name>mac os x</name>
891+
<arch>aarch64</arch>
892+
</os>
893+
</activation>
894+
<properties>
895+
<native.wheel.url>${native.wheel.url.macosx-arm64}</native.wheel.url>
896+
</properties>
897+
</profile>
885898
<profile>
886899
<id>windowsos</id>
887900
<activation>

tensorflow-core/tensorflow-core-api/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# Script to build native TensorFlow libraries
33
set -eu
44

5+
6+
7+
58
# Allows us to use ccache with Bazel on Mac
69
export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
710

tensorflow-core/tensorflow-core-api/pom.xml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<properties>
1818
<native.build.skip>false</native.build.skip>
19+
<native.build.folder>${project.build.directory}/native/org/tensorflow/internal/c_api/${native.classifier}/</native.build.folder>
1920
<javacpp.build.skip>${native.build.skip}</javacpp.build.skip>
2021
<javacpp.parser.skip>${native.build.skip}</javacpp.parser.skip>
2122
<javacpp.compiler.skip>${native.build.skip}</javacpp.compiler.skip>
@@ -173,6 +174,7 @@
173174
</execution>
174175
</executions>
175176
</plugin>
177+
176178
<plugin>
177179
<artifactId>maven-compiler-plugin</artifactId>
178180
<version>3.8.0</version>
@@ -246,16 +248,16 @@
246248
<classPath>${project.build.outputDirectory}</classPath>
247249
<includePaths>
248250
<includePath>${project.basedir}/</includePath>
249-
<includePath>${project.basedir}/bazel-${project.artifactId}/external/org_tensorflow/</includePath>
250-
<includePath>${project.basedir}/bazel-bin/external/org_tensorflow/</includePath>
251-
<includePath>${project.basedir}/bazel-${project.artifactId}/external/com_google_absl/</includePath>
252-
<includePath>${project.basedir}/bazel-${project.artifactId}/external/eigen_archive/</includePath>
253-
<includePath>${project.basedir}/bazel-${project.artifactId}/external/com_google_protobuf/src/</includePath>
251+
<!-- <includePath>${project.basedir}/bazel-${project.artifactId}/external/org_tensorflow/</includePath>-->
252+
<!-- <includePath>${project.basedir}/bazel-bin/external/org_tensorflow/</includePath>-->
253+
<!-- <includePath>${project.basedir}/bazel-${project.artifactId}/external/com_google_absl/</includePath>-->
254+
<!-- <includePath>${project.basedir}/bazel-${project.artifactId}/external/eigen_archive/</includePath>-->
255+
<!-- <includePath>${project.basedir}/bazel-${project.artifactId}/external/com_google_protobuf/src/</includePath>-->
256+
<includePath>${project.basedir}/downloads/tensorflow/include/</includePath>
254257
<includePath>${project.basedir}/target/classes/org/tensorflow/internal/c_api/include/</includePath>
255258
</includePaths>
256259
<linkPaths>
257-
<linkPath>${project.basedir}/bazel-bin/external/llvm_openmp/</linkPath>
258-
<linkPath>${project.basedir}/bazel-bin/external/org_tensorflow/tensorflow/</linkPath>
260+
<linkPath>${native.build.folder}</linkPath>
259261
</linkPaths>
260262
<resourcePaths>
261263
<resourcePath>${project.basedir}/../../</resourcePath>
@@ -296,7 +298,10 @@
296298
<skip>${javacpp.build.skip}</skip>
297299
<buildCommand>
298300
<program>bash</program>
299-
<argument>${project.basedir}/build.sh</argument>
301+
<argument>prepare_build.sh</argument>
302+
<!--argument>${project.basedir}/build.sh</argument-->
303+
<argument>${native.wheel.url}</argument>
304+
<argument>${native.build.folder}</argument>
300305
</buildCommand>
301306
<environmentVariables>
302307
<PLATFORM>${javacpp.platform}</PLATFORM>
@@ -355,7 +360,7 @@
355360
<goal>build</goal>
356361
</goals>
357362
<configuration>
358-
<outputDirectory>${project.build.directory}/native/org/tensorflow/internal/c_api/${native.classifier}/</outputDirectory>
363+
<outputDirectory>${native.build.folder}/</outputDirectory>
359364
<skip>${javacpp.compiler.skip}</skip>
360365
<classOrPackageName>org.tensorflow.internal.c_api.**</classOrPackageName>
361366
<copyLibs>true</copyLibs>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
PYTHON_WHEEL_URL="$1"
5+
TARGET_FOLDER="$2"
6+
DOWNLOAD_FOLDER="downloads"
7+
DOWNLOADED_FILE="tensorflow.zip" # TODO extract name from wheel url, change .whl to .zip
8+
9+
mkdir -p $TARGET_FOLDER
10+
mkdir -p $DOWNLOAD_FOLDER
11+
12+
if [ ! -f $DOWNLOAD_FOLDER/$DOWNLOADED_FILE ]; then
13+
curl -L $PYTHON_WHEEL_URL --output-dir $DOWNLOAD_FOLDER --output $DOWNLOADED_FILE
14+
fi
15+
16+
unzip -u -d $DOWNLOAD_FOLDER $DOWNLOAD_FOLDER/$DOWNLOADED_FILE
17+
18+
# TODO Per OS logic
19+
mv -f $DOWNLOAD_FOLDER/tensorflow/libtensorflow_cc.2.dylib $DOWNLOAD_FOLDER/tensorflow/libtensorflow_framework.2.dylib $TARGET_FOLDER
20+
ln -s $TARGET_FOLDER/libtensorflow_cc.2.dylib $TARGET_FOLDER/libtensorflow_cc.dylib
21+
ln -s $TARGET_FOLDER/libtensorflow_framework.2.dylib $TARGET_FOLDER/libtensorflow_framework.dylib

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/Compute_func_Pointer_TF_OpKernelContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/Create_func_TF_OpKernelConstruction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/Deallocator_Pointer_long_Pointer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/Delete_func_Pointer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/GradFunc.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

@@ -19,7 +19,7 @@ public class GradFunc extends FunctionPointer {
1919
public GradFunc(Pointer p) { super(p); }
2020
protected GradFunc() { allocate(); }
2121
private native void allocate();
22-
public native @ByVal NativeStatus call(@Const @ByRef TF_Scope scope, @Const @ByRef NativeOperation op,
22+
public native @ByVal Status call(@Const @ByRef TF_Scope scope, @Const @ByRef NativeOperation op,
2323
@Const @ByRef NativeOutputVector grad_inputs,
2424
NativeOutputVector grad_outputs);
2525
}

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/GradOpRegistry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

@@ -40,8 +40,8 @@ public class GradOpRegistry extends Pointer {
4040
* Note that 'func' can be null for ops that have registered no-gradient with
4141
* the registry.
4242
* Returns error status otherwise. */
43-
public native @ByVal NativeStatus Lookup(@StdString BytePointer op, @ByPtrPtr GradFunc func);
44-
public native @ByVal NativeStatus Lookup(@StdString String op, @ByPtrPtr GradFunc func);
43+
public native @ByVal Status Lookup(@StdString BytePointer op, @ByPtrPtr GradFunc func);
44+
public native @ByVal Status Lookup(@StdString String op, @ByPtrPtr GradFunc func);
4545

4646
/** Returns a pointer to the global gradient function registry. */
4747
public static native GradOpRegistry Global();

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/Listener_BytePointer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/Listener_String.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/NameMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/NativeGraphPointer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/NativeOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/NativeOutput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/NativeOutputVector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/Node.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/NodeBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/Shape_inference_func_TF_ShapeInferenceContext_TF_Status.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/SourceLocation.java

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.8: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.9: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

@@ -7,39 +7,50 @@
77
import org.bytedeco.javacpp.annotation.*;
88

99
import static org.tensorflow.internal.c_api.global.tensorflow.*;
10-
// namespace errors
10+
// namespace error
11+
1112
/** \ingroup core
1213
* Denotes success or failure of a call in Tensorflow. */
13-
@Name("tensorflow::Status") @NoOffset @Properties(inherit = org.tensorflow.internal.c_api.presets.tensorflow.class)
14-
public class NativeStatus extends Pointer {
14+
@Namespace("tsl") @NoOffset @Properties(inherit = org.tensorflow.internal.c_api.presets.tensorflow.class)
15+
public class Status extends Pointer {
1516
static { Loader.load(); }
1617
/** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
17-
public NativeStatus(Pointer p) { super(p); }
18+
public Status(Pointer p) { super(p); }
19+
/** Native array allocator. Access with {@link Pointer#position(long)}. */
20+
public Status(long size) { super((Pointer)null); allocateArray(size); }
21+
private native void allocateArray(long size);
22+
@Override public Status position(long position) {
23+
return (Status)super.position(position);
24+
}
25+
@Override public Status getPointer(long i) {
26+
return new Status((Pointer)this).offsetAddress(i);
27+
}
1828

1929
/** Create a success status. */
30+
public Status() { super((Pointer)null); allocate(); }
31+
private native void allocate(); // Not inlined to save code space
2032

2133
/** \brief Create a status with the specified error code and msg as a
2234
* human-readable string containing more detailed information. */
2335

2436
/** Copy the specified status. */
25-
public native @ByRef @Name("operator =") NativeStatus put(@Const @ByRef NativeStatus s);
37+
public Status(@Const @ByRef Status s) { super((Pointer)null); allocate(s); }
38+
private native void allocate(@Const @ByRef Status s);
39+
public native @ByRef @Name("operator =") Status put(@Const @ByRef Status s);
2640
// #ifndef SWIG
2741
// #endif // SWIG
2842

29-
// Prefer using OkStatus().
30-
public static native @ByVal NativeStatus OK();
31-
3243
/** Returns true iff the status indicates success. */
3344
public native @Cast("bool") boolean ok();
3445

35-
46+
public native @Cast("tsl::error::Code") int code();
3647

3748
public native @StdString BytePointer error_message();
3849

39-
public native @Cast("bool") @Name("operator ==") boolean equals(@Const @ByRef NativeStatus x);
50+
public native @Cast("bool") @Name("operator ==") boolean equals(@Const @ByRef Status x);
4051

4152
///
42-
public native @Cast("bool") @Name("operator !=") boolean notEquals(@Const @ByRef NativeStatus x);
53+
public native @Cast("bool") @Name("operator !=") boolean notEquals(@Const @ByRef Status x);
4354

4455
/** \brief If {@code ok()}, stores {@code new_status} into {@code *this}. If {@code !ok()},
4556
* preserves the current status, but may augment with additional
@@ -52,7 +63,7 @@ public class NativeStatus extends Pointer {
5263
* {@code overall_status.Update(new_status);} */
5364

5465
///
55-
public native void Update(@Const @ByRef NativeStatus new_status);
66+
public native void Update(@Const @ByRef Status new_status);
5667

5768
/** \brief Return a string representation of this status suitable for
5869
* printing. Returns the string {@code "OK"} for success.
@@ -73,7 +84,7 @@ public class NativeStatus extends Pointer {
7384
// Payload Management APIs (Cloned from absl::Status)
7485
//----------------------------------------------------------------------------
7586
// A payload may be attached to a status to provide additional context to an
76-
// error that may not be satisfied by an existing `tensorflow::error::Code`.
87+
// error that may not be satisfied by an existing `tsl::error::Code`.
7788
// Typically, this payload serves one of several purposes:
7889
//
7990
// * It may provide more fine-grained semantic information about the error
@@ -127,5 +138,14 @@ public class NativeStatus extends Pointer {
127138
// forbidden and could result in undefined behavior.
128139

129140

130-
public native @Span @Cast("const tensorflow::SourceLocation*") SourceLocation GetSourceLocations();
141+
// Sets the stack frame associated with this status object.
142+
// Stack traces are only kept and returned via GetStackTrace() if
143+
// !this->ok().
144+
145+
146+
// Retrieve an associated stack frame for a non-OK status that was
147+
// set via SetStackTrace().
148+
149+
150+
131151
}

0 commit comments

Comments
 (0)