1/* Copyright 2017 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_COMPILER_XLA_SERVICE_GPU_TRANSFER_MANAGER_H_
17#define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_TRANSFER_MANAGER_H_
18
19#include <vector>
20
21#include "tensorflow/compiler/xla/service/generic_transfer_manager.h"
22#include "tensorflow/compiler/xla/service/gpu/infeed_manager.h"
23#include "tensorflow/compiler/xla/service/transfer_manager.h"
24#include "tensorflow/compiler/xla/statusor.h"
25#include "tensorflow/compiler/xla/xla_data.pb.h"
26#include "tensorflow/core/platform/macros.h"
27#include "tensorflow/core/platform/stream_executor_no_cuda.h"
28#include "tensorflow/core/platform/types.h"
29
30namespace xla {
31
32// An implementation of the XLA GenericTransferManager that
33// handles GPU-specific infeed.
34class GpuTransferManager : public GenericTransferManager {
35 public:
36  GpuTransferManager();
37  ~GpuTransferManager() override {}
38
39  Status TransferLiteralToInfeed(perftools::gputools::StreamExecutor* executor,
40                                 const Literal& literal) override;
41  Status TransferBufferToInfeed(perftools::gputools::StreamExecutor* executor,
42                                int64 size, const void* source) override;
43
44 private:
45  // Initiates the infeed data transfers. InfeedBuffer->Done() must be
46  // called to clean up the memory allocated for InfeedBuffer.
47  StatusOr<gpu::InfeedBuffer*> TransferBufferToInfeedInternal(
48      perftools::gputools::StreamExecutor* executor, int64 size,
49      const void* source);
50
51  // Enqueues infeed data buffers with the infeed manager after their
52  // transfer completes.
53  Status EnqueueBuffersToInfeed(perftools::gputools::StreamExecutor* executor,
54                                std::vector<gpu::InfeedBuffer*> buffers);
55
56  TF_DISALLOW_COPY_AND_ASSIGN(GpuTransferManager);
57};
58
59}  // namespace xla
60
61#endif  // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_TRANSFER_MANAGER_H_
62