Does TVM include a tensor expression language for C++?

Hi everyone,

For C++ deployment, I have seen the tutorial example in:

https://docs.tvm.ai/deploy/cpp_deploy.html

where the libraries created in the python API are used to run a function in the C++ environment.

That made me wonder, does TVM include a Tensor Expression Language that can be coded directly in C++, or do you have to use the python API and then include the generated libraries in C++ to be able to run the TVM code?

I appreciate any help on this question.

Hey @sergiomatiz,

It is possible to write the Tensor Expression Language in C++ for example:

  using namespace tvm;
  using namespace tvm::te;

  Var m("m"), n("n"), l("l");
  te::Tensor A = te::placeholder({m, l}, DataType::Float(32), "A");
  te::Tensor B = te::placeholder({n, l}, DataType::Float(32), "B");
  IterVar rv = reduce_axis(Range{0, l}, "k");

  auto C = te::compute({m, n}, [&](Var i, Var j) {
      return sum(max(1 + A[i][rv] + 1, B[j][rv]), {rv});
      }, "C");

If you’d like to see more examples I would encourage you to check out the C++ tests in this directory: https://github.com/apache/incubator-tvm/tree/master/tests/cpp

1 Like

Hi @DPankratz,

Thanks a lot for the information. This is very useful :slight_smile:

1 Like