Skip to content

Commit 916b730

Browse files
committed
---
yaml --- r: 340947 b: refs/heads/rxwei-patch-1 c: c834a27 h: refs/heads/master i: 340945: df0f190 340943: 97af6d8
1 parent 15a6303 commit 916b730

File tree

403 files changed

+36153
-1459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

403 files changed

+36153
-1459
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: bcdd46cdfe5348bc4c65ed964de8acf794be1cf4
1018+
refs/heads/rxwei-patch-1: c834a27076ab8b12a054ff43a6f8d98006eed533
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# vim swap files
1919
.*.sw[a-z]
2020
.sw?
21+
*.vscode
2122

2223
#==============================================================================#
2324
# Explicit files to ignore (only matches one).

branches/rxwei-patch-1/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ option(SWIFT_BUILD_STATIC_SDK_OVERLAY
6161
"Build static variants of the Swift SDK overlay"
6262
FALSE)
6363

64+
option(SWIFT_ENABLE_TENSORFLOW
65+
"Enable TensorFlow in the compiler and build the Swift TensorFlow library"
66+
FALSE)
67+
6468
# In many cases, the CMake build system needs to determine whether to include
6569
# a directory, or perform other actions, based on whether the stdlib or SDK is
6670
# being built at all -- statically or dynamically. Please note that these
@@ -342,6 +346,19 @@ option(SWIFT_REPORT_STATISTICS
342346
"Create json files which contain internal compilation statistics"
343347
FALSE)
344348

349+
#
350+
# User-configurable TensorFlow specific options.
351+
#
352+
set(SWIFT_TENSORFLOW_HOST_LIB_DIR "" CACHE PATH
353+
"If set, directory with TensorFlow host libraries to be linked into swiftc.")
354+
set(SWIFT_TENSORFLOW_TARGET_LIB_DIR "" CACHE PATH
355+
"If set, directory with TensorFlow target libraries to be linked into swift programs.")
356+
357+
set(SWIFT_TENSORFLOW_HOST_INCLUDE_DIR "" CACHE PATH
358+
"If set, directory with host TensorFlow headers.")
359+
set(SWIFT_TENSORFLOW_TARGET_INCLUDE_DIR "" CACHE PATH
360+
"If set, directory with target TensorFlow headers.")
361+
345362
#
346363
# User-configurable experimental options. Do not use in production builds.
347364
#
@@ -1054,6 +1071,11 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
10541071
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE})
10551072
endif()
10561073

1074+
# Enable TensorFlow in compiler code.
1075+
if(SWIFT_ENABLE_TENSORFLOW)
1076+
add_definitions(-DSWIFT_ENABLE_TENSORFLOW)
1077+
endif()
1078+
10571079
# Add all of the subdirectories, where we actually do work.
10581080

10591081
###############

