Skip to content

Commit

Permalink
[SYCL][CUDA] Fix support of printf for CUDA backend on Windows. (in…
Browse files Browse the repository at this point in the history
…tel#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`
  • Loading branch information
mmoadeli authored May 28, 2024
1 parent 2fc9284 commit 704a2a3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
5 changes: 0 additions & 5 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,6 @@ bool SemaSYCL::isDeclAllowedInSYCLDeviceCode(const Decl *D) {
FD->getBuiltinID() == Builtin::BI__builtin_printf))
return true;

// Allow to use `::printf` only for CUDA.
if (getASTContext().getTargetInfo().getTriple().isNVPTX()) {
if (FD->getBuiltinID() == Builtin::BIprintf)
return true;
}
const DeclContext *DC = FD->getDeclContext();
if (II && II->isStr("__spirv_ocl_printf") &&
!FD->isDefined() &&
Expand Down
8 changes: 6 additions & 2 deletions clang/test/CodeGenSYCL/Inputs/sycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,15 @@ namespace experimental {
#endif
template <typename... Args>
int printf(const __SYCL_CONSTANT_AS char *__format, Args... args) {
#if defined(__SYCL_DEVICE_ONLY__) && defined(__SPIR__)
#if defined(__SYCL_DEVICE_ONLY__)
#if (defined(__SPIR__) || defined(__SPIRV__))
return __spirv_ocl_printf(__format, args...);
#else
return __builtin_printf(__format, args...);
#endif // (defined(__SPIR__) || defined(__SPIRV__))
#else
return ::printf(__format, args...);
#endif // defined(__SYCL_DEVICE_ONLY__) && defined(__SPIR__)
#endif // defined(__SYCL_DEVICE_ONLY__)
}

template <typename T, typename... Props>
Expand Down
6 changes: 5 additions & 1 deletion sycl/include/sycl/ext/oneapi/experimental/builtins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ namespace ext::oneapi::experimental {
//
template <typename FormatT, typename... Args>
int printf(const FormatT *__format, Args... args) {
#if defined(__SYCL_DEVICE_ONLY__) && (defined(__SPIR__) || defined(__SPIRV__))
#if defined(__SYCL_DEVICE_ONLY__)
#if (defined(__SPIR__) || defined(__SPIRV__))
return __spirv_ocl_printf(__format, args...);
#else
return __builtin_printf(__format, args...);
#endif
#else
return ::printf(__format, args...);
#endif // defined(__SYCL_DEVICE_ONLY__) && (defined(__SPIR__) ||
Expand Down

0 comments on commit 704a2a3

Please sign in to comment.