[cfe-dev] [LLVMdev] OpenCL support

Villmow, Micah Micah.Villmow at amd.com
Thu Dec 9 10:38:44 PST 2010



> -----Original Message-----
> From: Anton Lokhmotov [mailto:Anton.Lokhmotov at arm.com]
> Sent: Thursday, December 09, 2010 2:14 AM
> To: cfe-dev at cs.uiuc.edu
> Cc: Villmow, Micah
> Subject: Re: [cfe-dev] [LLVMdev] OpenCL support
> 
> > Also, don't forget there is a difference between local int a and
> local
> > int* a, one is just a pointer to some pre-allocated memory and the
> > other actually requires memory to be allocated.
> Correct.
> 
> > Any implementation should ignore local pointers variables and only
> deal
> > with local scalar, vector and array variables.
> Sorry, I'm not sure what do you mean by this.
> 
> int f()
> {
>     int * __local p; // __local pointer to __private memory
>     __local int * p; // __private pointer to __local memory
> }
> 
> Both examples seem reasonable to me.
[Villmow, Micah] Yeah, but since neither one actually requires any memory allocation, there does not need to be any special processing. It is only when memory allocation for the local address space inside of a kernel occurs that needs to be handled differently.
> 
> 
> > [Villmow, Micah] A kernel with locally defined variables cannot call
> > another kernel with local variables. This is illegal in OpenCL
> because
> > when a kernel calls another kernel, that kernel is treated as a
> normal
> > function. A normal function is not allowed to have local variables
> > declared inside the body. Basically this restricts locally defined
> > variables in a kernel body to the top level kernel function only.
> This sounds reasonable, but, to be precise, the specification says:
> "The
> behavior of calling kernel functions with variables declared inside the
> function with the __local or local qualifier from other kernel
> functions is
> implementation-defined."  In principle, an implementation can
> statically
> compute the call graph of the kernel function being compiled and
> conflate
> local memory allocation requirements from different kernel functions in
> the
> graph...
[Villmow, Micah] Ok I see your point. We make it illegal because of these two lines in the spec.
"It is just a regular function call if a __kernel function is called by another kernel 
function. "
and
"This qualifier can be used with arguments to functions (including __kernel functions) declared as pointers, or 
with variables declared inside a __kernel function."

Since having a kernel call another kernel turns the second kernel into a regular function call, we interpret it as being illegal to allocate local memory in a non-top level kernel. But your view is also valid.
> 
> Regards,
> Anton.
> 
> 
> 






More information about the cfe-dev mailing list