Skip to content

Commit 71d7993

Browse files
authored
Merge PR #48 from tudasc/devel
2 parents aeb9ca5 + adf61dc commit 71d7993

23 files changed

+657
-125
lines changed

.github/workflows/basic-ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ jobs:
3838
3939
- name: Build TypeART
4040
run: |
41-
cmake -B build -DTEST_CONFIG=ON -DENABLE_CODE_COVERAGE=ON -DLLVM_EXTERNAL_LIT=${EXTERNAL_LIT}
41+
cmake -B build -DTEST_CONFIG=ON -DENABLE_CODE_COVERAGE=ON -DSOFTCOUNTERS=ON -DLLVM_EXTERNAL_LIT=${EXTERNAL_LIT}
4242
cmake --build build --parallel
4343
44-
- name: Test TypeART with coverage (exludes lulesh)
44+
- name: Test TypeART with coverage
4545
run: |
4646
cmake --build build --target lcov-clean
4747
cmake --build build --target test -- ARGS=-VV
@@ -51,7 +51,7 @@ jobs:
5151

5252
- name: Build TypeART release
5353
run: |
54-
cmake -B build_lulesh -DCMAKE_BUILD_TYPE=Release -DMPI_INTERCEPT_LIB=ON -DSHOW_STATS=ON
54+
cmake -B build_lulesh -DCMAKE_BUILD_TYPE=Release -DMPI_INTERCEPT_LIB=ON -DSHOW_STATS=ON -DSOFTCOUNTERS=ON
5555
cmake --build build_lulesh --parallel
5656
5757
- name: Test TypeART release on lulesh

.github/workflows/ext-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
jobs:
99
build-and-run-testbench:
1010
runs-on: ubuntu-20.04
11-
if: "!contains(github.event.head_commit.message, '[ci skip]') || !contains(github.event.head_commit.message, '[ci ext skip]')"
11+
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[ci ext skip]')"
1212
steps:
1313
- uses: actions/checkout@v2
1414

@@ -49,7 +49,7 @@ jobs:
4949
5050
- name: Build & install TypeART
5151
run: |
52-
cmake -B build -DCMAKE_BUILD_TYPE=Release -DMPI_INTERCEPT_LIB=ON -DSHOW_STATS=ON
52+
cmake -B build -DCMAKE_BUILD_TYPE=Release -DMPI_INTERCEPT_LIB=ON -DSHOW_STATS=ON -DSOFTCOUNTERS=ON
5353
cmake --build build --parallel --target install
5454
echo "TYPEART_PATH=${GITHUB_WORKSPACE}/install/typeart" >> $GITHUB_ENV
5555

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.14)
22

33
project(typeart
4-
VERSION 1.5.0
4+
VERSION 1.5
55
)
66

