Skip to content

Refactor GpuVector to wrap GpuBuffer - #7372

Open
havahol wants to merge 7 commits into
OPM:masterfrom
havahol:refactor-gpu-vector-buffer
Open

Refactor GpuVector to wrap GpuBuffer#7372
havahol wants to merge 7 commits into
OPM:masterfrom
havahol:refactor-gpu-vector-buffer

Conversation

@havahol

@havahol havahol commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Refactor GpuVector to own GPU memory via GpuBuffer

Summary

Previously, GpuVector duplicated responsibilities already handled by GpuBuffer: allocation, deallocation, size tracking, and parts of host/device transfer.

This PR refactors GpuVector to wrap a GpuBuffer member, reusing GpuBuffer for raw GPU storage while keeping vector-specific operations (cuBLAS, async copies, index-set helpers, dim instead of size) in GpuVector.

The public GpuVector API is unchanged.

Changes

GpuVector refactor

  • Replaced T* m_dataOnDevice and int m_numberOfElements with GpuBuffer<T> m_buffer.
  • Delegated equivalent functionality to GpuBuffer where possible (constructors, data(), dim(), host/device copies for Dune::BlockVector, etc.).
  • GpuBuffer stores size as size_t; cuBLAS calls now use detail::to_int() at the call site instead of storing size as int in GpuVector.
  • Added checkedSize() to validate that requested sizes fit in int during construction and resize() (cuBLAS requirement).

GpuBuffer fixes and tests

Expanded test_GpuBuffer coverage, which exposed and fixed two bugs:

  • resize: growing a buffer updated m_numberOfElements but did just re-allocate the old capacity.
  • copyToHost(BlockVector): size check compared against size() instead of dim() (total scalar count = size() * block_size = dim()).

Pointer attribute helpers

  • Renamed is_gpu_pointer.hpp to gpu_pointer_attributes.hpp.
  • Added isCPUPointer() to detect whether a pointer refers to host memory (used when validating host pointers passed to GpuBuffer constructors).

Test plan

(Suggested by the LLM that fixed all my markdown encodings - not sure if you usually specify this, or if it is standard anyway)

  • Build GPU-enabled opm-simulators
  • ctest -R 'TestGpuVector|TestGpuBuffer|test_gpu_pointer_attributes' --output-on-failure
  • Run broader gpuistl tests that use GpuVector (e.g. TestGpuJac, TestGpuDILU, test_preconditioner_factory_gpu), or simply all tests.
  • Confirm tests still pass after hipify (HIP build)

Next steps

  • Move all cudaMemcpy calls into reusable utility functions in gpuistl::detail.
  • Centralize pointer-attribute checks (e.g. host vs device) in those helpers so GpuVector, GpuBuffer, and other gpuistl types can share the same logic.
  • Extend GpuBuffer with async transfers.

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.

1 participant