branches/rxwei-patch-1/CONTRIBUTING.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,23 @@ license](https://swift.org/LICENSE.txt).
55

66
---
77

8-
Before submitting the pull request, please make sure you have [tested your
9-
changes](https://github.com/apple/swift/blob/master/docs/ContinuousIntegration.md)
10-
and that they follow the Swift project [guidelines for contributing
11-
code](https://swift.org/contributing/#contributing-code).
8+
Before submitting a pull request, please make sure that your changes follow the
9+
[Swift project guidelines for contributing code](https://swift.org/contributing/#contributing-code).
10+
11+
We request that code changes unrelated to Swift for TensorFlow be submitted to
12+
the [upstream Swift repository](https://github.com/apple/swift). For example,
13+
code formatting changes that do not affect Swift for TensorFlow source code
14+
should be submitted upstream.
15+
16+
It is a good idea to discuss any non-trivial submissions with the project
17+
maintainers before submitting a pull request: please join the
18+
[[email protected]](https://groups.google.com/a/tensorflow.org/d/forum/swift)
19+
mailing list to participate in discussions.
20+
21+
All changes to existing Swift source code should be marked clearly with a
22+
`SWIFT_ENABLE_TENSORFLOW` comment at the top of every diff hunk. This makes
23+
it easier to merge from upstream.
24+
25+
Continuous integration (CI) is still being set up, so if you submit a pull
26+
request with non-trivial changes that require test coverage, please anticipate
27+
some delay before we can properly review and merge it.

branches/rxwei-patch-1/README.md

Lines changed: 116 additions & 124 deletions
Large diffs are not rendered by default.

branches/rxwei-patch-1/cmake/modules/AddSwift.cmake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,9 @@ endfunction()
668668
# [SWIFT_COMPILE_FLAGS flag1...]
669669
# [LINK_FLAGS flag1...]
670670
# [FILE_DEPENDS target1 ...]
671+
# SWIFT_ENABLE_TENSORFLOW
672+
# [EXTRA_RPATHS rpath1 ...]
673+
# END SWIFT_ENABLE_TENSORFLOW
671674
# [DONT_EMBED_BITCODE]
672675
# [IS_STDLIB]
673676
# [FORCE_BUILD_OPTIMIZED]
@@ -724,6 +727,11 @@ endfunction()
724727
# FILE_DEPENDS
725728
# Additional files this library depends on.
726729
#
730+
# SWIFT_ENABLE_TENSORFLOW
731+
# EXTRA_RPATHS
732+
# List of directories to add to this library's RPATH.
733+
# END SWIFT_ENABLE_TENSORFLOW
734+
#
727735
# DONT_EMBED_BITCODE
728736
# Don't embed LLVM bitcode in this target, even if it is enabled globally.
729737
#
@@ -768,6 +776,9 @@ function(_add_swift_library_single target name)
768776
C_COMPILE_FLAGS
769777
DEPENDS
770778
FILE_DEPENDS
779+
# SWIFT_ENABLE_TENSORFLOW
780+
EXTRA_RPATHS
781+
# END SWIFT_ENABLE_TENSORFLOW
771782
FRAMEWORK_DEPENDS
772783
FRAMEWORK_DEPENDS_WEAK
773784
GYB_SOURCES
@@ -1102,6 +1113,28 @@ function(_add_swift_library_single target name)
11021113
set_target_properties("${target}" PROPERTIES NO_SONAME TRUE)
11031114
endif()
11041115

1116+
# SWIFT_ENABLE_TENSORFLOW
1117+
# Hande extra RPATHs.
1118+
set(local_rpath "")
1119+
if("${SWIFTLIB_SINGLE_SDK}" STREQUAL "LINUX" AND NOT "${SWIFTLIB_SINGLE_SDK}" STREQUAL "ANDROID")
1120+
set(local_rpath "$ORIGIN:/usr/lib/swift/linux")
1121+
elseif("${SWIFTLIB_SINGLE_SDK}" STREQUAL "CYGWIN")
1122+
set(local_rpath "$ORIGIN:/usr/lib/swift/cygwin")
1123+
endif()
1124+
foreach(rpath_element ${SWIFTLIB_SINGLE_EXTRA_RPATHS})
1125+
if("${local_rpath}" STREQUAL "")
1126+
set(local_rpath "${rpath_element}")
1127+
else()
1128+
set(local_rpath "${local_rpath}:${rpath_element}")
1129+
endif()
1130+
endforeach()
1131+
if(NOT "${local_rpath}" STREQUAL "")
1132+
set_target_properties("${target}"
1133+
PROPERTIES
1134+
INSTALL_RPATH "${local_rpath}")
1135+
endif()
1136+
# END SWIFT_ENABLE_TENSORFLOW
1137+
11051138
set_target_properties("${target}" PROPERTIES BUILD_WITH_INSTALL_RPATH YES)
11061139
set_target_properties("${target}" PROPERTIES FOLDER "Swift libraries")
11071140

@@ -2305,6 +2338,18 @@ function(_add_swift_executable_single name)
23052338
"-Xlinker" "@executable_path/../lib/swift/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}")
23062339
endif()
23072340

2341+
# SWIFT_ENABLE_TENSORFLOW
2342+
set(swift_relative_library_path "../lib/swift/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}")
2343+
is_darwin_based_sdk("${SWIFTEXE_SINGLE_SDK}" IS_DARWIN)
2344+
# NOTE: Adding "${SWIFTLIB_DIR}/.." to the rpath was necessary to fix linker
2345+
# errors for Syntax/Parser tests on Linux.
2346+
if("${SWIFTEXE_SINGLE_SDK}" STREQUAL "LINUX" AND NOT "${SWIFTEXE_SINGLE_SDK}" STREQUAL "ANDROID")
2347+
set(local_rpath "$ORIGIN:$ORIGIN/${swift_relative_library_path}:${SWIFTLIB_DIR}/..:/usr/lib/swift/linux")
2348+
elseif("${SWIFTEXE_SINGLE_SDK}" STREQUAL "CYGWIN")
2349+
set(local_rpath "$ORIGIN:$ORIGIN/${swift_relative_library_path}:${SWIFTLIB_DIR}/..:/usr/lib/swift/cygwin")
2350+
endif()
2351+
# END SWIFT_ENABLE_TENSORFLOW
2352+
23082353
_list_add_string_suffix(
23092354
"${SWIFTEXE_SINGLE_LINK_LIBRARIES}"
23102355
"-${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}-${SWIFTEXE_SINGLE_ARCHITECTURE}"
@@ -2372,6 +2417,13 @@ function(_add_swift_executable_single name)
23722417
endif()
23732418

23742419
set_target_properties(${name} PROPERTIES FOLDER "Swift executables")
2420+
2421+
# SWIFT_ENABLE_TENSORFLOW
2422+
if(NOT "${local_rpath}" STREQUAL "")
2423+
set_target_properties("${name}" PROPERTIES INSTALL_RPATH "${local_rpath}")
2424+
endif()
2425+
set_target_properties("${name}" PROPERTIES BUILD_WITH_INSTALL_RPATH YES)
2426+
# END SWIFT_ENABLE_TENSORFLOW
23752427
endfunction()
23762428

23772429
macro(add_swift_tool_subdirectory name)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SWIFT_ENABLE_TENSORFLOW
2+
# Find TensorFlow.
3+
4+
include(FindPackageHandleStandardArgs)
5+
6+
find_path(TF_INCLUDE_DIR
7+
NAMES third_party/tensorflow/c tensorflow/c
8+
HINTS ${SWIFT_TENSORFLOW_TARGET_INCLUDE_DIR} /usr/include /usr/local/include)
9+
if (EXISTS ${TF_INCLUDE_DIR}/third_party/tensorflow/c/c_api.h)
10+
# This is experimental and not covered by CI.
11+
set(TF_PATH_ADJUSTMENT "third_party")
12+
else()
13+
# Note: This is the normal workflow.
14+
set(TF_PATH_ADJUSTMENT "")
15+
endif()
16+
17+
find_library(TF_LIBRARY
18+
NAMES tensorflow
19+
HINTS ${SWIFT_TENSORFLOW_TARGET_LIB_DIR} /usr/lib /usr/local/lib)
20+
set(TF_LIBRARIES ${TF_LIBRARY})
21+
22+
find_package_handle_standard_args(TensorFlow DEFAULT_MSG TF_INCLUDE_DIR TF_LIBRARIES)
23+
mark_as_advanced(${TF_INCLUDE_DIR} ${TF_LIBRARIES})

branches/rxwei-patch-1/cmake/modules/SwiftSource.cmake

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,16 @@ function(_compile_swift_files
228228

229229
# The standard library and overlays are always built resiliently.
230230
if(SWIFTFILE_IS_STDLIB)
231-
list(APPEND swift_flags "-enable-library-evolution")
231+
# SWIFT_ENABLE_TENSORFLOW
232+
# FIXME(TF-328): Resilience is currently disabled for the TensorFlow module
233+
# because it causes compilation to crash during IRGen.
234+
# Also, disable resilience for DifferentiationUnittest because resilience
235+
# changes generated AD code, leading to additional leaks.
236+
if(NOT "${SWIFTFILE_MODULE_NAME}" STREQUAL "TensorFlow" AND
237+
NOT "${SWIFTFILE_MODULE_NAME}" STREQUAL "DifferentiationUnittest")
238+
list(APPEND swift_flags "-enable-library-evolution")
239+
list(APPEND swift_flags "-Xfrontend" "-enable-resilience")
240+
endif()
232241
endif()
233242

234243
if(SWIFT_STDLIB_USE_NONATOMIC_RC)

branches/rxwei-patch-1/docs/ContinuousIntegration.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,21 @@ This page is designed to assist in the understanding of proper practices for tes
2525

2626
In order for the Swift project to be able to advance quickly, it is important that we maintain a green build [[1]](#footnote-1). In order to help maintain this green build, the Swift project heavily uses pull request (PR) testing. Specifically, an important general rule is that **all** non-trivial checkins to any Swift Project repository should at least perform a [smoke test](#smoke-testing) if simulators will not be impacted *or* a full [validation test](#validation-testing) if simulators may be impacted. If in addition one is attempting to make a source breaking change across multiple repositories, one should follow the cross repo source breaking changes workflow. We now continue by describing the Swift system for Pull Request testing, @swift-ci:
2727

28-
### @swift-ci
28+
### @swift-ci (Swift for TensorFlow)
29+
30+
31+
Platform | Comment
32+
------------ | -------
33+
All supported platforms | @swift-ci Please test tensorflow
34+
All supported platforms | @swift-ci Please clean test tensorflow
35+
Linux | @swift-ci Please test tensorflow Linux
36+
Linux GPU | @swift-ci Please test tensorflow Linux GPU
37+
macOS | @swift-ci Please test tensorflow macOS
38+
39+
Status can be checked at https://ci-external.swift.org/view/Pull%20Request/.
40+
41+
42+
### @swift-ci (general Swift)
2943

3044
Users with [commit access](https://swift.org/contributing/#commit-access) can trigger pull request testing by writing a comment on a PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment used. The current test types are:
3145

branches/rxwei-patch-1/docs/SIL.rst

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5552,6 +5552,77 @@ destination (if it returns with ``throw``).
55525552

55535553
The rules on generic substitutions are identical to those of ``apply``.
55545554

5555+
.. SWIFT_ENABLE_TENSORFLOW
5556+
5557+
Automatic Differentiation
5558+
~~~~~~~~~~~~~~~~~~~~~~~~~
5559+
5560+
autodiff_function
5561+
`````````````````
5562+
5563+
::
5564+
5565+
sil-instruction ::= 'autodiff_function'
5566+
sil-autodiff-function-parameter-indices?
5567+
sil-autodiff-function-order?
5568+
sil-value ':' sil-type
5569+
sil-autodiff-associated-functions-clause?
5570+
5571+
sil-autodiff-function-parameter-indices ::= '[' 'wrt' [0-9]+ (',', [0-9]+)* ']'
5572+
sil-autodiff-function-differentiation-order ::= '[' 'order' [0-9]+ ']'
5573+
sil-autodiff-associated-functions-clause ::= 'with' sil-autodiff-associated-function-list
5574+
(',' sil-autodiff-associated-function-list)*
5575+
sil-autodiff-associated-function-list ::= '{' sil-value ',' sil-value '}'
5576+
5577+
5578+
autodiff_function [wrt 0] [order 1] %0 : $(T) -> T \
5579+
with {%1 : $(T) -> (T) -> T, %2 : $(T) -> (T) -> T}
5580+
5581+
Bundles a function with its associated differentiation functions up to a
5582+
specified differentiation order into an ``@differentiable`` function. There are
5583+
2 associated functions per differentiation order: a Jacobian-vector products
5584+
(JVP) function and a vector-Jacobian products (VJP) function.
5585+
5586+
``[wrt ...]`` specifies parameter indices that the original function is
5587+
differentiable with respect to. When not specified, it defaults to all
5588+
parameters.
5589+
5590+
``[order ...]`` specifies the maximum differentiation order for the resulting
5591+
function. The number of lists of associated functions is equal to the order.
5592+
5593+
A ``with`` clause specifies the differentiation functions associated
5594+
with the original function. When a ``with`` clause is not specified, the first
5595+
operand will be differentiated to produce associated functions, and a ``with``
5596+
clause will be added to the instruction.
5597+
5598+
In raw SIL, it is optional to provide a ``with`` clause. In canonical SIL, a
5599+
``with`` clause is mandatory.
5600+
5601+
5602+
autodiff_function_extract
5603+
`````````````````````````
5604+
5605+
::
5606+
5607+
sil-instruction ::= 'autodiff_function_extract'
5608+
sil-autodiff-associated-function-kind
5609+
sil-autodiff-function-order
5610+
sil-value ':' sil-type
5611+
5612+
sil-autodiff-function-extractee ::= '[' sil-autodiff-function-extractee ']'
5613+
sil-autodiff-function-extractee-name ::= 'original' | 'jvp' | 'vjp'
5614+
sil-autodiff-function-differentiation-order ::= '[' 'order' [0-9]+ ']'
5615+
5616+
5617+
autodiff_function_extract [original] %0 : $@differentiable (T) -> T
5618+
autodiff_function_extract [jvp] [order 1] %0 : $@differentiable (T) -> T
5619+
autodiff_function_extract [vjp] [order 1] %0 : $@differentiable (T) -> T
5620+
5621+
Extracts the original function or an associated function from the given
5622+
``@differentiable`` function at a specific differentiation order. It must be
5623+
provided with an extractee: ``[original]``, ``[jvp]`` or ``[vjp]``.
5624+
5625+
55555626
Assertion configuration
55565627
~~~~~~~~~~~~~~~~~~~~~~~
55575628

branches/rxwei-patch-1/include/swift/ABI/MetadataValues.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ class TargetFunctionTypeFlags {
746746
ThrowsMask = 0x01000000U,
747747
ParamFlagsMask = 0x02000000U,
748748
EscapingMask = 0x04000000U,
749+
// SWIFT_ENABLE_TENSORFLOW
750+
DifferentiableMask = 0x08000000U
749751
};
750752
int_type Data;
751753

@@ -781,6 +783,13 @@ class TargetFunctionTypeFlags {
781783
return TargetFunctionTypeFlags<int_type>((Data & ~EscapingMask) |
782784
(isEscaping ? EscapingMask : 0));
783785
}
786+
787+
// SWIFT_ENABLE_TENSORFLOW
788+
constexpr TargetFunctionTypeFlags<int_type>
789+
withDifferentiable(bool isDifferentiable) const {
790+
return TargetFunctionTypeFlags<int_type>((Data & ~DifferentiableMask) |
791+
(isDifferentiable ? DifferentiableMask : 0));
792+
}
784793

785794
unsigned getNumParameters() const { return Data & NumParametersMask; }
786795

@@ -795,6 +804,11 @@ class TargetFunctionTypeFlags {
795804
bool isEscaping() const {
796805
return bool (Data & EscapingMask);
797806
}
807+
808+
// SWIFT_ENABLE_TENSORFLOW
809+
bool isDifferentiable() const {
810+
return bool (Data & DifferentiableMask);
811+
}
798812

799813
bool hasParameterFlags() const { return bool(Data & ParamFlagsMask); }
800814

@@ -818,9 +832,11 @@ using FunctionTypeFlags = TargetFunctionTypeFlags<size_t>;
818832
template <typename int_type>
819833
class TargetParameterTypeFlags {
820834
enum : int_type {
821-
ValueOwnershipMask = 0x7F,
822-
VariadicMask = 0x80,
823-
AutoClosureMask = 0x100,
835+
// SWIFT_ENABLE_TENSORFLOW
836+
ValueOwnershipMask = 0x7F,
837+
VariadicMask = 0x80,
838+
AutoClosureMask = 0x100,
839+
NonDifferentiableMask = 0x200
824840
};
825841
int_type Data;
826842

@@ -850,6 +866,8 @@ class TargetParameterTypeFlags {
850866
bool isNone() const { return Data == 0; }
851867
bool isVariadic() const { return Data & VariadicMask; }
852868
bool isAutoClosure() const { return Data & AutoClosureMask; }
869+
// SWIFT_ENABLE_TENSORFLOW
870+
bool isNonDifferentiable() const { return Data & NonDifferentiableMask; }
853871

854872
ValueOwnership getValueOwnership() const {
855873
return (ValueOwnership)(Data & ValueOwnershipMask);

0 commit comments

Comments
 (0)