Skip to content

fn naive backend: reuse temporaries via sid::cached_allocator - #1836

Open
havogt wants to merge 2 commits into
GridTools:masterfrom
havogt:fn-naive-tmp-cached-allocator
Open

havogt wants to merge 2 commits into
GridTools:masterfrom
havogt:fn-naive-tmp-cached-allocator

Conversation

@havogt

@havogt havogt commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Depends on #1835 — only the last commit belongs to this PR.

Switches the fn naive backend's temporary allocator to sid::cached_allocator, which the fn GPU backend and the stencil cpu_kfirst/cpu_ifirst backends already use. Buffers are reused across calls instead of being freshly allocated (and page-faulted) every time.

Measured from gt4py (gtfn CPU, 6 temporaries of 256×256×80 float64, laptop, with the double allocation of #1832 removed): 37 ms (no zero-fill, #1835) → 16 ms per call with this PR.

Caveats of cached_allocator, for the reviewer to weigh:

  • Retention: buffers are cached per thread and per exact byte size and are never released before thread exit.
  • Thread affinity: the deleter returns a buffer to the allocating thread's thread_local cache. fn::make_backend creates the allocator and it is destroyed on the calling thread, and the thread pool only runs the loops inside a stage, so this is safe with the OpenMP and dummy pools. With the HPX pool, a caller that is itself an HPX task can resume on a different worker after hpx::parallel::for_loop; the destructor then pushes onto another worker's cache without synchronization. The same holds for an allocator that outlives its allocating thread.

std::make_unique<char[]> value-initializes, which zero-fills every
temporary serially on each call.
@havogt

havogt commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Written by an agent on behalf of @havogt

@gridtoolsjenkins

Copy link
Copy Markdown
Collaborator

Hi there, this is jenkins continuous integration...
Do you want me to verify this patch?

This branch has not been deployed

No deployments
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