【问题标题】:VS program crashes in debug but not release mode?VS程序在调试但不是发布模式下崩溃?
【发布时间】:2014-05-29 14:22:54
【问题描述】:

我在 VS 2012 中运行以下程序来尝试查找 Thrust 函数:

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <thrust/find.h>
#include <thrust/device_vector.h>
#include <stdio.h>

int main() {
    thrust::device_vector<char> input(4);

    input[0] = 'a';
    input[1] = 'b';
    input[2] = 'c';
    input[3] = 'd';

    thrust::device_vector<char>::iterator iter;

    iter = thrust::find(input.begin(), input.end(), 'a');

    std::cout << "Index of a = " << iter - input.begin() << std::endl;

    return 0;
}

这是取自http://docs.thrust.googlecode.com/hg/group__searching.html#ga99c7a59cef5b9f4cdbc70f37b2e221be的代码示例的修改版本

当我在调试模式下运行此程序时,我的程序崩溃并收到错误 Debug Error! ... R6010 - abort() has been called。但是,在发布模式下运行它,我只会得到预期的输出 Index of a = 0

我知道崩溃的发生是因为包含 find 函数的行。

什么可能导致这种情况发生?

【问题讨论】:

    标签: c++ visual-studio-2012 cuda thrust


    【解决方案1】:

    有一些类似的问题,例如here

    引用评论:“众所周知,Thrust 在为调试而构建时无法正确编译和运行”

    来自docs:“nvcc 不支持设备调试 Thrust 代码。使用(例如,nvcc -G、nvcc --device-debug 0 等)编译的 Thrust 函数可能会崩溃。”

    【讨论】:

    • 我想我遇到过这个问题,但我不确定它是否与我使用 Visual Studio 相关。我假设 Visual Studio 使用 cuda-gdb(请参阅developer.nvidia.com/cuda-gdb - “开发人员应确保查看 NVIDIA Nsight 以进行集成调试和分析。用于 Linux 和 MAC 支持的 Nsight Eclipse 版和用于 Windows 的 Nsight Visual Studio 版。 " 这是在 CUDA-GDB 页面上,所以我假设是这样。)
    • 我只做了一点cuda,但是当我尝试时它似乎适用于gcc和VS。
    • cuda-gdb 是一个仅限 linux 的产品,基于 linux 中著名的 gdb 调试器。所以它与Windows无关。但是,VS 中的调试 CUDA 项目在编译时添加了-G 开关(使用nvcc),这是问题的症结所在,如答案中提供的文档链接所示。
    猜你喜欢
    • 1970-01-01
    • 2012-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-25
    • 1970-01-01
    • 1970-01-01
    • 2011-01-21
    相关资源
    最近更新 更多