-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
[AutoDiff] Change cross-file derivative registration to a frontend flag. #29339
Conversation
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`
// 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
@swift-ci Please test tensorflow |
@swift-ci Please clean test tensorflow linux |
Is the intent for this to become a driver flag? |
Perhaps yes. We noticed that To support |
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 |
There was a problem hiding this comment.
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.
@swift-ci Please test tensorflow |
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