Is --cuda-path necessary for generating an AST only?

I’m currently using clang to generate the syntax tree of a CUDA code, the compilation itself is done by NVRTC. The syntax tree is necessary to create wrappers for C#. The toolkit is not installed, but placed in some directory.

For that reason I use the following basic parameters

“-nocudalib” // because of no linking
“-nogpulib” // don’t know whats the difference to nocudalib
“-fsyntax-only” // For the AST only
“–cuda-device-only” // The file only contains device code.
“–cuda-gpu-arch=sm_50”
$“–cuda-path={cudaToolkitPath}”
“-std=c++17”

A few questions came up and it would be nice if someone has some answers to these questions:

  1. One problem is that I don’t understand why I need --cuda-path at all when I want the AST only (-fsyntax-only)?
  2. Do I need to set the --cuda-path-ignore-env if the --cuda-path is set?
  3. I seems that the --cuda-path requires a bin folder inside. Since I’m using NVRTC this are the only binaries I need to deliver with my package.
  4. What is the difference between -nogpulib and -nocudalib?

I generally see no reason for the --cuda-path for the AST only mode and I couldn’t find much information around it.

Are there any hints on this to to it even better?

Thanks
Martin

I think it is needed because headers from CUDA could impact pre-processing and thus the actual code the front end is gonna see.

@shiltian: Thanks for the reply. I would be completely fine with the headers but I see no reason for the bin folder (where NVCC etc is inside).

I think that is a sanity check in the compiler driver because other programming models like OpenMP will call some tools (basically ToolChain) provided by CUDA.

1 Like

Correct. Clang implicitly includes __clang_cuda_runtime_wrapper.h which then includes cuda_runtime.h; the latter is provided by the CUDA ToolKit.

The --cuda-path= and --cuda-path-ignore-env options are queried by CudaInstallationDetector::CudaInstallationDetector() in clang/lib/Driver/ToolChains/Cuda.cpp. Perusing that code might help reveal what all it is used for.

1 Like

Clang pre-includes quite a few headers that are necessary for compiling CUDA source.

  • Do I need to set the --cuda-path-ignore-env if the --cuda-path is set?

No. Explicit --cuda-path wins.

  • I seems that the --cuda-path requires a bin folder inside. Since I’m using NVRTC this are the only binaries I need to deliver with my package.

It’s a 'sanity check by clang driver. The driver assumes specific CUDA SDK directory layout for finding the tools, includes and libdevice bitcode. Not all the parts may be strictly necessary for the syntax-only compilation, but the check is currently always the same. I would not object to a patch relaxing this to make various tooling use cases easier.

  • What is the difference between -nogpulib and -nocudalib?

None, they are aliases:
def : Flag<["-"], "nocudalib">, Alias<nogpulib>;

1 Like

Thank you all for the detailed explanation.

@Artem-B: I think it would help relaxing it a bit because now it is shown as an error although not needed.

Just as a background, I had to rename the bin folder since it is exluded via .gitignore, so I renamed it to something else. But I think I’ll find a way around.

One workaroung I’ve suggested in the past is to create a fake CUDA installation directory structure, populate it with symlinks to the real directories/files and point --cuda-path there.

I wonder if we could do that via clang’s virtual filesystem without having to create the actual directory.