Skip to content

Commit

Permalink
CPU feature logging
Browse files Browse the repository at this point in the history
Signed-off-by: Benoit Jacob <jacob.benoit.1@gmail.com>
  • Loading branch information
bjacob committed Oct 17, 2024
1 parent 05bbcf1 commit 30d54bf
Show file tree
Hide file tree
Showing 33 changed files with 433 additions and 269 deletions.
24 changes: 5 additions & 19 deletions build_tools/bazel/iree_check_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def iree_check_test(
input_type = None,
runner_args = [],
tags = [],
target_cpu_features = None,
timeout = None,
**kwargs):
"""Creates an iree-check-module test for the specified source file.
Expand All @@ -43,19 +42,16 @@ def iree_check_test(
driver and input file are passed automatically.
tags: additional tags to apply to the generated test. Tag
"driver=DRIVER" and "target=TARGET" are added automatically.
target_cpu_features: currently unimplemented (must be empty), will
eventually allow specifying target CPU features.
timeout: timeout for the generated tests.
**kwargs: any additional attributes to pass to the underlying native_test.
"""

if target_cpu_features:
fail("target_cpu_features must currently be empty")
input_type_flags = []
if input_type:
input_type_flags = ["--iree-input-type=%s" % input_type]
flags = [
"--iree-hal-target-backends=%s" % target_backend,
"--iree-hal-target-cpu=generic",
] + compiler_flags + input_type_flags
bytecode_module_name = name + "_bytecode_module"
iree_bytecode_module(
Expand Down Expand Up @@ -91,7 +87,6 @@ def iree_check_single_backend_test_suite(
input_type = None,
runner_args = [],
tags = [],
target_cpu_features = None,
timeout = None,
**kwargs):
"""Creates a test suite of iree-check-module tests for a single backend/driver pair.
Expand All @@ -112,8 +107,6 @@ def iree_check_single_backend_test_suite(
iree-check-module tests. The driver and input file are passed
automatically. To use different runner_args per test, create a
separate suite or iree_check_test.
target_cpu_features: currently unimplemented (must be empty), will
eventually allow specifying target CPU features.
tags: tags to apply to the generated tests. Note that as in standard test
suites, manual is treated specially and will also apply to the test
suite itself.
Expand All @@ -130,13 +123,6 @@ def iree_check_single_backend_test_suite(
if target_backend == "rocm" or driver == "hip":
return

# We haven't implemented this so far because we have been using target_cpu_features so far only
# for aarch64 targets, for which we use the CMake build. To future people implementing this:
# target_cpu_features should be a list, and here it should be joined into a comma-separated
# string to be passed to --iree-llvmcpu-target-cpu-features
if target_cpu_features:
fail("target_cpu_features must currently be empty")

tests = []
for src in srcs:
test_name = "_".join([name, src])
Expand Down Expand Up @@ -200,10 +186,10 @@ def iree_check_test_suite(
Currently unimplemented in Bazel due to difficulty of specializing
to target architecture in Bazel. The following describes the
semantics that this should have if implemented. Each
entry is either "default" for the architecture defaults, or a colon-
separated triple "arch:name:cpu_features" where "arch" filters
for a target CPU architecture (in IREE_ARCH format), "name" is a
short name for the CPU features set (used to generate target names)
entry is either "generic" for the architecture defaults, or "host"
for the host CPU,or a colon-separated triple "arch:name:cpu_features"
where "arch" filters for a target CPU architecture (in IREE_ARCH format),
"name" is a short name for the CPU features set (used to generate target names)
and cpu_features is a comma-separated list of LLVM target attributes
to enable. Example:
x86_64:avx2_fma:+avx,+avx2,+fma
Expand Down
23 changes: 7 additions & 16 deletions build_tools/bazel/iree_e2e_generated_runner_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def iree_e2e_runner_test(
compiler_flags = [],
runner_args = [],
tags = [],
target_cpu_features = None,
timeout = None,
**kwargs):
"""Creates a test using a specified test runner program.
Expand All @@ -44,23 +43,18 @@ def iree_e2e_runner_test(
added automatically.
test_runner: test runner program to run.
timeout: timeout for the generated tests.
target_cpu_features: target CPU features. Only for llvm-cpu backend.
**kwargs: any additional attributes to pass to the underlying tests and
test suite.
"""

if target_cpu_features:
fail("target_cpu_features must currently be empty")

iree_bytecode_module(
name = name + "_%s_module" % test_type,
module_name = tests_vmfb,
src = tests_src,
flags = [
"--iree-hal-target-backends=%s" % target_backend,
] + ([
"--iree-llvmcpu-target-cpu-features=%s" % target_cpu_features,
] if target_cpu_features else []) + compiler_flags,
"--iree-hal-target-cpu=generic",
] + compiler_flags,
visibility = ["//visibility:private"],
testonly = True,
**kwargs
Expand Down Expand Up @@ -106,7 +100,6 @@ def iree_single_backend_e2e_runner_test(
compiler_flags = [],
runner_args = [],
tags = [],
target_cpu_features = None,
timeout = None,
**kwargs):
"""Generates an iree_e2e_runner_test using a custom python generator script.
Expand All @@ -133,7 +126,6 @@ def iree_single_backend_e2e_runner_test(
added automatically.
test_runner: test runner program to run.
timeout: timeout for the generated tests.
target_cpu_features: target CPU features. Only for llvm-cpu backend.
**kwargs: any additional attributes to pass to the underlying tests and
test suite.
"""
Expand Down Expand Up @@ -171,7 +163,6 @@ def iree_single_backend_e2e_runner_test(
runner_args = runner_args,
tags = tags,
timeout = timeout,
target_cpu_features = target_cpu_features,
**kwargs
)

Expand Down Expand Up @@ -213,13 +204,13 @@ def iree_generated_e2e_runner_test(
Currently unimplemented in Bazel due to difficulty of specializing
to target architecture in Bazel. The following describes the
semantics that this should have if implemented. Each
entry is either "default" for the architecture defaults, or a colon-
separated triple "arch:name:cpu_features" where "arch" filters
for a target CPU architecture (in IREE_ARCH format), "name" is a
short name for the CPU features set (used to generate target names)
entry is either "generic" for the architecture defaults, or "host"
for the host CPU,or a colon-separated triple "arch:name:cpu_features"
where "arch" filters for a target CPU architecture (in IREE_ARCH format),
"name" is a short name for the CPU features set (used to generate target names)
and cpu_features is a comma-separated list of LLVM target attributes
to enable. Example:
x86_64:avx2_fma:+avx,+avx2,+fma
x86_64:avx2_fma:+avx,+avx2,+fma
**kwargs: any additional attributes to pass to the underlying tests and test suite.
"""

Expand Down
5 changes: 0 additions & 5 deletions build_tools/bazel_to_cmake/bazel_to_cmake_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,6 @@ def iree_check_single_backend_test_suite(
target_backends_and_drivers=None,
runner_args=None,
tags=None,
target_cpu_features=None,
timeout=None,
**kwargs,
):
Expand All @@ -787,9 +786,6 @@ def iree_check_single_backend_test_suite(
input_type_block = self._convert_string_arg_block("INPUT_TYPE", input_type)
runner_args_block = self._convert_string_list_block("RUNNER_ARGS", runner_args)
labels_block = self._convert_string_list_block("LABELS", tags)
target_cpu_features_block = self._convert_string_arg_block(
"TARGET_CPU_FEATURES", target_cpu_features
)
timeout_block = self._convert_timeout_arg_block("TIMEOUT", timeout)

self._converter.body += (
Expand All @@ -802,7 +798,6 @@ def iree_check_single_backend_test_suite(
f"{input_type_block}"
f"{runner_args_block}"
f"{labels_block}"
f"{target_cpu_features_block}"
f"{timeout_block}"
f")\n\n"
)
Expand Down
48 changes: 20 additions & 28 deletions build_tools/cmake/iree_check_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ endfunction()
# "driver=${DRIVER}" are added automatically.
# MODULE_FILE_NAME: Optional, specifies the absolute path to the filename
# to use for the generated IREE module (.vmfb).
# TARGET_CPU_FEATURES: If specified, a string passed as argument to
# --iree-llvmcpu-target-cpu-features.
# DEPENDS: Optional. Additional dependencies beyond SRC and the tools.
# INPUT_TYPE: The value for the --iree-input-type= flag. Also disables tests
# if no compiled support for that configuration.
Expand All @@ -53,7 +51,7 @@ function(iree_check_test)
_RULE
""
"NAME;SRC;TARGET_BACKEND;DRIVER;MODULE_FILE_NAME;INPUT_TYPE"
"COMPILER_FLAGS;RUNNER_ARGS;LABELS;TARGET_CPU_FEATURES;DEPENDS;TIMEOUT"
"COMPILER_FLAGS;RUNNER_ARGS;LABELS;DEPENDS;TIMEOUT"
${ARGN}
)

Expand Down Expand Up @@ -162,9 +160,6 @@ function(iree_check_test)
if(_RULE_INPUT_TYPE)
list(APPEND _BASE_COMPILER_FLAGS "--iree-input-type=${_RULE_INPUT_TYPE}")
endif()
if(_RULE_TARGET_CPU_FEATURES)
list(APPEND _BASE_COMPILER_FLAGS "--iree-llvmcpu-target-cpu-features=${_RULE_TARGET_CPU_FEATURES}")
endif()
if(_NORMALIZED_TARGET_BACKEND STREQUAL "ROCM")
list(APPEND _BASE_COMPILER_FLAGS "--iree-hip-target=${IREE_HIP_TEST_TARGET_CHIP}")
endif()
Expand Down Expand Up @@ -242,8 +237,6 @@ endfunction()
# different args per test, create a separate suite or iree_check_test.
# LABELS: Additional labels to apply to the generated tests. The package path
# is added automatically.
# TARGET_CPU_FEATURES: If specified, a string passed as argument to
# --iree-llvmcpu-target-cpu-features.
# DEPENDS: Optional. Additional dependencies beyond SRC and the tools.
# INPUT_TYPE: The value for the --iree-input-type= flag. Also disables tests
# if no compiled support for that configuration.
Expand All @@ -256,7 +249,7 @@ function(iree_check_single_backend_test_suite)
_RULE
""
"NAME;TARGET_BACKEND;DRIVER;INPUT_TYPE"
"SRCS;COMPILER_FLAGS;RUNNER_ARGS;LABELS;TARGET_CPU_FEATURES;DEPENDS;TIMEOUT"
"SRCS;COMPILER_FLAGS;RUNNER_ARGS;LABELS;DEPENDS;TIMEOUT"
${ARGN}
)

Expand Down Expand Up @@ -284,7 +277,6 @@ function(iree_check_single_backend_test_suite)
INPUT_TYPE ${_RULE_INPUT_TYPE}
RUNNER_ARGS ${_RULE_RUNNER_ARGS}
LABELS ${_RULE_LABELS}
TARGET_CPU_FEATURES ${_RULE_TARGET_CPU_FEATURES}
DEPENDS ${_RULE_DEPENDS}
TIMEOUT ${_RULE_TIMEOUT}
)
Expand All @@ -309,7 +301,6 @@ function(iree_check_single_backend_test_suite)
INPUT_TYPE ${_RULE_INPUT_TYPE}
RUNNER_ARGS ${_RULE_RUNNER_ARGS}
LABELS ${_RULE_LABELS}
TARGET_CPU_FEATURES ${_RULE_TARGET_CPU_FEATURES}
DEPENDS ${_RULE_DEPENDS}
TIMEOUT ${_RULE_TIMEOUT}
)
Expand All @@ -328,7 +319,6 @@ function(iree_check_single_backend_test_suite)
INPUT_TYPE ${_RULE_INPUT_TYPE}
RUNNER_ARGS ${_RULE_RUNNER_ARGS}
LABELS ${_RULE_LABELS}
TARGET_CPU_FEATURES ${_RULE_TARGET_CPU_FEATURES}
DEPENDS ${_RULE_DEPENDS}
TIMEOUT ${_RULE_TIMEOUT}
)
Expand All @@ -342,9 +332,7 @@ endfunction()
# This function has 3 output-params: variables that it sets with PARENT_SCOPE:
# _ENABLED, _FEATURES_NAME, _FEATURES.
#
# "default" is handled specially. _ENABLED is always set to "TRUE" and
# _FEATURES_NAME and _FEATURES are set to
# the empty string.
# "generic" and "host" are handled specially, as CPU names.
#
# Other values are parsed as "arch:features_name:features". The `arch`
# component is matched with `IREE_ARCH`, `_ENABLED` is set to "TRUE" if and
Expand All @@ -354,23 +342,28 @@ endfunction()
#
# Examples:
#
# default:
# _ENABLED="TRUE" unconditionally,
# other output strings are "".
# generic:
# _ENABLED="TRUE" unconditionally, _FEATURES_NAME="generic", _FEATURES="".
#
# host:
# _ENABLED="TRUE" unconditionally, _FEATURES_NAME="host", _FEATURES="".
#
# aarch64:dotprod:+dotprod:
# _ENABLED="TRUE" if the target architecture is aarch64, and in that case:
# _FEATURES_NAME="dotprod".
# _FEATURES="+dotprod".
function(parse_target_cpu_features_variant _VARIANT_STRING _ENABLED_VAR
_FEATURES_NAME_VAR _FEATURES_VAR)
_FEATURES_NAME_VAR _COMPILER_FLAGS_VAR)
set("${_ENABLED_VAR}" FALSE PARENT_SCOPE)
set("${_FEATURES_NAME_VAR}" "" PARENT_SCOPE)
set("${_FEATURES_VAR}" "" PARENT_SCOPE)
if("${_VARIANT_STRING}" STREQUAL "default")
set("${_COMPILER_FLAGS_VAR}" "" PARENT_SCOPE)
if("${_VARIANT_STRING}" STREQUAL "generic" OR "${_VARIANT_STRING}" STREQUAL "host")
set("${_ENABLED_VAR}" TRUE PARENT_SCOPE)
set("${_FEATURES_NAME_VAR}" "${_VARIANT_STRING}" PARENT_SCOPE)
set("${_COMPILER_FLAGS_VAR}" "--iree-llvmcpu-target-cpu=${_VARIANT_STRING}" PARENT_SCOPE)
return()
endif()

