-
Notifications
You must be signed in to change notification settings - Fork 622
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
Reduce Sum Op #2379
Merged
Merged
Reduce Sum Op #2379
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6c20f54
Add sum op
awolant e47e965
Sum op implementation
awolant e55bd4a
Merge branch 'master' into reduce_sum_op
awolant 03126f5
Fix license
awolant cbd5a8a
Remove Mean
awolant ff2bfc0
Rename dtype param
awolant b176284
Merge branch 'master' into reduce_sum_op
awolant 4da42e6
Static map tests
awolant 10df331
Static map docs
awolant abba831
Fix lint
awolant 809ce9c
Add CPU only tests
awolant 596a759
Move ops to reductions module
awolant 5b5ef71
Fix review
awolant 56f3174
Fix for review
awolant 269cbb2
Fix review
awolant c3d7c48
Add output type promotion
awolant 195b731
Fix lint
awolant 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 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 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 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 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,121 @@ | ||
// Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <gtest/gtest.h> | ||
#include <typeinfo> | ||
#include <vector> | ||
#include <unordered_map> | ||
|
||
#include "dali/kernels/kernel.h" | ||
#include "dali/core/static_map.h" | ||
#include "dali/kernels/type_tag.h" | ||
|
||
#define TEST_TYPES_MAP ( \ | ||
((uint8_t), (uint8_t, uint64_t, float)), \ | ||
((int8_t), (int64_t)), \ | ||
((uint16_t), (uint16_t, uint64_t)), \ | ||
((int16_t), (int16_t)), \ | ||
((uint32_t), (uint32_t, float)), \ | ||
((int32_t), (int32_t)), \ | ||
((int64_t), (int64_t)), \ | ||
((float), (float))) | ||
|
||
namespace { | ||
template <typename T, typename S> | ||
void TypedFunc() {} | ||
|
||
using TypeTagMap = std::unordered_map<int, std::vector<int>>; | ||
|
||
template <typename T> | ||
struct StaticMap : public testing::Test { | ||
StaticMap() { | ||
type_mapping_[dali::TypeTag<uint8_t>()] = { | ||
dali::TypeTag<uint8_t>(), dali::TypeTag<uint64_t>(), dali::TypeTag<float>() }; | ||
type_mapping_[dali::TypeTag<int8_t>()] = { dali::TypeTag<int64_t>() }; | ||
type_mapping_[dali::TypeTag<uint16_t>()] = { | ||
dali::TypeTag<uint16_t>(), dali::TypeTag<uint64_t>() }; | ||
type_mapping_[dali::TypeTag<int16_t>()] = { dali::TypeTag<int16_t>() }; | ||
type_mapping_[dali::TypeTag<uint32_t>()] = { | ||
dali::TypeTag<uint32_t>(), dali::TypeTag<float>() }; | ||
type_mapping_[dali::TypeTag<int32_t>()] = { dali::TypeTag<int32_t>() }; | ||
type_mapping_[dali::TypeTag<int64_t>()] = { dali::TypeTag<int64_t>() }; | ||
type_mapping_[dali::TypeTag<float>()] = { dali::TypeTag<float>() }; | ||
} | ||
|
||
protected: | ||
template <typename P, typename R> | ||
void TypedMethod(int input_arg_type, int output_arg_type) { | ||
int input_call_type = dali::TypeTag<P>(); | ||
int output_call_type = dali::TypeTag<R>(); | ||
|
||
ASSERT_EQ(input_arg_type, input_call_type); | ||
ASSERT_EQ(output_arg_type, output_call_type); | ||
} | ||
TypeTagMap type_mapping_; | ||
}; | ||
|
||
} // namespace | ||
|
||
typedef testing::Types< | ||
uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, int64_t, float> TypesToTest; | ||
|
||
TYPED_TEST_SUITE(StaticMap, TypesToTest); | ||
|
||
TYPED_TEST(StaticMap, ValidTypes) { | ||
using TestedType = gtest_TypeParam_; | ||
|
||
int input_type = dali::TypeTag<TestedType>(); | ||
for (auto &output_type : this->type_mapping_[input_type]) { | ||
TYPE_MAP( | ||
input_type, | ||
output_type, | ||
dali::TypeTag, | ||
InputType, | ||
OutputType, | ||
TEST_TYPES_MAP, | ||
(this->template TypedMethod<InputType, OutputType>(input_type, output_type);), | ||
(FAIL()), | ||
(FAIL())) | ||
} | ||
} | ||
|
||
TEST(StaticMapFailure, InvalidInputType) { | ||
int input_type = dali::TypeTag<uint64_t>(); | ||
int output_type = dali::TypeTag<int32_t>(); | ||
TYPE_MAP( | ||
input_type, | ||
output_type, | ||
dali::TypeTag, | ||
InputType, | ||
OutputType, | ||
TEST_TYPES_MAP, | ||
(TypedFunc<InputType, OutputType>(); FAIL();), | ||
(SUCCEED()), | ||
(FAIL())) | ||
} | ||
|
||
TEST(StaticMapFailure, InvalidOutputType) { | ||
int input_type = dali::TypeTag<float>(); | ||
int output_type = dali::TypeTag<int32_t>(); | ||
TYPE_MAP( | ||
input_type, | ||
output_type, | ||
dali::TypeTag, | ||
InputType, | ||
OutputType, | ||
TEST_TYPES_MAP, | ||
(TypedFunc<InputType, OutputType>(); FAIL();), | ||
(FAIL()), | ||
(SUCCEED())) | ||
} |
This file contains 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,121 @@ | ||
// Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <gtest/gtest.h> | ||
#include <typeinfo> | ||
#include <vector> | ||
#include <unordered_map> | ||
|
||
#include "dali/kernels/kernel.h" | ||
#include "dali/core/static_map.h" | ||
#include "dali/kernels/type_tag.h" | ||
|
||
#define TEST_TYPES_MAP ( \ | ||
((uint8_t), (uint8_t, uint64_t, float)), \ | ||
((int8_t), (int64_t)), \ | ||
((uint16_t), (uint16_t, uint64_t)), \ | ||
((int16_t), (int16_t)), \ | ||
((uint32_t), (uint32_t, float)), \ | ||
((int32_t), (int32_t)), \ | ||
((int64_t), (int64_t)), \ | ||
((float), (float))) | ||
|
||
namespace { | ||
template <typename T, typename S> | ||
void TypedFunc() {} | ||
|
||
using TypeTagMap = std::unordered_map<int, std::vector<int>>; | ||
|
||
template <typename T> | ||
struct StaticMapNVCC : public testing::Test { | ||
StaticMapNVCC() { | ||
type_mapping_[dali::TypeTag<uint8_t>()] = { | ||
dali::TypeTag<uint8_t>(), dali::TypeTag<uint64_t>(), dali::TypeTag<float>() }; | ||
type_mapping_[dali::TypeTag<int8_t>()] = { dali::TypeTag<int64_t>() }; | ||
type_mapping_[dali::TypeTag<uint16_t>()] = { | ||
dali::TypeTag<uint16_t>(), dali::TypeTag<uint64_t>() }; | ||
type_mapping_[dali::TypeTag<int16_t>()] = { dali::TypeTag<int16_t>() }; | ||
type_mapping_[dali::TypeTag<uint32_t>()] = { | ||
dali::TypeTag<uint32_t>(), dali::TypeTag<float>() }; | ||
type_mapping_[dali::TypeTag<int32_t>()] = { dali::TypeTag<int32_t>() }; | ||
type_mapping_[dali::TypeTag<int64_t>()] = { dali::TypeTag<int64_t>() }; | ||
type_mapping_[dali::TypeTag<float>()] = { dali::TypeTag<float>() }; | ||
} | ||
|
||
protected: | ||
template <typename P, typename R> | ||
void TypedMethod(int input_arg_type, int output_arg_type) { | ||
int input_call_type = dali::TypeTag<P>(); | ||
int output_call_type = dali::TypeTag<R>(); | ||
|
||
ASSERT_EQ(input_arg_type, input_call_type); | ||
ASSERT_EQ(output_arg_type, output_call_type); | ||
} | ||
TypeTagMap type_mapping_; | ||
}; | ||
|
||
} // namespace | ||
|
||
typedef testing::Types< | ||
uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, int64_t, float> TypesToTest; | ||
|
||
TYPED_TEST_SUITE(StaticMapNVCC, TypesToTest); | ||
|
||
TYPED_TEST(StaticMapNVCC, ValidTypes) { | ||
using TestedType = gtest_TypeParam_; | ||
|
||
int input_type = dali::TypeTag<TestedType>(); | ||
for (auto &output_type : this->type_mapping_[input_type]) { | ||
TYPE_MAP( | ||
input_type, | ||
output_type, | ||
dali::TypeTag, | ||
InputType, | ||
OutputType, | ||
TEST_TYPES_MAP, | ||
(this->template TypedMethod<InputType, OutputType>(input_type, output_type);), | ||
(FAIL()), | ||
(FAIL())) | ||
} | ||
} | ||
|
||
TEST(StaticMapFailureNVCC, InvalidInputType) { | ||
int input_type = dali::TypeTag<uint64_t>(); | ||
int output_type = dali::TypeTag<int32_t>(); | ||
TYPE_MAP( | ||
input_type, | ||
output_type, | ||
dali::TypeTag, | ||
InputType, | ||
OutputType, | ||
TEST_TYPES_MAP, | ||
(TypedFunc<InputType, OutputType>(); FAIL();), | ||
(SUCCEED()), | ||
(FAIL())) | ||
} | ||
|
||
TEST(StaticMapFailureNVCC, InvalidOutputType) { | ||
int input_type = dali::TypeTag<float>(); | ||
int output_type = dali::TypeTag<int32_t>(); | ||
TYPE_MAP( | ||
input_type, | ||
output_type, | ||
dali::TypeTag, | ||
InputType, | ||
OutputType, | ||
TEST_TYPES_MAP, | ||
(TypedFunc<InputType, OutputType>(); FAIL();), | ||
(FAIL()), | ||
(SUCCEED())) | ||
} |
This file contains 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
Oops, something went wrong.
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.
Maybe you could mention why we are ack-ing this for the future reader.
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.
Added comment to relevant file - static_map.h