eyalroz / cuda-api-wrappers

Thin, unified, C++-flavored wrappers for the CUDA APIs
BSD 3-Clause "New" or "Revised" License
766 stars 79 forks source link

Drop copy_parameters_t in favor of a nicer copy parameters builder #615

Open eyalroz opened 5 months ago

eyalroz commented 5 months ago

We currently user a builder-ish copy parameters class, which inherits the actual raw copy parameters. But - it involves a lot of code duplication, use of conditional expressions etc. Perhaps it would be better and simpler to have a builder class which doesn't immediately set the actual copy parameters, and is more structured , i.e. something like

struct copy_parameters_builder_t  {
enum end_t { start = 0, end = 1 };
struct endpoint_t = {
    // context, extent, offset, pitch etc. - possibly as optionals
};
endpoint_t endpoints[2];
endpoint_t& start() { return endpoints[end_t::start]; }
endpoint_t& end() { return endpoints[end_t::end]; }
copy_parameters_t build();
}

Then one could write something like my_builder.start().offset = dim3{1, 2, 3}; }

The downside of this design is less one-liners (although we can always add methods to endpoint_t, and make it hold a reference to the containing copy params build, which can be returned from setter methods)