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