Commit 9ff71f4
authored
[CodeGenC] Handle GlobalVar callee as internal function call (#15103)
Analogous to #14901, treat GlobalVar callees as internal function calls in CodeGenC. This specific PR doesn't provide new end-to-end functionality, as the target="c" backend isn't compiled. It does lead into allowing subroutines in any target whose codegen derives from CodeGenC, which will depend on the single-module lowering flow in #14985.
* [CodeGenC] Added unit tests for desired behavior
* [CodeGenC] Handle GlobalVar callee as internal function call
* Update CodeGenC subclasses for updated interface
- Call `DeclareFunction` for each `PrimFunc`, prior to any
`AddFunction` calls
- Provide both `GlobalVar` and `PrimFunc` to `AddFunction` calls.
* Updated CRT test to expect forward declaration
* Provide forward declarations for call_extern in cmsis
* Avoid duplicate forward declaration
C's automatic pointer cast (e.g. `void*` to `int*`) means that use of
the arguments to infer the function signature may be incorrect. If a
`call_extern` refers to a function within the same module, only output
a single forward declaration based on the PrimFunc's parameters, not
based on the CallNode's arguments.
* Updated expected ptx cuda
* Cast the AOT pools to the arg type
* Improved tvm::GetType for tvm_access_ptr and address_of
These `Call` instances can return a
`PointerType(PrimType(pointee_dtype))` rather than a
`PrimType(DataType::Handle())`.
* [ARM][Topi] Update micro kernels to use same argument type as caller
Previously, the micro kernels for gemm, avg_pool, max_pool, and
tensordot relied on C's implicit type conversions for the arguments,
when the caller's argument types differ from the signature's parameter
types. This works, except when the codegen has auto-generated a
forward declaration based on the caller's argument types, such as
during AOT, which then causes a conflicting definition.
Since the codegen cannot determine the functions names from the
`"pragma_import_c"` in order to suppress these forward declarations,
this conflict can be more easily resolved by updating the micro kernel
signatures. The three types of mismatches are below.
- Use of `int` or `long` parameters, whose width may vary by compiler,
instead of fixed-width types.
- TIR expecting the data array's integer type to also be used as an
error code's return type, rather than the micro kernels' `int32_t`
error code.
- Pointer conversion done during argument conversion.
Type conversions are done at the start of each micro kernel, to avoid
changing types that are used within the computational sections of each
micro kernel.
* Updated unit tests with private=True
Required for internal functions after PR #15214
* Docstring updates from review1 parent 34cacb0 commit 9ff71f4
File tree
27 files changed
+591
-297
lines changed- python/tvm/topi/arm_cpu/mprofile/dsp/micro_kernel
- src
- relay/backend/contrib
- cmsisnn
- example_target_hooks
- uma
- target
- opt
- source
- tir/op
- tests/python
- relay/aot
- topi/python
- unittest
27 files changed
+591
-297
lines changedLines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
117 | | - | |
| 116 | + | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| |||
Lines changed: 70 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
| 159 | + | |
160 | 160 | | |
161 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
162 | 167 | | |
163 | 168 | | |
164 | 169 | | |
| |||
200 | 205 | | |
201 | 206 | | |
202 | 207 | | |
203 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
204 | 214 | | |
205 | 215 | | |
206 | 216 | | |
| |||
221 | 231 | | |
222 | 232 | | |
223 | 233 | | |
224 | | - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
225 | 239 | | |
226 | 240 | | |
227 | 241 | | |
| |||
265 | 279 | | |
266 | 280 | | |
267 | 281 | | |
268 | | - | |
| 282 | + | |
269 | 283 | | |
270 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
271 | 290 | | |
272 | 291 | | |
273 | 292 | | |
| |||
309 | 328 | | |
310 | 329 | | |
311 | 330 | | |
312 | | - | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
313 | 336 | | |
314 | 337 | | |
315 | 338 | | |
| |||
327 | 350 | | |
328 | 351 | | |
329 | 352 | | |
330 | | - | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
331 | 358 | | |
332 | 359 | | |
333 | 360 | | |
| |||
368 | 395 | | |
369 | 396 | | |
370 | 397 | | |
371 | | - | |
| 398 | + | |
372 | 399 | | |
373 | | - | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
374 | 406 | | |
375 | 407 | | |
376 | 408 | | |
| |||
387 | 419 | | |
388 | 420 | | |
389 | 421 | | |
390 | | - | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
391 | 427 | | |
392 | 428 | | |
393 | 429 | | |
| |||
408 | 444 | | |
409 | 445 | | |
410 | 446 | | |
411 | | - | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
412 | 452 | | |
413 | 453 | | |
414 | 454 | | |
| |||
450 | 490 | | |
451 | 491 | | |
452 | 492 | | |
453 | | - | |
| 493 | + | |
454 | 494 | | |
455 | | - | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
456 | 501 | | |
457 | 502 | | |
458 | 503 | | |
| |||
469 | 514 | | |
470 | 515 | | |
471 | 516 | | |
472 | | - | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
473 | 522 | | |
474 | 523 | | |
475 | 524 | | |
| |||
487 | 536 | | |
488 | 537 | | |
489 | 538 | | |
490 | | - | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
491 | 544 | | |
492 | 545 | | |
493 | 546 | | |
| |||
520 | 573 | | |
521 | 574 | | |
522 | 575 | | |
523 | | - | |
| 576 | + | |
524 | 577 | | |
525 | 578 | | |
526 | 579 | | |
| |||
Lines changed: 8 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
111 | 113 | | |
112 | 114 | | |
113 | 115 | | |
| |||
120 | 122 | | |
121 | 123 | | |
122 | 124 | | |
123 | | - | |
| 125 | + | |
| 126 | + | |
124 | 127 | | |
125 | 128 | | |
126 | 129 | | |
| |||
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
393 | | - | |
| 393 | + | |
| 394 | + | |
394 | 395 | | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
395 | 400 | | |
396 | 401 | | |
397 | 402 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | 49 | | |
57 | 50 | | |
58 | 51 | | |
| |||
519 | 512 | | |
520 | 513 | | |
521 | 514 | | |
522 | | - | |
523 | 515 | | |
524 | | - | |
525 | | - | |
526 | | - | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
527 | 520 | | |
528 | 521 | | |
529 | 522 | | |
| |||
538 | 531 | | |
539 | 532 | | |
540 | 533 | | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
| 534 | + | |
| 535 | + | |
546 | 536 | | |
547 | 537 | | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
548 | 544 | | |
549 | 545 | | |
550 | 546 | | |
| |||
Lines changed: 20 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
60 | 67 | | |
| 68 | + | |
61 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
62 | 76 | | |
63 | 77 | | |
64 | 78 | | |
| |||
0 commit comments