Eigen 版本3.3.90

gcc版本5.4.0

我目前正在尝试向我的Eigen Tensor项目添加多线程支持,但是在创建评估张量操作所需的ThreadPoolDevice时遇到了问题。

产生错误的最小代码示例如下所示。这是基于Eigen Docs中的shown here示例。

#include <iostream>
#define EIGEN_USE_THREADS
#include <unsupported/Eigen/CXX11/Tensor>
#include <unsupported/Eigen/CXX11/ThreadPool>

int main()
{
    std::cout << "Eigen Version " << EIGEN_WORLD_VERSION << "." << EIGEN_MAJOR_VERSION << "." << EIGEN_MINOR_VERSION << std::endl;

    // Create the Eigen ThreadPoolDevice.
    Eigen::ThreadPoolDevice my_device(4 /* number of threads to use */);

    Eigen::Tensor<float, 2> a(40, 40);
    Eigen::Tensor<float, 2> b(40, 40);

    // Now just use the device when evaluating expressions.
    Eigen::array<Eigen::IndexPair<int>, 1> product_dims = { Eigen::IndexPair<int>(1, 0) };
    Eigen::Tensor<float, 2> c;
    c.device(my_device) = a.contract(b, product_dims);

    std::cout << "Result was " << c << std::endl;

    return 0;
}

这将产生错误消息,如下所示:
thread_pool_tests.cpp: In function ‘int main()’:
thread_pool_tests.cpp:12:68: error: no matching function for call to ‘Eigen::ThreadPoolDevice::ThreadPoolDevice(int)’
  Eigen::ThreadPoolDevice my_device(4 /* number of threads to use */);
                                                                    ^
In file included from /usr/local/include/unsupported/Eigen/CXX11/Tensor:103:0,
                 from thread_pool_tests.cpp:4:
/usr/local/include/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h:55:3: note: candidate: Eigen::ThreadPoolDevice::ThreadPoolDevice(Eigen::ThreadPoolInterface*, int, Eigen::Allocator*)
   ThreadPoolDevice(ThreadPoolInterface* pool, int num_cores, Allocator* allocator = NULL)
   ^
/usr/local/include/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h:55:3: note:   candidate expects 3 arguments, 1 provided
/usr/local/include/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h:53:8: note: candidate: constexpr Eigen::ThreadPoolDevice::ThreadPoolDevice(const Eigen::ThreadPoolDevice&)
 struct ThreadPoolDevice {
        ^
/usr/local/include/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h:53:8: note:   no known conversion for argument 1 from ‘int’ to ‘const Eigen::ThreadPoolDevice&’
/usr/local/include/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h:53:8: note: candidate: constexpr Eigen::ThreadPoolDevice::ThreadPoolDevice(Eigen::ThreadPoolDevice&&)
/usr/local/include/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h:53:8: note:   no known conversion for argument 1 from ‘int’ to ‘Eigen::ThreadPoolDevice&&’

似乎此版本中的ThreadPoolDevice构造函数还期望有一个指向ThreadPoolInterface派生的对象的指针。但是我找不到这种形式的任何例子。有谁知道我该如何解决这个问题并开始在我的应用程序中使用ThreadPoolDevices。

谢谢。

最佳答案

查看错误消息和ThreadPoolDevice(ThreadPoolInterface* pool, int num_cores) : pool_(pool), num_threads_(num_cores) { } here, on line 107,我将大步走出去,建议您需要创建并将ThreadPool的地址传递给构造函数。该源文件顶部有一个ThreadPool typedef。

免责声明-我尚未对此进行测试。这是基于对源代码文件的检查。 NonBlockingThreadPool.h

Eigen::ThreadPool pool(4/*number of threads*/);
Eigen::ThreadPoolDevice my_device(&pool, 4 /* number of threads to use */);

我不知道您的示例文档是否过时,或者只是错误...

10-08 08:24