bounty明天到期。回答此问题可获得+100声望奖励。SuperKogito希望引起更多的关注这个问题:我希望得到更多的关注,并最终得到一个答案,因为大多数相关的帖子都没有提供解决方案
我正在尝试构建一个C项目,其中我使用英特尔的数学内核库(MKL)来加速矩阵乘法,如下所示:
#define MKL
#ifdef MKL
#include <mkl.h>
#endif
void gemm_cpu(int TA, int TB, int M, int N, int K, float ALPHA, float *A, int lda, float *B, int ldb, float BETA, float *C, int ldc)
{
#ifdef MKL
if (!TA && !TB)
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, M, N, K, ALPHA, A, lda, B, ldb, BETA, C, ldc);
else if (TA && !TB)
cblas_sgemm(CblasRowMajor, CblasTrans, CblasNoTrans, M, N, K, ALPHA, A, lda, B, ldb, BETA, C, ldc);
else if (!TA && TB)
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, M, N, K, ALPHA, A, lda, B, ldb, BETA, C, ldc);
else
cblas_sgemm(CblasRowMajor, CblasTrans, CblasTrans, M, N, K, ALPHA, A, lda, B, ldb, BETA, C, ldc);
#else
for (int i = 0; i < N * M; ++i)
C[i] *= BETA;
if (!TA && !TB)
gemm_nn(M, N, K, ALPHA, A, lda, B, ldb, C, ldc);
else if (TA && !TB)
gemm_tn(M, N, K, ALPHA, A, lda, B, ldb, C, ldc);
else if (!TA && TB)
gemm_nt(M, N, K, ALPHA, A, lda, B, ldb, C, ldc);
else
gemm_tt(M, N, K, ALPHA, A, lda, B, ldb, C, ldc);
#endif
}
我在Windows 10上使用CLion作为IDE,并使用gcc.exe(MinGW-W 64 x86_64-ucrt-posix-seh,由布雷希特桑德斯构建)12.2.0作为编译器。不幸的是,我的构建失败,无法链接MKL。我构建MKL的cmake如下:
# The Mkl has to be installed locally
set(external_folder "D:/Users/superkogito/Desktop/workspace/project/external")
set(mkl_dir "${external_folder}/mkl")
# link options provided by https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor
message(STATUS "[MKL] MKL path: ${mkl_dir}.")
# 64bits
set(mkl_libraries
"${mkl_dir}/lib/intel64/mkl_intel_lp64.lib"
"${mkl_dir}/lib/intel64/mkl_core.lib"
"${mkl_dir}/lib/intel64/mkl_sequential.lib"
)
set(mkl_dlls
"${mkl_dir}/lib/intel64/mkl_intel_lp64_dll.lib"
"${mkl_dir}/lib/intel64/mkl_core_dll.lib"
"${mkl_dir}/lib/intel64/mkl_sequential_dll.lib"
)
add_library(mkl INTERFACE)
add_compile_definitions(MKL_LP64)
add_compile_definitions(function=cblas_sgemm)
target_link_directories(mkl INTERFACE "${mkl_dir}/lib/intel64")
target_link_libraries(mkl INTERFACE ${mkl_dlls})
target_include_directories(mkl INTERFACE "${mkl_dir}/include")
## install mkl libs
INSTALL(FILES ${mkl_libraries} DESTINATION lib)
# Also install the dll on windows
install(FILES ${mkl_dlls} DESTINATION lib)
我尝试了不同的配置我的Cmake文件,但我总是得到这样的undefined reference to ..
错误:
Warning: .drectve `-defaultlib:"uuid.lib" ' unrecognized
Warning: corrupt .drectve at end of def file
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(_sgemm_lp64.obj):(.text[sgemm]+0x219): undefined reference to `__security_check_cookie'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(_sgemm_lp64.obj):(.text[sgemm]+0x37c): undefined reference to `__security_check_cookie'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(_sgemm_lp64.obj):(.xdata+0x1c): undefined reference to `__GSHandlerCheck'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(_sgemm_lp64.obj):(.xdata+0x3c): undefined reference to `__GSHandlerCheck'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(_sgemm_lp64.obj):(.text[sgemm_64]+0x1a8): undefined reference to `__security_check_cookie'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(_sgemm_lp64.obj):(.text[sgemm_64]+0x2fc): undefined reference to `__security_check_cookie'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(_sgemm_lp64.obj):(.xdata+0x1c): undefined reference to `__GSHandlerCheck'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(_sgemm_lp64.obj):(.xdata+0x3c): undefined reference to `__GSHandlerCheck'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.text[mkl_serv_printf_s]+0x54): undefined reference to `__stdio_common_vfprintf'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.text[mkl_serv_fprintf_s]+0x78): undefined reference to `__stdio_common_vsnprintf_s'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.text[mkl_serv_fprintf_s]+0xb8): undefined reference to `__security_check_cookie'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.xdata+0x10): undefined reference to `__GSHandlerCheck'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.text[mkl_serv_fprintf_stdout_s]+0x54): undefined reference to `__stdio_common_vfprintf'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.text[mkl_serv_vfprintf_s]+0x2e): undefined reference to `__stdio_common_vfprintf'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.text[mkl_serv_vfprintf_stdout_s]+0x38): undefined reference to `__stdio_common_vfprintf'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.text[mkl_serv_sprintf_s]+0x5f): undefined reference to `__stdio_common_vsnprintf_s'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.text[mkl_serv_sprintf_char_s]+0x65): undefined reference to `__stdio_common_vsnprintf_s'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.text[mkl_serv_vsprintf_s]+0x43): undefined reference to `__stdio_common_vsnprintf_s'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.text[mkl_serv_vsnprintf_s]+0x48): undefined reference to `__stdio_common_vsnprintf_s'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.text[mkl_serv_snprintf_s]+0x5e): undefined reference to `__stdio_common_vsnprintf_s'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.text[mkl_serv_sscanf_s]+0x54): undefined reference to `__stdio_common_vsscanf'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.text[mkl_serv_fscanf_s]+0x46): undefined reference to `__stdio_common_vfscanf'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.text[mkl_serv_vfprintf_stderr_s]+0x38): undefined reference to `__stdio_common_vfprintf'
D:/wecode_build_tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Users/superkogito/Desktop/workspace/cpp/audio_framework_v2/plugin/my_plugins/ImGuiExample/external/mkl/lib/intel64/mkl_intel_lp64_dll.lib(mkl_libc.obj):(.text[mkl_serv_fprintf_stderr_s]+0x54): undefined reference to `__stdio_common_vfprintf'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
这似乎是由于MKL和mingw之间的不兼容性,如以下链接所述:
- link MKL libraries in Windows / Clion /Cmake
- https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-linking-with-MinGW64-is-it-still-impossible/m-p/1155228
但我希望有人有一个补丁,或者也许因为我只需要cblas_sgemm
,我可能能够围绕不兼容性进行构建。我主要需要避免使用Visual Studio,所以如果有办法绕过它,我想听听。
1条答案
按热度按时间7cjasjjr1#
此外,由于MKL源代码是关闭的,我不能从源代码构建,所以我希望有一个补丁或确认这是不可能的。
我在文档中没有看到任何暗示支持
MinGW
的内容。似乎唯一支持的平台是Windows、Linux和MacOS。我主要需要避免使用Visual Studio,所以如果有办法绕过它,我想听听。
我会考虑使用
Visual Studio Code
,它对于跨平台的CMake C++开发来说绝对是可爱的。但是,由于您已经在使用
clion
,因此值得指出的是,您可以将MSVC工具链与CLion一起使用:https://www.jetbrains.com/help/clion/quick-tutorial-on-configuring-clion-on-windows.html#MSVC
这将允许您与英特尔提供的
pre-built
Windows二进制文件兼容。