77
set(TYPEART_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

cmake/ToolchainOptions.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ option(SOFTCOUNTERS "Enable software tracking of #tracked addrs. / #distinct che
1212
option(TEST_CONFIG "Set logging levels to appropriate levels for test runner to succeed" OFF)
1313
option(ENABLE_CODE_COVERAGE "Enable code coverage statistics" OFF)
1414
option(ENABLE_LLVM_CODE_COVERAGE "Enable llvm-cov code coverage statistics" OFF)
15+
option(TEST_CONFIGURE_IDE "Add targets so the IDE (e.g., Clion) can interpret test files better" ON)
16+
mark_as_advanced(TEST_CONFIGURE_IDE)
1517

1618
include(AddLLVM)
1719
include(llvm-lit)

lib/passes/instrumentation/TypeARTFunctions.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
#include "TypeARTFunctions.h"
66

7+
#include "support/Logger.h"
8+
79
#include "llvm/IR/Argument.h"
8-
#include "llvm/IR/CFG.h"
910
#include "llvm/IR/Function.h"
1011
#include "llvm/IR/GlobalValue.h"
11-
#include "llvm/IR/IRBuilder.h"
1212
#include "llvm/IR/LLVMContext.h"
1313
#include "llvm/IR/Module.h"
1414
#include "llvm/IR/Type.h"
@@ -49,13 +49,17 @@ llvm::Function* TAFunctionDeclarator::make_function(IFunc id, llvm::StringRef ba
4949
// f->setLinkage(GlobalValue::ExternalWeakLinkage);
5050
};
5151
const auto do_make = [&](auto& name, auto f_type) {
52-
auto fc = m.getOrInsertFunction(name, f_type);
53-
#if LLVM_VERSION >= 10
54-
auto f = dyn_cast<Function>(fc.getCallee());
55-
#else
56-
auto f = dyn_cast<Function>(fc);
57-
#endif
58-
setFunctionLinkageExternal(f);
52+
const bool has_f = m.getFunction(name) != nullptr;
53+
auto fc = m.getOrInsertFunction(name, f_type);
54+
55+
Function* f{nullptr};
56+
if (has_f) {
57+
LOG_WARNING("Function " << name << " is already declared in the module.")
58+
f = dyn_cast<Function>(fc.getCallee()->stripPointerCasts());
59+
} else {
60+
f = dyn_cast<Function>(fc.getCallee());
61+
setFunctionLinkageExternal(f);
62+
}
5963
addOptimizerAttributes(f);
6064
return f;
6165
};

lib/runtime/AccessCountPrinter.h

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
//
2+
// Created by ahueck on 30.12.20.
3+
//
4+
5+
#ifndef TYPEART_ACCESSCOUNTPRINTER_H
6+
#define TYPEART_ACCESSCOUNTPRINTER_H
7+
8+
#include "AccessCounter.h"
9+
#include "support/Logger.h"
10+
#include "support/Table.h"
11+
12+
#include <map>
13+
#include <set>
14+
#include <sstream>
15+
#include <string>
16+
#include <string_view>
17+
#include <unordered_map>
18+
#include <unordered_set>
19+
20+
namespace typeart::softcounter {
21+
namespace memory {
22+
struct MemOverhead {
23+
static constexpr auto pointerMapSize = sizeof(RuntimeT::PointerMap); // Map overhead
24+
static constexpr auto perNodeSizeMap =
25+
sizeof(std::remove_pointer<std::map<MemAddr, PointerInfo>::iterator::_Link_type>::type) +
26+
sizeof(RuntimeT::MapEntry); // not applicable to btree
27+
static constexpr auto stackVectorSize = sizeof(RuntimeT::Stack); // Stack overhead
28+
static constexpr auto perNodeSizeStack = sizeof(RuntimeT::StackEntry); // Stack allocs
29+
double stack{0};
30+
double map{0};
31+
};
32+
inline MemOverhead estimate(Counter stack_max, Counter heap_max, Counter global_max, const double scale = 1024.0) {
33+
MemOverhead mem;
34+
mem.stack = double(MemOverhead::stackVectorSize +
35+
MemOverhead::perNodeSizeStack * std::max<size_t>(RuntimeT::StackReserve, stack_max)) /
36+
scale;
37+
mem.map =
38+
double(MemOverhead::pointerMapSize + MemOverhead::perNodeSizeMap * (stack_max + heap_max + global_max)) / scale;
39+
return mem;
40+
}
41+
} // namespace memory
42+
43+
template <typename Recorder>
44+
void serialise(const Recorder& r, llvm::raw_ostream& buf) {
45+
if constexpr (std::is_same_v<Recorder, NoneRecorder>) {
46+
return;
47+
} else {
48+
const auto memory_use = memory::estimate(r.getMaxStackAllocs(), r.getMaxHeapAllocs(), r.getGlobalAllocs());
49+
50+
Table t("Alloc Stats from softcounters");
51+
t.wrap_length = true;
52+
t.put(Row::make("Total heap", r.getHeapAllocs(), r.getHeapArray()));
53+
t.put(Row::make("Total stack", r.getStackAllocs(), r.getStackArray()));
54+
t.put(Row::make("Total global", r.getGlobalAllocs(), r.getGlobalArray()));
55+
t.put(Row::make("Max. Heap Allocs", r.getMaxHeapAllocs()));
56+
t.put(Row::make("Max. Stack Allocs", r.getMaxStackAllocs()));
57+
t.put(Row::make("Addresses checked", r.getAddrChecked()));
58+
t.put(Row::make("Distinct Addresses checked", r.getSeen().size()));
59+
t.put(Row::make("Addresses re-used", r.getAddrReuses()));
60+
t.put(Row::make("Addresses missed", r.getAddrMissing()));
61+
t.put(Row::make("Distinct Addresses missed", r.getMissing().size()));
62+
t.put(Row::make("Total free heap", r.getHeapAllocsFree(), r.getHeapArrayFree()));
63+
t.put(Row::make("Total free stack", r.getStackAllocsFree(), r.getStackArrayFree()));
64+
t.put(Row::make("Null/Zero/NullZero Addr", r.getNullAlloc(), r.getZeroAlloc(), r.getNullAndZeroAlloc()));
65+
t.put(Row::make("User-def. types", r.getNumUDefTypes()));
66+
t.put(Row::make("Estimated memory use (KiB)", size_t(std::round(memory_use.map + memory_use.stack))));
67+
t.put(Row::make("Bytes per node map/stack", memory::MemOverhead::perNodeSizeMap,
68+
memory::MemOverhead::perNodeSizeStack));
69+
70+
t.print(buf);
71+
72+
std::set<int> type_id_set;
73+
const auto fill_set = [&type_id_set](const auto& map) {
74+
for (const auto& [key, val] : map) {
75+
type_id_set.insert(key);
76+
}
77+
};
78+
fill_set(r.getHeapAlloc());
79+
fill_set(r.getGlobalAlloc());
80+
fill_set(r.getStackAlloc());
81+
fill_set(r.getHeapFree());
82+
fill_set(r.getStackFree());
83+
84+
const auto count = [](const auto& map, auto id) {
85+
auto it = map.find(id);
86+
if (it != map.end()) {
87+
return it->second;
88+
}
89+
return 0ll;
90+
};
91+
92+
Table type_table("Allocation type detail (heap, stack, global)");
93+
type_table.table_header = '#';
94+
for (auto type_id : type_id_set) {
95+
type_table.put(Row::make(std::to_string(type_id), count(r.getHeapAlloc(), type_id),
96+
count(r.getStackAlloc(), type_id), count(r.getGlobalAlloc(), type_id),
97+
typeart_get_type_name(type_id)));
98+
}
99+
100+
type_table.print(buf);
101+
102+
Table type_table_free("Free allocation type detail (heap, stack)");
103+
type_table_free.table_header = '#';
104+
for (auto type_id : type_id_set) {
105+
type_table_free.put(Row::make(std::to_string(type_id), count(r.getHeapFree(), type_id),
106+
count(r.getStackFree(), type_id), typeart_get_type_name(type_id)));
107+
}
108+
109+
type_table_free.print(buf);
110+
}
111+
}
112+
} // namespace typeart::softcounter
113+
114+
#endif // TYPEART_ACCESSCOUNTPRINTER_H

0 commit comments

Comments
 (0)