-
Notifications
You must be signed in to change notification settings - Fork 4
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
Backend structure #7
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1151430
feat: Backend structure, incomplete but gives an idea.
semi-h be4b39b
chore: Add comments.
semi-h be783c4
fix: base backend compiles.
semi-h 16ea142
feat: Simplified cuda_backend compiles and we have an executable.
semi-h ca7cb48
feat: Backend structure is ready to execute kernels.
semi-h d3bde27
feat: Example use of a CUDA kernel in the CUDA backend.
semi-h f134f94
feat(cuda): Move towards running transeq via the cuda backend.
semi-h 62c6eca
feat(cuda): Transport equation implementation is complete.
semi-h 5c46780
feat(cuda): Add set_fields and get_fields for host-device transfers.
semi-h 71f177f
fix(cuda): Fix a bug in the CUDA backend with blocks and threads.
semi-h d416702
refactor: Extract a solver class from backend class.
semi-h 679bfb8
feat: Simplify tdsops initialisation.
semi-h 238e48a
feat(cuda): Handle halo data copy in a dedicated subroutine.
semi-h 73886dc
refactor: Simplify setting prev and next for each dimension.
semi-h ef6f800
chore: Cleanups.
semi-h 2b9c91b
feat: Use preprocessor to handle the CUDA backend in the main file.
semi-h 5ac4f30
feat(omp): Add an empty OpenMP backend to test the backend structure.
semi-h 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
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,131 @@ | ||
module m_base_backend | ||
use m_allocator, only: allocator_t, field_t | ||
use m_common, only: dp | ||
use m_tdsops, only: tdsops_t, dirps_t | ||
|
||
implicit none | ||
|
||
type, abstract :: base_backend_t | ||
!! base_backend class defines all the abstract operations that the | ||
!! solver class requires. | ||
!! | ||
!! For example, transport equation in solver class evaluates the | ||
!! derivatives in x, y, and z directions, and reorders the input | ||
!! fields as required. Then finally, combines all the directional | ||
!! derivatives to obtain the divergence of U*. | ||
!! | ||
!! All these high level operations solver class executes are | ||
!! defined here using the abstract interfaces. Every backend | ||
!! implementation extends the present abstact backend class to | ||
!! define the specifics of these operations based on the target | ||
!! architecture. | ||
|
||
real(dp) :: nu | ||
class(allocator_t), pointer :: allocator | ||
class(dirps_t), pointer :: xdirps, ydirps, zdirps | ||
contains | ||
procedure(transeq_ders), deferred :: transeq_x | ||
procedure(transeq_ders), deferred :: transeq_y | ||
procedure(transeq_ders), deferred :: transeq_z | ||
procedure(transposer), deferred :: trans_x2y | ||
procedure(transposer), deferred :: trans_x2z | ||
procedure(sum9into3), deferred :: sum_yzintox | ||
procedure(get_fields), deferred :: get_fields | ||
procedure(set_fields), deferred :: set_fields | ||
procedure(alloc_tdsops), deferred :: alloc_tdsops | ||
end type base_backend_t | ||
|
||
abstract interface | ||
subroutine transeq_ders(self, du, dv, dw, u, v, w, dirps) | ||
!! transeq equation obtains the derivatives direction by | ||
!! direction, and the exact algorithm used to obtain these | ||
!! derivatives are decided at runtime. Backend implementations | ||
!! are responsible from directing calls to transeq_ders into | ||
!! the correct algorithm. | ||
import :: base_backend_t | ||
import :: field_t | ||
import :: dirps_t | ||
implicit none | ||
|
||
class(base_backend_t) :: self | ||
class(field_t), intent(inout) :: du, dv, dw | ||
class(field_t), intent(in) :: u, v, w | ||
type(dirps_t), intent(in) :: dirps | ||
end subroutine transeq_ders | ||
end interface | ||
|
||
abstract interface | ||
subroutine transposer(self, u_, v_, w_, u, v, w) | ||
!! transposer subroutines are straightforward, they rearrange | ||
!! data into our specialist data structure so that regardless | ||
!! of the direction tridiagonal systems are solved efficiently | ||
!! and fast. | ||
import :: base_backend_t | ||
import :: field_t | ||
implicit none | ||
|
||
class(base_backend_t) :: self | ||
class(field_t), intent(inout) :: u_, v_, w_ | ||
class(field_t), intent(in) :: u, v, w | ||
end subroutine transposer | ||
end interface | ||
|
||
abstract interface | ||
subroutine sum9into3(self, du, dv, dw, du_y, dv_y, dw_y, du_z, dv_z, dw_z) | ||
!! sum9into3 subroutine combines all the directional velocity | ||
!! derivatives into the corresponding x directional fields. | ||
import :: base_backend_t | ||
import :: field_t | ||
implicit none | ||
|
||
class(base_backend_t) :: self | ||
class(field_t), intent(inout) :: du, dv, dw | ||
class(field_t), intent(in) :: du_y, dv_y, dw_y, du_z, dv_z, dw_z | ||
end subroutine sum9into3 | ||
end interface | ||
|
||
abstract interface | ||
subroutine get_fields(self, u_out, v_out, w_out, u, v, w) | ||
!! copy the specialist data structure from device or host back | ||
!! to a regular 3D data structure. | ||
import :: base_backend_t | ||
import :: dp | ||
import :: field_t | ||
implicit none | ||
|
||
class(base_backend_t) :: self | ||
real(dp), dimension(:, :, :), intent(out) :: u_out, v_out, w_out | ||
class(field_t), intent(in) :: u, v, w | ||
end subroutine get_fields | ||
|
||
subroutine set_fields(self, u, v, w, u_in, v_in, w_in) | ||
!! copy the initial condition stored in a regular 3D data | ||
!! structure into the specialist data structure arrays on the | ||
!! device or host. | ||
import :: base_backend_t | ||
import :: dp | ||
import :: field_t | ||
implicit none | ||
|
||
class(base_backend_t) :: self | ||
class(field_t), intent(inout) :: u, v, w | ||
real(dp), dimension(:, :, :), intent(in) :: u_in, v_in, w_in | ||
end subroutine set_fields | ||
end interface | ||
|
||
abstract interface | ||
subroutine alloc_tdsops(self, tdsops, n, dx, operation, scheme) | ||
import :: base_backend_t | ||
import :: dp | ||
import :: tdsops_t | ||
implicit none | ||
|
||
class(base_backend_t) :: self | ||
class(tdsops_t), allocatable, intent(inout) :: tdsops | ||
integer, intent(in) :: n | ||
real(dp), intent(in) :: dx | ||
character(*), intent(in) :: operation, scheme | ||
end subroutine alloc_tdsops | ||
end interface | ||
|
||
end module m_base_backend |
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.
Not sure how you want to go about tests, but this function would be well suited to have one as it is easy to make a typo with sign/variables and it is isolated from the rest of the codebase.