为什么我有一个“未对齐的内存访问不支持”错误? [英] Why do I have an "unaligned memory accesses not supported" error?

查看:149
本文介绍了为什么我有一个“未对齐的内存访问不支持”错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个未对齐的内存访问不支持的错误,并做了谷歌搜索
,但没有明确的解释。
整个错误消息是:

I got an "unaligned memory accesses not supported error" and did a Google search for that but there were no clear explanations. The whole error message is:

/c:\cuda\include\math_functions_dbl_ptx1.h(1308): Error: Unaligned memory accesses not supported

以下代码导致错误:

for (j = low; j <= high; j++)

变量j和高声明为int。

The variables j and high are declared as int. This kind of error was encountered before but resolved by itself (I did nothing).

任何人都可以解释这件事吗?

Can anybody explain about this matter?

推荐答案

理论



在许多机器上,但不是Intel IA32或其亲戚要访问一个2字节的数量(整数),地址必须是偶数,不奇数;如果要访问4字节的数量(整数或浮点数),地址必须是4个字节的倍数;如果要访问8字节数量(整数或双精度),则地址必须是8个字节的倍数;等等。

Theory

On many machines - but not Intel IA32 ones or their relatives - if you want to access a 2-byte quantity (integer), the address must be even, not odd; if you want to access a 4-byte quantity (integer or float) the address must be a multiple of 4 bytes; if you want to access an 8-byte quantity (integer or double), the address must be a multiple of 8 bytes; and so on.

表面上,然后,你已经以某种方式让你的代码尝试取消引用一个指针,它的位设置在低阶部分,当你不应该。例如,强制问题(在C中)的一种方式是:

Superficially, then, you have somehow got your code trying dereference a pointer which has bits set in the low-order parts when you should not. For example, one way of forcing the issue (in C) would be:

long l = 0x12345678;
void *v = (char *)&l + 1;
long *lp = v;
l = *lp;

当您经历指针运算时, lp 不是4字节(或8字节)对齐;它是一个由于 +1 。最后一行将给出一个未对齐的内存访问指针。

By the time you've gone through the pointer arithmetic, the address in lp is not 4-byte (or 8-byte) aligned; it is off-by-one because of the +1. The last line would give an unaligned memory access pointer.

因为你没有显示声明你的代码,我们不能确定是什么原因导致的麻烦(虽然你说 j 都是 int 变量;对没有注释)。事实上,几乎独立于声明,似乎不太可能引用 for 循环是麻烦的源头。它可能是接近的代码,但它可能不是那行。

Since you have not shown the declarations for your code, we can't be sure what causes the trouble (though you do say j and high are int variables; no comment about low). Indeed, almost independent of the declarations, it seems unlikely that the quoted for loop is the source of the trouble. It may be code close to that, but it probably is not that line.

有一个机会,你有一个缓冲区重写问题在某处,正在修改指针意外,并且修改的指针生成错误。但是,由于那一行似乎没有包含任何指针,所以不太可能是那条实际触发麻烦的行。

There is a chance that you have a buffer over-writing problem somewhere and are modifying a pointer by accident, and that modified pointer generates the error. But, since that line does not seem to include any pointers, it is unlikely to be that line that is actually triggering the trouble.

这篇关于为什么我有一个“未对齐的内存访问不支持”错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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