From 9a813e26c127f6a3c36fad03388cdf5a27123f4d Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Fri, 7 Jun 2024 13:39:45 -0700 Subject: [PATCH] Add quantized kernel test (#3899) Summary: Quantized kernels are tested in a different way than aten ops, because they need their specific Functions.h header, and we can't re-use aten tests. Modify the generated header path a bit for all tests to use it correctly. Pull Request resolved: https://github.com/pytorch/executorch/pull/3899 Reviewed By: shoumikhin Differential Revision: D58301544 Pulled By: kirklandsign fbshipit-source-id: 7d12b826b118e828bf71f8042f9b68205c2f6e07 --- build/Test.cmake | 1 + kernels/optimized/CMakeLists.txt | 2 +- kernels/portable/CMakeLists.txt | 2 +- kernels/quantized/CMakeLists.txt | 6 ++- kernels/quantized/test/CMakeLists.txt | 47 +++++++++++++++++++ .../quantized/test/op_choose_qparams_test.cpp | 2 +- kernels/test/CMakeLists.txt | 2 +- test/run_oss_cpp_tests.sh | 1 + 8 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 kernels/quantized/test/CMakeLists.txt diff --git a/build/Test.cmake b/build/Test.cmake index 0759ef4d14..b2b23cb03a 100644 --- a/build/Test.cmake +++ b/build/Test.cmake @@ -28,6 +28,7 @@ find_package(GTest CONFIG REQUIRED) target_link_options_shared_lib(extension_data_loader) target_link_options_shared_lib(portable_kernels) target_link_options_shared_lib(portable_ops_lib) +target_link_options_shared_lib(quantized_ops_lib) # Add code coverage flags to supported compilers if(EXECUTORCH_USE_CPP_CODE_COVERAGE) diff --git a/kernels/optimized/CMakeLists.txt b/kernels/optimized/CMakeLists.txt index 0b0ecacbf4..858e51160e 100644 --- a/kernels/optimized/CMakeLists.txt +++ b/kernels/optimized/CMakeLists.txt @@ -70,7 +70,7 @@ gen_operators_lib( install( TARGETS cpublas optimized_kernels optimized_ops_lib DESTINATION lib - PUBLIC_HEADER DESTINATION include/optimized + PUBLIC_HEADER DESTINATION include/executorch/kernels/optimized/ ) install(TARGETS cpublas DESTINATION lib) diff --git a/kernels/portable/CMakeLists.txt b/kernels/portable/CMakeLists.txt index e8c412c287..eb3cedd5b3 100644 --- a/kernels/portable/CMakeLists.txt +++ b/kernels/portable/CMakeLists.txt @@ -67,5 +67,5 @@ gen_operators_lib( install( TARGETS portable_kernels portable_ops_lib DESTINATION lib - PUBLIC_HEADER DESTINATION include/portable + PUBLIC_HEADER DESTINATION include/executorch/kernels/portable/ ) diff --git a/kernels/quantized/CMakeLists.txt b/kernels/quantized/CMakeLists.txt index 0137783078..c649a793ed 100644 --- a/kernels/quantized/CMakeLists.txt +++ b/kernels/quantized/CMakeLists.txt @@ -100,4 +100,8 @@ gen_operators_lib( LIB_NAME "quantized_ops_lib" KERNEL_LIBS quantized_kernels DEPS executorch ) -install(TARGETS quantized_kernels quantized_ops_lib DESTINATION lib) +install( + TARGETS quantized_kernels quantized_ops_lib + DESTINATION lib + PUBLIC_HEADER DESTINATION include/executorch/kernels/quantized/ +) diff --git a/kernels/quantized/test/CMakeLists.txt b/kernels/quantized/test/CMakeLists.txt new file mode 100644 index 0000000000..8df233d931 --- /dev/null +++ b/kernels/quantized/test/CMakeLists.txt @@ -0,0 +1,47 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +# This file should be formatted with +# ~~~ +# cmake-format -i CMakeLists.txt +# ~~~ +# It should also be cmake-lint clean. +# + +cmake_minimum_required(VERSION 3.19) +project(kernels_quantized_test) + +# Use C++17 for test. +set(CMAKE_CXX_STANDARD 17) + +set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) + +include(${EXECUTORCH_ROOT}/build/Test.cmake) + +set(_kernels_quantized_test_sources + op_add_test.cpp + op_choose_qparams_test.cpp + op_dequantize_test.cpp + op_embedding4b_test.cpp + op_embedding_test.cpp + op_mixed_linear_test.cpp + op_mixed_mm_test.cpp + op_quantize_test.cpp +) + +et_cxx_test( + kernels_quantized_test + SOURCES + ${_kernels_quantized_test_sources} + EXTRA_LIBS + quantized_kernels + quantized_ops_lib + portable_kernels + portable_ops_lib +) +target_include_directories( + kernels_quantized_test PRIVATE "${CMAKE_INSTALL_PREFIX}/include" +) diff --git a/kernels/quantized/test/op_choose_qparams_test.cpp b/kernels/quantized/test/op_choose_qparams_test.cpp index 4ed405c1b7..e7acfb0cf4 100644 --- a/kernels/quantized/test/op_choose_qparams_test.cpp +++ b/kernels/quantized/test/op_choose_qparams_test.cpp @@ -48,6 +48,6 @@ void test_dtype() { EXPECT_TENSOR_EQ(zero_point_out, expected_zero_point); } -TEST(OpQuantizeOutTest, AllDtypesSupported) { +TEST(OpChooseQparamsTensorOutTest, AllDtypesSupported) { test_dtype(); } diff --git a/kernels/test/CMakeLists.txt b/kernels/test/CMakeLists.txt index a69fe5302a..6b965538b5 100644 --- a/kernels/test/CMakeLists.txt +++ b/kernels/test/CMakeLists.txt @@ -31,7 +31,7 @@ foreach(kernel ${_kernels}) add_custom_command( OUTPUT "${_wrapper_path}" COMMAND mkdir -p ${_wrapper_dir} - COMMAND echo "#include <${kernel}/Functions.h>" > "${_wrapper_path}" + COMMAND echo "#include " > "${_wrapper_path}" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" COMMENT "Generating ${_wrapper_path}" VERBATIM diff --git a/test/run_oss_cpp_tests.sh b/test/run_oss_cpp_tests.sh index 527555324e..305dc2a6d2 100755 --- a/test/run_oss_cpp_tests.sh +++ b/test/run_oss_cpp_tests.sh @@ -31,6 +31,7 @@ build_executorch() { -DCMAKE_INSTALL_PREFIX=cmake-out \ -DEXECUTORCH_USE_CPP_CODE_COVERAGE=ON \ -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \ + -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \ -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \