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:
- Install the OneAPI base toolkit
- Make sure ONEAPI_ROOT points to C:\Program Files (x86)\Intel\oneAPI\
- Add $(ONEAPI_ROOT)\mkl\latest\include to the C/C++ | General | Additional Include Directories
- Add $(ONEAPI_ROOT)\mkl\latest\lib to the Linker | General | Additional Library Directories
- Add mkl_intel_lp64_dll.lib;mkl_tbb_thread_dll.lib;mkl_core_dll.lib; to the Linker | Input | Additional Dependencies
- 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
版权声明:本文标题:winui 3 - Can one use MKL with C++WinRT? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736600105a1945204.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论