-
Notifications
You must be signed in to change notification settings - Fork 74k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple graph operations from their implementation
- Loading branch information
1 parent
9b884d8
commit 0c3ab56
Showing
22 changed files
with
1,084 additions
and
727 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
tensorflow/java/src/main/java/org/tensorflow/AbstractOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
package org.tensorflow; | ||
|
||
/** | ||
* Base class for {@link Operation} implementations. | ||
* | ||
* <p>As opposed to {@link Operation} itself, this class is package private and | ||
* therefore its usage is limited to internal purposes only. | ||
*/ | ||
abstract class AbstractOperation implements Operation { | ||
|
||
AbstractOperation(long unsafeNativeHandle) { | ||
this.unsafeNativeHandle = unsafeNativeHandle; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("<%s '%s'>", type(), name()); | ||
} | ||
|
||
/** | ||
* Returns the native handle of the {@code outputIdx}th output of this operation. | ||
* | ||
* <p>The nature of the returned value varies depending on current the execution environment. | ||
* <ul> | ||
* <li>In eager mode, the value is a handle to the tensor returned at this output.</li> | ||
* <li>In graph mode, the value is a handle to the operation itself, which should be paired with | ||
* the index of the output when calling the native layer.</li> | ||
* </ul> | ||
* | ||
* @param outputIdx index of the output in this operation | ||
* @return a native handle, see method description for more details | ||
*/ | ||
abstract long getUnsafeNativeHandle(int outputIdx); | ||
|
||
/** | ||
* Returns the shape of the tensor of the {code outputIdx}th output of this operation. | ||
* | ||
* @param outputIdx index of the output of this operation | ||
* @return output tensor shape | ||
*/ | ||
abstract long[] shape(int outputIdx); | ||
|
||
/** | ||
* Returns the datatype of the tensor of the {code outputIdx}th output of this operation. | ||
* | ||
* @param outputIdx index of the output of this operation | ||
* @return output tensor datatype | ||
*/ | ||
abstract DataType dtype(int outputIdx); | ||
|
||
long getUnsafeNativeHandle() { | ||
return unsafeNativeHandle; | ||
} | ||
|
||
private final long unsafeNativeHandle; | ||
} |
33 changes: 33 additions & 0 deletions
33
tensorflow/java/src/main/java/org/tensorflow/ExecutionEnvironment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
package org.tensorflow; | ||
|
||
/** | ||
* Defines an environment for creating and executing TensorFlow {@link Operation}s. | ||
*/ | ||
public interface ExecutionEnvironment { | ||
|
||
/** | ||
* Returns a builder to create a new {@link Operation}. | ||
* | ||
* @param type of the Operation (i.e., identifies the computation to be performed) | ||
* @param name to refer to the created Operation in this environment scope. | ||
* @return an {@link OperationBuilder} to create an Operation when {@link | ||
* OperationBuilder#build()} is invoked. If {@link OperationBuilder#build()} is not invoked, | ||
* then some resources may leak. | ||
*/ | ||
OperationBuilder opBuilder(String type, String name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.