Skip to content

Commit acdef3d

Browse files
zaleslawrnett
authored andcommitted
Add option to run TensorFlow job on the preferred device (via Scope) (tensorflow#159)
* Draft for DeviceSpec integration * Added generation for Ops * Removed something from generated Ops * Finalized the PR * Refactored Scope.apply method * Handle case of separate usage of control dependencies in Init method
1 parent dd5439a commit acdef3d

File tree

1,163 files changed

+1422
-1176
lines changed

Some content is hidden

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

1,163 files changed

+1422
-1176
lines changed

tensorflow-core/tensorflow-core-api/src/bazel/op_generator/op_generator.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,9 @@ void RenderFactoryMethods(const OpSpec& op, const Type& op_class,
246246
writer->EndLine();
247247
}
248248
}
249+
249250
// Add control dependencies, if any.
250-
writer->Append("opBuilder = scope.applyControlDependencies(opBuilder);");
251+
writer->Append("opBuilder = scope.apply(opBuilder);");
251252
writer->EndLine();
252253

253254
for (const AttributeSpec& attribute : op.attributes()) {

tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/Ops.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.nio.charset.Charset;
2121
import java.util.List;
2222
import org.tensorflow.DataType;
23+
import org.tensorflow.DeviceSpec;
2324
import org.tensorflow.EagerSession;
2425
import org.tensorflow.ExecutionEnvironment;
2526
import org.tensorflow.Operand;
@@ -7724,6 +7725,15 @@ public Ops withName(String opName) {
77247725
return new Ops(scope.withName(opName));
77257726
}
77267727

7728+
/**
7729+
* Returns an API that uses the provided DeviceSpec for an op.
7730+
*
7731+
* @see {@link Scope#withDevice(DeviceSpec)}
7732+
*/
7733+
public Ops withDevice(DeviceSpec deviceSpec) {
7734+
return new Ops(scope.withDevice(deviceSpec));
7735+
}
7736+
77277737
/**
77287738
* Returns an API that adds operations to the graph with the provided control dependencies.
77297739
*

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/op/audio/AudioSpectrogram.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private Options() {
9494
public static AudioSpectrogram create(Scope scope, Operand<TFloat32> input, Long windowSize, Long stride, Options... options) {
9595
OperationBuilder opBuilder = scope.env().opBuilder("AudioSpectrogram", scope.makeOpName("AudioSpectrogram"));
9696
opBuilder.addInput(input.asOutput());
97-
opBuilder = scope.applyControlDependencies(opBuilder);
97+
opBuilder = scope.apply(opBuilder);
9898
opBuilder.setAttr("window_size", windowSize);
9999
opBuilder.setAttr("stride", stride);
100100
if (options != null) {

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/op/audio/DecodeWav.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private Options() {
9090
public static DecodeWav create(Scope scope, Operand<TString> contents, Options... options) {
9191
OperationBuilder opBuilder = scope.env().opBuilder("DecodeWav", scope.makeOpName("DecodeWav"));
9292
opBuilder.addInput(contents.asOutput());
93-
opBuilder = scope.applyControlDependencies(opBuilder);
93+
opBuilder = scope.apply(opBuilder);
9494
if (options != null) {
9595
for (Options opts : options) {
9696
if (opts.desiredChannels != null) {

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/op/audio/EncodeWav.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static EncodeWav create(Scope scope, Operand<TFloat32> audio, Operand<TIn
5656
OperationBuilder opBuilder = scope.env().opBuilder("EncodeWav", scope.makeOpName("EncodeWav"));
5757
opBuilder.addInput(audio.asOutput());
5858
opBuilder.addInput(sampleRate.asOutput());
59-
opBuilder = scope.applyControlDependencies(opBuilder);
59+
opBuilder = scope.apply(opBuilder);
6060
return new EncodeWav(opBuilder.build());
6161
}
6262

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/op/audio/Mfcc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static Mfcc create(Scope scope, Operand<TFloat32> spectrogram, Operand<TI
104104
OperationBuilder opBuilder = scope.env().opBuilder("Mfcc", scope.makeOpName("Mfcc"));
105105
opBuilder.addInput(spectrogram.asOutput());
106106
opBuilder.addInput(sampleRate.asOutput());
107-
opBuilder = scope.applyControlDependencies(opBuilder);
107+
opBuilder = scope.apply(opBuilder);
108108
if (options != null) {
109109
for (Options opts : options) {
110110
if (opts.upperFrequencyLimit != null) {

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/op/bitwise/BitwiseAnd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static <T extends TNumber> BitwiseAnd<T> create(Scope scope, Operand<T> x
6969
OperationBuilder opBuilder = scope.env().opBuilder("BitwiseAnd", scope.makeOpName("BitwiseAnd"));
7070
opBuilder.addInput(x.asOutput());
7171
opBuilder.addInput(y.asOutput());
72-
opBuilder = scope.applyControlDependencies(opBuilder);
72+
opBuilder = scope.apply(opBuilder);
7373
return new BitwiseAnd<T>(opBuilder.build());
7474
}
7575

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/op/bitwise/BitwiseOr.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static <T extends TNumber> BitwiseOr<T> create(Scope scope, Operand<T> x,
6969
OperationBuilder opBuilder = scope.env().opBuilder("BitwiseOr", scope.makeOpName("BitwiseOr"));
7070
opBuilder.addInput(x.asOutput());
7171
opBuilder.addInput(y.asOutput());
72-
opBuilder = scope.applyControlDependencies(opBuilder);
72+
opBuilder = scope.apply(opBuilder);
7373
return new BitwiseOr<T>(opBuilder.build());
7474
}
7575

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/op/bitwise/BitwiseXor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static <T extends TNumber> BitwiseXor<T> create(Scope scope, Operand<T> x
6969
OperationBuilder opBuilder = scope.env().opBuilder("BitwiseXor", scope.makeOpName("BitwiseXor"));
7070
opBuilder.addInput(x.asOutput());
7171
opBuilder.addInput(y.asOutput());
72-
opBuilder = scope.applyControlDependencies(opBuilder);
72+
opBuilder = scope.apply(opBuilder);
7373
return new BitwiseXor<T>(opBuilder.build());
7474
}
7575

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/op/bitwise/Invert.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public final class Invert<T extends TNumber> extends RawOp implements Operand<T>
8888
public static <T extends TNumber> Invert<T> create(Scope scope, Operand<T> x) {
8989
OperationBuilder opBuilder = scope.env().opBuilder("Invert", scope.makeOpName("Invert"));
9090
opBuilder.addInput(x.asOutput());
91-
opBuilder = scope.applyControlDependencies(opBuilder);
91+
opBuilder = scope.apply(opBuilder);
9292
return new Invert<T>(opBuilder.build());
9393
}
9494

0 commit comments

Comments
 (0)