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

[Rust][IRModule] Flesh out IRModule methods #6741

Merged
merged 12 commits into from
Nov 5, 2020

Conversation

jroesch
Copy link
Member

@jroesch jroesch commented Oct 23, 2020

This PR fully expand the IRModule interface in Rust and fixes a whole host of sharp edges and improves the procedural macros for generating the boilerplate.

cc @mwillsey @altanh @imalsogreg @gussmith23

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

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

The LLVM flags look good to me

use quote::quote;
use syn::parse::{Parse, ParseStream, Result};

use syn::{FnArg, Generics, Ident, Lit, Meta, NestedMeta, Pat, ReturnType, TraitItemMethod, Type};
use syn::{FnArg, Signature, Attribute, token::Semi, Visibility, Generics, Ident, Lit, Meta, NestedMeta, Pat, ReturnType, Type};
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: line length

Copy link
Contributor

Choose a reason for hiding this comment

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

WTB rustfmt

Copy link
Member Author

Choose a reason for hiding this comment

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

I probably just haven't run it yet, since everything is automatic I tend to just run it when I know I'm gtg.

use syn::{FnArg, Generics, Ident, Lit, Meta, NestedMeta, Pat, ReturnType, TraitItemMethod, Type};
use syn::{FnArg, Signature, Attribute, token::Semi, Visibility, Generics, Ident, Lit, Meta, NestedMeta, Pat, ReturnType, Type};

struct ExternalItem {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: brief rustdoc? Some comments would help me get the story of what ExternalItem and External are for.

Copy link
Contributor

Choose a reason for hiding this comment

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

What Greg said

let derives = quote! {
impl std::hash::Hash for #ref_id {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.0.hash(state)
Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly dumb comment (I'm not familiar with this macro) - is self.0 always the right thing to hash? Or is #ref_id sometimes a tuple with multiple fields, where field .1 and .2 etc. may be part of what distinguishes objects when hashing?

Copy link
Member Author

Choose a reason for hiding this comment

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

No we generate a wrapper new type over the ObjectPtr which contains 1 field always. ObjectPtr is currently dispatching to TVM's C++ hashing so we have cross language consistency.

@@ -83,6 +83,10 @@ impl DataType {
DataType::new(DL_FLOAT_CODE, bits, lanes)
}

pub const fn float32() -> DataType {
Copy link
Contributor

Choose a reason for hiding this comment

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

if this is float32, should the old float be renamed to float64 (to avoid clashing with float vs. double size intuition?)

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 don't use float/double terminology in TVM due to the fact that both integers and floating point values are both parametric by vector length and bit width. The float method here takes both bit width and vector length, unless I'm missing something.

Copy link
Contributor

@imalsogreg imalsogreg left a comment

Choose a reason for hiding this comment

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

I left a couple nit comments and questions. But it seems fine to merge, to me.
Haven't tested anything (I'm not up to speed yet on running TVM or using these rust bindings)

@jroesch
Copy link
Member Author

jroesch commented Oct 31, 2020

I left a couple nit comments and questions. But it seems fine to merge, to me.
Haven't tested anything (I'm not up to speed yet on running TVM or using these rust bindings)

Its pretty easy to get started, @adelbertc has not repro'd running them if you are interested. I will finish adding tests and ping you guys again.

use syn::{FnArg, Generics, Ident, Lit, Meta, NestedMeta, Pat, ReturnType, TraitItemMethod, Type};
use syn::{FnArg, Signature, Attribute, token::Semi, Visibility, Generics, Ident, Lit, Meta, NestedMeta, Pat, ReturnType, Type};

struct ExternalItem {
Copy link
Contributor

Choose a reason for hiding this comment

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

What Greg said

rust/tvm-macros/src/external.rs Show resolved Hide resolved
rust/tvm-macros/src/object.rs Show resolved Hide resolved
rust/tvm-rt/src/array.rs Show resolved Hide resolved
rust/tvm-rt/src/object/object_ptr.rs Show resolved Hide resolved
@jroesch
Copy link
Member Author

jroesch commented Nov 5, 2020

@adelbertc @imalsogreg I will try and ship docs for proc macro after landing this branch if that's cool with you guys, just so I can unblock some other branches I have.

Copy link
Contributor

@electriclilies electriclilies left a comment

Choose a reason for hiding this comment

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

I don't know rust very well, but looks good to me

@jroesch jroesch merged commit a4bd5f8 into apache:main Nov 5, 2020
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Dec 2, 2020
* WIP

* WIP

* WIP

* WIP

* Disable WASM and fix rebase

* Work on finishing tests

* Make entire object system printable

* Write some more tests for IRModule

* All tests pass

* Format

* Restore module.cc

* Bump syn
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Dec 4, 2020
* WIP

* WIP

* WIP

* WIP

* Disable WASM and fix rebase

* Work on finishing tests

* Make entire object system printable

* Write some more tests for IRModule

* All tests pass

* Format

* Restore module.cc

* Bump syn
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Dec 4, 2020
* WIP

* WIP

* WIP

* WIP

* Disable WASM and fix rebase

* Work on finishing tests

* Make entire object system printable

* Write some more tests for IRModule

* All tests pass

* Format

* Restore module.cc

* Bump syn
@jroesch jroesch deleted the rust-improve-ir-mod branch February 4, 2021 04:44
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.

6 participants