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_MEAN_H
|
|
|
|
|
2021-05-02 23:51:49 +02:00
|
|
|
/// Averaging state; this is for computing running averages
|
|
|
|
/// XXX eventually
|
|
|
|
struct ircd_math_mean
|
|
|
|
{
|
2022-06-20 03:51:50 +02:00
|
|
|
/// Summand spread. TODO XXX
|
|
|
|
float sum[4];
|
|
|
|
|
|
|
|
/// Divisor.
|
|
|
|
uint div;
|
|
|
|
|
|
|
|
/// Last addend.
|
|
|
|
float last;
|
|
|
|
|
|
|
|
/// Computed mean.
|
|
|
|
float mean;
|
2021-05-02 23:51:49 +02:00
|
|
|
};
|
|
|
|
|
2021-11-10 00:47:27 +01:00
|
|
|
#ifdef __OPENCL_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.
|
2021-04-15 19:07:17 +02:00
|
|
|
///
|
|
|
|
/// provide:
|
|
|
|
/// li = local thread id
|
|
|
|
/// ln = local group size
|
|
|
|
///
|
2021-04-02 21:51:59 +02:00
|
|
|
inline void
|
2022-01-07 19:59:31 +01:00
|
|
|
ircd_simt_math_mean_f4lldr(__local float4 *const buf,
|
2021-11-06 03:26:39 +01:00
|
|
|
const uint ln,
|
|
|
|
const uint li)
|
2021-04-02 21:51:59 +02:00
|
|
|
{
|
2022-01-07 19:59:31 +01:00
|
|
|
ircd_simt_reduce_add_f4lldr(buf, ln, li);
|
2021-04-02 21:51:59 +02:00
|
|
|
|
2021-04-15 19:07:17 +02:00
|
|
|
if(li == 0)
|
2022-01-07 19:59:31 +01:00
|
|
|
{
|
|
|
|
const float
|
|
|
|
sum = ircd_simt_reduce_add_f4(buf[li]),
|
2022-01-23 20:04:23 +01:00
|
|
|
div = ln * 4,
|
|
|
|
res = sum / div;
|
2021-04-02 21:51:59 +02:00
|
|
|
|
2022-01-07 19:59:31 +01:00
|
|
|
buf[li] = res;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd_simt_broadcast_f4lldr(buf, ln, li);
|
2021-04-02 21:51:59 +02:00
|
|
|
}
|
2021-05-02 23:43:10 +02:00
|
|
|
#endif
|