You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Create a build-time mapping of module name strings to module types #548
To support runtime configuration, and possibly #546, we need a way to convert between the strings given in a configuration file ("hashed_perceptron", "lru", "ip_stride", etc.) to the type of the module object. As a stretch goal, we should see if we can map both directions.
There are a number of possible options, not all of which will work for our purposes.
Some solutions use __FUNCTION__ and parse the resulting string. (link)
Since a string will be provided, it could be possible to create a constexpr function that lexicographically iterates through all possible identifiers, and returns a truthy value only for those which match a valid identifier. That might be totally off into the weeds, though.
Any solution must be generated at build-time, not at configure time, and callable at runtime.
Another option may be a global map.
Every module could have a static call to insert itself into the map, called once somewhere within its .h or .cc file.
A fully constructed map should allow us to associate a string with the module.
I know it might not be great for runtime, but we could then use typeid to do a reverse lookup to convert types to strings if necessary (or modules could have another function that just returns a predefined string when called).
This is something that seems like could be scaled well and shouldn't run into any weird edge cases. We could also assert that all entries into the map are unique, so if we have a collision we can quit out.
Getting the mangled name for the module also works if you use typeid(module).name(), but demangling doesn't seem like it has any great solutions if we want to avoid boost and support clang and MSVC.
Do we necessarily need to map the strings to types? What are we trying to accomplish by knowing the type? If there were a way to have a function achieve what we want, then maybe we could map strings to function objects / functors?
Of course, you have talked about virtualizing the member hooks, which would mean we could just pass around a prefetcher* and a replacement*, but we still need to relate the string to a type to instantiate the subclass.
What I am saying is maybe the instantiation can be passed off to something the prefetcher can insert into the map. Not sure exactly what, but maybe a templated function object or something like that? Then invoke that particular entry in the map to construct a specific module.
Activity
maccoymerrell commentedon Nov 16, 2024
Does here help at all? typeid(module).name() seems like it might work, but I am not sure.
maccoymerrell commentedon Nov 16, 2024
Another option may be a global map.
Every module could have a static call to insert itself into the map, called once somewhere within its .h or .cc file.
A fully constructed map should allow us to associate a string with the module.
I know it might not be great for runtime, but we could then use typeid to do a reverse lookup to convert types to strings if necessary (or modules could have another function that just returns a predefined string when called).
This is something that seems like could be scaled well and shouldn't run into any weird edge cases. We could also assert that all entries into the map are unique, so if we have a collision we can quit out.
Getting the mangled name for the module also works if you use typeid(module).name(), but demangling doesn't seem like it has any great solutions if we want to avoid boost and support clang and MSVC.
ngober commentedon Nov 18, 2024
I'm dubious regarding
typeid. Its support has always been shaky, and the output format isn't very friendly.We could modify the module base class constructors to the following:
... and then somehow map the strings to types. It's not clear to me how we would do that though. I'd have to think about it longer.
maccoymerrell commentedon Nov 18, 2024
Do we necessarily need to map the strings to types? What are we trying to accomplish by knowing the type? If there were a way to have a function achieve what we want, then maybe we could map strings to function objects / functors?
ngober commentedon Nov 18, 2024
We need to know the type so that we can instantiate the
cache_builderorcore_buildertemplate parameters.maccoymerrell commentedon Nov 18, 2024
Can we use templates during runtime?
ngober commentedon Nov 18, 2024
No, but we can do something clever like:
Of course, you have talked about virtualizing the member hooks, which would mean we could just pass around a
prefetcher*and areplacement*, but we still need to relate the string to a type to instantiate the subclass.maccoymerrell commentedon Nov 18, 2024
What I am saying is maybe the instantiation can be passed off to something the prefetcher can insert into the map. Not sure exactly what, but maybe a templated function object or something like that? Then invoke that particular entry in the map to construct a specific module.