Hello everyone,
I am having difficulties compiling Thrust example on streams.
I am using CUDA 8 with Thrust upgraded to 1.8.1, but I cannot compile this example, found in thrust\system\cuda\execution_policy.h
#include <thrust/for_each.h>
#include <thrust/system/cuda/execution_policy.h>
struct printf_functor
{
cudaStream_t s;
printf_functor(cudaStream_t s) : s(s) {}
__host__ __device__
void operator()(int)
{
printf("Hello, world from stream %p\n", static_cast<void*>(s));
}
};
int main()
{
// create two CUDA streams
cudaStream_t s1, s2;
cudaStreamCreate(&s1);
cudaStreamCreate(&s2);
thrust::counting_iterator<int> iter(0);
// execute for_each on two different streams
thrust::for_each(thrust::cuda::par(s1), iter, iter + 1, printf_functor(s1));
thrust::for_each(thrust::cuda::par(s2), iter, iter + 1, printf_functor(s2));
// synchronize with both streams
cudaStreamSynchronize(s1);
cudaStreamSynchronize(s2);
// destroy streams
cudaStreamDestroy(s1);
cudaStreamDestroy(s2);
return 0;
}
The problem is that thrust::cuda::par cannot take stream as argument, compiler (VS2012 x64) for lines 27 and 28 says “error : no instance of function template “thrust::system::cuda::detail::par_t::operator()” matches the argument list, argument types are: (cudaStream_t), object type is: const thrust::system::cuda::detail::par_t”
Compilation via CMAKE as
CUDA_ADD_LIBRARY(${MY_MODULE_NAME} SHARED ${SRC_CUDA_MY_MODULE} OPTIONS -DTHRUSTSORT_BUILD;--use_fast_math;-arch=compute_30)
(yes its built like lib, but I’ve just commented out my code and placed the example instead, just to test whether it compiles or not)
when I create a .cpp file with the same code, the error in VS2012 is as follows: error C2893: Failed to specialize function template ‘thrust::detail::enable_if<thrust::detail::is_allocator::value,thrust::detail::execute_with_allocator<Allocator,thrust::system::cuda::detail::execute_on_stream_base>>::type thrust::system::cuda::detail::par_t::operator ()(Allocator &) const’ With the following template arguments: ‘cudaStream_t’
What am I doing wrong?
Thanks for any help