Skip to content
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

GridTools Stage Extents #136

Closed
wants to merge 28 commits into from

Conversation

eddie-c-davis
Copy link
Contributor

Description

This PR modifies the GridTools backends to use the make_stage_with_extent method to define stages rather than make_stage as in the Dawn backends. For example, the qx_edge_west stencil in the FV3 dycore,

def qx_edge_west2(qin: sd, dxa: sd, qx: sd):
    with computation(PARALLEL), interval(...):
        g_in = dxa / dxa[-1, 0, 0]
        qx0 = qx
        qx = (
            3.0 * (g_in * qin[-1, 0, 0] + qin) - (g_in * qx0[-1, 0, 0] + qx0[1, 0, 0])
        ) / (2.0 + 2.0 * g_in)

the qx0 temporary is introduced to prevent a nonzero horizontal extents static assertion error. The generated code with make_stage compiles but produces incorrect data. The proposed change generates the following code which produces correct results.

computation_t gt_computation = gt::make_computation<backend_t>(
        make_grid(domain),
        gt::make_multistage(gt::execute::parallel(),
            gt::make_stage_with_extent<stage__10_func, gt::extent<0, 0, 0, 0>>(
                p_dxa(), p_g_in()
            ),
            gt::make_stage_with_extent<stage__13_func, gt::extent<-1, 1, 0, 0>>(
                p_qx(), p_qx0()
            ),
            gt::make_stage_with_extent<stage__16_func, gt::extent<0, 0, 0, 0>>(
                p_g_in(), p_qin(), p_qx0(), p_qx()
            )
        )
    );

This change is required because the GridTools dependence analysis cannot always compute the necessary extents when temporaries are reused. The is documented in issue #920 in the GridTools repository.

@havogt
Copy link
Contributor

havogt commented Aug 12, 2020

Finally, I found the root cause of the issue, see #143. Did this PR fix the issue for all GT backends (especially GPU). There should be a data race even with this PR. The stage_with_extent probably "fixed" the dependency analysis, but not the race condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants