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.
|
|
|
|
|
2021-05-02 23:43:10 +02:00
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_SIMT_REDUCE_ADD_H
|
|
|
|
|
2021-11-10 00:47:27 +01:00
|
|
|
#ifdef __OPENCL_VERSION__
|
2021-04-02 21:51:59 +02:00
|
|
|
/// Sum all elements in the buffer. All threads in the group participate;
|
|
|
|
/// result is placed in index [0], the rest of the buffer is trashed.
|
|
|
|
inline void
|
2021-11-06 03:26:39 +01:00
|
|
|
ircd_simt_reduce_add_f4lldr(__local float4 *const buf,
|
|
|
|
const uint ln,
|
|
|
|
const uint li)
|
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)
|
|
|
|
buf[li] += buf[li + stride];
|
|
|
|
}
|
2022-02-21 20:05:42 +01:00
|
|
|
|
|
|
|
if(!ircd_math_is_pow2(ln) && li == 0)
|
|
|
|
buf[li] += buf[li + 2];
|
2021-04-02 21:51:59 +02:00
|
|
|
}
|
2021-05-02 23:43:10 +02:00
|
|
|
#endif
|
2021-04-02 21:51:59 +02:00
|
|
|
|
2021-11-10 00:47:27 +01:00
|
|
|
#ifdef __OPENCL_VERSION__
|
2021-04-15 18:02:44 +02:00
|
|
|
/// Sum all elements in the buffer. All threads in the group participate;
|
|
|
|
/// result is placed in index [0], the rest of the buffer is trashed.
|
2022-01-23 20:03:32 +01:00
|
|
|
inline void
|
|
|
|
ircd_simt_reduce_add_flldr(__local float *const buf,
|
|
|
|
const uint ln,
|
|
|
|
const uint li)
|
2022-11-23 02:30:10 +01:00
|
|
|
#if defined(cl_khr_subgroups)
|
|
|
|
{
|
|
|
|
const float
|
|
|
|
ret = work_group_reduce_add(buf[li]);
|
|
|
|
|
|
|
|
if(li == 0)
|
|
|
|
buf[li] = ret;
|
|
|
|
}
|
|
|
|
#else
|
2022-01-23 20:03:32 +01:00
|
|
|
{
|
|
|
|
for(uint stride = ln >> 1; stride > 0; stride >>= 1)
|
|
|
|
{
|
|
|
|
barrier(CLK_LOCAL_MEM_FENCE);
|
|
|
|
|
|
|
|
if(li < stride)
|
|
|
|
buf[li] += buf[li + stride];
|
|
|
|
}
|
2022-02-21 20:05:42 +01:00
|
|
|
|
|
|
|
if(!ircd_math_is_pow2(ln) && li == 0)
|
|
|
|
buf[li] += buf[li + 2];
|
2022-01-23 20:03:32 +01:00
|
|
|
}
|
|
|
|
#endif
|
2022-11-23 02:30:10 +01:00
|
|
|
#endif
|
2022-01-23 20:03:32 +01:00
|
|
|
|
|
|
|
#ifdef __OPENCL_VERSION__
|
|
|
|
/// Sum all elements in the buffer. All threads in the group participate;
|
|
|
|
/// result is placed in index [0], the rest of the buffer is trashed.
|
|
|
|
inline void
|
|
|
|
ircd_simt_reduce_add_illdr(__local int *const buf,
|
|
|
|
const uint ln,
|
|
|
|
const uint li)
|
|
|
|
{
|
|
|
|
if(li > 0)
|
|
|
|
atomic_add(buf + 0, buf[li]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __OPENCL_VERSION__
|
|
|
|
/// Sum all elements in the buffer. All threads in the group participate;
|
|
|
|
/// result is placed in index [0], the rest of the buffer is trashed.
|
|
|
|
inline void
|
|
|
|
ircd_simt_reduce_add_ulldr(__local uint *const buf,
|
|
|
|
const uint ln,
|
|
|
|
const uint li)
|
|
|
|
{
|
|
|
|
if(li > 0)
|
|
|
|
atomic_add(buf + 0, buf[li]);
|
|
|
|
}
|
|
|
|
#endif
|