1 /* Copyright 2020 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_STREAM_EXECUTOR_TPU_TPU_COMPUTATION_PLACER_H_ 17 #define TENSORFLOW_STREAM_EXECUTOR_TPU_TPU_COMPUTATION_PLACER_H_ 18 19 #include "tensorflow/compiler/xla/service/computation_placer.h" 20 #include "tensorflow/compiler/xla/statusor.h" 21 #include "tensorflow/stream_executor/tpu/tpu_executor_c_api.h" 22 #include "tensorflow/stream_executor/tpu/tpu_topology.h" 23 24 namespace tensorflow { 25 namespace tpu { 26 27 class TpuComputationPlacer : public xla::ComputationPlacer { 28 public: 29 template <typename T> 30 using StatusOr = xla::StatusOr<T>; 31 32 TpuComputationPlacer(); 33 ~TpuComputationPlacer() override; 34 35 StatusOr<int> DeviceId(int replica, int computation, int replica_count, 36 int computation_count) override; 37 38 StatusOr<xla::DeviceAssignment> AssignDevices(int replica_count, 39 int computation_count) override; 40 41 static StatusOr<xla::DeviceAssignment> AssignLocalDevices( 42 TpuHostLocationExternal host_location, int replica_count, 43 int computation_count); 44 45 private: 46 XLA_ComputationPlacer* placer_; 47 }; 48 49 } // namespace tpu 50 } // namespace tensorflow 51 52 #endif // TENSORFLOW_STREAM_EXECUTOR_TPU_TPU_COMPUTATION_PLACER_H_ 53