[cfe-dev] Determine CUDA qualifiers in AST

Peter Collingbourne peter at pcc.me.uk
Thu Jun 16 08:53:30 PDT 2011


On Thu, Jun 16, 2011 at 03:19:34PM +0000, Felix Schmitt wrote:
> I used the following code:
> void HandleTranslationUnit(ASTContext &C) {
> ...
> 
> for (DeclContext::decl_iterator
>                 D = C.getTranslationUnitDecl()->decls_begin(),
>                     DEnd = C.getTranslationUnitDecl()->decls_end();
>                     D != DEnd;
>                     ++D)
>             {
>                 FunctionDecl *FD;
>                 Stmt *Body;
>                 if ((FD = dyn_cast<FunctionDecl > (*D)) != 0/)
>                 {
>                     if (FD->hasAttr<CUDAGlobalAttr>())
>                         std::cout << "Found __global__ qualifier";
> }
> }
> }
> 
> on the file my_kernel.cu:
> 
> #include <cuda_runtime.h>
> 
> __global__
> void kernel(int *a)
> {
> 	int tx = blockIdx.x * blockDim.x + threadIdx.x;
> }
> 
> However, no message is written.
> My diagnostic printer prints:
> 
> Diagnostics: 
> my_kernel.cu:6:11: error: use of undeclared identifier 'blockIdx'
> my_kernel.cu:6:24: error: use of undeclared identifier 'blockDim'
> my_kernel.cu:6:37: error: use of undeclared identifier 'threadIdx'
> 
> Can this have anything to do with it?

Assuming you are using the NVIDIA header files, you should add
-D__CUDACC__ to your frontend command line.  This will cause the
headers to both define the __global__ (etc.) macros correctly and
declare the blockIdx (etc.) variables.

Thanks,
-- 
Peter



More information about the cfe-dev mailing list