Skip to content

Commit 3fd1c07

Browse files
committed
[SYCL] Improve SYCL library versioning macro
We have a macro `__SYCL_COMPILER_VERSION` which only corresponds to a date when build was performed - it does not give any indication of the actual compiler version, nor does it give any indication of the actual library build. This patch attempts to deprecate that old macro and replaces it with `__LIBSYCL_TIMESTAMP` which contains a date of the latest commit included into the SYCL library (and therefore SYCL headers) build. Using commit date is more relibable than build date and its naming speicifally refers to library instead of the compiler. "Attempts" above is because it is a bit tricky to deprecate a macro and heavily depends on the compiler which is being used. Not every 3rd-party host compiler is covered, i.e. deprecation message may only be emitted from device compilation pass in certain cases. Resolves #2250
1 parent 023cb2b commit 3fd1c07

File tree

7 files changed

+84
-4
lines changed

7 files changed

+84
-4
lines changed

sycl/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,9 @@ set(SYCL_EXT_ONEAPI_BACKEND_CUDA ${LLVM_HAS_NVPTX_TARGET})
188188
set(SYCL_EXT_ONEAPI_BACKEND_HIP ${LLVM_HAS_AMDGPU_TARGET})
189189

190190
# Configure SYCL version macro
191-
set(sycl_inc_dir ${CMAKE_CURRENT_SOURCE_DIR}/include)
191+
set(SYCL_ROOT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
192192
set(sycl_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/source)
193-
string(TIMESTAMP __SYCL_COMPILER_VERSION "%Y%m%d")
194-
configure_file("source/version.hpp.in" "${SYCL_INCLUDE_BUILD_DIR}/sycl/version.hpp")
193+
include(SYCLVersionFromVCS)
195194
configure_file("source/feature_test.hpp.in" "${SYCL_INCLUDE_BUILD_DIR}/sycl/feature_test.hpp")
196195

197196
# Generate device_aspect_macros.hpp
@@ -217,6 +216,7 @@ install(FILES
217216
include(AddBoostMp11Headers)
218217
include(FetchBoostUnorderedHeaders)
219218

219+
set(sycl_inc_dir ${CMAKE_CURRENT_SOURCE_DIR}/include)
220220
# This is workaround to detect changes (add or modify) in subtree which
221221
# are not detected by copy_directory command.
222222
# TODO: detect and process remove header/directory case
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
# Grab the date of the latest commit
3+
execute_process(
4+
COMMAND git log -1 --format=%as # date in YYYY-MM-DD mode
5+
WORKING_DIRECTORY ${SYCL_ROOT_SOURCE_DIR}
6+
OUTPUT_VARIABLE GIT_COMMIT_DATE_TEMP
7+
OUTPUT_STRIP_TRAILING_WHITESPACE
8+
)
9+
10+
string(REPLACE "-" "" __LIBSYCL_TIMESTAMP ${GIT_COMMIT_DATE_TEMP})
11+
12+
# Legacy thing for backwards compatibility. Use of the current date is not
13+
# reliable, because we can always make new build from older commits.
14+
string(TIMESTAMP __SYCL_COMPILER_VERSION "%Y%m%d")
15+
configure_file("${sycl_src_dir}/version.hpp.in" "${SYCL_INCLUDE_BUILD_DIR}/sycl/version.hpp")

sycl/doc/PreprocessorMacros.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ This file describes macros that have effect on SYCL compiler and run-time.
5757

5858
## Version macros
5959

60+
- `__LIBSYCL_TIMESTAMP` is set to an integer literal which corresponds to a date
61+
when the latest commit into `sycl/` subproject was done. It could be used
62+
to distinguish between different library builds (which includes SYCL headers)
63+
to workaround any bugs, or API/ABI-breaking changes. The format is `YYYYMMDD`.
64+
6065
- `__LIBSYCL_MAJOR_VERSION` is set to SYCL runtime library major version.
6166
- `__LIBSYCL_MINOR_VERSION` is set to SYCL runtime library minor version.
6267
- `__LIBSYCL_PATCH_VERSION` is set to SYCL runtime library patch version.

sycl/source/version.hpp.in

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
1-
//==------ version.hpp --- SYCL compiler version macro ---------*- C++ -*---==//
1+
//==------- version.hpp --- SYCL library version macro ---------*- C++ -*---==//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// __SYCL_COMPILER_VERSION is a legacy macro which does not represent a compiler
10+
// version, but instead only conveys a date when sycl library was built.
11+
12+
#if /* defined(__GNUC__) || */ defined(__clang__)
13+
// clang supports GCC-style pragma messages, but GCC does not!
14+
// include/sycl/version.hpp error: missing binary operator before token "("
15+
// 14 | #define __SYCL_COMPILER_VERSION _Pragma("GCC warning \"..\"") 20241120
16+
17+
#cmakedefine __SYCL_COMPILER_VERSION _Pragma( \
18+
"GCC warning \"__SYCL_COMPILER_VERSION is deprecated, " \
19+
"use __LIBSYCL_TIMESTAMP instead\"") ${__SYCL_COMPILER_VERSION}
20+
#elif defined(_MSC_VER)
21+
#cmakedefine __SYCL_COMPILER_VERSION ${__SYCL_COMPILER_VERSION}
22+
// It seems like MSVC ignores that pragma if its embedded into a macro
23+
// definition, so we have it on a standalone line
24+
_Pragma("deprecated(\"__SYCL_COMPILER_VERSION\")")
25+
#else
26+
// As a fallback, we still define the macro, but without a deprecation warning.
27+
// This path is only expected to be taken when 3rd-party host compiler is used
28+
// and that is not clang/msvc
929
#cmakedefine __SYCL_COMPILER_VERSION ${__SYCL_COMPILER_VERSION}
30+
#endif
31+
32+
#cmakedefine __LIBSYCL_TIMESTAMP ${__LIBSYCL_TIMESTAMP}
33+
1034
#define __LIBSYCL_MAJOR_VERSION ${SYCL_MAJOR_VERSION}
1135
#define __LIBSYCL_MINOR_VERSION ${SYCL_MINOR_VERSION}
1236
#define __LIBSYCL_PATCH_VERSION ${SYCL_PATCH_VERSION}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clangxx -fsycl -fsycl-host-compiler=cl %s \
2+
// RUN: -fsycl-host-compiler-options="/std:c++17 /Zc:__cplusplus" -c \
3+
// RUN: -o %t.out | FileCheck %s
4+
// REQUIRES: windows
5+
6+
#include <sycl/sycl.hpp>
7+
8+
// CHECK: '__SYCL_COMPILER_VERSION': name was marked as #pragma deprecated
9+
#if __SYCL_COMPILER_VERSION >= 2024
10+
11+
#endif
12+
13+
int main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clangxx -fsycl %s -fsyntax-only -Xclang -verify
2+
3+
#include <sycl/sycl.hpp>
4+
5+
// expected-warning@+1 {{__SYCL_COMPILER_VERSION is deprecated, use __LIBSYCL_TIMESTAMP instead}}
6+
#if __SYCL_COMPILER_VERSION >= 2024
7+
8+
#endif
9+
10+
int main() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clangxx -fsycl -fsycl-host-compiler=g++ %s -c %t.out | FileCheck %s
2+
// XFAIL: *
3+
// XFAIL-TRACKER: TBD
4+
// REQUIRES: linux
5+
6+
#include <sycl/sycl.hpp>
7+
8+
// CHECK: __SYCL_COMPILER_VERSION is deprecated, use __LIBSYCL_TIMESTAMP instead
9+
#if __SYCL_COMPILER_VERSION >= 2024
10+
11+
#endif
12+
13+
int main() {}

0 commit comments

Comments
 (0)