Skip to content
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-13333] Control flow differentiation crash for bb argument with loadable type, address-only tangent type #55773

Open
dan-zheng opened this issue Jul 31, 2020 · 1 comment
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@dan-zheng
Copy link
Collaborator

Previous ID SR-13333
Radar rdar://problem/73388882
Original Reporter @dan-zheng
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, AutoDiff, CompilerCrash
Assignee None
Priority Medium

md5: bb1c156db6a6cef9587ca5c447c5cd8c

Issue Description:

import _Differentiation

class Class<T: Differentiable>: Differentiable {
  var x: T
  let bool: Bool = true

  init(_ x: T) {
    self.x = x
  }
}

@differentiable
func foo<T: Differentiable>(_ c: Class<T>) -> Class<T> {
  if c.bool {
    return c
  }
  return c
}

Crash:

$ swiftc crash.swift
Assertion failed: (getTangentValueCategory(originalValue) == SILValueCategory::Object), function getAdjointValue, file /Users/danielzheng/swift-merge/swift/lib/SILOptimizer/Differentiation/PullbackCloner.cpp, line 469.
Stack dump:
0.  Program arguments: /Users/danielzheng/swift-merge/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-frontend -frontend -c -primary-file crash.swift -target x86_64-apple-darwin19.4.0 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.16.sdk -color-diagnostics -target-sdk-version 10.16 -module-name crash -o /var/folders/m_/6f7q8zfs3n9fr0c_4gy8840m00hc_q/T/crash-3da463.o
1.  Swift version 5.3-dev (LLVM 5b20e5d73717a73, Swift 3ce6bf550a8947d)
2.  While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for crash.crash)
3.  While running pass #&#8203;207 SILModuleTransform "Differentiation".
4.  While processing // differentiability witness for foo<A>(_:)
sil_differentiability_witness hidden [parameters 0] [results 0] <T where T : Differentiable> @$s5crash3fooyAA5ClassCyxGAE16_Differentiation14DifferentiableRzlF : $@convention(thin) <T where T : Differentiable> (@guaranteed Class<T>) -> @owned Class<T> {
}

 on SIL function "@$s5crash3fooyAA5ClassCyxGAE16_Differentiation14DifferentiableRzlF".
 for 'foo(_:)' (at crash.swift:18:1)
5.  While generating VJP for SIL function "@$s5crash3fooyAA5ClassCyxGAE16_Differentiation14DifferentiableRzlF".
 for 'foo(_:)' (at crash.swift:18:1)
6.  While generating pullback for SIL function "@$s5crash3fooyAA5ClassCyxGAE16_Differentiation14DifferentiableRzlF".
 for 'foo(_:)' (at crash.swift:18:1)
0  swift-frontend           0x0000000106ac0165 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift-frontend           0x0000000106abf138 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x0000000106ac0746 SignalHandler(int) + 262
3  libsystem_platform.dylib 0x00007fff6a3e15fd _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338733709856
5  libsystem_c.dylib        0x00007fff6a2b7808 abort + 120
6  libsystem_c.dylib        0x00007fff6a2b6ac6 err + 0
7  swift-frontend           0x0000000106ca95b3 swift::autodiff::PullbackCloner::Implementation::getAdjointValue(swift::SILBasicBlock*, swift::SILValue) (.cold.2) + 35
8  swift-frontend           0x0000000102b0b022 swift::autodiff::PullbackCloner::Implementation::getAdjointValue(swift::SILBasicBlock*, swift::SILValue) + 274
9  swift-frontend           0x0000000102b0828f swift::autodiff::PullbackCloner::Implementation::visitSILBasicBlock(swift::SILBasicBlock*) + 1391
10 swift-frontend           0x0000000102b05424 swift::autodiff::PullbackCloner::Implementation::run() + 6452

The crash occurs because basic block adjoint value propagation logic in PullbackCloner::Implementation::visitSILBasicBlock assumes that active bb arguments have loadable TangentVector types, not address-only TangentVector types.

@airspeedswift
Copy link
Member

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

3 participants