CUDA调试与VS - 不能检查__restrict__指针(操作无效) [英] CUDA debugging with VS - can't examine __restrict__ pointers (Operation is not valid)

查看:434
本文介绍了CUDA调试与VS - 不能检查__restrict__指针(操作无效)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的内核,其中我使用malloc分配一些空间,简单如下:

  __ global__ void chainKernel (){
float * __restrict__ boo =(float *)malloc(sizeof(float));
* boo = 0;
* boo = * boo + 100;
return;
}



如果我在 * boo = * boo + 100 我看不到* boo的内容。取而代之的是,由于调试器窗口中变量旁边的对象的当前状态,得到操作无效。如果我删除 __ restrict __ ,但是,值显示正确。这是正常的行为吗?



我的系统:CUDA 5.5.20,Nsight 3.1.0.13141,Windows 7 x64,VS2010,GeForce GTX Titan。

$ b $ __ restrict __ 的一个好处是它允许编译器对优化更积极。当你有这样的简单代码,编译器可以完全优化, __ restrict __ 关键字可以帮助编译器这样做。



无法在调试器中检查变量的常见原因之一是由于编译器优化,无论是在本地(变量超出范围,当你没有期望它)或全局(一个变量完全优化)。



请注意,您在此问题中显示的内核的定义没有任何用处。因此,编译器可能会优化东西。



要解决这个问题(对于这种情况),放一个 printf(%f,* boo); 语句紧跟在最后的 boo 赋值之后,编译器将无法优化变量。您还应该使用 -G 开关进行调试。


I have a simple kernel, in which I'm allocating some space using malloc, simply as:

__global__ void chainKernel() {
    float* __restrict__ boo = (float*)malloc(sizeof(float));
    *boo = 0;
    *boo = *boo + 100;
    return;
}

If I put a breakpoint on *boo = *boo + 100 I can't see the contents of *boo. Instead I get Operation is not valid due to the current state of the object next to the variable in the debugger window. If I remove the __restrict__ however, the value is shown correctly. Is this normal behavior?

My system: CUDA 5.5.20, Nsight 3.1.0.13141, Windows 7 x64, VS2010, GeForce GTX Titan.

解决方案

One of the benefits of __restrict__ is that it allows the compiler to be more aggressive with optimizations. When you have simple code like this that the compiler can completely optimize away, the __restrict__ keyword may help the compiler do just that.

One of the common reasons for not being able to inspect variables in the debugger is due to compiler optimizations, either locally (a variable going out of scope when you weren't expecting it) or globally (a variable that has been completely optimized away).

Note that the definition of the kernel you've shown in this question does nothing useful. Therefore the compiler may be optimizing things away.

To work around this (for this case), put a printf("%f", *boo); statement immediately after the final boo assignment, and the compiler will not be able to optimize the variable away. You should also be using the -G switch for debugging.

这篇关于CUDA调试与VS - 不能检查__restrict__指针(操作无效)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