This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Add function for setting LIBOMPTARGET_INFO at runtime
ClosedPublic

Authored by jhuber6 on Apr 19 2021, 9:43 AM.

Details

Summary

This patch adds a new runtime function __tgt_set_info_flag that allows the
user to set the information level at runtime without using the environment
variable. Using this will require an extern function, but will eventually be
added into an auxilliary library for OpenMP support functions.

This patch required moving the current InfoLevel to a global variable which must
be instantiated by each plugin. Communication between the host and device is
done through the __tgt_rtl_set_info_flag which should be defined by any plugin
that want's to use the information level.

Diff Detail

Event Timeline

jhuber6 created this revision.Apr 19 2021, 9:43 AM
jhuber6 requested review of this revision.Apr 19 2021, 9:43 AM
This revision is now accepted and ready to land.Apr 19 2021, 9:50 AM
jhuber6 updated this revision to Diff 339387.Apr 21 2021, 2:35 PM
jhuber6 edited the summary of this revision. (Show Details)

Changing the interface, previously each plugin / file had its own version of the static variable, now to change it we need a global atomic variable to represent it. Whenever the value is updated it also needs to be sent to the currently loaded plugins if they support it. I added the __tgt_rtl_set_info_flag function to the plugin library for this purpose.

This revision was landed with ongoing or failed builds.Apr 22 2021, 9:48 AM
This revision was automatically updated to reflect the committed changes.

Surprising amount of code here, probably because it changes from one function to some code * number plugins.

Was the idea to allow directly writing to static uint32_t InfoLevel = 0;, which is inconvenient when it's a static function? If so, that is still achievable in header only fashion without adding global variables to program scope, e.g. by returning a reference from getInfoLevel and adding a setter function, or going with a detail function that is called by the getter and setter.

Surprising amount of code here, probably because it changes from one function to some code * number plugins.

Was the idea to allow directly writing to static uint32_t InfoLevel = 0;, which is inconvenient when it's a static function? If so, that is still achievable in header only fashion without adding global variables to program scope, e.g. by returning a reference from getInfoLevel and adding a setter function, or going with a detail function that is called by the getter and setter.

The problem I had was that in libomptarget there wasn't a single instance of #include "Debug.h". This meant that there were about three different versions of InfoLevel. This meant if the variable was static it wouldn't set everyone's version of InfoLevel when called from the function. It might've been a better solution to just require that Debug.h is included only once per library, then use a method like you described. It would certainly be nicer to not require setting the extern variables for each plugin, which is what I originally removed.

The problem I had was that in libomptarget there wasn't a single instance of #include "Debug.h". This meant that there were about three different versions of InfoLevel. This meant if the variable was static it wouldn't set everyone's version of InfoLevel when called from the function. It might've been a better solution to just require that Debug.h is included only once per library, then use a method like you described. It would certainly be nicer to not require setting the extern variables for each plugin, which is what I originally removed.

I think that was collateral damage from getInfoLevel being static. Changing that to just inline will mean a single copy per shared library, which seems to be the right semantics. Probably still want the local variable to be atomic qualified though.

The problem I had was that in libomptarget there wasn't a single instance of #include "Debug.h". This meant that there were about three different versions of InfoLevel. This meant if the variable was static it wouldn't set everyone's version of InfoLevel when called from the function. It might've been a better solution to just require that Debug.h is included only once per library, then use a method like you described. It would certainly be nicer to not require setting the extern variables for each plugin, which is what I originally removed.

I think that was collateral damage from getInfoLevel being static. Changing that to just inline will mean a single copy per shared library, which seems to be the right semantics. Probably still want the local variable to be atomic qualified though.

Seems reasonable. I'd probably have another function that returns a reference to the internal atomic variable, then getInfoLevel() just returns the value inside the atomic. Should this be a another review? Or a revert + fix.

Seems reasonable. I'd probably have another function that returns a reference to the internal atomic variable, then getInfoLevel() just returns the value inside the atomic.

Sounds good.

Should this be a another review? Or a revert + fix.

I don't think anything is broken here so would suggest another patch + review on top, leaving this in place. Plus that way if the header only version doesn't work out so well we still have this fix.