summaryrefslogtreecommitdiff
path: root/src/utilities.cc
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2016-05-15 20:13:57 +0200
committerCedric Nugteren <web@cedricnugteren.nl>2016-05-15 20:13:57 +0200
commit4b6bdd83a224daca05256a49fdc03c4dd4af6fc9 (patch)
tree224178b4dcc34a5b0c2e4b9030e999cca7aebac9 /src/utilities.cc
parent5e1b2e021f4b746a77619e0ad5ab35d9a0d4df54 (diff)
Added header with conversions from and to half-precision floating-point
Diffstat (limited to 'src/utilities.cc')
-rw-r--r--src/utilities.cc71
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);