Holds some information about the platform on which an XlaLaunch/_XlaCompile/_XlaRun op must run on.
| 34 | // Holds some information about the platform on which an |
| 35 | // XlaLaunch/_XlaCompile/_XlaRun op must run on. |
| 36 | class XlaPlatformInfo { |
| 37 | public: |
| 38 | XlaPlatformInfo() : device_type_("") {} |
| 39 | XlaPlatformInfo(XlaPlatformInfo&&) = default; |
| 40 | explicit XlaPlatformInfo(const DeviceType device_type, |
| 41 | se::Platform::Id platform_id, |
| 42 | const XlaDevice::Metadata* xla_device_metadata, |
| 43 | std::shared_ptr<se::DeviceMemoryAllocator> device_allocator) |
| 44 | : device_type_(device_type), |
| 45 | platform_id_(platform_id), |
| 46 | xla_device_metadata_(xla_device_metadata), |
| 47 | device_allocator_(device_allocator) {} |
| 48 | |
| 49 | XlaPlatformInfo& operator=(XlaPlatformInfo&& other) = default; |
| 50 | |
| 51 | bool UseMultipleStreams() const { |
| 52 | return xla_device_metadata_ && xla_device_metadata_->UseMultipleStreams(); |
| 53 | } |
| 54 | |
| 55 | // Non-null only when run on an XLA device. |
| 56 | std::shared_ptr<se::DeviceMemoryAllocator> custom_allocator() const { |
| 57 | return device_allocator_; |
| 58 | } |
| 59 | |
| 60 | DeviceType device_type() const { return device_type_; } |
| 61 | |
| 62 | // This is equal to xla_device_metadata()->platform()->id() if |
| 63 | // xla_device_metadata() is not nullptr. |
| 64 | se::Platform::Id platform_id() const { return platform_id_; } |
| 65 | |
| 66 | // This may be null if the op this XlaPlatformInfo is for was not placed on an |
| 67 | // XLA device. |
| 68 | const XlaDevice::Metadata* xla_device_metadata() const { |
| 69 | return xla_device_metadata_; |
| 70 | } |
| 71 | bool is_on_xla_device() const { return xla_device_metadata() != nullptr; } |
| 72 | |
| 73 | private: |
| 74 | DeviceType device_type_; |
| 75 | se::Platform::Id platform_id_; |
| 76 | |
| 77 | // xla_device_metadata_ lives in the tensorflow::DeviceBase in which the |
| 78 | // XlaLaunch/_XlaCompile/_XlaRun op is placed and thus does not die before the |
| 79 | // XlaLaunch/_XlaCompile/_XlaRun OpKernel. |
| 80 | const XlaDevice::Metadata* xla_device_metadata_; |
| 81 | |
| 82 | // If the op associated with this XlaPlatformInfo is placed on an XLA device |
| 83 | // then device_allocator_ is the xla::Backend's memory allocator. If the op |
| 84 | // is placed on a regular CPU or GPU device then device_allocator_ is null. |
| 85 | // The allocator is of unknowm provenance; keep it in a shared pointer to |
| 86 | // set an artificial refcount of one |
| 87 | std::shared_ptr<se::DeviceMemoryAllocator> device_allocator_; |
| 88 | |
| 89 | TF_DISALLOW_COPY_AND_ASSIGN(XlaPlatformInfo); |
| 90 | }; |
| 91 | |
| 92 | // XlaLocalLaunchBase is almost the same as XlaLocalLaunchOp. |
| 93 | // The only difference is that it does not require arguments to follow |
no outgoing calls
no test coverage detected