From 32d1c6e0c1257f05fbd3f3d3d80956e96a5007a9 Mon Sep 17 00:00:00 2001 From: cgli Date: Sat, 23 Mar 2024 00:19:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DCmake=20Windows=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E4=B8=8B=EF=BC=8Cint4=E4=B9=B1=E7=A0=81=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 5 +++- README.md | 3 ++ docs/faq.md | 8 ++++- example/Win32Demo/fastllm-gpu.vcxproj | 20 ++++++++++--- example/Win32Demo/fastllm.vcxproj | 43 ++++++++++++++------------- 5 files changed, 52 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff4bdf31..1aa7869f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,9 @@ set(CMAKE_BUILD_TYPE "Release") if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread --std=c++17 -O2") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOMINMAX -O2 /std:c++17 /arch:AVX /source-charset:utf-8") + set(CMAKE_CXX_FLAGS_DEBUG "/MTd /Zi /Ob0 /Od /RTC1") + set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob1 /Gy /DNDEBUG") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOMINMAX /std:c++17 /arch:AVX2 /source-charset:utf-8") else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread --std=c++17 -O2 -march=native") endif() @@ -39,6 +41,7 @@ set(FASTLLM_CXX_SOURCES src/fastllm.cpp src/device.cpp src/model.cpp src/executo include_directories(include) include_directories(include/utils) include_directories(include/models) +include_directories(include/devices/cpu) if (USE_MMAP) add_compile_definitions(USE_MMAP) diff --git a/README.md b/README.md index f575cad0..336d313f 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,7 @@ python setup.py install 我们假设已经获取了名为`model.flm`的模型(参照 [模型获取](#模型获取),初次使用可以先下载转换好的模型) 编译完成之后在build目录下可以使用下列demo: + ``` sh # 这时在fastllm/build目录下 @@ -177,6 +178,8 @@ streamlit run tools/web_demo.py model.flm ``` +Windows下的编译推荐使用Cmake GUI + Visual Studio,在图形化界面中完成。 + 如编译中存在问题,尤其是Windows下的编译,可参考[FAQ](docs/faq.md) ### 简易python调用 diff --git a/docs/faq.md b/docs/faq.md index 62850ff1..5ce9a868 100755 --- a/docs/faq.md +++ b/docs/faq.md @@ -55,7 +55,7 @@ cmake .. -DUSE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=native > include\fastllm.h(234): error : identifier "DataDevice" is undefined > .... -**解决办法:** 使用cmake构建通常不存在这一问题。参考 [example\README.md](/example/README.md)。签出代码后,**修改 include/fastllm.h**,Visual Studio中点击”文件“ -> "高级保存选项",在编码中选择”Unicode (UTF-8 **带签名**) -代码页 65001“,或在其他文本编辑器中转为”UTF-8 BOM“编码。(由于linux下gcc不识别BOM头,MSVC依赖BOM判断文件编码,该修改只能手动处理。) +**解决办法:** 参考 [example\README.md](/example/README.md)。签出代码后,**修改 include/fastllm.h**,Visual Studio中点击”文件“ -> "高级保存选项",在编码中选择”Unicode (UTF-8 **带签名**) -代码页 65001“,或在其他文本编辑器中转为”UTF-8 BOM“编码。(由于linux下gcc不识别BOM头,MSVC依赖BOM判断文件编码,该修改只能手动处理。) ### main.exe 无法识别中文输入 @@ -63,6 +63,12 @@ cmake .. -DUSE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=native **解决办法:** 编译[Win32Demo](/example/README.md#win32demo-windows平台) 或使用 [WebUI](/example/README.md#web-ui) +### Windows(MSVC)编译下,int4出现乱码 + +**原因:** MSVC编译器优化选项 "`/Ob2`"、"`/Ob3`"与的现有代码冲突, + +**解决办法:** 编译时,在”属性“中找到"C/C++" -> "优化" -> "内联函数扩展" 中选择“只适用于 __inline (/Ob1)”。 + ### 导入提示 FileNotFoundError **现象:** diff --git a/example/Win32Demo/fastllm-gpu.vcxproj b/example/Win32Demo/fastllm-gpu.vcxproj index 00338b91..d3c7b695 100644 --- a/example/Win32Demo/fastllm-gpu.vcxproj +++ b/example/Win32Demo/fastllm-gpu.vcxproj @@ -100,7 +100,9 @@ NOMINMAX;USE_CUDA;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) MultiThreadedDebug $(ProjectDir)..\..\include;$(ProjectDir)..\..\include\devices;$(ProjectDir)..\..\include\devices\cpu;$(ProjectDir)..\..\include\devices\cuda;$(ProjectDir)..\..\include\models;$(ProjectDir)..\..\include\utils;$(CUDA_PATH)\include;%(AdditionalIncludeDirectories) - /arch:AVX /source-charset:utf-8 %(AdditionalOptions) + /source-charset:utf-8 %(AdditionalOptions) + AdvancedVectorExtensions2 + true cudart.lib;cublas.lib;%(AdditionalDependencies) @@ -120,7 +122,9 @@ NOMINMAX;USE_CUDA;WIN64;__AVX__;__AVX2__;_DEBUG;_LIB;%(PreprocessorDefinitions) $(ProjectDir)..\..\include;$(ProjectDir)..\..\include\devices;$(ProjectDir)..\..\include\devices\cpu;$(ProjectDir)..\..\include\devices\cuda;$(ProjectDir)..\..\include\models;$(ProjectDir)..\..\include\utils;$(CUDA_PATH)\include;%(AdditionalIncludeDirectories) MultiThreadedDebug - /arch:AVX /source-charset:utf-8 %(AdditionalOptions) + /source-charset:utf-8 %(AdditionalOptions) + AdvancedVectorExtensions2 + true cudart.lib;cublas.lib;%(AdditionalDependencies) @@ -143,7 +147,11 @@ NOMINMAX;USE_CUDA;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) MultiThreaded $(ProjectDir)..\..\include;$(ProjectDir)..\..\include\devices;$(ProjectDir)..\..\include\devices\cpu;$(ProjectDir)..\..\include\devices\cuda;$(ProjectDir)..\..\include\models;$(ProjectDir)..\..\include\utils;$(CUDA_PATH)\include;%(AdditionalIncludeDirectories) - /arch:AVX /source-charset:utf-8 %(AdditionalOptions) + /source-charset:utf-8 %(AdditionalOptions) + AdvancedVectorExtensions2 + OnlyExplicitInline + true + cudart.lib;cublas.lib;%(AdditionalDependencies) @@ -167,7 +175,11 @@ NOMINMAX;USE_CUDA;__AVX__;__AVX2__;WIN64;NDEBUG;_LIB;%(PreprocessorDefinitions) $(ProjectDir)..\..\include;$(ProjectDir)..\..\include\devices;$(ProjectDir)..\..\include\devices\cpu;$(ProjectDir)..\..\include\devices\cuda;$(ProjectDir)..\..\include\models;$(ProjectDir)..\..\include\utils;$(CUDA_PATH)\include;%(AdditionalIncludeDirectories) MultiThreaded - /arch:AVX /source-charset:utf-8 %(AdditionalOptions) + /source-charset:utf-8 %(AdditionalOptions) + AdvancedVectorExtensions2 + OnlyExplicitInline + true + cudart.lib;cublas.lib;%(AdditionalDependencies) diff --git a/example/Win32Demo/fastllm.vcxproj b/example/Win32Demo/fastllm.vcxproj index 3c7fe284..bb62cae2 100644 --- a/example/Win32Demo/fastllm.vcxproj +++ b/example/Win32Demo/fastllm.vcxproj @@ -52,7 +52,6 @@ Unicode - @@ -94,18 +93,17 @@ Level3 Disabled - NOMINMAX;_LIB;WIN32;_DEBUG;%(PreprocessorDefinitions) + NOMINMAX;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) MultiThreadedDebug $(ProjectDir)..\..\include;$(ProjectDir)..\..\include\devices;$(ProjectDir)..\..\include\devices\cpu;$(ProjectDir)..\..\include\devices\cuda;$(ProjectDir)..\..\include\models;$(ProjectDir)..\..\include\utils;$(CUDA_PATH)\include;%(AdditionalIncludeDirectories) - /arch:AVX /source-charset:utf-8 %(AdditionalOptions) + /source-charset:utf-8 %(AdditionalOptions) + AdvancedVectorExtensions2 + true cudart.lib;cublas.lib;%(AdditionalDependencies) Windows - - compute_61,sm_61;%(CodeGeneration) - @@ -113,18 +111,17 @@ Level3 Disabled - NOMINMAX;_LIB;__AVX__;__AVX2__;WIN64;_DEBUG;%(PreprocessorDefinitions) - $(ProjectDir)..\..\include;$(ProjectDir)..\..\include\devices;$(ProjectDir)..\..\include\devices\cpu;$(ProjectDir)..\..\include\devices\cuda;$(ProjectDir)..\..\include\models;$(ProjectDir)..\..\include\utils;%(AdditionalIncludeDirectories) + NOMINMAX;WIN64;__AVX__;__AVX2__;_DEBUG;_LIB;%(PreprocessorDefinitions) + $(ProjectDir)..\..\include;$(ProjectDir)..\..\include\devices\cpu;$(ProjectDir)..\..\include\models;$(ProjectDir)..\..\include\utils;%(AdditionalIncludeDirectories) MultiThreadedDebug - /arch:AVX /source-charset:utf-8 %(AdditionalOptions) + /source-charset:utf-8 %(AdditionalOptions) + AdvancedVectorExtensions2 + true cudart.lib;cublas.lib;%(AdditionalDependencies) Windows - - compute_61,sm_61;%(CodeGeneration) - @@ -134,10 +131,14 @@ MaxSpeed true true - NOMINMAX;_LIB;WIN32;NDEBUG;%(PreprocessorDefinitions) + NOMINMAX;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) MultiThreaded $(ProjectDir)..\..\include;$(ProjectDir)..\..\include\devices;$(ProjectDir)..\..\include\devices\cpu;$(ProjectDir)..\..\include\devices\cuda;$(ProjectDir)..\..\include\models;$(ProjectDir)..\..\include\utils;$(CUDA_PATH)\include;%(AdditionalIncludeDirectories) - /arch:AVX /source-charset:utf-8 %(AdditionalOptions) + /source-charset:utf-8 %(AdditionalOptions) + AdvancedVectorExtensions2 + OnlyExplicitInline + true + cudart.lib;cublas.lib;%(AdditionalDependencies) @@ -145,9 +146,6 @@ true true - - compute_61,sm_61;%(CodeGeneration) - @@ -157,10 +155,14 @@ MaxSpeed true true - NOMINMAX;_LIB;__AVX__;__AVX2__;WIN64;NDEBUG;%(PreprocessorDefinitions) - $(ProjectDir)..\..\include;$(ProjectDir)..\..\include\devices;$(ProjectDir)..\..\include\devices\cpu;$(ProjectDir)..\..\include\devices\cuda;$(ProjectDir)..\..\include\models;$(ProjectDir)..\..\include\utils;%(AdditionalIncludeDirectories) + NOMINMAX;__AVX__;__AVX2__;WIN64;NDEBUG;_LIB;%(PreprocessorDefinitions) + $(ProjectDir)..\..\include;$(ProjectDir)..\..\include\devices\cpu;$(ProjectDir)..\..\include\models;$(ProjectDir)..\..\include\utils;%(AdditionalIncludeDirectories) MultiThreaded - /arch:AVX /source-charset:utf-8 %(AdditionalOptions) + /source-charset:utf-8 %(AdditionalOptions) + AdvancedVectorExtensions2 + OnlyExplicitInline + true + Windows @@ -202,5 +204,4 @@ - \ No newline at end of file