如何将密集的向量转换为CUDA中的稀疏向量
How to convert dense vector to sparse vector in CUDA ?
我在GPU内存中有一个大密集向量(不是矩阵):
[1,3,0,0,4,0,0]
并希望将其转换为稀疏格式:
values = [1,3,4];index = [0,1,4]
我知道我可以在cuSPARSE
中调用cusparse<t>dense2csc()
,但这是为矩阵而设计的,并且可能对向量不有效。还有其他方法吗?或者也许是cuda内核。谢谢
使用thrust::copy_if
int * d_index = [1,3,0,0,4,0,0];
int * d_index_compact;
struct non_negative
{
__host__ __device__
bool operator()(const int x)
{
return x >= 0;
}
};
thrust::copy_if(thrust::cuda::par, d_index, d_index + this->vocab_size , d_index_compact, non_negative()); // d_index_compact = [1,3,4];
相关文章:
- 写入向量<向量<bool>>
- 函数向量_指针有不同的原型,我可以构建一个吗
- 编译时未启用intel oneApi CUDA支持
- 在统一内存 CUDA C/C++ 中分配 2D 向量
- 如何在 CUDA 中(有效地)将大量向量相互比较
- CUDA:复杂标量 *双稀疏矩阵 *双向量
- 如何将密集的向量转换为CUDA中的稀疏向量
- CUDA矢量减少以处理长度小于512的向量
- Cuda 内核返回向量
- 如何在CUDA内核中添加向量元素
- CUDA 推力:类的:d向量 |错误
- CUDA内核自动调用内核来完成向量加法.为什么?
- 在 cuda 内核中创建向量
- CUDA - STL 向量在传递给使用 nvcc 编译的类时损坏
- 两个单精度浮点向量的点积在 CUDA 内核中产生的结果与在主机上的结果不同
- 获取CUDA推力::transform运算符()函数内向量的索引
- 如何在cuda中有效地将向量重复到矩阵
- 如何从两个数组中生成一对向量,然后使用CUDA/Thrust按对的第一个元素排序
- 在 CUDA 中相互减去向量的元素
- CUDA 中的稀疏矩阵向量乘法