首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在CUDA函数中使用CUSP矩阵?

在CUDA函数中使用CUSP矩阵?
EN

Stack Overflow用户
提问于 2018-04-24 16:46:06
回答 1查看 113关注 0票数 0

我想写一个核函数,它以2个CUSP矩阵A和B作为输入,

然后并行将数据填充到B中。

代码语言:javascript
复制
#include <cusp/coo_matrix.h>
#include <cusp/print.h>
#include <iostream>

__global__ void kernel_example(cusp::coo_matrix<int,float,cusp::host_memory>* A,
cusp::coo_matrix<int,float,cusp::host_memory>* B){
    printf("hello from kernel...");
    //actual operations go here.
}

int main(void)
{
    // allocate storage
    cusp::coo_matrix<int,float,cusp::host_memory> A(4,3,6);
    cusp::coo_matrix<int,float,cusp::host_memory> B(4,3,6);

    // initialize matrix entries on host
    A.row_indices[0] = 0; A.column_indices[0] = 0; A.values[0] = 10;
    A.row_indices[1] = 0; A.column_indices[1] = 2; A.values[1] = 20;
    A.row_indices[2] = 2; A.column_indices[2] = 2; A.values[2] = 30;
    A.row_indices[3] = 3; A.column_indices[3] = 0; A.values[3] = 40;
    A.row_indices[4] = 3; A.column_indices[4] = 1; A.values[4] = 50;
    A.row_indices[5] = 3; A.column_indices[5] = 2; A.values[5] = 60;

    kernel_example<<<1,1>>>(A,B);
    cudaDeviceSynchronize();    

    return 0;
}

随后会出现以下错误:

代码语言:javascript
复制
error: no suitable conversion function from "cusp::coo_matrix<int, float, cusp::host_memory>" to "cusp::coo_matrix<int, float, cusp::host_memory> *" exists

我该怎么做呢?

EN

回答 1

Stack Overflow用户

发布于 2018-04-24 16:54:04

错误是因为函数签名是针对指针的,而您传递的是一个对象。你可以通过引用来传递,它将会生成。

应该是

代码语言:javascript
复制
__global__ void kernel_example(cusp::coo_matrix<int, float, cusp::host_memory>& A,
    cusp::coo_matrix<int, float, cusp::host_memory>& B) {
    printf("hello from kernel...");
    //actual operations go here.
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49997179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档