https://github.com/frasercrmck updated https://github.com/llvm/llvm-project/pull/87989
>From c53dc3564822f305d09d19dc3b7327b33028fe11 Mon Sep 17 00:00:00 2001 From: Fraser Cormack <fra...@codeplay.com> Date: Thu, 4 Apr 2024 17:49:13 +0100 Subject: [PATCH] [libclc] Add initial LIT tests --- libclc/CMakeLists.txt | 4 +++ libclc/test/CMakeLists.txt | 38 +++++++++++++++++++++++ libclc/test/add_sat.cl | 3 ++ libclc/test/as_type.cl | 5 ++- libclc/test/convert.cl | 5 ++- libclc/test/cos.cl | 5 ++- libclc/test/cross.cl | 5 ++- libclc/test/fabs.cl | 5 ++- libclc/test/get_group_id.cl | 5 ++- libclc/test/lit.cfg.py | 57 ++++++++++++++++++++++++++++++++++ libclc/test/lit.site.cfg.py.in | 24 ++++++++++++++ libclc/test/rsqrt.cl | 8 +++-- libclc/test/subsat.cl | 11 ++++--- 13 files changed, 163 insertions(+), 12 deletions(-) create mode 100644 libclc/test/CMakeLists.txt create mode 100644 libclc/test/lit.cfg.py create mode 100644 libclc/test/lit.site.cfg.py.in diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 7528228b3b7f9b..ca5e5d1d1755d2 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -411,3 +411,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) endif() endforeach( d ) endforeach( t ) + +if( NOT LIBCLC_STANDALONE_BUILD ) + add_subdirectory( test ) +endif() diff --git a/libclc/test/CMakeLists.txt b/libclc/test/CMakeLists.txt new file mode 100644 index 00000000000000..796b6a0e1e8544 --- /dev/null +++ b/libclc/test/CMakeLists.txt @@ -0,0 +1,38 @@ +set(LIBCLC_TEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + +configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py + MAIN_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py +) + +list(APPEND LIBCLC_TEST_DEPS + libclc::clang + FileCheck count not +) + +add_custom_target(check-libclc) + +foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) + foreach( d ${${t}_devices} ) + + get_libclc_device_info( + TRIPLE ${t} + DEVICE ${d} + CPU cpu + ARCH_SUFFIX arch_suffix + CLANG_TRIPLE clang_triple + ) + + add_lit_testsuite(check-libclc-${arch_suffix} + "Running libclc ${arch_suffix} regression tests" + ${CMAKE_CURRENT_BINARY_DIR} + PARAMS "target=${clang_triple}" cpu=${cpu} "builtins=${arch_suffix}.bc" + DEPENDS prepare-${arch_suffix}.bc ${LIBCLC_TEST_DEPS} + ) + + add_dependencies( check-libclc check-libclc-${arch_suffix} ) + + endforeach() +endforeach() diff --git a/libclc/test/add_sat.cl b/libclc/test/add_sat.cl index 45c8567b440397..f23a105ac83386 100644 --- a/libclc/test/add_sat.cl +++ b/libclc/test/add_sat.cl @@ -1,3 +1,6 @@ +// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s + +// CHECK: foo __kernel void foo(__global char *a, __global char *b, __global char *c) { *a = add_sat(*b, *c); } diff --git a/libclc/test/as_type.cl b/libclc/test/as_type.cl index e8fb1228d28d11..729303a53da051 100644 --- a/libclc/test/as_type.cl +++ b/libclc/test/as_type.cl @@ -1,3 +1,6 @@ -__kernel void foo(int4 *x, float4 *y) { +// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s + +// CHECK: foo +__kernel void foo(__global int4 *x, __global float4 *y) { *x = as_int4(*y); } diff --git a/libclc/test/convert.cl b/libclc/test/convert.cl index 928fc326b6a18f..9ea5b192769a26 100644 --- a/libclc/test/convert.cl +++ b/libclc/test/convert.cl @@ -1,3 +1,6 @@ -__kernel void foo(int4 *x, float4 *y) { +// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s + +// CHECK: foo +__kernel void foo(__global int4 *x, __global float4 *y) { *x = convert_int4(*y); } diff --git a/libclc/test/cos.cl b/libclc/test/cos.cl index 4230eb2a0e93c6..21384ba1d73dfd 100644 --- a/libclc/test/cos.cl +++ b/libclc/test/cos.cl @@ -1,3 +1,6 @@ -__kernel void foo(float4 *f) { +// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s + +// CHECK: foo +__kernel void foo(__global float4 *f) { *f = cos(*f); } diff --git a/libclc/test/cross.cl b/libclc/test/cross.cl index 08955cbd9af568..c628a6656c5739 100644 --- a/libclc/test/cross.cl +++ b/libclc/test/cross.cl @@ -1,3 +1,6 @@ -__kernel void foo(float4 *f) { +// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s + +// CHECK: foo +__kernel void foo(__global float4 *f) { *f = cross(f[0], f[1]); } diff --git a/libclc/test/fabs.cl b/libclc/test/fabs.cl index 91d42c466676fd..27881304224567 100644 --- a/libclc/test/fabs.cl +++ b/libclc/test/fabs.cl @@ -1,3 +1,6 @@ -__kernel void foo(float *f) { +// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s + +// CHECK: foo +__kernel void foo(__global float *f) { *f = fabs(*f); } diff --git a/libclc/test/get_group_id.cl b/libclc/test/get_group_id.cl index 43725cda802710..cd4d114b59ed16 100644 --- a/libclc/test/get_group_id.cl +++ b/libclc/test/get_group_id.cl @@ -1,3 +1,6 @@ -__kernel void foo(int *i) { +// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s + +// CHECK: foo +__kernel void foo(__global int *i) { i[get_group_id(0)] = 1; } diff --git a/libclc/test/lit.cfg.py b/libclc/test/lit.cfg.py new file mode 100644 index 00000000000000..059a49bed2fbd2 --- /dev/null +++ b/libclc/test/lit.cfg.py @@ -0,0 +1,57 @@ +import os + +import lit.formats +import lit.util + +from lit.llvm import llvm_config +from lit.llvm.subst import ToolSubst +from lit.llvm.subst import FindTool + +# Configuration file for the 'lit' test runner. + +# name: The name of this test suite. +config.name = "libclc" + +# testFormat: The test format to use to interpret tests. +config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) + +# suffixes: A list of file extensions to treat as test files. +config.suffixes = [ + ".cl", +] + +# test_source_root: The root path where tests are located. +config.test_source_root = os.path.join(os.path.dirname(__file__)) + +# test_exec_root: The root path where tests should be run. +config.test_exec_root = os.path.join(config.test_run_dir, "test") + +llvm_config.use_default_substitutions() + +target = lit_config.params.get("target", "") +builtins = lit_config.params.get("builtins", "") + +clang_flags = [ + "-fno-builtin", + "-target", + target, + "-Xclang", + "-mlink-builtin-bitcode", + "-Xclang", + os.path.join(config.libclc_lib_dir, builtins), + "-nogpulib", +] + +cpu = lit_config.params.get("cpu", "") +if cpu: + clang_flags.append(f"-mcpu={cpu}") + +llvm_config.use_clang(additional_flags=clang_flags) + +tools = [ + "llvm-dis", + "not", +] +tool_dirs = [config.llvm_tools_dir] + +llvm_config.add_tool_substitutions(tools, tool_dirs) diff --git a/libclc/test/lit.site.cfg.py.in b/libclc/test/lit.site.cfg.py.in new file mode 100644 index 00000000000000..b507ef5aaa240d --- /dev/null +++ b/libclc/test/lit.site.cfg.py.in @@ -0,0 +1,24 @@ +@LIT_SITE_CFG_IN_HEADER@ + +import sys + +config.llvm_src_root = path(r"@LLVM_SOURCE_DIR@") +config.llvm_obj_root = path(r"@LLVM_BINARY_DIR@") +config.llvm_tools_dir = lit_config.substitute(path(r"@LLVM_TOOLS_DIR@")) +config.llvm_libs_dir = lit_config.substitute(path(r"@LLVM_LIBS_DIR@")) +config.llvm_shlib_dir = lit_config.substitute(path(r"@SHLIBDIR@")) +config.lit_tools_dir = path(r"@LLVM_LIT_TOOLS_DIR@") +config.host_triple = "@LLVM_HOST_TRIPLE@" +config.target_triple = "@LLVM_TARGET_TRIPLE@" +config.host_arch = "@HOST_ARCH@" +config.python_executable = "@Python3_EXECUTABLE@" +config.libclc_src_dir = path(r"@LIBCLC_SOURCE_DIR@") +config.libclc_lib_dir = path(r"@LIBCLC_BINARY_DIR@") +config.test_run_dir = path(r"@LIBCLC_BINARY_DIR@") + +import lit.llvm +lit.llvm.initialize(lit_config, config) + +# Let the main config do the real work. +lit_config.load_config( + config, os.path.join(config.libclc_src_dir, "test/lit.cfg.py")) diff --git a/libclc/test/rsqrt.cl b/libclc/test/rsqrt.cl index 13ad216b79f4bf..89bd903feecc91 100644 --- a/libclc/test/rsqrt.cl +++ b/libclc/test/rsqrt.cl @@ -1,6 +1,10 @@ -#pragma OPENCL EXTENSION cl_khr_fp64 : enable +// RUN: %clang -emit-llvm -S %s -__kernel void foo(float4 *x, double4 *y) { +#if defined(cl_khr_fp64) + +__kernel void foo(__global float4 *x, __global double4 *y) { x[1] = rsqrt(x[0]); y[1] = rsqrt(y[0]); } + +#endif diff --git a/libclc/test/subsat.cl b/libclc/test/subsat.cl index a83414b4dc850c..ec808e7556d26e 100644 --- a/libclc/test/subsat.cl +++ b/libclc/test/subsat.cl @@ -1,19 +1,22 @@ -__kernel void test_subsat_char(char *a, char x, char y) { +// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s + +// CHECK: test_subsat_char +__kernel void test_subsat_char(__global char *a, char x, char y) { *a = sub_sat(x, y); return; } -__kernel void test_subsat_uchar(uchar *a, uchar x, uchar y) { +__kernel void test_subsat_uchar(__global uchar *a, uchar x, uchar y) { *a = sub_sat(x, y); return; } -__kernel void test_subsat_long(long *a, long x, long y) { +__kernel void test_subsat_long(__global long *a, long x, long y) { *a = sub_sat(x, y); return; } -__kernel void test_subsat_ulong(ulong *a, ulong x, ulong y) { +__kernel void test_subsat_ulong(__global ulong *a, ulong x, ulong y) { *a = sub_sat(x, y); return; } \ No newline at end of file _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits