mirror of
https://github.com/zebrajr/tensorflow.git
synced 2025-12-06 12:20:11 +01:00
[xla:ffi] Document XLA:FFI binary API guarantees and add a supporteded API range check
PiperOrigin-RevId: 822214561
This commit is contained in:
parent
c37a4aaa58
commit
6141496817
9
third_party/xla/xla/ffi/api/c_api.h
vendored
9
third_party/xla/xla/ffi/api/c_api.h
vendored
|
|
@ -61,6 +61,15 @@ XLA_FFI_DEFINE_STRUCT_TRAITS(XLA_FFI_Extension_Base, next);
|
|||
// Version
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// XLA FFI provides a stable binary API for registering custom calls with
|
||||
// XLA runtime. XLA runtime guarantees that old API version are supported for
|
||||
// at least 12 months, after that point FFI library has to be recompiled with
|
||||
// latest XLA FFI headers to support new features. We don't plan to break ABI
|
||||
// compatibility, unless it's absolutely necessary to enable new features that
|
||||
// can't be implemented in a backward compatible way.
|
||||
//
|
||||
// The range of supported API versions is defined in `xla/ffi/ffi_api.cc`.
|
||||
|
||||
// Incremented when an ABI-incompatible change is made to the interface.
|
||||
//
|
||||
// Major changes include:
|
||||
|
|
|
|||
38
third_party/xla/xla/ffi/ffi_api.cc
vendored
38
third_party/xla/xla/ffi/ffi_api.cc
vendored
|
|
@ -97,6 +97,25 @@ struct XLA_FFI_ExecutionContext {
|
|||
|
||||
namespace xla::ffi {
|
||||
|
||||
// The minimum XLA:FFI API version that XLA runtime supports.
|
||||
static constexpr std::pair<int32_t, int32_t> kMinSupportedApiVersion = {
|
||||
/*major=*/0,
|
||||
/*minor=*/1,
|
||||
};
|
||||
|
||||
// The maximum XLA:FFI API version that XLA runtime supports.
|
||||
static constexpr std::pair<int32_t, int32_t> kMaxSupportedApiVersion = {
|
||||
XLA_FFI_API_MAJOR,
|
||||
XLA_FFI_API_MINOR,
|
||||
};
|
||||
|
||||
static bool IsSupportedApiVersion(const XLA_FFI_Api_Version& api_version) {
|
||||
std::pair<int32_t, int32_t> version = {api_version.major_version,
|
||||
api_version.minor_version};
|
||||
return version >= kMinSupportedApiVersion &&
|
||||
version <= kMaxSupportedApiVersion;
|
||||
}
|
||||
|
||||
bool IsCommandBufferCompatible(XLA_FFI_Handler_Traits traits) {
|
||||
return traits & XLA_FFI_HANDLER_TRAITS_COMMAND_BUFFER_COMPATIBLE;
|
||||
}
|
||||
|
|
@ -381,17 +400,18 @@ static absl::Status RegisterHandler(absl::string_view name,
|
|||
name, platform);
|
||||
}
|
||||
|
||||
// Check the API versions.
|
||||
// Check the API version that FFI handler was compiled with is supported.
|
||||
TF_ASSIGN_OR_RETURN(XLA_FFI_Metadata metadata, GetMetadata(bundle.execute));
|
||||
const XLA_FFI_Api_Version& api_version = metadata.api_version;
|
||||
if (std::make_pair(api_version.major_version, api_version.minor_version) >
|
||||
std::make_pair(XLA_FFI_API_MAJOR, XLA_FFI_API_MINOR)) {
|
||||
if (!IsSupportedApiVersion(metadata.api_version)) {
|
||||
return InvalidArgument(
|
||||
"FFI handler registration for %s on platform %s (canonical %s) failed "
|
||||
"because the handler's API version (%d.%d) is incompatible with the "
|
||||
"framework's API version (%d.%d)",
|
||||
name, platform, canonical_platform, api_version.major_version,
|
||||
api_version.minor_version, XLA_FFI_API_MAJOR, XLA_FFI_API_MINOR);
|
||||
"XLA FFI handler registration for %s on platform %s (canonical %s) "
|
||||
"failed because the handler's API version (%d.%d) is incompatible with "
|
||||
"the framework's API version (%d.%d). Minimum supported API version is "
|
||||
"(%d.%d).",
|
||||
name, platform, canonical_platform, metadata.api_version.major_version,
|
||||
metadata.api_version.minor_version, kMaxSupportedApiVersion.first,
|
||||
kMaxSupportedApiVersion.second, kMinSupportedApiVersion.first,
|
||||
kMinSupportedApiVersion.second);
|
||||
}
|
||||
|
||||
// Incorporate handler traits.
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user