Skip to content

Commit 841526c

Browse files
authored
Remove TFSendRecvOpaqueHandle flag (#21733)
1 parent 134500f commit 841526c

File tree

3 files changed

+2
-80
lines changed

3 files changed

+2
-80
lines changed

lib/SILOptimizer/Mandatory/TFPartition.cpp

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ static llvm::cl::opt<bool> TFWarnScalarTransfer(
6767
"Emit warnings for sends/receives that transfer values that are "
6868
"known to be scalar."));
6969

70-
// TODO: Remove this short-term flag once we migrate over all unit tests.
71-
static llvm::cl::opt<bool> TFSendRecvOpaqueHandle(
72-
"tf-send-recv-opaque-handle", llvm::cl::init(true),
73-
llvm::cl::desc("When true, variant and resource handles can be sent via "
74-
"eager API as tensor handles."));
75-
7670
template <typename... T, typename... U>
7771
static InFlightDiagnostic diagnose(ASTContext &Context, SourceLoc loc,
7872
Diag<T...> diag, U &&... args) {
@@ -789,7 +783,6 @@ class TFFunctionPartition {
789783
void diagnoseUsesFromHost(SILValue value, SILLocation loc);
790784
void diagnoseCopyToHost(SILValue value, SILInstruction *user,
791785
SILLocation loc);
792-
void diagnoseOpaqueHandleCopy(SILValue value, SILInstruction *user);
793786

794787
private:
795788
// Marking.
@@ -932,13 +925,6 @@ void TFFunctionPartition::diagnoseCopyToAccelerator(
932925
// Try to determine a good source location to report.
933926
auto loc = getUserSourceLocation(value);
934927

935-
// Opaque handles can never be sent or passed as tensor program arguments.
936-
// Type checking must have rejected host functions that are either a)
937-
// public with private ABI or b) marked @inline(never).
938-
assert(TFSendRecvOpaqueHandle ||
939-
(!isOpaqueHandle(value->getType()) &&
940-
"Opaque handles should never have been on the host"));
941-
942928
// Try to make a useful description of the value being copied to help
943929
// disambiguate.
944930
std::string description = "value";
@@ -1040,12 +1026,6 @@ void TFFunctionPartition::diagnoseUsesFromHost(SILValue value,
10401026
if (isUserIgnoredByPartitioning(user))
10411027
continue;
10421028

1043-
// If the value is a non-copyable opaque handle, emit an error.
1044-
if (!TFSendRecvOpaqueHandle && isOpaqueHandle(value->getType())) {
1045-
diagnoseOpaqueHandleCopy(value, user);
1046-
continue;
1047-
}
1048-
10491029
// If we are running this in the context of an expression run in the REPL or
10501030
// playgrounds, or script mode, then we should never emit a warning: we know
10511031
// we're going to be implicitly copying things in as warnings all the time.
@@ -1105,20 +1085,6 @@ void TFFunctionPartition::diagnoseCopyToHost(SILValue value,
11051085
}
11061086
}
11071087

1108-
/// Emit an error for invalid send/receive of opaque handles.
1109-
void TFFunctionPartition::diagnoseOpaqueHandleCopy(SILValue value,
1110-
SILInstruction *user) {
1111-
assert(!TFSendRecvOpaqueHandle);
1112-
assert(isOpaqueHandle(value->getType()) &&
1113-
"Shouldn't emit an error for opaque handle copy when the value is not "
1114-
"an opaque handle");
1115-
auto &ctx = value->getFunction()->getASTContext();
1116-
diagnose(ctx, getUserSourceLocation(value).getSourceLoc(),
1117-
diag::tfop_value_no_send_receive);
1118-
diagnose(ctx, getUserSourceLocation(user).getSourceLoc(),
1119-
diag::tf_value_used_here);
1120-
}
1121-
11221088
/// Some instruction in the specified block needs to be split out to the
11231089
/// accelerator, so we mark it (and its control dependencies) as to-be-moved
11241090
/// over.
@@ -3718,19 +3684,6 @@ void TFFunctionPartition::balanceRetainReleaseCount(SILValue oldResult,
37183684

37193685
void TFFunctionPartition::insertReplacementGraphOp(
37203686
ArrayRef<SILValue> resultValues) {
3721-
// Sanity check that all result values are tensor handles. Note SIL
3722-
// accelerator functions under the "tensorflow" convention can also return
3723-
// variant and resource tensors (in addition to tensor handles), but such
3724-
// functions will not generate all host-side code, and thus this method will
3725-
// not be called.
3726-
assert(TFSendRecvOpaqueHandle ||
3727-
llvm::all_of(resultValues,
3728-
[](SILValue resultValue) {
3729-
return isTensorHandle(resultValue->getType());
3730-
}) &&
3731-
"Cannot return a non-TensorHandle value to host in the TF program "
3732-
"-- should this function use tensorflow convention?");
3733-
37343687
auto &ctx = hostFn.getASTContext();
37353688
auto loc = hostFn.getLocation();
37363689

@@ -3775,17 +3728,6 @@ void TFFunctionPartition::insertReplacementGraphOp(
37753728

37763729
void TFFunctionPartition::insertTensorComputationStartEndTerminate(
37773730
ArrayRef<SILValue> resultValues) {
3778-
// Sanity check that all result values are tensor handles. Note SIL
3779-
// accelerator functions under the "tensorflow" convention can also return
3780-
// variant and resource tensors (in addition to tensor handles), but such
3781-
// functions will not generate all host-side code, and thus this method will
3782-
// not be called.
3783-
for (auto resultValue : resultValues) {
3784-
assert(TFSendRecvOpaqueHandle || isTensorHandle(resultValue->getType()) &&
3785-
"Cannot return a non-TensorHandle value to host in the TF program "
3786-
"-- should this function use tensorflow convention?");
3787-
}
3788-
37893731
auto &ctx = hostFn.getASTContext();
37903732
auto loc = hostFn.getLocation();
37913733

@@ -3925,8 +3867,7 @@ void TFFunctionPartition::insertTensorComputationStartEndTerminate(
39253867
// closed over. If it is a TensorHandle<T>, load the CTensorHandle out of
39263868
// it. If it is a scalar, then we need to box the scalar in a
39273869
// CTensorHandle.
3928-
if ((TFSendRecvOpaqueHandle &&
3929-
isTensorFlowValue(tensorValue->getType().getASTType())) ||
3870+
if (isTensorFlowValue(tensorValue->getType().getASTType()) ||
39303871
isTensorHandle(tensorValue->getType().getASTType())) {
39313872
// Upcast to _AnyTensorHandle.
39323873
tensorValue = B.createUpcast(loc, tensorValue, anyTensorHandleSILTy);
@@ -4209,15 +4150,6 @@ bool TFFunctionPartition::partition(bool isTest) {
42094150
continue;
42104151
}
42114152

4212-
// If it's an opaque handle such as VariantHandle or ResourceHandle,
4213-
// it cannot be a result except when it's being returned in an
4214-
// accelerator-only function.
4215-
if (!TFSendRecvOpaqueHandle && isOpaqueHandle(result->getType()) &&
4216-
!(isAcceleratorOnly(hostFn) && isReturning(user))) {
4217-
diagnoseOpaqueHandleCopy(result, user);
4218-
return true;
4219-
}
4220-
42214153
// Remember if the instruction has any use. If not, then it never
42224154
// needs to be sent or returned.
42234155
hasAnyUse = true;

test/TensorFlowRuntime/dataset_global.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// TODO: Revert to %target-run-simple-swift once we complete send/recv support for resource/variant tensors.
2-
// RUN: %target-run-send-recv-handle-swift %swift-tensorflow-test-run-extra-options
1+
// RUN: %target-run-simple-swift %swift-tensorflow-test-run-extra-options
32
// RUN: %target-run-dynamic-compilation-swift %swift-tensorflow-test-run-extra-options
43
// REQUIRES: executable_test
54
// REQUIRES: swift_test_mode_optimize

test/lit.cfg

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,6 @@ def use_interpreter_for_simple_runs():
635635
# tests to the new code path (when the flag is true).
636636
config.target_run_simple_swift_use_device_stack = (
637637
"%s %%s -Xllvm -tf-use-device-stack" % (target_run_base))
638-
config.target_run_simple_swift_send_recv_handle = (
639-
"%s %%s -Xllvm -tf-send-recv-opaque-handle" % (target_run_base))
640638
config.target_run_swift_dynamic_compilation = (
641639
"%s %%s -Xllvm -tf-dynamic-compilation" % (target_run_base))
642640
config.target_run_simple_swiftgyb = (
@@ -1144,12 +1142,6 @@ if not getattr(config, 'target_run_simple_swift', None):
11441142
'%s %%t/a.out &&'
11451143
'%s %%t/a.out'
11461144
% (config.target_build_swift, mcp_opt, swift_tensorflow_extra_options, config.target_codesign, config.target_run))
1147-
config.target_run_simple_swift_send_recv_handle = (
1148-
'%%empty-directory(%%t) && '
1149-
'%s %s %%s -Xllvm -tf-send-recv-opaque-handle -o %%t/a.out -module-name main %s && '
1150-
'%s %%t/a.out &&'
1151-
'%s %%t/a.out'
1152-
% (config.target_build_swift, mcp_opt, swift_tensorflow_extra_options, config.target_codesign, config.target_run))
11531145
config.target_run_swift_dynamic_compilation = (
11541146
'%%empty-directory(%%t) && '
11551147
'%s %s %%s -Xllvm -tf-dynamic-compilation -DTF_DYNAMIC_COMPILATION -o %%t/a.out -module-name main %s && '
@@ -1306,7 +1298,6 @@ config.substitutions.append(('%target-run-simple-swift-swift3', config.target_ru
13061298
config.substitutions.append(('%target-run-simple-swift', config.target_run_simple_swift))
13071299
# SWIFT_ENABLE_TENSORFLOW
13081300
config.substitutions.append(('%target-run-use-device-stack-swift', config.target_run_simple_swift_use_device_stack))
1309-
config.substitutions.append(('%target-run-send-recv-handle-swift', config.target_run_simple_swift_send_recv_handle))
13101301
config.substitutions.append(('%target-run-dynamic-compilation-swift', config.target_run_swift_dynamic_compilation))
13111302
config.substitutions.append(('%target-run-simple-no-vjp-swift', config.target_run_simple_no_vjp_swift))
13121303
config.substitutions.append(('%target-run-simple-parse-stdlib-swift', config.target_run_simple_parse_stdlib_swift))

0 commit comments

Comments
 (0)