We are in the progress of refactoring the codebase to introduce a unified infra. While most of the current code refactoring is wrt to the c++ side without touching the frontends, it would be great for us to start thinking about code organizations in the python side.
This RFC discusses the following points:
Q1: Whether to Reflect the C++ folder structure
As we start to introduce more concepts into the project, it is no longer sustainable to continue put things under the root scope.
One potential solution is to make the python project roughly
reflect the C++ folder structure as in include/tvm
.
We will need to bring some of the root scope files into subfolders
as we start to introduce these sub-folders in C++.
Of course, we can still export specific names to the root scope(see below).
Example changes:
- ir/module.py will contain the definition of IRModule.
- /api.py:compute -> top/api.py:compute (assuming some of the compute goes into the top namespace)
Q2: runtime namespace
We have a clear separation between runtime and compiler in the c++ codebase. All the runtime related features are under the runtime folder.
Putting python runtime related code into an explicit subfolder will help to bring a clearly isolated sub-component that might help future deployment.
Example changes:
- We can rename _ffi to runtime(as most of the folder are runtime features).
- /ndarray.py -> runtime/ndarray.py
Note that we can also separate runtime/contrib
vs contrib
as in the c++ side.
Q3: What to export to the root scope and Name conflicts
Having a separate namespace does not prevent us to re-export things back into the root. One thing we need to resolve here is potential name conflicts.
For example, both runtime and IR have their own Module
and Function
. It is crucial to have a clear way to distinguish between the IR data structure and the runtime data structure.
Q3.1: runtime.PackedFunc vs tvm.Function
At the moment, tvm.Function actually refers to c++ PackedFunc. It might be better to rename to runtime. PackedFunc to avoid confusion.
Q3.2: IRModule vs runtime.Module
Module is the most tricky one to name. Right now tvm.module.py corresponds to runtime.Module. We will need to introduce IRModule to the python side.
Here are some possible naming choices to avoid conflicts:
- Just use namespace: ir.Module vs runtime.Module
- This will mean that we prefer not to export them to the root scope.
- Use prefix e.g IRModule (RTModule)
At the moment we use the name IRModule to distinguish it from runtime::Module
in the C++ side.
The class name itself is not used as frequently as global functions that load these modules.
In particular, the following API
tvm.module.load('xyz.so')
might need to be changed to
tvm.runtime.load('xyz.so')
Please share your thoughts.