diff options
author | Cedric Nugteren <web@cedricnugteren.nl> | 2017-11-19 20:05:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-19 20:05:15 +0100 |
commit | da76d7ab81555452a1049eb1a6d130073427067d (patch) | |
tree | 92439d8bee44c34d63f288a73bdc372ba84dc42b /src/utilities/utilities.cpp | |
parent | c41d219ea42087c1b8d933b733b381005123cb91 (diff) | |
parent | defad3d1a249dd5f8c011cf28cc3c888d710d56a (diff) |
Merge pull request #216 from CNugteren/integrated_tuner
Integrated tuner
Diffstat (limited to 'src/utilities/utilities.cpp')
-rw-r--r-- | src/utilities/utilities.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/utilities/utilities.cpp b/src/utilities/utilities.cpp index f2574104..1546fbf5 100644 --- a/src/utilities/utilities.cpp +++ b/src/utilities/utilities.cpp @@ -397,6 +397,37 @@ template <> bool PrecisionSupported<half>(const Device &device) { return device. // ================================================================================================= +// Retrieves the squared difference, used for example for computing the L2 error +template <typename T> +double SquaredDifference(const T val1, const T val2) { + const auto difference = (val1 - val2); + return static_cast<double>(difference * difference); +} + +// Compiles the default case for standard data-types +template double SquaredDifference<float>(const float, const float); +template double SquaredDifference<double>(const double, const double); + +// Specialisations for non-standard data-types +template <> +double SquaredDifference(const float2 val1, const float2 val2) { + const auto real = SquaredDifference(val1.real(), val2.real()); + const auto imag = SquaredDifference(val1.imag(), val2.imag()); + return real + imag; +} +template <> +double SquaredDifference(const double2 val1, const double2 val2) { + const auto real = SquaredDifference(val1.real(), val2.real()); + const auto imag = SquaredDifference(val1.imag(), val2.imag()); + return real + imag; +} +template <> +double SquaredDifference(const half val1, const half val2) { + return SquaredDifference(HalfToFloat(val1), HalfToFloat(val2)); +} + +// ================================================================================================= + // High-level info std::string GetDeviceType(const Device& device) { return device.Type(); |