How can I generate C code, create an IR LLVM and use it with te.extern?

Hi,

I would like to generate C code in my python script like this:

cc_code = """
extern "C" int my_conv2d(float* data, float* weight, float* output) {
    // code in C of my convolution
}
"""

and then be able to use it with te.extern (or something else) to call this function:

Output = tvm.te.extern(
    output_size,
    [A, W],
    lambda ins, outs: tvm.tir.call_packed(
        "my_conv2d", ins[0], ins[1], outs[0], other_arguments
    ),
    name="Output",
)

I have seen how pragma is used in this file tests/python/all-platform-minimal-test/test_minimal_target_codegen_llvm.py

Unfortunately, I can’t use pragma here because I make a te.extern call and I don’t want to make a value by value function call as it is done in the test_minimal_target_codegen_llvm.py file. I just want to run my_conv2d to do my convolution and get the output.

Is it possible to make a C function, generate an LLVM IR and use this function with te.extern or something else?

Thank you

hi @cali,

if you want to tensorize you can look at the cortex-M gemm impl. that might not be exactly what you want to do but it may be a place to start.

Andrew

There is a ready-to-run example that does this I think Use Tensorize to Leverage Hardware Intrinsics — tvm 0.8.dev0 documentation

Thanks for your answer but I don’t want to use Tensorize because I want to use my function written in cc_code directly.