• 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_PACKED_LITERAL_READER_H_
17 #define TENSORFLOW_COMPILER_XLA_PACKED_LITERAL_READER_H_
18 
19 #include <memory>
20 
21 #include "tensorflow/compiler/xla/literal.h"
22 #include "tensorflow/compiler/xla/statusor.h"
23 #include "tensorflow/compiler/xla/types.h"
24 #include "tensorflow/compiler/xla/xla_data.pb.h"
25 #include "tensorflow/core/platform/env.h"
26 
27 namespace xla {
28 
29 // Reads packed data from a metadata-less file as requested by a user (who must
30 // know its internal format). These are yielded as (structured) literal values.
31 class PackedLiteralReader {
32  public:
33   // Ownership of file is passed to this instance -- this instance takes
34   // responsibility for closing it.
35   explicit PackedLiteralReader(tensorflow::RandomAccessFile* file);
36   ~PackedLiteralReader();
37 
38   // Yields the next packed literal with shape "shape" as read from the
39   // underlying file stream.
40   //
41   // Layout is optional. If it is not provided, no layout is set on the literal
42   // that is produced.
43   StatusOr<Literal> Read(const Shape& shape, const Layout* layout = nullptr);
44 
45   // Returns whether the input file has been fully exhausted; i.e. all available
46   // packed literals have been read and we're at the end of the file.
47   bool IsExhausted() const;
48 
49  private:
50   tensorflow::RandomAccessFile* file_;  // We own and close in our destructor
51   uint64_t offset_;                     // Next file offset to read from
52 
53   PackedLiteralReader(const PackedLiteralReader&) = delete;
54   PackedLiteralReader& operator=(const PackedLiteralReader&) = delete;
55 };
56 
57 }  // namespace xla
58 
59 #endif  // TENSORFLOW_COMPILER_XLA_PACKED_LITERAL_READER_H_
60