-
Notifications
You must be signed in to change notification settings - Fork 114
draft: Proteus lambda redesign RAJA-side support #2052
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
Draft
johnbowen42
wants to merge
5
commits into
develop
Choose a base branch
from
feature/bowen/proteus-lambda-redesign-support
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d2cbb14
Add kernel loop bodies variadic registration method
johnbowen42 01a094b
Forall support, add tests
johnbowen42 06459b8
new launch/kernel examples
johnbowen42 1cf660b
Merge branch 'develop' into feature/bowen/proteus-lambda-redesign-sup…
johnbowen42 6c2c55b
Finalize examples and kernel support
johnbowen42 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
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,152 @@ | ||
| //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// | ||
| // Copyright (c) Lawrence Livermore National Security, LLC and other | ||
| // RAJA Project Developers. See top-level LICENSE and COPYRIGHT | ||
| // files for dates and other details. No copyright assignment is required | ||
| // to contribute to RAJA. | ||
| // | ||
| // SPDX-License-Identifier: (BSD-3-Clause) | ||
| //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// | ||
| // This example mirrors forall-jit.cpp, but uses RAJA::kernel to drive the | ||
| // outer parallel loop. | ||
|
|
||
| #include <cstdlib> | ||
| #include <iostream> | ||
|
|
||
| #include "RAJA/RAJA.hpp" | ||
| #include "RAJA/util/Timer.hpp" | ||
|
|
||
| #if defined(RAJA_ENABLE_CUDA) | ||
| using kernel_policy = RAJA::KernelPolicy< | ||
| RAJA::statement::CudaKernelFixed<256, | ||
| RAJA::statement::Tile<0, RAJA::tile_fixed<256>, | ||
| RAJA::cuda_block_x_direct, | ||
| RAJA::statement::For<0, RAJA::cuda_thread_x_direct, | ||
| RAJA::statement::Lambda<0>>>>>; | ||
| #elif defined(RAJA_ENABLE_HIP) | ||
| using kernel_policy = RAJA::KernelPolicy< | ||
| RAJA::statement::HipKernelFixed<256, | ||
| RAJA::statement::Tile<0, RAJA::tile_fixed<256>, | ||
| RAJA::hip_block_x_direct, | ||
| RAJA::statement::For<0, RAJA::hip_thread_x_direct, | ||
| RAJA::statement::Lambda<0>>>>>; | ||
| #elif defined(RAJA_ENABLE_OPENMP) | ||
| using kernel_policy = RAJA::KernelPolicy< | ||
| RAJA::statement::For<0, RAJA::omp_parallel_for_exec, | ||
| RAJA::statement::Lambda<0>>>; | ||
| #else | ||
| using kernel_policy = RAJA::KernelPolicy< | ||
| RAJA::statement::For<0, RAJA::seq_exec, RAJA::statement::Lambda<0>>>; | ||
| #endif | ||
|
|
||
| int main(int argc, char **argv) { | ||
| if (argc < 5) { | ||
| std::cout | ||
| << "Expected ./bin/kernel-jit <num rows> <num cols> <num matrices> " | ||
| "<boolean accum>, for example ./bin/kernel-jit 24 16 1000000 1\n"; | ||
| return 1; | ||
| } | ||
|
|
||
| int a = std::stoi(argv[1]); | ||
| int b = std::stoi(argv[2]); | ||
| int N = std::stoi(argv[3]); | ||
| bool accum = std::stoi(argv[4]); | ||
|
|
||
| #ifdef RAJA_ENABLE_CUDA | ||
| using resource_policy = RAJA::cuda_exec<256>; | ||
| #elif defined(RAJA_ENABLE_HIP) | ||
| using resource_policy = RAJA::hip_exec<256>; | ||
| #elif defined(RAJA_ENABLE_OPENMP) | ||
| using resource_policy = RAJA::omp_parallel_for_exec; | ||
| #else | ||
| using resource_policy = RAJA::seq_exec; | ||
| #endif | ||
|
|
||
| auto res = RAJA::resources::get_default_resource<resource_policy>(); | ||
| double *A_ptr = res.template allocate<double>(N * a * b); | ||
| auto A = RAJA::make_permuted_view<RAJA::layout_right>(A_ptr, N, a, b); | ||
| double *B_ptr = res.template allocate<double>(N * a * b); | ||
| auto B = RAJA::make_permuted_view<RAJA::layout_right>(B_ptr, N, b, a); | ||
| double *C_ptr = res.template allocate<double>(N * a * a); | ||
| auto C = RAJA::make_permuted_view<RAJA::layout_right>(C_ptr, N, a, a); | ||
|
|
||
| auto Seg = RAJA::RangeSegment(0, N); | ||
|
|
||
| RAJA::kernel<kernel_policy>(RAJA::make_tuple(Seg), [=](int i) { | ||
| for (int row = 0; row < a; ++row) { | ||
| for (int col = 0; col < b; ++col) { | ||
| A(i, row, col) = 0; | ||
| B(i, row, col) = 0; | ||
| C(i, row, col) = 0; | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| RAJA::Timer aot_timer; | ||
| proteus::disable(); | ||
| aot_timer.start(); | ||
|
|
||
| RAJA::kernel<kernel_policy>(RAJA::make_tuple(Seg), [=](int i) { | ||
| for (int row = 0; row < a; ++row) { | ||
| for (int col = 0; col < b; ++col) { | ||
| A(i, row, col) = i % row; | ||
| B(i, row, col) = i % col; | ||
| C(i, row, col) = i % col; | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| RAJA::kernel<kernel_policy>(RAJA::make_tuple(Seg), [=](int i) { | ||
| for (int row = 0; row < a; ++row) { | ||
| for (int col = 0; col < b; ++col) { | ||
| if (!accum) { | ||
| C(i, row, col) = A(i, row, col) * B(i, col, row); | ||
| } else { | ||
| C(i, row, col) += A(i, row, col) * B(i, col, row); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| aot_timer.stop(); | ||
| proteus::enable(); | ||
| std::cout << "aot total time = " << aot_timer.elapsed() << "\n"; | ||
|
|
||
| RAJA::Timer jit_timer; | ||
| jit_timer.start(); | ||
|
|
||
| RAJA::kernel<kernel_policy>( | ||
| RAJA::make_tuple(Seg), | ||
| [=, a = RAJA_JIT_VARIABLE(a), b = RAJA_JIT_VARIABLE(b)](int i) | ||
| RAJA_JIT_COMPILE { | ||
| for (int row = 0; row < a; ++row) { | ||
| for (int col = 0; col < b; ++col) { | ||
| A(i, row, col) = i % row; | ||
| B(i, row, col) = i % col; | ||
| C(i, row, col) = i % col; | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| RAJA::kernel<kernel_policy>( | ||
| RAJA::make_tuple(Seg), | ||
| [=, a = RAJA_JIT_VARIABLE(a), b = RAJA_JIT_VARIABLE(b), | ||
| accum = RAJA_JIT_VARIABLE(accum)](int i) RAJA_JIT_COMPILE { | ||
| for (int row = 0; row < a; ++row) { | ||
| for (int col = 0; col < b; ++col) { | ||
| if (!accum) { | ||
| C(i, row, col) = A(i, row, col) * B(i, col, row); | ||
| } else { | ||
| C(i, row, col) += A(i, row, col) * B(i, col, row); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| jit_timer.stop(); | ||
|
|
||
| std::cout << "jit total time = " << jit_timer.elapsed() << "\n"; | ||
| std::cout << "speedup = " << aot_timer.elapsed() / jit_timer.elapsed() | ||
| << "\n"; | ||
|
|
||
| return 0; | ||
| } | ||
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.
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.
host device?