cuda-api-wrappers icon indicating copy to clipboard operation
cuda-api-wrappers copied to clipboard

Drop copy_parameters_t in favor of a nicer copy parameters builder

Open eyalroz opened this issue 1 year ago • 0 comments

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)

eyalroz avatar Mar 16 '24 20:03 eyalroz