Support views

Merged Daniel Hugo Campora Perez requested to merge dcampora_idea_view into master

This MR brings the ability to define views to Allen datatypes. A view is a datatype that is linked to the lifetime of other types, and it allows to define a type that relies on others (see #174 (closed) for a more comprehensive example).

Here is a working example:

      Velo::Clusters, dev_velo_cluster_container_t, dev_module_cluster_num_t, dev_number_of_events_t)

The type dev_velo_clusters_t is defined to be of type Velo::Clusters, with its lifetime linked to types dev_velo_cluster_container_t, dev_module_cluster_num_t, dev_number_of_events_t.

This type can be used just like any other type:

  auto velo_cluster_container = Velo::Clusters {parameters.dev_velo_cluster_container, estimated_number_of_clusters};
  parameters.dev_velo_clusters[event_number] = velo_cluster_container;

And subsequent algorithms can request it with no need to specify it as a view anymore:

  DEVICE_INPUT(dev_velo_clusters_t, Velo::Clusters) dev_velo_clusters;

The reason these two types are compatible is because the Allen underlying type of both the view and non-view parameter is Velo::Clusters.

Behind the scenes

Now every parameter has a using deps statement, where dependencies are set. TupleContainsWithView checks whether the tuple contains any parameter or view:

  template<typename T, typename Tuple>
  struct TupleContainsDecay;

  template<typename T, typename... Ts>
  struct TupleContainsDecay<T, std::tuple<Ts...>>
    : std::bool_constant<((std::is_base_of_v<std::decay_t<Ts>, std::decay_t<T>> || ...))> {

  template<typename T, typename Tuple>
  struct TupleContainsWithViews;

  template<typename T>
  struct TupleContainsWithViews<T, std::tuple<>> : std::bool_constant<false> {

  template<typename T, typename OtherT, typename... Ts>
  struct TupleContainsWithViews<T, std::tuple<OtherT, Ts...>>
    : std::bool_constant<
        std::is_same_v<T, OtherT> || TupleContainsWithViews<T, std::tuple<Ts...>>::value ||
        TupleContainsDecay<T, typename OtherT::deps>::value> {

It is also possible to check whether this worked by running ./Allen -p1 and looking at whether the parameter velo_masked_clustering__dev_velo_cluster_container_t is still populated in the device memory, in algorithm search by triplet.

Closes #174 (closed)

Edited by Daniel Hugo Campora Perez

Merge request reports