Commit a6ab4867 authored by André Anjos's avatar André Anjos 💬

Merge branch 'algorithm_cxx_v2' into 'master'

Algorithm cxx v2

See merge request !37
parents 5c7900bc ac103b42
Pipeline #24397 failed with stages
in 29 minutes and 50 seconds
...@@ -72,7 +72,7 @@ stages: ...@@ -72,7 +72,7 @@ stages:
- ./_ci/install.sh _ci master #updates ci support scripts - ./_ci/install.sh _ci master #updates ci support scripts
- ./_ci/before_build.sh - ./_ci/before_build.sh
- mv conda-bld ${CONDA_ROOT} - mv conda-bld ${CONDA_ROOT}
- ./scripts/before_test.sh - ./scripts/before_test.sh build
script: script:
- export BEAT_DOCKER_TESTS=true - export BEAT_DOCKER_TESTS=true
- BOB_TEST_ONLY=true ./_ci/build.sh - BOB_TEST_ONLY=true ./_ci/build.sh
......
...@@ -393,10 +393,12 @@ class Host(object): ...@@ -393,10 +393,12 @@ class Host(object):
# Mount the volumes # Mount the volumes
cmd.extend(container.volumes) cmd.extend(container.volumes)
# Expose the ports # Expose the ports
cmd.extend(container.ports) cmd.extend(container.ports)
# Environment variables
cmd.extend(container.environment_variables)
cmd.append(container.image) cmd.append(container.image)
cmd.extend(container.command) cmd.extend(container.command)
...@@ -624,6 +626,7 @@ class Container: ...@@ -624,6 +626,7 @@ class Container:
self.id = None self.id = None
self._volumes = {} self._volumes = {}
self._ports = {} self._ports = {}
self._environment_variables = {}
self._stats = None self._stats = None
self._name = None self._name = None
...@@ -670,6 +673,17 @@ class Container: ...@@ -670,6 +673,17 @@ class Container:
self._ports[container_port] = value self._ports[container_port] = value
def add_environment_variable(self, name, value):
"""Add an environment variable
Parameters:
:param str name: Name of the variable
:param str value: Content of the variable
"""
self._environment_variables[name] = value
def reset_ports(self): def reset_ports(self):
"""Empty the port bindings""" """Empty the port bindings"""
...@@ -724,6 +738,17 @@ class Container: ...@@ -724,6 +738,17 @@ class Container:
return ports return ports
@property
def environment_variables(self):
"""Returns the environment variables to set on this container.
"""
environment_variables = []
for k, v in self._environment_variables.items():
environment_variables.append('--env={}={}'.format(k, v))
return environment_variables
@property @property
def network(self): def network(self):
network = '' network = ''
...@@ -753,6 +778,7 @@ class Container: ...@@ -753,6 +778,7 @@ class Container:
cmd += "%s " % self.user cmd += "%s " % self.user
cmd += ' '.join(self.volumes) cmd += ' '.join(self.volumes)
cmd += ' '.join(self.ports) cmd += ' '.join(self.ports)
cmd += ' '.join(self.environment_variables)
cmd += "%s " % self.name cmd += "%s " % self.name
cmd += "%s " % self.image cmd += "%s " % self.image
......
...@@ -380,8 +380,8 @@ class Experiment(object): ...@@ -380,8 +380,8 @@ class Experiment(object):
self.algorithms[algoname] = thisalgo self.algorithms[algoname] = thisalgo
if thisalgo.errors: if thisalgo.errors:
self.errors.append("/analyzers/%s: algorithm `%s' is invalid" % \ self.errors.append("/analyzers/%s: algorithm `%s' is invalid:\n%s" % \
(analyzername, algoname)) (analyzername, algoname, "\n".join(thisalgo.errors)))
continue continue
else: else:
......
{
"language": "cxx",
"groups": [
{
"name": "main",
"inputs": {
"in_data": {
"type": "user/single_integer/1"
}
}
}
],
"results": {
"out_data": {
"type": "int32",
"display": false
}
}
}
cmake_minimum_required(VERSION 3.0)
project(BEAT_CORE_CXX_INTEGERS_ANALYZER)
set(BEAT_BACKEND_CXX_DIR "/usr/local/beat")
# CMake setup
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if (COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif (COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
# Retrieve the dependencies
find_package(Boost REQUIRED)
# Setup the search paths
include_directories(
"${BEAT_BACKEND_CXX_DIR}/include"
"${Boost_INCLUDE_DIRS}"
)
link_directories(
"${BEAT_BACKEND_CXX_DIR}/bin"
)
# List the source files
set(HEADERS "algorithm.h"
"beat_setup.h"
"user_single_integer_1.h"
)
set(SRCS "algorithm.cpp"
"beat_setup.cpp"
"user_single_integer_1.cpp"
)
# Create and link the library
add_library(cxx_integers_echo_analyzer SHARED ${SRCS} ${HEADERS})
target_link_libraries(cxx_integers_echo_analyzer beat_backend_cxx)
set_target_properties(cxx_integers_echo_analyzer PROPERTIES
COMPILE_FLAGS "-fPIC"
OUTPUT_NAME "1"
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${BEAT_CORE_CXX_INTEGERS_ECHO_ANALYZER_SOURCE_DIR}"
)
// NOTE: This file implements the algorithm declared in the file
// 'user/cxx_integers_echo/1.json'
#include "algorithm.h"
#include "beat.backend.cxx/input.h"
#include "beat.backend.cxx/inputlist.h"
#include "beat.backend.cxx/outputlist.h"
#include "beat.backend.cxx/dataloader.h"
#include "user_single_integer_1.h"
using namespace beat::backend::cxx;
Algorithm::Algorithm()
{
}
//---------------------------------------------------------
Algorithm::~Algorithm()
{
}
//---------------------------------------------------------
bool Algorithm::setup(const json& parameters)
{
return true;
}
//---------------------------------------------------------
bool Algorithm::prepare(const DataLoaderList& data_load_list)
{
return true;
}
//---------------------------------------------------------
bool Algorithm::process(const InputList& inputs,
const DataLoaderList& data_load_list,
const OutputList& outputs)
{
auto data = inputs["in_data"]->data<dataformats::user::single_integer_1>();
outputs["out_data"]->write(data);
return true;
}
//---------------------------------------------------------
IAlgorithm* create_algorithm()
{
return new Algorithm();
}
// NOTE: This file implements the algorithm declared in the file
// 'user/cxx_integers_echo/1.json'
#ifndef _BEAT_GENERATED_ALGORITHM_H_
#define _BEAT_GENERATED_ALGORITHM_H_
#include <beat.backend.cxx/algorithm.h>
class Algorithm: public beat::backend::cxx::IAlgorithmSequential
{
public:
Algorithm();
virtual ~Algorithm();
bool setup(const json& parameters) override;
bool prepare(const beat::backend::cxx::DataLoaderList& data_load_list) override;
bool process(const beat::backend::cxx::InputList& inputs,
const beat::backend::cxx::DataLoaderList& data_load_list,
const beat::backend::cxx::OutputList& outputs) override;
};
extern "C" {
beat::backend::cxx::IAlgorithm* create_algorithm();
}
#endif
// NOTE: This file was automatically generated from the algorithm declaration file
// 'user/cxx_integers_echo/1.json'
#include <beat.backend.cxx/dataformatfactory.h>
#include "beat_setup.h"
#include "user_single_integer_1.h"
using namespace beat::backend::cxx;
void setup_beat_cxx_module()
{
DataFormatFactory* factory = DataFormatFactory::getInstance();
factory->registerDataFormat<dataformats::user::single_integer_1>();
}
// NOTE: This file was automatically generated from the algorithm declaration file
// 'user/cxx_integers_echo/1.json'
#ifndef _BEAT_SETUP_H_
#define _BEAT_SETUP_H_
extern "C" {
void setup_beat_cxx_module();
}
#endif
// NOTE: This file was automatically generated from the dataformat declaration file
// 'user/single_integer/1.json'
#include "user_single_integer_1.h"
#include <beat.backend.cxx/dataformatfactory.h>
using namespace beat::backend::cxx;
dataformats::user::single_integer_1::single_integer_1()
{
}
//---------------------------------------------------------
size_t dataformats::user::single_integer_1::fixed_size()
{
return sizeof(int32_t);
}
//---------------------------------------------------------
size_t dataformats::user::single_integer_1::size() const
{
return dataformats::user::single_integer_1::fixed_size();
}
//---------------------------------------------------------
void dataformats::user::single_integer_1::pack(uint8_t** buffer) const
{
beat::backend::cxx::pack(value, buffer);
}
//---------------------------------------------------------
void dataformats::user::single_integer_1::unpack(uint8_t** buffer)
{
value = beat::backend::cxx::unpack_scalar<int32_t>(buffer);
}
//---------------------------------------------------------
Data* dataformats::user::single_integer_1::create()
{
return new user::single_integer_1();
}
//---------------------------------------------------------
const char *dataformats::user::single_integer_1::getNameStatic()
{
return "user/single_integer/1";
}
//---------------------------------------------------------
std::string dataformats::user::single_integer_1::toJson() const
{
return "{"
"\"field\":\"int32_t\""
"}";
}
// NOTE: This file was automatically generated from the dataformat declaration file
// 'user/single_integer/1.json'
#ifndef _BEAT_GENERATED_user_single_integer_1_H_
#define _BEAT_GENERATED_user_single_integer_1_H_
#include <beat.backend.cxx/data.h>
namespace dataformats {
namespace user {
class single_integer_1: public beat::backend::cxx::DataImpl<single_integer_1>
{
public:
single_integer_1();
static size_t fixed_size();
size_t size() const override;
void pack(uint8_t** buffer) const override;
void unpack(uint8_t** buffer) override;
static Data* create();
static const char *getNameStatic();
std::string toJson() const override;
public:
int32_t value;
};
} // user
} // dataformats
#endif
{
"schema_version": 2,
"language": "cxx",
"api_version": 2,
"type": "autonomous",
"splittable": true,
"groups": [
{
"name": "main",
"inputs": {
"in_data": {
"type": "user/single_integer/1"
}
},
"outputs": {
"out_data": {
"type": "user/single_integer/1"
}
}
}
]
}
cmake_minimum_required(VERSION 3.0)
project(BEAT_CORE_CXX_INTEGERS_ECHO_AUTONOMOUS)
set(BEAT_BACKEND_CXX_DIR "/usr/local/beat")
# CMake setup
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if (COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif (COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
# Retrieve the dependencies
find_package(Boost REQUIRED)
# Setup the search paths
include_directories(
"${BEAT_BACKEND_CXX_DIR}/include"
"${Boost_INCLUDE_DIRS}"
)
link_directories(
"${BEAT_BACKEND_CXX_DIR}/bin"
)
# List the source files
set(HEADERS "algorithm.h"
"beat_setup.h"
"user_single_integer_1.h"
)
set(SRCS "algorithm.cpp"
"beat_setup.cpp"
"user_single_integer_1.cpp"
)
# Create and link the library
add_library(cxx_integers_echo_autonomous SHARED ${SRCS} ${HEADERS})
target_link_libraries(cxx_integers_echo_autonomous beat_backend_cxx)
set_target_properties(cxx_integers_echo_autonomous PROPERTIES
COMPILE_FLAGS "-fPIC"
OUTPUT_NAME "1"
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${BEAT_CORE_CXX_INTEGERS_ECHO_AUTONOMOUS_SOURCE_DIR}"
)
// NOTE: This file implements the algorithm declared in the file
// 'user/cxx_integers_echo/1.json'
#include "algorithm.h"
#include "beat.backend.cxx/outputlist.h"
#include "beat.backend.cxx/dataloader.h"
#include "user_single_integer_1.h"
#include <iostream>
using namespace beat::backend::cxx;
Algorithm::Algorithm()
{
}
//---------------------------------------------------------
Algorithm::~Algorithm()
{
}
//---------------------------------------------------------
bool Algorithm::setup(const json& parameters)
{
return true;
}
//---------------------------------------------------------
bool Algorithm::prepare(const DataLoaderList& data_load_list)
{
return true;
}
//---------------------------------------------------------
bool Algorithm::process(const DataLoaderList& data_load_list, const OutputList& outputs)
{
auto data_loader = data_load_list.loader_of("in_data");
std::map<std::string, beat::backend::cxx::Data *> data;
int64_t start = -1;
int64_t end = -1;
for (int i = 0 ; i < data_loader->count() ; ++i) {
std::tie(data, start, end) = (*data_loader)[i];
auto value = static_cast<dataformats::user::single_integer_1*>(data["in_data"]);
outputs["out_data"]->write(value);
}
return true;
}
//---------------------------------------------------------
IAlgorithm* create_algorithm()
{
return new Algorithm();
}
// NOTE: This file implements the algorithm declared in the file
// 'user/cxx_integers_echo/1.json'
#ifndef _BEAT_GENERATED_ALGORITHM_H_
#define _BEAT_GENERATED_ALGORITHM_H_
#include <beat.backend.cxx/algorithm.h>
class Algorithm: public beat::backend::cxx::IAlgorithmAutonomous
{
public:
Algorithm();
virtual ~Algorithm();
bool setup(const json& parameters) override;
bool prepare(const beat::backend::cxx::DataLoaderList& data_load_list) override;
bool process(const beat::backend::cxx::DataLoaderList& data_load_list,
const beat::backend::cxx::OutputList& outputs) override;
};
extern "C" {
beat::backend::cxx::IAlgorithm* create_algorithm();
}
#endif
// NOTE: This file was automatically generated from the algorithm declaration file
// 'user/cxx_integers_echo/1.json'
#include <beat.backend.cxx/dataformatfactory.h>
#include "beat_setup.h"
#include "user_single_integer_1.h"
using namespace beat::backend::cxx;
void setup_beat_cxx_module()
{
DataFormatFactory* factory = DataFormatFactory::getInstance();
factory->registerDataFormat<dataformats::user::single_integer_1>();
}
// NOTE: This file was automatically generated from the algorithm declaration file
// 'user/cxx_integers_echo/1.json'
#ifndef _BEAT_SETUP_H_
#define _BEAT_SETUP_H_
extern "C" {
void setup_beat_cxx_module();
}
#endif
// NOTE: This file was automatically generated from the dataformat declaration file
// 'user/single_integer/1.json'
#include "user_single_integer_1.h"
#include <beat.backend.cxx/dataformatfactory.h>
using namespace beat::backend::cxx;
dataformats::user::single_integer_1::single_integer_1()
{
}
//---------------------------------------------------------
size_t dataformats::user::single_integer_1::fixed_size()
{
return sizeof(int32_t);
}
//---------------------------------------------------------
size_t dataformats::user::single_integer_1::size() const
{
return dataformats::user::single_integer_1::fixed_size();
}
//---------------------------------------------------------
void dataformats::user::single_integer_1::pack(uint8_t** buffer) const
{
beat::backend::cxx::pack(value, buffer);
}
//---------------------------------------------------------
void dataformats::user::single_integer_1::unpack(uint8_t** buffer)
{
value = beat::backend::cxx::unpack_scalar<int32_t>(buffer);
}
//---------------------------------------------------------
Data* dataformats::user::single_integer_1::create()
{
return new user::single_integer_1();
}
//---------------------------------------------------------
const char *dataformats::user::single_integer_1::getNameStatic()
{
return "user/single_integer/1";
}
//---------------------------------------------------------