Refactor GpuVector to wrap GpuBuffer - #7372
Open
havahol wants to merge 7 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor
GpuVectorto own GPU memory viaGpuBufferSummary
Previously,
GpuVectorduplicated responsibilities already handled byGpuBuffer: allocation, deallocation, size tracking, and parts of host/device transfer.This PR refactors
GpuVectorto wrap aGpuBuffermember, reusingGpuBufferfor raw GPU storage while keeping vector-specific operations (cuBLAS, async copies, index-set helpers, dim instead of size) inGpuVector.The public
GpuVectorAPI is unchanged.Changes
GpuVectorrefactorT* m_dataOnDeviceandint m_numberOfElementswithGpuBuffer<T> m_buffer.GpuBufferwhere possible (constructors,data(),dim(), host/device copies forDune::BlockVector, etc.).GpuBufferstores size assize_t; cuBLAS calls now usedetail::to_int()at the call site instead of storing size asintinGpuVector.checkedSize()to validate that requested sizes fit inintduring construction andresize()(cuBLAS requirement).GpuBufferfixes and testsExpanded
test_GpuBuffercoverage, which exposed and fixed two bugs:resize: growing a buffer updatedm_numberOfElementsbut did just re-allocate the old capacity.copyToHost(BlockVector): size check compared againstsize()instead ofdim()(total scalar count =size() * block_size = dim()).Pointer attribute helpers
is_gpu_pointer.hpptogpu_pointer_attributes.hpp.isCPUPointer()to detect whether a pointer refers to host memory (used when validating host pointers passed toGpuBufferconstructors).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)
ctest -R 'TestGpuVector|TestGpuBuffer|test_gpu_pointer_attributes' --output-on-failureGpuVector(e.g.TestGpuJac,TestGpuDILU,test_preconditioner_factory_gpu), or simply all tests.Next steps
cudaMemcpycalls into reusable utility functions ingpuistl::detail.GpuVector,GpuBuffer, and other gpuistl types can share the same logic.GpuBufferwith async transfers.