• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2017 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 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_LOGICAL_BUFFER_H_
17 #define TENSORFLOW_COMPILER_XLA_SERVICE_LOGICAL_BUFFER_H_
18 
19 #include <string>
20 
21 #include "absl/types/span.h"
22 #include "tensorflow/compiler/xla/service/buffer_value.h"
23 #include "tensorflow/compiler/xla/service/hlo.pb.h"
24 #include "tensorflow/compiler/xla/service/hlo_instruction.h"
25 #include "tensorflow/compiler/xla/shape_util.h"
26 #include "tensorflow/compiler/xla/types.h"
27 #include "tensorflow/compiler/xla/xla_data.pb.h"
28 #include "tensorflow/core/lib/gtl/int_type.h"
29 #include "tensorflow/core/platform/macros.h"
30 #include "tensorflow/core/platform/types.h"
31 
32 namespace xla {
33 
34 // TuplePointsToAnalysis uses this subclass of BufferValue.
35 class LogicalBuffer : public BufferValue {
36  public:
37   LogicalBuffer(HloInstruction* instruction, const ShapeIndex& index, Id id);
38   ~LogicalBuffer() override;
39 
40   // Return the instruction that defines the buffer.
instruction()41   HloInstruction* instruction() const override { return instruction_; }
42 
43   // Return the index within the output of the instruction where the buffer is
44   // defined. Index used defined as in ShapeUtil::GetSubshape()
index()45   const ShapeIndex& index() const override { return index_; }
46 
47   // Return the shape of the buffer. This reference points into the shape field
48   // of the instruction defining the buffer.  Therefore, the returned shape will
49   // contain the layout of instruction, if any.
shape()50   const Shape& shape() const override {
51     return ShapeUtil::GetSubshape(instruction_->shape(), index_);
52   }
53 
54   string ToString() const override;
55 
56  private:
57   HloInstruction* instruction_;
58   ShapeIndex index_;
59 
60   // Similar to HLO constructs (HloInstruction, etc), pointers are used for
61   // comparison to equality, so disable all copying.
62   TF_DISALLOW_COPY_AND_ASSIGN(LogicalBuffer);
63 };
64 
65 }  // namespace xla
66 
67 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_LOGICAL_BUFFER_H_
68