Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

[SYCL] Add more tests for experimental::printf #569

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9f93619
[SYCL] Add one test for experimental::printf
AlexeySachkov Nov 15, 2021
b376aa5
Add more tests
AlexeySachkov Nov 15, 2021
7390b32
Merge remote-tracking branch 'origin/intel' into expand-printf-tests
Dec 9, 2021
d36c054
Move the %% conversion into a separate test, adjust accordingly
Dec 11, 2021
e55534a
Disable GPU-specific failures
Dec 11, 2021
bf35522
Adjust target triple setting to accomodate CUDA runs
Dec 11, 2021
fe5b4b2
Adjust hex float checks for Windows-specific printing of zero LSBs
Dec 11, 2021
f483342
Add missing "mixed" float checks
Dec 11, 2021
f8fcf3b
Fix regexp ordering
Dec 11, 2021
bee58c6
Test generic address space alongside constant AS
Dec 13, 2021
914c5e8
Add a test for mixed address spaces
Dec 13, 2021
b8d829b
Add forgotten CHECK lines to mixed-address-space.cpp
Dec 13, 2021
1996142
Fix comment
Dec 13, 2021
c74956c
Avoid using OpenCL constant AS on host
Dec 15, 2021
5a1839e
Update CODEOWNERS
Dec 16, 2021
8b1072e
Mark int.cpp XFAIL on CUDA
Dec 16, 2021
13b0fc8
Merge remote-tracking branch 'origin/intel' into expand-printf-tests
Dec 16, 2021
01429d4
Merge remote-tracking branch 'origin/intel' into expand-printf-tests
Dec 22, 2021
bb4ec4a
Merge remote-tracking branch 'origin/intel' into expand-printf-tests
Dec 22, 2021
9f058e2
Merge remote-tracking branch 'origin/intel' into expand-printf-tests
Dec 23, 2021
99e1f60
Don't test wchar_t* and the L prefix at all, add corresponding FIXME
Dec 27, 2021
6a575b0
Introduce a separate test for long int specifier
Dec 27, 2021
a52eb4a
Merge remote-tracking branch 'origin/intel' into expand-printf-tests
Dec 27, 2021
0655321
Fix the CHECK line for char.cpp after latest adjustments
Dec 27, 2021
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
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ SYCL/OnlineCompiler @v-klochkov
# Plugin interface
SYCL/Plugin @smaslov-intel

# Printf
SYCL/Printf @AlexeySachkov @AGindinson @mlychkov

# Reduction algorithms
SYCL/Reduction @v-klochkov

Expand Down
78 changes: 78 additions & 0 deletions SYCL/Printf/char.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// 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
//
// 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
//
// FIXME: wchar_t* is not supported on GPU
// FIXME: String literal prefixes (L, u8, u, U) are not functioning on Windows
//
// CHECK: c=a
// CHECK: literal strings: s=Hello World!
// CHECK_DISABLED: non-literal strings: s=Hello, World! ls=

#include <CL/sycl.hpp>

#include <cstring>

#include "helper.hpp"

using namespace sycl;

void do_char_string_test() {
{
// %c format specifier, single character
FORMAT_STRING(fmt) = "c=%c\n"; // FIXME: lc is not tested

char c = 'a';

ext::oneapi::experimental::printf(fmt, c);
}

{
// %s format specifier, character string
FORMAT_STRING(fmt1) = "literal strings: s=%s %s\n";
ext::oneapi::experimental::printf(fmt1, "Hello",
// World!
"\x57\x6F\x72\x6C\x64\x21");

// FIXME: lack of support for non-literal strings in %s is an OpenCL
// limitation
/*
FORMAT_STRING(fmt2) = "non-literal strings: s=%s ls=%ls\n";
char str[20] = { '\0' };
const char *s = "Hello, World!";
for (int i = 0; i < 13; ++i) {
str[i] = s[i];
}

// FIXME: ls is untested here
ext::oneapi::experimental::printf(fmt2, str, "");
*/
}
}

class CharTest;

int main() {
queue q;

q.submit([](handler &cgh) {
cgh.single_task<CharTest>([]() { do_char_string_test(); });
});
q.wait();

return 0;
}
87 changes: 87 additions & 0 deletions SYCL/Printf/float.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// 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
//
// 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: 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

#include <CL/sycl.hpp>

#include "helper.hpp"

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);
}
}

class FloatTest;

int main() {
queue q;

q.submit([](handler &cgh) {
cgh.single_task<FloatTest>([]() { do_float_test(); });
});
q.wait();

return 0;
}
8 changes: 8 additions & 0 deletions SYCL/Printf/helper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#if defined(__SYCL_DEVICE_ONLY__) && defined(TEST_CONSTANT_AS)
// On device side, we have to put format string into a constant address space
// FIXME: remove this header completely once the toolchain's support for
// generic address-spaced format strings is stable.
#define FORMAT_STRING(X) static const __attribute__((opencl_constant)) char X[]
#else
#define FORMAT_STRING(X) static const char X[]
#endif
Loading