Enable SymbolicSgdLogisticRegression (SymSgdNative) on arm64 - #7671
Enable SymbolicSgdLogisticRegression (SymSgdNative) on arm64#7671vladimir-aubrecht wants to merge 1 commit into
Conversation
Build SymSgdNative and a small self-contained libMklImports shim on arm/arm64 so the SymbolicSgdLogisticRegression trainer works there without Intel MKL. - MklImportsArm: implement the four CBLAS routines SymSGD needs (sdot, saxpy, sdoti, saxpyi) as portable C with no external BLAS dependency, plus DFTI stubs. Drop find_package(BLAS) so it configures in the CI cross-compilation sysroots (which ship no BLAS). Export the symbols explicitly since the native build uses -fvisibility=hidden. - CMake: build MklImportsArm + SymSgdNative on arm, link SymSgdNative against the shim, and make the CBLAS calling convention portable. - Directory.Build.targets: ship libMklImports and libSymSgdNative next to the managed assemblies on arm. - SymSgdClassificationTrainer: marshal the native bool parameters of LearnAll as I1. The default 4-byte bool marshalling corrupts later stack arguments and segfaults on arm64. Fixes dotnet#5798 Co-authored-by: Anna Maresova <anicka@anicka.net> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@vladimir-aubrecht please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement ( “Agreement” ) is agreed to by the party signing below ( “You” ), 1. Definitions. “Code” means the computer software code, whether in human-readable or machine-executable form, “Project” means any of the projects owned or managed by .NET Foundation and offered under a license “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any “Submission” means the Code and any other copyrightable material Submitted by You, including any 2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any 3. Originality of Work. You represent that each of Your Submissions is entirely Your 4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else 5. Licenses. a. Copyright License. You grant .NET Foundation, and those who receive the Submission directly b. Patent License. You grant .NET Foundation, and those who receive the Submission directly or c. Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement. 6. Representations and Warranties. You represent that You are legally entitled to grant the above 7. Notice to .NET Foundation. You agree to notify .NET Foundation in writing of any facts or 8. Information about Submissions. You agree that contributions to Projects and information about 9. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and 10. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and .NET Foundation dedicates this Contribution License Agreement to the public domain according to the Creative Commons CC0 1. |
Summary
Enables the
SymbolicSgdLogisticRegressiontrainer (backed bySymSgdNative) on arm/arm64, where Intel MKL is unavailable. Fixes #5798.SymSGD uses only four CBLAS routines (
sdot,saxpy,sdoti,saxpyi). This PR provides them via a tiny, self-containedlibMklImportsshim built from portable C — with no external BLAS dependency — so it configures and links in the CI cross-compilation sysroots (which ship no OpenBLAS/BLAS).Changes
src/Native/MklImportsArm/(new): implements the four CBLAS routines as plain C loops (-O3autovectorizes the dense paths to NEON) plus MKL DFTI stubs. Nofind_package(BLAS)— zero external deps. Symbols are exported explicitly because the native build uses-fvisibility=hidden.src/Native/CMakeLists.txt: buildMklImportsArm+SymSgdNativeon arm.src/Native/SymSgdNative/CMakeLists.txt: linkSymSgdNativeagainst the shim on arm.src/Native/SymSgdNative/SparseBLAS.h: make the CBLAS calling convention portable (__cdeclonly on_WIN32).Directory.Build.targets: shiplibMklImportsandlibSymSgdNativenext to the managed assemblies on arm.SymSgdClassificationTrainer.cs: marshalLearnAll's nativeboolparameters asUnmanagedType.I1. The default 4-byteboolmarshalling corrupts later stack arguments and segfaults on arm64 (works on x64 by luck).Testing
Built native (Release + Debug) and ran the SymSGD trainer tests on Apple Silicon (arm64):
TestEstimatorSymSgdClassificationTrainerTestEstimatorSymSgdInitPredictorSimpleTrainAndPredictSymSGD3 passed, 0 failed. Without the
boolmarshalling fix, these crash the test host with a SIGSEGV insideLearnAll.Notes
SparseBLAS.hcalling-convention guard) is based on prior work by @anicka-net (credited as co-author).Microsoft.ML.Mkl.Components(OLS,VectorWhitening) andMicrosoft.ML.TimeSeriesstill require a real BLAS/LAPACK and are out of scope here.