在opencl中使用指针用于图像对象

时间:2015-09-16 07:08:29

标签: opencl gpu gpgpu

我正在尝试使用指针而不是2D图像对象缓冲区来读取图像对象

  img_fmt.image_channel_order = CL_R;
  img_fmt.image_channel_data_type = CL_UNORM_INT8;
__kernel void test(__read_only image2d_t in, __write_only image2d_t out)
{
    float *p;
    void *temp;
    temp = (void *)∈
    p=temp;

    if(get_global_id(0) == 10)
    printf("%f",*p);

}

然而,当我得到这个的印刷品时,我看到所有的值都是零。 我想这样做

1)找出其发生的原因?

2)如果以上工作我想在指针p上使用vload16一次获得16个像素?我不认为它可以从图像对象的地址获得16个像素,但我想看看该地址的内存中有什么?

当我在每个工作项ID上打印in的地址时,我看到了一件有趣的事情。使用以下代码:

__kernel void test(__read_only image2d_t in, __write_only image2d_t out)
{
    float *p;
    void *temp;
    temp = (void *)∈

    if(get_global_id(0) < 50)
    printf("%p",temp);

}



0x500000000 row no 0 col no 0      0x500004000 row no 0 col no 4      0x500008000 row no 0 col no 8     0x50000C000 row no 0 col no 12     0x500000080 row no 0 col no 16  0x500004080 row no 0 col no 20
0x500000008 row no 0 col no 1      0x500004008 row no 0 col no 5      0x500008008 row no 0 col no 9     0x50000C008 row no 0 col no 13     0x500000088 row no 0 col no 17  0x500004088 row no 0 col no 21
0x500000010 row no 0 col no 2      0x500004010 row no 0 col no 6      0x500008010 row no 0 col no 10    0x50000C010 row no 0 col no 14     0x500000090 row no 0 col no 18  0x500004090 row no 0 col no 22
0x500000018 row no 0 col no 3      0x500004018 row no 0 col no 7      0x500008018 row no 0 col no 11    0x50000C018 row no 0 col no 15     0x500000098 row no 0 col no 19  0x500004098 row no 0 col no 23

0x500000020 row no 1 col no 0      0x500004020 row no 1 col no 4      0x500008020 row no 1 col no 8     0x50000C020 row no 1 col no 12     0x5000000A0 row no 1 col no 16  0x5000040A0 row no 1 col no 20
0x500000028 row no 1 col no 1      0x500004028 row no 1 col no 5      0x500008028 row no 1 col no 9     0x50000C028 row no 1 col no 13     0x5000000A8 row no 1 col no 17  0x5000040A8 row no 1 col no 21
0x500000030 row no 1 col no 2      0x500004030 row no 1 col no 6      0x500008030 row no 1 col no 10    0x50000C030 row no 1 col no 14     0x5000000B0 row no 1 col no 18  0x5000040B0 row no 1 col no 22
0x500000038 row no 1 col no 3      0x500004038 row no 1 col no 7      0x500008038 row no 1 col no 11    0x50000C038 row no 1 col no 15     0x5000000B8 row no 1 col no 19  0x5000040B8 row no 1 col no 23

0x500000040 row no 2 col no 0      0x500004040 row no 2 col no 4      0x500008040 row no 2 col no 8     0x50000C040 row no 2 col no 12     0x5000000C0 row no 2 col no 16  0x5000040C0 row no 2 col no 20
0x500000048 row no 2 col no 1      0x500004048 row no 2 col no 5      0x500008048 row no 2 col no 9     0x50000C048 row no 2 col no 13     0x5000000C8 row no 2 col no 17  0x5000040C8 row no 2 col no 21
0x500000050 row no 2 col no 2      0x500004050 row no 2 col no 6      0x500008050 row no 2 col no 10    0x50000C050 row no 2 col no 14     0x5000000D0 row no 2 col no 18  0x5000040D0 row no 2 col no 22
0x500000058 row no 2 col no 3      0x500004058 row no 2 col no 7      0x500008058 row no 2 col no 11    0x50000C058 row no 2 col no 15     0x5000000D8 row no 2 col no 19  0x5000040D8 row no 2 col no 23

0x500000060 row no 3 col no 0      0x500004060 row no 3 col no 4      0x500008060 row no 3 col no 8     0x50000C060 row no 3 col no 12     0x5000000E0 row no 3 col no 16  0x5000040E0 row no 3 col no 20
0x500000068 row no 3 col no 1      0x500004068 row no 3 col no 5      0x500008068 row no 3 col no 9     0x50000C068 row no 3 col no 13     0x5000000E8 row no 3 col no 17  0x5000040E8 row no 3 col no 21
0x500000070 row no 3 col no 2      0x500004070 row no 3 col no 6      0x500008070 row no 3 col no 10    0x50000C070 row no 3 col no 14     0x5000000F0 row no 3 col no 18  0x5000040F0 row no 3 col no 22
0x500000078 row no 3 col no 3      0x500004078 row no 3 col no 7      0x500008078 row no 3 col no 11    0x50000C078 row no 3 col no 15     0x5000000F8 row no 3 col no 19  0x5000040F8 row no 3 col no 23

每个4x4磁贴存储在连续的地址空间中。实际上存在用于存储瓦片的模式像第0和第4个4x4块在内存中也是连续的。

我无法连接所有东西。如果有人能提供帮助,那将是美好的。

1 个答案:

答案 0 :(得分:0)

你根本无法做你想做的事; image2d_t类型不是指针。如果您的特定实现恰好让您以某种方式使用它看起来像图像数据,它只是实现的工件,您不能期望它是可移植的,甚至可以使用下一个驱动程序版本。

也许你想要的是你可以作为缓冲区或图像访问的设备内存。如果是,请使用cl_khr_image2d_from_buffer扩展名。