Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
Add C++ unordered_map test on DPU
Browse files Browse the repository at this point in the history
  • Loading branch information
qizzz committed Oct 2, 2023
1 parent 8ed16f3 commit 0230e5b
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 12 deletions.
1 change: 1 addition & 0 deletions DPDPU/Benchmarks/Micro/UnorderedMap/BuildDebug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rm -r build; meson setup build -Dbuildtype=debug; ninja -C build
1 change: 1 addition & 0 deletions DPDPU/Benchmarks/Micro/UnorderedMap/BuildRelease.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rm -r build; meson setup build -Dbuildtype=release; ninja -C build
1 change: 1 addition & 0 deletions DPDPU/Benchmarks/Micro/UnorderedMap/Run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./build/CacheTableBenchmark
64 changes: 64 additions & 0 deletions DPDPU/Benchmarks/Micro/UnorderedMap/Source/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <stdlib.h>
#include <stdio.h>
#include <unordered_map>

#include "CacheTable.h"
#include "ProfilerCC.h"

using std::unordered_map;

int main() {
const size_t totalItems = 20000000;

fprintf(stdout, "Allocating test items...\n");
CacheItemT* items = (CacheItemT*)malloc(totalItems * sizeof(CacheItemT));
if (!items) {
fprintf(stderr, "Failed to allocate items\n");
}

for (size_t i = 0; i != totalItems; i++) {
items[i].Key = i;
items[i].Version = 42;
items[i].FileId = 0;
items[i].Offset = i;
items[i].Size = 1;
}

fprintf(stdout, "Init the map...\n");
unordered_map<KeyT, CacheItemT> table;
table.reserve(CACHE_TABLE_CAPACITY);

fprintf(stdout, "Adding to the map...\n");
size_t itemCount = 0;
Profiler profiler(totalItems);

profiler.Start();
for (size_t i = 0; i != totalItems; i++) {
table[items[i].Key] = items[i];
itemCount++;
}
profiler.Stop();

fprintf(stdout, "%ld / %ld items added to the cache table\n", itemCount, totalItems);
profiler.Report();

fprintf(stdout, "Looking up from the cache table...\n");
itemCount = 0;
CacheItemT* itemQueried;
profiler.Start();
while (itemCount != totalItems) {
itemQueried = &table.find(items[itemCount].Key)->second;
if (itemQueried->Offset != items[itemCount].Offset) {
fprintf(stderr, "Incorrect result\n");
}
itemCount++;
}
profiler.Stop();

fprintf(stdout, "%ld items looked up\n", itemCount);
profiler.Report();

free(items);

return 0;
}
58 changes: 58 additions & 0 deletions DPDPU/Benchmarks/Micro/UnorderedMap/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
project('DDSFileBackEnd', 'C', 'CPP',
version: '0.1',
license: 'Proprietary',
default_options: ['buildtype=release'],
meson_version: '>= 0.61.2'
)

languages = ['c', 'cpp']

install_apps = false

base_cpp_args = [
'-std=c++11',
]

base_c_args = [
'-flax-vector-conversions',
]

# Resolve irrelevant compiler warnings
add_project_arguments('-Wno-format-zero-length', language: languages)
add_project_arguments('-Wno-address-of-packed-member', language: languages)
add_project_arguments('-Wno-deprecated-declarations', language: languages)

base_app_dependencies = []
base_app_dependencies += dependency('threads')

base_app_inc_dirs = [
include_directories('../../../Common/Include/'),
include_directories('../../../Common/Include/DPU/'),
]

app_link_args = []
app_link_args += ['-libverbs']
app_link_args += ['-lrdmacm']

APP_NAME = 'CacheTableBenchmark'

app_dependencies = base_app_dependencies
app_inc_dirs = base_app_inc_dirs
app_srcs = []

src = 'Source/'

app_srcs += [
src + 'Main.cpp',
'../../../Common/Source/DPU/ProfilerCC.cpp',
]

executable(APP_NAME,
app_srcs,
c_args : base_c_args,
cpp_args : base_cpp_args,
dependencies : [app_dependencies],
include_directories : app_inc_dirs,
link_args : app_link_args,
install: install_apps
)
16 changes: 8 additions & 8 deletions DPDPU/Common/Include/DDSTypes.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#pragma once

