-
Notifications
You must be signed in to change notification settings - Fork 103
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
Reshape method #1760
Open
artv3
wants to merge
13
commits into
develop
Choose a base branch
from
artv3/reshape
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.
Open
Reshape method #1760
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
726da15
reshape methods
artv3 119cc95
Merge branch 'develop' into artv3/reshape
artv3 e105bae
Merge branch 'develop' into artv3/reshape
artv3 78d32b3
add alias for view type
artv3 9807f31
compile time reverse array
artv3 28e714d
review reshape example
artv3 fc1f6a8
clean up pass
artv3 4d05ea5
clean up reshape example
artv3 b0a836a
push up version that takes index_seq
artv3 a1a254d
fix bug with custom layout
artv3 a691f40
clean up based on pr comments
artv3 cf3ff8c
Update include/RAJA/util/View.hpp
artv3 7ddbdb1
fix inside function call
artv3 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 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,134 @@ | ||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// | ||
// Copyright (c) 2016-24, Lawrence Livermore National Security, LLC | ||
// and RAJA project contributors. See the RAJA/LICENSE file for details. | ||
// | ||
// SPDX-License-Identifier: (BSD-3-Clause) | ||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// | ||
|
||
#include <cmath> | ||
#include <cstdlib> | ||
#include <cstring> | ||
#include <iostream> | ||
|
||
#include "RAJA/RAJA.hpp" | ||
#include "RAJA/util/Timer.hpp" | ||
|
||
|
||
#include "memoryManager.hpp" | ||
|
||
/* | ||
* RAJA Reshape method | ||
* | ||
* This example will intialize array using | ||
* the RAJA Reshape method. The Reshape | ||
* method offers right and left most unit | ||
* stride. | ||
* | ||
*/ | ||
|
||
/* | ||
* Define number of threads in a GPU thread block | ||
*/ | ||
#if defined(RAJA_ENABLE_CUDA) | ||
constexpr int CUDA_BLOCK_SIZE = 256; | ||
#endif | ||
|
||
#if defined(RAJA_ENABLE_HIP) | ||
constexpr int HIP_BLOCK_SIZE = 256; | ||
#endif | ||
|
||
// | ||
//Function for checking results | ||
// | ||
void checkResult(int *ptr, int N, int M, int K); | ||
|
||
int main(int RAJA_UNUSED_ARG(argc), char **RAJA_UNUSED_ARG(argv[])) | ||
{ | ||
|
||
std::cout << "\n\nRAJA reshape method example....\n"<< std::endl; | ||
|
||
const int K = 3; | ||
const int N = 1; | ||
const int M = 2; | ||
|
||
// Allocate memory for pointer | ||
int *Rptr = memoryManager::allocate<int>(K * N * M); | ||
int *Lptr = memoryManager::allocate<int>(K * N * M); | ||
|
||
//----------------------------------------------------------------------------// | ||
// | ||
// Initialize memory using right most unit stride | ||
// | ||
//----------------------------------------------------------------------------// | ||
std::cout << "\n\nInitialize array with right most indexing...\n"; | ||
auto Rview = RAJA::Reshape<RAJA::layout_right>::get(Rptr, K, N, M); | ||
|
||
for(int k = 0; k < K; ++k) { | ||
for(int n = 0; n < N; ++n) { | ||
for(int m = 0; m < M; ++m) { | ||
const int idx = m + M * (n + N * k); | ||
Rview(k,n,m) = idx; | ||
} | ||
} | ||
} | ||
|
||
checkResult(Rptr, K, N, M); | ||
|
||
|
||
//----------------------------------------------------------------------------// | ||
// | ||
// Initialize memory using left most unit stride | ||
// | ||
//----------------------------------------------------------------------------// | ||
std::cout << "\n\nInitialize array with left most indexing...\n"; | ||
|
||
auto Lview = RAJA::Reshape<RAJA::layout_left>::get(Lptr, K, N, M); | ||
|
||
//Note the loop ordering has change from above | ||
for(int m = 0; m < M; ++m) { | ||
for(int n = 0; n < N; ++n) { | ||
for(int k = 0; k < K; ++k) { | ||
|
||
const int idx = k + K * (n + N * m); | ||
Lview(k,m,n) = idx; | ||
} | ||
} | ||
} | ||
|
||
checkResult(Lptr, K, N, M); | ||
|
||
// | ||
// Clean up. | ||
// | ||
memoryManager::deallocate(Rptr); | ||
memoryManager::deallocate(Lptr); | ||
|
||
std::cout << "\n DONE!...\n"; | ||
return 0; | ||
} | ||
|
||
// | ||
// check result | ||
// | ||
void checkResult(int *ptr, int N, int M, int K) | ||
artv3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
|
||
bool status = true; | ||
|
||
for(int k = 0; k < K; ++k) { | ||
for(int n = 0; n < N; ++n) { | ||
for(int m = 0; m < M; ++m) { | ||
const int idx = m + M * (n + N * k); | ||
if (std::abs(ptr[idx] - idx) > 1.0e-12) { | ||
artv3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
status = false; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if ( status ) { | ||
std::cout << "\tresult -- PASS\n"; | ||
} else { | ||
std::cout << "\tresult -- FAIL\n"; | ||
} | ||
} |
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.
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.
I think these implementations are much easier to understand if your intent is just to show the mechanics of View reshaping. 👍