Skip to content

Commit

Permalink
Reverted alloc_multiplier behaviour in reserve, made upload() optimiz…
Browse files Browse the repository at this point in the history
…eGPU reside behind a templated parameter. Fine-tuned overwrite().
  • Loading branch information
markusbattarbee committed May 30, 2024
1 parent 2dc8472 commit ba838da
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions include/splitvector/splitvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class SplitVector {
size_t _alloc_multiplier = 2; // host variable; multiplier for when reserving more space
Allocator _allocator; // Allocator used to allocate and deallocate memory;
Residency _location; // Flags that describes the current residency of our data
SplitVector* d_vec; // device copy pointer
SplitVector* d_vec = nullptr; // device copy pointer

/**
* @brief Checks if a pointer is valid and throws an exception if it's null.
Expand Down Expand Up @@ -387,11 +387,14 @@ class SplitVector {

if constexpr (std::is_trivially_copyable<T>::value) {
if (other._location == Residency::device) {
_location = Residency::device;
SPLIT_CHECK_ERR(
split_gpuMemcpyAsync(_data, other._data, size() * sizeof(T), split_gpuMemcpyDeviceToDevice, stream));
int device;
SPLIT_CHECK_ERR(split_gpuGetDevice(&device));
if (_location == Residency::host) {
SPLIT_CHECK_ERR(split_gpuMemPrefetchAsync(_data, capacity() * sizeof(T), device, stream));
_location = Residency::device;
}
SPLIT_CHECK_ERR(
split_gpuMemcpyAsync(_data, other._data, size() * sizeof(T), split_gpuMemcpyDeviceToDevice, stream));
SPLIT_CHECK_ERR(split_gpuMemPrefetchAsync(_size, sizeof(size_t), device, stream));
SPLIT_CHECK_ERR(split_gpuMemPrefetchAsync(_capacity, sizeof(size_t), device, stream));
return;
Expand Down Expand Up @@ -475,12 +478,16 @@ class SplitVector {
* @param stream The GPU stream to perform the upload on.
* @return Pointer to the uploaded SplitVector on the GPU.
*/
template <bool optimize = true>
HOSTONLY
SplitVector<T, Allocator>* upload(split_gpuStream_t stream = 0) {
if (!d_vec) {
SPLIT_CHECK_ERR(split_gpuMallocAsync((void**)&d_vec, sizeof(SplitVector), stream));
}
SPLIT_CHECK_ERR(split_gpuMemcpyAsync(d_vec, this, sizeof(SplitVector), split_gpuMemcpyHostToDevice, stream));
if constexpr (optimize) {
optimizeGPU(stream);
}
return d_vec;
}
/**
Expand Down Expand Up @@ -842,11 +849,6 @@ class SplitVector {
*/
HOSTONLY
void reserve(size_t requested_space, bool eco = false, split_gpuStream_t stream = 0) {
// If the users passes eco=true we allocate
// exactly what was requested
if (!eco) {
requested_space *= _alloc_multiplier;
}
// Vector was default initialized
if (_data == nullptr) {
_deallocate();
Expand All @@ -860,6 +862,11 @@ class SplitVector {
return;
}
// Reallocate.
// If the users passes eco=true we allocate
// exactly what was requested
if (!eco) {
requested_space *= _alloc_multiplier;
}
reallocate(requested_space, stream);
return;
}
Expand Down

0 comments on commit ba838da

Please sign in to comment.