OpenCL的结构值在CPU正确的,但不能在GPU [英] OpenCL struct values correct on CPU but not on GPU

查看:129
本文介绍了OpenCL的结构值在CPU正确的,但不能在GPU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件至极一个结构是由主机code和内核

I do have a struct in a file wich is included by the host code and the kernel

typedef struct {
    float x, y, z,
          dir_x, dir_y, dir_z;
    int     radius;
} WorklistStruct;

我建立这个结构在​​我的C ++的主机code,并通过缓冲将其传递给OpenCL的内核。

I'm building this struct in my c++ host code and passing it via a buffer to the OpenCL kernel.

如果我选择的CPU设备计算,我将得到以下结果:

If I'm choosing an CPU device for computation I will get the following result:

 printf ( "item:[%f,%f,%f][%f,%f,%f]%d,%d\n", item.x, item.y, item.z, item.dir_x, item.dir_y,
                 item.dir_z , item.radius ,sizeof(float));

主持人:

item:[20.169043,7.000000,34.933712][0.000000,-3.000000,0.000000]1,4

设备(CPU):

item:[20.169043,7.000000,34.933712][0.000000,-3.000000,0.000000]1,4

如果我选择GPU设备(AMD)进行计算奇怪的事情正在发生:

And if I choose a GPU device (AMD) for computation weird things are happening:

主持人:

item:[58.406261,57.786015,58.137501][2.000000,2.000000,2.000000]2,4

装置(GPU):

Device (GPU):

item:[58.406261,2.000000,0.000000][0.000000,0.000000,0.000000]0,0

值得注意的是,的sizeof(浮动)是垃圾在GPU上。

Notable is that the sizeof(float) is garbage on the gpu.

我假设有一个与在不同的设备彩车的布局有问题。

I assume there is a problem with the layouts of floats on different devices.

请注意:结构包含在此类型和结构的每此数组中的结构数组是GPU垃圾

Note: the struct is contained in an array of structs of this type and every struct in this array is garbage on GPU

有没有人有一个想法,为什么是这种情况,我怎么能predict呢?

Anyone does have an idea why this is the case and how I can predict this?

编辑我添加了一个%d个在和和的1取而代之,结果是:1065353216

EDIT I added an %d at the and and replaced it by an 1, the result is:1065353216

修改:这里两个结构至极我使用

EDIT: here two structs wich I'm using

typedef struct {
      float x, y, z,//base coordinates 
      dir_x, dir_y, dir_z;//directio
      int     radius;//radius
} WorklistStruct;

typedef struct {
    float base_x, base_y, base_z; //base point 
    float radius;//radius 
    float dir_x, dir_y, dir_z; //initial direction
} ReturnStruct;

我测试了一些其他的东西,它看起来像一个printf的问题。值似乎是正确的。我传递的参数到返回结构,阅读这些值是正确的。

I tested some other things, it looks like a problem with printf. The values seems to be right. I passed the arguments to the return struct, read them and these values were correct.

我不希望发布所有相关的code,这将是一个几百行。
如果没有人有一个想法,我会融为一体preSS这一点。

I don't want to post all of the related code, this would be a few hundred lines. If noone has an idea I would compress this a bit.

啊,和印刷我使用的#pragma OPENCL EXTENSION cl_amd_printf:启用

编辑:
看起来真的像printf的一个问题。我根本就没有使用它了。

Looks really like a problem with printf. I simply don't use it anymore.

推荐答案

它看起来像我使用了错误的OpenCL头编译。如果我尝试在Intel平台上的code(OpenCL的1.2),一切都很好。但我的AMD平台(OpenCL的1.1)上我得到奇怪的值。

It looks like I used the wrong OpenCL headers for compiling. If I try the code on the Intel platform(OpenCL 1.2) everything is fine. But on my AMD platform (OpenCL 1.1) I get weird values.

我会尝试其他头。

这篇关于OpenCL的结构值在CPU正确的,但不能在GPU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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