Skip to content

readonly mappedfile wrapper class, use_mapped_model_loading option - #6537

Merged
nihui merged 6 commits into
Tencent:masterfrom
nihui:mmap-loading
Feb 9, 2026
Merged

readonly mappedfile wrapper class, use_mapped_model_loading option#6537
nihui merged 6 commits into
Tencent:masterfrom
nihui:mmap-loading

Conversation

@nihui

@nihui nihui commented Feb 8, 2026

Copy link
Copy Markdown
Member

z-image-ncnn 1024x1024

end2end 9060xt 7900xtx
baseline 1m7.296s 38.35s
+mmap 58.124s 31.86s

@github-actions github-actions Bot added the core label Feb 8, 2026
@tencent-adm

Copy link
Copy Markdown
Member

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@nihui nihui changed the title a simple mappedfile wrapper [WIP] a simple mappedfile wrapper Feb 8, 2026
@codecov-commenter

codecov-commenter commented Feb 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.06%. Comparing base (7d5d32d) to head (b5e3047).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/net.cpp 80.00% 3 Missing ⚠️
src/c_api.cpp 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6537      +/-   ##
==========================================
+ Coverage   92.94%   93.06%   +0.11%     
==========================================
  Files         809      847      +38     
  Lines      256714   266763   +10049     
==========================================
+ Hits       238613   248268    +9655     
- Misses      18101    18495     +394     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions Bot added the test label Feb 9, 2026
@github-actions github-actions Bot added the doc label Feb 9, 2026
@nihui nihui changed the title [WIP] a simple mappedfile wrapper simple mappedfile wrapper, use_mapped_model_loading option Feb 9, 2026
@nihui nihui changed the title simple mappedfile wrapper, use_mapped_model_loading option readonly mappedfile wrapper class, use_mapped_model_loading option Feb 9, 2026
@nihui
nihui requested a review from Copilot February 9, 2026 11:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an optional memory-mapped (“mmap”) path for loading model weights to reduce load time and memory copying, along with a new Option::use_mapped_model_loading toggle and updated in-memory load APIs to return size_t bytes consumed.

Changes:

  • Add MappedFile wrapper and a use_mapped_model_loading Option to enable mapped model loading on supported platforms.
  • Switch Net::load_param(const unsigned char*) / Net::load_model(const unsigned char*) return types from int to size_t.
  • Update the squeezenet test configuration and docs to use/reflect the new option and signatures.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
tests/test_squeezenet.cpp Enables mapped model loading and related options for one benchmark/test configuration.
src/platform.h.in Adds cross-platform MappedFile implementation and required includes for mmap/Windows mapping.
src/option.h Adds use_mapped_model_loading and adjusts option field layout/types.
src/option.cpp Initializes the newly added Option fields.
src/net.h Updates in-memory load APIs to return size_t.
src/net.cpp Implements mapped-file loading path in Net::load_model(path) and updates in-memory load implementations.
docs/how-to-use-and-FAQ/ncnn-load-model.md Updates documentation to reflect size_t return types for in-memory loading.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/platform.h.in Outdated
Comment thread src/net.cpp Outdated
Comment thread src/net.cpp Outdated
Comment thread src/net.cpp Outdated
Comment thread src/net.cpp Outdated
Comment thread src/platform.h.in Outdated
Comment thread src/net.cpp Outdated
Comment thread src/net.h
Comment thread src/net.h
Comment thread src/platform.h.in Outdated
nihui and others added 3 commits February 9, 2026 19:41
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@nihui
nihui merged commit e5e09d5 into Tencent:master Feb 9, 2026
104 of 110 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants