Skip to content

Commit b787671

Browse files
committed
Show correct line numbers in generated source lines for common tests
For CUDA/HIP and DPCPP, we create separate copies of the source files using configure_file(...) to apply different CMake file properties to them. For the compiler to report error messages with the correct source file name, this adds a #line preprocessor statement to the top of these generated files.
1 parent 8da182a commit b787671

8 files changed

Lines changed: 26 additions & 7 deletions

File tree

cmake/create_test.cmake

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ function(ginkgo_create_common_device_test test_name)
419419
"${gko_test_multi_args}"
420420
)
421421
ginkgo_build_test_name(${test_name} test_target_name ${ARGN})
422+
# the line number 5 here needs to match the line number that
423+
# /*@GKO_PREPROCESSOR_FILENAME_HELPER@*/ is placed in the source file
424+
set(GKO_PREPROCESSOR_FILENAME_HELPER
425+
"*/\n#line 5 \"${CMAKE_CURRENT_SOURCE_DIR}/${test_name}.cpp\"\n/*"
426+
)
422427
if(
423428
GINKGO_BUILD_SYCL
424429
AND NOT ("dpcpp" IN_LIST common_device_test_DISABLE_EXECUTORS)
@@ -429,7 +434,7 @@ function(ginkgo_create_common_device_test test_name)
429434
PRIVATE ${GINKGO_DPCPP_FLAGS}
430435
)
431436
# We need to use a new file to avoid sycl setting in other backends because add_sycl_to_target will change the source property.
432-
configure_file(${test_name}.cpp ${test_name}.dp.cpp COPYONLY)
437+
configure_file(${test_name}.cpp ${test_name}.dp.cpp @ONLY)
433438
gko_add_sycl_to_target(TARGET ${test_target_name}_dpcpp SOURCES ${test_name}.dp.cpp)
434439
target_link_options(
435440
${test_target_name}_dpcpp
@@ -448,7 +453,7 @@ function(ginkgo_create_common_device_test test_name)
448453
AND NOT ("cuda" IN_LIST common_device_test_DISABLE_EXECUTORS)
449454
)
450455
# need to make a separate file for this, since we can't set conflicting properties on the same file
451-
configure_file(${test_name}.cpp ${test_name}.cu COPYONLY)
456+
configure_file(${test_name}.cpp ${test_name}.cu @ONLY)
452457
ginkgo_create_cuda_test_internal(${test_name}_cuda ${CMAKE_CURRENT_BINARY_DIR}/${test_name}.cu ${test_target_name}_cuda ${ARGN})
453458
target_compile_definitions(
454459
${test_target_name}_cuda
@@ -460,7 +465,7 @@ function(ginkgo_create_common_device_test test_name)
460465
AND NOT ("hip" IN_LIST common_device_test_DISABLE_EXECUTORS)
461466
)
462467
# need to make a separate file for this, since we can't set conflicting properties on the same file
463-
configure_file(${test_name}.cpp ${test_name}.hip.cpp COPYONLY)
468+
configure_file(${test_name}.cpp ${test_name}.hip.cpp @ONLY)
464469
ginkgo_create_hip_test_internal(${test_name}_hip ${CMAKE_CURRENT_BINARY_DIR}/${test_name}.hip.cpp ${test_target_name}_hip ${ARGN})
465470
target_compile_definitions(
466471
${test_target_name}_hip

test/base/index_range.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

5+
/*@GKO_PREPROCESSOR_FILENAME_HELPER@*/
6+
57
#include "core/base/index_range.hpp"
68

79
#include <memory>

test/base/intrinsics.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

5+
/*@GKO_PREPROCESSOR_FILENAME_HELPER@*/
6+
57
#include "core/base/intrinsics.hpp"
68

79
#include <memory>

test/base/iterator_factory.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

5+
/*@GKO_PREPROCESSOR_FILENAME_HELPER@*/
6+
57
#include "core/base/iterator_factory.hpp"
68

79
#include <memory>

test/base/kernel_launch_generic.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

5+
/*@GKO_PREPROCESSOR_FILENAME_HELPER@*/
6+
57
#include <algorithm>
68
#include <memory>
79
#include <type_traits>

test/base/segmented_range.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

5+
/*@GKO_PREPROCESSOR_FILENAME_HELPER@*/
6+
57
#include "core/base/segmented_range.hpp"
68

79
#include <memory>

test/components/range_minimum_query_kernels.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

5+
/*@GKO_PREPROCESSOR_FILENAME_HELPER@*/
6+
57
#include "core/components/range_minimum_query_kernels.hpp"
68

79
#include <limits>

test/matrix/csr_kernels.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

5+
/*@GKO_PREPROCESSOR_FILENAME_HELPER@*/
6+
57
#include "core/matrix/csr_kernels.hpp"
68

79
#include <algorithm>

0 commit comments

Comments
 (0)