• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2016 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 // Declares the "host" platform, which is a CPU-only implementation of the
17 // StreamExecutor. The host platform only supports memory operations and plugin
18 // routines, and is primarily used for testing.
19 #ifndef TENSORFLOW_STREAM_EXECUTOR_HOST_HOST_PLATFORM_H_
20 #define TENSORFLOW_STREAM_EXECUTOR_HOST_HOST_PLATFORM_H_
21 
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include "tensorflow/core/platform/thread_annotations.h"
27 #include "tensorflow/stream_executor/executor_cache.h"
28 #include "tensorflow/stream_executor/lib/statusor.h"
29 #include "tensorflow/stream_executor/multi_platform_manager.h"
30 #include "tensorflow/stream_executor/platform.h"
31 #include "tensorflow/stream_executor/platform/port.h"
32 #include "tensorflow/stream_executor/stream_executor_pimpl.h"
33 #include "tensorflow/stream_executor/trace_listener.h"
34 
35 namespace stream_executor {
36 namespace host {
37 
38 // Host (CPU) platform plugin, registered as a singleton value via module
39 // initializer.
40 class HostPlatform : public Platform {
41  public:
42   HostPlatform();
43   ~HostPlatform() override;
44 
45   Platform::Id id() const override;
46 
47   // Device count is less clear-cut for CPUs than accelerators. This call
48   // currently returns the number of thread units in the host, as reported by
49   // base::NumCPUs().
50   int VisibleDeviceCount() const override;
51 
52   const std::string& Name() const override;
53 
54   port::StatusOr<std::unique_ptr<DeviceDescription>> DescriptionForDevice(
55       int ordinal) const override;
56 
57   port::StatusOr<StreamExecutor*> ExecutorForDevice(int ordinal) override;
58 
59   port::StatusOr<StreamExecutor*> ExecutorForDeviceWithPluginConfig(
60       int ordinal, const PluginConfig& config) override;
61 
62   port::StatusOr<StreamExecutor*> GetExecutor(
63       const StreamExecutorConfig& config) override;
64 
65   port::StatusOr<std::unique_ptr<StreamExecutor>> GetUncachedExecutor(
66       const StreamExecutorConfig& config) override;
67 
68   void RegisterTraceListener(std::unique_ptr<TraceListener> listener) override;
69 
70   void UnregisterTraceListener(TraceListener* listener) override;
71 
72  private:
73   // This platform's name.
74   std::string name_;
75 
76   // Cache of created StreamExecutors.
77   ExecutorCache executor_cache_;
78 
79   SE_DISALLOW_COPY_AND_ASSIGN(HostPlatform);
80 };
81 
82 }  // namespace host
83 }  // namespace stream_executor
84 
85 #endif  // TENSORFLOW_STREAM_EXECUTOR_HOST_HOST_PLATFORM_H_
86