Skip to content

Commit 4ebc428

Browse files
pkwasnie-inteligcbot
authored andcommitted
new intrinsic: subgroup clustered sort
Adds new intrinsic: subgroup clustered sort. This commit only exposes subgroup sort available in group_sort.cl as part of workgroup sort.
1 parent 22a716e commit 4ebc428

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

IGC/AdaptorOCL/ocl_igc_interface/igc_builtins.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ CIF_DEFINE_INTERFACE_VER(IgcBuiltins, 1) {
3030
using AlgorithmCoder = CIF::Coder<Algorithm_t>;
3131

3232
static constexpr auto sort = AlgorithmCoder::Enc("SORT");
33+
static constexpr auto clusteredSort = AlgorithmCoder::Enc("CLUSTER_SORT");
3334
} BuiltinAlgorithm;
3435

3536
typedef struct BuiltinMemoryType {

IGC/AdaptorOCL/ocl_igc_interface/impl/igc_builtins_impl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,15 @@ bool CIF_GET_INTERFACE_CLASS(IgcBuiltins, 1)::GetBuiltinMemoryRequired(IGCBuilti
5959
switch(algorithm)
6060
{
6161
case BuiltinAlgorithm::sort:
62+
case BuiltinAlgorithm::clusteredSort:
6263
{
6364
const size_t bits_per_pass = 4;
6465

66+
if ((algorithm == BuiltinAlgorithm::clusteredSort) && (scope != BuiltinMemoryScope::subGroup))
67+
{
68+
return false;
69+
}
70+
6571
if (scope == BuiltinMemoryScope::subGroup)
6672
{
6773
if ((variant != SortAlgorithmVariant::defaultPrivateSort) || (items > 1) ||

IGC/BiFModule/Implementation/group_sort.cl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,3 +1425,43 @@ DEFN_DEFAULT_WORK_GROUP_SORT_KEY_VALUE_ALL(half, f16, double, f64)
14251425
DEFN_DEFAULT_WORK_GROUP_SORT_KEY_VALUE_ALL(float, f32, double, f64)
14261426
DEFN_DEFAULT_WORK_GROUP_SORT_KEY_VALUE_ALL(double, f64, double, f64)
14271427
#endif //cl_khr_fp64
1428+
1429+
1430+
// Expose the sub-group sort functions functions as clustered sub-group sort.
1431+
#define DEFN_CLUSTERED_SUB_GROUP_SORT_KEY_ONLY(type,type_abbr, direction, is_asc) \
1432+
type __builtin_IB_sub_group_clustered_sort_##direction##_##type_abbr( \
1433+
type value,uint cluster_size) \
1434+
{ \
1435+
type sorted; \
1436+
switch (cluster_size) \
1437+
{ \
1438+
case 8: \
1439+
sorted = __builtin_sub_group_sort8(value, is_asc); \
1440+
break; \
1441+
case 16: \
1442+
sorted = __builtin_sub_group_sort16(value, is_asc); \
1443+
break; \
1444+
case 32: \
1445+
sorted = __builtin_sub_group_sort32(value, is_asc); \
1446+
break; \
1447+
default: \
1448+
break; \
1449+
} \
1450+
return sorted; \
1451+
}
1452+
1453+
#define DEFN_CLUSTERED_SUB_GROUP_SORT(type, type_abbr) \
1454+
DEFN_CLUSTERED_SUB_GROUP_SORT_KEY_ONLY(type, type_abbr, ascend, true) \
1455+
DEFN_CLUSTERED_SUB_GROUP_SORT_KEY_ONLY(type, type_abbr, descend, false)
1456+
1457+
DEFN_CLUSTERED_SUB_GROUP_SORT(char, i8)
1458+
DEFN_CLUSTERED_SUB_GROUP_SORT(short, i16)
1459+
DEFN_CLUSTERED_SUB_GROUP_SORT(int, i32)
1460+
DEFN_CLUSTERED_SUB_GROUP_SORT(long, i64)
1461+
DEFN_CLUSTERED_SUB_GROUP_SORT(float, f32)
1462+
#if defined(cl_khr_fp64)
1463+
DEFN_CLUSTERED_SUB_GROUP_SORT(double, f64)
1464+
#endif // defined(cl_khr_fp64)
1465+
#if defined(cl_khr_fp16)
1466+
DEFN_CLUSTERED_SUB_GROUP_SORT(half, f16)
1467+
#endif // defined(cl_khr_fp16)

0 commit comments

Comments
 (0)