Skip to content

Commit b3456eb

Browse files
cymbalrushfacebook-github-bot
authored andcommitted
Optimize memory when exporting. (#2341)
Summary: CoreML delegate when converting the `mlpackage` to an in-memory representation reads the directory contents in the `mlpackage` directory and writes it to a memory buffer this is expensive and the copying is not required. The change in the PR addresses by memory mapping the file contents to fixed addresses in the allocated memory, no memory is dirtied and the OS will bring the pages only when the bytes are read. Pull Request resolved: #2341 Reviewed By: digantdesai Differential Revision: D54997652 Pulled By: shoumikhin fbshipit-source-id: 2f479be5241f6d2c60005a2f6410514ee967a46e
1 parent c9dea32 commit b3456eb

25 files changed

+989
-279
lines changed

backends/apple/coreml/runtime/delegate/ETCoreMLModelManager.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ - (nullable NSURL *)compiledModelURLWithIdentifier:(NSString *)identifier
457457
using namespace inmemoryfs;
458458

459459
auto buffer = MemoryBuffer::make_unowned(const_cast<void *>(data.bytes), data.length);
460-
std::unique_ptr<InMemoryFileSystem> inMemoryFS = inmemoryfs::make(buffer);
460+
std::unique_ptr<InMemoryFileSystem> inMemoryFS = inmemoryfs::make_from_buffer(std::move(buffer));
461461
if (!inMemoryFS) {
462462
ETCoreMLLogErrorAndSetNSError(error,
463463
ETCoreMLErrorCorruptedModel,

backends/apple/coreml/runtime/delegate/backend_delegate.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ MLMultiArrayDataType get_data_type(MultiArray::DataType dataType) {
6363
return MLMultiArrayDataTypeFloat32;
6464
}
6565
case MultiArray::DataType::Double: {
66-
return MLMultiArrayDataTypeFloat64;
66+
return MLMultiArrayDataTypeDouble;
6767
}
6868
case MultiArray::DataType::Int: {
6969
return MLMultiArrayDataTypeInt32;

backends/apple/coreml/runtime/delegate/coreml_backend_delegate.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ ModelLoggingOptions get_logging_options(BackendExecutionContext& context) {
149149
ET_CHECK_OR_RETURN_ERROR(handle != nullptr,
150150
InvalidProgram,
151151
"%s: Failed to init the model.", ETCoreMLStrings.delegateIdentifier.UTF8String);
152-
152+
processed->Free();
153153
return handle;
154154
}
155155

0 commit comments

Comments
 (0)