-
Notifications
You must be signed in to change notification settings - Fork 96
Enables building Partition from local ranges #1227
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
Merged
Merged
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
04ef94c
add build_from_local_range to partition
greole f1f2450
move build_from_local_range into its own header
MarcelKoch 4d0f645
fixups after rebase
MarcelKoch be7e36c
use span for local range
MarcelKoch 9cc97cc
adds kernel to remove duplicate start/ends
MarcelKoch b0c5603
adds test for removing duplicate start/ends
MarcelKoch 68ae3a1
adds tests for build_from_local_range
MarcelKoch 8d5efce
adds note on invalid inputs
MarcelKoch 1077d9e
fixes reference kernel
MarcelKoch 6dcade0
allows specifying part ids for contiguous partition constructor
MarcelKoch 1ee1a97
adds sorting kernel for ranges + part-ids
MarcelKoch d849429
adds consistency check kernel (reference
MarcelKoch 9683e4e
wip
MarcelKoch 56598f4
fixes ranges gathering
MarcelKoch b782563
adds MPI tests
MarcelKoch 239af98
removes dead code
MarcelKoch f98acaf
adds device consecutive ranges check
MarcelKoch 5962b02
add omp sorting kernel
MarcelKoch 684b563
fixes tests
MarcelKoch b664ec4
adds cuda/hip/dpcpp sort kernels
MarcelKoch efd1a45
adds creator from local sizes
MarcelKoch 5a5b040
review updates
MarcelKoch 45e95ef
bump copyright
MarcelKoch c5caeba
review updates:
MarcelKoch 28bbc6f
safeguard against negative reduction size
MarcelKoch 92feba4
remove unused function
MarcelKoch 1c43396
fixes partition documentation
MarcelKoch d2c01b3
changes layout of gather ranges
MarcelKoch 457b7f0
adapts sorting to changed ranges layout
MarcelKoch 0d68caf
adapts consecutive check to changed ranges layout
MarcelKoch 3752a5b
adds kernel to compress ranges
MarcelKoch 4be22f9
review updates:
MarcelKoch 9ef64f2
review update:
MarcelKoch 29a5a8a
fixing dpcpp
MarcelKoch f8d3a8c
don't mix host and device buffers for MPI
MarcelKoch 31ae609
adds permutation iterator
MarcelKoch 3b7d008
use permute iterator for STL algorithms
MarcelKoch e6e3958
review updates:
MarcelKoch 8edb0e5
review updates:
MarcelKoch 8000e88
adds copy_assignable wrapper class
MarcelKoch 348b067
adds invalid state exception
MarcelKoch af51e52
review updates:
MarcelKoch 5fb31ba
Format files
ginkgo-bot 0383f94
uses placement-new for copy-assignable wrapper
MarcelKoch e90d154
Format files
ginkgo-bot a8c9900
remove undefined lambda default constructor
MarcelKoch e3308ff
use workaround for old dpcpp version
MarcelKoch 8cdb658
fixup after rebase
MarcelKoch 5285e41
review updates:
MarcelKoch 09bfa7f
use custom stream for thrust policy
MarcelKoch 8393dca
correctly define permutation map
MarcelKoch 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
54 changes: 54 additions & 0 deletions
54
common/cuda_hip/distributed/partition_helpers_kernels.hpp.inc
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,54 @@ | ||
/*******************************<GINKGO LICENSE>****************************** | ||
Copyright (c) 2017-2023, the Ginkgo authors | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
|
||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
******************************<GINKGO LICENSE>*******************************/ | ||
|
||
template <typename GlobalIndexType> | ||
void sort_by_range_start( | ||
std::shared_ptr<const DefaultExecutor> exec, | ||
array<GlobalIndexType>& range_start_ends, | ||
array<experimental::distributed::comm_index_type>& part_ids) | ||
{ | ||
auto num_ranges = range_start_ends.get_num_elems() / 2; | ||
auto strided_indices = thrust::make_transform_iterator( | ||
thrust::make_counting_iterator(0), | ||
[] __host__ __device__(const int i) { return 2 * i; }); | ||
auto start_it = thrust::make_permutation_iterator( | ||
range_start_ends.get_data(), strided_indices); | ||
auto end_it = thrust::make_permutation_iterator( | ||
range_start_ends.get_data() + 1, strided_indices); | ||
auto zip_it = thrust::make_zip_iterator( | ||
thrust::make_tuple(end_it, part_ids.get_data())); | ||
< 6DB6 /td> | thrust::stable_sort_by_key(thrust_policy(exec), start_it, | |
start_it + num_ranges, zip_it); | ||
} | ||
|
||
GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE( | ||
GKO_DECLARE_PARTITION_HELPERS_SORT_BY_RANGE_START); |
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
102 changes: 102 additions & 0 deletions
102
common/unified/distributed/partition_helpers_kernels.cpp
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,102 @@ | ||
/*******************************<GINKGO LICENSE>****************************** | ||
Copyright (c) 2017-2023, the Ginkgo authors | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
|
||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
******************************<GINKGO LICENSE>*******************************/ | ||
|
||
#include "core/distributed/partition_helpers_kernels.hpp" | ||
|
||
|
||
#include "common/unified/base/kernel_launch.hpp" | ||
#include "common/unified/base/kernel_launch_reduction.hpp" | ||
|
||
|
||
namespace gko { | ||
namespace kernels { | ||
namespace GKO_DEVICE_NAMESPACE { | ||
namespace partition_helpers { | ||
|
||
|
||
template <typename GlobalIndexType> | ||
void check_consecutive_ranges(std::shared_ptr<const DefaultExecutor> exec, | ||
const array<GlobalIndexType>& range_start_ends, | ||
bool& result) | ||
{ | ||
array<uint32> result_uint32{exec, 1}; | ||
auto num_ranges = range_start_ends.get_num_elems() / 2; | ||
// need additional guard because DPCPP doesn't return the initial value for | ||
// empty inputs | ||
if (num_ranges > 1) { | ||
run_kernel_reduction( | ||
exec, | ||
[] GKO_KERNEL(const auto i, const auto* ranges) { | ||
return ranges[2 * i] == ranges[2 * i + 1]; | ||
}, | ||
[] GKO_KERNEL(const auto a, const auto b) { | ||
return static_cast<uint32>(a && b); | ||
}, | ||
[] GKO_KERNEL(auto x) { return x; }, static_cast<uint32>(true), | ||
result_uint32.get_data(), num_ranges - 1, | ||
range_start_ends.get_const_data() + 1); | ||
result = | ||
static_cast<bool>(exec->copy_val_to_host(result_uint32.get_data())); | ||
} else { | ||
result = true; | ||
} | ||
} | ||
|
||
GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE( | ||
GKO_DECLARE_PARTITION_HELPERS_CHECK_CONSECUTIVE_RANGES); | ||
|
||
|
||
template <typename GlobalIndexType> | ||
void compress_ranges(std::shared_ptr<const DefaultExecutor> exec, | ||
const array<GlobalIndexType>& range_start_ends, | ||
array<GlobalIndexType>& range_offsets) | ||
{ | ||
run_kernel( | ||
exec, | ||
[] GKO_KERNEL(const auto i, const auto* start_ends, auto* offsets) { | ||
if (i == 0) { | ||
offsets[0] = start_ends[0]; | ||
} | ||
offsets[i + 1] = start_ends[2 * i + 1]; | ||
}, | ||
range_offsets.get_num_elems() - 1, range_start_ends.get_const_data(), | ||
range_offsets.get_data()); | ||
} | ||
|
||
GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE( | ||
GKO_DECLARE_PARTITION_HELPERS_COMPRESS_RANGES); | ||
|
||
|
||
} // namespace partition_helpers | ||
} // namespace GKO_DEVICE_NAMESPACE | ||
} // namespace kernels | ||
} // namespace gko |
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 |
---|---|---|
|
@@ -66,19 +66,22 @@ void count_ranges(std::shared_ptr<const DefaultExecutor> exec, | |
template <typename GlobalIndexType> | ||
void build_from_contiguous(std::shared_ptr<const DefaultExecutor> exec, | ||
const array<GlobalIndexType>& ranges, | ||
const array<comm_index_type>& part_id_mapping, | ||
GlobalIndexType* range_bounds, | ||
comm_index_type* part_ids) | ||
{ | ||
run_kernel( | ||
exec, | ||
[] GKO_KERNEL(auto i, auto ranges, auto bounds, auto ids) { | ||
[] GKO_KERNEL(auto i, auto ranges, auto mapping, auto bounds, auto ids, | ||
bool uses_mapping) { | ||
if (i == 0) { | ||
bounds[0] = 0; | ||
} | ||
bounds[i + 1] = ranges[i + 1]; | ||
ids[i] = i; | ||
ids[i] = uses_mapping ? mapping[i] : i; | ||
}, | ||
ranges.get_num_elems() - 1, ranges, range_bounds, part_ids); | ||
ranges.get_num_elems() - 1, ranges, part_id_mapping, range_bounds, | ||
part_ids, part_id_mapping.get_num_elems() > 0); | ||
Comment on lines
+83
to
+84
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. just an observation: Maybe we should ensure that empty arrays always point to |
||
} | ||
|
||
GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_PARTITION_BUILD_FROM_CONTIGUOUS); | ||
|
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,130 @@ | ||
/*******************************<GINKGO LICENSE>****************************** | ||
Copyright (c) 2017-2023, the Ginkgo authors | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
|
||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
******************************<GINKGO LICENSE>*******************************/ | ||
|
||
#ifndef GKO_CORE_BASE_COPY_ASSIGNABLE_HPP_ | ||
#define GKO_CORE_BASE_COPY_ASSIGNABLE_HPP_ | ||
|
||
|
||
#include <vector> | ||
|
||
|
||
namespace gko { | ||
namespace detail { | ||
|
||
|
||
template <typename T, typename = void> | ||
class copy_assignable; | ||
|
||
|
||
/** | ||
* Helper class to make a type copy assignable. | ||
* | ||
* This class wraps an object of a type that has a copy constructor, but not | ||
* a copy assignment. This is most often the case for lambdas. The wrapped | ||
* object can then be copy assigned, by relying on the copy constructor. | ||
* | ||
* @tparam T type with a copy constructor | ||
*/ | ||
template <typename T> | ||
class copy_assignable< | ||
T, typename std::enable_if<std::is_copy_constructible<T>::value>::type> { | ||
public: | ||
copy_assignable() = default; | ||
|
||
copy_assignable(const copy_assignable& other) | ||
{ | ||
if (this != &other) { | ||
*this = other; | ||
} | ||
} | ||
|
||
copy_assignable(copy_assignable&& other) noexcept | ||
{ | ||
if (this != &other) { | ||
*this = std::move(other); | ||
} | ||
} | ||
|
||
copy_assignable(const T& obj) : obj_{new (buf)(T)(obj)} {} | ||
|
||
copy_assignable(T&& obj) : obj_{new (buf)(T)(std::move(obj))} {} | ||
|
||
copy_assignable& operator=(const copy_assignable& other) | ||
{ | ||
if (this != &other) { | ||
if (obj_) { | ||
obj_->~T(); | ||
} | ||
obj_ = new (buf)(T)(*other.obj_); | ||
} | ||
return *this; | ||
} | ||
|
||
copy_assignable& operator=(copy_assignable&& other) noexcept | ||
{ | ||
if (this != &other) { | ||
if (obj_) { | ||
obj_->~T(); | ||
} | ||
obj_ = new (buf)(T)(std::move(*other.obj_)); | ||
} | ||
return *this; | ||
} | ||
|
||
~copy_assignable() | ||
{ | ||
if (obj_) { | ||
obj_->~T(); | ||
} | ||
} | ||
|
||
template <typename... Args> | ||
decltype(auto) operator()(Args&&... args) const | ||
{ | ||
return (*obj_)(std::forward<Args>(args)...); | ||
} | ||
|
||
T const& get() const { return *obj_; } | ||
|
||
T& get() { return *obj_; } | ||
|
||
private: | ||
//!< Store wrapped object on the stack, should use std::optional in c++17 | ||
T* obj_{}; | ||
alignas(T) unsigned char buf[sizeof(T)]; | ||
}; | ||
|
||
|
||
} // namespace detail | ||
} // namespace gko | ||
|
||
#endif // GKO_CORE_BASE_COPY_ASSIGNABLE_HPP_ |
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.
Uh oh!
There was an error while loading. Please reload this page.