Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement firestarter kernel #11

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
2 changes: 0 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ UseTab: Never

SpacesInParentheses: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceAfterControlStatementKeyword: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build*
.cache/
python
10 changes: 3 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,9 @@ else()
message(STATUS "X86Adapt wasn't found, DDCM not available.")
endif()

if (USE_FIRESTARTER)
include(cmake/BuildFirestarter.cmake)
message(STATUS "Building WITH firestarter.")
else()
message(STATUS "Building WITHOUT firestarter.")
endif()
# Allow the use of external metrics for firestarter
set(FIRESTARTER_LINK_STATIC OFF)
add_subdirectory(lib/FIRESTARTER)

target_include_directories(roco2 INTERFACE include)

Expand All @@ -96,7 +93,6 @@ macro(Roco2Configuration CONF )

target_link_libraries(
roco2_${CONF}
roco2_main
roco2_core
)

Expand Down
40 changes: 0 additions & 40 deletions cmake/BuildFirestarter.cmake

This file was deleted.

28 changes: 21 additions & 7 deletions include/roco2/kernels/firestarter.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#ifndef INCLUDE_ROCO2_KERNELS_FIRESTARTER_HPP
#define INCLUDE_ROCO2_KERNELS_FIRESTARTER_HPP

#include <roco2/chrono/util.hpp>
#include <roco2/kernels/base_kernel.hpp>

#include <roco2/chrono/util.hpp>
#include <firestarter/Payload/CompiledPayload.hpp>
#include <firestarter/Payload/Payload.hpp>

namespace roco2
{
Expand All @@ -24,15 +26,27 @@ namespace kernels
}

private:
/// Runs the firestarter kernel until a timepoint
/// \arg until The timepoint until the kernel should execute the high load function of
/// firestarter
void run_kernel(roco2::chrono::time_point until) override;

int (*firestarter_function_)(void*);
int (*firestarter_init_)(void*);
int base_function_;
/// This function terminates the execution of firestarter by writing the load variable to
/// ::firestarter::LoadThreadWorkType::LoadStop after the time of the experiment elapsed.
/// \arg until The timepoint until the kernel should execute the high load function of
/// firestarter
/// \arg load_var the reference to the variable that termination the load of firestarter
static void stop_kernel(roco2::chrono::time_point until,
::firestarter::LoadThreadWorkType& load_var);

/// The variable shared across all threads that termination the load of firestarter
::firestarter::LoadThreadWorkType load_var = ::firestarter::LoadThreadWorkType::LoadHigh;

const static param_type loop_count = 10000;
/// The unique ptr to the load and init function for firestarter
::firestarter::payload::CompiledPayload::UniquePtr compiled_payload_ptr = { nullptr,
nullptr };
};
}
}
} // namespace kernels
} // namespace roco2

#endif // INCLUDE_ROCO2_KERNELS_FIRESTARTER_HPP
34 changes: 10 additions & 24 deletions include/roco2/memory/thread_local.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#ifndef INCLUDE_ROCO2_MEMORY_HPP
#define INCLUDE_ROCO2_MEMORY_HPP

#include <firestarter/LoadWorkerMemory.hpp>
#include <roco2/memory/alignment_allocator.hpp>
#include <roco2/log.hpp>

#include <omp.h>

#include <vector>
#include <chrono>
#include <thread>
#include <memory>
#include <vector>

namespace roco2
{
Expand All @@ -21,9 +19,8 @@ namespace detail
{
thread_local_memory()
: vec_A(vec_size), vec_B(vec_size), vec_C(vec_size), vec_F(vec_size),
mat_A(mat_size * mat_size), mat_B(mat_size * mat_size),
mat_C(mat_size * mat_size), mem_buffer(mem_size),
firestarter_buffer(firestarter_size)
mat_A(mat_size * mat_size), mat_B(mat_size * mat_size), mat_C(mat_size * mat_size),
mem_buffer(mem_size)
{
for (std::size_t i = 0; i < vec_A.size(); ++i)
{
Expand All @@ -45,12 +42,6 @@ namespace detail
mem_buffer[i] = i * 23 + 42;
}

for (std::size_t i = 0; i < firestarter_buffer.size(); ++i)
{
firestarter_buffer[i] =
0.25 + static_cast<double>(i % 9267) * 0.24738995982e-4;
}

log::debug() << "Memory allocated and touched.";
}

Expand All @@ -64,25 +55,20 @@ namespace detail
std::vector<double> mat_C;

std::vector<std::uint64_t> mem_buffer;
std::vector<double, AlignmentAllocator<double, 32>> firestarter_buffer;

::firestarter::LoadWorkerMemory::UniquePtr firestarter_memory = { nullptr, nullptr };

const static std::size_t vec_size = 1024;
const static std::size_t mat_size = 512;

// size of mem_buffer equals 64MB
const static std::size_t mem_size =
64 * 1024 * 1024 / sizeof(mem_buffer[0]);

// size of mem_buffer equals 160MB
const static std::size_t firestarter_size =
512 * 1024 * 1024 / sizeof(firestarter_buffer[0]);
const static std::size_t mem_size = 64 * 1024 * 1024 / sizeof(mem_buffer[0]);
};
}
} // namespace detail

