Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用FindCUDA.cmake和带推力装置的推力系统OMP时出现编译错误_Cuda_Cmake_Openmp_Thrust - Fatal编程技术网

使用FindCUDA.cmake和带推力装置的推力系统OMP时出现编译错误

使用FindCUDA.cmake和带推力装置的推力系统OMP时出现编译错误,cuda,cmake,openmp,thrust,Cuda,Cmake,Openmp,Thrust,我最近发现,除了经典的cuda功能外,推力还能够处理自动OMP和TBB并行化 虽然我能够在一个简单的示例中使用这个非常简单的功能,但我的cmake配置生成了编译错误,可能是我使用FindCUDA.cmake的方式不对,或者这个模块不能以这种方式使用 这是我的Test.cu文件: #include <thrust/device_vector.h> #include <cstdio> struct cuda_hello { __host__ __device__ v

我最近发现,除了经典的cuda功能外,推力还能够处理自动OMP和TBB并行化

虽然我能够在一个简单的示例中使用这个非常简单的功能,但我的cmake配置生成了编译错误,可能是我使用FindCUDA.cmake的方式不对,或者这个模块不能以这种方式使用

这是我的Test.cu文件:

#include <thrust/device_vector.h>
#include <cstdio>

struct cuda_hello
{
  __host__ __device__
  void operator()(int x)
  {
    printf("Hello, world from Cuda!\n");
  }
};

int main()
{
    thrust::device_vector<int> cuda_vec(1, 0);
    thrust::for_each(cuda_vec.begin(),cuda_vec.end(),cuda_hello());
}
现在,当使用推力\设备\系统\ OMP(为CC 3.0设备编译)时,无法生成在linux下正确编译的Makefiles的cmakefile:

编译错误的类型为:

/usr/local/cuda/include/thrust/system/omp/detail/for_each.inl(53): error: incomplete type is not allowed
          detected during:
            instantiation of "RandomAccessIterator thrust::system::omp::detail::for_each_n(thrust::system::omp::detail::execution_policy<DerivedPolicy> &, RandomAccessIterator, Size, UnaryFunction) [with DerivedPolicy=thrust::system::omp::detail::tag, RandomAccessIterator=thrust::device_ptr<int>, Size=unsigned long, UnaryFunction=thrust::detail::host_generate_functor<thrust::detail::fill_functor<int>>]" 
/usr/local/cuda/include/thrust/detail/for_each.inl(69): here
            instantiation of "InputIterator thrust::for_each_n(const thrust::detail::execution_policy_base<DerivedPolicy> &, InputIterator, Size, UnaryFunction) [with DerivedPolicy=thrust::system::omp::detail::tag, InputIterator=thrust::device_ptr<int>, Size=unsigned long, UnaryFunction=thrust::detail::host_generate_functor<thrust::detail::fill_functor<int>>]" 
/usr/local/cuda/include/thrust/system/detail/generic/generate.inl(52): here
            instantiation of "OutputIterator thrust::system::detail::generic::generate_n(thrust::execution_policy<ExecutionPolicy> &, OutputIterator, Size, Generator) [with ExecutionPolicy=thrust::system::omp::detail::tag, OutputIterator=thrust::device_ptr<int>, Size=unsigned long, Generator=thrust::detail::fill_functor<int>]" 
/usr/local/cuda/include/thrust/detail/generate.inl(56): here
            instantiation of "OutputIterator thrust::generate_n(const thrust::detail::execution_policy_base<DerivedPolicy> &, OutputIterator, Size, Generator) [with DerivedPolicy=thrust::system::omp::detail::tag, OutputIterator=thrust::device_ptr<int>, Size=unsigned long, Generator=thrust::detail::fill_functor<int>]" 
/usr/local/cuda/include/thrust/system/detail/generic/fill.h(45): here
            instantiation of "OutputIterator thrust::system::detail::generic::fill_n(thrust::execution_policy<DerivedPolicy> &, OutputIterator, Size, const T &) [with DerivedPolicy=thrust::system::omp::detail::tag, OutputIterator=thrust::device_ptr<int>, Size=unsigned long, T=int]" 
/usr/local/cuda/include/thrust/detail/fill.inl(50): here
            [ 6 instantiation contexts not shown ]
            instantiation of "void thrust::detail::contiguous_storage<T, Alloc>::uninitialized_fill_n(thrust::detail::contiguous_storage<T, Alloc>::iterator, thrust::detail::contiguous_storage<T, Alloc>::size_type, const thrust::detail::contiguous_storage<T, Alloc>::value_type &) [with T=int, Alloc=thrust::device_malloc_allocator<int>]" 
/usr/local/cuda/include/thrust/detail/vector_base.inl(164): here
            instantiation of "void thrust::detail::vector_base<T, Alloc>::fill_init(thrust::detail::vector_base<T, Alloc>::size_type, const T &) [with T=int, Alloc=thrust::device_malloc_allocator<int>]" 
/usr/local/cuda/include/thrust/detail/vector_base.inl(139): here
            instantiation of "void thrust::detail::vector_base<T, Alloc>::init_dispatch(IteratorOrIntegralType, IteratorOrIntegralType, thrust::detail::true_type) [with T=int, Alloc=thrust::device_malloc_allocator<int>, IteratorOrIntegralType=int]" 
/usr/local/cuda/include/thrust/detail/vector_base.inl(224): here
            instantiation of "thrust::detail::vector_base<T, Alloc>::vector_base(InputIterator, InputIterator) [with T=int, Alloc=thrust::device_malloc_allocator<int>, InputIterator=int]" 
/usr/local/cuda/include/thrust/device_vector.h(148): here
            instantiation of "thrust::device_vector<T, Alloc>::device_vector(InputIterator, InputIterator) [with T=int, Alloc=thrust::device_malloc_allocator<int>, InputIterator=int]" 


/usr/local/cuda/include/thrust/system/omp/detail/for_each.inl(53): error: incomplete type is not allowed
          detected during:
            instantiation of "RandomAccessIterator thrust::system::omp::detail::for_each_n(thrust::system::omp::detail::execution_policy<DerivedPolicy> &, RandomAccessIterator, Size, UnaryFunction) [with DerivedPolicy=thrust::system::omp::detail::tag, RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, Size=long, UnaryFunction=cuda_hello]" 
(89): here
            instantiation of "RandomAccessIterator thrust::system::omp::detail::for_each(thrust::system::omp::detail::execution_policy<DerivedPolicy> &, RandomAccessIterator, RandomAccessIterator, UnaryFunction) [with DerivedPolicy=thrust::system::omp::detail::tag, RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, UnaryFunction=cuda_hello]" 
/usr/local/cuda/include/thrust/detail/for_each.inl(43): here
            instantiation of "InputIterator thrust::for_each(const thrust::detail::execution_policy_base<DerivedPolicy> &, InputIterator, InputIterator, UnaryFunction) [with DerivedPolicy=thrust::system::omp::detail::tag, InputIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, UnaryFunction=cuda_hello]" 
/usr/local/cuda/include/thrust/detail/for_each.inl(57): here
            instantiation of "InputIterator thrust::for_each(InputIterator, InputIterator, UnaryFunction) [with InputIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, UnaryFunction=cuda_hello]" 


2 errors detected in the compilation of "/tmp/tmpxft_00002d3a_00000000-6_Test.cpp1.ii".
CMake Error at ExecutableCmake_generated_Test.cu.o.cmake:264 (message):
  Error generating file



make[2]: *** [CMakeFiles/ExecutableCmake.dir/./ExecutableCmake_generated_Test.cu.o] Erreur 1
make[1]: *** [CMakeFiles/ExecutableCmake.dir/all] Erreur 2
make: *** [all] Erreur 2
/usr/local/cuda/include/推力/system/omp/detail/for_each.inl(53):错误:不允许类型不完整
在以下期间检测到:
实例化“RandomAccess迭代器推力::系统::omp::细节::for_each_n(推力::系统::omp::细节::执行_policy&,RandomAccess迭代器,大小,UnaryFunction)[使用DerivedPolicy=推力::系统::omp::细节::标记,RandomAccess迭代器=推力::设备_ptr,大小=无符号长,UnaryFunction=推力::细节::主机生成_函子]”
/usr/local/cuda/include/推力/细节/for_each.inl(69):这里
实例化“InputIterator推力::for_each_n(const推力::detail::execution_policy_base&,InputIterator,Size,UnaryFunction)[使用DerivedPolicy=推力::系统::omp::detail::标记,InputIterator=推力::设备_ptr,Size=unsigned long,UnaryFunction=推力::detail::主机生成_函子]”
/usr/local/cuda/include/推力/system/detail/generic/generate.inl(52):这里
实例化“输出迭代器推力::系统::细节::通用::生成\n(推力::执行\u策略&,输出迭代器,大小,生成器)[使用ExecutionPolicy=推力::系统::omp::细节::标记,输出迭代器=推力::设备\u ptr,大小=无符号长,生成器=推力::细节::填充\u函子]”
/usr/local/cuda/include/推力/detail/generate.inl(56):这里
实例化“输出迭代器推力::生成\n(常量推力::细节::执行\u策略\u基和,输出迭代器,大小,生成器)[使用DerivedPolicy=推力::系统::omp::细节::标记,输出迭代器=推力::设备\u ptr,大小=无符号长,生成器=推力::细节::填充\u函子]”
/usr/local/cuda/include/推力/system/detail/generic/fill.h(45):这里
实例化“输出迭代器推力::系统::细节::通用::填充(推力::执行)策略&,输出迭代器,大小,常数T&)[带有DerivedPolicy=推力::系统::omp::细节::标记,输出迭代器=推力::设备(ptr,大小=无符号长,T=int]”
/usr/local/cuda/include/推力/细节/fill.inl(50):这里
[6未显示实例化上下文]
实例化“void-推力::细节::连续存储::未初始化的\u填充\n(推力::细节::连续存储::迭代器,推力::细节::连续存储::大小\u类型,常量推力::细节::连续存储::值\u类型&)[带T=int,Alloc=推力::设备\u malloc \u分配器]”
/usr/local/cuda/include/推力/detail/vector_base.inl(164):这里
实例化“void-推力::细节::向量\基::填充\初始(推力::细节::向量\基::大小\类型,常数T&)[使用T=int,Alloc=推力::设备\ malloc \分配器]”
/usr/local/cuda/include/推力/detail/vector_base.inl(139):这里
实例化“无效推力::细节::向量基::初始调度(迭代器类型,迭代器类型,推力::细节::真类型)[使用T=int,Alloc=推力::设备分配程序,迭代器类型=int]”
/usr/local/cuda/include/推力/detail/vector_base.inl(224):这里
实例化“推力::细节::矢量\基::矢量\基(输入编译器,输入编译器)[使用T=int,Alloc=推力::设备\分配程序,输入编译器=int]”
/usr/local/cuda/include/推力/device_vector.h(148):这里
实例化“推力::设备\向量::设备\向量(InputIterator,InputIterator)[带T=int,Alloc=推力::设备\ malloc \ u分配器,InputIterator=int]”
/usr/local/cuda/include/THEST/system/omp/detail/for_each.inl(53):错误:不允许类型不完整
在以下期间检测到:
实例化“RandomAccessIterator推力::系统::omp::细节::for_each_n(推力::系统::omp::细节::执行_策略&,RandomAccessIterator,大小,UnaryFunction)[使用DerivedPolicy=推力::系统::omp::细节::标记,RandomAccessIterator=推力::细节::普通_迭代器,大小=长,UnaryFunction=cuda_你好]”
(89):这里
实例化“RandomAccess迭代器推力::系统::omp::细节::for_each(推力::系统::omp::细节::执行_策略&,RandomAccess迭代器,RandomAccess迭代器,UnaryFunction)[使用DerivedPolicy=推力::系统::omp::细节::标记,RandomAccess迭代器=推力::细节::普通_迭代器,UnaryFunction=cuda_hello]”
/usr/local/cuda/include/推力/细节/for_each.inl(43):这里
实例化“InputIterator推力::for_each(const推力::detail::execution_policy_base&,InputIterator,InputIterator,UnaryFunction)[使用DerivedPolicy=推力::系统::omp::detail::标记,InputIterator=推力::detail::normal_迭代器,UnaryFunction=cuda_hello]”
/usr/local/cuda/include/推力/细节/for_each.inl(57):这里
实例化“InputIterator推力::for_each(InputIterator,InputIterator,UnaryFunction)[使用InputIterator=推力::细节::普通迭代器,UnaryFunction=cuda\u hello]”
在编译“/tmp/tmpxft_00002d3a_00000000-6_Test.cpp1.ii”时检测到2个错误。
在ExecutableCmake生成的测试中出现CMake错误。cu.o.CMake:264(消息):
生成文件时出错
make[2]:***[CMakeFiles/ExecutableCmake.dir//ExecutableCmake\u生成的\u Test.cu.o]错误1
make[1]:***[CMakeFiles/ExecutableCmake.dir/all]Erreur 2
制造:**[全部]错误2
这些错误看起来与我将cuda代码放入非.cu文件时遇到的错误完全相同,但我对cmake了解不够,无法理解为什么会出现这个问题

提前谢谢你
PROJECT(ExecutableCmake)
set (OUTPUT_NAME ExecutableCmake)

cmake_minimum_required (VERSION 2.8)

#test variable
#set(THRUST_DEVICE_SYSTEM THRUST_DEVICE_SYSTEM_CUDA)
set(THRUST_DEVICE_SYSTEM THRUST_DEVICE_SYSTEM_OMP)
#set(THRUST_DEVICE_SYSTEM THRUST_DEVICE_SYSTEM_TBB)

########################################
####            Cuda Part           ####
########################################
find_package(CUDA REQUIRED)

list( APPEND CUDA_NVCC_FLAGS -gencode arch=compute_30,code=sm_30 -DTHRUST_DEVICE_SYSTEM=${THRUST_DEVICE_SYSTEM} )

set (sources_gpu_cuda
    Test.cu
)

########################################
####         /Cuda Part             ####
########################################

########################################
####           OMP Part             ####
########################################
set(omp_deps gomp)
########################################
####           /OMP Part            ####
########################################

set (sources
#cuda source files
${sources_gpu_cuda}
)

cuda_add_executable(${OUTPUT_NAME} ${sources} ${headers})
target_link_libraries (${OUTPUT_NAME} ${omp_deps})
/usr/local/cuda/include/thrust/system/omp/detail/for_each.inl(53): error: incomplete type is not allowed
          detected during:
            instantiation of "RandomAccessIterator thrust::system::omp::detail::for_each_n(thrust::system::omp::detail::execution_policy<DerivedPolicy> &, RandomAccessIterator, Size, UnaryFunction) [with DerivedPolicy=thrust::system::omp::detail::tag, RandomAccessIterator=thrust::device_ptr<int>, Size=unsigned long, UnaryFunction=thrust::detail::host_generate_functor<thrust::detail::fill_functor<int>>]" 
/usr/local/cuda/include/thrust/detail/for_each.inl(69): here
            instantiation of "InputIterator thrust::for_each_n(const thrust::detail::execution_policy_base<DerivedPolicy> &, InputIterator, Size, UnaryFunction) [with DerivedPolicy=thrust::system::omp::detail::tag, InputIterator=thrust::device_ptr<int>, Size=unsigned long, UnaryFunction=thrust::detail::host_generate_functor<thrust::detail::fill_functor<int>>]" 
/usr/local/cuda/include/thrust/system/detail/generic/generate.inl(52): here
            instantiation of "OutputIterator thrust::system::detail::generic::generate_n(thrust::execution_policy<ExecutionPolicy> &, OutputIterator, Size, Generator) [with ExecutionPolicy=thrust::system::omp::detail::tag, OutputIterator=thrust::device_ptr<int>, Size=unsigned long, Generator=thrust::detail::fill_functor<int>]" 
/usr/local/cuda/include/thrust/detail/generate.inl(56): here
            instantiation of "OutputIterator thrust::generate_n(const thrust::detail::execution_policy_base<DerivedPolicy> &, OutputIterator, Size, Generator) [with DerivedPolicy=thrust::system::omp::detail::tag, OutputIterator=thrust::device_ptr<int>, Size=unsigned long, Generator=thrust::detail::fill_functor<int>]" 
/usr/local/cuda/include/thrust/system/detail/generic/fill.h(45): here
            instantiation of "OutputIterator thrust::system::detail::generic::fill_n(thrust::execution_policy<DerivedPolicy> &, OutputIterator, Size, const T &) [with DerivedPolicy=thrust::system::omp::detail::tag, OutputIterator=thrust::device_ptr<int>, Size=unsigned long, T=int]" 
/usr/local/cuda/include/thrust/detail/fill.inl(50): here
            [ 6 instantiation contexts not shown ]
            instantiation of "void thrust::detail::contiguous_storage<T, Alloc>::uninitialized_fill_n(thrust::detail::contiguous_storage<T, Alloc>::iterator, thrust::detail::contiguous_storage<T, Alloc>::size_type, const thrust::detail::contiguous_storage<T, Alloc>::value_type &) [with T=int, Alloc=thrust::device_malloc_allocator<int>]" 
/usr/local/cuda/include/thrust/detail/vector_base.inl(164): here
            instantiation of "void thrust::detail::vector_base<T, Alloc>::fill_init(thrust::detail::vector_base<T, Alloc>::size_type, const T &) [with T=int, Alloc=thrust::device_malloc_allocator<int>]" 
/usr/local/cuda/include/thrust/detail/vector_base.inl(139): here
            instantiation of "void thrust::detail::vector_base<T, Alloc>::init_dispatch(IteratorOrIntegralType, IteratorOrIntegralType, thrust::detail::true_type) [with T=int, Alloc=thrust::device_malloc_allocator<int>, IteratorOrIntegralType=int]" 
/usr/local/cuda/include/thrust/detail/vector_base.inl(224): here
            instantiation of "thrust::detail::vector_base<T, Alloc>::vector_base(InputIterator, InputIterator) [with T=int, Alloc=thrust::device_malloc_allocator<int>, InputIterator=int]" 
/usr/local/cuda/include/thrust/device_vector.h(148): here
            instantiation of "thrust::device_vector<T, Alloc>::device_vector(InputIterator, InputIterator) [with T=int, Alloc=thrust::device_malloc_allocator<int>, InputIterator=int]" 


/usr/local/cuda/include/thrust/system/omp/detail/for_each.inl(53): error: incomplete type is not allowed
          detected during:
            instantiation of "RandomAccessIterator thrust::system::omp::detail::for_each_n(thrust::system::omp::detail::execution_policy<DerivedPolicy> &, RandomAccessIterator, Size, UnaryFunction) [with DerivedPolicy=thrust::system::omp::detail::tag, RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, Size=long, UnaryFunction=cuda_hello]" 
(89): here
            instantiation of "RandomAccessIterator thrust::system::omp::detail::for_each(thrust::system::omp::detail::execution_policy<DerivedPolicy> &, RandomAccessIterator, RandomAccessIterator, UnaryFunction) [with DerivedPolicy=thrust::system::omp::detail::tag, RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, UnaryFunction=cuda_hello]" 
/usr/local/cuda/include/thrust/detail/for_each.inl(43): here
            instantiation of "InputIterator thrust::for_each(const thrust::detail::execution_policy_base<DerivedPolicy> &, InputIterator, InputIterator, UnaryFunction) [with DerivedPolicy=thrust::system::omp::detail::tag, InputIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, UnaryFunction=cuda_hello]" 
/usr/local/cuda/include/thrust/detail/for_each.inl(57): here
            instantiation of "InputIterator thrust::for_each(InputIterator, InputIterator, UnaryFunction) [with InputIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, UnaryFunction=cuda_hello]" 


2 errors detected in the compilation of "/tmp/tmpxft_00002d3a_00000000-6_Test.cpp1.ii".
CMake Error at ExecutableCmake_generated_Test.cu.o.cmake:264 (message):
  Error generating file



make[2]: *** [CMakeFiles/ExecutableCmake.dir/./ExecutableCmake_generated_Test.cu.o] Erreur 1
make[1]: *** [CMakeFiles/ExecutableCmake.dir/all] Erreur 2
make: *** [all] Erreur 2
list(APPEND CUDA_NVCC_FLAGS -Xcompiler -fopenmp)