Skip to content

Optimization Engine

Mark Johnson edited this page Jul 10, 2018 · 14 revisions

Overview

One of the key components of veho is the CAN node specification optimization engine, a system for taking a set of CAN frame listeners and transforming them into a functionally equivalent set of listeners that is either a) reduced to meet the constraints of the target CAN controller, or b) expanded to make maximal use of the target CAN controller's resources. The engine is split up into several possible stages of optimization, namely preprocessing, normalization, reduction, and expansion.

Each optimization stage is composed of passes, which can be defined as classes with the following structure:

template <typename Controller, typename TypeMap, typename Callbacks>
struct optimization_pass {
    constexpr optimization_pass(Callbacks&& callbacks);

    using pass_category = /*pass tag*/

    using updated_type_map_type = /*type map after optimization pass is ran*/

    using updated_callbacks_type = /*callback set after optimization pass is ran*/

    updated_callbacks_type new_callbacks;
};

An optimization pass must be constructible in a constexpr context, since the listener optimization process takes place entirely at compiletime. In any given optimization pass, the type pass_category must be defined as one of the following tags, in the veho::facet::receiver::optimization namespace:

  • preprocessing_pass_tag
  • normalization_pass_tag
  • reduction_pass_tag
  • expansion_pass_tag

The pass tag used must correspond with the optimization stage the pass is designed to be ran in; for example, a pass in the normalization stage must have a member typedef equivalent to using pass_category = normalization_pass_tag. Lastly, each optimization pass must also produce three results: the type representation of the updated type map, the type representation of the updated callbacks, and the value representation of the updated callbacks.

Preprocessing

The preprocessing stage is designed to ensure that the collection of frame listeners passed through the optimization process is a unique set, which is a necessary precondition for the other optimization stages.

Normalization

The normalization stage takes the set of listeners and ensures that all listeners with overlapping frame selection semantics (i.e. exact frame id matchers within frame id range matchers, frame id range matchers with overlapping ranges, etc.) have their callbacks unified together.

append_range_filter_callback_to_exact_filter_callback_when_exact_within_range_pass

Reduction

condense_closest_exact_filters_to_range_pass

condense_closest_range_filters_to_super_range_pass

extend_range_filter_to_encapsulate_closest_exact_filter_pass

Expansion