cornell-zhang / hcl-dialect

HeteroCL-MLIR dialect for accelerator design
https://cornell-zhang.github.io/heterocl/index.html
Other
40 stars 17 forks source link

[Feature] Print to File #96

Open zzzDavid opened 2 years ago

zzzDavid commented 2 years ago

This thread is to discuss how to implement printing to file in MLIR.

Motivation

when we run the simulation model (llvm target) of the accelerator, we want to dump traces of different kinds, e.g. instruction, memory, cache trace, etc. We are using printf along with some tags for different traces, and post-process to bucket traces to different files. It would be nice to allow users to provide the file descriptors for different traces.

Is it achievable?

I'm not 100% sure if it's doable. One possible way I want to try is to leverage LLVM's ability to call C functions. For example, we can call fprintf to do that, we just have to find a way to pass a file descriptor to it (which essentially is an integer).

It is probably similar to how print is implemented, but I'm not exactly sure how LLVM dialect calls C function and what C functions are available, so I need to find out with some trial and error.