From ac1575056e0f3d7406cc7bcbbdbe71b08feb58ce Mon Sep 17 00:00:00 2001 From: Cedric Nugteren Date: Tue, 24 May 2016 14:06:16 +0200 Subject: Added proper argument handling and displaying for half-precision data-types --- README.md | 2 +- src/utilities.cc | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3b4b789e..f1a50ff4 100644 --- a/README.md +++ b/README.md @@ -200,7 +200,7 @@ CLBlast is in active development but already supports almost all the BLAS routin | IxAMAX | ✔ | ✔ | ✔ | ✔ | ✔ | | Level-2 | S | D | C | Z | H | -| ---------|---|---|---|---| --| +| ---------|---|---|---|---|---| | xGEMV | ✔ | ✔ | ✔ | ✔ | ✔ | | xGBMV | ✔ | ✔ | ✔ | ✔ | ✔ | | xHEMV | - | - | ✔ | ✔ | - | diff --git a/src/utilities.cc b/src/utilities.cc index 477f4a5f..1a7c8e45 100644 --- a/src/utilities.cc +++ b/src/utilities.cc @@ -79,7 +79,6 @@ std::string ToString(T value) { } template std::string ToString(int value); template std::string ToString(size_t value); -template std::string ToString(half value); template std::string ToString(float value); template std::string ToString(double value); @@ -99,6 +98,12 @@ std::string ToString(double2 value) { return real.str()+"+"+imag.str()+"i"; } +// If not possible directly: special case for half-precision +template <> +std::string ToString(half value) { + return std::to_string(HalfToFloat(value)); +} + // If not possible directly: special cases for CLBlast data-types template <> std::string ToString(Layout value) { @@ -157,7 +162,7 @@ T ConvertArgument(const char* value) { return static_cast(std::stoi(value)); } template <> half ConvertArgument(const char* value) { - return static_cast(std::stod(value)); + return FloatToHalf(static_cast(std::stod(value))); } template <> float ConvertArgument(const char* value) { return static_cast(std::stod(value)); @@ -285,11 +290,11 @@ void PopulateVector(std::vector &vector) { // Specialized versions of the above for half-precision template <> void PopulateVector(std::vector &vector) { - auto lower_limit = static_cast(kTestDataLowerLimit); - auto upper_limit = static_cast(kTestDataUpperLimit); + const auto lower_limit = static_cast(kTestDataLowerLimit); + const auto upper_limit = static_cast(kTestDataUpperLimit); std::mt19937 mt(GetRandomSeed()); std::uniform_real_distribution dist(lower_limit, upper_limit); - for (auto &element: vector) { element = static_cast(dist(mt)); } + for (auto &element: vector) { element = FloatToHalf(dist(mt)); } } // ================================================================================================= -- cgit v1.2.3