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.make
CXX_FLAGS
中的/MT
为/MD
cd $build_dir/Release && nmake
onnx
的编译(同样适应于Debian
版本)$build_dir/Release/_deps/onnx-build/CMakeFiles/*_proto.dir/build.make
python.exe */onnx-src/onnx/gen_proto.py
为python.exe ../onnx-src/onnx/gen_proto.py
cd $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.make
python3 */tools/ci_build/gen_def.py
为python3 ../../tools/ci_build/gen_def.py
cd $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