You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by jr...@apache.org on 2020/11/06 02:11:34 UTC
[incubator-tvm] 10/21: Fix calling
This is an automated email from the ASF dual-hosted git repository.
jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git
commit eeb86c63d693288f8d406aed6b1b0df6d28e4b07
Author: Jared Roesch <ro...@gmail.com>
AuthorDate: Thu Oct 15 21:37:34 2020 -0700
Fix calling
---
rust/tvm-rt/src/function.rs | 28 +++++++++++++++++-----------
rust/tvm/src/bin/tyck.rs | 2 +-
rust/tvm/src/ir/diagnostics/mod.rs | 4 +---
3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/rust/tvm-rt/src/function.rs b/rust/tvm-rt/src/function.rs
index bae06e9..c7aebdd 100644
--- a/rust/tvm-rt/src/function.rs
+++ b/rust/tvm-rt/src/function.rs
@@ -33,6 +33,7 @@ use std::{
};
use crate::errors::Error;
+use crate::object::ObjectPtr;
pub use super::to_function::{ToFunction, Typed};
pub use tvm_sys::{ffi, ArgValue, RetValue};
@@ -120,21 +121,26 @@ impl Function {
let mut ret_val = ffi::TVMValue { v_int64: 0 };
let mut ret_type_code = 0i32;
- check_call!(ffi::TVMFuncCall(
- self.handle,
- values.as_mut_ptr() as *mut ffi::TVMValue,
- type_codes.as_mut_ptr() as *mut c_int,
- num_args as c_int,
- &mut ret_val as *mut _,
- &mut ret_type_code as *mut _
- ));
+ let ret_code = unsafe {
+ ffi::TVMFuncCall(
+ self.handle,
+ values.as_mut_ptr() as *mut ffi::TVMValue,
+ type_codes.as_mut_ptr() as *mut c_int,
+ num_args as c_int,
+ &mut ret_val as *mut _,
+ &mut ret_type_code as *mut _
+ )
+ };
+
+ if ret_code != 0 {
+ return Err(Error::CallFailed(crate::get_last_error().into()));
+ }
let rv = RetValue::from_tvm_value(ret_val, ret_type_code as u32);
match rv {
RetValue::ObjectHandle(object) => {
- let optr = crate::object::ObjectPtr::from_raw(object as _).unwrap();
- // println!("after wrapped call: {}", optr.count());
- crate::object::ObjectPtr::leak(optr);
+ let optr = ObjectPtr::from_raw(object as _).unwrap();
+ ObjectPtr::leak(optr);
}
_ => {}
};
diff --git a/rust/tvm/src/bin/tyck.rs b/rust/tvm/src/bin/tyck.rs
index e0c7136..fbab027 100644
--- a/rust/tvm/src/bin/tyck.rs
+++ b/rust/tvm/src/bin/tyck.rs
@@ -18,7 +18,7 @@ fn main() -> Result<()> {
codespan::init().expect("Rust based diagnostics");
let opt = Opt::from_args();
println!("{:?}", &opt);
- let module = IRModule::parse_file(opt.input)?;
+ let module = IRModule::parse_file(opt.input);
// for (k, v) in module.functions {
// println!("Function name: {:?}", v);
diff --git a/rust/tvm/src/ir/diagnostics/mod.rs b/rust/tvm/src/ir/diagnostics/mod.rs
index fce214a..039d1ed 100644
--- a/rust/tvm/src/ir/diagnostics/mod.rs
+++ b/rust/tvm/src/ir/diagnostics/mod.rs
@@ -207,9 +207,7 @@ impl DiagnosticContext {
}
}
-// Override the global diagnostics renderer.
-// Params
-// ------
+/// Override the global diagnostics renderer.
// render_func: Option[Callable[[DiagnosticContext], None]]
// If the render_func is None it will remove the current custom renderer
// and return to default behavior.