0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-11 08:02:59 +01:00
construct/include/ircd/simt/reduce_max.h

67 lines
1.7 KiB
C
Raw Normal View History

2021-04-02 21:51:59 +02:00
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2021 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_SIMT_REDUCE_MAX_H
#ifdef __OPENCL_VERSION__
2021-04-02 21:51:59 +02:00
/// Find the greatest value in the buffer. All threads in the group participate;
/// the greatest value is placed in index [0], the rest of the buffer is
/// trashed.
inline void
ircd_simt_reduce_max_flldr(__local float *const buf,
const uint ln,
const uint li)
#if defined(cl_khr_subgroups)
{
const float
ret = work_group_reduce_max(buf[li]);
if(li == 0)
buf[li] = ret;
}
#else
2021-04-02 21:51:59 +02:00
{
for(uint stride = ln >> 1; stride > 0; stride >>= 1)
{
barrier(CLK_LOCAL_MEM_FENCE);
if(li < stride)
if(buf[li] < buf[li + stride])
buf[li] = buf[li + stride];
2021-04-02 21:51:59 +02:00
}
if(!ircd_math_is_pow2(ln) && li == 0)
if(buf[li] < buf[li + 2])
buf[li] = buf[li + 2];
2021-04-02 21:51:59 +02:00
}
#endif
#endif
2022-01-23 20:48:23 +01:00
#ifdef __OPENCL_VERSION__
inline void
ircd_simt_reduce_max_illdr(__local int *const buf,
const uint ln,
const uint li)
{
buf[li] = atomic_max(buf, buf[li]);
}
#endif
#ifdef __OPENCL_VERSION__
inline void
ircd_simt_reduce_max_ulldr(__local uint *const buf,
const uint ln,
const uint li)
{
buf[li] = atomic_max(buf, buf[li]);
}
#endif