quda icon indicating copy to clipboard operation
quda copied to clipboard

Unify Aggregates struct and OrthoAggregates struct via templating

Open bjoo opened this issue 3 years ago • 0 comments

Currently struct Aggregates in restrictor.cu and struct OrthoAggregates in block_orthogonalize.cu are essentially identical. They could be unified using a Tag template. E.g.

in include/powers_of_two_array.h

template<typename Tag, unsigned int Min, unsigned int Max>
struct TaggedAggregate {
     /* stuff here including: */
     using data_type = ...
     static constexpr data_type block = array_type();
    /* .. more stuff */
 };

then in restrictor.cu:

struct AggTag {};
using Aggregates = TaggedAggregate<AggTag, device::warp_size(), device::max_block_size()>;

and in block_orthogonalize.cu:

struct OrthoAggTag {};
using OrthoAggregates = TaggedAggregate<OrthoAggTag, device::warp_size(), device::max_block_size()>;

this would reduce code duplication and reduce boilerplate. The thing stopping me from doing this with C++-14 is to do with in-class initialization of the static member in the class template. The current approach uses outside of class initialization, but currently the Aggregates and BlockAggregates are not templates. Just about every combination of attempting to do the unified approach and initializing out of class that I could think of failed with C++-14. I suspect because of the constexpr keyword? or I am just not smart enough (definitely possible... I am not a huge master of static constexpr array members in templated classes)

bjoo avatar May 13 '21 14:05 bjoo