# NextPluggableDevice Overview The NextPluggableDevice (NPD) represents an advanced generation of [PluggableDevice](https://github.com/tensorflow/community/blob/master/rfcs/20200624-pluggable-device-for-tensorflow.html) mechanism. It not only facilitates a seamless integration of new accelerator plugins for registering devices with TensorFlow without requiring modifications to the TensorFlow codebase, but it also serves as a conduit to [OpenXLA (Accelerated Linear Algebra)](https://github.com/openxla/xla) via its [PJRT plugin](https://github.com/openxla/community/blob/main/rfcs/20230123-pjrt-plugin.html). - [Overview](#NextPluggableDevice-Overview) - [Why NextPluggableDevice](#Why-NextPluggableDevice) - [Starting With NextPluggableDevice](#How-to-start-with-XLA-using-NextPluggableDevice) - [Architecture](#NextPluggableDevice-Architecture) - [Runtime Switch](#Runtime-Switch-of-NextPluggableDevice-and-PluggableDevice) ## Why NextPluggableDevice Previously, Stock TensorFlow has designed & developed the [PluggableDevice](https://github.com/tensorflow/community/blob/master/rfcs/20200624-pluggable-device-for-tensorflow.html) to extend new device extensions without making device-specific changes to the TensorFlow code, and the PluggableDevice is tightly integrated with the [StreamExecutor C API](https://github.com/tensorflow/community/pull/257) today. However, excessive binding with StreamExecutor has made it difficult for the PluggableDevice to be compatible with [OpenXLA](https://github.com/openxla/xla). Precisely for this reason, TensorFlow evolved to use [PJRT plugin](https://github.com/openxla/community/blob/main/rfcs/20230123-pjrt-plugin.html) as the device API, resulting in the decoupling of the Pluggable Device from StreamExecutor, implemented as NextPluggableDevice. ## Start with XLA using NextPluggableDevice Enabling XLA in ITEX is exactly the same as it is in TensorFlow, except that you need to export environment variables first: ``` $ export TF_XLA_FLAGS="--tf_xla_use_device_api=true --tf_xla_auto_jit=2" $ python >>> import tensorflow as tf # TensorFlow registers NextPluggableDevice here >>> @tf.function(experimental_compile=True) ... def add_with_xla(a, b): ... return a + b >>> a = tf.constant([1.0, 2.0, 3.0]) >>> b = tf.constant([4.0, 5.0, 6.0]) >>> result = add_with_xla(a, b) >>> print("Result: ", result) Result: tf.Tensor([5. 7. 9.], shape=(3,), dtype=float32) ``` ## NextPluggableDevice Architecture The NextPluggableDevice represents an advanced generation of the [PluggableDevice](https://github.com/tensorflow/community/blob/master/rfcs/20200624-pluggable-device-for-tensorflow.html) mechanism. Intel® Extension for TensorFlow* integrates the NextPluggableDevice as a new device type, along with the corresponding [PJRT CAPI](https://github.com/tensorflow/tensorflow/blob/master/third_party/xla/xla/pjrt/c/pjrt_c_api.h) for registering its Ops & Kernels, XLA PJRT client, Runtime, as well as the legacy Graph Optimization API and Profiler interface. In this way, it not only facilitates a seamless integration of new accelerator plugins for registering devices with TensorFlow without requiring modifications to the TensorFlow codebase, but it also serves as a conduit to [OpenXLA](https://github.com/openxla/xla) via its [PJRT plugin](https://github.com/openxla/community/blob/main/rfcs/20230123-pjrt-plugin.html).