[Apache TVM Discuss] [Development/pre-RFC] [pre-RFC] Name mangling in IRModules

2022-06-10 Thread Mark Shields via Apache TVM Discuss
Name supplies usually have both a cache lookup: ``` name_supply.UniqueGlobalFor("__main__") ``` and a hinted fresh name generator: ``` name_supply.FreshGlobalWithPrefix("my_module", "my_var", "any_other_prefix") ``` --- [Visit Topic](https://discuss.tvm.apache.org/t/pre-rfc-name-mangling-i

[Apache TVM Discuss] [Development/pre-RFC] [pre-RFC] Name mangling in IRModules

2022-06-09 Thread tqchen via Apache TVM Discuss
> How would we enforce this fixed global symbol? Also from name supply? When a function need to fix a global name, it will attach an attr "global_symbol" with the name. That attr can be used say by BYOC to pick a name, attach the global symbol, so followup passes respect that constraint. We c

[Apache TVM Discuss] [Development/pre-RFC] [pre-RFC] Name mangling in IRModules

2022-06-09 Thread Andrew Reusch via Apache TVM Discuss
[quote="mbs-octoml, post:6, topic:12944"] Other than the plumbing, is there an issue with threading a name supply so that globals have a unique and appropriately hinted name at birth? [/quote] One question in my mind is: there are some names which must be stable e.g. `__main__`, `get_c_metadat

[Apache TVM Discuss] [Development/pre-RFC] [pre-RFC] Name mangling in IRModules

2022-06-09 Thread tqchen via Apache TVM Discuss
[quote="mbs-octoml, post:6, topic:12944"] (While doing this we could also ensure names begin in GlobalVar form instead of String form, since the latter causes multiple GlobalVars to be created with the same name [/quote] Indeed the `name_hint` field in GlobalVar is supposed to work for that p

[Apache TVM Discuss] [Development/pre-RFC] [pre-RFC] Name mangling in IRModules

2022-06-09 Thread Mark Shields via Apache TVM Discuss
Other than the plumbing, is there an issue with threading a name supply so that globals have a unique and appropriately hinted name at birth? It's not too hard to support name supply splitting such that names can be drawn from independent supplies without collision. It is also possible to refi

[Apache TVM Discuss] [Development/pre-RFC] [pre-RFC] Name mangling in IRModules

2022-06-09 Thread Andrew Reusch via Apache TVM Discuss
i agree with that direction, but I think to do that requires us to merge the IRModules so that mangling transforms are applied globally rather than to just a part of the program. do you agree? --- [Visit Topic](https://discuss.tvm.apache.org/t/pre-rfc-name-mangling-in-irmodules/12944/5)

[Apache TVM Discuss] [Development/pre-RFC] [pre-RFC] Name mangling in IRModules

2022-06-09 Thread tqchen via Apache TVM Discuss
Agree that mangling should be deferred as long as possible. I think the keys is not to push all mangling to a certain stage, but have a clear spec about what can be mangled, and what cannot --- [Visit Topic](https://discuss.tvm.apache.org/t/pre-rfc-name-mangling-in-irmodules/12944/4) to

[Apache TVM Discuss] [Development/pre-RFC] [pre-RFC] Name mangling in IRModules

2022-06-09 Thread Andrew Reusch via Apache TVM Discuss
One related thing was that we intended to consolidate all of the different functions into one IRModule (e.g. those passed to external codegen with those passed to ordinary TVM codegen). If we had done that, we could probably do the following: - If a Relay-to-Runtime hook is used, find a way t

[Apache TVM Discuss] [Development/pre-RFC] [pre-RFC] Name mangling in IRModules

2022-06-09 Thread tqchen via Apache TVM Discuss
This is somewhat related to linkage itself. Specifically, depending on the progress of lowering, there can be a need to decide on name earlier if some of the external codegen involved(e.g. BYOC that pre-decides on "global_symbol" of the name, or user specifies that they would like to "lock"

[Apache TVM Discuss] [Development/pre-RFC] [pre-RFC] Name mangling in IRModules

2022-06-09 Thread Andrew Reusch via Apache TVM Discuss
Hi all, In [[mini-RFC] Name mangling in AOT](https://discuss.tvm.apache.org/t/mini-rfc-name-mangling-in-aot/9907), we discussed ways to accommodate the `runtime::Module` tree in an embedded environment, where we prefer to call functions directly in the generated C using their symbol name rat