This is an archive of the discontinued LLVM Phabricator instance.

[PPCGCodeGen] Differentiate kernels based on their parent Scop

Authored by singam-sanjay on Jul 9 2017, 1:20 AM.



Add a sequence number that identifies a ptx_kernel's parent Scop within a function to it's name to differentiate it from other kernels produced from the same function, yet different Scops.

Kernels produced from different Scops can end up having the same name. Consider a function with 2 Scops and each Scop being able to produce just one kernel. Both of these kernels have the name "kernel_0". This can lead to the wrong kernel being launched when the runtime picks a kernel from its cache based on the name alone. This patch supplements D33985, by differentiating kernels across Scops as well.

Previously (even before D33985) while profiling kernels generated through JIT e.g. Julia, kernels associated with different functions, and even different SCoPs within a function, would be grouped together due to the common name. This patch prevents this grouping and the kernels are reported separately.

Diff Detail


Event Timeline

singam-sanjay created this revision.Jul 9 2017, 1:20 AM

@grosser I tried what you suggessted,

   Value *KernelString = Builder.CreateGlobalStringPtr(ASMString, Name);
-  Value *NameString = Builder.CreateGlobalStringPtr(Name, Name + "_name");
+  Value *NameString = Builder.CreateGlobalStringPtr(KernelString->getName(),
+                                                    Name + "_name");
   Value *GPUKernel = createCallGetKernel(KernelString, NameString);

KernelString->getName() evaluated to "" and KernelString->hasName() returns false. I think this is because the IR has still not been code-generated. Please correct me if I'm wrong.

Also, even if KernelString->getName() were to return its unique name in IR,

  1. The ptx_kernel in ASMString might still clash with other kernels since its name was set before KernelString's.
  2. The name given to polly_getKernel might look like "kernel_0.1" whereas the name of the kernel's actually "kernel_0"
grosser accepted this revision.Jul 10 2017, 10:25 PM

LGTM. Thanks for this patch!

6 ↗(On Diff #105754)

Please update clang to the latest version. Then this formatting difference should go away.

This revision is now accepted and ready to land.Jul 10 2017, 10:25 PM

And I forgot. Please run -instnamer of the test case first, such that the instructions in the test case are named.

  1. Instructions and basic blocks of new test case have been named.
  2. Removed format error with unittests/ScopPassManager/PassManagerTest.cpp
This revision was automatically updated to reflect the committed changes.