Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
08d0052
changes to enable better allocator support. this has been tested with…
kstppd Sep 6, 2024
22133a4
Merge branch 'master' of github.com:kstppd/hashinator into better_all…
kstppd Sep 6, 2024
6a5d4bc
use std allocator to demonstrate last commit's functionallity
kstppd Sep 6, 2024
ad05504
remove split host allocator since there is no need for it anymore
kstppd Sep 6, 2024
f2be8b3
fix hashinator ctpr
kstppd Sep 7, 2024
1ababbc
Add some more ctors for splitvectors and a host unit test with umpire
kstppd Sep 7, 2024
754aae0
more umpire tests
kstppd Sep 16, 2024
a53b4e9
update allocators in splittools
kstppd Sep 16, 2024
5b1e7e6
unit tests update
kstppd Sep 16, 2024
c2a0e96
Meson update to only build and test Umpire unit tests if Umpire is in…
kstppd Sep 28, 2024
3e09873
Implement some first changes at 38000ft
kstppd Oct 6, 2024
9cb9486
And update README
kstppd Oct 6, 2024
ff4d157
do not use offset of in non POD stuff
kstppd Dec 7, 2024
27789a6
Use optional to fix compiler warning us for no return in function
kstppd Dec 8, 2024
714d57d
Update README.md
kstppd Dec 8, 2024
12c58fa
Add memtest unit
kstppd Feb 9, 2025
8170005
Change splitvector's swap so that is it does not check for swapping w…
kstppd Feb 10, 2025
06e7013
finally an update
kstppd Apr 4, 2025
12f1a67
comment added
kstppd Apr 6, 2025
85a61a7
revert back to previous behavior for device buckets
kstppd Apr 6, 2025
3130b6b
some fixes and less restrictiv split vector contructors
kstppd Apr 8, 2025
60d65cc
some fixes and less restrictiv split vector contructors
kstppd Apr 8, 2025
3e69d91
fix
kstppd Apr 8, 2025
a2409ed
Revert "fix"
kstppd Apr 8, 2025
a108a65
tRevert "some fixes and less restrictiv split vector contructors"
kstppd Apr 8, 2025
aa9922b
Revert "some fixes and less restrictiv split vector contructors"
kstppd Apr 8, 2025
2361d04
fix
kstppd Apr 8, 2025
93653e9
relax is_trivial
kstppd Apr 8, 2025
2cdd964
Revert "Use optional to fix compiler warning us for no return in func…
kstppd Apr 12, 2025
b13a279
remove duplicate include
kstppd Apr 12, 2025
65d3dfa
comment update
kstppd Apr 12, 2025
1448978
Merge remote-tracking branch 'fmihpc/master' into better_allocator_su…
kstppd Apr 12, 2025
1a24b37
avoid a small git wreck
kstppd Apr 12, 2025
4290365
memcpy fix
kstppd Apr 12, 2025
fd4c004
use library in meson for umpire detection
kstppd Jun 6, 2025
c6d374c
update tests for Umpire compatibillity
kstppd Jun 10, 2025
6d63fcf
off with device buckets and the offset of thingy
kstppd Jun 11, 2025
60b87c6
test coarse mem
kstppd Jun 13, 2025
218dcc7
update bench script
kstppd Jun 13, 2025
b25c150
update bench script and allow coarse grain memory when running on AMD hw
kstppd Jun 13, 2025
a3d3d7f
Oops missing main type
kstppd Aug 14, 2025
dfd59c5
Oops missing main type
kstppd Aug 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,45 @@ int main()
hmap.insert(src.data(),src.size());
}
```
### Hashinator and SplitVector can also be used with external allocators

```c++
#include "splitvec.h"
//main.cu
using vector = split::SplitVector<int,std::allocator<int>>;


int main()
{
vector* vec = new vector{1,2,3,4,5};
vec->reserve(128);
std::cout<<vec[3]<<std::endl;
delete vec;
}
```

```c++
//main.cpp
#include "hashinator.h"

