From 1c5b3f4da81b7ae35b29415dd0d77071e291b0dc Mon Sep 17 00:00:00 2001 From: Ashvin Kumar Date: Wed, 6 Dec 2023 08:44:34 -0800 Subject: [PATCH 1/2] Updated CMakeLists.txt to add -DENABLE_TESTS argument at build Signed-off-by: Ashvin Kumar --- CMakeLists.txt | 15 ++++++++-- .../DlCompression/CMakeLists.txt | 5 +++- .../DlEqualization/CMakeLists.txt | 5 +++- .../DlQuantization/CMakeLists.txt | 5 +++- TrainingExtensions/common/CMakeLists.txt | 5 +++- TrainingExtensions/onnx/CMakeLists.txt | 4 ++- .../python/models/customops/CMakeLists.txt | 29 +++++++++++++------ TrainingExtensions/tensorflow/CMakeLists.txt | 5 +++- TrainingExtensions/torch/CMakeLists.txt | 5 ++-- 9 files changed, 59 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f6dff507ae..15f42b9a2d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -322,11 +322,22 @@ endif() add_subdirectory(ThirdParty) -enable_testing() +if (NOT (DEFINED ENABLE_TESTS)) + message("Test build not explicitly disabled. Enabling implicitly") + set(ENABLE_TESTS ON CACHE BOOL "") +endif(NOT (DEFINED ENABLE_TESTS)) + +if (ENABLE_TESTS) + message("Compiling test targets enabled") + enable_testing() + add_subdirectory(NightlyTests) +else (ENABLE_TESTS) + message("Compiling test targets disabled") +endif() + add_subdirectory(ModelOptimizations) add_subdirectory(TrainingExtensions) add_subdirectory(Examples) -add_subdirectory(NightlyTests) add_subdirectory(Docs) if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Benchmarks") add_subdirectory(Benchmarks) diff --git a/ModelOptimizations/DlCompression/CMakeLists.txt b/ModelOptimizations/DlCompression/CMakeLists.txt index eb767e2f35e..22775a1fcfc 100644 --- a/ModelOptimizations/DlCompression/CMakeLists.txt +++ b/ModelOptimizations/DlCompression/CMakeLists.txt @@ -60,5 +60,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/DlCompression DESTINATION ${AIMET_INSTALL_DIR}/lib/x86_64-linux-gnu/include) -add_subdirectory(test) +if (ENABLE_TESTS) + add_subdirectory(test) +endif() + whl_add_whl_prep_common_target(DlCompression) diff --git a/ModelOptimizations/DlEqualization/CMakeLists.txt b/ModelOptimizations/DlEqualization/CMakeLists.txt index 74437875db9..ae63d9d59eb 100644 --- a/ModelOptimizations/DlEqualization/CMakeLists.txt +++ b/ModelOptimizations/DlEqualization/CMakeLists.txt @@ -78,5 +78,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/DlEqualization DESTINATION ${AIMET_INSTALL_DIR}/lib/x86_64-linux-gnu/include) -add_subdirectory(test) +if (ENABLE_TESTS) + add_subdirectory(test) +endif() + whl_add_whl_prep_common_target(DlEqualization) diff --git a/ModelOptimizations/DlQuantization/CMakeLists.txt b/ModelOptimizations/DlQuantization/CMakeLists.txt index d84589a8319..9a1b70ef438 100644 --- a/ModelOptimizations/DlQuantization/CMakeLists.txt +++ b/ModelOptimizations/DlQuantization/CMakeLists.txt @@ -124,5 +124,8 @@ endif (ENABLE_CUDA) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/DlQuantization DESTINATION ${AIMET_INSTALL_DIR}/lib/x86_64-linux-gnu/include) -add_subdirectory(test) +if (ENABLE_TESTS) + add_subdirectory(test) +endif() + whl_add_whl_prep_common_target(DlQuantization) diff --git a/TrainingExtensions/common/CMakeLists.txt b/TrainingExtensions/common/CMakeLists.txt index 4e1d716f8d1..3c50d54c938 100644 --- a/TrainingExtensions/common/CMakeLists.txt +++ b/TrainingExtensions/common/CMakeLists.txt @@ -35,7 +35,10 @@ #============================================================================== add_subdirectory(src/python) -add_subdirectory(test) + +if (ENABLE_TESTS) + add_subdirectory(test) +endif() add_custom_target(whl_prep_cp_common DEPENDS whl_prep_cp_common_DlCompression diff --git a/TrainingExtensions/onnx/CMakeLists.txt b/TrainingExtensions/onnx/CMakeLists.txt index f5315f55202..9eb1c593b5d 100644 --- a/TrainingExtensions/onnx/CMakeLists.txt +++ b/TrainingExtensions/onnx/CMakeLists.txt @@ -40,8 +40,10 @@ find_path(ONNXRUNTIME_INC "onnxruntime_cxx_api.h" PATH_SUFFIXES onnxruntime_head find_package(Eigen3 REQUIRED) add_subdirectory(src/python) -add_subdirectory(test) +if (ENABLE_TESTS) + add_subdirectory(test) +endif() add_library(OnnxCppOps SHARED src/QcQuantizeOp.h diff --git a/TrainingExtensions/onnx/test/python/models/customops/CMakeLists.txt b/TrainingExtensions/onnx/test/python/models/customops/CMakeLists.txt index 6eed5a01058..a6f5bf91ec2 100644 --- a/TrainingExtensions/onnx/test/python/models/customops/CMakeLists.txt +++ b/TrainingExtensions/onnx/test/python/models/customops/CMakeLists.txt @@ -46,13 +46,24 @@ set_target_properties(torch_custom_add PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/artifacts/aimet_common/customops" ) -find_path(ONNXRUNTIME_INC "onnxruntime_cxx_api.h" PATH_SUFFIXES onnxruntime_headers/include) -find_library(ONNXRUNTIME_LIBRARY NAMES libonnxruntime.so PATH_SUFFIXES /onnxruntime_headers/lib) +# This block attempts to find the version number of the installed onnxruntime_headers +find_path(ONNXRUNTIME_VER "VERSION_NUMBER" PATH_SUFFIXES onnxruntime_headers) +file(READ ${ONNXRUNTIME_VER}/VERSION_NUMBER VERSION_NUMBER) +string(REGEX REPLACE "([^0123456789.])" "" VERSION_NUMBER ${VERSION_NUMBER}) +message(STATUS "Found onnxruntime_header version: ${VERSION_NUMBER}") -add_library(onnx_custom_add SHARED onnx_custom_add.cpp onnx_custom_add.h) -target_compile_features(onnx_custom_add PRIVATE cxx_std_14) -target_include_directories(onnx_custom_add PRIVATE ${ONNXRUNTIME_INC}) -target_link_libraries(onnx_custom_add PUBLIC ${ONNXRUNTIME_LIBRARY}) -set_target_properties(onnx_custom_add PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/artifacts/aimet_common/customops" - ) +# Only build custom op targets if onnxruntime_headers are from >= v1.15.1 +if(VERSION_NUMBER VERSION_GREATER_EQUAL "1.15.1") + find_path(ONNXRUNTIME_INC "onnxruntime_cxx_api.h" PATH_SUFFIXES onnxruntime_headers/include) + find_library(ONNXRUNTIME_LIBRARY NAMES libonnxruntime.so PATH_SUFFIXES /onnxruntime_headers/lib) + + add_library(onnx_custom_add SHARED onnx_custom_add.cpp onnx_custom_add.h) + target_compile_features(onnx_custom_add PRIVATE cxx_std_14) + target_include_directories(onnx_custom_add PRIVATE ${ONNXRUNTIME_INC}) + target_link_libraries(onnx_custom_add PUBLIC ${ONNXRUNTIME_LIBRARY}) + set_target_properties(onnx_custom_add PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/artifacts/aimet_common/customops" + ) +else() + message("onnxruntime headers must be >=v1.15.1 to build onnx customop targets. Skipping onnx custom op targets.") +endif() diff --git a/TrainingExtensions/tensorflow/CMakeLists.txt b/TrainingExtensions/tensorflow/CMakeLists.txt index 0548c9ed5cb..d52cc510f78 100644 --- a/TrainingExtensions/tensorflow/CMakeLists.txt +++ b/TrainingExtensions/tensorflow/CMakeLists.txt @@ -187,4 +187,7 @@ add_dependencies(whl_prep_ln whl_prep_ln_tensorflow) whl_add_whl_action_target(tensorflow) add_subdirectory(src/python) -add_subdirectory(test) + +if (ENABLE_TESTS) + add_subdirectory(test) +endif() diff --git a/TrainingExtensions/torch/CMakeLists.txt b/TrainingExtensions/torch/CMakeLists.txt index 5910e8c517c..8ab806fde5e 100644 --- a/TrainingExtensions/torch/CMakeLists.txt +++ b/TrainingExtensions/torch/CMakeLists.txt @@ -94,10 +94,11 @@ add_subdirectory(src/python) if (ENABLE_ONNX) message(STATUS "ONNX is enabled, skipping Torch Unit test") else(ENABLE_ONNX) - add_subdirectory(test) + if (ENABLE_TESTS) + add_subdirectory(test) + endif() endif(ENABLE_ONNX) - install(DIRECTORY ${CMAKE_BINARY_DIR}/artifacts/aimet_common/ DESTINATION ${AIMET_INSTALL_DIR}/lib/python/aimet_common FILES_MATCHING PATTERN "AimetTensorQuantizer*.so" From 5fcc12cde0ea35150fe7b7be0da69a71e1dd9349 Mon Sep 17 00:00:00 2001 From: Ashvin Kumar Date: Thu, 7 Dec 2023 09:17:10 -0800 Subject: [PATCH 2/2] Removed check disabling custom op build in case of mismatched ort version Signed-off-by: Ashvin Kumar --- .../python/models/customops/CMakeLists.txt | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/TrainingExtensions/onnx/test/python/models/customops/CMakeLists.txt b/TrainingExtensions/onnx/test/python/models/customops/CMakeLists.txt index a6f5bf91ec2..6eed5a01058 100644 --- a/TrainingExtensions/onnx/test/python/models/customops/CMakeLists.txt +++ b/TrainingExtensions/onnx/test/python/models/customops/CMakeLists.txt @@ -46,24 +46,13 @@ set_target_properties(torch_custom_add PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/artifacts/aimet_common/customops" ) -# This block attempts to find the version number of the installed onnxruntime_headers -find_path(ONNXRUNTIME_VER "VERSION_NUMBER" PATH_SUFFIXES onnxruntime_headers) -file(READ ${ONNXRUNTIME_VER}/VERSION_NUMBER VERSION_NUMBER) -string(REGEX REPLACE "([^0123456789.])" "" VERSION_NUMBER ${VERSION_NUMBER}) -message(STATUS "Found onnxruntime_header version: ${VERSION_NUMBER}") +find_path(ONNXRUNTIME_INC "onnxruntime_cxx_api.h" PATH_SUFFIXES onnxruntime_headers/include) +find_library(ONNXRUNTIME_LIBRARY NAMES libonnxruntime.so PATH_SUFFIXES /onnxruntime_headers/lib) -# Only build custom op targets if onnxruntime_headers are from >= v1.15.1 -if(VERSION_NUMBER VERSION_GREATER_EQUAL "1.15.1") - find_path(ONNXRUNTIME_INC "onnxruntime_cxx_api.h" PATH_SUFFIXES onnxruntime_headers/include) - find_library(ONNXRUNTIME_LIBRARY NAMES libonnxruntime.so PATH_SUFFIXES /onnxruntime_headers/lib) - - add_library(onnx_custom_add SHARED onnx_custom_add.cpp onnx_custom_add.h) - target_compile_features(onnx_custom_add PRIVATE cxx_std_14) - target_include_directories(onnx_custom_add PRIVATE ${ONNXRUNTIME_INC}) - target_link_libraries(onnx_custom_add PUBLIC ${ONNXRUNTIME_LIBRARY}) - set_target_properties(onnx_custom_add PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/artifacts/aimet_common/customops" - ) -else() - message("onnxruntime headers must be >=v1.15.1 to build onnx customop targets. Skipping onnx custom op targets.") -endif() +add_library(onnx_custom_add SHARED onnx_custom_add.cpp onnx_custom_add.h) +target_compile_features(onnx_custom_add PRIVATE cxx_std_14) +target_include_directories(onnx_custom_add PRIVATE ${ONNXRUNTIME_INC}) +target_link_libraries(onnx_custom_add PUBLIC ${ONNXRUNTIME_LIBRARY}) +set_target_properties(onnx_custom_add PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/artifacts/aimet_common/customops" + )