Skip to content

Commit

Permalink
Lossy metadata calculation: loop iteration threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrothenberger committed Jul 9, 2024
1 parent 9233e70 commit 99fe805
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 62 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ jobs:
cmake \
-DCMAKE_BUILD_TYPE=Debug \
-DDP_CALLTREE_PROFILING=1 \
-DDP_CALLTREE_PROFILING_METADATA_CUTOFF=0 \
..
make -j3
Expand Down
49 changes: 49 additions & 0 deletions discopop_library/DependencyMetadata/compare_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
#
# Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
#
# This software may be modified and distributed under the terms of
# the 3-Clause BSD License. See the LICENSE file in the package base
# directory for details.

from typing import Set


def main():
gold_result_path = "/home/lukas/dependency_metadata.txt"
gold_standard: Set[str] = set()

with open(gold_result_path, "r") as f:
for line in f.readlines():
line = line.replace("\n", "")
if line.startswith("#"):
continue
gold_standard.add(line)

tested_result_path = "/home/lukas/git/Benchmarks/miniFE/dp/src/.discopop/profiler/dependency_metadata.txt"
test_results: Set[str] = set()

with open(tested_result_path, "r") as f:
for line in f.readlines():
line = line.replace("\n", "")
if line.startswith("#"):
continue
test_results.add(line)

print("Total gold standard: ", len(gold_standard))
print("Total test results: ", len(test_results))
# identify number of matching results
matching = gold_standard.intersection(test_results)
print("Matching: ", len(matching))

# identify number of missed results
missed = gold_standard.difference(test_results)
print("Missed: ", len(missed))

# identify number of additional results
additional = test_results.difference(gold_standard)
print("Additional: ", len(additional))


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions docs/setup/discopop.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ where `<CMAKE_FLAGS>` can consist of any combination of the following flags and
- `-DDP_NUM_WORKERS=<int>` &ndash; Specify the number of worker threads available for the dependency analysis during profiling. Default: `3` worker threads. `0` can be used to disable the creation of additional threads for the analysis.
- `-DDP_HYBRID_PROFILING=[0|1]` &ndash; Enbale hybrid profiling. Default: `1`.
- `-DDP_CALLTREE_PROFILING=[0|1]` &ndash; Enable creation of a call tree during profiling to create extended dependency metadata for improved result quality. Negatively impacts profiling performance.
- `-DDP_CALLTREE_PROFILING_METADATA_CUTOFF=<int>` &ndash; Set a cutoff amount of vitis per basic block for dependency metadata calculation. Set `0` to disable cutoff. Default: `50000`.
- `-DDP_MEMORY_REGION_DEALIASING=[0|1]`: Enable or disable the generation of dependency de-aliasing information. Reduces potential false positive parallelization suggestions, but increases the profiling overhead.


Expand Down
7 changes: 7 additions & 0 deletions rtlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ if(DEFINED DP_CALLTREE_PROFILING)
endif()
endif()

if(DEFINED DP_CALLTREE_PROFILING_METADATA_CUTOFF)
target_compile_definitions(DiscoPoP_RT PUBLIC DP_CALLTREE_PROFILING_METADATA_CUTOFF=${DP_CALLTREE_PROFILING_METADATA_CUTOFF})
message(STATUS "WARNING: DiscoPoP configuration: DP_CALLTREE_PROFILING_METADATA_CUTOFF enabled. Incomplete dependency metadata possible.")
else()
target_compile_definitions(DiscoPoP_RT PUBLIC DP_CALLTREE_PROFILING_METADATA_CUTOFF=50)
message(STATUS "WARNING: DiscoPoP configuration: DP_CALLTREE_PROFILING_METADATA_CUTOFF set to default value: 50.")
endif()

