cuda - compile error occured in thrust/type_traits.h -
i try add trust::sort in cuda code, nvcc tell me that:
type_traits.h(322): error c2660: 'test' : function not take 1 arguments type_traits.h(322): error c2866:'thrust::detail::tt_detail::is_convertible_sfinae<from,to>::value' : const static data member of managed type must initialized @ point of declaration type_traits.h(355): error c2057: expected constant expressiontype_traits.h(363): error c2975: '__v' : invalid template argument 'thrust::detail::integral_constant', expected compile-time constant expression type_traits.h(363): error c2975: '__v' : invalid template argument 'thrust::detail::integral_constant', expected compile-time constant expression i have search there seems no 1 same problem me
the part of code thrust:
#include <thrust\sort.h> struct prepare_struct { float xp; float yp; float zp; float xs; float ys; float zs; float sep; int idsrc_ideve; }; int compare_sort(prepare_struct &a, prepare_struct &b){ return a.sep > b.sep;} void func(...){ ... prepare_struct* spos_d; checkcudaerrors( cudamalloc((void**)&spos_d, n*sizeof(prepare_struct) ) ); //a kernel fill spos_d thrust::sort(spos_d, spos_d + n, compare_sort); ... } if remove thrust::sort(), compiled without error
i've tried thrust::device_vector, same error
and raw_pointer_cast() same error message too
is bug inside thrust or nvcc?
or wrong in code?
environment:
win7 x64 vs 2010 cuda 5.0 sm_20
the device_vector version:
#include <thrust/device_vector.h> void func(...){ ... thrust::device_vector<prepare_struct> spos_dv(n_src_sta); prepare_struct* spos_d = thrust::raw_pointer_cast(spos_dv.data()); //a kernel fill spos_d thrust::sort(spos_dv.begin(),spos_dv.end(),compare_sort); ... }
when writing post on stack overflow, make sure provide short, self contained, correct (compilable), example (aka sscce). make life easier other members trying you, , find actual error in code. if code not compilable, provide example demonstrates compilation issue.
as program, there must things not telling us. trying achieve handled thrust without error. here modified (and completed) version of program:
#include <thrust/sort.h> #include <thrust/device_vector.h> #include <thrust/host_vector.h> struct prepare_struct { float xp; float yp; float zp; float xs; float ys; float zs; float sep; int idsrc_ideve; }; struct prepare_struct_compare { __host__ __device__ bool operator() (const prepare_struct& a, const prepare_struct& b) { return a.sep < b.sep; } }; void initialize(thrust::host_vector<prepare_struct>& v) { for(size_t = 0; < v.size(); i++) v[i].sep = v.size() - i; } void print(const thrust::host_vector<prepare_struct>& v) { for(size_t = 0; < v.size(); i++) std::cout << " " << v[i].sep; std::cout << "\n"; } int main () { const int n = 10; // initialize vector of prepare_struct on host thrust::host_vector<prepare_struct> vec_h(n); initialize(vec_h); std::cout << "initial vector:" << std::endl; print(vec_h); // copy vector device thrust::device_vector<prepare_struct> vec_d = vec_h; // sort on device thrust::sort (vec_d.begin(), vec_d.end(), prepare_struct_compare()); // copy result host thrust::host_vector<prepare_struct> res_h = vec_d; std::cout << "final vector:" << std::endl; print(res_h); } running program gives us:
initial vector: 10 9 8 7 6 5 4 3 2 1 final vector: 1 2 3 4 5 6 7 8 9 10
Comments
Post a Comment