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

compiler: Add optional pass for runtime stability check #2327

Merged
merged 4 commits into from
Mar 12, 2024

Conversation

FabioLuporini
Copy link
Contributor

No description provided.

Copy link

codecov bot commented Mar 11, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 11 lines in your changes are missing coverage. Please review.

Project coverage is 86.66%. Comparing base (32308f4) to head (aaea94a).

Files Patch % Lines
devito/passes/iet/errors.py 89.36% 2 Missing and 3 partials ⚠️
devito/operator/operator.py 63.63% 3 Missing and 1 partial ⚠️
devito/core/operator.py 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2327   +/-   ##
=======================================
  Coverage   86.66%   86.66%           
=======================================
  Files         229      231    +2     
  Lines       43176    43260   +84     
  Branches     8004     8022   +18     
=======================================
+ Hits        37417    37490   +73     
- Misses       5062     5068    +6     
- Partials      697      702    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

else:
continue

name = sregistry.make_name(prefix='energy')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe finitecheck it is likely someone would use energy since it used for various appplications

energy = Symbol(name=name, dtype=f.dtype)

eqns = [Eq(energy, 0.0),
Inc(energy, Abs(Pow(f.subs(f.time_dim, 0), 2)))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overkill, just f.sub the Abs(Pow won't change if it's NaN or not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Contributor Author

@FabioLuporini FabioLuporini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I've tweaked things

new generated code:

    /* Stability check */
    if ((time)%(100) == 0)
    {
      int check0 = is_finite0(x_M,x_m,y_M,y_m,nthreads,u_vec);
      if (!check0)
      {
        return 100;
      }
    }

and

static int is_finite0(const int x_M, const int x_m, const int y_M, const int y_m, const int nthreads, struct dataobj *restrict u_vec)
{
  float (*restrict u)[u_vec->size[1]][u_vec->size[2]] __attribute__ ((aligned (64))) = (float (*)[u_vec->size[1]][u_vec->size[2]]) u_vec->data;

  float accumulator = 0.0F;
  #pragma omp parallel num_threads(nthreads)
  {
    #pragma omp for collapse(2) schedule(static,1) reduction(+:accumulator)
    for (int x = x_m; x <= x_M; x += 1)
    {
      for (int y = y_m; y <= y_M; y += 1)
      {
        accumulator += u[0][x + 2][y + 2];
      }
    }
  }
  return isfinite(accumulator);
}

@FabioLuporini
Copy link
Contributor Author

also added another tiny test

Copy link
Contributor

@EdCaunt EdCaunt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

if not n.dim.is_Time:
continue

functions = [f for f in FindSymbols().visit(n)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: Might be cases where there is no stepping dim and only time dime, but can be for later if someone runs into it (unlikely).

@mloubout mloubout merged commit f29cb35 into master Mar 12, 2024
31 checks passed
@mloubout mloubout deleted the error-checking branch March 12, 2024 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants