Skip to content

Commit 4cb138a

Browse files
authored
Add CMake mlas_private_compile_definitions variable for internal MLAS definitions. (microsoft#26225)
### Description <!-- Describe your changes. --> Add CMake `mlas_private_compile_definitions` variable for internal MLAS definitions. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> Refactor so that it is easier to add new private compile definitions for MLAS and related targets.
1 parent 8af9f58 commit 4cb138a

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

cmake/onnxruntime_mlas.cmake

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ set(MLAS_ROOT ${ONNXRUNTIME_ROOT}/core/mlas)
55
set(MLAS_SRC_DIR ${MLAS_ROOT}/lib)
66
set(MLAS_INC_DIR ${MLAS_ROOT}/inc)
77

8+
# mlas_private_compile_definitions contains compile definitions that are private to onnxruntime_mlas and targets which
9+
# use internal MLAS headers like mlasi.h.
10+
set(mlas_private_compile_definitions)
811
#
912
# All hardware agnostic source files here
1013
# hardware specific files would cause trouble in
@@ -133,9 +136,9 @@ function(setup_mlas_source_for_windows)
133136
)
134137

135138
if (onnxruntime_USE_ARM_NEON_NCHWC)
136-
setup_arm_neon_nchwc()
139+
setup_arm_neon_nchwc()
137140
endif()
138-
141+
139142
if (onnxruntime_USE_KLEIDIAI)
140143
setup_kleidiai()
141144
endif()
@@ -293,11 +296,12 @@ endfunction()
293296

294297
function (setup_arm_neon_nchwc)
295298
target_sources(onnxruntime_mlas PRIVATE
296-
${MLAS_SRC_DIR}/sconv.h
299+
${MLAS_SRC_DIR}/sconv.h
297300
${MLAS_SRC_DIR}/sconv_kernel_neon.cpp
298301
${MLAS_SRC_DIR}/spool_kernel_neon.cpp
299302
)
300-
target_compile_definitions(onnxruntime_mlas PRIVATE MLAS_USE_ARM_NEON_NCHWC)
303+
list(APPEND mlas_private_compile_definitions MLAS_USE_ARM_NEON_NCHWC)
304+
set(mlas_private_compile_definitions ${mlas_private_compile_definitions} PARENT_SCOPE)
301305
endfunction ()
302306

303307
if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
@@ -445,25 +449,25 @@ else()
445449
${MLAS_SRC_DIR}/eltwise_kernel_neon.cpp
446450
${MLAS_SRC_DIR}/sqnbitgemm_kernel_neon_int8_i8mm.cpp
447451
)
448-
452+
449453
# Conditionally add the SVE implementation if compiler supports it
450454
if (onnxruntime_USE_SVE)
451455
list(APPEND mlas_platform_srcs ${MLAS_SRC_DIR}/sve/mlasi_sve.h)
452456
list(APPEND mlas_platform_srcs ${MLAS_SRC_DIR}/sve/elementwise_sve.cpp)
453457
set_source_files_properties(${MLAS_SRC_DIR}/sve/elementwise_sve.cpp PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+sve+fp16 ")
454-
target_compile_definitions(onnxruntime_mlas PRIVATE MLAS_USE_SVE)
458+
list(APPEND mlas_private_compile_definitions MLAS_USE_SVE)
455459
endif()
456460

457461
if (onnxruntime_USE_ARM_NEON_NCHWC)
458-
setup_arm_neon_nchwc()
462+
setup_arm_neon_nchwc()
459463
endif()
460-
464+
461465
if (onnxruntime_USE_KLEIDIAI)
462466
setup_kleidiai()
463467
endif()
464468
set_source_files_properties(${MLAS_SRC_DIR}/sqnbitgemm_kernel_neon_int8.cpp
465469
PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+dotprod")
466-
set_source_files_properties(${MLAS_SRC_DIR}/sqnbitgemm_kernel_neon_int8_i8mm.cpp
470+
set_source_files_properties(${MLAS_SRC_DIR}/sqnbitgemm_kernel_neon_int8_i8mm.cpp
467471
PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+i8mm ")
468472

469473
if (NOT APPLE)
@@ -806,6 +810,8 @@ foreach(mlas_target ${ONNXRUNTIME_MLAS_LIBS})
806810
target_include_directories(${mlas_target} PRIVATE ${MLAS_INC_DIR} ${MLAS_SRC_DIR})
807811
onnxruntime_add_include_to_target(${mlas_target} ${GSL_TARGET})
808812

813+
target_compile_definitions(${mlas_target} PRIVATE ${mlas_private_compile_definitions})
814+
809815
set_target_properties(${mlas_target} PROPERTIES FOLDER "ONNXRuntime")
810816
endforeach()
811817

cmake/onnxruntime_unittests.cmake

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,9 +1325,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
13251325
${BENCHMARK_DIR}/layer_normalization.cc)
13261326
target_include_directories(onnxruntime_benchmark PRIVATE ${ONNXRUNTIME_ROOT} ${onnxruntime_graph_header} ${ONNXRUNTIME_ROOT}/core/mlas/inc)
13271327
target_compile_definitions(onnxruntime_benchmark PRIVATE BENCHMARK_STATIC_DEFINE)
1328-
if (onnxruntime_USE_SVE)
1329-
target_compile_definitions(onnxruntime_benchmark PRIVATE MLAS_USE_SVE)
1330-
endif()
1328+
target_compile_definitions(onnxruntime_benchmark PRIVATE ${mlas_private_compile_definitions})
13311329
if(WIN32)
13321330
target_compile_options(onnxruntime_benchmark PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:--compiler-options /wd4141>"
13331331
"$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:/wd4141>")
@@ -1355,9 +1353,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
13551353
target_include_directories(onnxruntime_mlas_benchmark PRIVATE ${ONNXRUNTIME_ROOT}/core/mlas/inc)
13561354
target_link_libraries(onnxruntime_mlas_benchmark PRIVATE benchmark::benchmark onnxruntime_util ${ONNXRUNTIME_MLAS_LIBS} onnxruntime_common ${CMAKE_DL_LIBS})
13571355
target_compile_definitions(onnxruntime_mlas_benchmark PRIVATE BENCHMARK_STATIC_DEFINE)
1358-
if (onnxruntime_USE_SVE)
1359-
target_compile_definitions(onnxruntime_mlas_benchmark PRIVATE MLAS_USE_SVE)
1360-
endif()
1356+
target_compile_definitions(onnxruntime_mlas_benchmark PRIVATE ${mlas_private_compile_definitions})
13611357
if(WIN32)
13621358
target_link_libraries(onnxruntime_mlas_benchmark PRIVATE debug Dbghelp)
13631359
# Avoid using new and delete. But this is a benchmark program, it's ok if it has a chance to leak.
@@ -1655,9 +1651,7 @@ endif()
16551651
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
16561652
)
16571653
endif()
1658-
if (onnxruntime_USE_SVE)
1659-
target_compile_definitions(onnxruntime_mlas_test PRIVATE MLAS_USE_SVE)
1660-
endif()
1654+
target_compile_definitions(onnxruntime_mlas_test PRIVATE ${mlas_private_compile_definitions})
16611655
target_include_directories(onnxruntime_mlas_test PRIVATE ${ONNXRUNTIME_ROOT}/core/mlas/inc ${ONNXRUNTIME_ROOT}
16621656
${CMAKE_CURRENT_BINARY_DIR})
16631657
target_link_libraries(onnxruntime_mlas_test PRIVATE GTest::gtest GTest::gmock ${ONNXRUNTIME_MLAS_LIBS} onnxruntime_common)

0 commit comments

Comments
 (0)