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 // Class declaration for Stream type that enqueues tasks onto a host/CPU-based
     17 // execution context (as opposed to a GPU device), HostExecutor.
     18 #ifndef TENSORFLOW_STREAM_EXECUTOR_HOST_HOST_STREAM_H_
     19 #define TENSORFLOW_STREAM_EXECUTOR_HOST_HOST_STREAM_H_
     20 
     21 #include <functional>
     22 #include <memory>
     23 
     24 #include "tensorflow/stream_executor/lib/threadpool.h"
     25 #include "tensorflow/stream_executor/stream_executor_internal.h"
     26 
     27 namespace perftools {
     28 namespace gputools {
     29 namespace host {
     30 
     31 class HostStream : public internal::StreamInterface {
     32  public:
     33   HostStream();
     34   ~HostStream() override;
     35 
     36   bool EnqueueTask(std::function<void()> task);
     37 
     38   void *CudaStreamHack() override { return nullptr; }
     39   void **CudaStreamMemberHack() override { return nullptr; }
     40 
     41   void BlockUntilDone();
     42 
     43  private:
     44   // Use only one thread and own task queue to preserve FIFO ordering
     45   // for the operations enqueued by any given stream.
     46   static const int kExecutorThreads = 1;
     47   std::unique_ptr<port::ThreadPool> host_executor_;
     48 
     49   mutex mu_;
     50   int pending_tasks_ GUARDED_BY(mu_) = 0;
     51   condition_variable completion_condition_;
     52 };
     53 
     54 }  // namespace host
     55 }  // namespace gputools
     56 }  // namespace perftools
     57 
     58 #endif  // TENSORFLOW_STREAM_EXECUTOR_HOST_HOST_STREAM_H_
     59