Retrieve grid variable name in CUDA kernel call

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(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!