-
Notifications
You must be signed in to change notification settings - Fork 119
Add sparse stack #2014
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
Add sparse stack #2014
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
30c9a59
add sparse stack
6aa4c0e
Update core/device_hooks/common_kernels.inc.cpp
cflinto 80efbf3
Update omp/sketch/sparse_stack_kernels.cpp
cflinto db5dfc4
Update omp/sketch/sparse_stack_kernels.cpp
cflinto 887e8a7
Update omp/sketch/sparse_stack_kernels.cpp
cflinto ee5f811
Update omp/sketch/sparse_stack_kernels.cpp
cflinto 4c5f05a
Update common/cuda_hip/sketch/sparse_stack_kernels.cpp
cflinto acdd456
pre-commit
8560039
correct spaces
94173a7
add sparse stack tests (untested)
8cac6ca
correct number of arguments for sparse stack
a60daf9
add default create for sketch classes
300fd07
correct when sketch_size is 0
816bad9
try to fix sparse stack tests
9d2c752
change the uniform int case
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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors | ||
| // | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| #include "core/sketch/sparse_stack_kernels.hpp" | ||
|
|
||
| #include <ginkgo/core/base/exception_helpers.hpp> | ||
|
|
||
| namespace gko { | ||
| namespace kernels { | ||
| namespace GKO_DEVICE_NAMESPACE { | ||
| namespace sparse_stack { | ||
|
|
||
|
|
||
| template <typename ValueType, typename IndexType> | ||
| void generate(std::shared_ptr<const DefaultExecutor> exec, | ||
| size_type sketch_size, size_type input_size, size_type zeta, | ||
| array<IndexType>& hash_map, array<ValueType>& signs, | ||
| uint64 seed) GKO_NOT_IMPLEMENTED; | ||
|
|
||
| GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE( | ||
| GKO_DECLARE_SPARSE_STACK_GENERATE); | ||
|
|
||
| template <typename ValueType, typename IndexType> | ||
| void apply(std::shared_ptr<const DefaultExecutor> exec, size_type zeta, | ||
| const array<IndexType>& hash_map, const array<ValueType>& signs, | ||
| matrix::view::dense<const ValueType> b, | ||
| matrix::view::dense<ValueType> x) GKO_NOT_IMPLEMENTED; | ||
|
|
||
| GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(GKO_DECLARE_SPARSE_STACK_APPLY); | ||
|
|
||
| template <typename ValueType, typename IndexType> | ||
| void rapply(std::shared_ptr<const DefaultExecutor> exec, size_type zeta, | ||
| const array<IndexType>& hash_map, const array<ValueType>& signs, | ||
| matrix::view::dense<const ValueType> b, | ||
| matrix::view::dense<ValueType> x) GKO_NOT_IMPLEMENTED; | ||
|
|
||
| GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(GKO_DECLARE_SPARSE_STACK_RAPPLY); | ||
|
|
||
|
|
||
| } // namespace sparse_stack | ||
|
cflinto marked this conversation as resolved.
|
||
| } // 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
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,4 +1,4 @@ | ||||||||||||||
| // SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors | ||||||||||||||
| // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors | ||||||||||||||
| // | ||||||||||||||
| // SPDX-License-Identifier: BSD-3-Clause | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -57,6 +57,9 @@ | |||||||||||||
| #include "core/preconditioner/jacobi_kernels.hpp" | ||||||||||||||
| #include "core/preconditioner/sor_kernels.hpp" | ||||||||||||||
| #include "core/reorder/rcm_kernels.hpp" | ||||||||||||||
| #include "core/sketch/count_sketch_kernels.hpp" | ||||||||||||||
| #include "core/sketch/gaussian_sketch_kernels.hpp" | ||||||||||||||
| #include "core/sketch/sparse_stack_kernels.hpp" | ||||||||||||||
| #include "core/solver/batch_bicgstab_kernels.hpp" | ||||||||||||||
| #include "core/solver/batch_cg_kernels.hpp" | ||||||||||||||
| #include "core/solver/bicg_kernels.hpp" | ||||||||||||||
|
|
@@ -76,8 +79,6 @@ | |||||||||||||
| #include "core/solver/multigrid_kernels.hpp" | ||||||||||||||
| #include "core/solver/pipe_cg_kernels.hpp" | ||||||||||||||
| #include "core/solver/upper_trs_kernels.hpp" | ||||||||||||||
| #include "core/sketch/count_sketch_kernels.hpp" | ||||||||||||||
| #include "core/sketch/gaussian_sketch_kernels.hpp" | ||||||||||||||
| #include "core/stop/criterion_kernels.hpp" | ||||||||||||||
| #include "core/stop/residual_norm_kernels.hpp" | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -1190,6 +1191,16 @@ GKO_STUB_VALUE_AND_INDEX_TYPE(GKO_DECLARE_COUNT_SKETCH_RAPPLY); | |||||||||||||
|
|
||||||||||||||
| } // namespace count_sketch | ||||||||||||||
|
|
||||||||||||||
| namespace sparse_stack { | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| GKO_STUB_VALUE_AND_INDEX_TYPE(GKO_DECLARE_SPARSE_STACK_GENERATE); | ||||||||||||||
| GKO_STUB_VALUE_AND_INDEX_TYPE(GKO_DECLARE_SPARSE_STACK_APPLY); | ||||||||||||||
| GKO_STUB_VALUE_AND_INDEX_TYPE(GKO_DECLARE_SPARSE_STACK_RAPPLY); | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| } // namespace sparse_stack | ||||||||||||||
|
cflinto marked this conversation as resolved.
|
||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| } // namespace GKO_HOOK_MODULE | ||||||||||||||
|
Comment on lines
+1202
to
1205
Member
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.
Suggested change
|
||||||||||||||
| } // namespace kernels | ||||||||||||||
|
|
||||||||||||||
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,88 @@ | ||
| // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors | ||
| // | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| #include <ginkgo/core/base/precision_dispatch.hpp> | ||
| #include <ginkgo/core/matrix/dense.hpp> | ||
| #include <ginkgo/core/sketch/sparse_stack.hpp> | ||
|
|
||
| #include "core/sketch/sparse_stack_kernels.hpp" | ||
|
|
||
|
|
||
| namespace gko { | ||
| namespace sketch { | ||
| namespace sparse_stack { | ||
| namespace { | ||
|
|
||
|
|
||
| GKO_REGISTER_OPERATION(generate, sparse_stack::generate); | ||
| GKO_REGISTER_OPERATION(apply, sparse_stack::apply); | ||
| GKO_REGISTER_OPERATION(rapply, sparse_stack::rapply); | ||
|
|
||
|
|
||
| } // anonymous namespace | ||
| } // namespace sparse_stack | ||
|
|
||
|
|
||
| template <typename ValueType, typename IndexType> | ||
| SparseStack<ValueType, IndexType>::SparseStack( | ||
| std::shared_ptr<const Executor> exec, size_type sketch_size, | ||
| size_type input_size, size_type zeta, uint64 seed) | ||
| : EnableLinOp<SparseStack, SketchOperator<ValueType>>( | ||
| exec, dim<2>{sketch_size, input_size}), | ||
| zeta_{zeta}, | ||
| hash_map_{exec, input_size * zeta}, | ||
| signs_{exec, input_size * zeta}, | ||
| seed_{seed} | ||
| { | ||
| exec->run(sparse_stack::make_generate(sketch_size, input_size, zeta_, | ||
| hash_map_, signs_, seed_)); | ||
| } | ||
|
cflinto marked this conversation as resolved.
|
||
|
|
||
|
|
||
| template <typename ValueType, typename IndexType> | ||
| std::unique_ptr<SparseStack<ValueType, IndexType>> | ||
| SparseStack<ValueType, IndexType>::create(std::shared_ptr<const Executor> exec, | ||
| size_type sketch_size, | ||
| size_type input_size, size_type zeta, | ||
| uint64 seed) | ||
| { | ||
| return std::unique_ptr<SparseStack>{ | ||
| new SparseStack(exec, sketch_size, input_size, zeta, seed)}; | ||
| } | ||
|
|
||
| template <typename ValueType, typename IndexType> | ||
| std::unique_ptr<SparseStack<ValueType, IndexType>> | ||
| SparseStack<ValueType, IndexType>::create(std::shared_ptr<const Executor> exec) | ||
| { | ||
| return std::unique_ptr<SparseStack>{new SparseStack(exec)}; | ||
| } | ||
|
|
||
|
|
||
| template <typename ValueType, typename IndexType> | ||
| void SparseStack<ValueType, IndexType>::apply_sketch_impl( | ||
| const matrix::Dense<ValueType>* b, matrix::Dense<ValueType>* x) const | ||
| { | ||
| this->get_executor()->run(sparse_stack::make_apply( | ||
| zeta_, hash_map_, signs_, b->get_const_device_view(), | ||
| x->get_device_view())); | ||
| } | ||
|
|
||
|
|
||
| template <typename ValueType, typename IndexType> | ||
| void SparseStack<ValueType, IndexType>::rapply_sketch_impl( | ||
| const matrix::Dense<ValueType>* b, matrix::Dense<ValueType>* x) const | ||
| { | ||
| this->get_executor()->run(sparse_stack::make_rapply( | ||
| zeta_, hash_map_, signs_, b->get_const_device_view(), | ||
| x->get_device_view())); | ||
| } | ||
|
|
||
|
|
||
| #define GKO_DECLARE_SPARSE_STACK(ValueType, IndexType) \ | ||
| class SparseStack<ValueType, IndexType> | ||
| GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(GKO_DECLARE_SPARSE_STACK); | ||
|
|
||
|
|
||
| } // namespace sketch | ||
| } // 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 |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors | ||
| // | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| #ifndef GKO_CORE_SKETCH_SPARSE_STACK_KERNELS_HPP_ | ||
| #define GKO_CORE_SKETCH_SPARSE_STACK_KERNELS_HPP_ | ||
|
|
||
|
|
||
| #include <ginkgo/core/base/array.hpp> | ||
| #include <ginkgo/core/base/types.hpp> | ||
| #include <ginkgo/core/matrix/dense.hpp> | ||
|
|
||
| #include "core/base/kernel_declaration.hpp" | ||
|
|
||
|
|
||
| namespace gko { | ||
| namespace kernels { | ||
|
|
||
|
|
||
| #define GKO_DECLARE_SPARSE_STACK_GENERATE(ValueType, IndexType) \ | ||
| void generate(std::shared_ptr<const DefaultExecutor> exec, \ | ||
| size_type sketch_size, size_type input_size, size_type zeta, \ | ||
| array<IndexType>& hash_map, array<ValueType>& signs, \ | ||
| gko::uint64 seed) | ||
|
|
||
| #define GKO_DECLARE_SPARSE_STACK_APPLY(ValueType, IndexType) \ | ||
| void apply(std::shared_ptr<const DefaultExecutor> exec, size_type zeta, \ | ||
| const array<IndexType>& hash_map, \ | ||
| const array<ValueType>& signs, \ | ||
| matrix::view::dense<const ValueType> b, \ | ||
| matrix::view::dense<ValueType> x) | ||
|
|
||
| #define GKO_DECLARE_SPARSE_STACK_RAPPLY(ValueType, IndexType) \ | ||
| void rapply(std::shared_ptr<const DefaultExecutor> exec, size_type zeta, \ | ||
| const array<IndexType>& hash_map, \ | ||
| const array<ValueType>& signs, \ | ||
| matrix::view::dense<const ValueType> b, \ | ||
| matrix::view::dense<ValueType> x) | ||
|
|
||
|
|
||
| #define GKO_DECLARE_ALL_AS_TEMPLATES \ | ||
| template <typename ValueType, typename IndexType> \ | ||
| GKO_DECLARE_SPARSE_STACK_GENERATE(ValueType, IndexType); \ | ||
| template <typename ValueType, typename IndexType> \ | ||
| GKO_DECLARE_SPARSE_STACK_APPLY(ValueType, IndexType); \ | ||
| template <typename ValueType, typename IndexType> \ | ||
| GKO_DECLARE_SPARSE_STACK_RAPPLY(ValueType, IndexType) | ||
|
|
||
|
|
||
| GKO_DECLARE_FOR_ALL_EXECUTOR_NAMESPACES(sparse_stack, | ||
| GKO_DECLARE_ALL_AS_TEMPLATES); | ||
|
|
||
|
|
||
| #undef GKO_DECLARE_ALL_AS_TEMPLATES | ||
|
|
||
|
|
||
| } // namespace kernels | ||
| } // namespace gko | ||
|
|
||
|
|
||
| #endif // GKO_CORE_SKETCH_SPARSE_STACK_KERNELS_HPP_ |
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,2 +1,3 @@ | ||
| ginkgo_create_test(gaussian_sketch) | ||
| ginkgo_create_test(count_sketch) | ||
| ginkgo_create_test(sparse_stack) |
Oops, something went wrong.
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.