subgroups: Fix Wformat warnings (#1549)

The main source of warnings was the use of `%d` for printing a
templated type `T`, where `T` could be any cl_ scalar or vector type.

Introduce `print_expected_obtained`.  It takes const references to
handle alignment of the cl_ types.

Define `operator<<` for all types used by the subgroup tests.  Ideally
those would be template functions enabled by TypeManager data, but
that requires some more work on the TypeManager (which we'd ideally do
after more warnings have been enabled).  So for now, define the
`operator<<` instances using preprocessor defines.

Also fix a few instances where the wrong format specifier was used for
`size_t` types.

Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>

Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
This commit is contained in:
Sven van Haastregt
2022-11-15 17:12:31 +00:00
committed by GitHub
parent 2110e45cce
commit fc4260bdae
6 changed files with 126 additions and 13 deletions

View File

@@ -456,6 +456,52 @@ struct cl_half16
};
}
// Declare operator<< for cl_ types, accessing the .s member.
#define OP_OSTREAM(Ty, VecSize) \
std::ostream &operator<<(std::ostream &os, const Ty##VecSize &val);
// Declare operator<< for subgroups::cl_ types, accessing the .data member and
// forwarding to operator<< for the cl_ types.
#define OP_OSTREAM_SUBGROUP(Ty, VecSize) \
std::ostream &operator<<(std::ostream &os, const Ty##VecSize &val);
// Declare operator<< for all vector sizes.
#define OP_OSTREAM_ALL_VEC(Ty) \
OP_OSTREAM(Ty, 2) \
OP_OSTREAM(Ty, 4) \
OP_OSTREAM(Ty, 8) \
OP_OSTREAM(Ty, 16) \
OP_OSTREAM_SUBGROUP(subgroups::Ty, 3)
OP_OSTREAM_ALL_VEC(cl_char)
OP_OSTREAM_ALL_VEC(cl_uchar)
OP_OSTREAM_ALL_VEC(cl_short)
OP_OSTREAM_ALL_VEC(cl_ushort)
OP_OSTREAM_ALL_VEC(cl_int)
OP_OSTREAM_ALL_VEC(cl_uint)
OP_OSTREAM_ALL_VEC(cl_long)
OP_OSTREAM_ALL_VEC(cl_ulong)
OP_OSTREAM_ALL_VEC(cl_float)
OP_OSTREAM_ALL_VEC(cl_double)
OP_OSTREAM_ALL_VEC(cl_half)
OP_OSTREAM_SUBGROUP(subgroups::cl_half, )
OP_OSTREAM_SUBGROUP(subgroups::cl_half, 2)
OP_OSTREAM_SUBGROUP(subgroups::cl_half, 4)
OP_OSTREAM_SUBGROUP(subgroups::cl_half, 8)
OP_OSTREAM_SUBGROUP(subgroups::cl_half, 16)
#undef OP_OSTREAM
#undef OP_OSTREAM_SUBGROUP
#undef OP_OSTREAM_ALL_VEC
template <typename Ty>
std::string print_expected_obtained(const Ty &expected, const Ty &obtained)
{
std::ostringstream oss;
oss << "Expected: " << expected << " Obtained: " << obtained;
return oss.str();
}
static bool int64_ok(cl_device_id device)
{
char profile[128];