-
Notifications
You must be signed in to change notification settings - Fork 1
Number test context precision error, decimal place rounding and bool cast functors and tests #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abstrackt
wants to merge
5
commits into
mis-wut:master
Choose a base branch
from
gprabowski:gpu_project_2023_dev
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1c9152f
Make all libraries local and fix include errors
gprabowski e0e0cae
Force highest CUDA compatible with RAPIDS
gprabowski 47dace0
Fix cuDF includes
gprabowski ed048c5
Add actions and their tests: round and to_bool
gprabowski 6a0c6ea
Fixed test context precision error
abstrackt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| [submodule "third_parties/googletest"] | ||
| path = third_parties/googletest | ||
| url = https://github.com/google/googletest.git | ||
| [submodule "third_parties/fmt"] | ||
| path = third_parties/fmt | ||
| url = https://github.com/fmtlib/fmt.git | ||
| [submodule "third_parties/mp11"] | ||
| path = third_parties/mp11 | ||
| url = git@github.com:mis-wut/mp11.git | ||
| url = https://github.com/boostorg/mp11.git | ||
| [submodule "third_parties/CLI11"] | ||
| path = third_parties/CLI11 | ||
| url = https://github.com/CLIUtils/CLI11.git | ||
| [submodule "third_parties/googletest"] | ||
| path = third_parties/googletest | ||
| url = https://github.com/google/googletest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #ifndef META_JSON_PARSER_ROUND_CUH | ||
| #define META_JSON_PARSER_ROUND_CUH | ||
| #include <type_traits> | ||
| #include <cmath> | ||
| #include <cuda_runtime_api.h> | ||
|
|
||
| /** | ||
| * @tparam Dec represents number of decimal places kept (non-negative integer) | ||
| * @tparam NumT must be a floating point type | ||
| */ | ||
| template <intmax_t Dec, class NumT = float> | ||
| struct RoundFunctor { | ||
| using Num = NumT; | ||
| static_assert(std::is_floating_point<Num>::value, "NumT must be a floating point type."); | ||
| static_assert(Dec >= 0, "Cannot round to negative decimal places"); | ||
|
|
||
| template <class NumberT> inline __device__ Num operator()(NumberT c) const { | ||
| Num val = static_cast<Num>(c); | ||
| Num div = static_cast<Num>(pow(10.0, Dec)); | ||
| val = trunc(val*div)/div; | ||
| return val; | ||
| } | ||
| }; | ||
|
|
||
| #endif //META_JSON_PARSER_ROUND_CUH | ||
24 changes: 24 additions & 0 deletions
24
include/meta_json_parser/action/number_functors/to_bool.cuh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #ifndef META_JSON_PARSER_TO_BOOL_CUH | ||
| #define META_JSON_PARSER_TO_BOOL_CUH | ||
| #include <type_traits> | ||
| #include <cuda_runtime_api.h> | ||
|
|
||
| /** | ||
| * @tparam InT must be an arithmetic type | ||
| * @tparam OuT must be an integral type (default bool) | ||
| */ | ||
| template <class InT> | ||
| struct ToBoolFunctor { | ||
| using In = InT; | ||
|
|
||
| static_assert(std::is_arithmetic<In>::value, "InT must be an arithmetic type."); | ||
|
|
||
| constexpr static In Zero = static_cast<In>(0); | ||
|
|
||
| template <class NumberT> inline __device__ bool operator()(NumberT c) const { | ||
| In val = static_cast<In>(c); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simple cast depending on the sign of the input value |
||
| return val > Zero; | ||
| } | ||
| }; | ||
|
|
||
| #endif //META_JSON_PARSER_TO_BOOL_CUH | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #include <gtest/gtest.h> | ||
| #include <meta_json_parser/action/jrealnumber.cuh> | ||
| #include <meta_json_parser/action/number_functors/round.cuh> | ||
| #include "test_helper.h" | ||
| #include "test_configuration.h" | ||
| #include "test_utility/contexts/number_test_context.cuh" | ||
| #include "test_utility/test_launcher.cuh" | ||
|
|
||
| class RoundTest : public ::testing::Test { }; | ||
|
|
||
| template <intmax_t Dec, class NumT> | ||
| class RoundTestContext : public NumberTestContext<NumT> { | ||
| using Base = NumberTestContext<NumT>; | ||
| using Calculation = typename Base::Calculation; | ||
| public: | ||
| RoundTestContext(size_t testSize, size_t groupSize, unsigned long seed) | ||
| : NumberTestContext<NumT>(testSize, groupSize, seed) { } | ||
|
|
||
| void InsertedNumberCallback(size_t index, Calculation value) override { | ||
| Calculation val = static_cast<Calculation>(value); | ||
| Calculation div = static_cast<Calculation>(pow(10.0, Dec)); | ||
| val = trunc(val*div)/div; | ||
| (Base::m_h_correct)[index] = val; | ||
| } | ||
| }; | ||
|
|
||
| template<class OutTypeT, intmax_t DecT, int GroupSizeT> | ||
| void templated_Round() | ||
| { | ||
| constexpr OutTypeT MinGenerate = -1000.0; | ||
| constexpr OutTypeT MaxGenerate = 1000.0; | ||
| using Functor = RoundFunctor<DecT, OutTypeT>; | ||
| RoundTestContext<DecT, typename Functor::Num> context(TEST_SIZE, GroupSizeT, SEED); | ||
| context.SetMinimumValue(MinGenerate); | ||
| context.SetMaximumValue(MaxGenerate); | ||
| context.Initialize(); | ||
| using Options = boost::mp11::mp_list< | ||
| boost::mp11::mp_list<JRealNumberOptions::JRealNumberTransformer, Functor> | ||
| >; | ||
| using BA = JRealNumber<OutTypeT, void, Options>; | ||
| LaunchTest<BA, boost::mp11::mp_int<GroupSizeT>>(context); | ||
| } | ||
|
|
||
| #define META_ParseJRealNumberTests(WS)\ | ||
| TEST_F(RoundTest, float_W##WS) {\ | ||
| templated_Round<float, 1, WS>();\ | ||
| }\ | ||
| TEST_F(RoundTest, double_W##WS) {\ | ||
| templated_Round<double, 1, WS>();\ | ||
| }\ | ||
|
|
||
| META_WS_4(META_ParseJRealNumberTests) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #include <gtest/gtest.h> | ||
| #include <meta_json_parser/action/jnumber.cuh> | ||
| #include <meta_json_parser/action/number_functors/to_bool.cuh> | ||
| #include "test_helper.h" | ||
| #include "test_configuration.h" | ||
| #include "test_utility/contexts/number_test_context.cuh" | ||
| #include "test_utility/test_launcher.cuh" | ||
|
|
||
| class ToBoolTest : public ::testing::Test { }; | ||
|
|
||
| template <class InT> | ||
| class ToBoolTestContext : public NumberTestContext<InT> { | ||
| using Base = NumberTestContext<InT>; | ||
| using Calculation = typename Base::Calculation; | ||
| constexpr static InT Zero = static_cast<InT>(0); | ||
| public: | ||
| ToBoolTestContext(size_t testSize, size_t groupSize, unsigned long seed) | ||
| : NumberTestContext<InT>(testSize, groupSize, seed) { } | ||
|
|
||
| void InsertedNumberCallback(size_t index, Calculation value) override { | ||
| Calculation result = static_cast<Calculation>(value > Zero); | ||
| (Base::m_h_correct)[index] = result; | ||
| } | ||
| }; | ||
|
|
||
| template<class OutTypeT, int GroupSizeT> | ||
| void templated_ToBool() | ||
| { | ||
| constexpr OutTypeT MinGenerate = -1000; | ||
| constexpr OutTypeT MaxGenerate = 1000; | ||
| using Functor = ToBoolFunctor<OutTypeT>; | ||
| ToBoolTestContext<typename Functor::In> context(TEST_SIZE, GroupSizeT, SEED); | ||
| context.SetMinimumValue(MinGenerate); | ||
| context.SetMaximumValue(MaxGenerate); | ||
| context.Initialize(); | ||
| using Options = boost::mp11::mp_list< | ||
| boost::mp11::mp_list<JNumberOptions::JNumberTransformer, Functor> | ||
| >; | ||
| using BA = JNumber<OutTypeT, void, Options>; | ||
| LaunchTest<BA, boost::mp11::mp_int<GroupSizeT>>(context); | ||
| } | ||
|
|
||
| #define META_ParseJBooleanTests(WS)\ | ||
| TEST_F(ToBoolTest, int32_W##WS) {\ | ||
| templated_ToBool<int32_t, WS>();\ | ||
| }\ | ||
| META_WS_4(META_ParseJBooleanTests) |
Submodule googletest
updated
245 files
Submodule mp11
updated
from 19c1a9 to 773ec9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiply by a power of 10, truncate to the nearest integer to cut the remaining decimal places and divide to revert to the original value.