Skip to content

Commit

Permalink
Merge PR #48 from tudasc/devel
Browse files Browse the repository at this point in the history
  • Loading branch information
ahueck authored Jan 4, 2021
2 parents aeb9ca5 + adf61dc commit 71d7993
Show file tree
Hide file tree
Showing 23 changed files with 657 additions and 125 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/basic-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ jobs:
- name: Build TypeART
run: |
cmake -B build -DTEST_CONFIG=ON -DENABLE_CODE_COVERAGE=ON -DLLVM_EXTERNAL_LIT=${EXTERNAL_LIT}
cmake -B build -DTEST_CONFIG=ON -DENABLE_CODE_COVERAGE=ON -DSOFTCOUNTERS=ON -DLLVM_EXTERNAL_LIT=${EXTERNAL_LIT}
cmake --build build --parallel
- name: Test TypeART with coverage (exludes lulesh)
- name: Test TypeART with coverage
run: |
cmake --build build --target lcov-clean
cmake --build build --target test -- ARGS=-VV
Expand All @@ -51,7 +51,7 @@ jobs:

- name: Build TypeART release
run: |
cmake -B build_lulesh -DCMAKE_BUILD_TYPE=Release -DMPI_INTERCEPT_LIB=ON -DSHOW_STATS=ON
cmake -B build_lulesh -DCMAKE_BUILD_TYPE=Release -DMPI_INTERCEPT_LIB=ON -DSHOW_STATS=ON -DSOFTCOUNTERS=ON
cmake --build build_lulesh --parallel
- name: Test TypeART release on lulesh
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ext-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
build-and-run-testbench:
runs-on: ubuntu-20.04
if: "!contains(github.event.head_commit.message, '[ci skip]') || !contains(github.event.head_commit.message, '[ci ext skip]')"
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[ci ext skip]')"
steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Build & install TypeART
run: |
cmake -B build -DCMAKE_BUILD_TYPE=Release -DMPI_INTERCEPT_LIB=ON -DSHOW_STATS=ON
cmake -B build -DCMAKE_BUILD_TYPE=Release -DMPI_INTERCEPT_LIB=ON -DSHOW_STATS=ON -DSOFTCOUNTERS=ON
cmake --build build --parallel --target install
echo "TYPEART_PATH=${GITHUB_WORKSPACE}/install/typeart" >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.14)

project(typeart
VERSION 1.5.0
VERSION 1.5
)

