Skip to content

[AutoDiff] Change cross-file derivative registration to a frontend flag. #29339

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

Merged
merged 2 commits into from
Jan 23, 2020

Conversation

dan-zheng
Copy link
Contributor

Change -enable-experimental-cross-file-derivative-registration from an
-Xllvm flag to a -Xfrontend flag.

This makes the flag consistent with:

  • -enable-experimental-differentiable-programming
  • -enable-experimental-forward-mode-differentiation

Change `-enable-experimental-cross-file-derivative-registration` from an
`-Xllvm` flag to a `-Xfrontend` flag.

This makes the flag consistent with:
- `-enable-experimental-differentiable-programming`
- `-enable-experimental-forward-mode-differentiation`
@dan-zheng dan-zheng added the tensorflow This is for "tensorflow" branch PRs. label Jan 21, 2020
@dan-zheng dan-zheng requested review from rxwei and marcrasi January 21, 2020 21:17
// RUN: %target-build-swift -Xllvm -enable-experimental-cross-file-derivative-registration -I %S/Inputs -I %t %s %t/CForeign.o
// RUN: %target-swift-emit-silgen -enable-experimental-cross-file-derivative-registration -I %S/Inputs -I %t %s | %FileCheck %s --check-prefix=CHECK-SILGEN --check-prefix=CHECK
// RUN: %target-swift-emit-sil -enable-experimental-cross-file-derivative-registration -I %S/Inputs -I %t %s | %FileCheck %s --check-prefix=CHECK-SIL --check-prefix=CHECK
// RUN: %target-build-swift -Xfrontend -enable-experimental-cross-file-derivative-registration -I %S/Inputs -I %t %s %t/CForeign.o
Copy link
Contributor

@rxwei rxwei Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need -Xfrontend when using the frontend. swiftc -enable-experimental... or swift -enable-experimental... should just work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing -Xfrontend from this RUN line doesn't work, I tried it.

$ llvm-project/llvm/utils/lit/lit.py -vvv build/Ninja-ReleaseAssert/swift-macosx-x86_64/test-macosx-x86_64/AutoDiff/downstream/derivative_registration_foreign
...
: 'RUN: at line 5';   xcrun --toolchain default --sdk '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk' /Users/danielzheng/swift-dev/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swiftc -target x86_64-apple-macosx10.9  -module-cache-path '/Users/danielzheng/swift-dev/build/Ninja-ReleaseAssert/swift-macosx-x86_64/swift-test-results/x86_64-apple-macosx10.9/clang-module-cache' -F '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks' -toolchain-stdlib-rpath -Xlinker -rpath -Xlinker '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks'  -swift-version 4  -Xfrontend -ignore-module-source-info  -F '/Users/danielzheng/swift-dev/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib' -Xlinker -rpath -Xlinker '/Users/danielzheng/swift-dev/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib' -enable-experimental-cross-file-derivative-registration -I /Users/danielzheng/swift-dev/swift/test/AutoDiff/downstream/derivative_registration_foreign/Inputs -I /Users/danielzheng/swift-dev/build/Ninja-ReleaseAssert/swift-macosx-x86_64/test-macosx-x86_64/AutoDiff/downstream/derivative_registration_foreign/Output/main.swift.tmp /Users/danielzheng/swift-dev/swift/test/AutoDiff/downstream/derivative_registration_foreign/main.swift /Users/danielzheng/swift-dev/build/Ninja-ReleaseAssert/swift-macosx-x86_64/test-macosx-x86_64/AutoDiff/downstream/derivative_registration_foreign/Output/main.swift.tmp/CForeign.o
--
Exit Code: 1

Command Output (stderr):
--
/Users/danielzheng/swift-dev/swift/test/AutoDiff/downstream/derivative_registration_foreign/main.swift:28:2: error: derivative not in the same file as the original function
@derivative(of: cFunction)
 ^

This was unexpected to me too (swift -enable-experimental... doesn't always work), I noticed it for a while. Perhaps the options aren't registered properly in Options.td - we can investigate more later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct, the frontend flags are unsupported options, that is, they are within the purview of the compiler and may be changed at anytime (including having the behavior be entirely the opposite of the previous release). If you are using the driver (that is swiftc) you must specify -Xfrontend for the flag.

For this option, I believe that the current approach is desirable anyways as longer term we would like to remove the -enable-experimental-cross-file-derivative-registration flag and simply enable it unconditionally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rxwei I think that the confusion here may be related to the use of %target-build-swift which actually uses the driver and not the frontend.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I normally use %target-swift-frontend. Is there a reason we need to use %target-build-swift here, @dan-zheng ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%target-build-swift is closer to how normal swift compilation works, making the test more realistic so that it catches more bugs. I don't know exactly what the differences are, but I have observed that some symbols that are visible when you compile with %target-swift-frontend are actually hidden when you compile normally. Also, %target-build-swift respects swift_test_mode=optimize, so that it tests both -Onone and -O compilation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@dan-zheng
Copy link
Contributor Author

@swift-ci Please test tensorflow

@dan-zheng
Copy link
Contributor Author

@swift-ci Please clean test tensorflow linux

@CodaFi
Copy link
Contributor

CodaFi commented Jan 22, 2020

Is the intent for this to become a driver flag?

@dan-zheng
Copy link
Contributor Author

Is the intent for this to become a driver flag?

Perhaps yes. We noticed that {swift,swiftc} -enable-experimental-cross-file-derivative-registration doesn't always work (#29339 (comment)), sometimes requiring -Xfrontend. I haven't investigated further yet.

To support {swift,swiftc} -enable-experimental-cross-file-derivative-registration, would you recommend making it a driver flag?

@compnerd
Copy link
Member

To support {swift,swiftc} -enable-experimental-cross-file-derivative-registration, would you recommend making it a driver flag?

Given that we want to have this flag not be required in general I think that this being a frontend flag makes more sense (the user explicitly opts into this under the agreement that they are aware of what they are doing and realize that this behaviour may change).

@rxwei
Copy link
Contributor

rxwei commented Jan 23, 2020

To support {swift,swiftc} -enable-experimental-cross-file-derivative-registration, would you recommend making it a driver flag?

Given that we want to have this flag not be required in general I think that this being a frontend flag makes more sense (the user explicitly opts into this under the agreement that they are aware of what they are doing and realize that this behaviour may change).

Makes sense.

// RUN: %target-build-swift -Xllvm -enable-experimental-cross-file-derivative-registration -I %S/Inputs -I %t %s %t/CForeign.o
// RUN: %target-swift-emit-silgen -enable-experimental-cross-file-derivative-registration -I %S/Inputs -I %t %s | %FileCheck %s --check-prefix=CHECK-SILGEN --check-prefix=CHECK
// RUN: %target-swift-emit-sil -enable-experimental-cross-file-derivative-registration -I %S/Inputs -I %t %s | %FileCheck %s --check-prefix=CHECK-SIL --check-prefix=CHECK
// RUN: %target-build-swift -Xfrontend -enable-experimental-cross-file-derivative-registration -I %S/Inputs -I %t %s %t/CForeign.o
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rxwei I think that the confusion here may be related to the use of %target-build-swift which actually uses the driver and not the frontend.

…ion`.

Robust fix for validation-test/ParseableInterface/verify_all_overlays.py.
@dan-zheng
Copy link
Contributor Author

@swift-ci Please test tensorflow

@dan-zheng dan-zheng merged commit 677a671 into swiftlang:tensorflow Jan 23, 2020
@dan-zheng dan-zheng deleted the retrodiff-frontend-flag branch January 23, 2020 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tensorflow This is for "tensorflow" branch PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants