占用所有GPGPU内存并调用所有数据的内核

时间:2017-07-09 12:47:38

标签: opencl opencl-c

我需要分配尽可能多的 struct Thing ,因为GPGPU内存允许并为每个 struct Thing 调用内核。

OpenCL不允许一次分配所有 CL_DEVICE_GLOBAL_MEM_SIZE 内存 - 每个单独分配最多可以分配 CL_DEVICE_MAX_MEM_ALLOC_SIZE 。第二个通常比所有记忆少4倍。所以我决定创建4个缓冲区。

此外,您不能在两个OpenCL内核中使用指针指针以及从主机向内核传递args时,因此您无法将缓冲区数组传递给内核(因为每个缓冲区都是指向第一个结构的指针事情在数组中。)

到目前为止,我的内核代码是这样的:

kernel void workWithThings(
    constant uint64_t t1Count,
        global struct Thing * t1,
    constant uint64_t t2Count,
        global struct Thing * t2,
    constant uint64_t t3Count,
        global struct Thing * t3,
    constant uint64_t t4Count,
        global struct Thing * t4
)
{
    private ulong gid = get_global_id( 0 );
    private struct Thing * t;
    if ( gid > t1Count )
    {
        gid -= t1Count;
        if ( gid > t2Count )
        {
            gid -= t2Count;
            if ( gid > t3Count )
            {
                gid -= t3Count;
                t = & t4[ gid ];
            }
            else
            {
                t = & t3[ gid ];
            }
        }
        else
        {
            t = & t2[ gid ];
        }
    }
    else
    {
        t = & t1[ gid ];
    }

    //do the actual work:
    //t->...
}

这真的是唯一的方法吗?我觉得编写这样的代码非常愚蠢。请帮忙。

0 个答案:

没有答案