How to work with Eigen in CUDA kernels

前端 未结 4 822

Eigen is a c++ linear algebra library http://eigen.tuxfamily.org.

It\'s easy to work with basic data types, like basic float arrays, and just copy it to device memory an

4条回答
  •  被撕碎了的回忆
    2021-02-04 04:34

    Since November 2016 (Release of Eigen 3.3), a new option exists: Using Eigen directly inside CUDA kernels - see this question.

    Example from the linked question:

    __global__ void cu_dot(Eigen::Vector3f *v1, Eigen::Vector3f *v2, double *out, size_t N)
    {
        int idx = blockIdx.x * blockDim.x + threadIdx.x;
        if(idx < N)
        {
            out[idx] = v1[idx].dot(v2[idx]);
        }
        return;
    }
    

    Copying an array of Eigen::Vector3f to device:

    Eigen::Vector3f *host_vectors = new Eigen::Vector3f[N];
    Eigen::Vector3f *dev_vectors;
    cudaMalloc((void **)&dev_vectors, sizeof(Eigen::Vector3f)*N)
    cudaMemcpy(dev_vectors, host_vectors, sizeof(Eigen::Vector3f)*N, cudaMemcpyHostToDevice)
    

提交回复
热议问题