Introduce benchmark support using Google Benchmark
This commit is contained in:
@@ -90,6 +90,7 @@ set(DRAMSYS_EXTENSIONS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/extensions")
|
||||
|
||||
### Build options ###
|
||||
option(DRAMSYS_BUILD_TESTS "Build DRAMSys unit tests" OFF)
|
||||
option(DRAMSYS_BUILD_BENCHMARKS "Build DRAMSys benchmarks" OFF)
|
||||
option(DRAMSYS_VERBOSE_CMAKE_OUTPUT "Show detailed CMake output" OFF)
|
||||
option(DRAMSYS_BUILD_CLI "Build DRAMSys Command Line Tool" ON)
|
||||
option(DRAMSYS_WITH_DRAMPOWER "Build with DRAMPower support enabled." OFF)
|
||||
@@ -125,6 +126,18 @@ if(DRAMSYS_BUILD_TESTS)
|
||||
set_target_properties(gtest_main PROPERTIES FOLDER lib/gtest)
|
||||
endif()
|
||||
|
||||
### GoogleBenchmark ###
|
||||
if(DRAMSYS_BUILD_BENCHMARKS)
|
||||
set(BENCHMARK_ENABLE_TESTING OFF)
|
||||
|
||||
FetchContent_Declare(
|
||||
benchmark
|
||||
URL https://github.com/google/benchmark/archive/refs/tags/v1.8.3.zip
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(benchmark)
|
||||
endif()
|
||||
|
||||
### SystemC ###
|
||||
if (DRAMSYS_USE_EXTERNAL_SYSTEMC)
|
||||
list(APPEND CMAKE_PREFIX_PATH $ENV{SYSTEMC_HOME} /opt/systemc)
|
||||
@@ -179,3 +192,11 @@ if(DRAMSYS_BUILD_TESTS)
|
||||
include(CTest)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
###############################################
|
||||
### Benchmark Directory ###
|
||||
###############################################
|
||||
|
||||
if(DRAMSYS_BUILD_BENCHMARKS)
|
||||
add_subdirectory(benches)
|
||||
endif()
|
||||
|
||||
54
benches/CMakeLists.txt
Normal file
54
benches/CMakeLists.txt
Normal file
@@ -0,0 +1,54 @@
|
||||
# Copyright (c) 2023, RPTU Kaiserslautern-Landau
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
|
||||
# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# Authors:
|
||||
# Derek Christ
|
||||
|
||||
###############################################
|
||||
### benches_dramsys ###
|
||||
###############################################
|
||||
|
||||
cmake_minimum_required(VERSION 3.1.0)
|
||||
|
||||
project(benches_dramsys)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
addressdecoder.cpp
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR})
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER benches)
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
DRAMSys::util
|
||||
DRAMSys::libdramsys
|
||||
benchmark
|
||||
)
|
||||
|
||||
build_source_group()
|
||||
74
benches/addressdecoder.cpp
Normal file
74
benches/addressdecoder.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2023, RPTU Kaiserslautern-Landau
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Authors:
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#include "addressdecoder.h"
|
||||
|
||||
#include <DRAMSys/config/AddressMapping.h>
|
||||
#include <DRAMSys/simulation/AddressDecoder.h>
|
||||
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <random>
|
||||
|
||||
static DRAMSys::AddressDecoder addressDecoder()
|
||||
{
|
||||
auto addressMapping = nlohmann::json::parse(addressMappingJsonString)
|
||||
.at("addressmapping")
|
||||
.get<DRAMSys::Config::AddressMapping>();
|
||||
DRAMSys::AddressDecoder decoder(addressMapping);
|
||||
return decoder;
|
||||
}
|
||||
|
||||
static void decode(benchmark::State& state)
|
||||
{
|
||||
auto decoder = addressDecoder();
|
||||
|
||||
std::default_random_engine engine;
|
||||
std::uniform_int_distribution<uint64_t> distribution(0, decoder.maxAddress());
|
||||
|
||||
for (auto _ : state)
|
||||
{
|
||||
auto decodedAddress = decoder.decodeAddress(distribution(engine));
|
||||
benchmark::DoNotOptimize(decodedAddress);
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK(decode);
|
||||
|
||||
int sc_main(int argc, char** argv)
|
||||
{
|
||||
::benchmark::Initialize(&argc, argv);
|
||||
::benchmark::RunSpecifiedBenchmarks();
|
||||
return 0;
|
||||
}
|
||||
87
benches/addressdecoder.h
Normal file
87
benches/addressdecoder.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2022, RPTU Kaiserslautern-Landau
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Authors:
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
inline constexpr std::string_view addressMappingJsonString = R"(
|
||||
{
|
||||
"addressmapping": {
|
||||
"PSEUDOCHANNEL_BIT":[
|
||||
29
|
||||
],
|
||||
"BANKGROUP_BIT":[
|
||||
27,
|
||||
28
|
||||
],
|
||||
"BANK_BIT": [
|
||||
25,
|
||||
26
|
||||
],
|
||||
"BYTE_BIT": [
|
||||
0,
|
||||
1,
|
||||
2
|
||||
],
|
||||
"COLUMN_BIT": [
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9
|
||||
],
|
||||
"ROW_BIT": [
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
15,
|
||||
16,
|
||||
17,
|
||||
18,
|
||||
19,
|
||||
20,
|
||||
21,
|
||||
22,
|
||||
23,
|
||||
24
|
||||
]
|
||||
}
|
||||
}
|
||||
)";
|
||||
@@ -86,6 +86,7 @@ public:
|
||||
[[nodiscard]] DecodedAddress decodeAddress(uint64_t encAddr) const;
|
||||
[[nodiscard]] unsigned decodeChannel(uint64_t encAddr) const;
|
||||
[[nodiscard]] uint64_t encodeAddress(DecodedAddress decodedAddress) const;
|
||||
[[nodiscard]] uint64_t maxAddress() const { return maximumAddress; }
|
||||
|
||||
void print() const;
|
||||
void plausibilityCheck(const MemSpec &memSpec);
|
||||
|
||||
Reference in New Issue
Block a user