Skip to content

Commit

Permalink
Adding experimental iree_io_file_map_view API.
Browse files Browse the repository at this point in the history
This allows for any iree_io_file_handle_t to be mapped into host memory
on platforms where doing so is supported. Eventually this will be
replaced with a proper mapping object and view API that will allow us
to unify the ELF loading, file_io utils, and parameter handling APIs.
  • Loading branch information
benvanik committed Dec 18, 2024
1 parent 2121abe commit ef1ef57
Show file tree
Hide file tree
Showing 17 changed files with 657 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ loadParameterIndex(ModuleOp moduleOp, StringRef path,
return failure();

// Parse the archive as a particular format.
iree_allocator_t hostAllocator = iree_allocator_system();
return handleRuntimeError(
moduleOp,
iree_io_parse_file_index(iree_make_string_view(path.data(), path.size()),
fileHandle->get(), parameterIndex),
fileHandle->get(), parameterIndex,
hostAllocator),
"parsing parameter archive");
}

Expand Down
9 changes: 5 additions & 4 deletions runtime/bindings/python/io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ void ParameterIndexAddFromFileHandle(ParameterIndex &self, std::string &key,
void ParameterIndexParseFileHandle(ParameterIndex &self,
FileHandle &file_handle,
std::string &format) {
CheckApiStatus(iree_io_parse_file_index(
iree_make_string_view(format.data(), format.size()),
file_handle.raw_ptr(), self.raw_ptr()),
"Could not parse parameter file index");
CheckApiStatus(
iree_io_parse_file_index(
iree_make_string_view(format.data(), format.size()),
file_handle.raw_ptr(), self.raw_ptr(), iree_allocator_system()),
"Could not parse parameter file index");
}

void ParameterIndexLoadFile(ParameterIndex &self, std::string &file_path,
Expand Down
4 changes: 3 additions & 1 deletion runtime/src/iree/base/internal/file_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,9 @@ iree_status_t iree_file_create_mapped(const char* path, uint64_t file_size,
IREE_TRACE_ZONE_BEGIN(z0);

iree_file_contents_t* contents = NULL;
iree_allocator_malloc(allocator, sizeof(*contents), (void**)&contents);
IREE_RETURN_AND_END_ZONE_IF_ERROR(
z0,
iree_allocator_malloc(allocator, sizeof(*contents), (void**)&contents));
contents->allocator = allocator;

iree_status_t status = iree_file_create_mapped_platform(
Expand Down
Loading

0 comments on commit ef1ef57

Please sign in to comment.