# Interpret _VARIANT_STRING as a CMake list (;-separated).
string(REPLACE ":" ";" _COMPONENTS "${_VARIANT_STRING}")
list(LENGTH _COMPONENTS _NUM_COMPONENTS)
Expand All @@ -385,7 +378,7 @@ function(parse_target_cpu_features_variant _VARIANT_STRING _ENABLED_VAR
if(_FILTER_ARCH STREQUAL IREE_ARCH)
set("${_ENABLED_VAR}" TRUE PARENT_SCOPE)
set("${_FEATURES_NAME_VAR}" "${_FEATURES_NAME}" PARENT_SCOPE)
set("${_FEATURES_VAR}" "${_FEATURES}" PARENT_SCOPE)
set("${_COMPILER_FLAGS_VAR}" "--iree-llvmcpu-target-cpu-features=${_FEATURES}" PARENT_SCOPE)
endif()
endfunction()

Expand Down Expand Up @@ -413,8 +406,8 @@ endfunction()
# LABELS: Additional labels to apply to the generated tests. The package path is
# added automatically.
# TARGET_CPU_FEATURES_VARIANTS: list of target cpu features variants. Each
# entry is either "default" for the architecture defaults, or a colon-
# separated triple "arch:name:cpu_features" where "arch" filters
# entry is either "generic" for the architecture defaults, or "host" for
# the host CPU, or a colon-separated triple "arch:name:cpu_features" where "arch" filters
# for a target CPU architecture (in IREE_ARCH format), "name" is a
# short name for the CPU features set (used to generate target names)
# and cpu_features is a comma-separated list of LLVM target attributes
Expand Down Expand Up @@ -443,7 +436,7 @@ function(iree_check_test_suite)
if(_RULE_TARGET_CPU_FEATURES_VARIANTS)
set(_TARGET_CPU_FEATURES_VARIANTS "${_RULE_TARGET_CPU_FEATURES_VARIANTS}")
else()
set(_TARGET_CPU_FEATURES_VARIANTS "default")
set(_TARGET_CPU_FEATURES_VARIANTS "generic")
endif()

if(NOT DEFINED _RULE_TARGET_BACKENDS AND NOT DEFINED _RULE_DRIVERS)
Expand All @@ -466,7 +459,7 @@ function(iree_check_test_suite)
list(GET _RULE_DRIVERS ${_INDEX} _DRIVER)
foreach(_VARIANT_STRING IN LISTS _TARGET_CPU_FEATURES_VARIANTS)
parse_target_cpu_features_variant("${_VARIANT_STRING}"
_ENABLED _TARGET_CPU_FEATURES_NAME _TARGET_CPU_FEATURES)
_ENABLED _TARGET_CPU_FEATURES_NAME _VARIANT_COMPILER_FLAGS)
if(NOT _ENABLED)
# The current entry is disabled on the target CPU architecture.
continue()
Expand All @@ -488,12 +481,11 @@ function(iree_check_test_suite)
${_DRIVER}
COMPILER_FLAGS
${_RULE_COMPILER_FLAGS}
${_VARIANT_COMPILER_FLAGS}
RUNNER_ARGS
${_RULE_RUNNER_ARGS}
LABELS
${_LABELS}
TARGET_CPU_FEATURES
${_TARGET_CPU_FEATURES}
TIMEOUT
${_RULE_TIMEOUT}
INPUT_TYPE
Expand Down
Loading

0 comments on commit 30d54bf

Please sign in to comment.