Created
May 29, 2025 08:03
-
-
Save Abirdcfly/7500ac74c7fc9b9d573eca7027c78e8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/cmake/cpu_extension.cmake b/cmake/cpu_extension.cmake | |
index 00670bd39..15f6bdeb5 100644 | |
--- a/cmake/cpu_extension.cmake | |
+++ b/cmake/cpu_extension.cmake | |
@@ -18,8 +18,11 @@ endif() | |
include_directories("${CMAKE_SOURCE_DIR}/csrc") | |
- | |
-set (ENABLE_NUMA TRUE) | |
+if (MACOSX_FOUND) | |
+ set (ENABLE_NUMA OFF) | |
+else() | |
+ set (ENABLE_NUMA TRUE) | |
+endif() | |
# | |
# Check the compile flags | |
@@ -30,14 +33,17 @@ if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") | |
"-mf16c" | |
) | |
endif() | |
- | |
-if(MACOSX_FOUND) | |
- list(APPEND CXX_COMPILE_FLAGS | |
- "-DVLLM_CPU_EXTENSION") | |
-else() | |
- list(APPEND CXX_COMPILE_FLAGS | |
- "-fopenmp" | |
- "-DVLLM_CPU_EXTENSION") | |
+if (MACOSX_FOUND) | |
+ # 使用sysctl获取CPU特性 | |
+ execute_process(COMMAND sysctl -n machdep.cpu.leaf7_features | |
+ OUTPUT_VARIABLE CPU_FEATURES | |
+ RESULT_VARIABLE SYSCTL_RET) | |
+ if (NOT SYSCTL_RET EQUAL 0) | |
+ message(FATAL_ERROR "Failed to check CPU features via sysctl") | |
+ endif() | |
+ string(STRIP "${CPU_FEATURES}" CPU_FEATURES) | |
+ set(CPUINFO "${CPU_FEATURES}") # 将结果存入CPUINFO变量 | |
+ message("${CPUINFO}" "cpuinfo 信息") | |
endif() | |
if (NOT MACOSX_FOUND) | |
@@ -51,7 +57,11 @@ endif() | |
function (find_isa CPUINFO TARGET OUT) | |
- string(FIND ${CPUINFO} ${TARGET} ISA_FOUND) | |
+ if (MACOSX_FOUND) | |
+ string(FIND "${CPUINFO}" "${TARGET}" ISA_FOUND) | |
+ else() | |
+ string(FIND "${CPUINFO}" "${TARGET}" ISA_FOUND) | |
+ endif() | |
if(NOT ISA_FOUND EQUAL -1) | |
set(${OUT} ON PARENT_SCOPE) | |
else() | |
@@ -73,13 +83,8 @@ is_avx512_disabled(AVX512_DISABLED) | |
if (MACOSX_FOUND AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") | |
set(APPLE_SILICON_FOUND TRUE) | |
else() | |
- find_isa(${CPUINFO} "avx2" AVX2_FOUND) | |
- find_isa(${CPUINFO} "avx512f" AVX512_FOUND) | |
- find_isa(${CPUINFO} "POWER10" POWER10_FOUND) | |
- find_isa(${CPUINFO} "POWER9" POWER9_FOUND) | |
- find_isa(${CPUINFO} "asimd" ASIMD_FOUND) # Check for ARM NEON support | |
- find_isa(${CPUINFO} "bf16" ARM_BF16_FOUND) # Check for ARM BF16 support | |
- find_isa(${CPUINFO} "S390" S390_FOUND) | |
+ find_isa("${CPUINFO}" "AVX2" AVX2_FOUND) | |
+ find_isa("${CPUINFO}" "AVX512" AVX512_FOUND) | |
endif() | |
@@ -170,6 +175,23 @@ if (AVX512_FOUND AND NOT AVX512_DISABLED) | |
list(APPEND LIBS dnnl) | |
endif() | |
+ | |
+if (MACOSX_FOUND) | |
+ find_package(OpenMP REQUIRED) | |
+ list(APPEND CXX_COMPILE_FLAGS | |
+ "-Xpreprocessor" | |
+ "-fopenmp" | |
+ "-I/usr/local/Cellar/libomp/20.1.5/include" | |
+ ) | |
+ list(APPEND LIBS | |
+ "-lomp" | |
+ "-L/usr/local/Cellar/libomp/20.1.5/lib" | |
+ ) | |
+ message("${OpenMP_CXX_FLAGS}" "!!!" "${OpenMP_CXX_LIBRARIES}" "!!!openmp 信息") | |
+ message("${CXX_COMPILE_FLAGS}" "!!!" "${LIBS}" "!!!编译信息") | |
+else() | |
+ list(APPEND CXX_COMPILE_FLAGS "-fopenmp") | |
+endif() | |
message(STATUS "CPU extension compile flags: ${CXX_COMPILE_FLAGS}") | |
if(ENABLE_NUMA) | |
@@ -214,4 +236,5 @@ define_gpu_extension_target( | |
WITH_SOABI | |
) | |
-message(STATUS "Enabling C extension.") | |
\ No newline at end of file | |
+message(STATUS "Enabling C extension.") | |
+ | |
diff --git a/requirements/cpu.txt b/requirements/cpu.txt | |
index 69f732c24..6bdc28c8a 100644 | |
--- a/requirements/cpu.txt | |
+++ b/requirements/cpu.txt | |
@@ -2,10 +2,10 @@ | |
-r common.txt | |
# Dependencies for CPUs | |
-torch==2.6.0+cpu; platform_machine == "x86_64" | |
-torch==2.6.0; platform_system == "Darwin" | |
-torch==2.6.0; platform_machine == "ppc64le" or platform_machine == "aarch64" | |
-torch==2.7.0.dev20250304; platform_machine == "s390x" | |
+#torch==2.6.0+cpu; platform_machine == "x86_64" | |
+#torch==2.6.0; platform_system == "Darwin" | |
+#torch==2.6.0; platform_machine == "ppc64le" or platform_machine == "aarch64" | |
+#torch==2.7.0.dev20250304; platform_machine == "s390x" | |
# required for the image processor of minicpm-o-2_6, this must be updated alongside torch | |
torchaudio; platform_machine != "ppc64le" and platform_machine != "s390x" | |
@@ -17,4 +17,4 @@ torchvision==0.21.0; platform_machine == "ppc64le" | |
datasets # for benchmark scripts | |
# cpu cannot use triton 3.3.0 | |
-triton==3.2.0; platform_machine == "x86_64" | |
+#triton==3.2.0; platform_machine == "x86_64" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment