Clang driver for OpenMP target offloading

Hi,

I am having some trouble to understand how the clang driver works for OpenMP offloading.

For example, if I run the following command (with the -v flag):

clang -v -g -fopenmp offloading_success.c -o offloading_success

I can see the invocations that clang does and if I run those command one by one I can successfully compile my program.

Now, if I do the same but with the offloading option, as in the following command:

clang -v -g -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda offloading_success.c -o offloading_success

the command works, compiles correctly, and when I run the program, it successfully run on the device.
However, if I show the invocations with “-v” and try to run the commands one by one it does not work and in particular I get an error with the last command which is the linking part with “ld”.
The error i get is the following:

/usr/bin/ld: cannot open linker script file /tmp/offloading_success-2b4739.lk: No such file or directory

Where is this “.lk” file generated? Is there a missing commands in the invocations?

I attached a file with the full invocation.

Thanks!
Best,
Simone

output.txt (15.2 KB)

Hi Simone,

you are more likely to get answers to frontend questions asking on cfe-dev. However, your output shows that you are using clang-ykt which isn't supported upstream so this is not the right place for your questions. Nevertheless, I'll answer some because the same "problem" will arise with (upstream) trunk.

Hi,

I am having some trouble to understand how the clang driver works for
OpenMP offloading.

For example, if I run the following command (with the -v flag):

clang -v -g -fopenmp offloading_success.c -o offloading_success

I can see the invocations that clang does and if I run those command
one by one I can successfully compile my program.

Just to clarify: This will compile but will fallback to run on the host because the arguments don't specify which device to compile for.

Now, if I do the same but with the offloading option, as in the
following command:

clang -v -g -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda
offloading_success.c -o offloading_success

the command works, compiles correctly, and when I run the program, it
successfully run on the device.

(which would not be the case for upstream trunk yet...)

However, if I show the invocations with "-v" and try to run the
commands one by one it does not work and in particular I get an error
with the last command which is the linking part with "ld".
The error i get is the following:

/usr/bin/ld: cannot open linker script file
/tmp/offloading_success-2b4739.lk [1]: No such file or directory

Where is this ".lk" file generated? Is there a missing commands in the
invocations?

The linker script is generated by Clang's driver (both in clang-ykt and trunk) and is deleted after its usage which is the default for temporary files. If you want to inspect the intermediate files, I suggest adding --save-temps which will dump a bunch of files to the current directory. (AFAIK this will result in more files than generated by default so that developers have more intermediate steps to look at.)

Cheers,
Jonas

Hi Jonas,

thanks for the answer.
For now I can use the “–save-temps” flag to keep my investigation.

Do you know what’s the timeline for integrating offloading for NVidia GPUs upstream?
I remember seeing a big patch for integrating OpenMP target generation in the clang driver and I thought it was already accepted and committed, but I might be wrong.

Thanks.
Simone

Hi Simone,

I'm not aware of a timeline, it's ready when all necessary patches are merged. One large missing piece is the device runtime.

Jonas