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_NORM_H
|
|
|
|
|
2021-11-10 00:47:27 +01:00
|
|
|
#ifdef __OPENCL_VERSION__
|
2021-04-02 21:51:59 +02:00
|
|
|
/// Normalize the input, placing the result in possibly overlapping output.
|
|
|
|
/// This procedure requires an additional temporary buffer.
|
|
|
|
inline void
|
|
|
|
ircd_simt_math_norm_f4lldr(__local float4 *const out,
|
|
|
|
__local const float4 *const in,
|
2021-11-06 03:26:39 +01:00
|
|
|
__local float4 *const restrict tmp,
|
|
|
|
const uint ln,
|
|
|
|
const uint li)
|
2021-04-02 21:51:59 +02:00
|
|
|
{
|
2022-01-07 19:59:31 +01:00
|
|
|
tmp[li] = in[li];
|
|
|
|
ircd_simt_math_mean_f4lldr(tmp, ln, li);
|
2021-04-02 21:51:59 +02:00
|
|
|
|
|
|
|
const float4
|
2022-03-05 21:56:05 +01:00
|
|
|
sub_mean = in[li] - tmp[li],
|
|
|
|
sub_mean_sqr = pow(sub_mean, 2);
|
2021-04-02 21:51:59 +02:00
|
|
|
|
2022-03-05 21:56:05 +01:00
|
|
|
out[li] = sub_mean_sqr;
|
|
|
|
ircd_simt_math_mean_f4lldr(out, ln, li);
|
2021-04-02 21:51:59 +02:00
|
|
|
|
|
|
|
const float4
|
2022-03-05 21:56:05 +01:00
|
|
|
epsilon = FLT_EPSILON,
|
|
|
|
s = native_sqrt(out[li] + epsilon),
|
|
|
|
res = sub_mean / s;
|
2021-04-02 21:51:59 +02:00
|
|
|
|
2022-03-05 21:56:05 +01:00
|
|
|
out[li] = res;
|
2021-04-02 21:51:59 +02:00
|
|
|
}
|
2021-05-02 23:43:10 +02:00
|
|
|
#endif
|