Suggest to add PC of kernel launch

Hi, I found that when I subscribe callbacks for kernel launch, the callback data Sanitizer_LaunchData doesn’t include the PC of the kernel. How can I get the current launched kernel’s start PC? If it is impossible now, could you please add this feature in the future version of santizier API?

Hi, I found two ways to get the pc of the launched kernel,

  1. using sanitizerGetFunctionPcAndSize
  2. or sanitizerPatchInstructions(SANITIZER_INSTRUCTION_BLOCK_ENTER, module, "sanitizer_block_enter_callback").

However, I got different values from them. By instrumenting block enter(the 2nd way), I got a PC. It is the correct PC because I also collect the device function calls and print their PCs. The device function calls’ PC is close to the second way’s results. And by calculating the offset of the device function calls, I can successfully get the corresponding sass code. As to the first way’s result, it is quite different from the device function calls.

The first method should be the correct one. Are you making the call before or after calling sanitizerPatchModule?

I tried to call sanitizerGetFunctionPcAndSize in the SANITIZER_CBID_LAUNCH_BEGIN and SANITIZER_CBID_LAUNCH_END branch in sanitizer_subscribe_callback . Both of them print out the same value and it is not the same as the PC got from the block enter.

Does sanitizerGetFunctionPcAndSize return the static PC or runtime PC?

Can you try sanitizerGetFunctionPcAndSize prior to sanitizerPatchModule and check if that fixes the issue?

It looks like the API returns the entry block patch PC after patching. I opened a bug to fix that behavior.

I can’t do that.

The sanitizerGetFunctionPcAndSize needs launchdata->module, which has to be there after SANITIZER_CBID_LAUNCH_BEGIN, as its argument. The SANITIZER_CBID_RESOURCE_MODULE_LOADED is always prior to SANITIZER_CBID_LAUNCH_BEGIN, and I need the sanitizerPatchModule to instrument block enter to get the correct PC to compare with the PC got from sanitizerGetFunctionPcAndSize.

I am not sure to follow the logic of why the API cannot be called prior to patching.

In that case, relying on BLOCK_ENTER address can be used as a workaround until the bug is fixed in the next release.

1 Like