I'd like to use Intel's Math Kernel Library (MKL) to do some calculations. I've figured this out for MFC programs, but I'm having trouble with C++/WinRT & WinUI 3 programs. For a repro, I took the standard "Blank App, Packaged (WinUI 3 in Desktop)" app and removed all traces of myProperty. Here's the new MainWindow.cpp:
#include "pch.h"
#include "MainWindow.xaml.h"
#if __has_include("MainWindow.g.cpp")
#include "MainWindow.g.cpp"
#endif
#include "mkl.h"
#include <exception>
// Standard SYCL header
//#include "compiler\2025.0\include\sycl\CL\sycl.hpp"
using namespace winrt;
using namespace Microsoft::UI::Xaml;
namespace winrt::TestMKL::implementation
{
MainWindow::MainWindow()
{
InitializeComponent();
}
void MainWindow::myButton_Click(IInspectable const&, RoutedEventArgs const&)
{
myButton().Content(box_value(L"Clicked"));
// Test MKL
// Example: Compute the dot product of two vectors
double x[3] = { 1.0, 2.0, 3.0 };
double y[3] = { 4.0, 5.0, 6.0 };
double rv;
try {
rv = cblas_ddot(3, x, 1, y, 1);
}
catch (const std::exception& e) {
OutputDebugString((L"MKL exception: " + to_hstring(e.what()) + L"\n").c_str());
}
OutputDebugString((L"Dot product: " + std::to_wstring(rv) + L"\n").c_str());
result().Text(winrt::hstring{ std::to_wstring(rv) });
}
}
No other code was changed.
You can download my code from https://github.com/dr-eck/MiniEditor
To make the code compile and link, do the following:
You must copy the DLLs even if you work from the Github repo.
The program should compile and run. When the button is clicked, the program disappears. Commenting out the MKL code verifies that the program does not disappear if cblas_ddot is not called.
How do I make this work?
After a few rounds of posts in the Intel Community Forum, (https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Can-one-use-MKL-with-C-WinRT/m-p/1656600/thread-id/36818#M36839) I have a partial answer. Using nmake, one can create an MKL subset with just the required functions that is compatible with Universal Windows Drivers (UWD). Here's a link to the documentation: https://www.intel.com/content/www/us/en/docs/onemkl/developer-guide-windows/2025-0/using-the-custom-dll-builder-in-command-line-mode.html
Here's an example of the export text file (uwd_func_list.txt):
cblas_dcopy
cblas_ddot
cblas_dgemm
cblas_dgemv
cblas_dnrm2
cblas_dscal
cblas_dswap
LAPACKE_dgesv
LAPACKE_dposv
LAPACKE_dsysv
LAPACKE_dpotrf
LAPACKE_dpotrs
And here's the .bat file I created to run nmake:
rem Set Visual Studio environment variables. LIB should have paths to desired OneCore.lib and universal crt libraries.
rem call "C:\Program Files (x86)\Intel\oneAPI\setvars-vcvarsall.bat" x64
rem add lib.exe folder to PATH
rem set path=%path%;"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x64"
rem add libcmt.lib folder to LIB
rem set lib=%lib%;"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\lib\x64"
rem add mt.exe folder to PATH
rem set path=%path%;"C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64"
rem Run custom dll builder script
rem nmake libintel64 interface=lp64 export=uwd_func_list.txt uwd_compat=yes crt=ucrt.lib name=mkl_uwd_compat
rem nmake "C:\Program Files (x86)\Intel\oneAPI\mkl\latest\share\mkl\tools\builder\makefile" interface=lp64 export=uwd_func_list.txt uwd_compat=yes crt=ucrt.lib name=mkl_uwd_compat
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\nmake" libintel64 interface=lp64 export=uwd_func_list.txt uwd_compat=yes crt=ucrt.lib name=mkl_uwd_compat
Copy the .txt and .bat files to C:\Program Files (x86)\Intel\oneAPI\mkl\latest\share\mkl\tools\builder and run the .bat. It should create four files named mkl_uwd_compat.*, a DLL, a manifest, an export and a library.
The DLL & .lib files created this way allow my app to compile, link & run. The only drawback is that UWD compatibility forces the app to run single-threaded, which defeats the purpose of using MKL in the first place. I'll update this thread when Intel comes up with a real solution.