diff options
author | Cedric Nugteren <web@cedricnugteren.nl> | 2016-05-15 20:13:57 +0200 |
---|---|---|
committer | Cedric Nugteren <web@cedricnugteren.nl> | 2016-05-15 20:13:57 +0200 |
commit | 4b6bdd83a224daca05256a49fdc03c4dd4af6fc9 (patch) | |
tree | 224178b4dcc34a5b0c2e4b9030e999cca7aebac9 /src | |
parent | 5e1b2e021f4b746a77619e0ad5ab35d9a0d4df54 (diff) |
Added header with conversions from and to half-precision floating-point
Diffstat (limited to 'src')
-rw-r--r-- | src/tuning/xaxpy.cc | 4 | ||||
-rw-r--r-- | src/utilities.cc | 71 |
2 files changed, 52 insertions, 23 deletions
diff --git a/src/tuning/xaxpy.cc b/src/tuning/xaxpy.cc index 7f62b811..d27cb73d 100644 --- a/src/tuning/xaxpy.cc +++ b/src/tuning/xaxpy.cc @@ -89,8 +89,9 @@ class TuneXaxpy { std::vector<T> &x_vec, std::vector<T> &y_vec, std::vector<T> &, std::vector<T> &, std::vector<T> &, std::vector<T> &) { + auto alpha_buffer = std::vector<T>{args.alpha}; tuner.AddArgumentScalar(static_cast<int>(args.n)); - tuner.AddArgumentScalar(static_cast<typename RealArg<T>::Type>(args.alpha)); + tuner.AddArgumentInput(alpha_buffer); tuner.AddArgumentInput(x_vec); tuner.AddArgumentOutput(y_vec); } @@ -106,7 +107,6 @@ class TuneXaxpy { } // namespace clblast // Shortcuts to the clblast namespace -using half = clblast::half; using float2 = clblast::float2; using double2 = clblast::double2; 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); |