Skip to content

Commit 7f3801b

Browse files
authored
Added tests to verify that devicelib APIs have no 'noinline' attribute. (#2847)
Device compilers may (and should) honor 'noinline' attribute even when optimizations are turned on. At the same time, we do not want to prevent inlining of devicelib wrappers and fallback implementations, since this may result in degraded performance. These tests verify that the devicelib APIs are not marked with 'noinline' attribute. Signed-off-by: Vyacheslav Zakharin <[email protected]>
1 parent c825791 commit 7f3801b

File tree

6 files changed

+277
-0
lines changed

6 files changed

+277
-0
lines changed

libdevice/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ set(CMAKE_MODULE_PATH
88

99
# Build libdevice for SYCL.
1010
include(SYCLLibdevice)
11+
12+
set(LIBDEVICE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
13+
set(LIBDEVICE_LIBRARY_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
14+
set(LIBDEVICE_RUNTIME_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
15+
set(LIBDEVICE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
16+
17+
add_subdirectory(test)

libdevice/test/CMakeLists.txt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
set(LIBDEVICE_TEST_DEPENDS
2+
FileCheck
3+
clang-offload-bundler
4+
count
5+
llvm-dis
6+
llvm-spirv
7+
not
8+
)
9+
10+
# Enable new IN_LIST operator.
11+
cmake_policy(SET CMP0057 NEW)
12+
if (libdevice IN_LIST LLVM_ENABLE_PROJECTS AND
13+
(sycl IN_LIST LLVM_ENABLE_PROJECTS OR
14+
sycl IN_LIST LLVM_EXTERNAL_PROJECTS))
15+
set(LLVM_HAS_LIBSYCLDEVICE TRUE)
16+
list(APPEND LIBDEVICE_TEST_DEPENDS libsycldevice)
17+
endif()
18+
19+
llvm_canonicalize_cmake_booleans(
20+
LLVM_HAS_LIBSYCLDEVICE
21+
)
22+
23+
configure_lit_site_cfg(
24+
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
25+
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
26+
MAIN_CONFIG
27+
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
28+
PATHS
29+
"CLANG_TOOLS_DIR"
30+
"CMAKE_CURRENT_SOURCE_DIR"
31+
"LIBDEVICE_SOURCE_DIR"
32+
"LIBDEVICE_BINARY_DIR"
33+
"LIBDEVICE_LIBRARY_DIR"
34+
"LIBDEVICE_RUNTIME_DIR"
35+
"LLVM_TOOLS_DIR"
36+
)
37+
38+
add_custom_target(libdevice-test-depends DEPENDS ${LIBDEVICE_TEST_DEPENDS})
39+
set_target_properties(libdevice-test-depends PROPERTIES FOLDER "Tests")
40+
41+
if(LLVM_BUILD_TOOLS AND
42+
LLVM_HAS_LIBSYCLDEVICE)
43+
set(exclude_from_check_all "")
44+
else()
45+
set(exclude_from_check_all "EXCLUDE_FROM_CHECK_ALL")
46+
endif()
47+
48+
add_lit_testsuite(check-libdevice "Running the libdevice regression tests"
49+
${CMAKE_CURRENT_BINARY_DIR}
50+
${exclude_from_check_all}
51+
DEPENDS ${LIBDEVICE_TEST_DEPENDS}
52+
)
53+
set_target_properties(check-libdevice PROPERTIES FOLDER "Tests")

libdevice/test/lit.cfg.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- Python -*-
2+
3+
# Configuration file for the 'lit' test runner.
4+
import os
5+
import sys
6+
7+
import lit.util
8+
import lit.formats
9+
from lit.llvm import llvm_config
10+
from lit.llvm.subst import FindTool
11+
from lit.llvm.subst import ToolSubst
12+
13+
# name: The name of this test suite.
14+
config.name = 'libdevice'
15+
16+
# suffixes: A list of file extensions to treat as test files.
17+
config.suffixes = ['.txt']
18+
19+
# excludes: A list of directories to exclude from the testsuite.
20+
config.excludes = ['CMakeLists.txt']
21+
22+
# test_source_root: The root path where tests are located.
23+
config.test_source_root = os.path.dirname(__file__)
24+
25+
# test_exec_root: The root path where tests should be run.
26+
config.test_exec_root = os.path.join(config.libdevice_binary_dir, 'test')
27+
28+
# testFormat: The test format to use to interpret tests.
29+
config.test_format = lit.formats.ShTest()
30+
31+
llvm_config.use_default_substitutions()
32+
33+
tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir]
34+
35+
tools = [
36+
'clang-offload-bundler', 'llvm-dis', 'llvm-spirv'
37+
]
38+
39+
llvm_config.add_tool_substitutions(tools, tool_dirs)
40+
41+
if config.has_libsycldevice:
42+
config.available_features.add("libsycldevice");
43+
config.substitutions.append(
44+
('%libsycldevice_obj_dir', config.libdevice_library_dir))
45+
if sys.platform in ['win32']:
46+
config.substitutions.append(
47+
('%libsycldevice_spv_dir', config.libdevice_runtime_dir))
48+
else:
49+
config.substitutions.append(
50+
('%libsycldevice_spv_dir', config.libdevice_library_dir))

libdevice/test/lit.site.cfg.py.in

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@LIT_SITE_CFG_IN_HEADER@
2+
@AUTO_GEN_COMMENT@
3+
4+
config.llvm_tools_dir = path(r"@LLVM_TOOLS_DIR@")
5+
config.clang_tools_dir = path(r"@CLANG_TOOLS_DIR@")
6+
config.libdevice_src_dir = path(r"@LIBDEVICE_SOURCE_DIR@")
7+
config.libdevice_binary_dir = path(r"@LIBDEVICE_BINARY_DIR@")
8+
config.libdevice_library_dir = path(r"@LIBDEVICE_LIBRARY_DIR@")
9+
config.libdevice_runtime_dir = path(r"@LIBDEVICE_RUNTIME_DIR@")
10+
config.has_libsycldevice = "@LLVM_HAS_LIBSYCLDEVICE@"
11+
12+
import sys
13+
14+
import lit.llvm
15+
lit.llvm.initialize(lit_config, config)
16+
17+
# Let the main config do the real work.
18+
lit_config.load_config(
19+
config, os.path.join(path(r"@CMAKE_CURRENT_SOURCE_DIR@"), "lit.cfg.py"))

libdevice/test/sycl_noinline.txt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
UNSUPPORTED: system-windows
2+
REQUIRES: libsycldevice
3+
4+
Verify that the wrapper functions and the fallback functions are not marked
5+
with noinline attribute.
6+
7+
RUN: llvm-spirv -r %libsycldevice_spv_dir/libsycl-fallback-cassert.spv -o %t.bc
8+
RUN: llvm-dis %t.bc -o - | FileCheck %s
9+
10+
RUN: llvm-spirv -r %libsycldevice_spv_dir/libsycl-fallback-cmath.spv -o %t.bc
11+
RUN: llvm-dis %t.bc -o - | FileCheck %s
12+
13+
RUN: llvm-spirv -r %libsycldevice_spv_dir/libsycl-fallback-cmath-fp64.spv -o %t.bc
14+
RUN: llvm-dis %t.bc -o - | FileCheck %s
15+
16+
RUN: llvm-spirv -r %libsycldevice_spv_dir/libsycl-fallback-complex.spv -o %t.bc
17+
RUN: llvm-dis %t.bc -o - | FileCheck %s
18+
19+
RUN: llvm-spirv -r %libsycldevice_spv_dir/libsycl-fallback-complex-fp64.spv -o %t.bc
20+
RUN: llvm-dis %t.bc -o - | FileCheck %s
21+
22+
RUN: clang-offload-bundler -type=o -unbundle \
23+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
24+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-fallback-cassert.o -outputs=%t.bc
25+
RUN: llvm-dis %t.bc -o - | FileCheck %s
26+
27+
RUN: clang-offload-bundler -type=o -unbundle \
28+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
29+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-fallback-cmath.o -outputs=%t.bc
30+
RUN: llvm-dis %t.bc -o - | FileCheck %s
31+
32+
RUN: clang-offload-bundler -type=o -unbundle \
33+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
34+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-fallback-cmath-fp64.o -outputs=%t.bc
35+
RUN: llvm-dis %t.bc -o - | FileCheck %s
36+
37+
RUN: clang-offload-bundler -type=o -unbundle \
38+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
39+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-fallback-complex.o -outputs=%t.bc
40+
RUN: llvm-dis %t.bc -o - | FileCheck %s
41+
42+
RUN: clang-offload-bundler -type=o -unbundle \
43+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
44+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-fallback-complex-fp64.o -outputs=%t.bc
45+
RUN: llvm-dis %t.bc -o - | FileCheck %s
46+
47+
RUN: clang-offload-bundler -type=o -unbundle \
48+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
49+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-crt.o -outputs=%t.bc
50+
RUN: llvm-dis %t.bc -o - | FileCheck %s
51+
52+
RUN: clang-offload-bundler -type=o -unbundle \
53+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
54+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-cmath.o -outputs=%t.bc
55+
RUN: llvm-dis %t.bc -o - | FileCheck %s
56+
57+
RUN: clang-offload-bundler -type=o -unbundle \
58+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
59+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-cmath-fp64.o -outputs=%t.bc
60+
RUN: llvm-dis %t.bc -o - | FileCheck %s
61+
62+
RUN: clang-offload-bundler -type=o -unbundle \
63+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
64+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-complex.o -outputs=%t.bc
65+
RUN: llvm-dis %t.bc -o - | FileCheck %s
66+
67+
RUN: clang-offload-bundler -type=o -unbundle \
68+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
69+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-complex-fp64.o -outputs=%t.bc
70+
RUN: llvm-dis %t.bc -o - | FileCheck %s
71+
72+
CHECK: target triple ={{.*}}spir64
73+
CHECK-NOT: ; Function Attrs:{{.*}}noinline
74+
CHECK-NOT: attributes #{{[0-9]+}} ={{.*}}noinline

libdevice/test/sycl_noinline_win.txt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
REQUIRES: system-windows
2+
REQUIRES: libsycldevice
3+
4+
Verify that the wrapper functions and the fallback functions are not marked
5+
with noinline attribute.
6+
7+
RUN: llvm-spirv -r %libsycldevice_spv_dir/libsycl-fallback-cassert.spv -o %t.bc
8+
RUN: llvm-dis %t.bc -o - | FileCheck %s
9+
10+
RUN: llvm-spirv -r %libsycldevice_spv_dir/libsycl-fallback-cmath.spv -o %t.bc
11+
RUN: llvm-dis %t.bc -o - | FileCheck %s
12+
13+
RUN: llvm-spirv -r %libsycldevice_spv_dir/libsycl-fallback-cmath-fp64.spv -o %t.bc
14+
RUN: llvm-dis %t.bc -o - | FileCheck %s
15+
16+
RUN: llvm-spirv -r %libsycldevice_spv_dir/libsycl-fallback-complex.spv -o %t.bc
17+
RUN: llvm-dis %t.bc -o - | FileCheck %s
18+
19+
RUN: llvm-spirv -r %libsycldevice_spv_dir/libsycl-fallback-complex-fp64.spv -o %t.bc
20+
RUN: llvm-dis %t.bc -o - | FileCheck %s
21+
22+
RUN: clang-offload-bundler -type=o -unbundle \
23+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
24+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-fallback-cassert.obj -outputs=%t.bc
25+
RUN: llvm-dis %t.bc -o - | FileCheck %s
26+
27+
RUN: clang-offload-bundler -type=o -unbundle \
28+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
29+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-fallback-cmath.obj -outputs=%t.bc
30+
RUN: llvm-dis %t.bc -o - | FileCheck %s
31+
32+
RUN: clang-offload-bundler -type=o -unbundle \
33+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
34+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-fallback-cmath-fp64.obj -outputs=%t.bc
35+
RUN: llvm-dis %t.bc -o - | FileCheck %s
36+
37+
RUN: clang-offload-bundler -type=o -unbundle \
38+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
39+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-fallback-complex.obj -outputs=%t.bc
40+
RUN: llvm-dis %t.bc -o - | FileCheck %s
41+
42+
RUN: clang-offload-bundler -type=o -unbundle \
43+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
44+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-fallback-complex-fp64.obj -outputs=%t.bc
45+
RUN: llvm-dis %t.bc -o - | FileCheck %s
46+
47+
RUN: clang-offload-bundler -type=o -unbundle \
48+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
49+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-crt.obj -outputs=%t.bc
50+
RUN: llvm-dis %t.bc -o - | FileCheck %s
51+
52+
RUN: clang-offload-bundler -type=o -unbundle \
53+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
54+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-cmath.obj -outputs=%t.bc
55+
RUN: llvm-dis %t.bc -o - | FileCheck %s
56+
57+
RUN: clang-offload-bundler -type=o -unbundle \
58+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
59+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-cmath-fp64.obj -outputs=%t.bc
60+
RUN: llvm-dis %t.bc -o - | FileCheck %s
61+
62+
RUN: clang-offload-bundler -type=o -unbundle \
63+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
64+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-complex.obj -outputs=%t.bc
65+
RUN: llvm-dis %t.bc -o - | FileCheck %s
66+
67+
RUN: clang-offload-bundler -type=o -unbundle \
68+
RUN: -targets=sycl-spir64-unknown-unknown-sycldevice \
69+
RUN: -inputs=%libsycldevice_obj_dir/libsycl-complex-fp64.obj -outputs=%t.bc
70+
RUN: llvm-dis %t.bc -o - | FileCheck %s
71+
72+
CHECK: target triple ={{.*}}spir64
73+
CHECK-NOT: ; Function Attrs:{{.*}}noinline
74+
CHECK-NOT: attributes #{{[0-9]+}} ={{.*}}noinline

0 commit comments

Comments
 (0)