0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-18 16:00:57 +01:00
construct/include/ircd/simt/mean.h

49 lines
1.3 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_MEAN_H
/// Averaging state; this is for computing running averages
/// XXX eventually
struct ircd_math_mean
{
float
last, ///< Last addend.
mean, ///< Computed mean.
sum[4]; ///< Summand spread. TODO XXX
};
#ifdef __OPENCL_C_VERSION__
2021-04-02 21:51:59 +02:00
/// Compute average of all elements in the input. The result is broadcast
/// to all elements of the output.
///
/// provide:
/// li = local thread id
/// ln = local group size
///
2021-04-02 21:51:59 +02:00
inline void
ircd_simt_math_mean_f4lldr(__local float4 *const restrict out,
__local const float4 *const restrict in)
2021-04-02 21:51:59 +02:00
{
const uint
li = get_local_id(0),
ln = get_local_size(0);
2021-04-02 21:51:59 +02:00
out[li] = in[li];
ircd_simt_reduce_add_f4lldr(out);
2021-04-02 21:51:59 +02:00
if(li == 0)
out[li] = ircd_simt_reduce_add_f4(out[li]) / (ln * 4);
2021-04-02 21:51:59 +02:00
ircd_simt_broadcast_f4lldr(out);
2021-04-02 21:51:59 +02:00
}
#endif