static detail::thread_local_memory& thread_local_memory()
{
static std::vector<std::unique_ptr<
detail::thread_local_memory>> memory(omp_get_max_threads());
static std::vector<std::unique_ptr<detail::thread_local_memory>> memory(omp_get_max_threads());

auto& tld = memory[omp_get_thread_num()];

Expand All @@ -93,5 +79,5 @@ static detail::thread_local_memory& thread_local_memory()

return *tld;
}
}
} // namespace roco2
#endif // INCLUDE_ROCO2_MEMORY_HPP
2 changes: 1 addition & 1 deletion lib/FIRESTARTER
Submodule FIRESTARTER updated 211 files
23 changes: 11 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(roco2_core_SOURCES)
list(APPEND roco2_core_SOURCES
main.cpp
metrics.cpp
cpu.cpp
fastcpufreq.c
Expand All @@ -13,27 +14,25 @@ else()
message(STATUS "Building WITHOUT asm kernels.")
endif()

if (USE_FIRESTARTER)
list(APPEND roco2_core_SOURCES firestarter_kernel.cpp)
endif()
list(APPEND roco2_core_SOURCES firestarter_kernel.cpp)

add_library(roco2_core STATIC ${roco2_core_SOURCES})
target_link_libraries(roco2_core PUBLIC roco2)
if (USE_FIRESTARTER)
target_compile_definitions(roco2_core PUBLIC "HAS_FIRESTARTER")
target_link_libraries(roco2_core PUBLIC firestarter)
add_dependencies(roco2_core libfirestarter)
endif()

target_link_libraries(roco2_core PUBLIC roco2 Nitro::env)

target_link_libraries(roco2_core PUBLIC
"-Wl,--whole-archive"
firestartercombined
"-Wl,--no-whole-archive"
)

if (USE_SCOREP)
option(ROCO2_HIGHLOW_INSTRUMENT_PHASES "instrument the individual high & low phases of the high-low-kernel" OFF)
if (ROCO2_HIGHLOW_INSTRUMENT_PHASES)
target_compile_definitions(roco2_core PUBLIC "ROCO2_HIGHLOW_INSTRUMENT_PHASES")
endif()
endif()

add_library(roco2_main STATIC main.cpp)
target_link_libraries(roco2_main PUBLIC roco2)

add_subdirectory(configurations)

add_subdirectory(test)
2 changes: 1 addition & 1 deletion src/configurations/ariel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
if (X86Adapt_FOUND AND CpuFreq_FOUND AND USE_FIRESTARTER AND USE_ASM_KERNELS)
if (X86Adapt_FOUND AND CpuFreq_FOUND AND USE_ASM_KERNELS)
Roco2Configuration(ariel)
endif()
2 changes: 1 addition & 1 deletion src/configurations/charon/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
if(CpuFreq_FOUND AND USE_FIRESTARTER AND USE_ASM_KERNELS)
if(CpuFreq_FOUND AND USE_ASM_KERNELS)
Roco2Configuration(charon)
endif()
5 changes: 2 additions & 3 deletions src/configurations/charon/experiment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ void run_experiments(roco2::chrono::time_point starting_point, bool eta_only)

roco2::experiments::const_lenght exp(experiment_startpoint, experiment_duration);

auto experiment = [&](auto& kernel, const auto& on) {
plan.push_back(roco2::task::experiment_task(exp, kernel, on));
};
auto experiment = [&](auto& kernel, const auto& on)
{ plan.push_back(roco2::task::experiment_task(exp, kernel, on)); };

auto setting = [&](auto lambda) { plan.push_back(roco2::task::make_lambda_task(lambda)); };

Expand Down
2 changes: 1 addition & 1 deletion src/configurations/charon_turbo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if(CpuFreq_FOUND AND USE_FIRESTARTER AND USE_ASM_KERNELS)
if(CpuFreq_FOUND AND USE_ASM_KERNELS)
Roco2Configuration(charon_turbo)
endif()

2 changes: 1 addition & 1 deletion src/configurations/conway/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if(CpuFreq_FOUND AND USE_FIRESTARTER AND USE_ASM_KERNELS)
if(X86Adapt_FOUND AND CpuFreq_FOUND AND USE_ASM_KERNELS)
Roco2Configuration(conway)
endif()

2 changes: 1 addition & 1 deletion src/configurations/example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
if(CpuFreq_FOUND AND USE_FIRESTARTER AND USE_ASM_KERNELS)
if(X86Adapt_FOUND AND CpuFreq_FOUND AND USE_ASM_KERNELS)
Roco2Configuration(example)
endif()
Loading