Skip to content

Commit 704a2a3

Browse files
authored
[SYCL][CUDA] Fix support of printf for CUDA backend on Windows. (#13784)
- Addresses a build error seen when using `printf` for CUDA backend on Windows. - The mentioned build error can be seen in [test-e2e/Basic/built-ins.cpp](https://github.com/mmoadeli/llvm/blob/sycl/sycl/test-e2e/Basic/built-ins.cpp) - Remove dead code as `printf` in SYCL cuda /amd device code calls `__builtin_printf`
1 parent 2fc9284 commit 704a2a3

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,6 @@ bool SemaSYCL::isDeclAllowedInSYCLDeviceCode(const Decl *D) {
383383
FD->getBuiltinID() == Builtin::BI__builtin_printf))
384384
return true;
385385

386-
// Allow to use `::printf` only for CUDA.
387-
if (getASTContext().getTargetInfo().getTriple().isNVPTX()) {
388-
if (FD->getBuiltinID() == Builtin::BIprintf)
389-
return true;
390-
}
391386
const DeclContext *DC = FD->getDeclContext();
392387
if (II && II->isStr("__spirv_ocl_printf") &&
393388
!FD->isDefined() &&

clang/test/CodeGenSYCL/Inputs/sycl.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,15 @@ namespace experimental {
473473
#endif
474474
template <typename... Args>
475475
int printf(const __SYCL_CONSTANT_AS char *__format, Args... args) {
476-
#if defined(__SYCL_DEVICE_ONLY__) && defined(__SPIR__)
476+
#if defined(__SYCL_DEVICE_ONLY__)
477+
#if (defined(__SPIR__) || defined(__SPIRV__))
477478
return __spirv_ocl_printf(__format, args...);
479+
#else
480+
return __builtin_printf(__format, args...);
481+
#endif // (defined(__SPIR__) || defined(__SPIRV__))
478482
#else
479483
return ::printf(__format, args...);
480-
#endif // defined(__SYCL_DEVICE_ONLY__) && defined(__SPIR__)
484+
#endif // defined(__SYCL_DEVICE_ONLY__)
481485
}
482486

483487
template <typename T, typename... Props>

sycl/include/sycl/ext/oneapi/experimental/builtins.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ namespace ext::oneapi::experimental {
7777
//
7878
template <typename FormatT, typename... Args>
7979
int printf(const FormatT *__format, Args... args) {
80-
#if defined(__SYCL_DEVICE_ONLY__) && (defined(__SPIR__) || defined(__SPIRV__))
80+
#if defined(__SYCL_DEVICE_ONLY__)
81+
#if (defined(__SPIR__) || defined(__SPIRV__))
8182
return __spirv_ocl_printf(__format, args...);
83+
#else
84+
return __builtin_printf(__format, args...);
85+
#endif
8286
#else
8387
return ::printf(__format, args...);
8488
#endif // defined(__SYCL_DEVICE_ONLY__) && (defined(__SPIR__) ||

0 commit comments

Comments
 (0)