-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR introduces a new prefix_sum kernel that is used instead of manually computing prefix sums in different places. This also fixes two bugs: * In CUDA/HIP ParILU, the wrong num_blocks is used for launching the prefix sum kernels * In Reference ParILU, the handling of non-existent diagonals during initialization is incorrect. Finally, it removes a few unnecessary calls to Array::clear since they would be cleaned up via RAII anyways. Related PR: #429
- Loading branch information
Showing
38 changed files
with
841 additions
and
330 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/*******************************<GINKGO LICENSE>****************************** | ||
Copyright (c) 2017-2020, 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_COMPONENTS_PREFIX_SUM_HPP_ | ||
#define GKO_CORE_COMPONENTS_PREFIX_SUM_HPP_ | ||
|
||
|
||
#include <memory> | ||
|
||
|
||
#include <ginkgo/core/base/executor.hpp> | ||
#include <ginkgo/core/base/types.hpp> | ||
|
||
|
||
namespace gko { | ||
namespace kernels { | ||
|
||
|
||
#define GKO_DECLARE_PREFIX_SUM_KERNEL(IndexType) \ | ||
void prefix_sum(std::shared_ptr<const DefaultExecutor> exec, \ | ||
IndexType *counts, size_type num_entries) | ||
|
||
|
||
#define GKO_DECLARE_ALL_AS_TEMPLATES \ | ||
template <typename IndexType> \ | ||
GKO_DECLARE_PREFIX_SUM_KERNEL(IndexType) | ||
|
||
|
||
namespace omp { | ||
|
||
GKO_DECLARE_ALL_AS_TEMPLATES; | ||
|
||
} // namespace omp | ||
|
||
|
||
namespace cuda { | ||
|
||
GKO_DECLARE_ALL_AS_TEMPLATES; | ||
|
||
} // namespace cuda | ||
|
||
|
||
namespace reference { | ||
|
||
GKO_DECLARE_ALL_AS_TEMPLATES; | ||
|
||
} // namespace reference | ||
|
||
|
||
namespace hip { | ||
|
||
GKO_DECLARE_ALL_AS_TEMPLATES; | ||
|
||
} // namespace hip | ||
|
||
|
||
#undef GKO_DECLARE_ALL_AS_TEMPLATES | ||
|
||
|
||
} // namespace kernels | ||
} // namespace gko | ||
|
||
#endif // GKO_CORE_COMPONENTS_PREFIX_SUM_HPP_ |
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,72 @@ | ||
/*******************************<GINKGO LICENSE>****************************** | ||
Copyright (c) 2017-2020, 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/components/prefix_sum.hpp" | ||
|
||
|
||
#include "cuda/components/prefix_sum.cuh" | ||
|
||
|
||
namespace gko { | ||
namespace kernels { | ||
namespace cuda { | ||
|
||
|
||
constexpr int prefix_sum_block_size = 512; | ||
|
||
|
||
template <typename IndexType> | ||
void prefix_sum(std::shared_ptr<const CudaExecutor> exec, IndexType *counts, | ||
size_type num_entries) | ||
{ | ||
auto num_blocks = ceildiv(num_entries, prefix_sum_block_size); | ||
Array<IndexType> block_sum_array(exec, num_blocks); | ||
auto block_sums = block_sum_array.get_data(); | ||
start_prefix_sum<prefix_sum_block_size> | ||
<<<num_blocks, prefix_sum_block_size>>>(num_entries, counts, | ||
block_sums); | ||
finalize_prefix_sum<prefix_sum_block_size> | ||
<<<num_blocks, prefix_sum_block_size>>>(num_entries, counts, | ||
block_sums); | ||
} | ||
|
||
GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DECLARE_PREFIX_SUM_KERNEL); | ||
|
||
// explicitly instantiate for size_type as well, as this is used in the SellP | ||
// format | ||
template void prefix_sum<size_type>(std::shared_ptr<const CudaExecutor> exec, | ||
size_type *counts, size_type num_entries); | ||
|
||
|
||
} // namespace cuda | ||
} // namespace kernels | ||
} // namespace gko |
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
Oops, something went wrong.