diff --git a/SYCL/Printf/double.cpp b/SYCL/Printf/double.cpp new file mode 100644 index 0000000000..060ef8b732 --- /dev/null +++ b/SYCL/Printf/double.cpp @@ -0,0 +1,85 @@ +// This test is written with an aim to check that experimental::printf behaves +// in the same way as printf from C99/C11 +// +// The test is written using conversion specifiers table from cppreference [1] +// [1]: https://en.cppreference.com/w/cpp/io/c/fprintf +// +// UNSUPPORTED: hip_amd +// +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out +// RUN: %CPU_RUN_PLACEHOLDER %t.out %CPU_CHECK_PLACEHOLDER +// RUN: %GPU_RUN_PLACEHOLDER %t.out %GPU_CHECK_PLACEHOLDER +// RUN: %ACC_RUN_PLACEHOLDER %t.out %ACC_CHECK_PLACEHOLDER +// FIXME: Remove dedicated constant address space testing once generic AS +// support is considered stable. +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.constant.out \ +// RUN: -DTEST_CONSTANT_AS +// RUN: %CPU_RUN_PLACEHOLDER %t.constant.out %CPU_CHECK_PLACEHOLDER +// RUN: %GPU_RUN_PLACEHOLDER %t.constant.out %GPU_CHECK_PLACEHOLDER +// RUN: %ACC_RUN_PLACEHOLDER %t.constant.out %ACC_CHECK_PLACEHOLDER +// +// CHECK: double -6.813800e+00, -6.813800E+00 +// CHECK: mixed 3.140000e+00, -6.813800E+00 +// CHECK: double -0x1.b4154d8cccccdp+2, -0X1.B4154D8CCCCCDP+2 +// CHECK: mixed 0x1.91eb86{{0*}}p+1, -0X1.B4154D8CCCCCDP+2 +// CHECK: double -6.8138, -6.8138 +// CHECK: mixed 3.14, -6.8138 + +#include + +#include + +#include "helper.hpp" + +using namespace sycl; + +void do_double_test() { + float f = 3.14; + double d = -f * 2.17; + + { + // %e, %E floating-point, decimal exponent notation + FORMAT_STRING(fmt_double) = "double %e, %E\n"; + FORMAT_STRING(fmt_mixed) = "mixed %e, %E\n"; + ext::oneapi::experimental::printf(fmt_double, d, d); + ext::oneapi::experimental::printf(fmt_mixed, f, d); + } + + { + // %a, %A floating-point, hexadecimal exponent notation + FORMAT_STRING(fmt_double) = "double %a, %A\n"; + FORMAT_STRING(fmt_mixed) = "mixed %a, %A\n"; + ext::oneapi::experimental::printf(fmt_double, d, d); + ext::oneapi::experimental::printf(fmt_mixed, f, d); + } + + { + // %g, %G floating-point + FORMAT_STRING(fmt_double) = "double %g, %G\n"; + FORMAT_STRING(fmt_mixed) = "mixed %g, %G\n"; + ext::oneapi::experimental::printf(fmt_double, d, d); + ext::oneapi::experimental::printf(fmt_mixed, f, d); + } +} + +class DoubleTest; + +int main() { + queue q; + + if (q.get_device().has(aspect::fp64)) { + q.submit([](handler &cgh) { + cgh.single_task([]() { do_double_test(); }); + }); + q.wait(); + } else + std::cout << "Skipping the actual test. " + "Printing hard-coded output from the host side:\n" + << "double -6.813800e+00, -6.813800E+00\n" + "mixed 3.140000e+00, -6.813800E+00\n" + "double -0x1.b4154d8cccccdp+2, -0X1.B4154D8CCCCCDP+2\n" + "mixed 0x1.91eb86p+1, -0X1.B4154D8CCCCCDP+2\n" + "double -6.8138, -6.8138\n" + "mixed 3.14, -6.8138\n"; + return 0; +} diff --git a/SYCL/Printf/float.cpp b/SYCL/Printf/float.cpp index a1988ed567..b872dd5c3c 100644 --- a/SYCL/Printf/float.cpp +++ b/SYCL/Printf/float.cpp @@ -10,6 +10,13 @@ // RUN: %CPU_RUN_PLACEHOLDER %t.out %CPU_CHECK_PLACEHOLDER // RUN: %GPU_RUN_PLACEHOLDER %t.out %GPU_CHECK_PLACEHOLDER // RUN: %ACC_RUN_PLACEHOLDER %t.out %ACC_CHECK_PLACEHOLDER +// FIXME: Remove dedicated non-variadic printf testing once the headers +// enforce it by default. +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.nonvar.out \ +// RUN: -D__SYCL_USE_NON_VARIADIC_SPIRV_OCL_PRINTF__ +// RUN: %CPU_RUN_PLACEHOLDER %t.nonvar.out %CPU_CHECK_PLACEHOLDER +// RUN: %GPU_RUN_PLACEHOLDER %t.nonvar.out %GPU_CHECK_PLACEHOLDER +// RUN: %ACC_RUN_PLACEHOLDER %t.nonvar.out %ACC_CHECK_PLACEHOLDER // FIXME: Remove dedicated constant address space testing once generic AS // support is considered stable. // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.constant.out \ @@ -18,15 +25,11 @@ // RUN: %GPU_RUN_PLACEHOLDER %t.constant.out %GPU_CHECK_PLACEHOLDER // RUN: %ACC_RUN_PLACEHOLDER %t.constant.out %ACC_CHECK_PLACEHOLDER // -// CHECK: float 3.140000e+00, 3.140000E+00 -// CHECK: double -6.813800e+00, -6.813800E+00 -// CHECK: mixed 3.140000e+00, -6.813800E+00 -// CHECK: float 0x1.91eb86{{0*}}p+1, 0X1.91EB86{{0*}}P+1 -// CHECK: double -0x1.b4154d8cccccdp+2, -0X1.B4154D8CCCCCDP+2 -// CHECK: mixed 0x1.91eb86{{0*}}p+1, -0X1.B4154D8CCCCCDP+2 -// CHECK: float 3.14, 3.14 -// CHECK: double -6.8138, -6.8138 -// CHECK: mixed 3.14, -6.8138 +// CHECK: 3.140000e+00, 3.140000E+00 +// CHECK: 0x1.91eb86{{0*}}p+1, 0X1.91EB86{{0*}}P+1 +// CHECK: 3.14, 3.14 + +#include #include @@ -35,44 +38,16 @@ using namespace sycl; void do_float_test() { - { - // %e, %E floating-point, decimal exponent notation - FORMAT_STRING(fmt1) = "float %e, %E\n"; - FORMAT_STRING(fmt2) = "double %e, %E\n"; - FORMAT_STRING(fmt3) = "mixed %e, %E\n"; - - float f = 3.14; - double d = -f * 2.17; - ext::oneapi::experimental::printf(fmt1, f, f); - ext::oneapi::experimental::printf(fmt2, d, d); - ext::oneapi::experimental::printf(fmt3, f, d); - } - - { - // %a, %A floating-point, hexadecimal exponent notation - FORMAT_STRING(fmt1) = "float %a, %A\n"; - FORMAT_STRING(fmt2) = "double %a, %A\n"; - FORMAT_STRING(fmt3) = "mixed %a, %A\n"; - - float f = 3.14; - double d = -f * 2.17; - ext::oneapi::experimental::printf(fmt1, f, f); - ext::oneapi::experimental::printf(fmt2, d, d); - ext::oneapi::experimental::printf(fmt3, f, d); - } - - { - // %g, %G floating-point - FORMAT_STRING(fmt1) = "float %g, %G\n"; - FORMAT_STRING(fmt2) = "double %g, %G\n"; - FORMAT_STRING(fmt3) = "mixed %g, %G\n"; - - float f = 3.14; - double d = -f * 2.17; - ext::oneapi::experimental::printf(fmt1, f, f); - ext::oneapi::experimental::printf(fmt2, d, d); - ext::oneapi::experimental::printf(fmt3, f, d); - } + float f = 3.14; + // %e, %E floating-point, decimal exponent notation + FORMAT_STRING(fmt1) = "float %e, %E\n"; + ext::oneapi::experimental::printf(fmt1, f, f); + // %a, %A floating-point, hexadecimal exponent notation + FORMAT_STRING(fmt2) = "float %a, %A\n"; + ext::oneapi::experimental::printf(fmt2, f, f); + // %g, %G floating-point + FORMAT_STRING(fmt3) = "float %g, %G\n"; + ext::oneapi::experimental::printf(fmt3, f, f); } class FloatTest; @@ -80,10 +55,19 @@ class FloatTest; int main() { queue q; +#ifndef __SYCL_USE_NON_VARIADIC_SPIRV_OCL_PRINTF__ + if (!q.get_device().has(aspect::fp64)) { + std::cout << "Skipping the actual test due to variadic argument promotion. " + "Printing hard-coded output from the host side:\n" + << "3.140000e+00, 3.140000E+00\n" + "0x1.91eb86p+1, 0X1.91EB86P+1\n" + "3.14, 3.14\n"; + return 0; + } +#endif // !__SYCL_USE_NON_VARIADIC_SPIRV_OCL_PRINTF__ q.submit([](handler &cgh) { cgh.single_task([]() { do_float_test(); }); }); q.wait(); - return 0; }