admin管理员组

文章数量:1123864

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

To make the code compile and link, do the following:

  1. Install the OneAPI base toolkit
  2. Make sure ONEAPI_ROOT points to C:\Program Files (x86)\Intel\oneAPI\
  3. Add $(ONEAPI_ROOT)\mkl\latest\include to the C/C++ | General | Additional Include Directories
  4. Add $(ONEAPI_ROOT)\mkl\latest\lib to the Linker | General | Additional Library Directories
  5. Add mkl_intel_lp64_dll.lib;mkl_tbb_thread_dll.lib;mkl_core_dll.lib; to the Linker | Input | Additional Dependencies
  6. copy mkl_blacs_lp64.2.dll, mkl_core.2.dll and mkl_tbb_thread.2.dll to the x64\Debug\TestMKL\AppX directory

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?

本文标签: winui 3Can one use MKL with CWinRTStack Overflow