在推力指针中包裹一个尖点稀疏矩阵变量

时间:2012-10-30 14:34:46

标签: cuda max sparse-matrix thrust cusp-library

我正在使用尖点进行稀疏矩阵乘法。从结果矩阵中我需要最大值而不将矩阵从设备存储器复制到主机存储器。我打算将结果矩阵包装在推力设备指针中,然后使用函数 thrust :: max_element 来获取最大元素。矩阵采用铜格式。如果C是结果稀疏矩阵则为
C.row_indices []:包含行号
C.column_indices []:包含列号
C.values []:包含实际值

所以基本上我需要来自C.values数组的最高值 使用

thrust::device_ptr<int> dev_ptr = C.values;

给出错误

error: no instance of constructor "thrust::device_ptr<T>::device_ptr [with T=int]" matches the argument list
 argument types are: (cusp::array1d<float, cusp::host_memory>)

如何包装我的结果矩阵以便在推力库中使用它?

1 个答案:

答案 0 :(得分:1)

如果我的设备矩阵定义是这样的:

cusp::coo_matrix<int, double, cusp::device_memory> A_d = A;

然后试试这个:

thrust::device_ptr<double> dev_ptr = &(A_d.values[0]);
thrust::device_ptr<double> max_ptr = thrust::max_element(dev_ptr, dev_ptr + 6);