gpt4 book ai didi

compiler-errors - Cuda 向量类型的推力支持

转载 作者:行者123 更新时间:2023-12-02 10:46:10 24 4
gpt4 key购买 nike

我目前正在尝试使用推力::upper_bound 函数。我遇到了我提供给函数的参数的问题。我想使用 CUDA 向量类型,特别是 double3 ,但是当我使用这种类型时,我遇到了几个推力库错误。

我正在运行的代码块如下:

/********************************************************************************                                                                            
eos_search_gpu()
purpose --- kernel to find the upper bound index for the
interpolation values
arguments --

y --- input double3 values for which we are searching
my --- input int number of values for which we are searching
x --- input double3 array of structs containin the data table
values for x, y, and f corresponding to structs
".x", ".y", and ".z"
n --- input int number of data values in the table
dim_x --- input int number of data values in the x-direcion of table
j[] --- input/output int[] array of int'sthat contains
the index of the (x,y,f) position of the upper bound


library calls --

__host__ __device__ ForwardIterator thrust::upper_bound(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
const LessThanComparable & value
)

exec --- the execution policy to use for parallelization
first --- the beginning of the ordered sequence
last --- the end of the ordered sequence
value --- the value to be searched.

Returns: the furthermost iterator i, such that value < *i is false


const detail::seq_t thrust::seq
an execution policy which requires analgorithm invocation to execute
sequentially in the current thread.

********************************************************************************/

__global__ void eos_search_gpu(const double3* y, const int my,
const double3* x, const int n,
const int dim_x, int * j){

int i = threadIdx.x + blockDim.x * blockIdx.x;
if ( i < my) {
const double ptr = thrust::upper_bound(thrust::seq, x[0].y , x[n-1].y, y[i].y);
j[i] = (ptr - x[i].y - 1);

}
}

显示的错误信息如下:
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/iterator/iterator_traits.h(45): error: a class or namespace qualified name is required
detected during:
instantiation of class "thrust::iterator_traits<T> [with T=double]"
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/iterator/detail/iterator_traits.inl(53): here
instantiation of class "thrust::iterator_difference<Iterator> [with Iterator=double]"
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/binary_search.h(102): here
instantiation of "ForwardIterator thrust::system::detail::sequential::upper_bound(thrust::system::detail::sequential::execution_policy<DerivedPolicy> &, ForwardIterator, ForwardIterator, const T &, StrictWeakOrdering) [with DerivedPolicy=thrust::detail::seq_t, ForwardIterator=double, T=double, StrictWeakOrdering=thrust::system::detail::generic::detail::binary_search_less]"
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/detail/binary_search.inl(83): here
instantiation of "ForwardIterator thrust::upper_bound(const thrust::detail::execution_policy_base<DerivedPolicy> &, ForwardIterator, ForwardIterator, const T &, StrictWeakOrdering) [with DerivedPolicy=thrust::detail::seq_t, ForwardIterator=double, T=double, StrictWeakOrdering=thrust::system::detail::generic::detail::binary_search_less]"
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/binary_search.inl(225): here
instantiation of "ForwardIterator thrust::system::detail::generic::upper_bound(thrust::execution_policy<DerivedPolicy> &, ForwardIterator, ForwardIterator, const T &) [with DerivedPolicy=thrust::detail::seq_t, ForwardIterator=double, T=double]"
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/detail/binary_search.inl(69): here
instantiation of "ForwardIterator thrust::upper_bound(const thrust::detail::execution_policy_base<DerivedPolicy> &, ForwardIterator, ForwardIterator, const LessThanComparable &) [with DerivedPolicy=thrust::detail::seq_t, ForwardIterator=double, LessThanComparable=double]"
Interpolation_cuda.cu(254): here

/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/iterator/iterator_traits.h(45): error: global-scope qualifier (leading "::") is not allowed
detected during:
instantiation of class "thrust::iterator_traits<T> [with T=double]"
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/iterator/detail/iterator_traits.inl(53): here
instantiation of class "thrust::iterator_difference<Iterator> [with Iterator=double]"
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/binary_search.h(102): here
instantiation of "ForwardIterator thrust::system::detail::sequential::upper_bound(thrust::system::detail::sequential::execution_policy<DerivedPolicy> &, ForwardIterator, ForwardIterator, const T &, StrictWeakOrdering) [with DerivedPolicy=thrust::detail::seq_t, ForwardIterator=double, T=double, StrictWeakOrdering=thrust::system::detail::generic::detail::binary_search_less]"
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/detail/binary_search.inl(83): here
instantiation of "ForwardIterator thrust::upper_bound(const thrust::detail::execution_policy_base<DerivedPolicy> &, ForwardIterator, ForwardIterator, const T &, StrictWeakOrdering) [with DerivedPolicy=thrust::detail::seq_t, ForwardIterator=double, T=double, StrictWeakOrdering=thrust::system::detail::generic::detail::binary_search_less]"
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/binary_search.inl(225): here
instantiation of "ForwardIterator thrust::system::detail::generic::upper_bound(thrust::execution_policy<DerivedPolicy> &, ForwardIterator, ForwardIterator, const T &) [with DerivedPolicy=thrust::detail::seq_t, ForwardIterator=double, T=double]"
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/detail/binary_search.inl(69): here
instantiation of "ForwardIterator thrust::upper_bound(const thrust::detail::execution_policy_base<DerivedPolicy> &, ForwardIterator, ForwardIterator, const LessThanComparable &) [with DerivedPolicy=thrust::detail::seq_t, ForwardIterator=double, LessThanComparable=double]"
Interpolation_cuda.cu(254): here

