third_party/xla/xla/pjrt/plugin/README.md
This directory contains code related to PJRT plugins. These plugins enable consumption of XLA's backends for multiple diverse hardware platforms (e.g., CPU, GPU, TPU).
xla_cpu, xla_gpu, and xla_tpu.plugin_names.h file for defining valid plugin names and the
static_registration.h for the macro to register plugins.GetXla...PjrtPlugin functions: Functions to get a single, statically
linked plugin for a specific platform.There are two primary ways to integrate a PJRT plugin into your application:
Dynamic Plugin Selection with GetCApiPlugin:
Mechanism:
GetCApiPlugin function with a plugin name (defined
in plugin_names.h).static_registration.h).Benefits:
Requirements:
plugin_names.h).Example (Conceptual):
const char* plugin_name = PJRT_PLUGIN_NAME_CPU;
// Or another name from plugin_names.h
absl::StatusOr<std::unique_ptr<PjrtClient>> client =
GetCApiClient(plugin_name, {}, nullptr);
if (!client.ok()) {
// Handle error
} else {
// Use the client: client.value()
}
Static Plugin Linking with GetXla...PjrtPlugin:
Mechanism:
GetXlaCpuPjrtPlugin() (or
similar for GPU and TPU).Benefits:
Requirements:
GetXla...PjrtPlugin function for your
target platform.Example (Conceptual):
absl::StatusOr<std::unique_ptr<PjrtClient>> client =
GetXlaCpuPjrtPlugin();
if (!client.ok()) {
// Handle error
} else {
// Use the client: client.value()
}
In summary, this plugin directory provides the infrastructure for consuming
XLA with hardware-specific plugins. You can choose between a flexible but more
complex dynamic approach using GetCApiPlugin or a simpler but less flexible
static approach using GetXla...PjrtPlugin.