-
Notifications
You must be signed in to change notification settings - Fork 4
Closed
Description
I want to rethink the way that allocators work for both GPU and CPU workloads. Singletons kind of suck on GPU. I want to make hshm completely header-only.
New Design:
- We will always pass in the allocator used by the data structure.
- We will not use singletons anymore. Containers will always be passed the allocator.
Do we want a single allocator with a memory context, or the ability to slice allocators into little pieces? Or both? Really all the mem context does say the thread we are on. Without MemContext, we would not know the thread we are on. So it should stay.
vector.h
namespace hshm::ipc {
template<typename T>
struct vector : public ShmContainer {
hshm::TypedPtr<T> data_;
void emplace_back(Allocator &ctx_alloc, Args&& ...args) {
if (IS_SHM_DATA_STRUCT(T)) {
T *local = alloc->Convert(data_);
new (&data_[hdr_->off_ + 1]) (ctx_alloc, std::forward<Args>(args)...)
}
}
};
}hipc::Backend backend;
backend.shm_init(backend_id, "shm_key");
hipc::ThreadLocalAllocator alloc;
alloc.shm_init(backend, alloc_id, 1024, sizeof(CustomHeader));
hipc::CtxAllocator<ThreadLocalAllocator> ctx_alloc(HSHM_MCTX, alloc);
FullPtr<hipc::vector<int>> x = ctx_alloc.New<hipc::vector<int>>(ctx_alloc, 1024);
ctx_alloc->GetHeader<Header>()->x = x.ptr_;hipc::Backend backend;
backend.shm_attach("shm_key");
hipc::ThreadLocalAllocator alloc;
alloc.shm_attach(backend);
hipc::CtxAllocator<ThreadLocalAllocator> ctx_alloc(HSHM_MCTX, alloc);
Header *hdr = ctx_alloc->GetHeader<Header>();
FullPtr<hipc::vector<int>> x(ctx_alloc, hdr->x);
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels