A "policy-based" design for a generic CUDA kernel
Is there a good reason against using the thrust library? It seems to come with the nvcc compiler and provides that kind of functionality:

#include &lt;iostream&gt;
#include &lt;thrust/transform.h&gt;


__device__ __managed__ float x[2], y[2];


template &lt;typename T&gt; struct square {
    __host__ __device__ T operator()(const T&amp; x) const {
        return x * x;
    }
};


int main(int argc, char const *argv[]) {
    x[0] = 1; x[1] = 2;
    thrust::transform(x, x + 2, y, square&lt;float&gt;());
    std::cout &lt;&lt; x[0] &lt;&lt; "**2 = " &lt;&lt; y[0] &lt;&lt; "\n";
    std::cout &lt;&lt; x[1] &lt;&lt; "**2 = " &lt;&lt; y[1];
    return 0;
}