Skip to content

Sdk #78

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

Closed
wants to merge 22 commits into from
Closed

Sdk #78

Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5b07ca5
base changes for sdk, bug fix for export_dependency_graph to a .dot file
OmerMajNition Feb 19, 2025
0035b41
first draft of sdk, work in progress
OmerMajNition Feb 19, 2025
fb31d00
reverted back info logs
OmerMajNition Feb 20, 2025
9be2807
command line arguments support added to SDK, copied files used by LF
OmerMajNition Feb 20, 2025
b7ace70
homogeneous and heterogeneous configuration support, config files gen…
OmerMajNition Feb 21, 2025
38ebfca
Parameter changes and homogenoeus heterogeneous config generation
OmerMajNition Feb 26, 2025
438c067
added reacion dependencies feature with a test case
OmerMajNition Feb 27, 2025
3ab09b9
parameters with default values, able to be passed from parent when co…
OmerMajNition Mar 3, 2025
008a4a5
Default parameters support with ReactorBanks
OmerMajNition Mar 3, 2025
46c4346
hello world and Workers examples added for LF weekly meeting
OmerMajNition Mar 4, 2025
a21791b
Workers example with published parameters
OmerMajNition Mar 5, 2025
4ea3411
fixed a bug
OmerMajNition Mar 5, 2025
5058c3c
gradually moving towards unified wiring function call that dumps the …
OmerMajNition Mar 7, 2025
591bc73
added reaction internals class that would help users define reactions…
OmerMajNition Mar 10, 2025
6eb494a
added conveneient macros to ease out reactions definition inside reactor
OmerMajNition Mar 10, 2025
294f2a2
bank index support in ReactionInternals and some more examples ported
OmerMajNition Mar 11, 2025
21a4b65
input to reactor bank input port wiring added
OmerMajNition Mar 11, 2025
5821e42
ported examples and tests to new ReactionInternals design, now reacti…
OmerMajNition Mar 12, 2025
5e1ecf2
fixed compilation issue
OmerMajNition Mar 14, 2025
5927709
ReactionChamber renaming, fix for gcc < 13 compiler versions
OmerMajNition Mar 19, 2025
35ce140
removing the function that would never get hit, gcc < 13 is already f…
OmerMajNition Mar 19, 2025
37055b1
compilation fix for TimePoint cout overload
OmerMajNition Mar 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ configure_file(include/reactor-cpp/config.hh.in include/reactor-cpp/config.hh @O
include(GNUInstallDirs)

add_subdirectory(lib)
add_subdirectory(reactor-sdk)

if(NOT DEFINED LF_REACTOR_CPP_SUFFIX)
add_subdirectory(examples)
endif()
Expand All @@ -71,3 +73,13 @@ if (DEFINED LF_REACTOR_CPP_SUFFIX)
else()
install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
endif()

if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)

add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
21 changes: 21 additions & 0 deletions cmake_uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
endif()

file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
exec_program(
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval
)
if(NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
endif()
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
endif()
endforeach()
1 change: 1 addition & 0 deletions examples/sdk-SrcSink-Fanout/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*build
28 changes: 28 additions & 0 deletions examples/sdk-SrcSink-Fanout/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.9)
project(src_sink_fanout VERSION 0.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard is cached for visibility in external tools." FORCE)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)

set(LF_MAIN_TARGET src_sink_fanout)

find_package(reactor-cpp PATHS )
find_package(reactor-sdk PATHS )

add_executable(${LF_MAIN_TARGET}
main.cc
)

include_directories(${CMAKE_CURRENT_LIST_DIR})

target_link_libraries(${LF_MAIN_TARGET} reactor-cpp)
target_link_libraries(${LF_MAIN_TARGET} reactor-sdk)

target_compile_options(${LF_MAIN_TARGET} PRIVATE -Wall -Wextra -pedantic)

include(Sink/SinkReactor.cmake)
include(Source/SourceReactor.cmake)
include(Main/MainReactor.cmake)
include(Config-a/Config-a.cmake)
17 changes: 17 additions & 0 deletions examples/sdk-SrcSink-Fanout/Config-a/Config-a.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "Config-a.hh"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make a folder for all the sdk stuff:

/examples/sdk/SrcSinkFanout/ConfigA/ConfigA.cc


UserParameters cfg_parameters;

ConfigParameter<int, uint32_t>::ParametersMap UserParameters::homogeneous_config() {
return {
{"Main.Source.iterations", ConfigParameterMetadata<int> { 5 } }
};
}

ConfigParameter<int, uint32_t>::ParametersMap UserParameters::heterogeneous_config() {
return {
{"Main.Source.iterations", ConfigParameterMetadata<int> { 20 } },
{"Main.Sink.n_ports", ConfigParameterMetadata<int> { 2 } }

};
}
16 changes: 16 additions & 0 deletions examples/sdk-SrcSink-Fanout/Config-a/Config-a.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include_directories(${CMAKE_CURRENT_LIST_DIR})

set(INCLUDE_FILES
"${CMAKE_CURRENT_LIST_DIR}/Config-a.hh"
)

set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/Config-a.cc"
)


