how to create an appropriate temp vector? #1033
Unanswered
bricerebsamen
asked this question in
Thrust
Replies: 2 comments 1 reply
-
Hello @bricerebsamen! You could try template template parameters to achieve that: template <template <class, class> class VectorT,
template <class> class AllocatorT,
class T>
void foo(VectorT<T, AllocatorT<T>> &vec) {
using vec_t = VectorT<T, AllocatorT<T>>;
vec_t tmp(vec.size() /* size */, 0 /* fill value */);
}
int main() {
{
thrust::host_vector<double> points(100);
foo(points);
}
{
thrust::device_vector<double> points(100);
foo(points);
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
Just FYI, the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
hello
I have a function that uses thrust and does something like this:
As it is, it's designed to work on the GPU only, because it uses a device_vector. So it assumes
points
is a device pointer. How could I modify this function so that it could accept either a device or host vector for points and work on cpu or gpu accordingly.perhaps the new signature could take iterators instead, which would encode "where" the input points are located
related to https://stackoverflow.com/questions/76597522/thrust-execution-policy-with-device-vector
Beta Was this translation helpful? Give feedback.
All reactions