Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions phlex/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cet_make_library(
declared_output.cpp
declared_predicate.cpp
declared_transform.cpp
declared_translator.cpp
declared_unfold.cpp
detail/filter_impl.cpp
detail/make_algorithm_name.cpp
Expand Down Expand Up @@ -49,6 +50,7 @@ install(
declared_output.hpp
declared_predicate.hpp
declared_transform.hpp
declared_translator.hpp
declared_unfold.hpp
fold_join_node.hpp
fold_node.hpp
Expand Down Expand Up @@ -76,6 +78,7 @@ install(
resource_api.hpp
source.hpp
transform_node.hpp
translator_node.hpp
unfold_node.hpp
upstream_predicates.hpp
DESTINATION include/phlex/core
Expand Down
12 changes: 12 additions & 0 deletions phlex/core/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ namespace phlex::detail {
template <typename T>
concept sendable = requires { typename phlex::experimental::sendable_type<T>; };

template <typename T, std::size_t N>
concept exactly_n_input_parameters = number_parameters<T> == N;

template <typename T>
concept exactly_one_input_parameter = exactly_n_input_parameters<T, 1>;

template <typename T, std::size_t N>
concept at_least_n_input_parameters = number_parameters<T> >= N;

Expand All @@ -29,6 +35,9 @@ namespace phlex::detail {
template <typename T>
concept at_least_two_input_parameters = at_least_n_input_parameters<T, 2>;

template <typename T>
concept exactly_one_output_object = number_output_objects<T> == 1ull;

template <typename T>
concept at_least_one_output_object = number_output_objects<T> >= 1ull;

Expand Down Expand Up @@ -73,6 +82,9 @@ namespace phlex::detail {

template <typename T>
concept is_transform_like = at_least_one_input_parameter<T> && at_least_one_output_object<T>;

template <typename T>
concept is_translator_like = exactly_one_input_parameter<T> && exactly_one_output_object<T>;
}

#endif // PHLEX_CORE_CONCEPTS_HPP
25 changes: 25 additions & 0 deletions phlex/core/declared_translator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "phlex/core/declared_translator.hpp"

#include "phlex/core/products_consumer.hpp"

#include <oneapi/tbb/flow_graph.h>

#include <string>
#include <utility>
#include <vector>

namespace phlex::detail {
declared_translator::declared_translator(phlex::experimental::algorithm_name name,
std::vector<std::string> predicates,
product_selectors input_products,
tbb::flow::graph& graph) :
products_consumer{std::move(name),
std::move(predicates),
std::move(input_products),
graph,
require_layers::multi_input_only}
{
}

declared_translator::~declared_translator() = default;
}
41 changes: 41 additions & 0 deletions phlex/core/declared_translator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef PHLEX_CORE_DECLARED_TRANSLATOR_HPP
#define PHLEX_CORE_DECLARED_TRANSLATOR_HPP

#include "phlex/core/producer.hpp"
#include "phlex/core/product_selector.hpp"
#include "phlex/core/products_consumer.hpp"
#include "phlex/model/algorithm_name.hpp"
#include "phlex/phlex_core_export.hpp"
#include "phlex/utilities/simple_ptr_map.hpp"

#include <oneapi/tbb/flow_graph.h>

#include <cstddef>
#include <memory>
#include <string>
#include <vector>

namespace phlex::detail {

class PHLEX_CORE_EXPORT declared_translator : public products_consumer, public producer {
public:
declared_translator(phlex::experimental::algorithm_name name,
std::vector<std::string> predicates,
product_selectors input_products,
tbb::flow::graph& graph);
~declared_translator() override;

phlex::experimental::algorithm_name const& name() const noexcept override
{
return products_consumer::name();
}

virtual std::size_t product_count() const = 0;
};

using declared_translator_ptr = std::unique_ptr<declared_translator>;
using declared_translators = simple_ptr_map<declared_translator_ptr>;

}

#endif // PHLEX_CORE_DECLARED_TRANSLATOR_HPP
1 change: 1 addition & 0 deletions phlex/core/framework_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ namespace phlex::detail {
filters_.merge(internal_edges_for_predicates(graph_, nodes_.predicates, nodes_.folds));
filters_.merge(internal_edges_for_predicates(graph_, nodes_.predicates, nodes_.unfolds));
filters_.merge(internal_edges_for_predicates(graph_, nodes_.predicates, nodes_.transforms));
filters_.merge(internal_edges_for_predicates(graph_, nodes_.predicates, nodes_.translators));
}

void framework_graph::make_bookkeeping_edges()
Expand Down
7 changes: 7 additions & 0 deletions phlex/core/framework_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ namespace phlex::detail {
return make_glue().transform(name, std::move(f), c);
}

auto translate(std::string_view name,
is_translator_like auto f,
concurrency c = concurrency::serial)
{
return make_glue().translate(name, std::move(f), c);
}

auto provide(std::string_view name, auto f, concurrency c = concurrency::serial)
{
return make_glue().provide(name, std::move(f), c);
Expand Down
21 changes: 21 additions & 0 deletions phlex/core/glue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "phlex/core/resource_api.hpp"
#include "phlex/core/source.hpp"
#include "phlex/core/transform_node.hpp"
#include "phlex/core/translator_node.hpp"
#include "phlex/metaprogramming/delegate.hpp"
#include "phlex/phlex_core_export.hpp"

Expand Down Expand Up @@ -146,6 +147,26 @@ namespace phlex::detail {
resources_);
}

// 'f' is a by-value sink: it is moved into algorithm_bits. The clang-tidy
// warning to take it by const reference is a false positive.
template <typename FT>
auto translate(std::string_view name,
FT f, // NOLINT(performance-unnecessary-value-param)
concurrency c)
{
internal::verify_name(name, config_);
return make_registration<translator_node, declared_translator_ptr>(
config_,
name,
stage_,
algorithm_bits{bound_obj_, std::move(f)},
c,
graph_,
nodes_,
errors_,
resources_);
}

// 'f' is a by-value sink: it is moved into algorithm_bits. The clang-tidy
// warning to take it by const reference is a false positive.
template <typename FT>
Expand Down
13 changes: 13 additions & 0 deletions phlex/core/graph_proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ namespace phlex::detail {
is_transform_like auto f, // NOLINT(performance-unnecessary-value-param)
concurrency c = concurrency::serial) const;

/// @brief Registers a translator node.
auto translate(std::string_view name,
is_translator_like auto f, // NOLINT(performance-unnecessary-value-param)
concurrency c = concurrency::serial) const;

/// @brief Registers an unfold node.
template <typename Unfolder>
auto unfold(std::string_view name,
Expand Down Expand Up @@ -211,6 +216,14 @@ namespace phlex::detail {
return create_glue().transform(name, std::move(f), c);
}

template <typename T>
auto graph_proxy<T>::translate(std::string_view name,
is_translator_like auto f,
concurrency c) const
{
return create_glue().translate(name, std::move(f), c);
}

template <typename T>
template <typename Unfolder>
auto graph_proxy<T>::unfold(std::string_view name,
Expand Down
5 changes: 5 additions & 0 deletions phlex/core/node_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace phlex::detail {
result.append_range(as_product_consumers(folds));
result.append_range(as_product_consumers(unfolds));
result.append_range(as_product_consumers(transforms));
result.append_range(as_product_consumers(translators));
return result;
}

Expand All @@ -51,6 +52,9 @@ namespace phlex::detail {
if (auto* node = transforms.get(node_name)) {
return node->num_calls();
}
if (auto* node = translators.get(node_name)) {
return node->num_calls();
}
if (auto* node = providers.get(node_name)) {
return node->num_calls();
}
Expand All @@ -69,6 +73,7 @@ namespace phlex::detail {

std::vector<producer*> result;
result.append_range(as_producers(transforms));
result.append_range(as_producers(translators));
result.append_range(as_producers(folds));
result.append_range(as_producers(unfolds));
return producer_catalog{result};
Expand Down
8 changes: 6 additions & 2 deletions phlex/core/node_catalog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "phlex/core/declared_output.hpp"
#include "phlex/core/declared_predicate.hpp"
#include "phlex/core/declared_transform.hpp"
#include "phlex/core/declared_translator.hpp"
#include "phlex/core/declared_unfold.hpp"
#include "phlex/core/producer_catalog.hpp"
#include "phlex/core/products_consumer.hpp"
Expand All @@ -23,7 +24,7 @@ namespace phlex::detail {
// A node_catalog is the framework_graph's registry of all the algorithm nodes
// that make up a Phlex data-processing application. It holds every kind of
// node the framework knows about (predicates, observers, outputs, folds,
// unfolds, transforms, and providers), grouped by type, and serves
// unfolds, transforms, translators, and providers), grouped by type, and serves
// as the single source of node information used to build and run the flow
// graph. It also holds the sources, which are factories for creating provider
// nodes.
Expand Down Expand Up @@ -52,7 +53,7 @@ namespace phlex::detail {
// There are three insertion paths, all of which ultimately insert a node
// into one of the simple_ptr_map members:
//
// 1. Algorithm registration (transform, predicate, observe, fold,
// 1. Algorithm registration (transform, translate, predicate, observe, fold,
// unfold, provide, output): Each declaration creates a short-lived
// *_api builder holding a registrar bound to the appropriate map (see
// registrar_for()). For all but output nodes, the registrar's
Expand Down Expand Up @@ -111,6 +112,7 @@ namespace phlex::detail {
simple_ptr_map<declared_fold_ptr> folds;
simple_ptr_map<declared_unfold_ptr> unfolds;
simple_ptr_map<declared_transform_ptr> transforms;
simple_ptr_map<declared_translator_ptr> translators;
simple_ptr_map<provider_node_ptr> providers;
simple_ptr_map<source_ptr> sources;

Expand All @@ -134,6 +136,8 @@ namespace phlex::detail {
return unfolds;
} else if constexpr (std::is_same_v<Ptr, declared_transform_ptr>) {
return transforms;
} else if constexpr (std::is_same_v<Ptr, declared_translator_ptr>) {
return translators;
} else if constexpr (std::is_same_v<Ptr, provider_node_ptr>) {
return providers;
} else if constexpr (std::is_same_v<Ptr, source_ptr>) {
Expand Down
1 change: 1 addition & 0 deletions phlex/core/registration_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "phlex/core/predicate_node.hpp"
#include "phlex/core/resource_api.hpp"
#include "phlex/core/transform_node.hpp"
#include "phlex/core/translator_node.hpp"
#include "phlex/core/unfold_node.hpp"
#include "phlex/core/upstream_predicates.hpp"
#include "phlex/metaprogramming/delegate.hpp"
Expand Down
Loading
Loading