MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / MMAPAllocation

Method MMAPAllocation

tensorflow/lite/mmap_allocation.cc:27–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25namespace tflite {
26
27MMAPAllocation::MMAPAllocation(const char* filename,
28 ErrorReporter* error_reporter)
29 : Allocation(error_reporter, Allocation::Type::kMMap),
30 mmapped_buffer_(MAP_FAILED) {
31 mmap_fd_ = open(filename, O_RDONLY);
32 if (mmap_fd_ == -1) {
33 error_reporter_->Report("Could not open '%s'.", filename);
34 return;
35 }
36 struct stat sb;
37 fstat(mmap_fd_, &sb);
38 buffer_size_bytes_ = sb.st_size;
39 mmapped_buffer_ =
40 mmap(nullptr, buffer_size_bytes_, PROT_READ, MAP_SHARED, mmap_fd_, 0);
41 if (mmapped_buffer_ == MAP_FAILED) {
42 error_reporter_->Report("Mmap of '%s' failed.", filename);
43 return;
44 }
45}
46
47MMAPAllocation::~MMAPAllocation() {
48 if (valid()) {

Callers

nothing calls this directly

Calls 1

ReportMethod · 0.45

Tested by

no test coverage detected