cmake-3.28.6-win32-x86或更高版本python、git、tar、zip、p7z 等工具EWDK-x64或x86控制台,在其中执行msys2_shell.cmd(如下操作均在msys2的shell中执行)where cmake python nmake cl ml64 ml nmake -? && cl
cmake和python通过在
shell中设置PATH来确保cmake不能用msys2的,
而python要用msys2的
onnxruntime-1.22.2代码git clone -b rel-1.22.2 –recursive https://github.com/microsoft/onnxruntime.git
onnxruntime代码目录cd onnxruntime
git submodule update –init –recursive
build_dir为编译工作目录,执行编译脚本build_dir=./build_cpp_only
python3 ./tools/ci_build/build.py \
--compile_no_warning_as_error \
--build_dir $build_dir \
--config Release \
--update --build \
--build_shared_lib \
--cmake_generator "NMake Makefiles" \
--cmake_extra_defines onnxruntime_BUILD_UNIT_TESTS=OFF \
--cmake_extra_defines CMAKE_INSTALL_PREFIX=$build_dir/install/ \
--skip_tests
--target install 项下述需要干预编译过程,故忽略此步
protobuf的编译$build_dir/Release/_deps/protobuf-build/CMakeFiles/*.dir/flags.makeCXX_FLAGS中的/MT为/MDcd $build_dir/Release && nmake
onnx的编译(同样适应于Debian版本)$build_dir/Release/_deps/onnx-build/CMakeFiles/*_proto.dir/build.makepython.exe */onnx-src/onnx/gen_proto.py为python.exe ../onnx-src/onnx/gen_proto.pycd $build_dir/Release && nmake
32位(x86)版本mlas(最高支持avx2)的编译$build_dir/Release/CMakeFiles/onnxruntime_mlas..dir/build.make删除所有
avx512的C++编译内容和amd64\*.asm编译内容
添加onnxruntime\core\mlas\lib\i386\*.asm对应的编译内容
$build_dir/Release/CMakeFiles/onnxruntime_mlas..dir/objects1.rsp删除所有
avx512的内容和amd64\*.asm内容
追加onnxruntime\core\mlas\lib\i386\*.asm对应的内容
onnxruntime\core\mlas\lib\amx_common.h源码在
#ifdef _WIN32和#define tile_dpbssd*之间添加如下内容
#if !defined (_M_X64)
// AMX
typedef int __tile;
extern void __cdecl _tile_loadconfig(const void *);
extern void __cdecl _tile_storeconfig(void *);
extern void __cdecl _tile_release(void);
extern void __cdecl _tile_loadd(__tile dst, const void *base, int stride);
extern void __cdecl _tile_stream_loadd(__tile dst, const void *base, int stride);
extern void __cdecl _tile_stored(__tile src, void *base, int stride);
extern void __cdecl _tile_zero(__tile dst);
extern void __cdecl _tile_dpbf16ps(__tile dst, __tile src1, __tile src2);
extern void __cdecl _tile_dpbssd(__tile dst, __tile src1, __tile src2);
extern void __cdecl _tile_dpbsud(__tile dst, __tile src1, __tile src2);
extern void __cdecl _tile_dpbusd(__tile dst, __tile src1, __tile src2);
extern void __cdecl _tile_dpbuud(__tile dst, __tile src1, __tile src2);
#endif /* defined (_M_X64) */
cd $build_dir/Release && nmake
onnxruntime_generate_def的编译$build_dir/Release/CMakeFiles/onnxruntime_generate_def.dir/build.makepython3 */tools/ci_build/gen_def.py为python3 ../../tools/ci_build/gen_def.pycd $build_dir/Release && nmake
cd $build_dir/Release && nmake install
cmake-3.28.6-linux-x86_64/bin添加到PATH前面build_dir,执行编译脚本build_dir=./build_cpp_only
python3 ./tools/ci_build/build.py \
--compile_no_warning_as_error \
--build_dir $build_dir \
--config Release \
--update --build \
--build_shared_lib \
--cmake_generator "Unix Makefiles" \
--cmake_extra_defines onnxruntime_BUILD_UNIT_TESTS=OFF \
--cmake_extra_defines CMAKE_INSTALL_PREFIX=$build_dir/install/ \
--skip_tests
onnx的编译同msvc2019版本如有多个
python版本,确保运行python3