在CUDA函数中使用CUSP矩阵?

时间:2018-04-24 08:46:06

标签: c++11 parallel-processing cuda gpu cusp-library

我想写一个内核函数,它将输入2个CUSP矩阵A和B作为输入,然后将数据并行填充到B中。

#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;
}

发生以下错误:

error: no suitable conversion function from "cusp::coo_matrix<int, float, cusp::host_memory>" to "cusp::coo_matrix<int, float, cusp::host_memory> *" exists

我该怎么做?

1 个答案:

答案 0 :(得分:-1)

错误是因为函数签名是针对指针的,并且您正在传递一个对象。你可以通过引用传递,它将构建。

应该是

__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.
}