[cfe-dev] Retrieve grid variable name in CUDA kernel call

于 秋沣 via cfe-dev cfe-dev at lists.llvm.org
Thu Dec 28 22:51:00 PST 2017

Hi all,

I'm trying to retrieve the grid variable name inside a CUDA kernel call. For example, I have the following CUDA code:

    dim3 Dg(nelr / BLOCK_SIZE_1), Db(BLOCK_SIZE_1);

    cuda_initialize_variables<<<Dg, Db>>>(nelr, variables);

    getLastCudaError("initialize_variables failed");

What I need is to find the name of the grid variable, in this case, Dg.
Currently, I'm able to find the CUDAKernelCallExpr, and get the CallExpr pointer by using the following code:
    CUDAKernelCallExpr *kce = dyn_cast<CUDAKernelCallExpr>(stmt);
    CallExpr *kernelConfig = kce->getConfig();
    Expr *grid = kernelConfig->getArg(0);
Now I'm stuck at the problem is how to find the actual name of the grid, in this case, "Dg".

Here is the AST dump of the Expr *grid:
CXXConstructExpr 0x564e5305f928 'dim3':'struct dim3' 'void (const struct dim3 &) throw()'
`-ImplicitCastExpr 0x564e5305f910 'const dim3':'const struct dim3' lvalue <NoOp>
  `-DeclRefExpr 0x564e5305f7b0 'dim3':'struct dim3' lvalue Var 0x564e5305f468 'Dg' 'dim3':'struct dim3'

Thank you in advance!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20171229/a29a64ca/attachment.html>

More information about the cfe-dev mailing list