set(TYPEART_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
Expand Down
2 changes: 2 additions & 0 deletions cmake/ToolchainOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ option(SOFTCOUNTERS "Enable software tracking of #tracked addrs. / #distinct che
option(TEST_CONFIG "Set logging levels to appropriate levels for test runner to succeed" OFF)
option(ENABLE_CODE_COVERAGE "Enable code coverage statistics" OFF)
option(ENABLE_LLVM_CODE_COVERAGE "Enable llvm-cov code coverage statistics" OFF)
option(TEST_CONFIGURE_IDE "Add targets so the IDE (e.g., Clion) can interpret test files better" ON)
mark_as_advanced(TEST_CONFIGURE_IDE)

include(AddLLVM)
include(llvm-lit)
Expand Down
22 changes: 13 additions & 9 deletions lib/passes/instrumentation/TypeARTFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

#include "TypeARTFunctions.h"

#include "support/Logger.h"

#include "llvm/IR/Argument.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
Expand Down Expand Up @@ -49,13 +49,17 @@ llvm::Function* TAFunctionDeclarator::make_function(IFunc id, llvm::StringRef ba
// f->setLinkage(GlobalValue::ExternalWeakLinkage);
};
const auto do_make = [&](auto& name, auto f_type) {
auto fc = m.getOrInsertFunction(name, f_type);
#if LLVM_VERSION >= 10
auto f = dyn_cast<Function>(fc.getCallee());
#else
auto f = dyn_cast<Function>(fc);
#endif
setFunctionLinkageExternal(f);
const bool has_f = m.getFunction(name) != nullptr;
auto fc = m.getOrInsertFunction(name, f_type);

Function* f{nullptr};
if (has_f) {
LOG_WARNING("Function " << name << " is already declared in the module.")
f = dyn_cast<Function>(fc.getCallee()->stripPointerCasts());
} else {
f = dyn_cast<Function>(fc.getCallee());
setFunctionLinkageExternal(f);
}
addOptimizerAttributes(f);
return f;
};
Expand Down
114 changes: 114 additions & 0 deletions lib/runtime/AccessCountPrinter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//
// Created by ahueck on 30.12.20.
//

#ifndef TYPEART_ACCESSCOUNTPRINTER_H
#define TYPEART_ACCESSCOUNTPRINTER_H

#include "AccessCounter.h"
#include "support/Logger.h"
#include "support/Table.h"

#include <map>
#include <set>
#include <sstream>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>

namespace typeart::softcounter {
namespace memory {
struct MemOverhead {
static constexpr auto pointerMapSize = sizeof(RuntimeT::PointerMap); // Map overhead
static constexpr auto perNodeSizeMap =
sizeof(std::remove_pointer<std::map<MemAddr, PointerInfo>::iterator::_Link_type>::type) +
sizeof(RuntimeT::MapEntry); // not applicable to btree
static constexpr auto stackVectorSize = sizeof(RuntimeT::Stack); // Stack overhead
static constexpr auto perNodeSizeStack = sizeof(RuntimeT::StackEntry); // Stack allocs
double stack{0};
double map{0};
};
inline MemOverhead estimate(Counter stack_max, Counter heap_max, Counter global_max, const double scale = 1024.0) {
MemOverhead mem;
mem.stack = double(MemOverhead::stackVectorSize +
MemOverhead::perNodeSizeStack * std::max<size_t>(RuntimeT::StackReserve, stack_max)) /
scale;
mem.map =
double(MemOverhead::pointerMapSize + MemOverhead::perNodeSizeMap * (stack_max + heap_max + global_max)) / scale;
return mem;
}
} // namespace memory

template <typename Recorder>
void serialise(const Recorder& r, llvm::raw_ostream& buf) {
if constexpr (std::is_same_v<Recorder, NoneRecorder>) {
return;
} else {
const auto memory_use = memory::estimate(r.getMaxStackAllocs(), r.getMaxHeapAllocs(), r.getGlobalAllocs());

Table t("Alloc Stats from softcounters");
t.wrap_length = true;
t.put(Row::make("Total heap", r.getHeapAllocs(), r.getHeapArray()));
t.put(Row::make("Total stack", r.getStackAllocs(), r.getStackArray()));
t.put(Row::make("Total global", r.getGlobalAllocs(), r.getGlobalArray()));
t.put(Row::make("Max. Heap Allocs", r.getMaxHeapAllocs()));
t.put(Row::make("Max. Stack Allocs", r.getMaxStackAllocs()));
t.put(Row::make("Addresses checked", r.getAddrChecked()));
t.put(Row::make("Distinct Addresses checked", r.getSeen().size()));
t.put(Row::make("Addresses re-used", r.getAddrReuses()));
t.put(Row::make("Addresses missed", r.getAddrMissing()));
t.put(Row::make("Distinct Addresses missed", r.getMissing().size()));
t.put(Row::make("Total free heap", r.getHeapAllocsFree(), r.getHeapArrayFree()));
t.put(Row::make("Total free stack", r.getStackAllocsFree(), r.getStackArrayFree()));
t.put(Row::make("Null/Zero/NullZero Addr", r.getNullAlloc(), r.getZeroAlloc(), r.getNullAndZeroAlloc()));
t.put(Row::make("User-def. types", r.getNumUDefTypes()));
t.put(Row::make("Estimated memory use (KiB)", size_t(std::round(memory_use.map + memory_use.stack))));
t.put(Row::make("Bytes per node map/stack", memory::MemOverhead::perNodeSizeMap,
memory::MemOverhead::perNodeSizeStack));

t.print(buf);

std::set<int> type_id_set;
const auto fill_set = [&type_id_set](const auto& map) {
for (const auto& [key, val] : map) {
type_id_set.insert(key);
}
};
fill_set(r.getHeapAlloc());
fill_set(r.getGlobalAlloc());
fill_set(r.getStackAlloc());
fill_set(r.getHeapFree());
fill_set(r.getStackFree());

const auto count = [](const auto& map, auto id) {
auto it = map.find(id);
if (it != map.end()) {
return it->second;
}
return 0ll;
};

Table type_table("Allocation type detail (heap, stack, global)");
type_table.table_header = '#';
for (auto type_id : type_id_set) {
type_table.put(Row::make(std::to_string(type_id), count(r.getHeapAlloc(), type_id),
count(r.getStackAlloc(), type_id), count(r.getGlobalAlloc(), type_id),
typeart_get_type_name(type_id)));
}

type_table.print(buf);

Table type_table_free("Free allocation type detail (heap, stack)");
type_table_free.table_header = '#';
for (auto type_id : type_id_set) {
type_table_free.put(Row::make(std::to_string(type_id), count(r.getHeapFree(), type_id),
count(r.getStackFree(), type_id), typeart_get_type_name(type_id)));
}

type_table_free.print(buf);
}
}
} // namespace typeart::softcounter

#endif // TYPEART_ACCESSCOUNTPRINTER_H
Loading

0 comments on commit 71d7993

Please sign in to comment.