Add Python frontend for Neura hardware custom ops#273
Add Python frontend for Neura hardware custom ops#273YanzhouTang wants to merge 1 commit intocoredac:mainfrom
Conversation
I don't see MLIR output?
The correctness is based on "semantic", instead of execution, right? |
MLIR output is generated by running
Current correctness verification is semantic-level. Maybe we could register |
Then can we have a lit test to run the .py and check its output?
We can do this later (another PR once your design/infra is almost done). |
Summary
python/neura_ops.pyas the Python frontend interface for Neura hardware primitives.torch.ops.neura.gather()) to annotate hardware-specific memory access patterns that standard PyTorch ops cannot express.Example:
neura::gatherin hash encodinghash_encodekernel uses indirect addressing (level_embeddings[indices]) for hash-table lookups. After torch_mlir tracing, this becomesaten.index.Tensor, which loses the gather semantics needed by CGRA.torch.ops.neura.gather(table, indices)instead. torch_mlir preserves it astorch.operator "neura.gather", giving the compiler a clear signal.trilinear_interpolationto batch all 8 corner indices into a single gather per level (from 8 calls down to 1).Changes
python/neura_ops.py(new): Registersneura::gatherwith CPU and Meta implementations, compatible with PyTorch 2.1+.nerf_kernels.py(new): Importsneura_ops, replaces fancy indexing withtorch.ops.neura.gather(), two-phase trilinear interpolation.compile_hash_encode.py(new): Compilation script that exports clean ~930-line Torch Dialect MLIR withneura.gatherpreserved.Verification
neura.gatherappears exactly 2 times in output MLIR (one per level).aten.index.Tensorfully eliminated.