RAJA
RAJA copied to clipboard
Can RAJA plugins be made easier to understand and use?
Is there a way to add a plugin at run time via calling a method (note that I do not want to deal with shared objects)? All I can find is a way to do it at compile time:
static RAJA::util::PluginRegistry::add<ProfilePlugin> P("Profile", "Profiles RAJA loops");
This is so convoluted to me - I don't know what in the world is safe to do inside a plugin class. Here is what I am trying to do:
class ProfilePlugin : public RAJA::util::PluginStrategy {
public:
ProfilePlugin(const ProfilePlugin&) = delete;
static ProfilePlugin& getInstance() {
static ProfilePlugin s_plugin;
return s_plugin;
}
void preLaunch(const RAJA::util::PluginContext& p) override {
if (m_active) {
if (p.platform == RAJA::Platform::device) {
// start recording with nvtx or roctx using m_name as the label
}
}
}
void postLaunch(const RAJA::util::PluginContext& p) override {
if (m_active) {
if (p.platform == RAJA::Platform::device) {
// end recording with nvtx or roctx using m_name as the label
m_name = "";
}
}
}
void enable() {
m_active = true;
}
void disable() {
m_active = false;
}
void setName(std::string name) {
m_name = name;
}
private:
ProfilePlugin() = default;
bool m_active = false;
std::string m_name = "";
};
// It would be nice just to be able to register my plugin myself anywhere in my application.
RAJA::util::PluginRegistry::add(ProfilePlugin::getInstance(), "Profile", "Profile RAJA loops");
// Right before a RAJA loop
ProfilePlugin::getInstance().setName("My loop");
// At various points in my application
ProfilePlugin::getInstance().enable();
// Do some work
ProfilePlugin::getInstance().disable();
My guess is that this will not work with RAJA because of the singleton pattern. I can think of ways around this, but they are much more convoluted. I've been wanting to use RAJA plugins for a while and I think I could contribute some really useful ones to RAJA and or CHAI, but because it is so inflexible, I have written my own layer in CARE to do what I need to.
@adayton1 was the discussion of this at a RAJA meeting a while ago sufficient to resolve your issue? If not, do you have specific suggestions for changes you would like to see?
I have not had a chance to work on this (I'm still stuck on updating BLT/RAJA/Umpire/CHAI and a host of other libraries with outdated build systems that needed to be changed to build with C++14). But what would be helpful is updating the documentation for how to use addNode manually (that way we could pass a pointer to a class that has a private constructor, e.g. a singleton, to be registered).