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

First (write) access to temporary inside conditional bug #1142

Open
Stagno opened this issue Jun 15, 2021 · 1 comment
Open

First (write) access to temporary inside conditional bug #1142

Stagno opened this issue Jun 15, 2021 · 1 comment
Labels

Comments

@Stagno
Copy link
Contributor

Stagno commented Jun 15, 2021

The following Dusk code

from dusk.script import *

@stencil
def temp_access_bug(
    a: Field[K],
    b: Field[Edge],
    d: Field[Edge, K],
    
) -> None:

    z: Field[Edge, K]

    with domain.upward as k:

        if (a):
            z = b
            d = z

fails with the following error:

Assertion failed: `exprStmt' first access of temp field to be demoted (i.e lifetime.Begin) is not an `ExprStmt`
Function: 'void dawn::demoteTemporaryFieldToLocalVariable(dawn::iir::StencilInstantiation*, dawn::iir::Stencil*, int, const dawn::iir::Stencil::Lifetime&)'
Location: /scratch-shared/meteoswiss/scratch/jenkins/spack-stages/admin-tsa/spack-stage-dawn4py-master-exy4bjidi4cwlilrflvsxs4x5rpwjjdi/spack-src/dawn/src/dawn/Optimizer/TemporaryHandling.cpp:157

Dawn is not able to properly look inside the conditional to figure out that the temporary is written before being read.
I encountered the problem when translating mo_velocity_advection_stencil_19 using temporaries. This is the simplest reproducible I could write.

@Stagno Stagno added the bug label Jun 15, 2021
@mroethlin
Copy link
Contributor

The work around to this is to first initialize the field like so:

@stencil
def temp_access_bug(
    a: Field[K],
    b: Field[Edge],
    d: Field[Edge, K],
    
) -> None:

    z: Field[Edge, K]

    with domain.upward as k:
        z = 0
        if (a):
            z = b
            d = z

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

No branches or pull requests

2 participants