[BACKEND][CODEGEN] C codegen with tests#2161
Conversation
|
@Huyuwei can you help review this? |
|
@mutinifni Can you briefly describe the current compilation flow? Most importantly, is it using DSOModule for the runtime? |
|
@Huyuwei It uses CSourceModule for saving the C source code - I have verified this by checking the type_key. Loading is done via the DSOModule. I was a bit uncertain about this module design and the export_library functionality as well, so please feel let me know if you think a different flow would be better instead. |
| namespace codegen { | ||
|
|
||
| CodeGenCHost::CodeGenCHost() { | ||
| module_name = GetUniqueName("__tvm_module_ctx"); |
There was a problem hiding this comment.
replace "__tvm_module_ctx" with tvm::runtime::symbol::tvm_module_ctx?
There was a problem hiding this comment.
This would make the generated code necessarily dependent on C++, but we want to keep the option of pure C as well. If there's a reason to use the latter symbol, I can change it.
|
@Huyuwei please take another look |
|
This PR cause the below issue with llvm target. python3 tutorials/get_started.py |
|
Thanks @srkreddy1238 for reporting this, @mutinifni can you send in a quick fix? We should not directly raise error when the headers are not found in general create_shared, instead, we should only call find_include_path and add it to the options in created_shared when it is a c module |
* Implement C code generation with tests * Code cleanup * Implement C code generation with tests * Code cleanup * tabs to spaces * make lint compliant * update export_library and reserve unique C keywords * move ReserveKeywordsAsUnique to codegen_c * some documentation and code cleanup * use tvm.contrib.util for tempdir in testcases
* Implement C code generation with tests * Code cleanup * Implement C code generation with tests * Code cleanup * tabs to spaces * make lint compliant * update export_library and reserve unique C keywords * move ReserveKeywordsAsUnique to codegen_c * some documentation and code cleanup * use tvm.contrib.util for tempdir in testcases
* Implement C code generation with tests * Code cleanup * Implement C code generation with tests * Code cleanup * tabs to spaces * make lint compliant * update export_library and reserve unique C keywords * move ReserveKeywordsAsUnique to codegen_c * some documentation and code cleanup * use tvm.contrib.util for tempdir in testcases
|
Hello, is there any documents or examples about how to use this c backend? |
|
Hi @dongxiao92, you can look at |
|
Hello, I want to generate C code too:
But failed: |
|
Hi @wujiaqi6630, if you want to see the C source code that is generated, you can use |
|
Thank you ! |
|
Hi@Mutinifni, I use the func.get_source(), but the code printed on the screen seems not to run on the X86 platform. How can I execute the C code. Looking forward to your reply |
|
Hi Any update on how to execute the generated C source code? I observe that when you generate the c source code for a module that is generated through a user-defined relay function you get a Thanks in advance! |
Hey, did you find out a way how to compile that generated c code? Thanks |
This PR introduces a gcc / g++ compatible C code generator for TVM, tested on x86 host.