[PATCH] D44435: CUDA ctor/dtor Module-Unique Symbol Name

Simeon Ehrig via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 7 02:13:23 PDT 2018


SimeonEhrig added a comment.

In https://reviews.llvm.org/D44435#1088019, @tra wrote:

> Perhaps we should take a step back and consider whether this is the right approach to solve your problem.
>
> If I understand it correctly, the real issue is that you repeatedly recompile the same module and cling will only use the function from the first module it's seen it in. Unlike regular functions that presumably remain the same in all the modules they are present in, CUDA constructors do change and you need cling to grab the one from the most recent module.
>
> This patch deals with the issue by attempting to add a unique sufix. Presumably cling will then generate some sort of unique module name and will get unique constructor name in return. The down side of this approach is that module name is something that is derived from the file name and the functionality you're changing is in the shared code, so you need to make sure that whatever you implement makes sense for LLVM in general and that it does what it claims it does. AFAICT, LLVM has no pressing need for the unique constructor name -- it's a function with internal linkage and, if we ever need to generate more than one, LLVM is capable of generating unique names within the module all by itself. The patch currently does not fulfill the "unique" part either.
>
> Perhaps you should consider a different approach which could handle the issue completely in cling. E.g. You could rename the constructor in the module's IR before passing it to JIT. Or you could rename it in PTX (it's just text after all) before passing it to driver or PTXAS.


You are right. The clang commit is not the best solution. So, we searched for another solution and found one. The solution is similar to your suggestion. We found a possibility to integrate a llvm module pass, which detects the symbols `__cuda_module_ctor` and `__cuda_module_dtor` and append the module name to the symbol, before the llvm IR will be generated. So, we were able to move the solution from clang to cling, which is better for both projects.


https://reviews.llvm.org/D44435





More information about the cfe-commits mailing list