Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .ci/scripts/test-cadence-generic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
# LICENSE file in the root directory of this source tree.
#
# Build the Cadence generic (reference) op-level gtest tests for the host and
# run them.
# run them, then build and run cadence_op_registry_test, which checks that every
# op in backends/cadence/aot/functions.yaml is registered by cadence_ops_lib.
#
# Unlike backends/cadence/build_cadence_runner.sh (built -fno-exceptions
# -fno-rtti), the gtest tests need exceptions + RTTI, so those flags are NOT set
# here.

set -euo pipefail

TEST_TARGET=cadence_generic_op_tests
TEST_BIN="cmake-out/backends/cadence/generic/operators/tests/${TEST_TARGET}"
BUILD_TARGETS=(cadence_generic_op_tests cadence_op_registry_test)
TEST_BINS=(
cmake-out/backends/cadence/generic/operators/tests/cadence_generic_op_tests
cmake-out/backends/cadence/cadence_op_registry_test
)

rm -rf cmake-out
cmake \
Expand All @@ -28,6 +32,9 @@ cmake \
-DPYTHON_EXECUTABLE="$(which python3)" \
-Bcmake-out .

cmake --build cmake-out --target "${TEST_TARGET}" -j"$(nproc)"
cmake --build cmake-out --target "${BUILD_TARGETS[@]}" -j"$(nproc)"

"${TEST_BIN}"
for TEST_BIN in "${TEST_BINS[@]}"; do
echo "=== running $(basename "${TEST_BIN}") ==="
"${TEST_BIN}"
done
62 changes: 36 additions & 26 deletions .ci/scripts/test-cadence-xtensa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
# LICENSE file in the root directory of this source tree.
#
# Build the Cadence Xtensa op-level gtest tests for the configured backend and
# run them on the Instruction Set Simulator (xt-run).
# run them on the Instruction Set Simulator (xt-run). On backends that opt in,
# also build and run cadence_op_registry_test, which checks that every op in the
# backend's functions yaml is registered by cadence_ops_lib.
#
# Requires the Xtensa toolchain env to already be set (run
# .ci/scripts/setup-xtensa-tools.sh <backend> first): XTENSA_TOOLCHAIN,
Expand All @@ -22,21 +24,27 @@ set -euo pipefail
: "${XTENSA_CORE:?run setup-xtensa-tools.sh first}"
: "${CADENCE_OPT_FLAG:?run setup-xtensa-tools.sh first}"

# Map the optimized-kernel flag to the backend dir + gtest target name.
# Map the optimized-kernel flag to the backend dir + gtest target name, and
# whether the backend runs cadence_op_registry_test.
case "${CADENCE_OPT_FLAG}" in
EXECUTORCH_NNLIB_OPT) TARGET_DIR=hifi ;;
EXECUTORCH_VISION_OPT) TARGET_DIR=vision ;;
EXECUTORCH_FUSION_G3_OPT) TARGET_DIR=fusion_g3 ;;
EXECUTORCH_NNLIB_OPT) TARGET_DIR=hifi RUN_REGISTRY_TEST=1 ;;
EXECUTORCH_VISION_OPT) TARGET_DIR=vision RUN_REGISTRY_TEST=0 ;;
EXECUTORCH_FUSION_G3_OPT) TARGET_DIR=fusion_g3 RUN_REGISTRY_TEST=0 ;;
*)
echo "ERROR: unknown CADENCE_OPT_FLAG='${CADENCE_OPT_FLAG}'" >&2
exit 1
;;
esac
TEST_TARGET="cadence_${TARGET_DIR}_op_tests"
TEST_ELF="cmake-out/backends/cadence/${TARGET_DIR}/operators/tests/${TEST_TARGET}"
TEST_ELFS=("cmake-out/backends/cadence/${TARGET_DIR}/operators/tests/${TEST_TARGET}")
BUILD_TARGETS=("${TEST_TARGET}")
if [[ "${RUN_REGISTRY_TEST}" == "1" ]]; then
BUILD_TARGETS+=(cadence_op_registry_test)
TEST_ELFS+=(cmake-out/backends/cadence/cadence_op_registry_test)
fi

NPROC=$(nproc)
echo "=== building ${TEST_TARGET} for ${XTENSA_CORE} (${CADENCE_OPT_FLAG}) ==="
echo "=== building ${BUILD_TARGETS[*]} for ${XTENSA_CORE} (${CADENCE_OPT_FLAG}) ==="
xt-clang --version | head -1

rm -rf cmake-out
Expand All @@ -61,24 +69,26 @@ cmake \
-DPYTHON_EXECUTABLE="$(which python3)" \
-Bcmake-out .

cmake --build cmake-out --target "${TEST_TARGET}" -j"${NPROC}"

if [[ ! -f "${TEST_ELF}" ]]; then
echo "ERROR: ${TEST_ELF} was not produced" >&2
exit 1
fi
cmake --build cmake-out --target "${BUILD_TARGETS[@]}" -j"${NPROC}"

