You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Wrapped TF C APIs as runtime functions, so that IRGen can generate calls to them (#19555)
* Wrapped TF C APIs as runtime functions, so that IRGen can generate calls to
them.
This patch "disolved" the call to the packaged experimental C API
TF_RunConstOp() into a set of finer-grained C API calls.
An alternative to the runtime function approach is to use Clang importer to call
the C APIs. Clang importer allows the C APIs to become available as SIL
functions with the same names, and thus can be found and called in IRGen via
silModule.findFunction() (see
https://github.com/apple/swift/blob/ad7def2c6bffd95d62e5e665c9faed0f8dac49f5/lib/IRGen/IRGenSIL.cpp#L1956-L1957). The
concerns with this approach are:
1. There are no precedents in IRGen that calls C APIs via this clang importer
route. Having IRGen depend on clang importer may not be desirable.
2. Some C APIs cannot be found via clang importer (e.g. TF_NewStatus() can be
found, but TFE_NewOp() cannot). As a work-around, these C APIs must be called in
the user module code first, before IRGen over the user module can locate them as
SIL functions. This feels brittle.
3. When passing objects between compiler runtime entry points (swift functions)
such as @_silgen_name("_swift_tfc_GetGlobalEagerContext") and the C APIs, IRGen
have to issue bitcast to convert between a real struct type (e.g. TFE_Context*)
and void* (i8* in LLVM type) as used in the entry points.
In contrast, the wrapped runtime functions consistently use void* in their
interfaces, so that IRGen need not do such bitcasts.
One downside with the runtime function approach is that we need to wrap ~20 TF C
APIs in the new files TensorFlow.{h,cpp}. This is however mostly a one-time eng cost.
* Reverted some compiler rt changes.
* Addressed feedback:
1. Removed runtime func impls, when we can us the C API ones.
2. Changed some compiler RT entry points to using @_cdecl, so that they can be
called in IRGen directly (instead of going through clang importer and silgen names).
* Addressed comments from @rxwei
* Added "find_package(TensorFlow REQUIRED)" to
swift/stdlib/public/runtime/CMakeLists.txt, because CI
run (e.g. https://ci-external.swift.org/view/Pull%20Request/job/swift-PR-TensorFlow-Linux/859/console)
reported:
```
CMake Error at stdlib/public/runtime/CMakeLists.txt:30 (include_directories):
include_directories given empty-string as include directory.
```
* Moved code in TensorFlow.{h,cpp} to the CTensorFLow
module (ctensorflow_init.{h,cpp}), so that the stdlib/public/runtime/ need not
depend on the TF library.
Also addresed more feedback.
0 commit comments