int main()
{

   Hashmap<uint32_t,uint32_t,std::allocator<uint32_t>> hmap;

   //Write
   for (uint32_t i=0 ; i<64; ++i){
      hmap[i]=rand()%10000;
   }

   //Read
   for (const auto& i:hmap){
      std::cout<<"["<<i.first<<" "<<i.second<<"] ";
   }
   std::cout<<std::endl;
}
```

`nvcc main.cu -std=c++17 --expt-relaxed-constexpr --expt-extended-lambda -gencode arch=compute_80,code=sm_80 -o example`

You can have a look in the Doxygen for a more feature-rich explanation of the methods and tools included!
Expand Down
1 change: 1 addition & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ inline bool isDeviceAccessible(void* ptr){
}
return true;
#endif
return false;
}

/**
Expand Down
186 changes: 125 additions & 61 deletions include/hashinator/hashinator.h

Large diffs are not rendered by default.

94 changes: 7 additions & 87 deletions include/splitvector/split_allocators.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,22 @@ class split_unified_allocator {
pointer address(reference x) const { return &x; }
const_pointer address(const_reference x) const { return &x; }

pointer allocate(size_type n, const void* /*hint*/ = 0) {
static pointer allocate(size_type n, const void* /*hint*/ = 0) {
T* ret;
assert(n && "allocate 0");
SPLIT_CHECK_ERR(split_gpuMallocManaged((void**)&ret, n * sizeof(value_type)));
if (ret == nullptr) {
throw std::bad_alloc();
}
#if defined(__HIP__) && !defined(AMD_COHERENCE_FINE)
int device;
SPLIT_CHECK_ERR(split_gpuGetDevice(&device));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

SPLIT_CHECK_ERR(split_gpuMemAdvise(ret, n * sizeof(value_type), hipMemAdviseSetCoarseGrain, device));
#endif
return ret;
}

static void* allocate_raw(size_type n, const void* /*hint*/ = 0) {
void* ret;
SPLIT_CHECK_ERR(split_gpuMallocManaged((void**)&ret, n));
if (ret == nullptr) {
throw std::bad_alloc();
}
return ret;
}

void deallocate(pointer p, size_type n) {
if (n != 0 && p != 0) {
SPLIT_CHECK_ERR(split_gpuFree(p));
}
}
static void deallocate(void* p, size_type n) {
static void deallocate(pointer p, size_type n) {
if (n != 0 && p != 0) {
SPLIT_CHECK_ERR(split_gpuFree(p));
}
Expand All @@ -127,76 +118,5 @@ class split_unified_allocator {

void destroy(pointer p) { p->~value_type(); }
};

#endif

/**
* @brief Custom allocator for host memory.
*
* This class provides an allocator for host memory, which can be accessed
* by the CPU. It allocates and deallocates memory using malloc and free functions,
* while also providing constructors and destructors for objects.
*
* @tparam T Type of the allocated objects.
*/
template <class T>
class split_host_allocator {
public:
typedef T value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef ptrdiff_t difference_type;
typedef size_t size_type;
template <class U>
struct rebind {
typedef split_host_allocator<U> other;
};

/**
* @brief Default constructor.
*/
split_host_allocator() throw() {}

/**
* @brief Copy constructor with different type.
*/
template <class U>
split_host_allocator(split_host_allocator<U> const&) throw() {}
pointer address(reference x) const { return &x; }
const_pointer address(const_reference x) const { return &x; }

pointer allocate(size_type n, const void* /*hint*/ = 0) {
pointer const ret = reinterpret_cast<pointer>(malloc(n * sizeof(value_type)));
if (ret == nullptr) {
throw std::bad_alloc();
}
return ret;
}

static void* allocate_raw(size_type n, const void* /*hint*/ = 0) {
void* ret = (void*)malloc(n);
if (ret == nullptr) {
throw std::bad_alloc();
}
return ret;
}

void deallocate(pointer p, size_type) { free(p); }

static void deallocate(void* p, size_type) { free(p); }

size_type max_size() const throw() {
size_type max = static_cast<size_type>(-1) / sizeof(value_type);
return (max > 0 ? max : 1);
}

template <typename U, typename... Args>
void construct(U* p, Args&&... args) {
::new (p) U(std::forward<Args>(args)...);
}

void destroy(pointer p) { p->~value_type(); }
};
} // namespace split
Loading