OpenCL CLK_LOCAL_MEM_FENCE 导致中止陷阱 6 [英] OpenCL CLK_LOCAL_MEM_FENCE causing abort trap 6

查看:82
本文介绍了OpenCL CLK_LOCAL_MEM_FENCE 导致中止陷阱 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一些关于图像卷积的练习(此处的信息)使用OpenCL.当我使用大小不是正方形的图像时(如 r x c)CLK_LOCAL_MEM_FENCE 使程序停止并出现中止陷阱 6.

I'm doing some exercise about convolution over images (info here) using OpenCL. When I use images whose size is not a square (like r x c) CLK_LOCAL_MEM_FENCE makes the program stop with abort trap 6.

我所做的基本上是用适当的值填充本地内存,等待这个填充本地内存的过程完成,使用barrier(CLK_LOCAL_MEM_FENCE),然后计算值.

What I do is essentially filing up the local memory with proper values, waiting for this process of filling the local memory to finish, using barrier(CLK_LOCAL_MEM_FENCE) and then calculating the values.

似乎当我使用像我告诉过你的障碍的图像时(CLK_LOCAL_MEM_FENCE)会产生问题,如果我评论该命令一切正常(这很奇怪,因为没有同步).有什么想法可能会导致这个问题?

It seems like when I use images like those I've told you about barrier(CLK_LOCAL_MEM_FENCE) gives issues, if I comment that command everything work fine (which is weird since there's no synchronization). What may cause this problem any idea?

当高度或宽度或两者都不是本地项目大小 (16 x 16) 的倍数时,就会出现问题.全局项目大小是 16 的倍数,例如 (512 x 512).

the problem comes when the hight or the width or both are not multiple of the the local items size (16 x 16). The global items size is aways a couple of values multiple of 16 like (512 x 512).

int c = get_global_id(0); 
int r = get_global_id(1); 

int lc = get_local_id(0);
int lr = get_local_id(1);

// this ignores indexes out of the input image.
if (c >= ImageWidth || r >= ImageHeight) return;

// fill a local array...

barrier(CLK_LOCAL_MEM_FENCE);

if (c < outputImageWidth && r < outputImageHeight)
{
     // LOCAL DATA PROCESSED  
     OutputImage[r* outputImageWidth +c] = someValue;
}

推荐答案

OpenCL 要求每个工作组屏障由该工作组中的每个 工作项执行.

OpenCL requires that each work-group barrier is executed by every work-item in that work-group.

在您发布的代码中,您有一个提前退出子句来防止超出范围的访问.这是在 OpenCL 1.X 中获得良好工作组大小的常用技巧,但不幸的是,这打破了上述条件,这将导致未定义的行为(通常是挂起或崩溃).

In the code that you have posted, you have an early exit clause to prevent out-of-range accesses. This is a common trick for getting nice work-group sizes in OpenCL 1.X, but unfortunately this breaks the above condition, and this will lead to undefined behaviour (typically either a hang or a crash).

您需要修改内核以避免这种情况,方法是删除早期退出子句(如果适用,可能还钳制超出范围的工作项),或者通过重构内核使超出范围的工作项:范围工作项在退出之前至少继续到障碍.

You will need to modify your kernel to avoid this, by either removing the early exit clause (and perhaps clamping out-of-range work-items instead, if applicable), or by restructuring the kernel so that out-of-range work-items continue at least as far as the barrier before exiting.

这篇关于OpenCL CLK_LOCAL_MEM_FENCE 导致中止陷阱 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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