Repository navigation
BQRRP MEX: bulk memcpy marshal, factor in output buffers, static libstdc++ - #2
Merged
Merged
Conversation
MATLAB ships its own older libstdc++.so.6, which lacks the GLIBCXX symbols emitted by GCC 13+, so a MEX built with a modern toolchain fails to load with 'GLIBCXX_x.y.z not found'. Statically linking libstdc++/libgcc into the MEX removes the runtime dependency. Same treatment the funnystrompp branch already carries; main needs it to be buildable with current GCC at all.
The input marshal bound a non-const TypedArray, which triggers MATLAB's copy-on-write unshare (a full deep copy of A before a single element is read), then copied element by element into a value-initialized std::vector (a third full pass to zero memory that is overwritten immediately). The marshal is now one memcpy from a const TypedArray view. Implicit mode goes further: BQRRP factors in place, so the input is marshaled straight into the out1 MATLAB buffer and the driver writes tau and J directly into their output buffers; no scratch allocations and no output round-trips remain. Explicit mode keeps one scratch copy (R extraction and ungqr post-process the factored form) allocated without value-initialization, and J is still written in place. Measured on 20000x500 implicit calls (median of 7, interleaved runs): 948 ms -> 855 ms end to end. Correctness: test_bqrrp passes all six size/type cases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Performance and buildability fixes for the BQRRP MEX (release-plan item C2). Two commits:
Statically link libstdc++ on GNU/Linux. MATLAB ships its own older
libstdc++.so.6, which lacks the GLIBCXX symbols emitted by GCC 13+, so a MEX built with a modern toolchain fails to load (GLIBCXX_x.y.z not found). This is the same treatment the funnystrompp branch already carries; main needs it to be buildable with current GCC at all. GCC/Linux-only; the flag list is empty for other compilers (AppleClang rejects-static-libgcc, and macOS has no GLIBCXX problem).Bulk memcpy marshal; factor directly inside the output buffers. The input marshal bound a non-const
TypedArray, which triggers MATLAB's copy-on-write unshare (a full deep copy of A before a single element is read), then copied element by element into a value-initializedstd::vector(a third full pass, zeroing memory that is immediately overwritten). It is now a singlememcpyfrom aconst TypedArrayview. In implicit mode the input is marshaled straight into theout1MATLAB buffer and BQRRP factors in place, writingtauandJdirectly into their output buffers, so no scratch allocations or output round-trips remain; explicit mode keeps one non-value-initialized scratch (R extraction andungqrpost-process the factored form) and writesJin place.Measured at 20000x500, implicit mode, median of 7 calls, interleaved old/new runs: 948 ms to 855 ms end to end (the ~93 ms delta is the eliminated copy passes over the 80 MB input plus the output round-trip). Correctness:
test_bqrrppasses all six size/type cases (double/single at three shapes).This is the same
copy_intoinsight already applied to the funnystrompp MEX on theadd-funnystrompp-mexbranch (where the marshal cost was measured to dominate at n = 3000); PR #1 will merge cleanly over it since the CMake block is byte-identical.