muda icon indicating copy to clipboard operation
muda copied to clipboard

Problem & questions

Open Da1sypetals opened this issue 6 months ago • 6 comments

  1. This code ran into compilation errors when I tried to use spmv (while solve works well):
#include <iostream>
#include <Eigen/Eigen>
#include <muda/muda.h>
#include <muda/ext/linear_system.h>

using namespace muda;


void run_tests() {

    int N = 3;

    // define a N*N matrix A and b
    DeviceTripletMatrix<float, 1> A;
    DeviceDenseVector<float> b(N);
    DeviceDenseVector<float> x(N);
    DeviceDenseVector<float> y(N);

    // reserve for triplets
    A.resize_triplets(N * N);
    A.reshape(N, N);

    std::cout << "sizes:\n";
    std::cout << A.row_indices().size()
              << "  " << A.col_indices().size()
              << "  " << A.values().size() << std::endl;

    ParallelFor(256).apply(N * N, [row_idx = A.row_indices().viewer(),
            col_idx = A.col_indices().viewer(),
            val = A.values().viewer(),
            b = b.viewer(), N]__device__(int i)mutable {

        row_idx(i) = i % N;
        col_idx(i) = i / N;
        val(i) = static_cast<float>(i * i);

        if (i < N) {
            b(i) = static_cast<float>(i);
        }

    });

    LinearSystemContext ctx;

    DeviceCOOMatrix<float> A_coo;
    ctx.convert(A, A_coo);
    DeviceCSRMatrix<float> A_csr;
    ctx.convert(A_coo, A_csr);


    ctx.solve(x.view(), A_csr.cview(), b.cview());

    std::cout << "solve done\n";
    ctx.spmv(A_csr.cview(), x.cview(), y.view());

    Eigen::VectorXf hx(N);
    x.copy_to(hx);
    for (int i = 0; i < N; i++) {
        std::cout << hx.coeff(i) << "  ";
    }
    std::cout << std::endl;

}

int main() {
    run_tests();
    return 0;
}

terminal output:

/mnt/a/dev/muda/muda-template/submodules/muda/src/muda/ext/linear_system/details/routines/spmv.inl(15): error: argument of type "const cusparseDnVecDescr *" is incompatible with parameter of type "cusparseDnVecDescr_t"
          detected during:
            instantiation of "void muda::LinearSystemContext::generic_spmv(const T &, cusparseOperation_t, cusparseSpMatDescr_t, const cusparseDnVecDescr *, const T &, cusparseDnVecDescr_t) [with T=float]"
/mnt/a/dev/muda/muda-template/submodules/muda/src/muda/ext/linear_system/details/routines/spmv/csr_spmv.inl(12): here
            instantiation of "void muda::LinearSystemContext::spmv(const T &, muda::CCSRMatrixView<T>, muda::CDenseVectorView<T>, const T &, muda::DenseVectorView<T> &) [with T=float]"
/mnt/a/dev/muda/muda-template/submodules/muda/src/muda/ext/linear_system/details/routines/spmv/csr_spmv.inl(18): here
            instantiation of "void muda::LinearSystemContext::spmv(muda::CCSRMatrixView<T>, muda::CDenseVectorView<T>, muda::DenseVectorView<T>) [with T=float]"
/mnt/a/dev/muda/muda-template/src/main.cu(101): here

/mnt/a/dev/muda/muda-template/submodules/muda/src/muda/ext/linear_system/details/routines/spmv.inl(20): error: argument of type "const cusparseDnVecDescr *" is incompatible with parameter of type "cusparseDnVecDescr_t"
          detected during:
            instantiation of "void muda::LinearSystemContext::generic_spmv(const T &, cusparseOperation_t, cusparseSpMatDescr_t, const cusparseDnVecDescr *, const T &, cusparseDnVecDescr_t) [with T=float]"
/mnt/a/dev/muda/muda-template/submodules/muda/src/muda/ext/linear_system/details/routines/spmv/csr_spmv.inl(12): here
            instantiation of "void muda::LinearSystemContext::spmv(const T &, muda::CCSRMatrixView<T>, muda::CDenseVectorView<T>, const T &, muda::DenseVectorView<T> &) [with T=float]"
/mnt/a/dev/muda/muda-template/submodules/muda/src/muda/ext/linear_system/details/routines/spmv/csr_spmv.inl(18): here
            instantiation of "void muda::LinearSystemContext::spmv(muda::CCSRMatrixView<T>, muda::CDenseVectorView<T>, muda::DenseVectorView<T>) [with T=float]"
/mnt/a/dev/muda/muda-template/src/main.cu(101): here

2 errors detected in the compilation of "/mnt/a/dev/muda/muda-template/src/main.cu".
gmake[2]: *** [CMakeFiles/hello_muda.dir/build.make:92: CMakeFiles/hello_muda.dir/src/main.cu.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:286: CMakeFiles/hello_muda.dir/all] Error 2
gmake: *** [Makefile:156: all] Error 2

I wonder if there is any problem in mu Muda code or the problem is caused somewhere else.


  1. What is typically used (best practice) when it comes to small vector linear algebra on device (like float3, float3x3 and dot, outer product, etc.)? Thanks a lot in advance!

Da1sypetals avatar Jul 27 '24 02:07 Da1sypetals