/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/iterator/iterator_traits.h(45): error: expected a ";"
detected during:
instantiation of class "thrust::iterator_traits<T> [with T=double]"
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/iterator/detail/iterator_traits.inl(53): here
instantiation of class "thrust::iterator_difference<Iterator> [with Iterator=double]"
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/binary_search.h(102): here
instantiation of "ForwardIterator thrust::system::detail::sequential::upper_bound(thrust::system::detail::sequential::execution_policy<DerivedPolicy> &, ForwardIterator, ForwardIterator, const T &, StrictWeakOrdering) [with DerivedPolicy=thrust::detail::seq_t, ForwardIterator=double, T=double, StrictWeakOrdering=thrust::system::detail::generic::detail::binary_search_less]"
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/detail/binary_search.inl(83): here
instantiation of "ForwardIterator thrust::upper_bound(const thrust::detail::execution_policy_base<DerivedPolicy> &, ForwardIterator, ForwardIterator, const T &, StrictWeakOrdering) [with DerivedPolicy=thrust::detail::seq_t, ForwardIterator=double, T=double, StrictWeakOrdering=thrust::system::detail::generic::detail::binary_search_less]"
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/binary_search.inl(225): here
instantiation of "ForwardIterator thrust::system::detail::generic::upper_bound(thrust::execution_policy<DerivedPolicy> &, ForwardIterator, ForwardIterator, const T &) [with DerivedPolicy=thrust::detail::seq_t, ForwardIterator=double, T=double]"
/opt/cudatoolkit/9.1/bin/../targets/x86_64-linux/include/thrust/detail/binary_search.inl(69): here
instantiation of "ForwardIterator thrust::upper_bound(const thrust::detail::execution_policy_base<DerivedPolicy> &, ForwardIterator, ForwardIterator, const LessThanComparable &) [with DerivedPolicy=thrust::detail::seq_t, ForwardIterator=double, LessThanComparable=double]"
Interpolation_cuda.cu(254): here

我想知道推力是否支持使用 CUDA 矢量类型,或者我只是做错了什么。

最佳答案

您需要满足推力算法的所有预期输入类型。您没有这样做,因为您定义的几乎每个数量都与预期的推力不匹配。

首先,我们需要实际的迭代器。在设备代码中,这意味着指针。 Thrust 需要能够取消引用迭代器/指针,然后您必须指示推力如何处理该数量。为此,我们需要一个适当定义的仿函数。您不妨阅读 thrust quick start guide了解仿函数的定义和用法。最后,这里的明智指针/迭代器指的是 double3类型,所以我们需要制作几乎所有的东西来使用 double3 .注意我们需要选择the versionupper_bound这允许定义我们自己的自定义仿函数,所以我们可以操纵 double3数量(当我们取消引用迭代器/指针时得到的)正确。

这可能会有所帮助:

#include <thrust/binary_search.h>
#include <thrust/execution_policy.h>


struct my_comp_functor{
template <typename T>
__host__ __device__
bool operator()(T &t1, T &t2) {
return (t1.y < t2.y);}
};

__global__ void eos_search_gpu(const double3* y, const int my,
const double3* x, const int n,
const int dim_x, int * j, my_comp_functor my_comp){

int i = threadIdx.x + blockDim.x * blockIdx.x;
if ( i < my) {
const double3 *ptr = thrust::upper_bound(thrust::seq, x, x+n, y[i], my_comp);
j[i] = (ptr[0].y - x[i].y - 1);

}
}

int main(){

double3 *d_y, *d_x;
int *d_j;

cudaMalloc(&d_y, 1024);
cudaMalloc(&d_x, 1024);
cudaMalloc(&d_j, 1024);
struct my_comp_functor my_obj;
eos_search_gpu<<<1,1>>>(d_y, 0, d_x, 0, 0, d_j, my_obj);
cudaDeviceSynchronize();
}

(上面的代码在 CUDA 9.2 上对我来说编译没有编译错误,但它显然不是为了功能/有用而设计的)

最后,我觉得你正在干扰 double数量入 j[i] (一个整数)但它是你的代码。

另外,我可能在那个仿函数中弄错了顺序,所以您可能需要更改 <> .

当你调用这个内核时,注意我添加了一个参数;你需要实例化一个 my_comp_functor主机代码中的对象,然后将其传递给适当位置的内核。

最后,您似乎正在进行矢量化搜索,请注意推力具有 vectorized searches available这可能会消除对这个内核的需求。

关于compiler-errors - Cuda 向量类型的推力支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51274740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com