This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP][libomptarget] Init device when printing device info

Authored by kevinsala on Mar 14 2023, 12:34 PM.



Make sure the device is ready and initialized when printing the device information

Fixes #61392

Diff Detail

Event Timeline

kevinsala created this revision.Mar 14 2023, 12:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2023, 12:34 PM
kevinsala requested review of this revision.Mar 14 2023, 12:34 PM

This patch is still missing a test.

Will this solve the problem or mitigate the error?

Will this solve the problem or mitigate the error?

I also fear this will just make the script not crash but also useless.
That said, we probably want this regardless and then a patch to initialize stuff in the omp-device-info executable.
Eventually one test will be enough, given we don't have unit tests for this stuff yet.

kevinsala updated this revision to Diff 505415.Mar 15 2023, 2:58 AM

Explicitly initializing devices from llvm-omp-device-info tool.

The initial patch should fix the crash for the llvm-omp-device-info case, or any other case calling __tgt_print_device_info. I saw lazy initialization of devices in other API calls and tried to reproduced the same behavior. Anyway, initializing them explicitly from the tool seems more clean, so I just updated the patch with it.

Regarding the usefulness of this tool, it's true that it does not print anything relevant since nextgen plugins are not printing any information for the moment. I'm going to open a new patch to print at least the information reported by old plugins.

jplehr added a subscriber: jplehr.Mar 15 2023, 4:49 AM

There is also the option to auto initialize the devices at the plugin level when GenericPluginTy::getDevice(N) is called and device N is in a uninitialized state. In my opinion, that would be the safest option and would cover all cases. But it will require implementing a similar mechanism from libomptarget level to guarantee the device creation and initialization is tread-safe and serialized (i.e., std::call_once in libomptarget).

jdoerfert added inline comments.Mar 20 2023, 11:32 AM

Isn't this the same code as in __tgt_print_device_info? Why do we need this?

kevinsala added inline comments.Mar 21 2023, 2:18 AM

From previous comments I understood it was better to explicitly initialize devices from the llvm-omp-device-info. Is it preferable this explicit initialization or a lazy initialization by __tgt_print_device_info?

kevinsala updated this revision to Diff 520691.May 9 2023, 7:12 AM

Updating patch to initial version. We make sure in libomptarget that the device is initialized (ready) when printing its information. Together with, it should fix the llvm-omp-device-info command.

jhuber6 accepted this revision.May 9 2023, 7:13 AM
This revision is now accepted and ready to land.May 9 2023, 7:13 AM