Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C Device API #31

Merged
merged 3 commits into from
Oct 3, 2021
Merged

C Device API #31

merged 3 commits into from
Oct 3, 2021

Conversation

Mousius
Copy link
Member

@Mousius Mousius commented Sep 7, 2021

No description provided.

Copy link
Contributor

@areusch areusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @Mousius just a couple questions here

rfcs/0031-devices-api.md Outdated Show resolved Hide resolved
rfcs/0031-devices-api.md Show resolved Hide resolved
rfcs/0031-devices-api.md Outdated Show resolved Hide resolved
rfcs/0031-devices-api.md Outdated Show resolved Hide resolved
rfcs/0031-devices-api.md Outdated Show resolved Hide resolved
rfcs/0031-devices-api.md Show resolved Hide resolved
rfcs/0031-devices-api.md Show resolved Hide resolved
rfcs/0031-devices-api.md Show resolved Hide resolved
```

## PrimFunc Resource Handle
A `tir::Var` is added to `PrimFunc` in `include/tvm/tir/function.h` which enables a `PrimFunc` to track and use the `resource_handle` parameter. This will be used by both unpacked and packed APIs to pass the resource down without packing into `TVMValue`, instead as a `void *`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it kind of seems like we could get away without doing this by tracking which Target a function is going to run on and looking up the associated device API function in AOT/graph codegen. what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd still need to pass this into the function call though to the operator though?

rfcs/0031-devices-api.md Show resolved Hide resolved
@tqchen
Copy link
Member

tqchen commented Sep 8, 2021

Thanks @Mousius . One thing to note about process.

If we want to propose to change the TIR data structure(e.g. add resource handle field to PrimFunc), it would be great if we can have a separate RFC discuss process because the impact radius will be bigger and goes beyond micro TVM land.

@Mousius
Copy link
Member Author

Mousius commented Sep 22, 2021

@areusch I've updated this and replied to your comments, could you please take another look - I believe implementing this is now blocked on the PrimFunc discussion but we should be able to land this and begin work as soon as that's resolved.

Mousius added a commit to Mousius/tvm that referenced this pull request Sep 23, 2021
To address some of the concerns raised in apache#8280 and apache#8720 I've put together a series of functions to combine together names to re-use between these areas. These are meant to be a starting point to fix up the name generation to use the TVM C conventions and port the interface API header to C++.

These functions will also be used for constructing the names in the C Device API (apache/tvm-rfcs#31).
Mousius added a commit to Mousius/tvm that referenced this pull request Sep 23, 2021
To address some of the concerns raised in apache#8280 and apache#8720 I've put together a series of functions to combine together names to re-use between these areas. These are meant to be a starting point to fix up the name generation to use the TVM C conventions and port the interface API header to C++.

These functions will also be used for constructing the names in the C Device API (apache/tvm-rfcs#31).
Mousius added a commit to Mousius/tvm that referenced this pull request Sep 23, 2021
To address some of the concerns raised in apache#8280 and apache#8720 I've put together a series of functions to combine together names to re-use between these areas. These are meant to be a starting point to fix up the name generation to use the TVM C conventions and port the interface API header to C++.

These functions will also be used for constructing the names in the C Device API (apache/tvm-rfcs#31).
Mousius added a commit to Mousius/tvm that referenced this pull request Sep 23, 2021
To address some of the concerns raised in apache#8280 and apache#8720 I've put together a series of functions to combine together names to re-use between these areas. These are meant to be a starting point to fix up the name generation to use the TVM C conventions and port the interface API header to C++.

These functions will also be used for constructing the names in the C Device API (apache/tvm-rfcs#31).
rfcs/0031-devices-api.md Show resolved Hide resolved
@@ -41,7 +41,7 @@ In this example, you can see the diversity of RTOS implementations for drivers a
[guide-level-explanation]: #guide-level-explanation

## User App
`tvm_device_<device>_t`s are implemented for each RTOS or platform required, these are included by the user who chooses as appropriate for their application. Notably, to avoid dynamic allocation, the user must provide the `tvm_device_<device>_t` struct and initialise it rather than it being created and setup for them in the API. This is augmented by named functions for each device, examples in the case of the "woofles" accelerator:
TVM presumes that the RTOS, platform, or user application defines a struct type `tvm_device_<device>_t`, these are included by the user who chooses an implementation as appropriate for their application. Notably, to avoid dynamic allocation, the user must provide the `tvm_device_<device>_t` struct and initialise it rather than it being created and setup for them in the API. TVM then expects an implementation of the named functions for each device, examples in the case of the "woofles" accelerator:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also explicitly highlight where <device> comes from from a user PoV?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not covered by the example just below this block?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, that was not the question, amended the text to clarify the origin.

rfcs/0031-devices-api.md Show resolved Hide resolved
@@ -306,6 +293,8 @@ Another route to take is to treat RTOSes as entirely separate from TVM, requirin
# Unresolved questions
[unresolved-questions]: #unresolved-questions

Is coupling `Target`s with this Device API to the C Runtime acceptable? From the authors point of view this seems an acceptable trade off given the devices won't function correctly without the flow control.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's likely that TargetDevice will play a role here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a TargetDevice RFC I can reference? Otherwise I'd assume TargetDevice is speculative rather than something we should include here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry not yet :/. it's sort of teased in the future work section of my Artifact pre-RFC. i'm more including this pointer here as an "early FYI" how i'd like to solve this (e.g. using the TargetDevice name as the mechanism to bind a sub-target to a Device API impl).

Mousius added a commit to Mousius/tvm that referenced this pull request Sep 24, 2021
To address some of the concerns raised in apache#8280 and apache#8720 I've put together a series of functions to combine together names to re-use between these areas. These are meant to be a starting point to fix up the name generation to use the TVM C conventions and port the interface API header to C++.

These functions will also be used for constructing the names in the C Device API (apache/tvm-rfcs#31).
@Mousius
Copy link
Member Author

Mousius commented Sep 27, 2021

@areusch this one is ready for a look again 😸

areusch pushed a commit to apache/tvm that referenced this pull request Sep 30, 2021
* Introduce centralised name transformation functions

To address some of the concerns raised in #8280 and #8720 I've put together a series of functions to combine together names to re-use between these areas. These are meant to be a starting point to fix up the name generation to use the TVM C conventions and port the interface API header to C++.

These functions will also be used for constructing the names in the C Device API (apache/tvm-rfcs#31).

* Improve error handling and error messages

* Sanitize sanitise to sanitize

This patch aims to sanitize uses of sanitise to the form of sanitize to be consistent with the overall codebases use of American English.
@areusch areusch merged commit b9d11df into apache:main Oct 3, 2021
@areusch
Copy link
Contributor

areusch commented Oct 3, 2021

thanks @Mousius !

ylc pushed a commit to ylc/tvm that referenced this pull request Jan 7, 2022
* Introduce centralised name transformation functions

To address some of the concerns raised in apache#8280 and apache#8720 I've put together a series of functions to combine together names to re-use between these areas. These are meant to be a starting point to fix up the name generation to use the TVM C conventions and port the interface API header to C++.

These functions will also be used for constructing the names in the C Device API (apache/tvm-rfcs#31).

* Improve error handling and error messages

* Sanitize sanitise to sanitize

This patch aims to sanitize uses of sanitise to the form of sanitize to be consistent with the overall codebases use of American English.
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
* Introduce centralised name transformation functions

To address some of the concerns raised in apache#8280 and apache#8720 I've put together a series of functions to combine together names to re-use between these areas. These are meant to be a starting point to fix up the name generation to use the TVM C conventions and port the interface API header to C++.

These functions will also be used for constructing the names in the C Device API (apache/tvm-rfcs#31).

* Improve error handling and error messages

* Sanitize sanitise to sanitize

This patch aims to sanitize uses of sanitise to the form of sanitize to be consistent with the overall codebases use of American English.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants