gpufort icon indicating copy to clipboard operation
gpufort copied to clipboard

[ACC] Handle !$acc declare

Open domcharrier opened this issue 3 years ago • 1 comments

!$acc declare is not handled yet.

  • "A declare directive is used in the declaration section of a Fortran subroutine, function, or module."

  • "In a Fortran module declaration section, only create, copyin, device_resident, and 2084 link clauses are allowed."

For more details on the directive, see "2.13. Declare Directive" in the specification

Implementation approach:

  • [ ] Host functions & subroutines:

    • [x] Track function/subroutine begin and declarations in scanner tree & indexer
    • [x] Consider !$acc declare in indexer
    • [ ] Track return statements in scanner tree as child node of function/procedure (begin)
    • [ ] Track function/subroutine end in scanner tree as child node of function/procedure (begin)
    • [ ] Emit unstructured enter data routine call or equivalent shortcut after declaration section of function/subroutine
    • [ ] Emit unstructured exit data routine call or equivalent shortcut before function/subroutine end or return statement
  • [ ] Modules / Program

    • [x] Track module and declarations in scanner tree & indexer
    • [x] Consider !$acc declare in indexer
    • [ ] Assumed-size arrays * [x] Track allocate statements in in scanner tree * [ ] Emit unstructured enter data routine call or equivalent shortcut after allocate
    • [ ] Explicit-size arrays
      • [ ] ??? - not totally sure where to put the allocation
        • if no save keyword:
          • body of function/subroutine/program that uses the module
        • else if save keyword and not already present in global scope (scope 0):
          • body of function/subroutine/program that uses the module
      • [ ] Emit unstructured enter data routine call or equivalent shortcut where appropriate

Accelerator routines use "acc-declared" variables

Some thoughts:

  • Device routines can use variables that are mapped to the device via acc declare statements.
  • When we generate HIP code, we need to pass the respective device pointers as kernel parameters.
  • Hence, we would need to add a use statement with the respective module to the caller's (assuming loopnest) parent so that it is available in this scope. In case of gang, worker, vector accelerator routines, this must be done recursively.

domcharrier avatar May 04 '21 09:05 domcharrier

FYI @domcharrier - We use !$acc declare very frequently in our code.

sael9740 avatar May 04 '21 20:05 sael9740