if(DEFINED DP_MEMORY_REGION_DEALIASING)
if(NOT ${DP_MEMORY_REGION_DEALIASING} EQUAL 0)
Expand Down
1 change: 1 addition & 0 deletions rtlib/injected_functions/dp_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void __dp_read(LID lid, ADDR addr, const char *var) {
current.addr = addr;
#if DP_CALLTREE_PROFILING
current.call_tree_node_ptr = call_tree->get_current_node_ptr();
current.calculate_dependency_metadata = loop_manager->enable_calculate_dependency_metadata();
#endif

#if defined DP_NUM_WORKERS && DP_NUM_WORKERS == 0
Expand Down
1 change: 1 addition & 0 deletions rtlib/injected_functions/dp_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void __dp_write(LID lid, ADDR addr, const char *var) {

#if DP_CALLTREE_PROFILING
current.call_tree_node_ptr = call_tree->get_current_node_ptr();
current.calculate_dependency_metadata = loop_manager->enable_calculate_dependency_metadata();
#endif

#if defined DP_NUM_WORKERS && DP_NUM_WORKERS == 0
Expand Down
24 changes: 24 additions & 0 deletions rtlib/loop/LoopManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,20 @@ class LoopManager {
}

void create_new_loop(const std::int32_t function_level, const std::int32_t loop_id, const LID begin_line) {
#if DP_CALLTREE_PROFILING
// check if dependency metadata calculation should be disabled due to inheritance
bool inherited_dep_metadata_calculation = true;
if (! loopStack.empty()){
inherited_dep_metadata_calculation = loopStack.top().get_dependency_metadata_calculation_enabled();
}

#endif
loopStack.push(LoopTableEntry(function_level, loop_id, 0, begin_line));
#if DP_CALLTREE_PROFILING
// set the inherited metadata calculation flag
loopStack.non_const_top().set_dependency_metadata_calculation_enabled(inherited_dep_metadata_calculation);

#endif
if (loops.find(begin_line) == loops.end()) {
loops.insert(pair<LID, LoopRecord *>(begin_line, new LoopRecord(0, 0, 0)));
}
Expand All @@ -46,8 +59,19 @@ class LoopManager {
return loopStack.empty() || (loopStack.top().loopID != loop_id);
}

#if DP_CALLTREE_PROFILING
bool enable_calculate_dependency_metadata() {
return loopStack.top().get_dependency_metadata_calculation_enabled();
};
#endif

void iterate_loop(const std::int32_t function_level) {
loopStack.increment_top_count();
#if DP_CALLTREE_PROFILING
if(! DP_CALLTREE_PROFILING_METADATA_CUTOFF == 0){
loopStack.non_const_top().set_dependency_metadata_calculation_enabled(loopStack.top().get_dependency_metadata_calculation_enabled() && (DP_CALLTREE_PROFILING_METADATA_CUTOFF > loopStack.top().get_count()));
}
#endif
#ifdef DP_DEBUG
std::cout << "(" << std::dec << loopStack.top().funcLevel << ")";
std::cout << "Loop " << loopStack.top().loopID << " iterates " << loopStack.top().count << " times." << std::endl;
Expand Down
2 changes: 2 additions & 0 deletions rtlib/loop/LoopTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct LoopTable {

const LoopTableEntry &top() const { return contents.back(); }

LoopTableEntry &non_const_top() { return contents.back(); }

const LoopTableEntry &first() const { return contents[0]; }

const LoopTableEntry &topMinusN(const std::size_t n) const { return contents[contents.size() - 1 - n]; }
Expand Down
19 changes: 18 additions & 1 deletion rtlib/loop/LoopTableEntry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ namespace __dp {
// For loop tracking
struct LoopTableEntry {
LoopTableEntry(std::int32_t function_level, std::int32_t loop_id, std::int32_t number_hits, LID begin_line)
: funcLevel(function_level), loopID(loop_id), count(number_hits), begin(begin_line) {}
: funcLevel(function_level), loopID(loop_id), count(number_hits), begin(begin_line) {
#if DP_CALLTREE_PROFILING
dependency_metadata_calculation_enabled = true;
#endif
}

std::int32_t funcLevel;
std::int32_t loopID;
Expand All @@ -37,8 +41,21 @@ struct LoopTableEntry {

void increment_count() noexcept { ++count; }

#if DP_CALLTREE_PROFILING
void set_dependency_metadata_calculation_enabled(bool value){
dependency_metadata_calculation_enabled = value;
}

bool get_dependency_metadata_calculation_enabled() const {
return dependency_metadata_calculation_enabled;
}
#endif

private:
std::int32_t count;
#if DP_CALLTREE_PROFILING
bool dependency_metadata_calculation_enabled;
#endif
};

} // namespace __dp
124 changes: 63 additions & 61 deletions rtlib/runtimeFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace __dp {
#if DP_CALLTREE_PROFILING
void addDep(depType type, LID curr, LID depOn, const char *var, string AAvar, ADDR addr,
std::unordered_map<ADDR, std::shared_ptr<CallTreeNode>> *thread_private_write_addr_to_call_tree_node_map,
std::unordered_map<ADDR, std::shared_ptr<CallTreeNode>> *thread_private_read_addr_to_call_tree_node_map) {
std::unordered_map<ADDR, std::shared_ptr<CallTreeNode>> *thread_private_read_addr_to_call_tree_node_map, bool calculate_dependency_metadata) {
#else
void addDep(depType type, LID curr, LID depOn, const char *var, string AAvar, ADDR addr) {
#endif
Expand Down Expand Up @@ -91,62 +91,64 @@ void addDep(depType type, LID curr, LID depOn, const char *var, string AAvar, AD

#if DP_CALLTREE_PROFILING
// register dependency for call_tree based metadata calculation
DependencyMetadata dmd;
switch (type) {
case RAW:
// register metadata calculation
// cout << "Register metadata calculation: RAW " << decodeLID(curr) << " " << decodeLID(depOn) << " " << var << " ("
// << (*thread_private_write_addr_to_call_tree_node_map)[addr]->get_loop_or_function_id() << " , " <<
// (*thread_private_write_addr_to_call_tree_node_map)[addr]->get_iteration_id() << ") " << " (" <<
// (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_loop_or_function_id() << " , " <<
// (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_iteration_id() << ")\n";

// process directly
dmd = processQueueElement(MetaDataQueueElement(type, curr, depOn, var, AAvar,
(*thread_private_read_addr_to_call_tree_node_map)[addr],
(*thread_private_write_addr_to_call_tree_node_map)[addr]));
dependency_metadata_results_mtx->lock();
dependency_metadata_results->insert(dmd);
dependency_metadata_results_mtx->unlock();

// metadata_queue->insert(); // optimization potential: do not use copies here!
break;
case WAR:
// update write
// register metadata calculation
// cout << "Register metadata calculation: WAR " << decodeLID(curr) << " " << decodeLID(depOn) << " " << var << " ("
// << (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_loop_or_function_id() << " , " <<
// (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_iteration_id() << ") " << " (" <<
// (*thread_private_write_addr_to_call_tree_node_map)[addr]->get_loop_or_function_id() << " , " <<
// (*thread_private_write_addr_to_call_tree_node_map)[addr]->get_iteration_id() << ")\n";

dmd = processQueueElement(MetaDataQueueElement(type, curr, depOn, var, AAvar,
(*thread_private_write_addr_to_call_tree_node_map)[addr],
(*thread_private_read_addr_to_call_tree_node_map)[addr]));
dependency_metadata_results_mtx->lock();
dependency_metadata_results->insert(dmd);
dependency_metadata_results_mtx->unlock();
// metadata_queue->insert(); // optimization potential: do not use copies here!
break;
case WAW:
// register metadata calculation
// cout << "Register metadata calculation: WAW " << decodeLID(curr) << " " << decodeLID(depOn) << " " << var << " ("
// << (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_loop_or_function_id() << " , " <<
// (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_iteration_id() << ") " << " (" <<
// (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_loop_or_function_id() << " , " <<
// (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_iteration_id() << ")\n";
dmd = processQueueElement(MetaDataQueueElement(type, curr, depOn, var, AAvar,
(*thread_private_write_addr_to_call_tree_node_map)[addr],
(*thread_private_write_addr_to_call_tree_node_map)[addr]));
dependency_metadata_results_mtx->lock();
dependency_metadata_results->insert(dmd);
dependency_metadata_results_mtx->unlock();
// metadata_queue->insert(); // optimization potential: do not use copies here!
break;
case INIT:
break;
default:
break;
if(calculate_dependency_metadata){
DependencyMetadata dmd;
switch (type) {
case RAW:
// register metadata calculation
// cout << "Register metadata calculation: RAW " << decodeLID(curr) << " " << decodeLID(depOn) << " " << var << " ("
// << (*thread_private_write_addr_to_call_tree_node_map)[addr]->get_loop_or_function_id() << " , " <<
// (*thread_private_write_addr_to_call_tree_node_map)[addr]->get_iteration_id() << ") " << " (" <<
// (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_loop_or_function_id() << " , " <<
// (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_iteration_id() << ")\n";

// process directly
dmd = processQueueElement(MetaDataQueueElement(type, curr, depOn, var, AAvar,
(*thread_private_read_addr_to_call_tree_node_map)[addr],
(*thread_private_write_addr_to_call_tree_node_map)[addr]));
dependency_metadata_results_mtx->lock();
dependency_metadata_results->insert(dmd);
dependency_metadata_results_mtx->unlock();

// metadata_queue->insert(); // optimization potential: do not use copies here!
break;
case WAR:
// update write
// register metadata calculation
// cout << "Register metadata calculation: WAR " << decodeLID(curr) << " " << decodeLID(depOn) << " " << var << " ("
// << (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_loop_or_function_id() << " , " <<
// (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_iteration_id() << ") " << " (" <<
// (*thread_private_write_addr_to_call_tree_node_map)[addr]->get_loop_or_function_id() << " , " <<
// (*thread_private_write_addr_to_call_tree_node_map)[addr]->get_iteration_id() << ")\n";

dmd = processQueueElement(MetaDataQueueElement(type, curr, depOn, var, AAvar,
(*thread_private_write_addr_to_call_tree_node_map)[addr],
(*thread_private_read_addr_to_call_tree_node_map)[addr]));
dependency_metadata_results_mtx->lock();
dependency_metadata_results->insert(dmd);
dependency_metadata_results_mtx->unlock();
// metadata_queue->insert(); // optimization potential: do not use copies here!
break;
case WAW:
// register metadata calculation
// cout << "Register metadata calculation: WAW " << decodeLID(curr) << " " << decodeLID(depOn) << " " << var << " ("
// << (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_loop_or_function_id() << " , " <<
// (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_iteration_id() << ") " << " (" <<
// (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_loop_or_function_id() << " , " <<
// (*thread_private_read_addr_to_call_tree_node_map)[addr]->get_iteration_id() << ")\n";
dmd = processQueueElement(MetaDataQueueElement(type, curr, depOn, var, AAvar,
(*thread_private_write_addr_to_call_tree_node_map)[addr],
(*thread_private_write_addr_to_call_tree_node_map)[addr]));
dependency_metadata_results_mtx->lock();
dependency_metadata_results->insert(dmd);
dependency_metadata_results_mtx->unlock();
// metadata_queue->insert(); // optimization potential: do not use copies here!
break;
case INIT:
break;
default:
break;
}
}

#endif
Expand Down Expand Up @@ -430,7 +432,7 @@ void analyzeSingleAccess(__dp::AbstractShadow *SMem, __dp::AccessInfo &access) {
#endif
#if DP_CALLTREE_PROFILING
addDep(RAW, access.lid, lastWrite, access.var, access.AAvar, access.addr,
thread_private_write_addr_to_call_tree_node_map, thread_private_read_addr_to_call_tree_node_map);
thread_private_write_addr_to_call_tree_node_map, thread_private_read_addr_to_call_tree_node_map, access.calculate_dependency_metadata);
#else
addDep(RAW, access.lid, lastWrite, access.var, access.AAvar, access.addr);
#endif
Expand All @@ -451,7 +453,7 @@ void analyzeSingleAccess(__dp::AbstractShadow *SMem, __dp::AccessInfo &access) {
// INIT
#if DP_CALLTREE_PROFILING
addDep(INIT, access.lid, 0, access.var, access.AAvar, access.addr,
thread_private_write_addr_to_call_tree_node_map, thread_private_read_addr_to_call_tree_node_map);
thread_private_write_addr_to_call_tree_node_map, thread_private_read_addr_to_call_tree_node_map, access.calculate_dependency_metadata);
#else
addDep(INIT, access.lid, 0, access.var, access.AAvar, access.addr);
#endif
Expand All @@ -461,7 +463,7 @@ void analyzeSingleAccess(__dp::AbstractShadow *SMem, __dp::AccessInfo &access) {
// WAR
#if DP_CALLTREE_PROFILING
addDep(WAR, access.lid, lastRead, access.var, access.AAvar, access.addr,
thread_private_write_addr_to_call_tree_node_map, thread_private_read_addr_to_call_tree_node_map);
thread_private_write_addr_to_call_tree_node_map, thread_private_read_addr_to_call_tree_node_map, access.calculate_dependency_metadata);
#else
addDep(WAR, access.lid, lastRead, access.var, access.AAvar, access.addr);
#endif
Expand All @@ -476,7 +478,7 @@ void analyzeSingleAccess(__dp::AbstractShadow *SMem, __dp::AccessInfo &access) {
// WAW
#if DP_CALLTREE_PROFILING
addDep(WAW, access.lid, lastWrite, access.var, access.AAvar, access.addr,
thread_private_write_addr_to_call_tree_node_map, thread_private_read_addr_to_call_tree_node_map);
thread_private_write_addr_to_call_tree_node_map, thread_private_read_addr_to_call_tree_node_map, access.calculate_dependency_metadata);
#else
addDep(WAW, access.lid, lastWrite, access.var, access.AAvar, access.addr);
#endif
Expand Down
3 changes: 3 additions & 0 deletions rtlib/runtimeFunctionsTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ struct AccessInfo {
: isRead(isRead), lid(lid), var(var), AAvar(AAvar), addr(addr), skip(skip) {
#if DP_CALLTREE_PROFILING
call_tree_node_ptr = nullptr;
calculate_dependency_metadata = true;
#endif
}

AccessInfo() : isRead(false), lid(0), var(""), AAvar(""), addr(0), skip(false) {
#if DP_CALLTREE_PROFILING
call_tree_node_ptr = nullptr;
calculate_dependency_metadata = true;
#endif
}

Expand All @@ -80,6 +82,7 @@ struct AccessInfo {
ADDR addr;
#if DP_CALLTREE_PROFILING
shared_ptr<CallTreeNode> call_tree_node_ptr;
bool calculate_dependency_metadata;
#endif
};

Expand Down

0 comments on commit 99fe805

Please sign in to comment.