-
Notifications
You must be signed in to change notification settings - Fork 12
Initial OpenMP/GPU support #228
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
Open
pbartholomew08
wants to merge
28
commits into
xcompact3d:main
Choose a base branch
from
pbartholomew08:omp_gpu
base: main
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
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
265a028
WIP: Implement a OpenMP target field type and allocator
pbartholomew08 c8ae25e
Move OpenMP target offloads to omp/target directory
pbartholomew08 9dad110
Optionally build OpenMP Target backend
pbartholomew08 1be2573
Fix types in OpenMP target block allocator
pbartholomew08 d1da9cf
WIP on OMP target vecadd
pbartholomew08 68b0fef
Correcting link order
pbartholomew08 63dc2ac
Cleaning up test_vecadd
pbartholomew08 e170514
The omp backend must assign its allocator based on class
pbartholomew08 1ad568c
Don't declare the method as a module function
pbartholomew08 833e6f5
Need to allocate the new field pointer
pbartholomew08 85005a7
Specify the target mapping operations when creating a field
pbartholomew08 842fc8d
Initially 'working' OMP target vec add
pbartholomew08 59b40ed
Remove debugging print statement
pbartholomew08 a48a61c
We only need the 3-D view of data on the device
pbartholomew08 19acbc9
Remove duplicate entry from CMakeLists sources
pbartholomew08 c713318
Mark index calculations as offloadable
pbartholomew08 13f435e
Add support for get/set fields with OMP target
pbartholomew08 06c1877
WIP - attempting simplified OMP calls
pbartholomew08 105d7d4
WIP allocating memory using OpenMP API
pbartholomew08 6ef42de
Continuing ...
pbartholomew08 362e992
Trying to map pointers to target...
pbartholomew08 dbf7ee0
Initial working version of OMPTARGET vec add
pbartholomew08 8fbf90c
Restore IBM module
pbartholomew08 46ca117
Minor formatting change
pbartholomew08 559642d
Adding support for OMP offload of timestepping
pbartholomew08 9755b76
Update OMPTGT test definitions
pbartholomew08 794a8f3
Run fprettify
pbartholomew08 083c5f0
Fixing CUDA syntax
pbartholomew08 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,179 @@ | ||
| !!! backends/omp/target/allocator.f90 | ||
| !! | ||
| !! Implements an allocator specialised to OMP target offloading | ||
|
|
||
| module m_omptgt_allocator | ||
|
|
||
| use iso_c_binding, only: c_ptr, c_f_pointer, c_sizeof | ||
| use omp_lib, only: omp_target_alloc, omp_target_free, omp_get_default_device | ||
|
|
||
| use m_common, only: dp | ||
|
|
||
| use m_allocator, only: allocator_t | ||
| use m_mesh, only: mesh_t | ||
| use m_field, only: field_t | ||
|
|
||
| implicit none | ||
|
|
||
| private | ||
| public :: omptgt_allocator_t | ||
| public :: omptgt_field_t | ||
|
|
||
| type, extends(allocator_t) :: omptgt_allocator_t | ||
| contains | ||
| procedure :: create_block => create_block_omptgt | ||
| end type omptgt_allocator_t | ||
|
|
||
| interface omptgt_allocator_t | ||
| module procedure omptgt_allocator_init | ||
| end interface omptgt_allocator_t | ||
|
|
||
| type, extends(field_t) :: omptgt_field_t | ||
| ! A device-resident field | ||
| integer, private :: dev_id | ||
| type(c_ptr), private :: dev_ptr | ||
| real(dp), pointer, private :: p_data_tgt(:) => null() | ||
| real(dp), pointer, contiguous :: data_tgt(:, :, :) => null() | ||
| contains | ||
| procedure :: destroy => omptgt_field_destroy | ||
| procedure :: fill => fill_omptgt | ||
| procedure :: get_shape => get_shape_omptgt | ||
| procedure :: set_shape => set_shape_omptgt | ||
| end type omptgt_field_t | ||
|
|
||
| interface omptgt_field_t | ||
| module procedure omptgt_field_init | ||
| end interface omptgt_field_t | ||
|
|
||
| contains | ||
|
|
||
| ! Constructor for the OMP target offload allocator | ||
| type(omptgt_allocator_t) function omptgt_allocator_init(dims, sz) result(a) | ||
| integer, intent(in) :: dims(3) | ||
| integer, intent(in) :: sz | ||
|
|
||
| a%allocator_t = allocator_t(dims, sz) | ||
| end function omptgt_allocator_init | ||
|
|
||
| ! Allocates a device-resident block | ||
| function create_block_omptgt(self, next) result(ptr) | ||
| class(omptgt_allocator_t), intent(inout) :: self | ||
| class(field_t), pointer, intent(in) :: next | ||
| type(omptgt_field_t), pointer :: newblock_tgt | ||
| class(field_t), pointer :: ptr | ||
|
|
||
| self%next_id = self%next_id + 1 | ||
| allocate (newblock_tgt) | ||
| newblock_tgt = omptgt_field_t(self%ngrid, next, id=self%next_id) | ||
| ptr => newblock_tgt | ||
|
|
||
| end function create_block_omptgt | ||
|
|
||
| ! Constructs a device-resident field | ||
| type(omptgt_field_t) function omptgt_field_init(ngrid, next, id) result(f) | ||
| integer, intent(in) :: ngrid | ||
| class(field_t), pointer, intent(in) :: next | ||
| integer, intent(in) :: id | ||
|
|
||
| f%refcount = 0 | ||
| f%next => next | ||
| f%id = id | ||
|
|
||
| f%dev_id = omp_get_default_device() | ||
| f%dev_ptr = omp_target_alloc(ngrid*c_sizeof(0.0_dp), f%dev_id) | ||
| call c_f_pointer(f%dev_ptr, f%p_data_tgt, shape=[ngrid]) | ||
|
|
||
| end function omptgt_field_init | ||
|
|
||
| subroutine omptgt_field_destroy(self) | ||
| class(omptgt_field_t) :: self | ||
|
|
||
| nullify (self%data_tgt) | ||
| nullify (self%p_data_tgt) | ||
| call omp_target_free(self%dev_ptr, self%dev_id) | ||
| end subroutine | ||
|
|
||
| ! Deallocates device-resident memory before deallocating the base type | ||
| subroutine destroy(self) | ||
|
Collaborator
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. This |
||
| class(omptgt_allocator_t) :: self | ||
|
|
||
| class(field_t), pointer :: ptr | ||
|
|
||
| ptr => self%first | ||
| do | ||
| if (.not. associated(ptr)) then | ||
| exit | ||
| end if | ||
|
|
||
| select type (ptr) | ||
| type is (omptgt_field_t) | ||
| call ptr%destroy() | ||
| end select | ||
|
|
||
| ptr => ptr%next | ||
| end do | ||
|
|
||
| call self%allocator_t%destroy() | ||
| end subroutine | ||
|
|
||
| subroutine fill_omptgt(self, c) | ||
| class(omptgt_field_t) :: self | ||
| real(dp), intent(in) :: c | ||
|
|
||
| !call fill_omptgt_(self%p_data_tgt, c, size(self%p_data_tgt)) | ||
| call fill_omptgt_3d_(self%data_tgt, c) | ||
|
|
||
| end subroutine fill_omptgt | ||
|
|
||
| subroutine fill_omptgt_(p_data_tgt, c, n) | ||
| real(dp), dimension(:), intent(inout) :: p_data_tgt | ||
| real(dp), intent(in) :: c | ||
| integer, intent(in) :: n | ||
|
|
||
| integer :: i | ||
|
|
||
| !$omp target teams distribute parallel do has_device_addr(p_data_tgt) | ||
| do i = 1, n | ||
| p_data_tgt(i) = c | ||
| end do | ||
| !$omp end target teams distribute parallel do | ||
|
|
||
| end subroutine | ||
|
|
||
| subroutine fill_omptgt_3d_(data_tgt, c) | ||
| real(dp), dimension(:, :, :), intent(inout) :: data_tgt | ||
| real(dp), intent(in) :: c | ||
|
|
||
| integer, dimension(3) :: n | ||
| integer :: i, j, k | ||
|
|
||
| n = shape(data_tgt) | ||
|
|
||
| !$omp target teams distribute parallel do collapse(3) has_device_addr(data_tgt) | ||
| do k = 1, n(3) | ||
| do j = 1, n(2) | ||
| do i = 1, n(1) | ||
| data_tgt(i, j, k) = c | ||
| end do | ||
| end do | ||
| end do | ||
| !$omp end target teams distribute parallel do | ||
| end subroutine | ||
|
|
||
| function get_shape_omptgt(self) result(dims) | ||
| class(omptgt_field_t) :: self | ||
| integer :: dims(3) | ||
|
|
||
| dims = shape(self%data_tgt) | ||
| end function | ||
|
|
||
| subroutine set_shape_omptgt(self, dims) | ||
| class(omptgt_field_t) :: self | ||
| integer, intent(in) :: dims(3) | ||
|
|
||
| call c_f_pointer(self%dev_ptr, self%data_tgt, shape=dims) | ||
|
|
||
| end subroutine | ||
|
|
||
| end module m_omptgt_allocator | ||
|
|
||
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.
Could we use CMake cache varibales (e.g.
OMP_TGT_ARCH) so we don't need to edit CMake files?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.
Good point - this was added for development, and not intended as the actual implementation