如何在Opencl中编写嵌套循环 [英] How to write Nested loop in Opencl

查看:300
本文介绍了如何在Opencl中编写嵌套循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原始C代码是



The original C code is

void GaussianArray(float* Gauss, int variable){
    for(int i = 1; i < variable; i++ )
    {
        Gauss[i] = 1;
        for(int j = i - 1; j > 0; j-- )
        {
            Gauss[j] += Gauss[j - 1];
        }
    }
}





------------ -----------------------------------------

我我试图制作opencl内核代码。

如何将上述函数更改为内核?



-----------------------------------------------------
I'm trying to make opencl kernel code.
how to change above function to kernel?

推荐答案

你误解了计算中非常基本的东西。首先,OpenCL不是一种语言,这是一个框架: http://en.wikipedia.org/wiki/OpenCL [ ^ ]。

所以,首先,C语言仍然是C语言。第二:高级语言语言生成相同的代码,对于内核与否,无关紧要。特别是,函数体的代码在堆栈上工作,它总是可用的,以及堆栈指针。唯一的问题是第一个参数,指针:它应该指向内存中的有效点。但这是调用代码的问题,而不是你显示的代码,这很好。



-SA
You misunderstand something very basic in computing. First, OpenCL is not a language, this is a framework: http://en.wikipedia.org/wiki/OpenCL[^].
So, first, the C language remains C language. Second: high-level languages languages produce the same code, for kernel or not, does not matter. In particular, the code of the body of the function works on stack, which is always available, as well as the stack pointer. The only problem is the first parameter, the pointer: it should point to the valid point in memory. But this is a matter of calling code, not the code you show, which is just fine.

—SA


这篇关于如何在Opencl中编写嵌套循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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