使用具有自定义数据类型的async_work_group_copy [英] Using async_work_group_copy with a custom data type

查看:129
本文介绍了使用具有自定义数据类型的async_work_group_copy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用async_work_group_copy在openCL中将某些数据从__global复制到__local.问题是,我没有使用内置数据类型.

I need to copy some data from __global to __local in openCL using async_work_group_copy. The issue is, I'm not using a built-in data type.

我尝试过的代码片段如下:

The code snip of what I have tried is as follows:

typedef struct Y
{
    ...
} Y;

typedef struct X
{
    Y y[MAXSIZE];
} X;

kernel void krnl(global X* restrict x){ 
    global const Y* l = x[a].y;

    local Y* l2;

    size_t sol2 = sizeof(l);

    async_work_group_copy(l2, l, sol2, 0);
}

其中'a'只是int的向量.此代码不起作用,特别是因为gen_type不是内置代码.规格(1.2)表示:

where 'a' is just a vector of int. This code does not work, specifically because the gen_type is not a built-in one. The specs (1.2) says:

我们使用通用类型名称gentype指示内置数据 除非另有说明,否则类型...作为参数的类型.

We use the generic type name gentype to indicate the built-in data types ... as the type for the arguments unless otherwise stated.

那么我该如何声明该数据类型?

so how do I otherwisely state this data type?

推荐答案

OpenCL async_work_group_copy()设计用于复制基本数据类型的N个元素.但是,它并不真正知道要复制什么.因此,您可以告诉它复制N个字节,其中包含内部的任何类型(包括结构).类似于memcpy().

OpenCL async_work_group_copy() is designed to copy N elements of a basic data type. However it does not really know what is being copied. So you can tell it to copy N bytes, containing any type inside (including structs). Similar to memcpy().

您可以这样做:

kernel void krnl(global X* restrict x){ 
    global const Y* l = x[a].y;
    local Y l2;

    size_t sol2 = sizeof(Y);

    async_work_group_copy((local char *)&l2, (global char *)l, sol2, 0);
}

但是,请记住,您需要在内核端显式声明本地内存,或者在API端以动态方式声明本地内存,然后将指针传递给本地内存. 您不能不进行任何初始化就直接创建一个本地指针并在那里复制. (请参阅我的代码)

However, remember that you need to declare local memory explicitly in side the kernel, or dinamically from the API side and pass a pointer to local memory. You can't just create a local pointer without any initialization and copy there. (see my code)

这篇关于使用具有自定义数据类型的async_work_group_copy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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