Skip to content

Commit

Permalink
Add quantized kernel test (pytorch#3899)
Browse files Browse the repository at this point in the history
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: pytorch#3899

Reviewed By: shoumikhin

Differential Revision: D58301544

Pulled By: kirklandsign

fbshipit-source-id: 7d12b826b118e828bf71f8042f9b68205c2f6e07
  • Loading branch information
kirklandsign authored and facebook-github-bot committed Jun 7, 2024
1 parent 5715d2f commit 9a813e2
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 5 deletions.
1 change: 1 addition & 0 deletions build/Test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion kernels/optimized/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion kernels/portable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/
)
6 changes: 5 additions & 1 deletion kernels/quantized/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/
)
47 changes: 47 additions & 0 deletions kernels/quantized/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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"
)
2 changes: 1 addition & 1 deletion kernels/quantized/test/op_choose_qparams_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ void test_dtype() {
EXPECT_TENSOR_EQ(zero_point_out, expected_zero_point);
}

TEST(OpQuantizeOutTest, AllDtypesSupported) {
TEST(OpChooseQparamsTensorOutTest, AllDtypesSupported) {
test_dtype<ScalarType::Byte>();
}
2 changes: 1 addition & 1 deletion kernels/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <executorch/kernels/${kernel}/Functions.h>" > "${_wrapper_path}"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMENT "Generating ${_wrapper_path}"
VERBATIM
Expand Down
1 change: 1 addition & 0 deletions test/run_oss_cpp_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit 9a813e2

Please sign in to comment.