NVCC编译了特征库,并在运行时失败的结构中的MatrixxD大小
NVCC compiles the Eigen library, and the resize of MatrixXd in the structure at runtime fails
我使用的是eigen库版本3.3,带有G 5.4,cuda 8.0在ubuntu 16.04 lts中。
编写代码时发生的事情令人困惑。当我尝试在结构中调整eigen :: matrixxd
时,就会发生崩溃结构如下。
struct cudaCopy{
struct s_path_info *nodes_parents
struct s_path_info *nodes_children
...
}
s_path_info结构如下。
struct s_path_info{
Eigen::MatrixXd supps;
Eigen::MatrixXd residu;
...
问题如下。
struct cudaCopy *mem;
mem = (struct cudaCopy*)malloc(sizeof(struct cudaCopy));
和
mem->nodes_parents = (struct s_path_info*)malloc(50 * sizeof(struct s_path_info))
for(int i=0; i<50; i++){
mem->nodes_parents[i].supps.resize(1, 1); // ERROR
这是GDB执行代码的回溯。
#0 __GI___libc_free (mem=0x1) at malloc.c:2949 #1 0x000000000040a538 in Eigen::internal::aligned_free (ptr=0x1) at ../Eigen/Eigen/src/Core/util/Memory.h:177 #2 0x000000000040f3e8 in Eigen::internal::conditional_aligned_free<true> (ptr=0x1) at ../Eigen/Eigen/src/Core/util/Memory.h:230 #3 0x000000000040cdd4 in Eigen::internal::conditional_aligned_delete_auto<double, true> (ptr=0x1, size=7209728) at ../Eigen/Eigen/src/Core/util/Memory.h:416 #4 0x000000000040d085 in Eigen::DenseStorage<double, -1, -1, -1, 0>::resize (this=0x6e1348, size=20, rows=20, cols=1) at ../Eigen/Eigen/src/Core/DenseStorage.h:406 #5 0x000000000040ba9e in Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >::resize (this=0x6e1348, rows=20, cols=1) at ../Eigen/Eigen/src/Core/PlainObjectBase.h:293 #6 0x000000000040697f in search::islsp_EstMMP_BF_reuse (this=0x7fffffffe4b0) at exam.cu:870 #7 0x0000000000404f33 in main () at exam.cu:422
有趣的是,以下效果很好。
mem->nodes_children = (struct s_path_info*)malloc(10*50*sizeof(struct s_path_info))
for(int i=0; i<10*50; i++){
mem->nodes_children[i].supps.resize(1, 1); // OK
我不明白为什么不能调整nodes_parents。
我感谢对此事的任何评论。谢谢。
您将nodes_parents
设置为非初始化的内存,这意味着s_path_info
的构造函数(以及其成员的构造(从未被调用。而不是struct s_path_info *nodes_parents
,您应该简单地写:
std::vector<s_path_info> nodes_parents;
,您的主cudaCopy
应该只是一个堆栈变量:
cudaCopy mem;
通常,请勿在C 内使用malloc
,尤其是不适合非豆荚。
n.b。:与nodes_children
一起使用的事实可能是纯粹的巧合。
相关文章:
- 结构化绑定初始值设定项表单 { 赋值表达式 } 对于 clang 上的数组类型失败
- 我应该如何在C++中使用结构体解决输入失败的问题?
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 在VS 2017中,朋友通过具有私有析构函数的结构的unique_ptr向量进行迭代失败
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- 我的C++模板失败:非模板结构的显式专用化
- 使用初始值设定项列表初始化结构,对于 std::array 失败
- NVCC编译了特征库,并在运行时失败的结构中的MatrixxD大小
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- 匿名结构可提高函数转换在GCC 5.4上失败
- 为什么结构化绑定在 GCC 上失败
- 在分配的结构中初始化 std::map 在 Windows 上失败
- 如果将键定义为std :: string,则存储在REDIS中的POD结构的验证将失败
- 为什么结构make_unique在包含 std::p romise 作为成员时失败?
- 体系结构x86_64的未定义符号,链接器命令失败
- gsoap-linux c++/结构失败传递
- CUDA 将用户定义的结构传递给内核失败
- push_back包含向量的结构时失败
- 运行时检查失败 #0 - (ESP 的值未正确保存) - 调用存储在结构中的函数时