diff --git a/sycl/test-e2e/Printf/int.cpp b/sycl/test-e2e/Printf/int.cpp index 5a46788251412..2af772e9d903d 100644 --- a/sycl/test-e2e/Printf/int.cpp +++ b/sycl/test-e2e/Printf/int.cpp @@ -5,9 +5,11 @@ // [1]: https://en.cppreference.com/w/cpp/io/c/fprintf // // UNSUPPORTED: target-amd -// FIXME: The 'short' type gets overflown with sporadic values on CUDA. -// XFAIL: cuda -// XFAIL-TRACKER: https://github.com/intel/llvm/issues/14734 +// CUDA device-side printf does not support the hh length modifier and treats +// %hd as double. When running on the CUDA backend, this test avoids hh/%hd and +// uses %d/%i/%o/%x/%X/%u for int-promoted types (char/short) instead. +// See: +// https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#formatted-output // RUN: %{build} -o %t.out // RUN: %{run} %t.out | FileCheck %s @@ -23,7 +25,7 @@ using namespace sycl; -void do_d_i_test() { // %d, %i signed integer, decimal representation +void do_d_i_test(bool IsCuda) { // %d, %i signed integer, decimal representation // Some reference values constexpr char CHAR_VALUE = 0x7B; // 123 constexpr short SHORT_VALUE = 0x3039; // 12345 @@ -41,16 +43,33 @@ void do_d_i_test() { // %d, %i signed integer, decimal representation size_t zd = LONG_LONG_VALUE; ptrdiff_t td = LONG_LONG_VALUE; - FORMAT_STRING(fmt1) = "Decimal positive values:\n" - "\tsigned char: %hhd\n" - "\tshort: %hd\n" - "\tint: %d\n" - "\tlong: %ld\n" - "\tlong long: %lld\n" - "\tintmax_t: %jd\n" - "\tsigned size_t: %zd\n" - "\tptrdiff_t: %td\n"; - ext::oneapi::experimental::printf(fmt1, hhd, hd, d, ld, lld, jd, zd, td); + FORMAT_STRING(fmt1_default) = "Decimal positive values:\n" + "\tsigned char: %hhd\n" + "\tshort: %hd\n" + "\tint: %d\n" + "\tlong: %ld\n" + "\tlong long: %lld\n" + "\tintmax_t: %jd\n" + "\tsigned size_t: %zd\n" + "\tptrdiff_t: %td\n"; + FORMAT_STRING(fmt1_cuda) = "Decimal positive values:\n" + "\tsigned char: %d\n" + "\tshort: %d\n" + "\tint: %d\n" + "\tlong: %ld\n" + "\tlong long: %lld\n" + "\tintmax_t: %lld\n" + "\tsigned size_t: %lld\n" + "\tptrdiff_t: %lld\n"; + if (IsCuda) { + ext::oneapi::experimental::printf( + fmt1_cuda, static_cast(hhd), static_cast(hd), d, ld, lld, + static_cast(jd), static_cast(zd), + static_cast(td)); + } else { + ext::oneapi::experimental::printf(fmt1_default, hhd, hd, d, ld, lld, jd, zd, + td); + } // CHECK: Decimal positive values: // CHECK-NEXT: signed char: 123 // CHECK-NEXT: short: 12345 @@ -61,16 +80,33 @@ void do_d_i_test() { // %d, %i signed integer, decimal representation // CHECK-NEXT: signed size_t: 1234567891011121314 // CHECK-NEXT: ptrdiff_t: 1234567891011121314 - FORMAT_STRING(fmt2) = "Integer positive values:\n" - "\tsigned char: %hhi\n" - "\tshort: %hi\n" - "\tint: %i\n" - "\tlong: %li\n" - "\tlong long: %lli\n" - "\tintmax_t: %ji\n" - "\tsigned size_t: %zi\n" - "\tptrdiff_t: %ti\n"; - ext::oneapi::experimental::printf(fmt2, hhd, hd, d, ld, lld, jd, zd, td); + FORMAT_STRING(fmt2_default) = "Integer positive values:\n" + "\tsigned char: %hhi\n" + "\tshort: %hi\n" + "\tint: %i\n" + "\tlong: %li\n" + "\tlong long: %lli\n" + "\tintmax_t: %ji\n" + "\tsigned size_t: %zi\n" + "\tptrdiff_t: %ti\n"; + FORMAT_STRING(fmt2_cuda) = "Integer positive values:\n" + "\tsigned char: %i\n" + "\tshort: %i\n" + "\tint: %i\n" + "\tlong: %li\n" + "\tlong long: %lli\n" + "\tintmax_t: %lli\n" + "\tsigned size_t: %lli\n" + "\tptrdiff_t: %lli\n"; + if (IsCuda) { + ext::oneapi::experimental::printf( + fmt2_cuda, static_cast(hhd), static_cast(hd), d, ld, lld, + static_cast(jd), static_cast(zd), + static_cast(td)); + } else { + ext::oneapi::experimental::printf(fmt2_default, hhd, hd, d, ld, lld, jd, zd, + td); + } // CHECK: Integer positive values: // CHECK-NEXT: signed char: 123 // CHECK-NEXT: short: 12345 @@ -90,16 +126,33 @@ void do_d_i_test() { // %d, %i signed integer, decimal representation zd = -zd; td = -td; - FORMAT_STRING(fmt3) = "Decimal negative values:\n" - "\tsigned char: %hhd\n" - "\tshort: %hd\n" - "\tint: %d\n" - "\tlong: %ld\n" - "\tlong long: %lld\n" - "\tintmax_t: %jd\n" - "\tsigned size_t: %zd\n" - "\tptrdiff_t: %td\n"; - ext::oneapi::experimental::printf(fmt3, hhd, hd, d, ld, lld, jd, zd, td); + FORMAT_STRING(fmt3_default) = "Decimal negative values:\n" + "\tsigned char: %hhd\n" + "\tshort: %hd\n" + "\tint: %d\n" + "\tlong: %ld\n" + "\tlong long: %lld\n" + "\tintmax_t: %jd\n" + "\tsigned size_t: %zd\n" + "\tptrdiff_t: %td\n"; + FORMAT_STRING(fmt3_cuda) = "Decimal negative values:\n" + "\tsigned char: %d\n" + "\tshort: %d\n" + "\tint: %d\n" + "\tlong: %ld\n" + "\tlong long: %lld\n" + "\tintmax_t: %lld\n" + "\tsigned size_t: %lld\n" + "\tptrdiff_t: %lld\n"; + if (IsCuda) { + ext::oneapi::experimental::printf( + fmt3_cuda, static_cast(hhd), static_cast(hd), d, ld, lld, + static_cast(jd), static_cast(zd), + static_cast(td)); + } else { + ext::oneapi::experimental::printf(fmt3_default, hhd, hd, d, ld, lld, jd, zd, + td); + } // CHECK: Decimal negative values: // CHECK-NEXT: signed char: -123 // CHECK-NEXT: short: -12345 @@ -110,16 +163,33 @@ void do_d_i_test() { // %d, %i signed integer, decimal representation // CHECK-NEXT: signed size_t: -1234567891011121314 // CHECK-NEXT: ptrdiff_t: -1234567891011121314 - FORMAT_STRING(fmt4) = "Integer negative values:\n" - "\tsigned char: %hhi\n" - "\tshort: %hi\n" - "\tint: %i\n" - "\tlong: %li\n" - "\tlong long: %lli\n" - "\tintmax_t: %ji\n" - "\tsigned size_t: %zi\n" - "\tptrdiff_t: %ti\n"; - ext::oneapi::experimental::printf(fmt4, hhd, hd, d, ld, lld, jd, zd, td); + FORMAT_STRING(fmt4_default) = "Integer negative values:\n" + "\tsigned char: %hhi\n" + "\tshort: %hi\n" + "\tint: %i\n" + "\tlong: %li\n" + "\tlong long: %lli\n" + "\tintmax_t: %ji\n" + "\tsigned size_t: %zi\n" + "\tptrdiff_t: %ti\n"; + FORMAT_STRING(fmt4_cuda) = "Integer negative values:\n" + "\tsigned char: %i\n" + "\tshort: %i\n" + "\tint: %i\n" + "\tlong: %li\n" + "\tlong long: %lli\n" + "\tintmax_t: %lli\n" + "\tsigned size_t: %lli\n" + "\tptrdiff_t: %lli\n"; + if (IsCuda) { + ext::oneapi::experimental::printf( + fmt4_cuda, static_cast(hhd), static_cast(hd), d, ld, lld, + static_cast(jd), static_cast(zd), + static_cast(td)); + } else { + ext::oneapi::experimental::printf(fmt4_default, hhd, hd, d, ld, lld, jd, zd, + td); + } // CHECK: Integer negative values: // CHECK-NEXT: signed char: -123 // CHECK-NEXT: short: -12345 @@ -131,7 +201,7 @@ void do_d_i_test() { // %d, %i signed integer, decimal representation // CHECK-NEXT: ptrdiff_t: -1234567891011121314 } -void do_o_test() { // %o unsigned integer, octal representation +void do_o_test(bool IsCuda) { // %o unsigned integer, octal representation // Some reference values constexpr unsigned char CHAR_VALUE = 0123; constexpr unsigned short SHORT_VALUE = 0123456; @@ -148,16 +218,34 @@ void do_o_test() { // %o unsigned integer, octal representation size_t zo = LONG_LONG_VALUE; ptrdiff_t to = LONG_LONG_VALUE; - FORMAT_STRING(fmt1) = "Octal:\n" - "\tunsigned char: %hho\n" - "\tunsigned short: %ho\n" - "\tunsigned int: %o\n" - "\tunsigned long: %lo\n" - "\tunsigned long long: %llo\n" - "\tuintmax_t: %jo\n" - "\tsize_t: %zo\n" - "\tptrdiff_t (unsigned version): %to\n"; - ext::oneapi::experimental::printf(fmt1, hho, ho, o, lo, llo, jo, zo, to); + FORMAT_STRING(fmt1_default) = "Octal:\n" + "\tunsigned char: %hho\n" + "\tunsigned short: %ho\n" + "\tunsigned int: %o\n" + "\tunsigned long: %lo\n" + "\tunsigned long long: %llo\n" + "\tuintmax_t: %jo\n" + "\tsize_t: %zo\n" + "\tptrdiff_t (unsigned version): %to\n"; + FORMAT_STRING(fmt1_cuda) = "Octal:\n" + "\tunsigned char: %o\n" + "\tunsigned short: %o\n" + "\tunsigned int: %o\n" + "\tunsigned long: %lo\n" + "\tunsigned long long: %llo\n" + "\tuintmax_t: %llo\n" + "\tsize_t: %llo\n" + "\tptrdiff_t (unsigned version): %llo\n"; + if (IsCuda) { + ext::oneapi::experimental::printf(fmt1_cuda, static_cast(hho), + static_cast(ho), o, lo, llo, + static_cast(jo), + static_cast(zo), + static_cast(to)); + } else { + ext::oneapi::experimental::printf(fmt1_default, hho, ho, o, lo, llo, jo, zo, + to); + } // CHECK: Octal: // CHECK-NEXT: unsigned char: 123 // CHECK-NEXT: unsigned short: 123456 @@ -169,7 +257,8 @@ void do_o_test() { // %o unsigned integer, octal representation // CHECK-NEXT: ptrdiff_t (unsigned version): 1234567012345670123456 } -void do_x_test() { // %x, %X unsigned integer, hexadecimal representation +void do_x_test( + bool IsCuda) { // %x, %X unsigned integer, hexadecimal representation // Some reference values constexpr unsigned char CHAR_VALUE = 0x12; constexpr unsigned short SHORT_VALUE = 0x1234; @@ -186,16 +275,34 @@ void do_x_test() { // %x, %X unsigned integer, hexadecimal representation size_t zx = LONG_LONG_VALUE; ptrdiff_t tx = LONG_LONG_VALUE; - FORMAT_STRING(fmt1) = "Hexadecimal:\n" - "\tunsigned char: %hhx\n" - "\tunsigned short: %hx\n" - "\tunsigned int: %x\n" - "\tunsigned long: %lx\n" - "\tunsigned long long: %llx\n" - "\tuintmax_t: %jx\n" - "\tsize_t: %zx\n" - "\tptrdiff_t: %tx\n"; - ext::oneapi::experimental::printf(fmt1, hhx, hx, x, lx, llx, jx, zx, tx); + FORMAT_STRING(fmt1_default) = "Hexadecimal:\n" + "\tunsigned char: %hhx\n" + "\tunsigned short: %hx\n" + "\tunsigned int: %x\n" + "\tunsigned long: %lx\n" + "\tunsigned long long: %llx\n" + "\tuintmax_t: %jx\n" + "\tsize_t: %zx\n" + "\tptrdiff_t: %tx\n"; + FORMAT_STRING(fmt1_cuda) = "Hexadecimal:\n" + "\tunsigned char: %x\n" + "\tunsigned short: %x\n" + "\tunsigned int: %x\n" + "\tunsigned long: %lx\n" + "\tunsigned long long: %llx\n" + "\tuintmax_t: %llx\n" + "\tsize_t: %llx\n" + "\tptrdiff_t: %llx\n"; + if (IsCuda) { + ext::oneapi::experimental::printf(fmt1_cuda, static_cast(hhx), + static_cast(hx), x, lx, llx, + static_cast(jx), + static_cast(zx), + static_cast(tx)); + } else { + ext::oneapi::experimental::printf(fmt1_default, hhx, hx, x, lx, llx, jx, zx, + tx); + } // CHECK: Hexadecimal: // CHECK-NEXT: unsigned char: 12 // CHECK-NEXT: unsigned short: 1234 @@ -206,16 +313,34 @@ void do_x_test() { // %x, %X unsigned integer, hexadecimal representation // CHECK-NEXT: size_t: 123456789abcdef0 // CHECK-NEXT: ptrdiff_t: 123456789abcdef0 - FORMAT_STRING(fmt2) = "Hexadecimal (capital letters):\n" - "\tunsigned char: %hhX\n" - "\tunsigned short: %hX\n" - "\tunsigned int: %X\n" - "\tunsigned long: %lX\n" - "\tunsigned long long: %llX\n" - "\tuintmax_t: %jX\n" - "\tsize_t: %zX\n" - "\tptrdiff_t: %tX\n"; - ext::oneapi::experimental::printf(fmt2, hhx, hx, x, lx, llx, jx, zx, tx); + FORMAT_STRING(fmt2_default) = "Hexadecimal (capital letters):\n" + "\tunsigned char: %hhX\n" + "\tunsigned short: %hX\n" + "\tunsigned int: %X\n" + "\tunsigned long: %lX\n" + "\tunsigned long long: %llX\n" + "\tuintmax_t: %jX\n" + "\tsize_t: %zX\n" + "\tptrdiff_t: %tX\n"; + FORMAT_STRING(fmt2_cuda) = "Hexadecimal (capital letters):\n" + "\tunsigned char: %X\n" + "\tunsigned short: %X\n" + "\tunsigned int: %X\n" + "\tunsigned long: %lX\n" + "\tunsigned long long: %llX\n" + "\tuintmax_t: %llX\n" + "\tsize_t: %llX\n" + "\tptrdiff_t: %llX\n"; + if (IsCuda) { + ext::oneapi::experimental::printf(fmt2_cuda, static_cast(hhx), + static_cast(hx), x, lx, llx, + static_cast(jx), + static_cast(zx), + static_cast(tx)); + } else { + ext::oneapi::experimental::printf(fmt2_default, hhx, hx, x, lx, llx, jx, zx, + tx); + } // CHECK: Hexadecimal (capital letters): // CHECK-NEXT: unsigned char: 12 // CHECK-NEXT: unsigned short: 1234 @@ -227,7 +352,7 @@ void do_x_test() { // %x, %X unsigned integer, hexadecimal representation // CHECK-NEXT: ptrdiff_t: 123456789ABCDEF0 } -void do_u_test() { // %u unsigned integer, decimal representation +void do_u_test(bool IsCuda) { // %u unsigned integer, decimal representation // Some reference values constexpr char CHAR_VALUE = 0x7B; // 123 constexpr short SHORT_VALUE = 0x3039; // 12345 @@ -245,16 +370,34 @@ void do_u_test() { // %u unsigned integer, decimal representation size_t zu = LONG_LONG_VALUE; ptrdiff_t tu = LONG_LONG_VALUE; - FORMAT_STRING(fmt1) = "Unsigned decimal:\n" - "\tunsigned char: %hhu\n" - "\tunsigned short: %hu\n" - "\tunsigned int: %u\n" - "\tunsigned long: %lu\n" - "\tunsigned long long: %llu\n" - "\tuintmax_t: %ju\n" - "\tsize_t: %zu\n" - "\tptrdiff_t: %tu\n"; - ext::oneapi::experimental::printf(fmt1, hhu, hu, u, lu, llu, ju, zu, tu); + FORMAT_STRING(fmt1_default) = "Unsigned decimal:\n" + "\tunsigned char: %hhu\n" + "\tunsigned short: %hu\n" + "\tunsigned int: %u\n" + "\tunsigned long: %lu\n" + "\tunsigned long long: %llu\n" + "\tuintmax_t: %ju\n" + "\tsize_t: %zu\n" + "\tptrdiff_t: %tu\n"; + FORMAT_STRING(fmt1_cuda) = "Unsigned decimal:\n" + "\tunsigned char: %u\n" + "\tunsigned short: %u\n" + "\tunsigned int: %u\n" + "\tunsigned long: %lu\n" + "\tunsigned long long: %llu\n" + "\tuintmax_t: %llu\n" + "\tsize_t: %llu\n" + "\tptrdiff_t: %llu\n"; + if (IsCuda) { + ext::oneapi::experimental::printf(fmt1_cuda, static_cast(hhu), + static_cast(hu), u, lu, llu, + static_cast(ju), + static_cast(zu), + static_cast(tu)); + } else { + ext::oneapi::experimental::printf(fmt1_default, hhu, hu, u, lu, llu, ju, zu, + tu); + } // CHECK: Unsigned decimal: // CHECK-NEXT: unsigned char: 123 // CHECK-NEXT: unsigned short: 12345 @@ -271,12 +414,14 @@ class IntTest; int main() { queue q; - q.submit([](handler &cgh) { - cgh.single_task([]() { - do_d_i_test(); - do_o_test(); - do_x_test(); - do_u_test(); + const bool IsCuda = (q.get_backend() == backend::ext_oneapi_cuda); + + q.submit([&](handler &cgh) { + cgh.single_task([=]() { + do_d_i_test(IsCuda); + do_o_test(IsCuda); + do_x_test(IsCuda); + do_u_test(IsCuda); }); }); q.wait();