-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a custom device tuple implementation to support zip_iterator in device code. Related PR: #1604
- Loading branch information
Showing
13 changed files
with
420 additions
and
96 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
ginkgo_create_common_test(batch_multi_vector_kernels) | ||
ginkgo_create_common_and_reference_test(device_matrix_data_kernels) | ||
ginkgo_create_common_device_test(index_range) | ||
ginkgo_create_common_device_test(iterator_factory) | ||
ginkgo_create_common_device_test(kernel_launch_generic) | ||
ginkgo_create_common_and_reference_test(executor) | ||
ginkgo_create_common_and_reference_test(timer) |
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,70 @@ | ||
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include "core/base/iterator_factory.hpp" | ||
|
||
#include <memory> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <ginkgo/core/base/array.hpp> | ||
|
||
#include "common/unified/base/kernel_launch.hpp" | ||
#include "core/test/utils.hpp" | ||
#include "test/utils/common_fixture.hpp" | ||
|
||
|
||
class IteratorFactory : public CommonTestFixture { | ||
public: | ||
IteratorFactory() | ||
: key_array{exec, {6, 2, 3, 8, 1, 0, 2}}, | ||
value_array{exec, {9, 5, 7, 2, 4, 7, 2}}, | ||
expected_key_array{ref, {7, 1, 2, 2, 3, 6, 8}}, | ||
expected_value_array{ref, {7, 4, 2, 5, 7, 9, 2}} | ||
{} | ||
|
||
gko::array<int> key_array; | ||
gko::array<int> value_array; | ||
gko::array<int> expected_key_array; | ||
gko::array<int> expected_value_array; | ||
}; | ||
|
||
|
||
// nvcc doesn't like device lambdas declared in complex classes, move it out | ||
void run_zip_iterator(std::shared_ptr<gko::EXEC_TYPE> exec, | ||
gko::array<int>& key_array, gko::array<int>& value_array) | ||
{ | ||
gko::kernels::GKO_DEVICE_NAMESPACE::run_kernel( | ||
exec, | ||
[] GKO_KERNEL(auto i, auto keys, auto values, auto size) { | ||
auto begin = gko::detail::make_zip_iterator(keys, values); | ||
auto end = begin + size; | ||
using std::swap; | ||
for (auto it = begin; it != end; ++it) { | ||
auto min_it = it; | ||
for (auto it2 = it; it2 != end; ++it2) { | ||
if (*it2 < *min_it) { | ||
min_it = it2; | ||
} | ||
} | ||
swap(*it, *min_it); | ||
} | ||
// check structured bindings | ||
auto [key, value] = *begin; | ||
static_assert(std::is_same<std::remove_reference_t<decltype(key)>, | ||
int>::value, | ||
"incorrect type"); | ||
gko::get<0>(*begin) = value; | ||
}, | ||
1, key_array, value_array, static_cast<int>(key_array.get_size())); | ||
} | ||
|
||
|
||
TEST_F(IteratorFactory, KernelRunsZipIterator) | ||
{ | ||
run_zip_iterator(exec, key_array, value_array); | ||
|
||
GKO_ASSERT_ARRAY_EQ(key_array, expected_key_array); | ||
GKO_ASSERT_ARRAY_EQ(value_array, expected_value_array); | ||
} |