From 2f226134a8797e034b7a8b859fff409020edbb43 Mon Sep 17 00:00:00 2001 From: Conor Hoekstra Date: Wed, 3 Feb 2021 20:17:55 -0500 Subject: [PATCH 1/5] Use string literals in release_assert --- cpp/include/cudf/fixed_point/fixed_point.hpp | 26 +++----------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/cpp/include/cudf/fixed_point/fixed_point.hpp b/cpp/include/cudf/fixed_point/fixed_point.hpp index c8e2ac01f41..cbd23b5680f 100644 --- a/cpp/include/cudf/fixed_point/fixed_point.hpp +++ b/cpp/include/cudf/fixed_point/fixed_point.hpp @@ -550,22 +550,6 @@ class fixed_point { } }; // namespace numeric -/** @brief Function that converts Rep to `std::string` - * - * @tparam Rep Representation type - * @return String-ified Rep - */ -template -std::string print_rep() -{ - if (cuda::std::is_same::value) - return "int32_t"; - else if (cuda::std::is_same::value) - return "int64_t"; - else - return "unknown type"; -} - /** @brief Function for identifying integer overflow when adding * * @tparam Rep Type of integer to check for overflow on @@ -642,7 +626,7 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point operator+(fixed_point(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) && - "fixed_point overflow of underlying representation type " + print_rep()); + "fixed_point overflow"); #endif @@ -661,7 +645,7 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point operator-(fixed_point(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) && - "fixed_point overflow of underlying representation type " + print_rep()); + "fixed_point overflow"); #endif @@ -675,8 +659,7 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point operator*(fixed_point(lhs._value, rhs._value) && - "fixed_point overflow of underlying representation type " + print_rep()); + release_assert(!multiplication_overflow(lhs._value, rhs._value) && "fixed_point overflow"); #endif @@ -691,8 +674,7 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point operator/(fixed_point(lhs._value, rhs._value) && - "fixed_point overflow of underlying representation type " + print_rep()); + release_assert(!division_overflow(lhs._value, rhs._value) && "fixed_point overflow"); #endif From 90136e92c92baaeb2992fcdd7d3c337146258f4c Mon Sep 17 00:00:00 2001 From: Conor Hoekstra <36027403+codereport@users.noreply.github.com> Date: Wed, 3 Feb 2021 21:04:53 -0500 Subject: [PATCH 2/5] Copyright --- cpp/include/cudf/fixed_point/fixed_point.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/include/cudf/fixed_point/fixed_point.hpp b/cpp/include/cudf/fixed_point/fixed_point.hpp index cbd23b5680f..205649a688e 100644 --- a/cpp/include/cudf/fixed_point/fixed_point.hpp +++ b/cpp/include/cudf/fixed_point/fixed_point.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, NVIDIA CORPORATION. + * Copyright (c) 2020-2021, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 1076d846fb53492a08c141626a011d907c89d640 Mon Sep 17 00:00:00 2001 From: Conor Hoekstra <36027403+codereport@users.noreply.github.com> Date: Wed, 3 Feb 2021 21:23:03 -0500 Subject: [PATCH 3/5] Use assert --- cpp/include/cudf/fixed_point/fixed_point.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cpp/include/cudf/fixed_point/fixed_point.hpp b/cpp/include/cudf/fixed_point/fixed_point.hpp index 205649a688e..ae685e2c57f 100644 --- a/cpp/include/cudf/fixed_point/fixed_point.hpp +++ b/cpp/include/cudf/fixed_point/fixed_point.hpp @@ -27,6 +27,7 @@ #include #include #include +#include //! `fixed_point` and supporting types namespace numeric { @@ -625,7 +626,7 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point operator+(fixed_point(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) && + assert(!addition_overflow(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) && "fixed_point overflow"); #endif @@ -643,7 +644,7 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point operator-(fixed_point(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) && "fixed_point overflow"); @@ -659,7 +660,7 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point operator*(fixed_point(lhs._value, rhs._value) && "fixed_point overflow"); + assert(!multiplication_overflow(lhs._value, rhs._value) && "fixed_point overflow"); #endif @@ -674,7 +675,7 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point operator/(fixed_point(lhs._value, rhs._value) && "fixed_point overflow"); + assert(!division_overflow(lhs._value, rhs._value) && "fixed_point overflow"); #endif From dac254a23dbe467ae460532defa03bddd06cf1e1 Mon Sep 17 00:00:00 2001 From: Conor Hoekstra <36027403+codereport@users.noreply.github.com> Date: Wed, 3 Feb 2021 21:27:22 -0500 Subject: [PATCH 4/5] Clang format --- cpp/include/cudf/fixed_point/fixed_point.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cpp/include/cudf/fixed_point/fixed_point.hpp b/cpp/include/cudf/fixed_point/fixed_point.hpp index ae685e2c57f..82b1e22f135 100644 --- a/cpp/include/cudf/fixed_point/fixed_point.hpp +++ b/cpp/include/cudf/fixed_point/fixed_point.hpp @@ -627,7 +627,7 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point operator+(fixed_point(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) && - "fixed_point overflow"); + "fixed_point overflow"); #endif @@ -644,9 +644,8 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point operator-(fixed_point(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) && - "fixed_point overflow"); + assert(!subtraction_overflow(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) && + "fixed_point overflow"); #endif From eb7027983a2065e9f1c3fba705c915426a835ad7 Mon Sep 17 00:00:00 2001 From: Conor Hoekstra Date: Wed, 3 Feb 2021 21:50:16 -0500 Subject: [PATCH 5/5] Clang format (not by hand) --- cpp/include/cudf/fixed_point/fixed_point.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/include/cudf/fixed_point/fixed_point.hpp b/cpp/include/cudf/fixed_point/fixed_point.hpp index 82b1e22f135..20246022d8e 100644 --- a/cpp/include/cudf/fixed_point/fixed_point.hpp +++ b/cpp/include/cudf/fixed_point/fixed_point.hpp @@ -25,9 +25,9 @@ #include // add cuda namespace #include +#include #include #include -#include //! `fixed_point` and supporting types namespace numeric {