1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_CORE_COMMON_RUNTIME_PLUGGABLE_DEVICE_PLUGGABLE_DEVICE_FACTORY_H_ 17 #define TENSORFLOW_CORE_COMMON_RUNTIME_PLUGGABLE_DEVICE_PLUGGABLE_DEVICE_FACTORY_H_ 18 19 #include <memory> 20 #include <string> 21 #include <unordered_map> 22 #include <vector> 23 24 #include "tensorflow/core/common_runtime/device/device_id.h" 25 #include "tensorflow/core/common_runtime/device_factory.h" 26 #include "tensorflow/core/framework/device_attributes.pb.h" 27 #include "tensorflow/core/public/session_options.h" 28 29 namespace tensorflow { 30 class PluggableDeviceFactory : public DeviceFactory { 31 public: 32 PluggableDeviceFactory(const string& device_type, 33 const string& platform_name); 34 Status ListPhysicalDevices(std::vector<string>* devices) override; 35 Status CreateDevices(const SessionOptions& options, 36 const std::string& name_prefix, 37 std::vector<std::unique_ptr<Device>>* devices) override; 38 Status GetDeviceDetails(int device_index, 39 std::unordered_map<string, string>* details) override; 40 41 private: 42 // Populates *device_localities with the DeviceLocality descriptor for 43 // every TfDeviceId. 44 Status GetDeviceLocalities(int num_tf_devices, 45 std::vector<DeviceLocality>* device_localities); 46 // Create a PluggableDevice associated with 'tf_device_id', allocates 47 // (strictly) 'memory_limit' bytes of PluggableDevice memory to it, and adds 48 // it to the 'devices' vector. 49 Status CreatePluggableDevice(const SessionOptions& options, 50 const std::string& name_prefix, 51 TfDeviceId tf_device_id, int64_t memory_limit, 52 const DeviceLocality& dev_locality, 53 std::vector<std::unique_ptr<Device>>* devices); 54 55 const string device_type_; 56 const string platform_name_; 57 }; 58 59 } // namespace tensorflow 60 61 #endif // TENSORFLOW_CORE_COMMON_RUNTIME_PLUGGABLE_DEVICE_PLUGGABLE_DEVICE_FACTORY_H_ 62