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-11856] [AutoDiff] Linear function component extraction crasher #54263

Closed
rxwei opened this issue Nov 26, 2019 · 5 comments
Closed

[SR-11856] [AutoDiff] Linear function component extraction crasher #54263

rxwei opened this issue Nov 26, 2019 · 5 comments
Assignees
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@rxwei
Copy link
Member

rxwei commented Nov 26, 2019

Previous ID SR-11856
Radar None
Original Reporter @rxwei
Type Bug
Status Closed
Resolution Won't Do
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, AutoDiff
Assignee @rxwei
Priority Medium

md5: c555fa04d5247fec54692416e79752d1

relates to:

  • TF-851 [AD] Robust SILGen thunking for @differentiable functions

Issue Description:

import Swift
func foo(_ x: Float) -> Float {
  return 2 * x
}
func foo_transpose(_ v: Float) -> Float {
  return v
}
let lin_foo = Builtin.linearFunction_arity1(foo, foo_transpose)
let trans_foo = transpose(of: lin_foo)
expectEqual(2, trans_foo(2))

Compile this with swiftc -parse-stdlib, then you'll get

Assertion failed: (fnTy->getDifferentiabilityKind() == DifferentiabilityKind::Normal), function getExtracteeType, file /Users/rxwei/Development/Swift/swift-tf-source/swift/lib/SIL/SILInstructions.cpp, line 701.
Stack dump:
0.  Program arguments: /Users/rxwei/Development/Swift/swift-tf-source/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64/bin/swift -frontend -c -primary-file linear.swift -disable-objc-attr-requires-foundation-module -target x86_64-apple-darwin19.0.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -parse-stdlib -module-name linear -o /var/folders/f7/gx5hq4810p19_3432sb8yfkw0000gn/T/linear-a6b94a.o
1.  Swift version 5.1.1-dev (Swift 658b7f7ddc)
0  swift                    0x0000000112e83e85 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x0000000112e82e88 llvm::sys::RunSignalHandlers() + 248
2  swift                    0x0000000112e84478 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff6f494b1d _sigtramp + 29
4  swift                    0x0000000114a86201 cmark_strbuf__initbuf + 127468
5  libsystem_c.dylib        0x00007fff6f36aa1c abort + 120
6  libsystem_c.dylib        0x00007fff6f369cd6 err + 0
7  swift                    0x00000001130fdb83 swift::DifferentiableFunctionExtractInst::getExtracteeType(swift::SILValue, swift::NormalDifferentiableFunctionTypeComponent, swift::SILModule&) (.cold.7) + 35
8  swift                    0x000000010fe645b6 swift::DifferentiableFunctionExtractInst::getExtracteeType(swift::SILValue, swift::NormalDifferentiableFunctionTypeComponent, swift::SILModule&) + 278
9  swift                    0x000000010fe6461e swift::DifferentiableFunctionExtractInst::DifferentiableFunctionExtractInst(swift::SILModule&, swift::SILDebugLocation, swift::NormalDifferentiableFunctionTypeComponent, swift::SILValue, llvm::Optional<swift::SILType>) + 78
10 swift                    0x000000010f9510dc createThunk(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeLowering const&) + 2636
11 swift                    0x000000010f948a26 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::SGFContext) + 2374
12 swift                    0x000000010f947bcb swift::Lowering::SILGenFunction::emitSubstToOrigValue(swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::SGFContext) + 171
13 swift                    0x000000010f8d5fb9 swift::Lowering::Conversion::emit(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::SGFContext) const + 745
14 swift                    0x000000010f8d5c1e swift::Lowering::ConvertingInitialization::finishEmission(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue) + 94
15 swift                    0x000000010f8d5a80 swift::Lowering::SILGenFunction::emitConvertedRValue(swift::SILLocation, swift::Lowering::Conversion const&, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>) + 384
16 swift                    0x000000010f87373f swift::Lowering::ArgumentSource::getConverted(swift::Lowering::SILGenFunction&, swift::Lowering::Conversion const&, swift::Lowering::SGFContext) && + 159
17 swift                    0x000000010f8a78db (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 3627
18 swift                    0x000000010f894416 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 70
19 swift                    0x000000010f8b1a03 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 147
20 swift                    0x000000010f8b17b9 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus) && + 713
21 swift                    0x000000010f8b113b (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::CanTypeWrapper<swift::FunctionType>&, swift::Lowering::AbstractionPattern&, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&, swift::CanTypeWrapper<swift::FunctionType>&) + 1787
22 swift                    0x000000010f8977a2 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3186
23 swift                    0x000000010f896a98 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 2408
24 swift                    0x000000010f8f577a swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 106
25 swift                    0x000000010f8e878f swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional<swift::SILLocation>) + 303
26 swift                    0x000000010f8da41f swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 335
27 swift                    0x000000010f8da4fd swift::Lowering::SILGenFunction::visitPatternBindingDecl(swift::PatternBindingDecl*) + 45
28 swift                    0x000000010f88c742 swift::Lowering::SILGenModule::visitTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 530
29 swift                    0x000000010f88cc63 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 915
30 swift                    0x000000010f88dbc4 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions&, swift::FileUnit*) + 308
31 swift                    0x000000010f88e026 swift::performSILGeneration(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions&) + 38
32 swift                    0x000000010f582005 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 7477
33 swift                    0x000000010f57f37a swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2874
34 swift                    0x000000010f524699 main + 729
35 libdyld.dylib            0x00007fff6f2932e5 start + 1
36 libdyld.dylib            0x0000000000000011 start + 2429996333
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)
@rxwei
Copy link
Member Author

rxwei commented Nov 26, 2019

This is because createAutoDiffThunk does not handle linear functions yet.

@rxwei
Copy link
Member Author

rxwei commented Nov 26, 2019

I pushed some WIP to rxwei:SR-11856: https://github.com/apple/swift/compare/tensorflow...rxwei:SR-11856?expand=1.

The biggest complexity in fixing this is to implement AnyFunctionType::getAutoDiffTransposeFunctionType, which does not yet exist. This should be a high priority as this blocks testing linear functions and implementing transposition.

@rxwei
Copy link
Member Author

rxwei commented Nov 26, 2019

@marcrasi This could be a good thing to tackle after retrodiff 🙂

@dan-zheng
Copy link
Collaborator

Related createAutoDiffThunk issue: TF-851. See bottom of issue for some WIP, it's not ideal though.

@dan-zheng
Copy link
Collaborator

The biggest complexity in fixing this is to implement AnyFunctionType::getAutoDiffTransposeFunctionType, which does not yet exist. This should be a high priority as this blocks testing linear functions and implementing transposition.

AnyFunctionType::getAutoDiffTransposeFunctionType also seems relevant for finalizing @transpose(of🙂 type-checking rules: TF-1003.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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
Projects
None yet
Development

No branches or pull requests

2 participants