# Exporting sources for C++ only operator/kernel implementations

**URL:** <https://discuss.tvm.apache.org/t/exporting-sources-for-c-only-operator-kernel-implementations/10062>\
**Category:** Development\
**Created:** [May 22, 2021, 2:34pm UTC](https://discuss.tvm.apache.org/t/exporting-sources-for-c-only-operator-kernel-implementations/10062 "2021-05-22T14:34:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PhilippvK](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/philippvk/32/2287_2.png) [@PhilippvK](https://discuss.tvm.apache.org/u/PhilippvK)\
**Post date:** [May 22, 2021, 2:34pm UTC](https://discuss.tvm.apache.org/t/exporting-sources-for-c-only-operator-kernel-implementations/10062/1 "2021-05-22T14:34:48Z")

</div>

For a custom operator I am currently implementing I generate C-code following the BYOC approach. As I have to include 3rd party C++ header files containing namespaces etc. I have not really found a way to compile my kernels (In my case `src/lib2.c`) without changing the file extension to `.cc` or `.cpp`.

Also it would be great to use C++ features in the kernel Implementations as well. Is this currently not supported (maybe due to the overhead this would have for embedded deployment) or have I overlooked anything?

My implementations should be mainly deployed in an uTVM environment I am exporting the output files for the target device using either of these approaches:

1. following the (default) uTVM Flow using `tvm.micro.build_static_runtime()`)
2. Using the Model Library Format (`tvm.micro.export_model_format()`) from uTVM (and compile externally)

However I think my concern is not uTVM specific.

My Quick fix to generate `lib*.cc` files instead of `lib*.c` files without needing to rename them manually after the export is based on hardcoding the file extension in `python/tvm/micro/model_library_format.py` (for (2)) and `python/tvm/runtime/module.py` (for (1)).

Now I would like to find something more robust to contribute it to the TVM codebase but I am not sure on how to integrate it in a meaningful way. My main two question are:

- How to tell TVM that C++ files need to be generated instead of using the default .c file extension. This maybe passed in as an optional argument by the user (for all `CSourceModules` that are going to be build together) or internally on a per-module basis (f.e. in by BYOC code)
- Can I reuse the available `CSourceModule` and stick with the type\_key `"c"` for C++ as well by just changing the filename extension or should I add another type key like `"cc"`/`"cpp"` with an separate `SourceModuleNode`.

I would appreciate a lot if someone could give me a hint on wether I have misunderstood anything and if my proposal sounds like an improvement to the TVM ecosystem, feel free to discuss my questions on the possible implementations as well.
