Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions clang/lib/Sema/SPIRVBuiltins.td
Original file line number Diff line number Diff line change
Expand Up @@ -722,12 +722,6 @@ foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {

// 2.8. Misc instructions

let IsVariadic = 1 in {
foreach name = ["printf"] in {
def : OCLSPVBuiltin<name, [Int, PointerType<ConstType<TrueChar>, ConstantAS>]>;
}
}

foreach name = ["prefetch"] in {
def : OCLSPVBuiltin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
}
Expand Down
10 changes: 10 additions & 0 deletions sycl/include/CL/__spirv/spirv_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,16 @@ extern SYCL_EXTERNAL float __spirv_ConvertBF16ToFINTEL(uint16_t) noexcept;
__SYCL_CONVERGENT__ extern SYCL_EXTERNAL __SYCL_EXPORT __ocl_vec_t<uint32_t, 4>
__spirv_GroupNonUniformBallot(uint32_t Execution, bool Predicate) noexcept;

#ifdef __SYCL_USE_NON_VARIADIC_SPIRV_OCL_PRINTF__
template <typename... Args>
extern SYCL_EXTERNAL int
__spirv_ocl_printf(const __attribute__((opencl_constant)) char *Format,
Args... args);
#else
extern SYCL_EXTERNAL int
__spirv_ocl_printf(const __attribute__((opencl_constant)) char *Format, ...);
#endif

#else // if !__SYCL_DEVICE_ONLY__

template <typename dataT>
Expand Down
40 changes: 40 additions & 0 deletions sycl/test/extensions/experimental-printf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// This test is intended to check that internal
// __SYCL_USE_NON_VARIADIC_SPIRV_OCL_PRINTF__ works as expected, i.e. we can
// see printf ExtInst regardless of the macro presence and that argument
// promotion is disabled if the macro is present.
//
// RUN: %clangxx -fsycl -fsycl-device-only -fno-sycl-use-bitcode %s -o %t.spv
// RUN: llvm-spirv -to-text %t.spv -o %t.spt
// RUN: FileCheck %s --check-prefixes CHECK,CHECK-DOUBLE < %t.spt
//
// RUN: %clangxx -fsycl -fsycl-device-only -fno-sycl-use-bitcode -D__SYCL_USE_NON_VARIADIC_SPIRV_OCL_PRINTF__ %s -o %t.spv
// RUN: llvm-spirv -to-text %t.spv -o %t.spt
// RUN: FileCheck %s --check-prefixes CHECK,CHECK-FLOAT < %t.spt

// CHECK-FLOAT: TypeFloat [[#TYPE:]] 32
// CHECK-DOUBLE: TypeFloat [[#TYPE:]] 64
// CHECK: Constant [[#TYPE]] [[#CONST:]]
// CHECK: ExtInst [[#]] [[#]] [[#]] printf [[#]] [[#CONST]]

#include <CL/sycl.hpp>

#ifdef __SYCL_DEVICE_ONLY__
#define __SYCL_CONSTANT_AS __attribute__((opencl_constant))
#else
#define __SYCL_CONSTANT_AS
#endif

const __SYCL_CONSTANT_AS char fmt[] = "Hello, World! %f\n";

int main() {
sycl::queue q;

q.submit([&](sycl::handler &cgh) {
cgh.single_task([=]() {
float f = 3.14;
sycl::ext::oneapi::experimental::printf(fmt, f);
});
});

return 0;
}