You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/06/16 21:12:50 UTC

[GitHub] [incubator-tvm] robo-corg commented on a change in pull request #5769: [WIP] `tvm` crate stage 3 of Rust refactor

robo-corg commented on a change in pull request #5769:
URL: https://github.com/apache/incubator-tvm/pull/5769#discussion_r441143914



##########
File path: rust/tvm/tests/callback/src/bin/error.rs
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use std::panic;
+
+use tvm_frontend::{errors::Error, *};
+
+fn main() {
+    register_global_func! {
+        fn error(_args: &[TVMArgValue]) -> Result<TVMRetValue, Error> {
+            Err(errors::TypeMismatchError{
+                expected: "i64".to_string(),
+                actual: "f64".to_string(),
+            }.into())
+        }
+    }
+
+    let mut registered = function::Builder::default();
+    registered.get_function("error");
+    assert!(registered.func.is_some());
+    registered.args(&[10, 20]);
+
+    println!("expected error message is:");
+    panic::set_hook(Box::new(|panic_info| {
+        // if let Some(msg) = panic_info.message() {
+        //     println!("{:?}", msg);
+        // }

Review comment:
       Delete 
   ```suggestion
   ```

##########
File path: rust/out-of-tree/import_pass.py
##########
@@ -0,0 +1,44 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import tvm
+import tvm.relay
+from tvm.ir.transform import PassContext
+
+x = tvm.relay.var("x", shape=(10,))
+test_func = tvm.relay.Function([x], x)
+test_mod = tvm.IRModule.from_expr(test_func)
+
+pass_dylib = "/Users/jroesch/Git/tvm/rust/target/debug/libmy_pass.dylib"

Review comment:
       Hardcoded path on your hard drive

##########
File path: rust/out-of-tree/src/lib.rs
##########
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use std::ffi::c_void;
+use std::os::raw::c_int;
+use tvm::ir::relay::{self, Function};
+use tvm::runtime::ObjectRef;
+use tvm::transform::{function_pass, PassInfo, Pass, PassContext, IRModule};
+use tvm::runtime::function::{register, Result};
+use tvm::export_pass;
+
+fn my_pass_fn(func: relay::Function, module: IRModule, ctx: PassContext) -> Function {
+    let var = relay::Var::new("Hi from Rust!".into(), ObjectRef::null());
+    relay::Function::new(
+        func.params.clone(),
+        var.to_expr(),
+        func.ret_type.clone(),
+        func.type_params.clone())
+}
+
+// fn the_pass() -> Result<Pass> {
+//     let pass_info = PassInfo::new(15, "RustPass".into(), vec![])?;
+//     function_pass(my_pass_fn, pass_info)
+// }

Review comment:
       Delete
   ```suggestion
   ```

##########
File path: rust/tvm-rt/src/to_function.rs
##########
@@ -46,46 +46,52 @@ pub use tvm_sys::{ffi, ArgValue, RetValue};
 /// And the implementation of it to `ToFunction`.
 pub trait Typed<I, O> {
     fn args(i: &[ArgValue<'static>]) -> Result<I>;
-    fn ret(o: O) -> RetValue;
+    fn ret(o: O) -> Result<RetValue>;
 }
 
-impl<F, O: Into<RetValue>> Typed<(), O> for F
+impl<F, O, E> Typed<(), O> for F
 where
     F: Fn() -> O,
+    Error: From<E>,

Review comment:
       Does this add a bound to TryInto<... Error> ?

##########
File path: rust/tvm/tests/callback/src/bin/string.rs
##########
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#![allow(unused_imports)]
+
+#[macro_use]
+extern crate tvm_frontend as tvm;
+use std::convert::TryInto;
+use tvm::{errors::Error, *};
+
+// FIXME

Review comment:
       Fix it or maybe add a better comment?

##########
File path: rust/tvm-rt/src/string.rs
##########
@@ -73,7 +73,7 @@ impl String {
 // mod tests {
 //     use super::String;
 //     use crate::object::debug_print;
-//     use crate::ToObjectRef;
+//     use crate::IsObjectRef;
 //     use anyhow::{ensure, Result};
 
 //     #[test]

Review comment:
       Delete commented out code

##########
File path: rust/out-of-tree/Cargo.toml
##########
@@ -0,0 +1,33 @@
+# Licensed to the Apache Software Foundation (ASF) under one

Review comment:
       Should this be some kind of example instead of its own crate?

##########
File path: rust/tvm/src/ir/relay/mod.rs
##########
@@ -0,0 +1,282 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use crate::runtime::{IsObject, Object, ObjectPtr, ObjectRef, String as TString, IsObjectRef};
+use crate::runtime::array::Array;
+use crate::DataType;
+use tvm_macros::Object;
+
+#[repr(C)]
+#[derive(Object)]
+#[ref_name = "Id"]
+#[type_key = "relay.Id"]
+pub struct IdNode {
+    pub base: Object,
+    pub name_hint: TString,
+}

Review comment:
       I forge does derive(Object) implement debug? It would be neat to have debug work on relay ast.

##########
File path: rust/runtime/tests/test_wasm32/Cargo.toml
##########
@@ -22,5 +22,6 @@ license = "Apache-2.0"
 authors = ["TVM Contributors"]
 
 [dependencies]
+anyhow = "*"

Review comment:
       Should this be pinned?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org