diff options
Diffstat (limited to 'src/utilities.cc')
-rw-r--r-- | src/utilities.cc | 71 |
1 files changed, 50 insertions, 21 deletions
diff --git a/src/utilities.cc b/src/utilities.cc index 5325c3e8..477f4a5f 100644 --- a/src/utilities.cc +++ b/src/utilities.cc @@ -22,6 +22,56 @@ namespace clblast { // ================================================================================================= +// Returns a scalar with a default value +template <typename T> +T GetScalar() { + return static_cast<T>(2.0); +} +template float GetScalar<float>(); +template double GetScalar<double>(); + +// Specialized version of the above for half-precision +template <> +half GetScalar() { + return FloatToHalf(2.0f); +} + +// Specialized versions of the above for complex data-types +template <> +float2 GetScalar() { + return {2.0f, 0.5f}; +} +template <> +double2 GetScalar() { + return {2.0, 0.5}; +} + +// Returns a scalar of value 1 +template <typename T> +T ConstantOne() { + return static_cast<T>(1.0); +} +template float ConstantOne<float>(); +template double ConstantOne<double>(); + +// Specialized version of the above for half-precision +template <> +half ConstantOne() { + return FloatToHalf(1.0f); +} + +// Specialized versions of the above for complex data-types +template <> +float2 ConstantOne() { + return {1.0f, 0.0f}; +} +template <> +double2 ConstantOne() { + return {1.0, 0.0}; +} + +// ================================================================================================= + // Implements the string conversion using std::to_string if possible template <typename T> std::string ToString(T value) { @@ -244,27 +294,6 @@ void PopulateVector(std::vector<half> &vector) { // ================================================================================================= -// Returns a scalar with a default value -template <typename T> -T GetScalar() { - return static_cast<T>(2.0); -} -template half GetScalar<half>(); -template float GetScalar<float>(); -template double GetScalar<double>(); - -// Specialized versions of the above for complex data-types -template <> -float2 GetScalar() { - return {2.0f, 0.5f}; -} -template <> -double2 GetScalar() { - return {2.0, 0.5}; -} - -// ================================================================================================= - // Rounding functions performing ceiling and division operations size_t CeilDiv(const size_t x, const size_t y) { return 1 + ((x - 1) / y); |