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
[SR-7765] Lack of support for imperfect loop exits blocking simpleCounterLoop test #50304
Comments
Comment by Mingsheng Hong (JIRA) Another test case for Gogul :-) public func mockMLPTrainingStep(x: Tensor<Float>, y: Tensor<Float>, numLayers: Int32) {
let initWeights = [Float](repeating: 0.0, count: Int(numLayers))
// TODO: remove this once we fix compiler bug
let _ = Tensor<Float>(0.0)
var W = Tensor<Float>(shape: TensorShape(numLayers), scalars: initWeights)
// The activations of a hidden layer, initialized to the input layer.
var h = x
var i: Int32 = 0
// while i != numLayers {
for i in 0..<numLayers {
let layerW = Raw.gatherV2(
params: W,
indices: Tensor<Int32>(i),
axis: Tensor<Int32>(0))
h = relu(layerW * h)
// i += 1
}
} |
Comment by Mingsheng Hong (JIRA) Simplified: public func foo(N: Int32) {
var a = Tensor<Float>(1.0)
// var i: Int32 = 0
// while i < N {
for _ in 0..<N {
a += a
// i += 1
}
_hostOp(a)
}
|
Comment by Gogul Balakrishnan (JIRA) Ming, the simplified example causes a crash: %99 = builtin "cmp_ult_Int32"(%96 : $Builtin.Int32, %92 : $Builtin.Int32) : $Builtin.Int1 // user: %102
Unexpected instruction type!
UNREACHABLE executed at /usr/local/google/home/bgogul/workspace/brain/s4tf/swift/lib/SILOptimizer/Mandatory/TFPartition.cpp:2712! Can you reproduce it on your branch? |
Comment by Mingsheng Hong (JIRA) Sorry – I believe we'll need #17890 first |
Comment by Gogul Balakrishnan (JIRA) Relevant PRs:
More changes are needed. |
Comment by Gogul Balakrishnan (JIRA) One more PR: #18122 |
Comment by Gogul Balakrishnan (JIRA) One more PR: #19811 |
Comment by Gogul Balakrishnan (JIRA) Cleanup TFNoUndefsInSESE flag: #20611 |
Comment by Gogul Balakrishnan (JIRA) Cleanup remaining flag: #20634 |
Additional Detail from JIRA
md5: 4693077c5208bb49c990afc7cee0adbf
Issue Description:
Here is simple example and command line to reproduce the issue:
// buggy.swift
import TensorFlow
public func foo() {
let maxCount: Int32 = 100
var a = Tensor<Int32>(0)
let b = Tensor<Int32>(1)
var count: Int32 = 0
a -= b
while count < maxCount {
a += b
count += 1
if count == 50 {
break
}
// a += b
}
a -= b
print(a)
}
foo()
build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/bin/swift -Xllvm --tf-dump-intermediates -Xllvm --tf-dump-graph -O buggy.swift
The crash is at:
SESE FIXME: Loops with multiple exits not handled yet!
UNREACHABLE executed at .../swift/lib/SILOptimizer/Mandatory/TFCanonicalizeCFG.cpp:261!
The input to partition pass is:
// foo()
sil @$S9B731014403fooyyF : $@convention(thin) () -> () {
bb0:
%0 = integer_literal $Builtin.Int32, 100 // user: %22
%1 = integer_literal $Builtin.Int32, 0 // user: %2
%2 = builtin "__tfop_tfc.scalarToTensor,$in"(%1 : $Builtin.Int32) : $TensorHandle<Int32> // users: %9, %8, %6
%3 = integer_literal $Builtin.Int32, 1 // users: %19, %31, %4
%4 = builtin "__tfop_tfc.scalarToTensor,$in"(%3 : $Builtin.Int32) : $TensorHandle<Int32> // users: %18, %16, %15, %13, %70, %44, %41, %40, %38, %30, %28, %27, %25, %10, %8, %7, %5
strong_retain %4 : $TensorHandle<Int32> // id: %5
strong_retain %2 : $TensorHandle<Int32> // id: %6
strong_retain %4 : $TensorHandle<Int32> // id: %7
%8 = builtin "__tfop_Sub,$in,$in"(%2 : $TensorHandle<Int32>, %4 : $TensorHandle<Int32>) : $TensorHandle<Int32> // users: %17, %16, %14
strong_release %2 : $TensorHandle<Int32> // id: %9
strong_release %4 : $TensorHandle<Int32> // id: %10
%11 = integer_literal $Builtin.Int1, -1 // user: %31
%12 = integer_literal $Builtin.Int32, 50 // user: %33
strong_retain %4 : $TensorHandle<Int32> // id: %13
strong_retain %8 : $TensorHandle<Int32> // id: %14
strong_retain %4 : $TensorHandle<Int32> // id: %15
%16 = builtin "__tfop_Add,$in,$in"(%8 : $TensorHandle<Int32>, %4 : $TensorHandle<Int32>) : $TensorHandle<Int32> // user: %19
strong_release %8 : $TensorHandle<Int32> // id: %17
strong_release %4 : $TensorHandle<Int32> // id: %18
br bb1(%16 : $TensorHandle<Int32>, %3 : $Builtin.Int32) // id: %19
// %20 // users: %24, %29, %28, %26
// %21 // users: %31, %22
bb1(%20 : $TensorHandle<Int32>, %21 : $Builtin.Int32): // Preds: bb4 bb0
%22 = builtin "cmp_slt_Int32"(%21 : $Builtin.Int32, %0 : $Builtin.Int32) : $Builtin.Int1 // user: %23
cond_br %22, bb3, bb2 // id: %23
bb2: // Preds: bb1
br bb6(%20 : $TensorHandle<Int32>) // id: %24
bb3: // Preds: bb1$Builtin.Int1) : $ (Builtin.Int32, Builtin.Int1) // user: %32
strong_retain %4 : $TensorHandle<Int32> // id: %25
strong_retain %20 : $TensorHandle<Int32> // id: %26
strong_retain %4 : $TensorHandle<Int32> // id: %27
%28 = builtin "__tfop_Add,$in,$in"(%20 : $TensorHandle<Int32>, %4 : $TensorHandle<Int32>) : $TensorHandle<Int32> // users: %35, %36
strong_release %20 : $TensorHandle<Int32> // id: %29
strong_release %4 : $TensorHandle<Int32> // id: %30
%31 = builtin "sadd_with_overflow_Int32"(%21 : $Builtin.Int32, %3 : $Builtin.Int32, %11 :
%32 = tuple_extract %31 : $(Builtin.Int32, Builtin.Int1), 0 // users: %35, %33
%33 = builtin "cmp_eq_Int32"(%32 : $Builtin.Int32, %12 : $Builtin.Int32) : $Builtin.Int1 // user: %34
cond_br %33, bb5, bb4 // id: %34
bb4: // Preds: bb3
br bb1(%28 : $TensorHandle<Int32>, %32 : $Builtin.Int32) // id: %35
bb5: // Preds: bb3
br bb6(%28 : $TensorHandle<Int32>) // id: %36
// %37 // users: %39, %41, %43
bb6(%37 : $TensorHandle<Int32>): // Preds: bb5 bb2
strong_retain %4 : $TensorHandle<Int32> // id: %38
strong_retain %37 : $TensorHandle<Int32> // id: %39
strong_retain %4 : $TensorHandle<Int32> // id: %40
%41 = builtin "__tfop_Sub,$in,$in"(%37 : $TensorHandle<Int32>, %4 : $TensorHandle<Int32>) : $TensorHandle<Int32> // users: %71, %62, %42
%42 = struct $Tensor<Int32> (%41 : $TensorHandle<Int32>) // user: %63
strong_release %37 : $TensorHandle<Int32> // id: %43
strong_release %4 : $TensorHandle<Int32> // id: %44
%45 = integer_literal $Builtin.Word, 1 // user: %48
%46 = integer_literal $Builtin.Int64, 1 // user: %47
%47 = struct $Int (%46 : $Builtin.Int64) // user: %52
%48 = alloc_ref [tail_elems $Any * %45 : $Builtin.Word] $_ContiguousArrayStorage<Any> // user: %49
%49 = upcast %48 : $_ContiguousArrayStorage<Any> to $_ContiguousArrayStorageBase // users: %59, %60, %58, %56, %54
%50 = integer_literal $Builtin.Int64, 2 // user: %51
%51 = struct $UInt (%50 : $Builtin.Int64) // user: %52
%52 = struct $_SwiftArrayBodyStorage (%47 : $Int, %51 : $UInt) // user: %53
%53 = struct $_ArrayBody (%52 : $_SwiftArrayBodyStorage) // user: %55
%54 = ref_element_addr %49 : $_ContiguousArrayStorageBase, #_ContiguousArrayStorageBase.countAndCapacity // user: %55
store %53 to %54 : $*_ArrayBody // id: %55
%56 = struct $_ContiguousArrayBuffer<Any> (%49 : $_ContiguousArrayStorageBase) // user: %57
%57 = struct $Array<Any> (%56 : $_ContiguousArrayBuffer<Any>) // user: %69
%58 = ref_tail_addr %49 : $_ContiguousArrayStorageBase, $Any // user: %61
strong_retain %49 : $_ContiguousArrayStorageBase // id: %59
strong_release %49 : $_ContiguousArrayStorageBase // id: %60
%61 = init_existential_addr %58 : $*Any, $Tensor<Int32> // user: %63
strong_retain %41 : $TensorHandle<Int32> // id: %62
store %42 to %61 : $*Tensor<Int32> // id: %63
// function_ref default argument 1 of print(_:separator:terminator🙂
%64 = function_ref @$Ss5print_9separator10terminatoryypd_S2StFfA0_ : $@convention(thin) () -> @owned String // user: %65
%65 = apply %64() : $@convention(thin) () -> @owned String // user: %69
// function_ref default argument 2 of print(_:separator:terminator🙂
%66 = function_ref @$Ss5print_9separator10terminatoryypd_S2StFfA1_ : $@convention(thin) () -> @owned String // user: %67
%67 = apply %66() : $@convention(thin) () -> @owned String // user: %69
// function_ref print(_:separator:terminator🙂
%68 = function_ref @$Ss5print_9separator10terminatoryypd_S2StF : $@convention(thin) (@owned Array<Any>, @owned String, @owned String) -> () // user: %69
%69 = apply %68(%57, %65, %67) : $@convention(thin) (@owned Array<Any>, @owned String, @owned String) -> ()
strong_release %4 : $TensorHandle<Int32> // id: %70
strong_release %41 : $TensorHandle<Int32> // id: %71
%72 = tuple () // user: %73
return %72 : $() // id: %73
} // end sil function '$S9B731014403fooyyF'
The text was updated successfully, but these errors were encountered: