Skip to content

Commit 01ce72c

Browse files
shoumikhinfacebook-github-bot
authored andcommitted
Fix includes in Core ML backend. (#3603)
Summary: Pull Request resolved: #3603 Some headers are relying on transitive includes, that may be missing when building for different platforms, so we have to include everything explicitly. Also, need to use quotes over angle parenthesis for local headers includes. Reviewed By: kirklandsign Differential Revision: D57340360 fbshipit-source-id: dedc9737314231be5255c06c3ad7c9a800b247b8
1 parent c69861d commit 01ce72c

14 files changed

+128
-114
lines changed

backends/apple/coreml/runtime/inmemoryfs/inmemory_filesystem.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <assert.h>
1111
#include <fstream>
1212
#include <iostream>
13-
#include <range.hpp>
1413
#include <sstream>
1514

1615
#if __has_include(<filesystem>)
@@ -22,7 +21,8 @@ namespace filesystem = std::experimental::filesystem;
2221
}
2322
#endif
2423

25-
#include <reversed_memory_stream.hpp>
24+
#include "range.hpp"
25+
#include "reversed_memory_stream.hpp"
2626

2727
namespace {
2828
using namespace inmemoryfs;

backends/apple/coreml/runtime/inmemoryfs/inmemory_filesystem.hpp

+44-43
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
#pragma once
99

1010
#include <functional>
11-
#include <inmemory_filesystem_metadata.hpp>
1211
#include <memory>
13-
#include <memory_buffer.hpp>
1412
#include <optional>
1513
#include <stdio.h>
1614
#include <string>
1715
#include <system_error>
1816

17+
#include "inmemory_filesystem_metadata.hpp"
18+
#include "memory_buffer.hpp"
19+
1920
namespace inmemoryfs {
2021

2122
/// A class representing an in-memory file system.
@@ -29,36 +30,36 @@ class InMemoryFileSystem final {
2930
DirectoryExpected, // If path is not a directory.
3031
FileExpected, // If the path is not a file.
3132
};
32-
33+
3334
/// Options for loading file content.
3435
enum class FileLoadOption: int8_t {
3536
Malloc = 1, // Copy file contents into memory.
3637
MMap, // Memory map file contents.
3738
LazyMMap // Memory map file contents but lazily.
3839
};
39-
40+
4041
/// The error category for `InMemoryFileSystem`.
4142
struct ErrorCategory final: public std::error_category {
4243
public:
4344
inline const char* name() const noexcept override {
4445
return "InMemoryFileSystem";
4546
}
46-
47+
4748
std::string message(int code) const override;
4849
};
49-
50+
5051
struct Attributes {
5152
time_t modificationTime;
52-
53+
5354
inline Attributes() noexcept:
5455
modificationTime(time(0))
5556
{}
5657
};
57-
58+
5859
using MetadataWriter = std::function<bool(const InMemoryFileSystemMetadata&, std::ostream&)>;
5960
using MetadataWriterInMemory = std::function<size_t(const InMemoryFileSystemMetadata&, void *)>;
6061
using MetadataReader = std::function<std::optional<InMemoryFileSystemMetadata>(std::istream&)>;
61-
62+
6263
/// A class representing an in-memory node. This could either be a file node or a directory node.
6364
class InMemoryNode {
6465
public:
@@ -67,7 +68,7 @@ class InMemoryFileSystem final {
6768
File = 0, /// Node is a File.
6869
Directory /// Node is a Directory.
6970
};
70-
71+
7172
/// Constructs an in-memory node instance.
7273
///
7374
/// @param name The name of the Node. It must be unique in the enclosing Directory.
@@ -78,38 +79,38 @@ class InMemoryFileSystem final {
7879
attributes_(std::move(attributes)),
7980
kind_(kind)
8081
{}
81-
82+
8283
InMemoryNode(InMemoryNode const&) = delete;
8384
InMemoryNode& operator=(InMemoryNode const&) = delete;
84-
85+
8586
inline virtual ~InMemoryNode() {}
86-
87+
8788
/// Returns the node attributes.
8889
inline Attributes attributes() const noexcept {
8990
return attributes_;
9091
}
91-
92+
9293
/// Sets the node attributes.
9394
///
9495
/// @param attributes The node attributes.
9596
inline void set_attributes(Attributes attributes) noexcept {
9697
attributes_ = std::move(attributes);
9798
}
98-
99+
99100
/// Returns the node kind, possible values are `File` and `Directory`.
100101
inline Kind kind() const noexcept {
101102
return kind_;
102103
}
103-
104+
104105
/// Returns the name of the node.
105106
inline const std::string& name() const noexcept {
106107
return name_;
107108
}
108-
109+
109110
inline void set_name(std::string name) noexcept {
110111
std::swap(name_, name);
111112
}
112-
113+
113114
/// Returns `true` if the node is a directory otherwise `false`.
114115
inline bool isDirectory() const noexcept {
115116
switch (kind_) {
@@ -119,58 +120,58 @@ class InMemoryFileSystem final {
119120
return false;
120121
}
121122
}
122-
123+
123124
/// Returns `true` if the node is a file otherwise `false`.
124125
inline bool isFile() const noexcept {
125126
return !isDirectory();
126127
}
127-
128+
128129
private:
129130
std::string name_;
130131
InMemoryFileSystem::Attributes attributes_;
131132
const Kind kind_;
132133
};
133-
134+
134135
/// Constructs an`InMemoryFileSystem` instance with an empty root and the specified name.
135136
///
136137
/// @param rootName The name of the root node.
137138
explicit InMemoryFileSystem(std::string rootName = "root") noexcept;
138-
139+
139140
/// Constructs an`InMemoryFileSystem` instance with the specified root.
140141
///
141142
/// @param root The root node.
142143
explicit InMemoryFileSystem(std::unique_ptr<InMemoryNode> root) noexcept
143144
:root_(std::move(root))
144145
{}
145-
146+
146147
InMemoryFileSystem(InMemoryFileSystem const&) = delete;
147148
InMemoryFileSystem& operator=(InMemoryFileSystem const&) = delete;
148-
149+
149150
virtual ~InMemoryFileSystem() {}
150-
151+
151152
/// Returns the root.
152153
InMemoryNode *root() const noexcept {
153154
return root_.get();
154155
}
155-
156+
156157
/// Checks if the node at the specified path is a directory.
157158
///
158159
/// @param canonical_path The path components from the root.
159160
/// @retval `true` if the node at the specified path is a directory otherwise `false`.
160161
bool is_directory(const std::vector<std::string>& canonical_path) noexcept;
161-
162+
162163
/// Checks if the node at the specified path is a file.
163164
///
164165
/// @param canonical_path The path components from the root.
165166
/// @retval `true` if the node at the specified path is a file otherwise `false`.
166167
bool is_file(const std::vector<std::string>& canonical_path) noexcept;
167-
168+
168169
/// Checks if the node at the specified path exists.
169170
///
170171
/// @param canonical_path The path components from the root.
171172
/// @retval `true` if the node at the specified path exists.
172173
bool exists(const std::vector<std::string>& canonical_path) const noexcept;
173-
174+
174175
/// Retrieves the canonical path of all the child nodes at the specified path. The node
175176
/// at the specified path must be a directory otherwise it returns an empty vector with the `error`
176177
/// populated.
@@ -180,23 +181,23 @@ class InMemoryFileSystem final {
180181
/// @retval paths to all the items at the specified path.
181182
std::vector<std::vector<std::string>> get_item_paths(const std::vector<std::string>& canonical_path,
182183
std::error_code& error) const noexcept;
183-
184+
184185
/// Retrieves the attributes of the item at the specified path.
185186
///
186187
/// @param canonical_path The path components from the root.
187188
/// @param error On failure, error is populated with the failure reason.
188189
/// @retval The item attributes at the specified path.
189190
std::optional<Attributes> get_attributes(const std::vector<std::string>& canonical_path,
190191
std::error_code& error) const noexcept;
191-
192+
192193
/// Retrieves the contents of the file at the specified path.
193194
///
194195
/// @param canonical_path The path components from the root.
195196
/// @param error On failure, error is populated with the failure reason.
196197
/// @retval The file contents or `nullptr` if the item at the specified path is not a file.
197198
std::shared_ptr<MemoryBuffer> get_file_content(const std::vector<std::string>& canonical_path,
198199
std::error_code& error) const noexcept;
199-
200+
200201
/// Creates an in-memory directory at the specified path.
201202
///
202203
/// @param canonical_path The path components from the root.
@@ -208,7 +209,7 @@ class InMemoryFileSystem final {
208209
Attributes attributes,
209210
bool create_intermediate_directories,
210211
std::error_code& error) noexcept;
211-
212+
212213
/// Creates an in-memory file at the specified path.
213214
///
214215
/// @param canonical_path The path components from the root.
@@ -222,15 +223,15 @@ class InMemoryFileSystem final {
222223
Attributes attributes,
223224
bool overwrite,
224225
std::error_code& error) noexcept;
225-
226+
226227
/// Removes the item at the specified path.
227228
///
228229
/// @param canonical_path The path components from the root.
229230
/// @param error On failure, error is populated with the failure reason.
230231
/// @retval `true` if the item is removed otherwise `false`.
231232
bool remove_item(const std::vector<std::string>& canonical_path,
232233
std::error_code& error) noexcept;
233-
234+
234235
/// Sets the attributes at the specified path.
235236
///
236237
/// @param canonical_path The path components from the root.
@@ -239,7 +240,7 @@ class InMemoryFileSystem final {
239240
bool set_attributes(const std::vector<std::string>& canonical_path,
240241
Attributes attributes,
241242
std::error_code& error) noexcept;
242-
243+
243244
/// Writes the item at the specified path to the filesystem.
244245
///
245246
/// @param canonical_path The path components from the root.
@@ -251,7 +252,7 @@ class InMemoryFileSystem final {
251252
const std::string& dst_path,
252253
bool recursive,
253254
std::error_code& error) const noexcept;
254-
255+
255256
/// Renames the item at the specified path, if there is already an item with the same name then
256257
/// the rename would fail.
257258
///
@@ -262,7 +263,7 @@ class InMemoryFileSystem final {
262263
bool rename_item(const std::vector<std::string>& canonical_path,
263264
const std::string& name,
264265
std::error_code& error) noexcept;
265-
266+
266267
/// Creates an`InMemoryFileSystem` from the filesystem path.
267268
///
268269
/// The structure of the `InMemoryFileSystem` is identical to the structure of the filesystem at the
@@ -275,7 +276,7 @@ class InMemoryFileSystem final {
275276
static std::unique_ptr<InMemoryFileSystem> make_from_directory(const std::string& path,
276277
FileLoadOption option,
277278
std::error_code& error) noexcept;
278-
279+
279280
/// Serializes the item at the specified path and writes it to the stream.
280281
///
281282
/// The structure of the `InMemoryFileSystem` is identical to the structure of the filesystem at the
@@ -292,7 +293,7 @@ class InMemoryFileSystem final {
292293
const MetadataWriter& metadata_writer,
293294
std::ostream& ostream,
294295
std::error_code& error) const noexcept;
295-
296+
296297
/// Serializes the item at the specified path and writes it to the stream.
297298
///
298299
/// The structure of the `InMemoryFileSystem` is identical to the structure of the filesystem at the
@@ -309,7 +310,7 @@ class InMemoryFileSystem final {
309310
const MetadataWriterInMemory& metadata_writer,
310311
void *dst,
311312
std::error_code& error) const noexcept;
312-
313+
313314
/// Computes the size of the buffer that would be needed to serialized the item at the specified path.
314315
///
315316
/// @param canonical_path The path components from the root.
@@ -319,15 +320,15 @@ class InMemoryFileSystem final {
319320
size_t get_buffer_size_for_serialization(const std::vector<std::string>& canonical_path,
320321
size_t alignment,
321322
const MetadataWriter& metadata_writer) const noexcept;
322-
323+
323324
/// Constructs an `InMemoryFileSystem` instance from the buffer contents.
324325
///
325326
/// @param buffer The memory buffer.
326327
/// @param metadata_reader The function to use when deserializing the filesystem metadata.
327328
/// @retval The constructed `InMemoryFileSystem` or `nullptr` if the deserialization failed.
328329
static std::unique_ptr<InMemoryFileSystem> make_from_buffer(const std::shared_ptr<MemoryBuffer>& buffer,
329330
const MetadataReader& metadata_reader) noexcept;
330-
331+
331332
private:
332333
const std::unique_ptr<InMemoryNode> root_;
333334
};

backends/apple/coreml/runtime/inmemoryfs/inmemory_filesystem_metadata.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
#pragma once
99

10-
#include <memory_buffer.hpp>
1110
#include <string>
1211
#include <vector>
1312
#include <unordered_map>
14-
#include <range.hpp>
13+
14+
#include "memory_buffer.hpp"
15+
#include "range.hpp"
1516

1617
namespace inmemoryfs {
1718

@@ -27,4 +28,3 @@ struct InMemoryFileSystemMetadata {
2728
};
2829

2930
} // namespace inmemoryfs
30-

backends/apple/coreml/runtime/inmemoryfs/inmemory_filesystem_py.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@
66
// Please refer to the license found in the LICENSE file in the root directory of the source tree.
77

88

9-
#include <inmemory_filesystem_utils.hpp>
109
#include <iostream>
1110
#include <memory>
12-
#include <memory_buffer.hpp>
13-
#include <memory_stream.hpp>
14-
#include <pybind11/pybind11.h>
15-
#include <pybind11/pytypes.h>
11+
#include <mutex>
1612
#include <sstream>
1713
#include <stdexcept>
1814
#include <string>
@@ -21,6 +17,13 @@
2117
#include <thread>
2218
#include <unistd.h>
2319

20+
#include <pybind11/pybind11.h>
21+
#include <pybind11/pytypes.h>
22+
23+
#include "inmemory_filesystem_utils.hpp"
24+
#include "memory_buffer.hpp"
25+
#include "memory_stream.hpp"
26+
2427
#if __has_include(<filesystem>)
2528
#include <filesystem>
2629
#elif __has_include(<experimental/filesystem>)

0 commit comments

Comments
 (0)