#ifdef __GNUC__
#include <stdatomic.h>
#elif defined (_MSC_VER)
#if defined (_MSC_VER) || defined (__cplusplus)
#include <atomic>
#else
#include <stdatomic.h>
#endif
#include <stdint.h>
#include <time.h>

#include "Protocol.h"

#if defined (_MSC_VER)
#if defined (_MSC_VER) || defined (__cplusplus)
template <class C>
using Atomic=std::atomic<C>;
#endif
Expand Down Expand Up @@ -58,10 +58,10 @@ typedef struct FileProperties {
time_t LastWriteTime;
FileSizeT FileSize;
FileAccessT Access;
#ifdef __GNUC__
_Atomic PositionInFileT Position;
#elif defined (_MSC_VER)
#if defined (_MSC_VER) || defined (__cplusplus)
Atomic<PositionInFileT> Position;
#else
_Atomic PositionInFileT Position;
#endif
FileShareModeT ShareMode;
char FileName[DDS_MAX_FILE_PATH];
Expand Down Expand Up @@ -102,4 +102,4 @@ AssertStaticDDSTypes((1 << sizeof(RequestIdT) * 8) - 1 == DDS_REQUEST_INVALID, 2
#pragma GCC diagnostic pop
#else
#pragma warning(pop)
#endif
#endif
2 changes: 1 addition & 1 deletion DPDPU/Common/Include/DPU/Profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ void InitProfiler(struct Profiler* Prof, size_t Ops);
void StartProfiler(struct Profiler* Prof);
void StopProfiler(struct Profiler* Prof);
double GetProfilerEllapsed(struct Profiler* Prof);
void ReportProfiler(struct Profiler* Prof);
void ReportProfiler(struct Profiler* Prof);
28 changes: 28 additions & 0 deletions DPDPU/Common/Include/DPU/ProfilerCC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <ctime>
#include <chrono>

using std::chrono::steady_clock;
using std::chrono::duration_cast;
using std::chrono::microseconds;

/**
* A profiler that counts elapsed time and computes opertions/s.
*
*/
class Profiler {
public:
Profiler(size_t _operations);
void Start();
void Stop();
double Ellapsed();
void Report();
void ReportLatency();
void ReportThroughput();

private:
steady_clock::time_point m_start_time;
steady_clock::time_point m_end_time;
size_t m_operations;
};
4 changes: 2 additions & 2 deletions DPDPU/Common/Include/Host/Profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using std::chrono::duration_cast;
using std::chrono::microseconds;

/**
* A profiler that counts elapsed time and comoputes opertions/s.
* A profiler that counts elapsed time and computes opertions/s.
*
*/
class Profiler {
Expand All @@ -25,4 +25,4 @@ class Profiler {
steady_clock::time_point m_start_time;
steady_clock::time_point m_end_time;
size_t m_operations;
};
};
42 changes: 42 additions & 0 deletions DPDPU/Common/Source/DPU/ProfilerCC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <iostream>

#include "ProfilerCC.h"

using std::cout;
using std::endl;

Profiler::Profiler(size_t _operations) {
m_operations = _operations;
}

void Profiler::Start() {
m_start_time = steady_clock::now();
}

void Profiler::Stop() {
m_end_time = steady_clock::now();
}

double Profiler::Ellapsed() {
auto dur = duration_cast<microseconds>(m_end_time - m_start_time);
return (double)dur.count();
}

void Profiler::Report() {
auto dur = duration_cast<microseconds>(m_end_time - m_start_time);
cout << "Porfiler:" << endl;
cout << "-- latency: " << dur.count() / 1000000.0 << " seconds" << endl;
cout << "-- throughput: " << m_operations * 1.0 / dur.count() << " million op/s" << endl;
}

void Profiler::ReportLatency() {
auto dur = duration_cast<microseconds>(m_end_time - m_start_time);
cout << "Porfiler:" << endl;
cout << "-- latency: " << dur.count() / 1000000.0 << " seconds" << endl;
}

void Profiler::ReportThroughput() {
auto dur = duration_cast<microseconds>(m_end_time - m_start_time);
cout << "Porfiler:" << endl;
cout << "-- throughput: " << m_operations * 1.0 / dur.count() << " million op/s" << endl;
}
2 changes: 1 addition & 1 deletion DPDPU/Common/Source/Host/Profiler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <iostream>

#include "profiler.h"
#include "Profiler.h"

using std::cout;
using std::endl;
Expand Down

0 comments on commit 0230e5b

Please sign in to comment.