Skip to content

[libclc][test] Really run libspirv tests on all targets #19395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 15, 2025
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
51 changes: 26 additions & 25 deletions libclc/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# required by lit.site.cfg.py.in
set(LIBCLC_TEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(LIBCLC_PERTARGET_TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/targets)

configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
Expand All @@ -16,40 +17,40 @@ set(LIBCLC_TEST_DEPS
count
)

add_custom_target(check-libclc)

umbrella_lit_testsuite_begin(check-libclc)
foreach( t ${LIBCLC_TARGET_TO_TEST} )
foreach( d ${${t}_devices} )
if( ${d} STREQUAL "none" )
set( mcpu )
set( arch_suffix "${t}" )
else()
set( mcpu "cpu=${d}" )
set( arch_suffix "${d}-${t}" )
endif()
message( " Testing : ${arch_suffix}" )

add_lit_testsuite(check-libclc-spirv-${arch_suffix}
"Running libclc spirv-${arch_suffix} regression tests"
${CMAKE_CURRENT_BINARY_DIR}
ARGS
--verbose
PARAMS "target=${t}" ${mcpu} "libclc-arch-suffix=${arch_suffix}"
"builtins=libspirv-${arch_suffix}.bc"
# Each target gets own lit testsuite directory.
# This is done because all suites passed to add_lit_testsuite
# are collected into a single invocation of lit, for example:
# add_lit_testsuite(check-a dir PARAMS "foo=1")
# add_lit_testsuite(check-b dir PARAMS "foo=2" "bar=3")
# results in a call to lit like this (for `check-all`):
# llvm-lit --param=foo=1 --param=foo=2 --param=bar=3 dir dir
# This means we can't reuse the same directory and rely on
# different parameter values to distinguish between targets, because
# parameters with the same name overwrite each other.
# The solution is to create a separate directory for each target,
# and copy the lit.site.cfg.py file there; the name of the
# directory will be used as the target name.
file(MAKE_DIRECTORY ${LIBCLC_PERTARGET_TEST_DIR}/${t})
file(COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
${LIBCLC_PERTARGET_TEST_DIR}/${t}/lit.site.cfg.py)

add_lit_testsuite(check-libclc-spirv-${t}
"Running libclc spirv-${t} regression tests"
${LIBCLC_PERTARGET_TEST_DIR}/${t}
DEPENDS
${LIBCLC_TEST_DEPS}
libspirv-builtins
)

add_dependencies(check-libclc check-libclc-spirv-${arch_suffix})

endforeach( d )
endforeach( t )

if(LIBCLC_GENERATE_REMANGLED_VARIANTS)
#Now that check-libclc is defined make sure that all remangler targets depend
# Now that check-libclc is defined make sure that all remangler targets depend
# on it.
foreach(remangler-test ${libclc-remangler-tests})
add_dependencies(check-libclc ${remangler-test})
set_property(GLOBAL APPEND PROPERTY LLVM_LIBCLC_ADDITIONAL_TEST_TARGETS ${remangler-test})
set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_TARGETS ${remangler-test})
endforeach()
endif()
umbrella_lit_testsuite_end(check-libclc)
37 changes: 23 additions & 14 deletions libclc/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,25 @@
from lit.llvm.subst import ToolSubst
from lit.llvm.subst import FindTool


def quote(s):
return f"'{s}'"


# Configuration file for the 'lit' test runner.

if config.libclc_target is None:
lit_config.fatal("libclc_target parameter must be set when running directly")

if config.libclc_target not in config.libclc_targets_to_test:
lit_config.fatal(
f"libclc_target '{config.libclc_target}' is not built. "
f"Available targets: {', '.join(quote(s) for s in config.libclc_targets_to_test)}"
)

# name: The name of this test suite.
config.name = "LIBCLC"
config.name = f"LIBCLC-{config.libclc_target.upper()}"


# testFormat: The test format to use to interpret tests.
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
Expand All @@ -28,16 +43,12 @@

libclc_inc = os.path.join(config.libclc_root, "libspirv", "include")

target = lit_config.params.get("target", "")
builtins = lit_config.params.get("builtins", "")
cpu = lit_config.params.get("cpu", "")
cpu = [] if cpu == "" else ["-mcpu=" + cpu]
libclc_arch_suffix = lit_config.params.get("libclc-arch-suffix", "")

# test_exec_root: The root path where tests should be run. We create a unique
# test directory per libclc target to test to avoid data races when multiple
# targets try and access the the same libclc test files.
config.test_exec_root = os.path.join(config.test_run_dir, "test", libclc_arch_suffix)
config.test_exec_root = os.path.join(
config.libclc_pertarget_test_dir, config.libclc_target
)

llvm_config.use_default_substitutions()

Expand All @@ -46,24 +57,22 @@
"-I",
libclc_inc,
"-target",
target,
config.libclc_target,
"-Xclang",
"-fdeclare-spirv-builtins",
"-Xclang",
"-mlink-builtin-bitcode",
"-Xclang",
os.path.join(config.llvm_libs_dir, "clc", builtins),
os.path.join(config.llvm_libs_dir, "clc", f"libspirv-{config.libclc_target}.bc"),
"-nogpulib",
]

if target == "amdgcn--amdhsa":
config.available_features.add("amdgcn")

if config.libclc_target == "amdgcn--amdhsa":
# libclc for amdgcn is currently built for tahiti which doesn't support
# fp16 so disable the extension for the tests
clang_flags += ["-Xclang", "-cl-ext=-cl_khr_fp16"]

llvm_config.use_clang(additional_flags=clang_flags + cpu)
llvm_config.use_clang(additional_flags=clang_flags)

config.substitutions.append(("%PATH%", config.environment["PATH"]))

Expand Down
14 changes: 13 additions & 1 deletion libclc/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@LIT_SITE_CFG_IN_HEADER@

import os
import sys

config.llvm_src_root = "@LLVM_SOURCE_DIR@"
Expand All @@ -14,10 +15,21 @@ config.target_triple = "@LLVM_TARGET_TRIPLE@"
config.host_arch = "@HOST_ARCH@"
config.python_executable = "@PYTHON_EXECUTABLE@"
config.libclc_root = "@LIBCLC_SOURCE_DIR@"
config.test_run_dir = "@LIBCLC_BINARY_DIR@"
config.libclc_binary_dir = "@LIBCLC_BINARY_DIR@"
config.libclc_targets_to_test = "@LIBCLC_TARGET_TO_TEST@".split(";")
config.libclc_pertarget_test_dir = "@LIBCLC_PERTARGET_TEST_DIR@"

import lit.llvm
lit.llvm.initialize(lit_config, config)

config.libclc_target = lit_config.params.get("libclc_target")

if config.libclc_target is None:
# This file is copied to per-target test directories by cmake,
# use the name of the directory containing this file as the target name.
dirname = os.path.dirname(__file__)
if os.path.realpath(dirname) != os.path.realpath("@CMAKE_CURRENT_BINARY_DIR@"):
config.libclc_target = os.path.basename(dirname)

# Let the main config do the real work.
lit_config.load_config(config, "@LIBCLC_TEST_SOURCE_DIR@/lit.cfg.py")
Loading