foreach(file IN LISTS INCLUDE_FILES)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${file}")
endforeach()

target_sources(${LF_MAIN_TARGET} PRIVATE ${SOURCE_FILES})
18 changes: 18 additions & 0 deletions examples/sdk-SrcSink-Fanout/Config-a/Config-a.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef USER_PARAMETERS_H
#define USER_PARAMETERS_H

#include <reactor-sdk/reactor-sdk.hh>
#include <map>
#include <variant>
#include <string>

using namespace sdk;

struct UserParameters : public ConfigParameter<int, uint32_t> {
ConfigParameter<int, uint32_t>::ParametersMap homogeneous_config();
ConfigParameter<int, uint32_t>::ParametersMap heterogeneous_config();
};

extern UserParameters cfg_parameters;

#endif // USER_PARAMETERS_H
27 changes: 27 additions & 0 deletions examples/sdk-SrcSink-Fanout/Main/MainReactor.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "MainReactor.hh"

void MainReactor::construction() {

cout << "Construction Main\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you overload cout? or did I miss the using namespace std ?


src = std::make_unique<SourceReactor>("Source", this);
snk = std::make_unique<SinkReactor>("Sink", this);
}

void MainReactor::assembling() {
cout << "Assembling Main\n";

src->req -->> snk->req;
snk->rsp --> src->rsp;

reaction("reaction_1").
triggers(&startup).
dependencies().
effects().
function(
[&](Startup& startup) {
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
"Starting up reaction\n" << "Bank:" << bank_index << " name:" << parameters.alias.value << " fqn:" << fqn() << endl;
}
);
}
16 changes: 16 additions & 0 deletions examples/sdk-SrcSink-Fanout/Main/MainReactor.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include_directories(${CMAKE_CURRENT_LIST_DIR})

set(INCLUDE_FILES
"${CMAKE_CURRENT_LIST_DIR}/MainReactor.hh"
)

set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/MainReactor.cc"
)


foreach(file IN LISTS INCLUDE_FILES)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${file}")
endforeach()

target_sources(${LF_MAIN_TARGET} PRIVATE ${SOURCE_FILES})
37 changes: 37 additions & 0 deletions examples/sdk-SrcSink-Fanout/Main/MainReactor.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <reactor-sdk/reactor-sdk.hh>

#include "Source/SourceReactor.hh"
#include "Sink/SinkReactor.hh"

using namespace sdk;

class MainReactor: public Reactor {
public:
struct Parameters : public SystemParameter<string> {
REACTOR_PARAMETER (string, alias, "Alternate name", "another", "another", "Src-Sink-Fanout-Example");

Parameters(Reactor *container)
: SystemParameter<string>(container) {
register_parameters (alias);
}
};

private:
Parameters parameters{this};

std::unique_ptr<SourceReactor> src;
std::unique_ptr<SinkReactor> snk;

public:
MainReactor(const std::string &name, Environment *env)
: Reactor(name, env) {}
MainReactor(const std::string &name, Reactor *container)
: Reactor(name, container) {}

void construction() override;
void assembling() override;
};


44 changes: 44 additions & 0 deletions examples/sdk-SrcSink-Fanout/Sink/SinkReactor.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "SinkReactor.hh"
using namespace std;

void SinkReactor::construction() {
cout << "Construction Sink n_ports:" << parameters.n_ports.value << "\n";
req.set_width (parameters.n_ports.value);
rsp.set_width (parameters.n_ports.value);
}

