Fix unused-function warnings and enable -Wunused-function (#1576)

Move functions in .h files to .cpp files where appropriate; align
prototypes and definitions; and remove functions that are not used.

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-12-13 17:47:48 +00:00
committed by GitHub
parent 58eb3d776d
commit 3cadff7115
9 changed files with 193 additions and 273 deletions

View File

@@ -21,39 +21,6 @@
#include "subhelpers.h"
#include <set>
#include <algorithm>
#include <random>
static cl_uint4 generate_bit_mask(cl_uint subgroup_local_id,
const std::string &mask_type,
cl_uint max_sub_group_size)
{
bs128 mask128;
cl_uint4 mask;
cl_uint pos = subgroup_local_id;
if (mask_type == "eq") mask128.set(pos);
if (mask_type == "le" || mask_type == "lt")
{
for (cl_uint i = 0; i <= pos; i++) mask128.set(i);
if (mask_type == "lt") mask128.reset(pos);
}
if (mask_type == "ge" || mask_type == "gt")
{
for (cl_uint i = pos; i < max_sub_group_size; i++) mask128.set(i);
if (mask_type == "gt") mask128.reset(pos);
}
// convert std::bitset<128> to uint4
auto const uint_mask = bs128{ static_cast<unsigned long>(-1) };
mask.s0 = (mask128 & uint_mask).to_ulong();
mask128 >>= 32;
mask.s1 = (mask128 & uint_mask).to_ulong();
mask128 >>= 32;
mask.s2 = (mask128 & uint_mask).to_ulong();
mask128 >>= 32;
mask.s3 = (mask128 & uint_mask).to_ulong();
return mask;
}
// DESCRIPTION :
// sub_group_broadcast - each work_item registers it's own value.
@@ -393,33 +360,6 @@ template <typename Ty> bool is_floating_point()
|| std::is_same<Ty, subgroups::cl_half>::value;
}
// limit possible input values to avoid arithmetic rounding/overflow issues.
// for each subgroup values defined different values
// for rest of workitems set 1
// shuffle values
static void fill_and_shuffle_safe_values(std::vector<cl_ulong> &safe_values,
int sb_size)
{
// max product is 720, cl_half has enough precision for it
const std::vector<cl_ulong> non_one_values{ 2, 3, 4, 5, 6 };
if (sb_size <= non_one_values.size())
{
safe_values.assign(non_one_values.begin(),
non_one_values.begin() + sb_size);
}
else
{
safe_values.assign(sb_size, 1);
std::copy(non_one_values.begin(), non_one_values.end(),
safe_values.begin());
}
std::mt19937 mersenne_twister_engine(10000);
std::shuffle(safe_values.begin(), safe_values.end(),
mersenne_twister_engine);
};
template <typename Ty, ArithmeticOp operation>
void generate_inputs(Ty *x, Ty *t, cl_int *m, int ns, int nw, int ng)
{

View File

@@ -16,6 +16,8 @@
#include "subhelpers.h"
#include <random>
// Define operator<< for cl_ types, accessing the .s member.
#define OP_OSTREAM(Ty, VecSize) \
std::ostream& operator<<(std::ostream& os, const Ty##VecSize& val) \
@@ -60,3 +62,168 @@ 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)
bs128 cl_uint4_to_bs128(cl_uint4 v)
{
return bs128(v.s0) | (bs128(v.s1) << 32) | (bs128(v.s2) << 64)
| (bs128(v.s3) << 96);
}
cl_uint4 bs128_to_cl_uint4(bs128 v)
{
bs128 bs128_ffffffff = 0xffffffffU;
cl_uint4 r;
r.s0 = ((v >> 0) & bs128_ffffffff).to_ulong();
r.s1 = ((v >> 32) & bs128_ffffffff).to_ulong();
r.s2 = ((v >> 64) & bs128_ffffffff).to_ulong();
r.s3 = ((v >> 96) & bs128_ffffffff).to_ulong();
return r;
}
cl_uint4 generate_bit_mask(cl_uint subgroup_local_id,
const std::string &mask_type,
cl_uint max_sub_group_size)
{
bs128 mask128;
cl_uint4 mask;
cl_uint pos = subgroup_local_id;
if (mask_type == "eq") mask128.set(pos);
if (mask_type == "le" || mask_type == "lt")
{
for (cl_uint i = 0; i <= pos; i++) mask128.set(i);
if (mask_type == "lt") mask128.reset(pos);
}
if (mask_type == "ge" || mask_type == "gt")
{
for (cl_uint i = pos; i < max_sub_group_size; i++) mask128.set(i);
if (mask_type == "gt") mask128.reset(pos);
}
// convert std::bitset<128> to uint4
auto const uint_mask = bs128{ static_cast<unsigned long>(-1) };
mask.s0 = (mask128 & uint_mask).to_ulong();
mask128 >>= 32;
mask.s1 = (mask128 & uint_mask).to_ulong();
mask128 >>= 32;
mask.s2 = (mask128 & uint_mask).to_ulong();
mask128 >>= 32;
mask.s3 = (mask128 & uint_mask).to_ulong();
return mask;
}
const char *const operation_names(ArithmeticOp operation)
{
switch (operation)
{
case ArithmeticOp::add_: return "add";
case ArithmeticOp::max_: return "max";
case ArithmeticOp::min_: return "min";
case ArithmeticOp::mul_: return "mul";
case ArithmeticOp::and_: return "and";
case ArithmeticOp::or_: return "or";
case ArithmeticOp::xor_: return "xor";
case ArithmeticOp::logical_and: return "logical_and";
case ArithmeticOp::logical_or: return "logical_or";
case ArithmeticOp::logical_xor: return "logical_xor";
default: log_error("Unknown operation request\n"); break;
}
return "";
}
const char *const operation_names(BallotOp operation)
{
switch (operation)
{
case BallotOp::ballot: return "ballot";
case BallotOp::inverse_ballot: return "inverse_ballot";
case BallotOp::ballot_bit_extract: return "bit_extract";
case BallotOp::ballot_bit_count: return "bit_count";
case BallotOp::ballot_inclusive_scan: return "inclusive_scan";
case BallotOp::ballot_exclusive_scan: return "exclusive_scan";
case BallotOp::ballot_find_lsb: return "find_lsb";
case BallotOp::ballot_find_msb: return "find_msb";
case BallotOp::eq_mask: return "eq";
case BallotOp::ge_mask: return "ge";
case BallotOp::gt_mask: return "gt";
case BallotOp::le_mask: return "le";
case BallotOp::lt_mask: return "lt";
default: log_error("Unknown operation request\n"); break;
}
return "";
}
const char *const operation_names(ShuffleOp operation)
{
switch (operation)
{
case ShuffleOp::shuffle: return "shuffle";
case ShuffleOp::shuffle_up: return "shuffle_up";
case ShuffleOp::shuffle_down: return "shuffle_down";
case ShuffleOp::shuffle_xor: return "shuffle_xor";
case ShuffleOp::rotate: return "rotate";
case ShuffleOp::clustered_rotate: return "clustered_rotate";
default: log_error("Unknown operation request\n"); break;
}
return "";
}
const char *const operation_names(NonUniformVoteOp operation)
{
switch (operation)
{
case NonUniformVoteOp::all: return "all";
case NonUniformVoteOp::all_equal: return "all_equal";
case NonUniformVoteOp::any: return "any";
case NonUniformVoteOp::elect: return "elect";
default: log_error("Unknown operation request\n"); break;
}
return "";
}
const char *const operation_names(SubgroupsBroadcastOp operation)
{
switch (operation)
{
case SubgroupsBroadcastOp::broadcast: return "broadcast";
case SubgroupsBroadcastOp::broadcast_first: return "broadcast_first";
case SubgroupsBroadcastOp::non_uniform_broadcast:
return "non_uniform_broadcast";
default: log_error("Unknown operation request\n"); break;
}
return "";
}
void set_last_workgroup_params(int non_uniform_size, int &number_of_subgroups,
int subgroup_size, int &workgroup_size,
int &last_subgroup_size)
{
number_of_subgroups = 1 + non_uniform_size / subgroup_size;
last_subgroup_size = non_uniform_size % subgroup_size;
workgroup_size = non_uniform_size;
}
void fill_and_shuffle_safe_values(std::vector<cl_ulong> &safe_values,
int sb_size)
{
// max product is 720, cl_half has enough precision for it
const std::vector<cl_ulong> non_one_values{ 2, 3, 4, 5, 6 };
if (sb_size <= non_one_values.size())
{
safe_values.assign(non_one_values.begin(),
non_one_values.begin() + sb_size);
}
else
{
safe_values.assign(sb_size, 1);
std::copy(non_one_values.begin(), non_one_values.end(),
safe_values.begin());
}
std::mt19937 mersenne_twister_engine(10000);
std::shuffle(safe_values.begin(), safe_values.end(),
mersenne_twister_engine);
}

View File

@@ -34,24 +34,17 @@ extern MTdata gMTdata;
typedef std::bitset<128> bs128;
extern cl_half_rounding_mode g_rounding_mode;
static bs128 cl_uint4_to_bs128(cl_uint4 v)
{
return bs128(v.s0) | (bs128(v.s1) << 32) | (bs128(v.s2) << 64)
| (bs128(v.s3) << 96);
}
bs128 cl_uint4_to_bs128(cl_uint4 v);
cl_uint4 bs128_to_cl_uint4(bs128 v);
cl_uint4 generate_bit_mask(cl_uint subgroup_local_id,
const std::string &mask_type,
cl_uint max_sub_group_size);
static cl_uint4 bs128_to_cl_uint4(bs128 v)
{
bs128 bs128_ffffffff = 0xffffffffU;
cl_uint4 r;
r.s0 = ((v >> 0) & bs128_ffffffff).to_ulong();
r.s1 = ((v >> 32) & bs128_ffffffff).to_ulong();
r.s2 = ((v >> 64) & bs128_ffffffff).to_ulong();
r.s3 = ((v >> 96) & bs128_ffffffff).to_ulong();
return r;
}
// limit possible input values to avoid arithmetic rounding/overflow issues.
// for each subgroup values defined different values
// for rest of workitems set 1 shuffle values
void fill_and_shuffle_safe_values(std::vector<cl_ulong> &safe_values,
int sb_size);
struct WorkGroupParams
{
@@ -270,87 +263,11 @@ enum class ArithmeticOp
logical_xor
};
static const char *const operation_names(ArithmeticOp operation)
{
switch (operation)
{
case ArithmeticOp::add_: return "add";
case ArithmeticOp::max_: return "max";
case ArithmeticOp::min_: return "min";
case ArithmeticOp::mul_: return "mul";
case ArithmeticOp::and_: return "and";
case ArithmeticOp::or_: return "or";
case ArithmeticOp::xor_: return "xor";
case ArithmeticOp::logical_and: return "logical_and";
case ArithmeticOp::logical_or: return "logical_or";
case ArithmeticOp::logical_xor: return "logical_xor";
default: log_error("Unknown operation request\n"); break;
}
return "";
}
static const char *const operation_names(BallotOp operation)
{
switch (operation)
{
case BallotOp::ballot: return "ballot";
case BallotOp::inverse_ballot: return "inverse_ballot";
case BallotOp::ballot_bit_extract: return "bit_extract";
case BallotOp::ballot_bit_count: return "bit_count";
case BallotOp::ballot_inclusive_scan: return "inclusive_scan";
case BallotOp::ballot_exclusive_scan: return "exclusive_scan";
case BallotOp::ballot_find_lsb: return "find_lsb";
case BallotOp::ballot_find_msb: return "find_msb";
case BallotOp::eq_mask: return "eq";
case BallotOp::ge_mask: return "ge";
case BallotOp::gt_mask: return "gt";
case BallotOp::le_mask: return "le";
case BallotOp::lt_mask: return "lt";
default: log_error("Unknown operation request\n"); break;
}
return "";
}
static const char *const operation_names(ShuffleOp operation)
{
switch (operation)
{
case ShuffleOp::shuffle: return "shuffle";
case ShuffleOp::shuffle_up: return "shuffle_up";
case ShuffleOp::shuffle_down: return "shuffle_down";
case ShuffleOp::shuffle_xor: return "shuffle_xor";
case ShuffleOp::rotate: return "rotate";
case ShuffleOp::clustered_rotate: return "clustered_rotate";
default: log_error("Unknown operation request\n"); break;
}
return "";
}
static const char *const operation_names(NonUniformVoteOp operation)
{
switch (operation)
{
case NonUniformVoteOp::all: return "all";
case NonUniformVoteOp::all_equal: return "all_equal";
case NonUniformVoteOp::any: return "any";
case NonUniformVoteOp::elect: return "elect";
default: log_error("Unknown operation request\n"); break;
}
return "";
}
static const char *const operation_names(SubgroupsBroadcastOp operation)
{
switch (operation)
{
case SubgroupsBroadcastOp::broadcast: return "broadcast";
case SubgroupsBroadcastOp::broadcast_first: return "broadcast_first";
case SubgroupsBroadcastOp::non_uniform_broadcast:
return "non_uniform_broadcast";
default: log_error("Unknown operation request\n"); break;
}
return "";
}
const char *const operation_names(ArithmeticOp operation);
const char *const operation_names(BallotOp operation);
const char *const operation_names(ShuffleOp operation);
const char *const operation_names(NonUniformVoteOp operation);
const char *const operation_names(SubgroupsBroadcastOp operation);
class subgroupsAPI {
public:
@@ -1732,15 +1649,9 @@ template <typename Ty, typename Fns, size_t TSIZE = 0> struct test
}
};
static void set_last_workgroup_params(int non_uniform_size,
int &number_of_subgroups,
int subgroup_size, int &workgroup_size,
int &last_subgroup_size)
{
number_of_subgroups = 1 + non_uniform_size / subgroup_size;
last_subgroup_size = non_uniform_size % subgroup_size;
workgroup_size = non_uniform_size;
}
void set_last_workgroup_params(int non_uniform_size, int &number_of_subgroups,
int subgroup_size, int &workgroup_size,
int &last_subgroup_size);
template <typename Ty>
static void set_randomdata_for_subgroup(Ty *workgroup, int wg_offset,