Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/Packaging.fs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ let zip (package:ZipPackage) header zipDir filesDir filesFilter =


let private updateNuspec (nuget:NuGetPackage) outPath dependencies (spec:NuGet.NuGet.NuGetParams) =
{ spec with ToolPath = "packages/build/NuGet.CommandLine/tools/NuGet.exe"
{ spec with ToolPath = Path.getFullName"packages/build/NuGet.CommandLine/tools/NuGet.exe"
OutputPath = outPath
WorkingDir = "obj/NuGet"
Version = nuget.Release.PackageVersion
Expand Down
46 changes: 46 additions & 0 deletions src/NativeProviders/Linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive
ENV VERSION=2024.0
ENV INTEL=/opt/intel
ENV MKL=$INTEL/mkl/$VERSION
ENV OPENMP=$INTEL/compiler/$VERSION

# Install system dependencies
RUN apt-get update && apt-get install -y \
wget \
curl \
g++ \
g++-multilib \
libc6-dev-i386 \
ca-certificates \
gnupg \
lsb-release \
software-properties-common \
&& rm -rf /var/lib/apt/lists/*

# Install Intel MKL using offline installer as it is not available in the apt repository
RUN mkdir -p /tmp/mkl \
&& cd /tmp/mkl \
&& wget https://registrationcenter-download.intel.com/akdlm/IRC_NAS/86d6a4c1-c998-4c6b-9fff-ca004e9f7455/l_onemkl_p_2024.0.0.49673.sh \
&& chmod +x l_onemkl_p_2024.0.0.49673.sh \
&& mkdir -p /opt/intel \
&& ./l_onemkl_p_2024.0.0.49673.sh -a -s --eula accept --install-dir /opt/intel \
&& rm -rf /tmp/mkl

# Set up environment variables for MKL
ENV LD_LIBRARY_PATH=""
ENV CPATH=""
ENV LIBRARY_PATH=""
ENV LD_LIBRARY_PATH=$MKL/lib/intel64:$OPENMP/lib:$LD_LIBRARY_PATH
ENV CPATH=$MKL/include:$CPATH
ENV LIBRARY_PATH=$MKL/lib/intel64:$OPENMP/lib:$LIBRARY_PATH

WORKDIR /workspace

# Copy project files
COPY . .

RUN chmod +x src/NativeProviders/Linux/mkl_build.sh

CMD ["sh", "-c", "cd src/NativeProviders/Linux && ./mkl_build.sh"]
40 changes: 40 additions & 0 deletions src/NativeProviders/Linux/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Build Native Libraries for MathNet.Numerics MKL for Linux

### Option 1: Manual Installation

**Install MKL**

There are many options. At time of writing this is a good source:
https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-download.html

**Install g++**

```bash
sudo apt-get install g++ g++-multilib libc6-dev-i386
```

**Build**

```bash
./mkl_build.sh
```

**Note:** You may have to update MKL's version number inside the script. See `VERSION` environment variable.

### Option 2: Docker

**Build the native libraries**

Run following commands from the project root.

```bash
docker build -f src/NativeProviders/Linux/Dockerfile -t mathnet-mkl-builder .
docker run --rm -v $(pwd)/out:/workspace/out mathnet-mkl-builder
```

## Output

The build creates native libraries in:
- `out/MKL/Linux/x64/libMathNetNumericsMKL.so` (64-bit)
- `out/MKL/Linux/x86/libMathNetNumericsMKL.so` (32-bit)
- Plus OpenMP runtime libraries (`libiomp5.so`)
17 changes: 9 additions & 8 deletions src/NativeProviders/Linux/mkl_build.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
Note: g++ multilib must be installed
export VERSION=2023.1.0
#!/bin/sh

export VERSION=2024.0
export INTEL=/opt/intel
export MKL=$INTEL/oneapi/mkl/$VERSION
export OPENMP=$INTEL/oneapi/compiler/$VERSION/linux/compiler/lib
export MKL=$INTEL/mkl/$VERSION
export OPENMP=$INTEL/compiler/$VERSION
export OUT=../../../out/MKL/Linux

mkdir -p $OUT/x64
mkdir -p $OUT/x86

g++ -std=c++11 -D_M_X64 -DGCC -m64 --shared -fPIC -o $OUT/x64/libMathNetNumericsMKL.so -I$MKL/include -I../Common -I../MKL ../MKL/memory.c ../MKL/capabilities.cpp ../MKL/vector_functions.c ../Common/blas.c ../Common/lapack.cpp ../MKL/fft.cpp -Wl,--start-group $MKL/lib/intel64/libmkl_intel_lp64.a $MKL/lib/intel64/libmkl_intel_thread.a $MKL/lib/intel64/libmkl_core.a -Wl,--end-group -L$OPENMP/intel64_lin -liomp5 -lpthread -lm
g++ -std=c++11 -D_M_X64 -DGCC -m64 --shared -fPIC -o $OUT/x64/libMathNetNumericsMKL.so -I$MKL/include -I../Common -I../MKL ../MKL/memory.c ../MKL/capabilities.cpp ../MKL/vector_functions.c ../Common/blas.c ../Common/lapack.cpp ../MKL/fft.cpp -Wl,--start-group $MKL/lib/intel64/libmkl_intel_lp64.a $MKL/lib/intel64/libmkl_intel_thread.a $MKL/lib/intel64/libmkl_core.a -Wl,--end-group -L$OPENMP/lib -liomp5 -lpthread -lm

cp $OPENMP/intel64_lin/libiomp5.so $OUT/x64/
cp $OPENMP/lib/libiomp5.so $OUT/x64/

g++ -std=c++11 -D_M_IX86 -DGCC -m32 --shared -fPIC -o $OUT/x86/libMathNetNumericsMKL.so -I$MKL/include -I../Common -I../MKL ../MKL/memory.c ../MKL/capabilities.cpp ../MKL/vector_functions.c ../Common/blas.c ../Common/lapack.cpp ../MKL/fft.cpp -Wl,--start-group $MKL/lib/ia32/libmkl_intel.a $MKL/lib/ia32/libmkl_intel_thread.a $MKL/lib/ia32/libmkl_core.a -Wl,--end-group -L$OPENMP/ia32_lin -liomp5 -lpthread -lm
g++ -std=c++11 -D_M_IX86 -DGCC -m32 --shared -fPIC -o $OUT/x86/libMathNetNumericsMKL.so -I$MKL/include -I../Common -I../MKL ../MKL/memory.c ../MKL/capabilities.cpp ../MKL/vector_functions.c ../Common/blas.c ../Common/lapack.cpp ../MKL/fft.cpp -Wl,--start-group $MKL/lib/ia32/libmkl_intel.a $MKL/lib/ia32/libmkl_intel_thread.a $MKL/lib/ia32/libmkl_core.a -Wl,--end-group -L$OPENMP/lib32 -liomp5 -lpthread -lm

cp $OPENMP/ia32_lin/libiomp5.so $OUT/x86/
cp $OPENMP/lib32/libiomp5.so $OUT/x86/
11 changes: 0 additions & 11 deletions src/NativeProviders/Linux/readme.txt

This file was deleted.