Skip to content

Commit 677a0b8

Browse files
Enable SymbolicSgdLogisticRegression (SymSgdNative) on arm64 (#7671)
Enables the SymbolicSgdLogisticRegression trainer (backed by SymSgdNative) 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-contained libMklImports shim 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).
1 parent 31acbe3 commit 677a0b8

21 files changed

Lines changed: 1757 additions & 42 deletions

‎.vsts-dotnet-ci.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jobs:
129129
- template: /build/ci/job-template.yml
130130
parameters:
131131
architecture: arm64
132-
name: MacOS_cross_arm64
132+
name: MacOS_arm64
133133
buildScript: ./build.sh
134134
customMatrixes:
135135
Debug_Build:
@@ -144,7 +144,7 @@ jobs:
144144
_targetFramework: net8.0
145145
innerLoop: true
146146
pool:
147-
vmImage: macOS-15
147+
vmImage: macOS-15-arm64
148148
helixQueue: osx.15.arm64.open
149149

150150
- template: /build/ci/job-template.yml

‎Directory.Build.targets‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
</ItemGroup>
3131

3232
<ItemGroup Condition="'$(TargetArchitecture)' == 'arm64' Or '$(TargetArchitecture)' == 'arm'">
33+
<!-- Remove native libraries that are unavailable on ARM. SymSgdNative is intentionally
34+
not removed because it is built with its self-contained CBLAS shim on ARM. -->
3335
<NativeAssemblyReference Remove="MklImports"/>
3436
<NativeAssemblyReference Remove="CpuMathNative"/>
3537
<NativeAssemblyReference Remove="FastTreeNative"/>
36-
<NativeAssemblyReference Remove="SymSgdNative"/>
3738
<NativeAssemblyReference Remove="MklProxyNative"/>
3839
<NativeAssemblyReference Remove="libiomp5md"/>
3940
</ItemGroup>

‎build/vsts-ci.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ variables:
3131
value: 1es-windows-2022
3232
- name: MacImage
3333
value: macOS-15
34+
- name: MacArm64Image
35+
value: macOS-15-arm64
3436
- ${{ if and(notin(variables['Build.Reason'], 'PullRequest'), eq(variables['Build.SourceBranch'], 'refs/heads/main')) }}:
3537
- name: enableSourceIndex
3638
value: true
@@ -158,7 +160,7 @@ extends:
158160
################################################################################
159161
pool:
160162
name: Azure Pipelines
161-
vmImage: $(MacImage)
163+
vmImage: $(MacArm64Image)
162164
os: macOS
163165
templateContext:
164166
outputs:

‎docs/building/unix-instructions.md‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,11 @@ macOS 10.13 (High Sierra) or higher is needed to build dotnet/machinelearning. W
6464

6565
On macOS a few components are needed which are not provided by a default developer setup:
6666
* cmake 3.10.3
67-
* libomp 7
67+
* libomp
6868
* gettext
6969
* All the requirements necessary to run .NET Core 3.1 applications. To view macOS prerequisites click [here](https://docs.microsoft.com/en-us/dotnet/core/install/macos?tabs=netcore31#dependencies).
7070

7171
One way of obtaining CMake and other required libraries is via [Homebrew](https://brew.sh):
7272
```sh
73-
$ brew update && brew install cmake https://raw.githubusercontent.com/dotnet/machinelearning/main/build/libomp.rb gettext && brew link gettext --force && brew link libomp --force
73+
$ brew update && brew install cmake libomp gettext && brew link gettext --force && brew link libomp --force
7474
```
75-
76-
Please note that newer versions of Homebrew [don't allow installing directly from a URL](https://github.com/Homebrew/brew/issues/8791). If you run into this issue, you may need to download libomp.rb first and install it with the local file instead.
77-
78-
Also, libomp version 7.0.0 doesn't have a cask for Big Sur. You can work around this by downloading the libomp.rb file and then calling `brew install libomp.rb --build-from-source --formula`.

‎docs/project-docs/components-and-dependencies.md‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ML.NET redistributes Intel MKL as Microsoft.ML.MKL.Redist in which is a minimize
2424
| `Microsoft.ML.FastTree` | `FastTreeRankingTrainer` | Optional native acceleration | Stable | Native library used on x86/x64; managed fallback |
2525
| `Microsoft.ML.ImageAnalytics` | `MLImage` (image exchange type) | `libSkiaSharp` | Stable | Wrapper over SkiaSharp / Google Skia; supported where dependency is supported |
2626
| `Microsoft.ML.LightGBM` | `LightGbm\*Trainer` | `LightGBM` | Stable | Wrapper over LightGBM; supported where dependency is supported |
27-
| `Microsoft.ML.MKL.Components` | `SymbolicSgdLogisticRegressionBinaryTrainer` | Intel MKL | Stable | Only works where Intel MKL works |
27+
| `Microsoft.ML.MKL.Components` | `SymbolicSgdLogisticRegressionBinaryTrainer` | Intel MKL (x86/x64); OpenMP runtime | Stable | Uses a built-in CBLAS implementation on ARM |
2828
| `Microsoft.ML.MKL.Redist` | Internal native Intel MKL | `libomp` | Stable | Not for direct reference; win-x86/x64 only |
2929
| `Microsoft.ML.OneDal` | Internal native Intel OneDal | Intel OneDAL | Preview | Not for direct reference; x64 only |
3030
| `Microsoft.ML.OnnxConverter` | Adds ONNX export support | `Microsoft.ML.OnnxRuntime` | Stable | Wrapper over ONNX Runtime; supports "bring your own" runtime |
@@ -266,4 +266,3 @@ graph TD
266266
class AutoML,CodeGen,FastTree,LightGBM,Recommender,TimeSeries,TorchSharp,ImageAnalytics,DnnFeaturizerAlexNet,DnnFeaturizerResNet18,DnnFeaturizerResNet50,DnnFeaturizerResNet101,DnnFeaturizerModelRedist,Vision,OnnxConverter,OnnxTransformer,TensorFlow,MKLComponents,Ensemble,EntryPoints,Experimental,FairLearn,Parquet,DataAnalysis,GenAICore,GenAILLaMA,GenAIMistral,GenAIPhi,Tokenizers,TokenizersGpt2,TokenizersR50k,TokenizersP50k,TokenizersO200k,TokenizersCl100k,SampleUtils algorithm
267267
class CpuMath,MKLRedist,OneDal bundled
268268
```
269-

‎docs/project-docs/platform-limitations.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ While ML.NET is cross-platform, there are some limitations for specific platform
88
| **Windows** | Yes | Yes |
99
| **Linux** | Yes | Yes |
1010
| **macOS** | Yes | Yes |
11-
| **ARM64** / **Apple M1** | Yes, with **limitations**.</br></br>The following are *not supported*:<ul><li>Symbolic SGD</li><li>TensorFlow</li><li>OLS</li><li>TimeSeries SSA</li><li>TimeSeries SrCNN</li><li>ONNX*</li><li>Light GBM*</li></ul>\**You can add support by compiling (no pre-compiled binaries provided).* | Yes, with **limitations**.</br></br>The following are *not supported*: <ul><li>Symbolic SGD</li><li>TensorFlow</li><li>OLS</li><li>TimeSeries SSA</li><li>TimeSeries SrCNN</li><li>ONNX</li></ul>|
11+
| **ARM64** / **Apple M1** | Yes, with **limitations**.</br></br>The following are *not supported*:<ul><li>TensorFlow</li><li>OLS</li><li>TimeSeries SSA</li><li>TimeSeries SrCNN</li><li>ONNX*</li><li>Light GBM*</li></ul>\**You can add support by compiling (no pre-compiled binaries provided).* | Yes, with **limitations**.</br></br>The following are *not supported*: <ul><li>TensorFlow</li><li>OLS</li><li>TimeSeries SSA</li><li>TimeSeries SrCNN</li><li>ONNX</li></ul>|
1212
| **Blazor WASM** | Yes, with **limitations**.</br></br>The following are *not supported*:<ul><li>Symbolic SGD</li><li>TensorFlow</li><li>OLS</li><li>TimeSeries SSA</li><li>TimeSeries SrCNN</li><li>ONNX</li><li>Light GBM</li><li>LDA</li><li>Matrix Factorization</li></ul> *Note: You must currently set the <code>EnableMLUnsupportedPlatformTargetCheck</code> flag to <code>false</code> to use ML.NET in Blazor.* | Yes, with **limitations**.</br></br>The following are *not supported*:<ul><li>Symbolic SGD</li><li>TensorFlow</li><li>OLS</li><li>TimeSeries SSA</li><li>TimeSeries SrCNN</li><li>ONNX</li><li>Light GBM</li><li>LDA</li><li>Matrix Factorization</li> |
1313

14+
> Symbolic SGD on macOS requires the Homebrew `libomp` package.
15+
>
1416
> Note: All the limitations listed above will throw a <code>DLL not found</code> exception.
1517
1618
If you are blocked by any of these limitations or would like to see different behavior when hitting them, please let us know by [filing an issue](https://github.com/dotnet/machinelearning/issues/new?assignees=&labels=&template=suggest-a-feature.md&title=).

‎eng/helix.proj‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@
111111

112112
<HelixPreCommands Condition="$(HelixTargetQueues.ToLowerInvariant().Contains('osx'))">$(HelixPreCommands);export LD_LIBRARY_PATH=/opt/homebrew/opt/mono-libgdiplus/lib;ls /usr/lib;ls $HELIX_WORKITEM_ROOT;export KMP_DUPLICATE_LIB_OK=TRUE;otool -L $HELIX_WORKITEM_ROOT/runtimes/osx-x64/native/lib_lightgbm.dylib</HelixPreCommands>
113113

114-
<!-- macOS x64 only: add DYLD paths so the local libomp/libiomp5 in the work item is discoverable -->
115-
<HelixPreCommands Condition="$(HelixTargetQueues.ToLowerInvariant().Contains('osx')) and '$(BuildArchitecture)'=='x64'">$(HelixPreCommands);export DYLD_LIBRARY_PATH=$HELIX_WORKITEM_ROOT:$DYLD_LIBRARY_PATH;export DYLD_FALLBACK_LIBRARY_PATH=$HELIX_WORKITEM_ROOT:$DYLD_FALLBACK_LIBRARY_PATH</HelixPreCommands>
114+
<!-- Add DYLD paths so the local libomp/libiomp5 in the work item is discoverable. -->
115+
<HelixPreCommands Condition="$(HelixTargetQueues.ToLowerInvariant().Contains('osx'))">$(HelixPreCommands);export DYLD_LIBRARY_PATH=$HELIX_WORKITEM_ROOT:$DYLD_LIBRARY_PATH;export DYLD_FALLBACK_LIBRARY_PATH=$HELIX_WORKITEM_ROOT:$DYLD_FALLBACK_LIBRARY_PATH</HelixPreCommands>
116116

117117
<HelixPreCommands Condition="$(HelixTargetQueues.ToLowerInvariant().Contains('armarch'))">$(HelixPreCommands);sudo apt update;sudo apt-get install libomp-dev libomp5 -y</HelixPreCommands>
118118

@@ -121,10 +121,23 @@
121121

122122
<RunTestScript Condition="'$(OS)' != 'Windows_NT'">runTests.sh</RunTestScript>
123123
<RunTestScript Condition="'$(OS)' == 'Windows_NT'">.\runTests.cmd</RunTestScript>
124+
</PropertyGroup>
125+
126+
<Exec Condition="$(HelixTargetQueues.ToLowerInvariant().Contains('osx'))"
127+
Command="brew --prefix libomp"
128+
ConsoleToMSBuild="true"
129+
StandardOutputImportance="Low">
130+
<Output TaskParameter="ConsoleOutput" PropertyName="MacLibOmpPrefix" />
131+
</Exec>
124132

125-
<MacFilesToCopy>/usr/local/opt/libomp/lib/libomp.dylib;</MacFilesToCopy>
133+
<PropertyGroup Condition="$(HelixTargetQueues.ToLowerInvariant().Contains('osx'))">
134+
<MacLibOmpPath>$(MacLibOmpPrefix)/lib/libomp.dylib</MacLibOmpPath>
135+
<MacFilesToCopy>$(MacLibOmpPath);</MacFilesToCopy>
126136
</PropertyGroup>
127137

138+
<Error Condition="$(HelixTargetQueues.ToLowerInvariant().Contains('osx')) And !Exists('$(MacLibOmpPath)')"
139+
Text="Unable to find the Homebrew libomp runtime at $(MacLibOmpPath)." />
140+
128141
<!-- Copy OpenMP runtime(s) to the publish folders for OSX -->
129142
<Copy Condition="$(HelixTargetQueues.ToLowerInvariant().Contains('osx'))"
130143
SourceFiles = "$(MacFilesToCopy)"
@@ -136,12 +149,12 @@
136149

137150
<!-- Fix up install names where we know about libomp.dylib usage -->
138151
<Exec Condition="Exists('$(BUILD_SOURCESDIRECTORY)\artifacts\bin\%(ProjectsWithTargetFramework.Filename)\$(BuildConfig)\%(ProjectsWithTargetFramework.TargetFrameworks)$(PublishFolder)\libSymSgdNative.dylib') AND $(HelixTargetQueues.ToLowerInvariant().Contains('osx'))"
139-
Command="install_name_tool -change &quot;/usr/local/opt/libomp/lib/libomp.dylib&quot; &quot;@loader_path/libomp.dylib&quot; $(BUILD_SOURCESDIRECTORY)/artifacts/bin/%(ProjectsWithTargetFramework.Filename)/$(BuildConfig)/%(ProjectsWithTargetFramework.TargetFrameworks)$(PublishFolder)/libSymSgdNative.dylib" />
152+
Command="install_name_tool -change &quot;$(MacLibOmpPath)&quot; &quot;@loader_path/libomp.dylib&quot; $(BUILD_SOURCESDIRECTORY)/artifacts/bin/%(ProjectsWithTargetFramework.Filename)/$(BuildConfig)/%(ProjectsWithTargetFramework.TargetFrameworks)$(PublishFolder)/libSymSgdNative.dylib" />
140153

141-
<Exec Condition="Exists('$(BUILD_SOURCESDIRECTORY)\artifacts\bin\%(ProjectsWithTargetFramework.Filename)\$(BuildConfig)\%(ProjectsWithTargetFramework.TargetFrameworks)$(PublishFolder)\runtimes\osx-x64\native\lib_lightgbm.dylib') AND $(HelixTargetQueues.ToLowerInvariant().Contains('osx'))"
154+
<Exec Condition="'$(BuildArchitecture)' == 'x64' AND Exists('$(BUILD_SOURCESDIRECTORY)\artifacts\bin\%(ProjectsWithTargetFramework.Filename)\$(BuildConfig)\%(ProjectsWithTargetFramework.TargetFrameworks)$(PublishFolder)\runtimes\osx-x64\native\lib_lightgbm.dylib') AND $(HelixTargetQueues.ToLowerInvariant().Contains('osx'))"
142155
Command="install_name_tool -change &quot;/usr/local/opt/libomp/lib/libomp.dylib&quot; &quot;@rpath/libomp.dylib&quot; $(BUILD_SOURCESDIRECTORY)/artifacts/bin/%(ProjectsWithTargetFramework.Filename)/$(BuildConfig)/%(ProjectsWithTargetFramework.TargetFrameworks)$(PublishFolder)/runtimes/osx-x64/native/lib_lightgbm.dylib" />
143156

144-
<Exec Condition="Exists('$(BUILD_SOURCESDIRECTORY)\artifacts\bin\%(ProjectsWithTargetFramework.Filename)\$(BuildConfig)\%(ProjectsWithTargetFramework.TargetFrameworks)$(PublishFolder)\runtimes\osx-x64\native\libonnxruntime.dylib') AND $(HelixTargetQueues.ToLowerInvariant().Contains('osx'))"
157+
<Exec Condition="'$(BuildArchitecture)' == 'x64' AND Exists('$(BUILD_SOURCESDIRECTORY)\artifacts\bin\%(ProjectsWithTargetFramework.Filename)\$(BuildConfig)\%(ProjectsWithTargetFramework.TargetFrameworks)$(PublishFolder)\runtimes\osx-x64\native\libonnxruntime.dylib') AND $(HelixTargetQueues.ToLowerInvariant().Contains('osx'))"
145158
Command="install_name_tool -change &quot;/usr/local/opt/libomp/lib/libomp.dylib&quot; &quot;@loader_path/libomp.dylib&quot; $(BUILD_SOURCESDIRECTORY)/artifacts/bin/%(ProjectsWithTargetFramework.Filename)/$(BuildConfig)/%(ProjectsWithTargetFramework.TargetFrameworks)$(PublishFolder)/runtimes/osx-x64/native/libonnxruntime.dylib" />
146159

147160
<!-- macOS x64 ONLY: if libiomp5.dylib isn't present in the publish folder, duplicate libomp.dylib as libiomp5.dylib -->

‎src/Microsoft.ML.Mkl.Components/SymSgdClassificationTrainer.cs‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,16 @@ private void CheckLabel(RoleMappedData examples, out int weightSetCount)
825825
private static unsafe class Native
826826
{
827827
//To triger the loading of MKL library since SymSGD native library depends on it.
828-
static Native() => ErrorMessage(0);
828+
//On ARM there is no MKL: SymSgdNative bundles the small CBLAS shim it needs and no
829+
//libMklImports is shipped, so skip this call (it would fail to load MklImports).
830+
static Native()
831+
{
832+
if (RuntimeInformation.ProcessArchitecture != Architecture.Arm64 &&
833+
RuntimeInformation.ProcessArchitecture != Architecture.Arm)
834+
{
835+
ErrorMessage(0);
836+
}
837+
}
829838

830839
internal const string NativePath = "SymSgdNative";
831840
internal const string MklPath = "MklImports";
@@ -834,8 +843,8 @@ private static unsafe class Native
834843

835844
[DllImport(NativePath), SuppressUnmanagedCodeSecurity]
836845
private static extern void LearnAll(int totalNumInstances, int* instSizes, int** instIndices,
837-
float** instValues, float* labels, bool tuneLR, ref float lr, float l2Const, float piw, float* weightVector, ref float bias,
838-
int numFeatres, int numPasses, int numThreads, bool tuneNumLocIter, ref int numLocIter, float tolerance, bool needShuffle, bool shouldInitialize,
846+
float** instValues, float* labels, [MarshalAs(UnmanagedType.I1)] bool tuneLR, ref float lr, float l2Const, float piw, float* weightVector, ref float bias,
847+
int numFeatres, int numPasses, int numThreads, [MarshalAs(UnmanagedType.I1)] bool tuneNumLocIter, ref int numLocIter, float tolerance, [MarshalAs(UnmanagedType.I1)] bool needShuffle, [MarshalAs(UnmanagedType.I1)] bool shouldInitialize,
839848
State* state, ChannelCallBack info);
840849

841850
/// <summary>

‎src/Native/CMakeLists.txt‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,11 @@ if(NOT ${ARCHITECTURE} MATCHES "arm.*")
265265
add_subdirectory(CpuMathNative)
266266
add_subdirectory(FastTreeNative)
267267
add_subdirectory(MklProxyNative)
268-
# TODO: once we fix the 4 intel MKL methods, SymSgdNative will need to go back in.
269-
add_subdirectory(SymSgdNative)
270-
endif()
268+
endif()
269+
270+
# On ARM, SymSgdNative compiles the small MklImportsArm CBLAS shim directly
271+
# (see SymSgdNative/CMakeLists.txt), so we do not build a separate libMklImports.
272+
add_subdirectory(SymSgdNative)
271273

272274
if(${ARCHITECTURE} MATCHES "[xX].*64")
273275
add_subdirectory(OneDalNative)
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
// ARM replacement for Intel MKL (libMklImports.so).
6+
//
7+
// This provides a small, self-contained libMklImports for arm/arm64 that
8+
// covers exactly the symbols SymSGD needs, with no external BLAS dependency.
9+
// That is important because the cross-compilation sysroots used in CI do not
10+
// ship OpenBLAS (or any system BLAS), so linking against one is not an option.
11+
//
12+
// SymSGD uses only four CBLAS routines:
13+
// * cblas_sdot / cblas_saxpy - dense single-precision dot and AXPY,
14+
// * cblas_sdoti / cblas_saxpyi - their sparse counterparts (MKL extensions).
15+
// All four are implemented below as plain C loops. With -O3 the compiler
16+
// autovectorizes the dense paths to NEON, matching hand-written BLAS closely.
17+
//
18+
// MKL DFTI (FFT) functions are stubbed — they are referenced by the managed
19+
// MKL Components initializer but not used by SymSGD. The stubs return error
20+
// codes so any actual FFT call fails cleanly rather than crashing.
21+
22+
// The native build is compiled with -fvisibility=hidden, so every symbol that
23+
// must be visible to SymSgdNative (the CBLAS routines) or to the managed
24+
// P/Invoke layer (DftiErrorMessage) has to be exported explicitly.
25+
#if defined(_WIN32)
26+
#define MKLIMPORTS_EXPORT __declspec(dllexport)
27+
#else
28+
#define MKLIMPORTS_EXPORT __attribute__((visibility("default")))
29+
#endif
30+
31+
// --- Dense BLAS (CBLAS, level 1) ---
32+
33+
MKLIMPORTS_EXPORT float cblas_sdot(const int n, const float *x, const int incx,
34+
const float *y, const int incy)
35+
{
36+
float result = 0.0f;
37+
if (incx == 1 && incy == 1)
38+
{
39+
for (int i = 0; i < n; i++)
40+
result += x[i] * y[i];
41+
}
42+
else
43+
{
44+
int ix = incx < 0 ? (1 - n) * incx : 0;
45+
int iy = incy < 0 ? (1 - n) * incy : 0;
46+
for (int i = 0; i < n; i++, ix += incx, iy += incy)
47+
result += x[ix] * y[iy];
48+
}
49+
return result;
50+
}
51+
52+
MKLIMPORTS_EXPORT void cblas_saxpy(const int n, const float a, const float *x, const int incx,
53+
float *y, const int incy)
54+
{
55+
if (a == 0.0f)
56+
return;
57+
if (incx == 1 && incy == 1)
58+
{
59+
for (int i = 0; i < n; i++)
60+
y[i] += a * x[i];
61+
}
62+
else
63+
{
64+
int ix = incx < 0 ? (1 - n) * incx : 0;
65+
int iy = incy < 0 ? (1 - n) * incy : 0;
66+
for (int i = 0; i < n; i++, ix += incx, iy += incy)
67+
y[iy] += a * x[ix];
68+
}
69+
}
70+
71+
// --- Sparse BLAS (MKL extensions, not in standard BLAS) ---
72+
73+
MKLIMPORTS_EXPORT void cblas_saxpyi(const int nz, const float a,
74+
const float *x, const int *indx, float *y)
75+
{
76+
for (int i = 0; i < nz; i++)
77+
y[indx[i]] += a * x[i];
78+
}
79+
80+
MKLIMPORTS_EXPORT float cblas_sdoti(const int nz, const float *x,
81+
const int *indx, const float *y)
82+
{
83+
float result = 0.0f;
84+
for (int i = 0; i < nz; i++)
85+
result += x[i] * y[indx[i]];
86+
return result;
87+
}
88+
89+
// --- DFTI (FFT) stubs ---
90+
91+
MKLIMPORTS_EXPORT const char* DftiErrorMessage(long status)
92+
{
93+
return "DFTI not available (arm64 MKL shim build)";
94+
}
95+
96+
MKLIMPORTS_EXPORT long DftiCreateDescriptor(void **h, int precision, int domain, int dim, ...)
97+
{
98+
*h = (void*)0;
99+
return -1;
100+
}
101+
102+
MKLIMPORTS_EXPORT long DftiSetValue(void *h, int param, ...)
103+
{
104+
return -1;
105+
}
106+
107+
MKLIMPORTS_EXPORT long DftiCommitDescriptor(void *h) { return -1; }
108+
MKLIMPORTS_EXPORT long DftiComputeForward(void *h, ...) { return -1; }
109+
MKLIMPORTS_EXPORT long DftiComputeBackward(void *h, ...) { return -1; }
110+
MKLIMPORTS_EXPORT long DftiFreeDescriptor(void **h)
111+
{
112+
// Match MKL's contract: clear the caller's handle after freeing so callers
113+
// that rely on the descriptor being nulled out (e.g. the managed
114+
// FreeDescriptor(ref IntPtr) P/Invoke) behave correctly.
115+
if (h != (void*)0)
116+
*h = (void*)0;
117+
return 0;
118+
}

0 commit comments

Comments
 (0)