Does MLIR supports CUDA source code generation?

I do know that there exists some paths in gpu codegen, but their output is either the mix of llvm IR and nvvm IR or ptx code. What if I want to do some optimizations at the level of cuda source code, can MLIR support cuda source code generation?

MLIR could support it, but it does not at the moment.
See also : EmitC - Generating C/C++ from MLIR for general source-emission and [RFC] The Natural Intersection of MLIR and C - #5 by Diana for folks interested in OpenCL and similar.

1 Like

Thank you for your reply! And I am reading these material, and have two questions.
One is that I notice the mlir-translate -mlir-to-cpp does not support some computing ops like arith.addf. I am wondering whether the emitc dialect only support call functions instead of define functions, meaning that we need another hand-written templated cpp file to define the functions so that we can call them in emitc?
Another question is that I haven’t found some passes that can convert dialect to emitc dialect, must we write our own file with emitc dialect?

The principle with EmitC is to use the Dialect lowering infrastructure to lower ops to a form that can be emitted.

I don’t know the status of lowering in-tree, but [FAQ] Why is “feature” not available in MLIR likely applies here.

There is some active work in this area in general: âš™ D149963 [mlir][emitc] Add add and sub operations

1 Like