diff --git a/CMakeLists.txt b/CMakeLists.txt index a312719..46901a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED TRUE) string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -g -DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG ") string(APPEND CMAKE_CXX_FLAGS_DEBUG " -DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG ") -string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra") +string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra ") ### # Mandatory: devices configuration file. diff --git a/benchmarks/warm_benchmark.cpp b/benchmarks/warm_benchmark.cpp index b323a18..d7a4a94 100644 --- a/benchmarks/warm_benchmark.cpp +++ b/benchmarks/warm_benchmark.cpp @@ -70,17 +70,25 @@ int main(int argc, char ** argv) // FIXME: move me to a memory allocator - rfaas::RdmaAllocator > rdmaAllocator(executor); - rdmalib::Buffer* in = rdmaAllocator.allocate(opts.input_size); - rdmaAllocator.construct(in, IBV_ACCESS_LOCAL_WRITE); - rdmalib::Buffer* out = rdmaAllocator.allocate(opts.input_size); - rdmaAllocator.construct(out, IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE); + // Sample: test demonstrating standard memory allocation. // rdmalib::Buffer in(opts.input_size, rdmalib::functions::Submission::DATA_HEADER_SIZE), out(opts.input_size); // in.register_memory(executor._state.pd(), IBV_ACCESS_LOCAL_WRITE); // out.register_memory(executor._state.pd(), IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE); -// const rfaas::RdmaAllocator > &rdmaAllocator1 = rdmaAllocator; - std::vector, rfaas::RdmaAllocator>> v(8, rdmaAllocator); + // Sample: test demonstrating allocation with our custom allocator. + rfaas::RdmaInfo info_in(executor,IBV_ACCESS_LOCAL_WRITE,rdmalib::functions::Submission::DATA_HEADER_SIZE); + rfaas::RdmaAllocator> allocator_in{info_in}; + rdmalib::Buffer* in = allocator_in.allocate(opts.input_size); + + rfaas::RdmaInfo info_out(executor,(IBV_ACCESS_LOCAL_WRITE| IBV_ACCESS_REMOTE_WRITE)); + rfaas::RdmaAllocator> allocator_out{info_out}; + rdmalib::Buffer* out = allocator_out.allocate(opts.input_size); + + // Sample: test demonstrating allocation with std::vector. + // rfaas::RdmaInfo info_v(executor,(IBV_ACCESS_LOCAL_WRITE| IBV_ACCESS_REMOTE_WRITE)); + // rfaas::RdmaAllocator> allocator_v{info_v}; + // std::vector, rfaas::RdmaAllocator>> v(allocator_v); + // TODO: Since the for loop writes a value of 1 to each byte of the in buffer, // it overwrites all bytes previously set to 0 by the memset() function. diff --git a/rfaas/include/rfaas/rdma_allocator.hpp b/rfaas/include/rfaas/rdma_allocator.hpp index 78f8032..1691b03 100644 --- a/rfaas/include/rfaas/rdma_allocator.hpp +++ b/rfaas/include/rfaas/rdma_allocator.hpp @@ -11,12 +11,24 @@ #include namespace rfaas { + + struct RdmaInfo { + + public: + RdmaInfo(executor& executor, const int access, const int header_size=0) + : executor(executor), access(access), header_size(header_size) {} + const executor& executor; + const int access; + const int header_size = 0; + }; + template class RdmaAllocator { + public: typedef T value_type; - inline explicit RdmaAllocator(const executor &executor) noexcept: _executor(executor) {} + inline explicit RdmaAllocator(RdmaInfo& info) noexcept: _info(info) {} template constexpr RdmaAllocator(const RdmaAllocator &) noexcept {} @@ -26,36 +38,21 @@ namespace rfaas { throw std::bad_array_new_length(); // Maybe we could directly call the memset function here - mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); - if (auto buffer = static_cast(std::malloc(size * sizeof(T)))){ + if (auto buffer = new rdmalib::Buffer(size, _info.header_size)) { report(buffer, size); + buffer->register_memory(_info.executor._state.pd(), _info.access); return buffer; } throw std::bad_alloc(); } - template - void construct (U* p, arg1 access) - { - std::cout << "constructor" << std::endl; - p->register_memory(_executor._state.pd(), access); - } - - template - void construct (U* p, arg1 access, arg2 head) - { - std::cout << "constructor" << std::endl; - p->register_memory(_executor._state.pd(), access, head); - } -// [[nodiscard]] inline T *construct(const std::size_t &size, const int &access, int header = 0) { - inline void deallocate(T *p, std::size_t size) noexcept { report(p, size, 0); - std::free(p); + p->~T(); } private: - const executor &_executor; + const RdmaInfo &_info; void report(T *p, std::size_t n, bool alloc = true) const { std::cout << (alloc ? "Alloc: " : "Dealloc: ") << sizeof(T) * n