File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
#define ATTR_SYCL_KERNEL __attribute__ ((sycl_kernel))
4
4
5
+ extern "C" int printf(const char * fmt, ...);
6
+
5
7
// Dummy runtime classes to model SYCL API.
6
8
inline namespace cl {
7
9
namespace sycl {
@@ -310,6 +312,21 @@ class spec_constant {
310
312
return get ();
311
313
}
312
314
};
315
+
316
+ #ifdef __SYCL_DEVICE_ONLY__
317
+ #define __SYCL_CONSTANT_AS __attribute__ ((opencl_constant))
318
+ #else
319
+ #define __SYCL_CONSTANT_AS
320
+ #endif
321
+ template <typename ... Args>
322
+ int printf (const __SYCL_CONSTANT_AS char *__format, Args... args) {
323
+ #if defined(__SYCL_DEVICE_ONLY__) && defined(__SPIR__)
324
+ return __spirv_ocl_printf (__format, args...);
325
+ #else
326
+ return ::printf (__format, args...);
327
+ #endif // defined(__SYCL_DEVICE_ONLY__) && defined(__SPIR__)
328
+ }
329
+
313
330
} // namespace experimental
314
331
} // namespace oneapi
315
332
} // namespace ext
Original file line number Diff line number Diff line change
1
+ // RUN: %clang_cc1 -fsycl-is-device -triple nvptx64-nvidia-cuda-sycldevice -std=c++11 -S -emit-llvm -x c++ %s -o - | FileCheck %s
2
+
3
+ #include " Inputs/sycl.hpp"
4
+
5
+ #ifdef __SYCL_DEVICE_ONLY__
6
+ #define CONSTANT __attribute__ ((opencl_constant))
7
+ #else
8
+ #define CONSTANT
9
+ #endif
10
+
11
+ static const CONSTANT char format_2[] = " Hello! %d %f\n " ;
12
+
13
+ int main () {
14
+ // Make sure that device printf is dispatched to CUDA's vprintf syscall.
15
+ // CHECK: alloca %printf_args
16
+ // CHECK: call i32 @vprintf
17
+ cl::sycl::kernel_single_task<class first_kernel >([]() { cl::sycl::ext::oneapi::experimental::printf (format_2, 123 , 1.23 ); });
18
+ }
You can’t perform that action at this time.
0 commit comments