Alexey Medvedev
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # NEMO/GPU OpenACC training/workshop ## Goals: - Perform hands-on practice for the methodology, tools and techniques that are used for NEMO/GPU porting - Alexey, Rommel: review and improvement of the existing hands-on materials and engineering tools - Carlos, Aitor: acquire practical skills of using OpenACC in NEMO - Laleh: check the correctness and ability to execute the Tracers and Ocean Dynamics regions on MN5-ACC ## Results ### Hands-on materials (Alexey & Rommel) Updated the introductory slides and added couple of new points: - the scalars in GPU code: workaround for NVIDIA - handling of OpenMP decomposition code in NEMO - general way of porting subroutines in NEMO URL: https://docs.google.com/presentation/d/1DNjQx3oWBne6s7fqcQXI2VwrOb3xQxOI ### Methodology and tools (Rommel & Alexey) - updated the Loki based tool for reviewing the Fortran modules in NEMO to get the basic structure: helps to make decisions before porting new modules to GPU - updated the tool that connects compiler diagnostics to source code - how to automate creting the data copy clauses for separate memory code? Brainstormed with Nikolaos ### Code: general and utility code (Alexey) - made an update to LBC code to use uniform lbc_lnk calls both in GPU and CPU code Now, istead of this duplicated code for `lbc_lnk` and `lbc_lnk_multi`: ``` oncpu CALL lbc_lnk( 'icedyn_adv_pra', zei_max, 'T', 1.0_wp ) oncpu CALL lbc_lnk( 'icedyn_adv_pra', zes_max, 'T', 1.0_wp ) ongpu CALL lbc_lnk_gpu( 'icedyn_adv_pra', zei_max, 'T', 1.0_wp ) ongpu CALL lbc_lnk_gpu( 'icedyn_adv_pra', zes_max, 'T', 1.0_wp ) ``` We can leave the `lbc_lnk` and `lbc_lnk_multi` code original, without any changes: ``` CALL lbc_lnk( 'icedyn_adv_pra', zei_max, 'T', 1.0_wp ) CALL lbc_lnk( 'icedyn_adv_pra', zes_max, 'T', 1.0_wp ) ``` - made an update to GPU macroses to simplify handling the OpenMP decomposition code Now instead of this code for OpenMP decomposition: ``` oncpu CALL nompinfo( itid, ithreads ) oncpu ji1 = nompstas(itid,npti) oncpu ji2 = nompends(itid,npti) ongpu itid = 0; ithreads = 1 ongpu ji1 = 1 ongpu ji2 = npti ``` we may use single GPU-aware macros that hides all details: ``` gpu_aware_omp_decomposition(npti, ji1, ji2) ``` ### Code: Tracers (Laleh) We checked the ability of the existing code to build & run, and the reproducibility of the existing ported code on MN5-ACC. #### Tracers: good modules The modules that are reproducible with at least 64 timesteps checked: - File: `OCE/TRA/tradmp.F90` - File: `OCE/TRA/trasbc.F90` - File: `OCE/TRA/tranxt.F90` - File: `OCE/TRA/traldf_iso.F90` - File: `OCE/TRA/trazdf.F90` #### Tracers: the modules with issues The modules with reproducibility issues: - File: `OCE/TRA/eosbn2.F90` > Issue: Results are not identical when using 64 time steps, though they are consistent at 16 time steps. - File: `OCE/TRA/traadv_fct.F90` > Issue: Reproducibility fails with 32 time steps or more. > Observation: Modifying the lateral boundary condition link from lbc_lnk_gpu to lbc_lnk did not resolve the issue. - File: `OCE/TRA/trabbl.F90` > Issue: Results are not reproducible even with 16 time steps. ### Code: Ocean dynamics modules (Laleh) We checked the ability of the existing code to build & run, and the reproducibility of the existing ported code on MN5-ACC. Also, ported some new code in `dynzdf.F90`. #### Ocean dynamics: good modules Reproducible and working OK: - File: `OCE/DYN/dynzad.F90` #### Ocean dynamics: the modules with isuues The modules with detected issues: - File: `OCE/DYN/dynzdf.F90` > Issue: A three-dimensional loop has a backward dependency in the third dimension, preventing reproducibility. > Observation: Even when using !$acc parallel loop seq on the outermost loop, reproducibility is not achieved. As a workaround, this loop is currently executed on the CPU. - File: `OCE/DYN/dynkeg.F90` > Issue: Long execution time leading to failure. > Error Message: Execution stops with error Failing at address: 0xc4f1002c245c. ### Tracers and Ocean dynamics modules: summary and recommendations: - Further investigation is required to isolate the root causes of non-reproducibility, especially in files like `tra_adv_fct`, `eosbn2.F90`, and `dynzdf.F90`. - Consider examining data dependencies under different execution models (CPU vs GPU). - Profiling and debugging tools should be employed to trace the execution failure in dynkeg.F90 especially deactivating async. - Code restructuring or loop reordering may be necessary to resolve backward dependencies that hinder reproducibility. - The recommendation is to prioritize Tracer modules: - First, we should understand why eos part is failing bitwise comparisons on late steps - Second, we have to detect and eliminate the identity issues on trabbl, tra_adv_fct - Then, it is good to try to make the whole step_tracers work in separate memory mode: - with explicit data transfer directives in each Fortran module on GH (build with `MANAGED_MEMORY=0`) - test then, if the same code works on MN5-ACC - try to gather all explicit data transfers into a big cumulative directive somewhere at the beginning of `step_tracers` ### Code: Sea Ice rheology module (Aitor) The module `src/ICE/icedyn_rhg_evp.F90` along with the function `ice_var_sshdyn` (`src/ICE/icevar.F90`) and subroutines `ice_strength` (`src/ICE/icedyn_rdgrft.F90`) and `bdy_ice_dyn` (`src/OCE/BDY/bdyice.F90`) were ported to work on GPUs in managed and separated memory modes. Here there are some observations made during the work: #### icedyn_rhg_evp - `zfmask`: Termporary arrays starting by z in NEMO code usually need to be acc created on the GPU and they do not persist after the execution of the subroutine. That is not the case of zfmask. The subroutine `icedyn_rhg_evp` receives the number of iteration `kt` as an argument and `zfmask` is only allocated in the original code if `kt==nit000` that is, the first iteration, and left in memory during all the runtime, never deallocated. When porting the code to GPU, the variable is initialised at `kt==nit000` and transfered back to the CPU. As it is a read-only parameter in next iterations, its valued is `!$acc copyin` when needed. ``` IF ( kt == nit000 ) THEN oncpu !$omp barrier oncpu !$omp master ALLOCATE( zfmask(jpi,jpj) ) ongpu !$acc data create(zfmask) ongpu !$acc parallel loop gang vector collapse(2) default(present) DO jj = 1, jpjm1 DO ji = 1, jpim1 ! NO vector opt. zfmask(ji,jj) = tmask(ji,jj,1) * tmask(ji+1,jj,1) * tmask(ji,jj+1,1) * tmask(ji+1,jj+1,1) END DO END DO ... ongpu !$acc update host(zfmask) ongpu !$acc end data ENDIF ... ongpu !$acc data copyin(zfmask) ongpu !$acc parallel loop gang vector collapse(2) default(present) DO jj = MAX(1,jj1), MIN(jj2,jpjm1) DO ji = 1, jpim1 ! shear at F points zds(ji,jj) = ( ( u_ice(ji,jj+1) * r1_e1u(ji,jj+1) - u_ice(ji,jj) * r1_e1u(ji,jj) ) * e1f(ji,jj) * e1f(ji,jj) & & + ( v_ice(ji+1,jj) * r1_e2v(ji+1,jj) - v_ice(ji,jj) * r1_e2v(ji,jj) ) * e2f(ji,jj) * e2f(ji,jj) & & ) * r1_e1e2f(ji,jj) * zfmask(ji,jj) END DO END DO ongpu !$acc end parallel loop ongpu !$acc end data ... ``` - The main calculation consists in a big outer loop over `jter` index and double nested loops inside it. As the range of jter was not known, this outer loop was left as it is in the original code, but internal double-nested loopes were parallelised and collapsed by default with `!$acc parallel loop gang vector collapse(2)` ``` DO jter = 1 , nn_nevp ... ongpu !$acc parallel loop gang vector collapse(2) default(present) DO jj = MAX(1,jj1), MIN(jj2,jpj) DO ji = 1, jpi zu_ice(ji,jj) = u_ice(ji,jj) * umask(ji,jj,1) ! velocity at previous time step zv_ice(ji,jj) = v_ice(ji,jj) * vmask(ji,jj,1) END DO END DO ongpu !$acc end parallel loop ... ``` Function `ice_var_sshdyn` and subroutines `ice_strength` and `bdy_ice_dyn` are only called inside this subroutine, so they can be ported directly to GPU without creating an alternate GPU version. #### rhg_evp Minor subroutine. Most of the arrays are already present on the GPU except `zres` which is `!$acc create`'d. #### ice_strength `SUM(..., dim=3)` had to be restructured to work on GPU, consider to change also the CPU version for the sake of homogeneity ``` oncpu strength(:,:) = rn_pstar * SUM( v_i(:,:,:), dim=3 ) * EXP( -rn_crhg * ( 1._wp - SUM( a_i(:,:,:), dim=3 ) ) ) ongpu !$acc parallel loop gang vector collapse(2) present(strength,a_i,v_i) ongpu DO jj = 1, jpj ongpu DO ji = 1, jpi ongpu strength(ji,jj) = rn_pstar * SUM( v_i(ji,jj,:) ) * EXP( -rn_crhg * ( 1._wp - SUM( a_i(ji,jj,:) ) ) ) ongpu END DO ongpu END DO ongpu !$acc end parallel loop ``` Variable `strength` is the one that is modified and returned #### ice_dyn_sshdyn Small subroutine with a couple of array assignations, no loops. #### bdy_ice_dyn Double nested loops inside of `SELECT-CASE` control structure. The approach was conservative only including `!$acc` directives inside each `CASE` statement, although some loops are treated sequentially. A more aggressive optimization entails placing the loops at the outside of `SELECT-CASE` control structure or directly removing it. ### Code: Ocean Dynamics dyn_vor module (Carlos) I ported the dyn_vor.F90 module and achieved reproducible results using the reproducible build type. I focused on the subroutine used by the vor_een option in the eORCA1 namelist, but the loop pattern is similar and can likely be easily adapted for the other options. I didn’t have time to port the trends call to trd_dyn, which is also not used in the eORCA1 configuration we tested. #### Code Transformations - `MAX()` and `MIN()` clauses in loop bounds caused incorrect results under OpenACC. Precomputing them outside the loop (e.g., `kj1_aux`, `kj2_aux`) fixed it. ``` ! Before (incorrect results) !$acc parallel loop gang vector present(...) DO jk = 1, jpkm1 DO jj = MAX(2, kj1), MIN(kj2, jpjm1) DO ji = fs_2, fs_jpim1 ... ! After (correct results) kj1_aux = MAX(2, kj1) kj2_aux = MIN(kj2, jpjm1) !$acc parallel loop gang vector present(...) DO jk = 1, jpkm1 DO jj = kj1_aux, kj2_aux DO ji = fs_2, fs_jpim1 ``` - Moving `SELECT-CASE` outside the main loop over jk to improve GPU parallelitzation and avoid issues with control flow inside parallel regions. Interestingly in this case MAX and MIN did not interfere with good code generation ... ``` ! Before (cannot collapse loops, switch inside) DO jk = 1, jpkm1 SELECT CASE(kvor) CASE(np_RVO) DO jj = MAX(2,kj1), MIN(kj2,jpj) DO ji = 2, jpi zwt(ji,jj,jk) = ... END DO END DO ... END SELECT END DO SELECT CASE(kvor) CASE(np_RVO) !$acc parallel loop collapse(3) ... DO jk = 1, jpkm1 DO jj = kj1_aux, kj2_aux DO ji = 2, jpi zwt(ji,jj,jk) = ... END DO END DO END DO ... END SELECT ``` - Original single jk loop with flux + vorticity calc caused wrong results under OpenACC kernels so we split it into three. ``` ! Loop 1: fluxes FOR jk zwx(...) = ... zwy(...) = ... ztne(...) = 0 ... END FOR ! Loop 2: jj = 2 case IF kj1 ≤ 2 AND kj2 ≥ 2 THEN FOR jk, ji ztne(ji,2,jk) = ... END FOR END IF ! Loop 3: general vorticity FOR jk, jj ≥ 3, ji ztne(ji,jj,jk) = ... END FOR ``` #### NEMO_build Suggestions/Requests - Add an option to the `dnb.sh` command to repeat from the makenemo step. This is useful when only a single file has changed, which is usually the case when continuously checking the reproducibility of new changes. - For Risc-V I will need a way of using the nemo-build with a test configuration because I need to work really small grids like 20,20,10 to be able to run with the emulator.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully