In the program I am writing right now I want use either GPU or CPU to compute (for benchmarking one against other). To do this I would like to have some universal pointer which I could initialize with an instance of device_vector or host_vector like this:
ptr = new host_vector<float>();
or
ptr = new device_vector<float>();
Both host_vector and device_vector inherit from detail::vector_base but I can't use a pointer of detail::vector_base because vector_base (which means device_vector and host_vector too) is a template class where template has two arguments - the type it contains and the allocator it uses. Both kinds of vectors use different allocators, which in turn means two different pointers.
Is there any way to define ptr so I can use it like in my examples?
I ended up combining @Michael Haidl 's and @Robert Crovella 's (and by proxy @talonmies ') suggestions to create a class (called it "UnifiedVector") which has two specializations based on a non-type parameter enum (ComputeMethod::GPU, ComputeMethod::CPU).
In one specialization UnifiedVector inherits host_vector and in the other device_vector. Then I template the classes that use UnifiedVector using the same enum so I can use it like that:
template<ComputeMethod C>
class SomeClass
{
private:
UnifiedVector<something,C> data;
}
Not sure how elegant or "right" this approach is, but I guess it'll suffice since it achieves the goal of making the vector "transparent" to the class thah uses it (as in it doesn't have to explicitely treat one kind of vector in different way or hold two pointers for two different possible vector types).