-
Notifications
You must be signed in to change notification settings - Fork 2k
Enable SymbolicSgdLogisticRegression (SymSgdNative) on arm64 #7671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vladimir-aubrecht
wants to merge
2
commits into
dotnet:main
Choose a base branch
from
vladimir-aubrecht:feature/symsgd-arm64
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| project(MklImportsArm) | ||
|
|
||
| # On ARM platforms, Intel MKL is not available. This target provides a small, | ||
| # self-contained libMklImports covering exactly the symbols SymSGD needs | ||
| # (dense/sparse level-1 CBLAS) plus DFTI stubs, with NO external BLAS | ||
| # dependency. This is required because the CI cross-compilation sysroots do | ||
| # not ship OpenBLAS or any system BLAS. | ||
|
|
||
| set(SOURCES | ||
| MklImportsArm.c | ||
| ) | ||
|
|
||
| if(NOT WIN32) | ||
| list(APPEND SOURCES ${VERSION_FILE_PATH}) | ||
| SET(CMAKE_SKIP_BUILD_RPATH FALSE) | ||
| SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) | ||
| SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) | ||
| SET(CMAKE_INSTALL_RPATH "$ORIGIN/") | ||
| endif() | ||
|
|
||
| add_library(MklImports SHARED ${SOURCES} ${RESOURCES}) | ||
|
|
||
| install_library_and_symbols(MklImports) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| // ARM replacement for Intel MKL (libMklImports.so). | ||
| // | ||
| // This provides a small, self-contained libMklImports for arm/arm64 that | ||
| // covers exactly the symbols SymSGD needs, with no external BLAS dependency. | ||
| // That is important because the cross-compilation sysroots used in CI do not | ||
| // ship OpenBLAS (or any system BLAS), so linking against one is not an option. | ||
| // | ||
| // SymSGD uses only four CBLAS routines: | ||
| // * cblas_sdot / cblas_saxpy - dense single-precision dot and AXPY, | ||
| // * cblas_sdoti / cblas_saxpyi - their sparse counterparts (MKL extensions). | ||
| // All four are implemented below as plain C loops. With -O3 the compiler | ||
| // autovectorizes the dense paths to NEON, matching hand-written BLAS closely. | ||
| // | ||
| // MKL DFTI (FFT) functions are stubbed — they are referenced by the managed | ||
| // MKL Components initializer but not used by SymSGD. The stubs return error | ||
| // codes so any actual FFT call fails cleanly rather than crashing. | ||
|
|
||
| // The native build is compiled with -fvisibility=hidden, so every symbol that | ||
| // must be visible to SymSgdNative (the CBLAS routines) or to the managed | ||
| // P/Invoke layer (DftiErrorMessage) has to be exported explicitly. | ||
| #if defined(_WIN32) | ||
| #define MKLIMPORTS_EXPORT __declspec(dllexport) | ||
| #else | ||
| #define MKLIMPORTS_EXPORT __attribute__((visibility("default"))) | ||
| #endif | ||
|
|
||
| // --- Dense BLAS (CBLAS, level 1) --- | ||
|
|
||
| MKLIMPORTS_EXPORT float cblas_sdot(const int n, const float *x, const int incx, | ||
| const float *y, const int incy) | ||
| { | ||
| float result = 0.0f; | ||
| if (incx == 1 && incy == 1) | ||
| { | ||
| for (int i = 0; i < n; i++) | ||
| result += x[i] * y[i]; | ||
| } | ||
| else | ||
| { | ||
| int ix = incx < 0 ? (1 - n) * incx : 0; | ||
| int iy = incy < 0 ? (1 - n) * incy : 0; | ||
| for (int i = 0; i < n; i++, ix += incx, iy += incy) | ||
| result += x[ix] * y[iy]; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| MKLIMPORTS_EXPORT void cblas_saxpy(const int n, const float a, const float *x, const int incx, | ||
| float *y, const int incy) | ||
| { | ||
| if (a == 0.0f) | ||
| return; | ||
| if (incx == 1 && incy == 1) | ||
| { | ||
| for (int i = 0; i < n; i++) | ||
| y[i] += a * x[i]; | ||
| } | ||
| else | ||
| { | ||
| int ix = incx < 0 ? (1 - n) * incx : 0; | ||
| int iy = incy < 0 ? (1 - n) * incy : 0; | ||
| for (int i = 0; i < n; i++, ix += incx, iy += incy) | ||
| y[iy] += a * x[ix]; | ||
| } | ||
| } | ||
|
|
||
| // --- Sparse BLAS (MKL extensions, not in standard BLAS) --- | ||
|
|
||
| MKLIMPORTS_EXPORT void cblas_saxpyi(const int nz, const float a, | ||
| const float *x, const int *indx, float *y) | ||
| { | ||
| for (int i = 0; i < nz; i++) | ||
| y[indx[i]] += a * x[i]; | ||
| } | ||
|
|
||
| MKLIMPORTS_EXPORT float cblas_sdoti(const int nz, const float *x, | ||
| const int *indx, const float *y) | ||
| { | ||
| float result = 0.0f; | ||
| for (int i = 0; i < nz; i++) | ||
| result += x[i] * y[indx[i]]; | ||
| return result; | ||
| } | ||
|
|
||
| // --- DFTI (FFT) stubs --- | ||
|
|
||
| MKLIMPORTS_EXPORT const char* DftiErrorMessage(long status) | ||
| { | ||
| return "DFTI not available (arm64 MKL shim build)"; | ||
| } | ||
|
|
||
| MKLIMPORTS_EXPORT long DftiCreateDescriptor(void **h, int precision, int domain, int dim, ...) | ||
| { | ||
| *h = (void*)0; | ||
| return -1; | ||
| } | ||
|
|
||
| MKLIMPORTS_EXPORT long DftiSetValue(void *h, int param, ...) | ||
| { | ||
| return -1; | ||
| } | ||
|
|
||
| MKLIMPORTS_EXPORT long DftiCommitDescriptor(void *h) { return -1; } | ||
| MKLIMPORTS_EXPORT long DftiComputeForward(void *h, ...) { return -1; } | ||
| MKLIMPORTS_EXPORT long DftiComputeBackward(void *h, ...) { return -1; } | ||
| MKLIMPORTS_EXPORT long DftiFreeDescriptor(void **h) | ||
| { | ||
| // Match MKL's contract: clear the caller's handle after freeing so callers | ||
| // that rely on the descriptor being nulled out (e.g. the managed | ||
| // FreeDescriptor(ref IntPtr) P/Invoke) behave correctly. | ||
| if (h != (void*)0) | ||
| *h = (void*)0; | ||
| return 0; | ||
| } |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.