From ee2f9ea8e602ccde517f6ffcaa5236d854a3a489 Mon Sep 17 00:00:00 2001
From: DTTerastar
Date: Sun, 6 Oct 2024 08:56:20 -0400
Subject: [PATCH] TryUseNativeMKL
---
Dockerfile | 14 +++++++++++++-
src/Program.cs | 1 +
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/Dockerfile b/Dockerfile
index 64ea5b68..7edc0869 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -13,12 +13,13 @@ RUN apt-get update \
WORKDIR /App
COPY . ./
-RUN dotnet restore
RUN echo "I am running on ${BUILDPLATFORM}"
RUN echo "building for ${TARGETPLATFORM}"
RUN export TARGETPLATFORM="${TARGETPLATFORM}"
+RUN dotnet add src/ESPresense.Companion.csproj package MathNet.Numerics.Providers.MKL
+RUN dotnet restore
RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/aspnet:8.0
@@ -27,7 +28,18 @@ EXPOSE 8267 8268
ENV ASPNETCORE_URLS "http://+:8267"
ENV OTA_UPDATE_PORT 8268
ENV CONFIG_DIR "/config/espresense"
+
+RUN if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
+ apt-get update && apt-get install -y apt-transport-https gnupg software-properties-common wget && \
+ wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB && \
+ apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB && \
+ rm GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB && \
+ echo "deb https://apt.repos.intel.com/mkl all main" > /etc/apt/sources.list.d/intel-mkl.list && \
+ apt-get update && apt-get install -y intel-mkl-64bit-2020.0-088; \
+ fi
+
COPY --from=build-env /App/out .
+
LABEL \
io.hass.version="VERSION" \
io.hass.type="addon" \
diff --git a/src/Program.cs b/src/Program.cs
index 9860caac..f6b7be54 100644
--- a/src/Program.cs
+++ b/src/Program.cs
@@ -23,6 +23,7 @@
builder.Host.UseSerilog((context, cfg) => cfg.ReadFrom.Configuration(context.Configuration));
+MathNet.Numerics.Control.TryUseNativeMKL();
Log.Logger.Information(MathNet.Numerics.Control.Describe().Trim('\r','\n'));
var configDir = Environment.GetEnvironmentVariable("CONFIG_DIR") ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".espresense");