Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[resolve #18] Add C++ allocator (partial) #28

Closed
wants to merge 3 commits into from

Conversation

William-Mou
Copy link
Contributor

@William-Mou William-Mou commented Apr 2, 2023

Story

This PR is open for issue #18, including the following features.

  • Add allocator implementation in rfaaslib.
  • Encapsulate the memory registration in rdmalib
    • provide generic enums for local/remote read/write ops + atomics.
  • Support in allocator registration
    • and deregistration of memory. (not test yet)
  • Add test demonstrating standard memory allocation.
  • Add test demonstrating allocation with std::vector and our custom allocator.

Achievements

  • Defines rdma_allocator.hpp, which provides the allocate and deallocate functions.
  • Use rfaas::RdmaAllocator<rdmalib::Buffer<char> > rdmaAllocator(executor); to instantiate the allocator object.
  • rdmaAllocator.allocate(size_t size, int access) intuitively allocates memory space for a buffer.

Test

  • By embedding std::cout in the allocator, you can test the program (eg: warm_benchmarker ) to run as expected.
warm_benchmarker --config benchmark.json --device-database client_devices.json --name empty --functions /home/mou/rFaaS/build-test/examples/libfunctions.so --executors-database executors_database.json -s 0xFFF

TODO

  • Complete the tasks not checked above

mou added 2 commits April 3, 2023 03:58
- An error occurred while linking the `RdmaAllocator` library to the `warm_benchmark` program.

```
FAILED: benchmarks/warm_benchmarker
: && /bin/clang++-15 -Wall -Wextra  -g -DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG  CMakeFiles/warm_benchmarker.dir/benchmarks/warm_benchmark.cpp.o CMakeFiles/warm_benchmarker.dir/benchmarks/warm_benchmark_opts.cpp.o -o benchmarks/warm_benchmarker  _deps/spdlog-build/libspdlogd.a  librfaaslib.a  libbenchmarks.a  librfaaslib.a  librdmalib.a  _deps/spdlog-build/libspdlogd.a  /usr/lib/x86_64-linux-gnu/librdmacm.so  /usr/lib/x86_64-linux-gnu/libibverbs.so  -ldl && :
/bin/ld: /bin/ld: DWARF error: invalid or unhandled FORM value: 0x23
CMakeFiles/warm_benchmarker.dir/benchmarks/warm_benchmark.cpp.o: in function `main':
warm_benchmark.cpp:(.text+0x493): undefined reference to `rfaas::RdmaAllocator<rdmalib::Buffer<char> >::allocate(unsigned long const&, int const&, unsigned long)'
/bin/ld: warm_benchmark.cpp:(.text+0x4e0): undefined reference to `rfaas::RdmaAllocator<rdmalib::Buffer<char> >::allocate(unsigned long const&, int const&, unsigned long)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
```

- Checking the argument and parameter types helped resolve the linking error.
- Inline functions are recommended to be merged into header files to allow for their optimization by the compiler.
- Compiled successfully without any errors.
- Add allocator implementation in rfaaslib.
- Encapsulate the memory registration in rdmalib
- Add test demonstrating standard memory allocation.
CMakeLists.txt Outdated
@@ -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 -std=c++17")
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use CXX_STANDARD instead.

#include <rfaas/executor.hpp>

namespace rfaas {
template<typename T>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the allocator should be of type T, and then always return rdmalib::Buffer object. If you look at the C++ allocator concept, then I think we should use A::pointer as rdmalib::Buffer.

if (size > std::size_t(-1) / sizeof(T))
throw std::bad_alloc();

auto buffer = new rdmalib::Buffer<char>(size, header);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need dynamic allocation for the buffer object itself :-) Once we properly define the pointer type.

… requirements example for the Allocator"](https://en.cppreference.com/w/cpp/named_req/Allocator).

Signed-off-by: mou <William-Mou>
@William-Mou
Copy link
Contributor Author

Hi @mcopik,
I have updated my code to have a structure similar to the documentation, which may help with communication 😊

@mcopik
Copy link
Contributor

mcopik commented Apr 3, 2023

@William-Mou Thanks! I will try to test this and merge in the coming days :)

@William-Mou
Copy link
Contributor Author

I proposed a better solution in #30, so #28 has been closed.

@William-Mou William-Mou reopened this Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants