1/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations 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
27namespace perftools {
28namespace gputools {
29namespace host {
30
31class 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