You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by sho via Apache TVM Discuss <no...@discuss.tvm.ai> on 2021/12/16 15:55:43 UTC

[Apache TVM Discuss] [Questions] What is ‘target’ in TVM?


Hi @areusch,

Sorry for my late reply. I needed some time to clean up my thought.

Could you correct me if I'm wrong?

As you probably know, I was confused about LLVM, and how it is used.
So LLVM is used to build TVM compiler. LLVM also works when you input your model into TVM compiler and get TVM's IR. LLVM compiles the TVM's IR, and produces executables.
(I'm still not sure where gcc is used when you build TVM from source though...)

![{809DA627-3A94-42BF-9588-56BDB9749AB2}.png|690x124](upload://dF7kSpxPWdBLmVmE0qPaBIJSNIy.jpeg) 

You don't alway need to use LLVM. In that case, you specify 'c' as the target, and get your C code ready. You can use this C code, the runtime and your other programs to build with your own compiler, and run inference on MCUs.

Sorry while you're budy preparing for TVMCon. Day1 was wonderful. I'm looking forward to Day2 and 3 as well.





---
[Visit Topic](https://discuss.tvm.apache.org/t/what-is-target-in-tvm/11682/5) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/723ce4256921f2e8d194e2bbdd5a38f53d723a696452fda681ac33cf8c59b5c5).

[Apache TVM Discuss] [Questions] What is ‘target’ in TVM?

Posted by sho via Apache TVM Discuss <no...@discuss.tvm.ai>.

Hi @areusch,
Thank you so much. LLVM is getting clear to me.

[quote="areusch, post:7, topic:11682"]
[quote="sho, post:5, topic:11682"]
As you probably know, I was confused about LLVM, and how it is used. So LLVM is used to build TVM compiler. LLVM also works when you input your model into TVM compiler and get TVM’s IR. LLVM compiles the TVM’s IR, and produces executables. (I’m still not sure where gcc is used when you build TVM from source though…)
[/quote]

There are actually two roles LLVM *could* play in TVM:

1. To build TVM from source
[/quote]

Ah LLVM is used to build TVM because it also has a frontend for C/C++!

[quote="areusch, post:7, topic:11682"]
As a Target backend (e.g. `relay.build(..., target="llvm")`), in which case TVM *links* against LLVM (e.g. LLVM is a static library) at compile time, and TVM then contains the code-generation pieces of LLVM and is in turn able to emit machine code to implement a model, just like LLVM does.
[/quote]

Ok, in this case LLVM emits code for say x86, arm, etc, at least not for microcontrollers.

I think I can now use TVM on any microcontrollers thanks to you. Also I have clearer idea about what LLVM is doing in TVM.





---
[Visit Topic](https://discuss.tvm.apache.org/t/what-is-target-in-tvm/11682/9) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/a516db2b3771a0909a94c412142a0da89cbbd0197ff446578942abd99dfd2569).

[Apache TVM Discuss] [Questions] What is ‘target’ in TVM?

Posted by Andrew Reusch via Apache TVM Discuss <no...@discuss.tvm.ai>.

@sho no problem, apologies if this is a bit confusing.

[quote="sho, post:5, topic:11682"]
As you probably know, I was confused about LLVM, and how it is used. So LLVM is used to build TVM compiler. LLVM also works when you input your model into TVM compiler and get TVM’s IR. LLVM compiles the TVM’s IR, and produces executables. (I’m still not sure where gcc is used when you build TVM from source though…)
[/quote]

There are actually two roles LLVM *could* play in TVM:
1. To build TVM from source
2. As a Target backend (e.g. `relay.build(..., target="llvm")`), in which case TVM *links* against LLVM (e.g. LLVM is a static library) at compile time, and TVM then contains the code-generation pieces of LLVM and is in turn able to emit machine code to implement a model, just like LLVM does.

[quote="sho, post:5, topic:11682"]
You don’t alway need to use LLVM. In that case, you specify ‘c’ as the target, and get your C code ready. You can use this C code, the runtime and your other programs to build with your own compiler, and run inference on MCUs.
[/quote]

This is correct. TVM's compilation flow is:
1. import models into Relay
2. "lower" Relay into TIR
3. "codegen" TIR to match the target. `// Target("llvm") or Target("c") mostly matters here`

So the final codegen step is where TIR is translated into some type of machine code. That could be LLVM's Intermediate Representation (which we can generate when TVM is linked against LLVM--like in kind #2 above), C source code, CUDA code, or other types.





---
[Visit Topic](https://discuss.tvm.apache.org/t/what-is-target-in-tvm/11682/7) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/efdb231699c1372a0fb8cc280c7db099ae656d06c82bc6d7b2ad42a4e4f21cff).