External c codgen - supporting tensors other than type float

@comaniac @zhiics

I am currently working on generating some external C code where one of the tensors is of type int64. I noticed that, by default, the logic in codegen_c.h assumes that all Tensors are of type float*. Is there a reason for this? If I were to modify the logic to support multiple data types, would that be a welcome change?

The change shouldn’t be too bad, just replacing std::vector<std::string> args with something like tvm::Array<relay::Var> args. Once we have a Var, we can infer the type and generate the correct code.

The only reason was just because we used it to demonstrate the flow, so you are welcome to file a PR for int64 :slight_smile:

1 Like

Thanks :slight_smile: one other question - in your example, you call malloc and free for the output buffer. However, TVM should already have allocated the output buffer. Do you mind if I remove that and just pass the output buffer to the function directly?

If you are talking about the primary output buffer, yes. We should directly make use of the output buffer TVM allocated instead of allocating a new one to avoid one unnecessary data copy. We did that because we can treat every node in the same way without worrying if the output of this node is the primary output or not. Again, this is just to simplify the implementation, and you are welcome to make it more efficient.

1 Like