1 /* Copyright 2017 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_COMPILER_XLA_SERVICE_PLATFORM_UTIL_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_PLATFORM_UTIL_H_ 18 19 #include <set> 20 #include <string> 21 #include <vector> 22 23 #include "tensorflow/compiler/xla/statusor.h" 24 #include "tensorflow/compiler/xla/types.h" 25 #include "tensorflow/core/platform/macros.h" 26 #include "tensorflow/core/platform/stream_executor_no_cuda.h" 27 #include "tensorflow/core/platform/types.h" 28 29 namespace xla { 30 31 // Utilities for querying platforms and devices used by XLA. 32 class PlatformUtil { 33 public: 34 // Returns the platforms present on the system and supported by XLA. 35 // 36 // Note that, even if a platform is present with zero devices, if we *do* have 37 // compilation support for it, it will be returned in this sequence. 38 static StatusOr<std::vector<se::Platform*>> GetSupportedPlatforms(); 39 40 // Convenience function which returns the default supported platform for 41 // tests. If exactly one supported platform is present, then this platform is 42 // the default platform. If exactly two platforms are present and one of them 43 // is the interpreter platform, then the other platform is the default 44 // platform. Otherwise returns an error. 45 static StatusOr<se::Platform*> GetDefaultPlatform(); 46 47 // Returns the platform according to the given name. Returns error if there is 48 // no such platform. 49 static StatusOr<se::Platform*> GetPlatform(const string& platform_name); 50 51 // Returns a vector of StreamExecutors for the given platform. 52 // If populated, only the devices in allowed_devices will have 53 // their StreamExecutors initialized, otherwise all StreamExecutors will be 54 // initialized and returned. 55 // 56 // If the platform has no visible devices, a not-found error is returned. 57 static StatusOr<std::vector<se::StreamExecutor*>> GetStreamExecutors( 58 se::Platform* platform, 59 const absl::optional<std::set<int>>& allowed_devices = absl::nullopt); 60 61 private: 62 TF_DISALLOW_COPY_AND_ASSIGN(PlatformUtil); 63 }; 64 65 } // namespace xla 66 67 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_PLATFORM_UTIL_H_ 68