Skip to content

Commit

Permalink
Feat/new memspec (#105)
Browse files Browse the repository at this point in the history
This commit introduces the new memspecs featured in tukl-msd/DRAMUtils.
---------

Co-authored-by: marcomoerz <[email protected]>
Co-authored-by: Thomas Psota <[email protected]>
  • Loading branch information
3 people authored Aug 1, 2024
1 parent 00081dd commit 5ed2d6e
Show file tree
Hide file tree
Showing 128 changed files with 2,525 additions and 2,202 deletions.
42 changes: 26 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ option(DRAMPOWER_BUILD_TESTS "Build DRAMPower unit tests" OFF)
option(DRAMPOWER_VERBOSE_CMAKE_OUTPUT "Show detailed CMake output" OFF)
option(DRAMPOWER_BUILD_CLI "Build DRAMPower Command Line Tool" OFF)

set(DRAMUTILS_DIR "" CACHE PATH "Local DRAMUtils installation path (optional)")

### Compiler settings ###
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

###############################################
### Library Settings ###
Expand All @@ -86,26 +90,32 @@ set(CMAKE_CXX_STANDARD 17)
### Detect OS threading library ###
find_package(Threads)

add_subdirectory(${DRAMPOWER_LIBRARY_DIR}/nlohmann_json)
### DRAMUtils ###
if (DRAMUTILS_DIR) # Fetch DRAMUtils from supplied local path
message(STATUS "Using local DRAMUtils installation from ${DRAMUTILS_DIR}")
FetchContent_Declare(
DRAMUtils
SOURCE_DIR ${DRAMUTILS_DIR}
)
else() # Fetch DRAMUtils from github
message(STATUS "Fetching DRAMUtils from github")
FetchContent_Declare(
DRAMUtils
GIT_REPOSITORY https://github.com/tukl-msd/DRAMUtils
GIT_TAG "v1.0"
)
endif()

### nlohmann_json ###
#FetchContent_Declare(
# json
# GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
# GIT_TAG v3.9.1)
#
#FetchContent_GetProperties(json)
#if(NOT json_POPULATED)
# FetchContent_Populate(json)
# add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL)
#endif()
FetchContent_MakeAvailable(DRAMUtils)
set_target_properties(DRAMUtils PROPERTIES FOLDER lib)

### GoogleTest ###
if(DRAMPOWER_BUILD_TESTS)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG release-1.12.1)
googletest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG release-1.12.1
)

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
Expand All @@ -123,7 +133,7 @@ endif()
add_subdirectory(src/DRAMPower)

if(DRAMPOWER_BUILD_CLI)
add_subdirectory(src/cli)
add_subdirectory(src/cli)
endif()

###############################################
Expand Down
77 changes: 77 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 14,
"patch": 0
},
"configurePresets": [
{
"name": "cmake-pedantic",
"hidden": true,
"warnings": {
"dev": true,
"deprecated": true,
"unusedCli": true,
"systemVars": false
}
},
{
"name": "dev-mode",
"hidden": true,
"inherits": "cmake-pedantic",
"cacheVariables": {
"DRAMPOWER_BUILD_TESTS": "ON",
"CMAKE_BUILD_PARALLEL_LEVEL": ""
}
},
{
"name": "ci-common",
"binaryDir": "${sourceDir}/build",
"inherits": [
"dev-mode"
],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "ci-unix",
"generator": "Unix Makefiles",
"inherits": [
"ci-common"
]
},
{
"name": "ci-msvc",
"generator": "Visual Studio 17 2022",
"inherits": [
"ci-common"
],
"cacheVariables": {
"CMAKE_CXX_FLAGS": "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /MP"
}
},
{
"name": "dev-unix",
"generator": "Unix Makefiles",
"inherits": [
"dev-mode"
],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic"
}
},
{
"name": "dev-msvc",
"generator": "Visual Studio 17 2022",
"inherits": [
"dev-mode"
],
"cacheVariables": {
"CMAKE_CXX_FLAGS": "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /MP"
}
}
]
}
2 changes: 1 addition & 1 deletion src/DRAMPower/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ file(GLOB_RECURSE HEADER_FILES CONFIGURE_DEPENDS *.h;*.hpp)
add_library(DRAMPower ${SOURCE_FILES} ${HEADER_FILES})
target_include_directories(DRAMPower PUBLIC ${PROJECT_SOURCE_DIR})
target_link_libraries(DRAMPower PUBLIC
nlohmann_json::nlohmann_json
DRAMUtils
)

