Skip to content
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

Implement Policies #218

Closed
wants to merge 13 commits into from
Closed

Conversation

devreal
Copy link
Contributor

@devreal devreal commented Feb 15, 2022

Policies are a mechanism to steer the execution of tasks through a single entity controlling different properties. The interface is extensible to allow for the addition of future properties without breaking backwards compatibility. If desired, providing a custom policy allows the compiler to fully inline all calls and thus avoid a bunch of indirect calls through std::function. This is useful for small tasks and allows us to reduce the overhead of querying these properties.

Currently, three properties are supported:

  1. Process map (aka keymap): map a key identifying a task to a process for execution. Implemented using the int procmap(const Key&) member.
  2. Priority map: map a key identifying a task to a priority. Implemented using the int priomap(const Key&) member.
  3. Inline map: map a key identifying a task to a max depth for inlining. Implemented using the int inlinemap(const Key&) member. This has yet to be implemented in the backends.

Policies can be specified in two ways:

  1. Using make_policy() to work with make_tt. Example:
return ttg::make_tt([](){ /* task function */ }, edges(...), edges(...), 
                ttg::make_policy([](const Key& key){ return key % world.size(); }, 
                                 [](const Key& key){ return key.x; /* priority */}));

Functions are defaulted to make sure that all necessary properties are implemented. A function that is not provided can later be set dynamically on the tt (using tt->set_inlinemap([](const Key&){ return 0; }) in the example above).

  1. Using a custom policy class:
struct MyPolicy : public ttg::TTPolicyBase {
  ttg::World world;
  MyPolicy(ttg::World world)
  : world(world), TTPolicyBase()
  { }
  int procmap(const Key& key) {
    return key % world.size();
  }
};

struct MyTT : ttg::TT<..., MyPolicy>
{
  ...
}

The procmap member function will shadow the procmap member of ttg::TTPolicyBase. Since the TT is templated on the policy, the procmap of MyPolicy is used. There is no need for virtual functions here. Similarly to the above, properties not specified in MyPolicy are defaulted to a std::function and can be set dynamically.

This PR is based on #217 to be able to default the policy type of TT so the diff is bigger than it will be if #217 gets merged.

We cannot pass a std::tuple as template argument as that may cause
ADL problems with std::tuple<void>. The new type ttg::typelist is
a shim wrapper that provides the tuple after the TT has been instantiated.

Also, use existing TT base type definition instead of redefining the base type.

Signed-off-by: Joseph Schuchart <[email protected]>
Signed-off-by: Joseph Schuchart <[email protected]>
Signed-off-by: Joseph Schuchart <[email protected]>
Signed-off-by: Joseph Schuchart <[email protected]>
Signed-off-by: Joseph Schuchart <[email protected]>
Signed-off-by: Joseph Schuchart <[email protected]>
The wrapper base class tries to avoid the indirect function
call if the std::function is not set. It also ensures that all
TTs provide the same functionality around policies.

Signed-off-by: Joseph Schuchart <[email protected]>
Signed-off-by: Joseph Schuchart <[email protected]>
Signed-off-by: Joseph Schuchart <[email protected]>
@devreal
Copy link
Contributor Author

devreal commented Mar 24, 2022

Superseded bu #226, closing

@devreal devreal closed this Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant