Skip to content

Commit b7ace70

Browse files
committed
homogeneous and heterogeneous configuration support, config files generation support
1 parent 9be2807 commit b7ace70

25 files changed

+716
-39
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*build
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cmake_minimum_required(VERSION 3.9)
2+
project(src_sink VERSION 0.0.0 LANGUAGES CXX)
3+
4+
set(CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard is cached for visibility in external tools." FORCE)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
8+
9+
set(LF_MAIN_TARGET src_sink)
10+
11+
find_package(reactor-cpp PATHS )
12+
find_package(reactor-sdk PATHS )
13+
14+
add_executable(${LF_MAIN_TARGET}
15+
main.cc
16+
)
17+
18+
include_directories(${CMAKE_CURRENT_LIST_DIR})
19+
20+
target_link_libraries(${LF_MAIN_TARGET} reactor-cpp)
21+
target_link_libraries(${LF_MAIN_TARGET} reactor-sdk)
22+
23+
target_compile_options(${LF_MAIN_TARGET} PRIVATE -Wall -Wextra -pedantic)
24+
25+
include(Sink/SinkReactor.cmake)
26+
include(Source/SourceReactor.cmake)
27+
include(Main/MainReactor.cmake)
28+
include(Config-a/Config-a.cmake)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "Config-a.hh"
2+
3+
UserParameters cfg_parameters;
4+
5+
ConfigParameter<int, uint32_t, string>::ParametersMap UserParameters::homogeneous_config() {
6+
return {
7+
{"Main.Source.iterations", ConfigParameterMetadata<int> { 5 } },
8+
{"Main.Sink.name", ConfigParameterMetadata<string> { "Homogeneous" } }
9+
};
10+
}
11+
12+
ConfigParameter<int, uint32_t, string>::ParametersMap UserParameters::heterogeneous_config() {
13+
return {
14+
{"Main.Source.iterations", ConfigParameterMetadata<int> { 20 } },
15+
{"Main.Source.n_ports", ConfigParameterMetadata<int> { 4 } },
16+
{"Main.n_sinks", ConfigParameterMetadata<int> { 4 } },
17+
{"Main.Sink_0.name", ConfigParameterMetadata<string> { "Heterogeneous_0" } },
18+
{"Main.Sink_2.name", ConfigParameterMetadata<string> { "Heterogeneous_2" } }
19+
20+
};
21+
}
22+
23+
// UserParameters::filter_out () {
24+
// if (cfg_map["T0.P0.L1.n_ervers"] != cfg_map["T0.P0.L2.n_ervers"]) {
25+
26+
// }
27+
// }
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
include_directories(${CMAKE_CURRENT_LIST_DIR})
2+
3+
set(INCLUDE_FILES
4+
"${CMAKE_CURRENT_LIST_DIR}/Config-a.hh"
5+
)
6+
7+
set(SOURCE_FILES
8+
"${CMAKE_CURRENT_LIST_DIR}/Config-a.cc"
9+
)
10+
11+
12+
foreach(file IN LISTS INCLUDE_FILES)
13+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${file}")
14+
endforeach()
15+
16+
target_sources(${LF_MAIN_TARGET} PRIVATE ${SOURCE_FILES})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include <reactor-sdk/reactor-sdk.hh>
4+
#include <map>
5+
#include <variant>
6+
#include <string>
7+
8+
using namespace sdk;
9+
10+
struct UserParameters : public ConfigParameter<int, uint32_t, string> {
11+
ConfigParameter<int, uint32_t, string>::ParametersMap homogeneous_config();
12+
ConfigParameter<int, uint32_t, string>::ParametersMap heterogeneous_config();
13+
};
14+
15+
extern UserParameters cfg_parameters;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "MainReactor.hh"
2+
3+
void MainReactor::construction() {
4+
5+
cout << "Construction Main n_sinks:" << parameters.n_sinks.value << "\n";
6+
7+
src = std::make_unique<SourceReactor>("Source", this);
8+
9+
for (int i = 0; i < parameters.n_sinks.value; i++) {
10+
snk.create_reactor();
11+
}
12+
}
13+
14+
void MainReactor::assembling() {
15+
cout << "Assembling Main n_sinks:" << parameters.n_sinks.value << "\n";
16+
17+
src->req --> snk.for_each(select_default(snk).req);
18+
// src->req --> snk.for_each(&SinkReactor::req); // alternative
19+
// src->req --> snk.for_each(&snk[0].req); // alternative
20+
// src->req --> snk->*(select_default(snk).req); // alternative
21+
// src->req --> snk->*(&SinkReactor::req); // alternative
22+
23+
snk.for_each(select_default(snk).rsp) --> src->rsp;
24+
// snk.for_each(&SinkReactor::rsp) --> src->rsp; // alternative
25+
// snk.for_each(&snk[0].rsp) --> src->rsp; // alternative
26+
// (snk->*(select_default(snk).rsp)) --> src->rsp; // alternative
27+
// (snk->*(&SinkReactor::rsp)) --> src->rsp; // alternative
28+
29+
reaction("reaction_1").
30+
triggers(&startup).
31+
effects().
32+
function(
33+
[&](Startup& startup) {
34+
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
35+
"Starting up reaction\n" << "Bank:" << bank_index << " name:" << parameters.alias.value << " fqn:" << fqn() << " n_sinks:" << parameters.n_sinks.value << endl;
36+
}
37+
);
38+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
include_directories(${CMAKE_CURRENT_LIST_DIR})
2+
3+
set(INCLUDE_FILES
4+
"${CMAKE_CURRENT_LIST_DIR}/MainReactor.hh"
5+
)
6+
7+
set(SOURCE_FILES
8+
"${CMAKE_CURRENT_LIST_DIR}/MainReactor.cc"
9+
)
10+
11+
12+
foreach(file IN LISTS INCLUDE_FILES)
13+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${file}")
14+
endforeach()
15+
16+
target_sources(${LF_MAIN_TARGET} PRIVATE ${SOURCE_FILES})
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
3+
#include <reactor-sdk/reactor-sdk.hh>
4+
5+
#include "Source/SourceReactor.hh"
6+
#include "Sink/SinkReactor.hh"
7+
8+
using namespace sdk;
9+
10+
class MainReactor: public Reactor {
11+
public:
12+
struct Parameters : public SystemParameter<string, int> {
13+
14+
// REACTOR_PARAMETER(<type>, <variable-name>, <description>, <min-value>, <max-value>, <default-value>);
15+
REACTOR_PARAMETER(string, alias, "Alternate name", "another", "another", "another");
16+
REACTOR_PARAMETER(int, n_sinks, "Sink reactors bank width", 1, 10, 1);
17+
REACTOR_PARAMETER(int, log_level, "Log level", 0, 1, 1);
18+
19+
Parameters(Reactor *container)
20+
: SystemParameter<string, int>(container) {
21+
register_parameters (alias, n_sinks, log_level);
22+
}
23+
};
24+
25+
private:
26+
Parameters parameters{this};
27+
28+
std::unique_ptr<SourceReactor> src;
29+
ReactorBank<SinkReactor> snk{"Sink", this};
30+
31+
public:
32+
MainReactor(const std::string &name, Environment *env)
33+
: Reactor(name, env) {}
34+
MainReactor(const std::string &name, Reactor *container)
35+
: Reactor(name, container) {}
36+
37+
void construction() override;
38+
void assembling() override;
39+
};
40+
41+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "SinkReactor.hh"
2+
using namespace std;
3+
4+
void SinkReactor::construction() {
5+
cout << "Construction Sink\n";
6+
}
7+
8+
void SinkReactor::assembling() {
9+
10+
cout << "Assembling Sink\n";
11+
12+
reaction("startup_reaction").
13+
triggers(&startup).
14+
effects().
15+
function(pass_function(startup_reaction)
16+
);
17+
18+
reaction("process_request").
19+
triggers(&req).
20+
effects(&rsp).
21+
function(pass_function(process_request)
22+
);
23+
}
24+
25+
26+
27+
void SinkReactor::startup_reaction (Startup& startup) {
28+
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
29+
"Starting up reaction\n" << "Bank:" << bank_index << " name:" << parameters.name.value << " fqn:" << fqn() << endl;
30+
}
31+
32+
void SinkReactor::process_request (Input<int>& req, Output<int>& rsp) {
33+
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
34+
"Received input:" << *req.get() << " bank:" << bank_index << endl;
35+
rsp.set (*req.get());
36+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
set(INCLUDE_FILES
2+
"${CMAKE_CURRENT_LIST_DIR}/SinkReactor.hh"
3+
)
4+
5+
set(SOURCE_FILES
6+
"${CMAKE_CURRENT_LIST_DIR}/SinkReactor.cc"
7+
)
8+
9+
10+
foreach(file IN LISTS INCLUDE_FILES)
11+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${file}")
12+
endforeach()
13+
14+
target_sources(${LF_MAIN_TARGET} PRIVATE ${SOURCE_FILES})

0 commit comments

Comments
 (0)