用SIMD命令编程时出现分段错误
segmentation fault in programm with SIMD commands
这是怎么回事?当我运行程序时,它说,Segmentation Fault (Core Dumped)
。我使用了一些SIMD命令。
float function ( Point p1, Point p2, int dim )
{
int k;
float result=0.0;
float *p3;
p3 = (float*) malloc (16);
k=dim%4;
__m128 *v_p1 = (__m128*)p1.coord;
__m128 *v_p2 = (__m128*)p2.coord;
__m128 *v_p3 = (__m128*)p3;
for (int i=0; i<dim/4; i++){
*v_p3= _mm_sub_ps(*v_p1,*v_p2);
}
for(int i=0; i<dim; i++){
result+=p3[i];
}
return(result);
}
任何SIMD _ps
指令都需要16
字节对齐的数据。从我可以告诉至少p3
没有正确对齐,所以你肯定会得到一个seg fault
,如果你不使用正确对齐的数据。我不能自己运行这段代码,但如果你按值分配给__m128
变量,你应该没问题,因为它们应该正确对齐:
__m128 v_p1 = _mm_set_ps( ... ); // not sure of the argument
__m128 v_p2 = _mm_set_ps( ... ); // not sure of the argument
__m128 v_p3 = _mm_set_ps1(p3) ;
正如注释所说,当使用SIMD intrinsic时,内存中的数据必须对齐(在此特殊情况下,16字节对齐),如果您在UNIX系统中尝试使用posix_memalign()
分配数据:
相关文章:
- 在某些循环内使用vector.push_back时出现分段错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 当我的阵列太大时出现分段错误
- 分段错误当我试图运行程序时出错
- 在c++中初始化矩阵时出现分段错误(核心转储)
- 尝试使用集合函数时出现分段错误
- 我无法缩小此分段错误的原因
- g++的分段错误(在NaN上使用to_string两次时)
- 我是如何在这段代码中出现分段错误的
- 创建结构的数组时遇到分段错误
- 在c++中键入向量中的所有值后,得到分段错误(核心转储)
- 在 c++ 中实现 Trie 时出现分段错误
- 为什么 fstream 在打开带有格式的文件时会导致分段错误?
- 为什么我遇到分段错误?
- 动态类的分段错误(家庭作业问题)
- 分段错误 - 读取初始化指针的数组
- 如何摆脱C ++中的分段错误错误?
- 使用 CTYPE 时出现分段错误
- 为什么代码给出分段错误?