void SinkReactor::assembling() {

cout << "Assembling Sink\n";

reaction("startup_reaction").
triggers(&startup).
dependencies().
effects().
function(pass_function(startup_reaction)
);

reaction("process_request").
triggers(&req).
dependencies().
effects(&rsp).
function(pass_function(process_request)
);
}



void SinkReactor::startup_reaction (Startup& startup) {
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
"Starting up reaction\n" << "Bank:" << bank_index << " name:" << parameters.name.value << " fqn:" << fqn() << endl;
}

void SinkReactor::process_request (MultiportInput<int>& req, MultiportOutput<int>& rsp) {
for (int i = 0; i < parameters.n_ports.value; ++i) {
if (req[i].is_present()) {
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
"Received input:" << *req[i].get() << " port:" << i << endl;
rsp[i].set (*req[i].get());
}
}
}
14 changes: 14 additions & 0 deletions examples/sdk-SrcSink-Fanout/Sink/SinkReactor.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
set(INCLUDE_FILES
"${CMAKE_CURRENT_LIST_DIR}/SinkReactor.hh"
)

set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/SinkReactor.cc"
)


foreach(file IN LISTS INCLUDE_FILES)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${file}")
endforeach()

target_sources(${LF_MAIN_TARGET} PRIVATE ${SOURCE_FILES})
34 changes: 34 additions & 0 deletions examples/sdk-SrcSink-Fanout/Sink/SinkReactor.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <reactor-sdk/reactor-sdk.hh>
using namespace std;
using namespace sdk;

class SinkReactor : public Reactor {
public:
struct Parameters : public SystemParameter<string, int> {
REACTOR_PARAMETER (string, name, "Alternate name", "Sink", "Sink", "Sink");
REACTOR_PARAMETER (int, n_ports, "Size of multiports", 1, 10, 1);

Parameters(Reactor *container)
: SystemParameter<string, int>(container) {
register_parameters (name, n_ports);
}
};

SinkReactor(const std::string &name, Environment *env)
: Reactor(name, env) {}
SinkReactor(const std::string &name, Reactor *container)
: Reactor(name, container) {}

Parameters parameters{this};

MultiportInput<int> req{"req", this};
MultiportOutput<int> rsp{"rsp", this};

void construction() override;
void assembling() override;

void startup_reaction (Startup &startup);
void process_request (MultiportInput<int>& req, MultiportOutput<int>& rsp);
};
58 changes: 58 additions & 0 deletions examples/sdk-SrcSink-Fanout/Source/SourceReactor.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

#include "SourceReactor.hh"
using namespace std;

void SourceReactor::construction() {

cout << "Construction Source iterations:" << parameters.iterations.value << "\n";
}

void SourceReactor::assembling() {
cout << "Assembling Source iterations:" << parameters.iterations.value << "\n";
reaction("reaction_1").
triggers(&startup).
dependencies().
effects(&sch).
function(
[&](Startup& startup, LogicalAction<int>& sched) {
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
"Starting up reaction\n" << "Bank:" << bank_index << " name:" << name << " fqn:" << fqn() << " iterations:" << parameters.iterations.value << endl;
if (itr < parameters.iterations.value) {
sched.schedule (itr, 0ms);
++itr;
}
}
);

reaction("reaction_2").
triggers(&sch).
dependencies().
effects(&req).
function(
[&](LogicalAction<int>& sch, Output<int>& req) {
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
"Scheduling iteration:" << *sch.get() << endl;
req.set (*sch.get());
}
);

reaction("reaction_3").
triggers(&rsp).
dependencies().
effects(&sch).
function(
[&](Input<int>& rsp, LogicalAction<int>& sch) {
if (rsp.is_present()) {
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
"Recevied response:" << *rsp.get() << endl;
}

if (itr < parameters.iterations.value) {
sch.schedule (itr, 0ms);
++itr;
} else {
request_stop();
}
}
);
}
13 changes: 13 additions & 0 deletions examples/sdk-SrcSink-Fanout/Source/SourceReactor.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set(INCLUDE_FILES
"${CMAKE_CURRENT_LIST_DIR}/SourceReactor.hh"
)

set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/SourceReactor.cc"
)

foreach(file IN LISTS INCLUDE_FILES)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${file}")
endforeach()

target_sources(${LF_MAIN_TARGET} PRIVATE ${SOURCE_FILES})
Loading
Loading