Skip to content

Commit

Permalink
Added C++ allocator to manage rdmalib::Buffer
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
mou authored and mou committed Apr 2, 2023
1 parent aa2f46b commit 662d933
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

###
# Mandatory: devices configuration file.
Expand Down Expand Up @@ -127,6 +127,7 @@ target_link_libraries(rdmalib PRIVATE cereal)
# client library
###
file(GLOB rdmalib_files "rfaas/lib/*.cpp")
message(STATUS "rdmalib_files ${rdmalib_files}")
add_library(rfaaslib STATIC ${rdmalib_files})
add_dependencies(rfaaslib spdlog)
add_dependencies(rfaaslib cereal)
Expand Down
27 changes: 18 additions & 9 deletions benchmarks/warm_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <rfaas/executor.hpp>
#include <rfaas/resources.hpp>
#include <rfaas/rdma_allocator.hpp>

#include "warm_benchmark.hpp"
#include "settings.hpp"
Expand Down Expand Up @@ -68,27 +69,35 @@ int main(int argc, char ** argv)
}

// FIXME: move me to a memory allocator
rdmalib::Buffer<char> 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);
memset(in.data(), 0, opts.input_size);
for(int i = 0; i < opts.input_size; ++i) {
((char*)in.data())[i] = 1;

rfaas::RdmaAllocator<rdmalib::Buffer<char> > rdmaAllocator(executor);
auto in = rdmaAllocator.allocate(opts.input_size, IBV_ACCESS_LOCAL_WRITE,
rdmalib::functions::Submission::DATA_HEADER_SIZE);
auto out = rdmaAllocator.allocate(opts.input_size, IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE);
// rdmalib::Buffer<char> 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);

// 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.
memset(in->data(), 0, opts.input_size);
for (int i = 0; i < opts.input_size; ++i) {
((char *) in->data())[i] = 1;
}

rdmalib::Benchmarker<1> benchmarker{settings.benchmark.repetitions};
spdlog::info("Warmups begin");
for(int i = 0; i < settings.benchmark.warmup_repetitions; ++i) {
SPDLOG_DEBUG("Submit warm {}", i);
executor.execute(opts.fname, in, out);
executor.execute(opts.fname, *in, *out);
}
spdlog::info("Warmups completed");

// Start actual measurements
for(int i = 0; i < settings.benchmark.repetitions;) {
benchmarker.start();
SPDLOG_DEBUG("Submit execution {}", i);
auto ret = executor.execute(opts.fname, in, out);
auto ret = executor.execute(opts.fname, *in, *out);
if(std::get<0>(ret)) {
SPDLOG_DEBUG("Finished execution {} out of {}", i, settings.benchmark.repetitions);
benchmarker.end(0);
Expand All @@ -108,7 +117,7 @@ int main(int argc, char ** argv)

printf("Data: ");
for(int i = 0; i < std::min(100, opts.input_size); ++i)
printf("%d ", ((char*)out.data())[i]);
printf("%d ", ((char*)out->data())[i]);
printf("\n");

return 0;
Expand Down
27 changes: 27 additions & 0 deletions rfaas/include/rfaas/rdma_allocator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Created by mou on 4/2/23.
//

#ifndef __RFAAS_RDMA_ALLOCATOR_HPP__
#define __RFAAS_RDMA_ALLOCATOR_HPP__

#include <cstddef>
#include <rdmalib/buffer.hpp>
#include <rfaas/executor.hpp>

namespace rfaas {
template<typename T>
class RdmaAllocator {
private:
const executor &_executor;

public:
inline explicit RdmaAllocator(const executor &executor) noexcept: _executor(executor) {}

inline T *allocate(const std::size_t &, const int &, int = 0);

inline void deallocate(T *p, std::size_t n) noexcept;
};
}

#endif //__RFAAS_RDMA_ALLOCATOR_HPP__
25 changes: 25 additions & 0 deletions rfaas/lib/rdma_allocator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Created by mou on 4/2/23.
//
#include <memory>

#include <rfaas/rdma_allocator.hpp>

namespace rfaas {

template<typename T>
inline T *RdmaAllocator<T>::allocate(const std::size_t &size, const int &access, int header) {
if (size > std::size_t(-1) / sizeof(T))
throw std::bad_alloc();

rdmalib::Buffer<char> buffer(size, header);
buffer.register_memory(_executor._state.pd(), access);

return buffer;
}

template<typename T>
inline void RdmaAllocator<T>::deallocate(T *p, std::size_t n) noexcept {
operator delete(p);
}
}

0 comments on commit 662d933

Please sign in to comment.