1/* Copyright 2015 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#ifndef TENSORFLOW_CORE_COMMON_RUNTIME_THREADPOOL_DEVICE_H_
17#define TENSORFLOW_CORE_COMMON_RUNTIME_THREADPOOL_DEVICE_H_
18
19#include "tensorflow/core/common_runtime/device_factory.h"
20#include "tensorflow/core/common_runtime/local_device.h"
21#include "tensorflow/core/common_runtime/node_file_writer.h"
22
23namespace tensorflow {
24
25// CPU device implementation.
26class ThreadPoolDevice : public LocalDevice {
27 public:
28 ThreadPoolDevice(const SessionOptions& options, const string& name,
29 Bytes memory_limit, const DeviceLocality& locality,
30 Allocator* allocator);
31 ~ThreadPoolDevice() override;
32
33 Allocator* GetAllocator(AllocatorAttributes attr) override;
34 Allocator* GetScopedAllocator(AllocatorAttributes attr,
35 int64_t step_id) override;
36 ScopedAllocatorMgr* GetScopedAllocatorMgr() const override {
37 return scoped_allocator_mgr_.get();
38 }
39 Status MakeTensorFromProto(const TensorProto& tensor_proto,
40 const AllocatorAttributes alloc_attrs,
41 Tensor* tensor) override;
42 void CopyTensorInSameDevice(const Tensor* input_tensor, Tensor* output_tensor,
43 const DeviceContext* device_context,
44 StatusCallback done) override;
45
46 Status Sync() override { return OkStatus(); }
47
48 void Compute(OpKernel* op_kernel, OpKernelContext* context) override;
49 void ComputeAsync(AsyncOpKernel* op_kernel, OpKernelContext* context,
50 AsyncOpKernel::DoneCallback done) override;
51
52 private:
53 void LogInputs(OpKernel* op_kernel, OpKernelContext* context);
54 void LogOutputs(OpKernel* op_kernel, OpKernelContext* context);
55
56 Allocator* allocator_; // Not owned
57 std::unique_ptr<ScopedAllocatorMgr> scoped_allocator_mgr_;
58 NodeFileWriter* node_file_writer_ = nullptr; // not owned
59};
60
61} // namespace tensorflow
62
63#endif // TENSORFLOW_CORE_COMMON_RUNTIME_THREADPOOL_DEVICE_H_
64