Skip to content

Improve usability of amrex::Gpu::Buffer#4697

Merged
WeiqunZhang merged 5 commits intoAMReX-Codes:developmentfrom
AlexanderSinn:improve_usability_of_amrex__Gpu__Buffer
Oct 9, 2025
Merged

Improve usability of amrex::Gpu::Buffer#4697
WeiqunZhang merged 5 commits intoAMReX-Codes:developmentfrom
AlexanderSinn:improve_usability_of_amrex__Gpu__Buffer

Conversation

@AlexanderSinn
Copy link
Copy Markdown
Member

@AlexanderSinn AlexanderSinn commented Oct 6, 2025

Summary

This PR expands the capabilities of amrex::Gpu::Buffer<T> so that it can be first default constructed, then modified by the CPU, and lastly copied over to the GPU, instead of everything happening in the constructor.

Example:

amrex::Gpu::Buffer<int> buf;

buf.resize(n);

for (int i=0; i<n; ++i) {
    buf[i] = i*i;
}

buf.copyToDeviceAsync();

int * ptr = buf.data();
// Use ptr inside ParallelFor

// optional:
// Change values of ptr inside ParallelFor
buf.copyToHost();
// Use buf.hostData() or buf[] on the CPU

Additional background

Follow-up to discussion in #4640

Checklist

The proposed changes:

  • fix a bug or incorrect behavior in AMReX
  • add new capabilities to AMReX
  • changes answers in the test suite to more than roundoff level
  • are likely to significantly affect the results of downstream AMReX users
  • include documentation in the code and/or rst files, if appropriate

@AlexanderSinn AlexanderSinn changed the title [WIP] Improve usability of amrex::Gpu::Buffer Improve usability of amrex::Gpu::Buffer Oct 7, 2025
@WeiqunZhang WeiqunZhang merged commit f9ad2c6 into AMReX-Codes:development Oct 9, 2025
73 checks passed
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