add_library(DRAMSys::DRAMPower ALIAS DRAMPower)
Expand Down
30 changes: 17 additions & 13 deletions src/DRAMPower/DRAMPower/command/Pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <bitset>
#include <cassert>
#include <unordered_map>
#include <vector>

namespace DRAMPower {
namespace pattern_descriptor {
Expand All @@ -26,7 +27,8 @@ enum class PatternEncoderBitSpec
{
L = 0,
H = 1,
LAST_BIT = 2
LAST_BIT = 2,
INVALID = -1
};

// struct for initializer list in PatternEncoderSettings
Expand All @@ -43,20 +45,20 @@ class PatternEncoderOverrides
std::unordered_map<pattern_descriptor::t, PatternEncoderBitSpec> settings;
public:
// Constructor with initializer list for settings
PatternEncoderOverrides(std::initializer_list<PatternEncoderSettingsEntry> settings)
PatternEncoderOverrides(std::initializer_list<PatternEncoderSettingsEntry> _settings)
{
for (const auto &setting : settings)
for (const auto &setting : _settings)
{
this->settings[setting.descriptor] = setting.bitSpec;
this->settings.emplace(setting.descriptor, setting.bitSpec);
}
};
PatternEncoderOverrides() = default;

public:
void updateSettings(std::initializer_list<PatternEncoderSettingsEntry> settings)
void updateSettings(std::initializer_list<PatternEncoderSettingsEntry> _settings)
{
// Update settings if descriptor is already present
for (const auto &setting : settings)
for (const auto &setting : _settings)
{
this->settings[setting.descriptor] = setting.bitSpec;
}
Expand All @@ -69,7 +71,11 @@ class PatternEncoderOverrides

PatternEncoderBitSpec getSetting(pattern_descriptor::t descriptor)
{
return this->settings[descriptor];
if (this->settings.find(descriptor) != this->settings.end())
{
return this->settings.at(descriptor);
}
return PatternEncoderBitSpec::INVALID;
};

bool hasSetting(pattern_descriptor::t descriptor)
Expand Down Expand Up @@ -98,19 +104,17 @@ inline bool applyBitSpec(
bool default_bit
)
{
if(!spec.hasSetting(descriptor))
{
return default_bit;
}

switch (spec.getSetting(descriptor))
auto setting = spec.getSetting(descriptor);
switch (setting)
{
case PatternEncoderBitSpec::L:
return false;
case PatternEncoderBitSpec::H:
return true;
case PatternEncoderBitSpec::LAST_BIT:
return LAST_BIT;
case PatternEncoderBitSpec::INVALID:
return default_bit;
default:
assert(false);
break;
Expand Down
15 changes: 12 additions & 3 deletions src/DRAMPower/DRAMPower/data/energy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ double energy_info_t::total() const
return total;
};

void energy_info_t::to_json(nlohmann::json &j) const
void energy_info_t::to_json(json_t &j) const
{
j = nlohmann::json{
{"ACT", E_act},
Expand Down Expand Up @@ -80,7 +80,16 @@ double DRAMPower::energy_t::total() const
return total;
}

void DRAMPower::energy_t::to_json(nlohmann::json &j) const
void DRAMPower::interface_energy_info_t::to_json(json_t &j) const
{
j = nlohmann::json{};
j["controller"]["dynamicEnergy"] = controller.dynamicEnergy;
j["controller"]["staticEnergy"] = controller.staticEnergy;
j["dram"]["dynamicEnergy"] = dram.dynamicEnergy;
j["dram"]["staticEnergy"] = dram.staticEnergy;
}

void DRAMPower::energy_t::to_json(json_t &j) const
{
j = nlohmann::json{
{"E_bg_act_shared", E_bg_act_shared},
Expand All @@ -94,7 +103,7 @@ void DRAMPower::energy_t::to_json(nlohmann::json &j) const
auto energy_arr = nlohmann::json::array();
for (const energy_info_t& energy : bank_energy)
{
nlohmann::json bank_energy_json;
json_t bank_energy_json;
energy.to_json(bank_energy_json);
energy_arr.push_back(bank_energy_json);
}
Expand Down
40 changes: 28 additions & 12 deletions src/DRAMPower/DRAMPower/data/energy.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

#include <vector>
#include <iostream>
#include <nlohmann/json.hpp>

#include <DRAMUtils/util/json_utils.h>

namespace DRAMPower {

Expand All @@ -29,7 +30,7 @@ struct energy_info_t
double E_ref_2B = 0.0;

double total() const;
void to_json(nlohmann::json &j) const;
void to_json(json_t &j) const;
energy_info_t& operator+=(const energy_info_t & other);
// Operator << for std::cout
friend std::ostream & operator<<(std::ostream & os, const energy_info_t & ei)
Expand Down Expand Up @@ -57,7 +58,7 @@ struct energy_t
{
std::vector<energy_info_t> bank_energy;
energy_info_t total_energy(); // TODO rename
void to_json(nlohmann::json &j) const;
void to_json(json_t &j) const;
constexpr inline const char * const get_Bank_energy_keyword() const
{
return "BankEnergy";
Expand Down Expand Up @@ -88,18 +89,18 @@ struct energy_t
double total() const;
};

struct interface_power_t
struct interface_energy_t
{
double dynamicPower = 0.0;
double staticPower = 0.0;
double dynamicEnergy = 0.0;
double staticEnergy = 0.0;

interface_power_t &operator+=(const interface_power_t &rhs) {
dynamicPower += rhs.dynamicPower;
staticPower += rhs.staticPower;
interface_energy_t &operator+=(const interface_energy_t &rhs) {
dynamicEnergy += rhs.dynamicEnergy;
staticEnergy += rhs.staticEnergy;
return *this;
}

friend interface_power_t operator+(interface_power_t lhs, const interface_power_t &rhs) {
friend interface_energy_t operator+(interface_energy_t lhs, const interface_energy_t &rhs) {
lhs += rhs;
return lhs;
}
Expand All @@ -109,8 +110,12 @@ struct interface_power_t

struct interface_energy_info_t
{
interface_power_t controller;
interface_power_t dram;
interface_energy_t controller;
interface_energy_t dram;

double total() const {
return controller.dynamicEnergy + controller.staticEnergy + dram.dynamicEnergy + dram.staticEnergy;
}

interface_energy_info_t &operator+=(const interface_energy_info_t &rhs) {
controller += rhs.controller;
Expand All @@ -123,6 +128,17 @@ struct interface_energy_info_t
lhs += rhs;
return lhs;
}

friend std::ostream & operator<<(std::ostream & os, const interface_energy_info_t & e)
{
os << "Controller: dynamicEnergy: " << e.controller.dynamicEnergy << " ";
os << "staticEnergy: " << e.controller.staticEnergy << std::endl;
os << "DRAM: dynamicEnergy: " << e.dram.dynamicEnergy << " ";
os << "staticEnergy: " << e.dram.staticEnergy << std::endl;
os << "Total: " << e.total() << std::endl;
return os;
}
void to_json(json_t &j) const;
};

};
Expand Down
Loading

0 comments on commit 5ed2d6e

Please sign in to comment.