VS program crashes in debug but not release mode?

2019-03-04 21:24发布

I am running the following program in VS 2012 to try out the Thrust function find:

#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;
}

This is a modified version of a code example taken from http://docs.thrust.googlecode.com/hg/group__searching.html#ga99c7a59cef5b9f4cdbc70f37b2e221be

When I run this in Debug mode, my program crashes and I get the error Debug Error! ... R6010 - abort() has been called. However, running this in Release mode I just get my expected output Index of a = 0.

I know that the crash happens because of the line that includes the find function.

What might cause this to happen?

1条回答
Bombasti
2楼-- · 2019-03-04 22:06

There are a few similar questions e.g. here

To quote a comment : "Thrust is known to not compile and run correctly when built for debugging"

And from the docs: "nvcc does not support device debugging Thrust code. Thrust functions compiled with (e.g., nvcc -G, nvcc --device-debug 0, etc.) will likely crash."

查看更多
登录 后发表回答