echo "=== running ${TEST_TARGET} on xt-run ==="
LOG=$(mktemp)
# --exit_with_target_code propagates gtest_main's exit code, so a failing test
# fails this step; also assert on the gtest summary lines as a backstop.
xt-run --turbo --exit_with_target_code "${TEST_ELF}" 2>&1 | tee "${LOG}"
if grep -q "\[ FAILED \]" "${LOG}"; then
echo "ERROR: gtest reported failures for ${TEST_TARGET}" >&2
exit 1
fi
if ! grep -q "\[ PASSED \]" "${LOG}"; then
echo "ERROR: ${TEST_TARGET} did not report a gtest PASSED summary" >&2
exit 1
fi
for TEST_ELF in "${TEST_ELFS[@]}"; do
if [[ ! -f "${TEST_ELF}" ]]; then
echo "ERROR: ${TEST_ELF} was not produced" >&2
exit 1
fi
TEST_NAME=$(basename "${TEST_ELF}")
echo "=== running ${TEST_NAME} on xt-run ==="
LOG=$(mktemp)
# --exit_with_target_code propagates gtest_main's exit code, so a failing test
# fails this step; also assert on the gtest summary lines as a backstop.
xt-run --turbo --exit_with_target_code "${TEST_ELF}" 2>&1 | tee "${LOG}"
if grep -q "\[ FAILED \]" "${LOG}"; then
echo "ERROR: gtest reported failures for ${TEST_NAME}" >&2
exit 1
fi
if ! grep -q "\[ PASSED \]" "${LOG}"; then
echo "ERROR: ${TEST_NAME} did not report a gtest PASSED summary" >&2
exit 1
fi
done
echo "Cadence ${TARGET_DIR} op tests passed on ${XTENSA_CORE}."
11 changes: 7 additions & 4 deletions .github/workflows/_xtensa_test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Reusable: build + run the Cadence Xtensa op-level gtest tests for one core on
# the Instruction Set Simulator (xt-run). Mirrors _xtensa_build.yml's native
# OIDC skeleton (running xt-run needs the same licensed toolchain),
# then builds the gtest op-test ELF and runs it on the simulator. The runner
# cross-compile and these op tests are separate build configs (the tests need
# exceptions/RTTI that the runner build disables), so this is a self-contained
# job rather than consuming the runner artifact.
# then builds the gtest op-test ELF and runs it on the simulator. On backends
# that opt in, test-cadence-xtensa.sh also builds and runs
# cadence_op_registry_test, which checks that cadence_ops_lib registers every
# op in the backend's functions yaml. The runner cross-compile and these op
# tests are separate build configs (the tests need exceptions/RTTI that the
# runner build disables), so this is a self-contained job rather than
# consuming the runner artifact.
name: xtensa-test

on:
Expand Down
36 changes: 36 additions & 0 deletions backends/cadence/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,40 @@ if(EXECUTORCH_BUILD_CADENCE_OP_TESTS
"${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/operators/tests/CMakeLists.txt"
)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/operators/tests)

# Op-registry gtest: links cadence_ops_lib the way cadence_executor_runner
# does and checks that every op codegen selected from the backend's functions
# yaml is in the kernel registry after runtime_init(). The op list is read at
# build time from cadence_ops_lib's selected_operators.yaml. gtest comes from
# the op-test dir above.
get_target_property(_cadence_ops_lib_dir cadence_ops_lib BINARY_DIR)
set(_selected_ops_yaml
${_cadence_ops_lib_dir}/cadence_ops_lib/selected_operators.yaml
)
set(_selected_ops_h
${CMAKE_CURRENT_BINARY_DIR}/cadence_ops_lib_selected_ops.h
)
add_custom_command(
OUTPUT ${_selected_ops_h}
COMMAND
${PYTHON_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/utils/gen_selected_ops_header.py
--oplist-yaml=${_selected_ops_yaml} --output-path=${_selected_ops_h}
DEPENDS ${_selected_ops_yaml}
${CMAKE_CURRENT_SOURCE_DIR}/utils/gen_selected_ops_header.py
)
add_executable(
cadence_op_registry_test cadence_op_registry_test.cpp ${_selected_ops_h}
)
target_compile_definitions(
cadence_op_registry_test PRIVATE GTEST_HAS_PTHREAD=0
)
target_include_directories(
cadence_op_registry_test PRIVATE ${_common_include_directories}
${CMAKE_CURRENT_BINARY_DIR}
)
target_link_libraries(
cadence_op_registry_test PRIVATE gtest gtest_main executorch
cadence_ops_lib
)
endif()
18 changes: 18 additions & 0 deletions backends/cadence/aot/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ fbcode_target(_kind = executorch_generated_lib,
"//executorch/backends/cadence/generic/operators:op_quantized_max_pool2d_nhwc",
"//executorch/backends/cadence/generic/operators:op_quantized_mul",
"//executorch/backends/cadence/generic/operators:op_quantized_relu",
"//executorch/backends/cadence/generic/operators:op_avg_pool2d",
"//executorch/backends/cadence/generic/operators:op_conv1d",
"//executorch/backends/cadence/generic/operators:op_conv2d",
"//executorch/backends/cadence/generic/operators:op_fully_connected",
"//executorch/backends/cadence/generic/operators:op_softmax",
"//executorch/backends/cadence/generic/operators:op_transposed_convolution",
"//executorch/backends/cadence/generic/operators:op_transposed_im2row",
"//executorch/kernels/portable:executorch_all_ops",
"//executorch/kernels/portable:operators",
],
Expand Down Expand Up @@ -741,3 +748,14 @@ fbcode_target(_kind = python_unittest,
"//later:lib",
],
)

fbcode_target(_kind = python_unittest,
name = "test_functions_yaml",
srcs = [
"tests/test_functions_yaml.py",
],
resources = glob(["functions*.yaml"]),
deps = [
"fbsource//third-party/pypi/pyyaml:pyyaml",
],
)
Loading
Loading