From f9332ef0fc4f1b3e36661e7cdb28b051152441a6 Mon Sep 17 00:00:00 2001 From: Tianqi Chen Date: Wed, 15 Jan 2020 19:44:39 -0800 Subject: [PATCH] [REFACTOR][FFI] Make more clear naming for C API Type codes. (#4715) This PR introduces more clear naming prefix for C API type codes to avoid conflict with other packages. We also removed TVMArray and TVMType to directly use DLTensor and DLDataType. --- apps/extension/src/tvm_ext.cc | 2 +- golang/src/ndarray.go | 18 +- golang/src/value.go | 52 ++-- include/tvm/expr_operator.h | 2 +- include/tvm/ir/attrs.h | 8 +- include/tvm/packed_func_ext.h | 8 +- include/tvm/runtime/c_runtime_api.h | 58 ++-- include/tvm/runtime/data_type.h | 2 +- include/tvm/runtime/device_api.h | 6 +- include/tvm/runtime/packed_func.h | 250 +++++++++--------- include/tvm/runtime/util.h | 4 +- jvm/native/src/main/native/jni_helper_func.h | 20 +- .../native/org_apache_tvm_native_c_api.cc | 14 +- python/tvm/_ffi/_ctypes/function.py | 20 +- python/tvm/_ffi/_cython/base.pxi | 22 +- python/tvm/_ffi/_cython/function.pxi | 52 ++-- python/tvm/_ffi/_cython/object.pxi | 2 +- python/tvm/_ffi/runtime_ctypes.py | 6 +- rust/runtime/src/graph.rs | 2 +- src/api/api_base.cc | 4 +- src/api/api_lang.cc | 22 +- src/codegen/codegen_c.cc | 2 +- src/codegen/codegen_c_host.cc | 4 +- src/codegen/datatype/registry.cc | 15 +- src/codegen/datatype/registry.h | 2 +- src/codegen/llvm/codegen_cpu.cc | 2 +- src/codegen/stackvm/codegen_stackvm.cc | 4 +- src/ir/attrs.cc | 2 +- src/ir/op.cc | 6 +- src/node/reflection.cc | 6 +- src/node/serialization.cc | 4 +- src/pass/lower_tvm_builtin.cc | 4 +- src/pass/make_api.cc | 8 +- src/relay/ir/doc.cc | 2 +- src/relay/ir/pretty_printer.cc | 2 +- src/relay/op/tensor/transform.cc | 2 +- src/runtime/c_runtime_api.cc | 18 +- src/runtime/contrib/cudnn/conv_forward.cc | 10 +- .../example_ext_runtime.cc | 8 +- src/runtime/contrib/nnpack/convolution.cc | 12 +- src/runtime/contrib/sort/sort.cc | 12 +- src/runtime/cpu_device_api.cc | 8 +- src/runtime/cuda/cuda_device_api.cc | 10 +- src/runtime/file_util.cc | 8 +- .../graph/debug/graph_runtime_debug.cc | 2 +- src/runtime/graph/graph_runtime.cc | 12 +- src/runtime/library_module.cc | 4 +- src/runtime/meta_data.h | 6 +- src/runtime/metal/metal_common.h | 10 +- src/runtime/metal/metal_device_api.mm | 8 +- src/runtime/micro/micro_device_api.cc | 6 +- src/runtime/micro/micro_session.cc | 10 +- src/runtime/micro/micro_session.h | 8 +- .../micro/standalone/utvm_graph_runtime.cc | 4 +- src/runtime/opencl/opencl_common.h | 6 +- src/runtime/opencl/opencl_device_api.cc | 10 +- src/runtime/opencl/opencl_module.cc | 4 +- src/runtime/opengl/opengl_common.h | 12 +- src/runtime/opengl/opengl_device_api.cc | 14 +- src/runtime/opengl/opengl_module.cc | 8 +- src/runtime/pack_args.h | 28 +- src/runtime/rocm/rocm_device_api.cc | 6 +- src/runtime/rpc/rpc_device_api.cc | 8 +- src/runtime/rpc/rpc_module.cc | 8 +- src/runtime/rpc/rpc_session.cc | 111 ++++---- src/runtime/rpc/rpc_session.h | 4 +- src/runtime/sgx/trusted/runtime.cc | 10 +- src/runtime/sgx/untrusted/sgx_module.cc | 8 +- src/runtime/stackvm/stackvm.cc | 4 +- src/runtime/stackvm/stackvm.h | 12 +- src/runtime/vm/memory_manager.h | 2 +- src/runtime/vm/naive_allocator.h | 2 +- src/runtime/vm/pooled_allocator.h | 2 +- src/runtime/vm/vm.cc | 8 +- src/runtime/vulkan/vulkan.cc | 13 +- src/runtime/workspace_pool.cc | 6 +- tests/cpp/packed_func_test.cc | 26 +- .../python/unittest/test_runtime_extension.py | 2 +- topi/src/topi.cc | 2 +- vta/src/device_api.cc | 8 +- web/tvm_runtime.js | 48 ++-- 81 files changed, 580 insertions(+), 587 deletions(-) diff --git a/apps/extension/src/tvm_ext.cc b/apps/extension/src/tvm_ext.cc index d57b41b1215be..7a685bf59e07d 100644 --- a/apps/extension/src/tvm_ext.cc +++ b/apps/extension/src/tvm_ext.cc @@ -156,7 +156,7 @@ TVM_REGISTER_GLOBAL("tvm_ext.nd_create") .set_body([](TVMArgs args, TVMRetValue *rv) { int additional_info = args[0]; *rv = NDSubClass(additional_info); - CHECK_EQ(rv->type_code(), kNDArrayContainer); + CHECK_EQ(rv->type_code(), kTVMNDArrayHandle); }); diff --git a/golang/src/ndarray.go b/golang/src/ndarray.go index e83d4ab1c0570..e7471347405c9 100644 --- a/golang/src/ndarray.go +++ b/golang/src/ndarray.go @@ -47,7 +47,7 @@ func (parray Array) nativeCPtr() (retVal uintptr) { } func (parray Array) nativeCopyFrom(data unsafe.Pointer, datalen int) (err error) { - ret := C.TVMArrayCopyFromBytes((*C.TVMArray)(unsafe.Pointer(parray.nativeCPtr())), + ret := C.TVMArrayCopyFromBytes((*C.DLTensor)(unsafe.Pointer(parray.nativeCPtr())), data, C.ulong(datalen)) if ret != 0 { @@ -65,7 +65,7 @@ func (parray Array) nativeCopyFrom(data unsafe.Pointer, datalen int) (err error) func (parray Array) CopyFrom(val interface{}) (err error) { var data unsafe.Pointer var datalen int - dtype := ((*C.TVMArray)(unsafe.Pointer(parray))).dtype + dtype := ((*C.DLTensor)(unsafe.Pointer(parray))).dtype switch val.(type) { case []int8: @@ -126,7 +126,7 @@ func (parray Array) CopyFrom(val interface{}) (err error) { } func (parray Array) nativeCopyTo (data unsafe.Pointer, datalen int) (err error){ - ret := C.TVMArrayCopyToBytes((*C.TVMArray)(unsafe.Pointer(parray.nativeCPtr())), + ret := C.TVMArrayCopyToBytes((*C.DLTensor)(unsafe.Pointer(parray.nativeCPtr())), unsafe.Pointer(data), C.ulong(datalen)) @@ -149,7 +149,7 @@ func (parray Array) AsSlice() (retVal interface{}, err error) { for ii := range shape { size *= shape[ii] } - dtype := ((*C.TVMArray)(unsafe.Pointer(parray))).dtype + dtype := ((*C.DLTensor)(unsafe.Pointer(parray))).dtype switch parray.GetDType() { case "int8": @@ -221,13 +221,13 @@ func (parray Array) AsSlice() (retVal interface{}, err error) { // GetNdim returns the number of dimentions in Array func (parray Array) GetNdim() (retVal int32) { - retVal = int32(((*C.TVMArray)(unsafe.Pointer(parray))).ndim) + retVal = int32(((*C.DLTensor)(unsafe.Pointer(parray))).ndim) return } // GetShape returns the number of dimentions in Array func (parray Array) GetShape() (retVal []int64) { - shapePtr := (*C.int64_t)(((*C.TVMArray)(unsafe.Pointer(parray))).shape) + shapePtr := (*C.int64_t)(((*C.DLTensor)(unsafe.Pointer(parray))).shape) ndim := parray.GetNdim() shapeSlice := (*[1<<31] int64)(unsafe.Pointer(shapePtr))[:ndim:ndim] @@ -238,14 +238,14 @@ func (parray Array) GetShape() (retVal []int64) { // GetDType returns the number of dimentions in Array func (parray Array) GetDType() (retVal string) { - ret := ((*C.TVMArray)(unsafe.Pointer(parray))).dtype + ret := ((*C.DLTensor)(unsafe.Pointer(parray))).dtype retVal, _ = dtypeFromTVMType(*(*pTVMType)(unsafe.Pointer(&ret))) return } // GetCtx returns the number of dimentions in Array func (parray Array) GetCtx() (retVal Context) { - ret := ((*C.TVMArray)(unsafe.Pointer(parray))).ctx + ret := ((*C.DLTensor)(unsafe.Pointer(parray))).ctx retVal = *(*Context)(unsafe.Pointer(&ret)) return } @@ -342,6 +342,6 @@ func Empty(shape []int64, args ...interface{}) (parray *Array, err error) { // // `ret` indicates the status of this api execution. func nativeTVMArrayFree(parray Array) (retVal int32) { - retVal = (int32)(C.TVMArrayFree((*C.TVMArray)(unsafe.Pointer(parray.nativeCPtr())))) + retVal = (int32)(C.TVMArrayFree((*C.DLTensor)(unsafe.Pointer(parray.nativeCPtr())))) return } diff --git a/golang/src/value.go b/golang/src/value.go index 1cb599e86486f..a7db894374af9 100644 --- a/golang/src/value.go +++ b/golang/src/value.go @@ -33,38 +33,38 @@ import ( "unsafe" ) -// KHandle is golang type code for TVM enum kHandle. -var KHandle = int32(C.kHandle) -// KNull is golang type code for TVM kNull. -var KNull = int32(C.kNull) -// KTVMType is golang type code for TVM kTVMType. -var KTVMType = int32(C.kTVMType) +// KHandle is golang type code for TVM enum kTVMOpaqueHandle. +var KHandle = int32(C.kTVMOpaqueHandle) +// KNull is golang type code for TVM kTVMNullptr. +var KNull = int32(C.kTVMNullptr) +// KTVMType is golang type code for TVM kTVMDataType. +var KTVMType = int32(C.kTVMDataType) // KTVMContext is golang type code for TVM kTVMContext. var KTVMContext = int32(C.kTVMContext) -// KArrayHandle is golang type code for TVM kArrayHandle. -var KArrayHandle = int32(C.kArrayHandle) -// KObjectHandle is golang type code for TVM kObjectHandle. -var KObjectHandle = int32(C.kObjectHandle) -// KModuleHandle is gonag type code for TVM kModuleHandle. -var KModuleHandle = int32(C.kModuleHandle) -// KFuncHandle is gonalg type code for TVM kFuncHandle. -var KFuncHandle = int32(C.kFuncHandle) -// KStr is golang type code for TVM kStr. -var KStr = int32(C.kStr) -// KBytes is golang type code for TVM kBytes. -var KBytes = int32(C.kBytes) -// KNDArrayContainer is golang typecode for kNDArrayContainer. -var KNDArrayContainer = int32(C.kNDArrayContainer) -// KExtBegin is golang enum corresponding to TVM kExtBegin. -var KExtBegin = int32(C.kExtBegin) +// KArrayHandle is golang type code for TVM kTVMDLTensorHandle. +var KArrayHandle = int32(C.kTVMDLTensorHandle) +// KObjectHandle is golang type code for TVM kTVMObjectHandle. +var KObjectHandle = int32(C.kTVMObjectHandle) +// KModuleHandle is gonag type code for TVM kTVMModuleHandle. +var KModuleHandle = int32(C.kTVMModuleHandle) +// KFuncHandle is gonalg type code for TVM kTVMPackedFuncHandle. +var KFuncHandle = int32(C.kTVMPackedFuncHandle) +// KStr is golang type code for TVM kTVMStr. +var KStr = int32(C.kTVMStr) +// KBytes is golang type code for TVM kTVMBytes. +var KBytes = int32(C.kTVMBytes) +// KNDArrayContainer is golang typecode for kTVMNDArrayHandle. +var KNDArrayContainer = int32(C.kTVMNDArrayHandle) +// KExtBegin is golang enum corresponding to TVM kTVMExtBegin. +var KExtBegin = int32(C.kTVMExtBegin) // KNNVMFirst is golang enum corresponding to TVM kNNVMFirst. -var KNNVMFirst = int32(C.kNNVMFirst) +var KNNVMFirst = int32(C.kTVMNNVMFirst) // KNNVMLast is golang enum corresponding to TVM kNNVMLast. -var KNNVMLast = int32(C.kNNVMLast) +var KNNVMLast = int32(C.kTVMNNVMLast) // KExtReserveEnd is golang enum corresponding to TVM kExtReserveEnd. -var KExtReserveEnd = int32(C.kExtReserveEnd) +var KExtReserveEnd = int32(C.kTVMExtReserveEnd) // KExtEnd is golang enum corresponding to TVM kExtEnd. -var KExtEnd = int32(C.kExtEnd) +var KExtEnd = int32(C.kTVMExtEnd) // KDLInt is golang type code for TVM kDLInt. var KDLInt = int32(C.kDLInt) // KDLUInt is golang type code for TVM kDLUInt. diff --git a/include/tvm/expr_operator.h b/include/tvm/expr_operator.h index 7d6b752597bc1..4fa8da1c6b72d 100644 --- a/include/tvm/expr_operator.h +++ b/include/tvm/expr_operator.h @@ -682,7 +682,7 @@ inline PrimExpr MakeConstScalar(DataType t, ValueType value) { // datatypes lowering pass, we will lower the value to its true representation in the format // specified by the datatype. // TODO(gus) when do we need to start worrying about doubles not being precise enough? - if (static_cast(t.code()) >= static_cast(kCustomBegin)) { + if (static_cast(t.code()) >= static_cast(kTVMCustomBegin)) { return FloatImm(t, static_cast(value)); } LOG(FATAL) << "cannot make const for type " << t; diff --git a/include/tvm/ir/attrs.h b/include/tvm/ir/attrs.h index 5916a78ea130d..1d02bf708ee3f 100644 --- a/include/tvm/ir/attrs.h +++ b/include/tvm/ir/attrs.h @@ -88,7 +88,7 @@ inline TObjectRef NullValue() { template<> inline DataType NullValue() { - return DataType(kHandle, 0, 0); + return DataType(DataType::kHandle, 0, 0); } /*! \brief Error thrown during attribute checking. */ @@ -492,7 +492,7 @@ inline void SetIntValue(T* ptr, const TVMArgValue& val) { template<> inline void SetValue(std::string* ptr, const TVMArgValue& val) { - if (val.type_code() == kStr) { + if (val.type_code() == kTVMStr) { *ptr = val.operator std::string(); } else { LOG(FATAL) << "Expect str"; @@ -762,7 +762,7 @@ class AttrsNode : public BaseAttrsNode { // linear search. auto ffind = [&args](const char* key, runtime::TVMArgValue* val) { for (int i = 0; i < args.size(); i += 2) { - CHECK_EQ(args.type_codes[i], kStr); + CHECK_EQ(args.type_codes[i], kTVMStr); if (!std::strcmp(key, args.values[i].v_str)) { *val = args[i + 1]; return true; @@ -777,7 +777,7 @@ class AttrsNode : public BaseAttrsNode { // construct a map then do lookup. std::unordered_map kwargs; for (int i = 0; i < args.size(); i += 2) { - CHECK_EQ(args.type_codes[i], kStr); + CHECK_EQ(args.type_codes[i], kTVMStr); kwargs[args[i].operator std::string()] = args[i + 1]; } auto ffind = [&kwargs](const char *key, runtime::TVMArgValue* val) { diff --git a/include/tvm/packed_func_ext.h b/include/tvm/packed_func_ext.h index 28918954b1862..cc380cdbd8aa7 100644 --- a/include/tvm/packed_func_ext.h +++ b/include/tvm/packed_func_ext.h @@ -100,7 +100,7 @@ struct ObjectTypeChecker > { // extensions for tvm arg value inline TVMPODValue_::operator tvm::PrimExpr() const { - if (type_code_ == kNull) return PrimExpr(); + if (type_code_ == kTVMNullptr) return PrimExpr(); if (type_code_ == kDLInt) { CHECK_LE(value_.v_int64, std::numeric_limits::max()); CHECK_GE(value_.v_int64, std::numeric_limits::min()); @@ -110,7 +110,7 @@ inline TVMPODValue_::operator tvm::PrimExpr() const { return PrimExpr(static_cast(value_.v_float64)); } - TVM_CHECK_TYPE_CODE(type_code_, kObjectHandle); + TVM_CHECK_TYPE_CODE(type_code_, kTVMObjectHandle); Object* ptr = static_cast(value_.v_handle); if (ptr->IsInstance()) { @@ -126,13 +126,13 @@ inline TVMPODValue_::operator tvm::PrimExpr() const { } inline TVMPODValue_::operator tvm::Integer() const { - if (type_code_ == kNull) return Integer(); + if (type_code_ == kTVMNullptr) return Integer(); if (type_code_ == kDLInt) { CHECK_LE(value_.v_int64, std::numeric_limits::max()); CHECK_GE(value_.v_int64, std::numeric_limits::min()); return Integer(static_cast(value_.v_int64)); } - TVM_CHECK_TYPE_CODE(type_code_, kObjectHandle); + TVM_CHECK_TYPE_CODE(type_code_, kTVMObjectHandle); Object* ptr = static_cast(value_.v_handle); CHECK(ObjectTypeChecker::Check(ptr)) << "Expect type " << ObjectTypeChecker::TypeName() diff --git a/include/tvm/runtime/c_runtime_api.h b/include/tvm/runtime/c_runtime_api.h index 8cb86bf725bc8..dba9dffad43af 100644 --- a/include/tvm/runtime/c_runtime_api.h +++ b/include/tvm/runtime/c_runtime_api.h @@ -86,62 +86,44 @@ typedef enum { } TVMDeviceExtType; /*! - * \brief The type code in TVMType - * \note TVMType is used in two places. + * \brief The type code in used in the TVM FFI. */ typedef enum { // The type code of other types are compatible with DLPack. // The next few fields are extension types // that is used by TVM API calls. - kHandle = 3U, - kNull = 4U, - kTVMType = 5U, + kTVMOpaqueHandle = 3U, + kTVMNullptr = 4U, + kTVMDataType = 5U, kTVMContext = 6U, - kArrayHandle = 7U, - kObjectHandle = 8U, - kModuleHandle = 9U, - kFuncHandle = 10U, - kStr = 11U, - kBytes = 12U, - kNDArrayContainer = 13U, + kTVMDLTensorHandle = 7U, + kTVMObjectHandle = 8U, + kTVMModuleHandle = 9U, + kTVMPackedFuncHandle = 10U, + kTVMStr = 11U, + kTVMBytes = 12U, + kTVMNDArrayHandle = 13U, // Extension codes for other frameworks to integrate TVM PackedFunc. // To make sure each framework's id do not conflict, use first and // last sections to mark ranges. // Open an issue at the repo if you need a section of code. - kExtBegin = 15U, - kNNVMFirst = 16U, - kNNVMLast = 20U, + kTVMExtBegin = 15U, + kTVMNNVMFirst = 16U, + kTVMNNVMLast = 20U, // The following section of code is used for non-reserved types. - kExtReserveEnd = 64U, - kExtEnd = 128U, + kTVMExtReserveEnd = 64U, + kTVMExtEnd = 128U, // The rest of the space is used for custom, user-supplied datatypes - kCustomBegin = 129U, + kTVMCustomBegin = 129U, } TVMTypeCode; -/*! - * \brief The data type used in TVM Runtime. - * - * Examples - * - float: type_code = 2, bits = 32, lanes=1 - * - float4(vectorized 4 float): type_code = 2, bits = 32, lanes=4 - * - int8: type_code = 0, bits = 8, lanes=1 - * - * \note Arguments TVM API function always takes bits=64 and lanes=1 - */ -typedef DLDataType TVMType; - /*! * \brief The Device information, abstract away common device types. */ typedef DLContext TVMContext; -/*! - * \brief The tensor array structure to TVM API. - */ -typedef DLTensor TVMArray; - /*! \brief the array handle */ -typedef TVMArray* TVMArrayHandle; +typedef DLTensor* TVMArrayHandle; /*! * \brief Union type of values @@ -152,13 +134,13 @@ typedef union { double v_float64; void* v_handle; const char* v_str; - TVMType v_type; + DLDataType v_type; TVMContext v_ctx; } TVMValue; /*! * \brief Byte array type used to pass in byte array - * When kBytes is used as data type. + * When kTVMBytes is used as data type. */ typedef struct { const char* data; diff --git a/include/tvm/runtime/data_type.h b/include/tvm/runtime/data_type.h index 5b222ac6b4426..c91c2cf824529 100644 --- a/include/tvm/runtime/data_type.h +++ b/include/tvm/runtime/data_type.h @@ -44,7 +44,7 @@ class DataType { kInt = kDLInt, kUInt = kDLUInt, kFloat = kDLFloat, - kHandle = TVMTypeCode::kHandle, + kHandle = TVMTypeCode::kTVMOpaqueHandle, }; /*! \brief default constructor */ DataType() {} diff --git a/include/tvm/runtime/device_api.h b/include/tvm/runtime/device_api.h index 4b0fcd3159ab5..7212aad5aa202 100644 --- a/include/tvm/runtime/device_api.h +++ b/include/tvm/runtime/device_api.h @@ -88,7 +88,7 @@ class TVM_DLL DeviceAPI { virtual void* AllocDataSpace(TVMContext ctx, size_t nbytes, size_t alignment, - TVMType type_hint) = 0; + DLDataType type_hint) = 0; /*! * \brief Free a data space on device. * \param ctx The device context to perform operation. @@ -115,7 +115,7 @@ class TVM_DLL DeviceAPI { size_t num_bytes, TVMContext ctx_from, TVMContext ctx_to, - TVMType type_hint, + DLDataType type_hint, TVMStreamHandle stream) = 0; /*! * \brief Create a new stream of execution. @@ -177,7 +177,7 @@ class TVM_DLL DeviceAPI { */ virtual void* AllocWorkspace(TVMContext ctx, size_t nbytes, - TVMType type_hint = {}); + DLDataType type_hint = {}); /*! * \brief Free temporal workspace in backend execution. * diff --git a/include/tvm/runtime/packed_func.h b/include/tvm/runtime/packed_func.h index afaff9c7364a0..d3ba2ae776877 100644 --- a/include/tvm/runtime/packed_func.h +++ b/include/tvm/runtime/packed_func.h @@ -374,14 +374,14 @@ inline const char* TypeCode2Str(int type_code); * \param s The string to be converted. * \return The corresponding tvm type. */ -inline TVMType String2TVMType(std::string s); +inline DLDataType String2DLDataType(std::string s); /*! * \brief convert a TVM type to string. * \param t The type to be converted. * \return The corresponding tvm type in string. */ -inline std::string TVMType2String(TVMType t); +inline std::string DLDataType2String(DLDataType t); // macro to check type code. #define TVM_CHECK_TYPE_CODE(CODE, T) \ @@ -440,17 +440,17 @@ class TVMPODValue_ { return value_.v_int64 != 0; } operator void*() const { - if (type_code_ == kNull) return nullptr; - if (type_code_ == kArrayHandle) return value_.v_handle; - TVM_CHECK_TYPE_CODE(type_code_, kHandle); + if (type_code_ == kTVMNullptr) return nullptr; + if (type_code_ == kTVMDLTensorHandle) return value_.v_handle; + TVM_CHECK_TYPE_CODE(type_code_, kTVMOpaqueHandle); return value_.v_handle; } operator DLTensor*() const { - if (type_code_ == kArrayHandle || - type_code_ == kNDArrayContainer) { + if (type_code_ == kTVMDLTensorHandle || + type_code_ == kTVMNDArrayHandle) { return static_cast(value_.v_handle); } else { - if (type_code_ == kNull) return nullptr; + if (type_code_ == kTVMNullptr) return nullptr; LOG(FATAL) << "Expect " << "DLTensor* or NDArray but get " << TypeCode2Str(type_code_); @@ -458,16 +458,16 @@ class TVMPODValue_ { } } operator NDArray() const { - if (type_code_ == kNull) return NDArray(ObjectPtr(nullptr)); - TVM_CHECK_TYPE_CODE(type_code_, kNDArrayContainer); + if (type_code_ == kTVMNullptr) return NDArray(ObjectPtr(nullptr)); + TVM_CHECK_TYPE_CODE(type_code_, kTVMNDArrayHandle); return NDArray(NDArray::FFIDataFromHandle( static_cast(value_.v_handle))); } operator Module() const { - if (type_code_ == kNull) { + if (type_code_ == kTVMNullptr) { return Module(ObjectPtr(nullptr)); } - TVM_CHECK_TYPE_CODE(type_code_, kModuleHandle); + TVM_CHECK_TYPE_CODE(type_code_, kTVMModuleHandle); return Module( ObjectPtr(static_cast(value_.v_handle))); } @@ -501,7 +501,7 @@ class TVMPODValue_ { protected: friend class TVMArgsSetter; friend class TVMRetValue; - TVMPODValue_() : type_code_(kNull) {} + TVMPODValue_() : type_code_(kTVMNullptr) {} TVMPODValue_(TVMValue value, int type_code) : value_(value), type_code_(type_code) {} @@ -547,35 +547,35 @@ class TVMArgValue : public TVMPODValue_ { // conversion operator. operator std::string() const { - if (type_code_ == kTVMType) { - return TVMType2String(operator TVMType()); - } else if (type_code_ == kBytes) { + if (type_code_ == kTVMDataType) { + return DLDataType2String(operator DLDataType()); + } else if (type_code_ == kTVMBytes) { TVMByteArray* arr = static_cast(value_.v_handle); return std::string(arr->data, arr->size); } else { - TVM_CHECK_TYPE_CODE(type_code_, kStr); + TVM_CHECK_TYPE_CODE(type_code_, kTVMStr); return std::string(value_.v_str); } } - operator TVMType() const { - if (type_code_ == kStr) { - return String2TVMType(operator std::string()); + operator DLDataType() const { + if (type_code_ == kTVMStr) { + return String2DLDataType(operator std::string()); } // None type - if (type_code_ == kNull) { - TVMType t; - t.code = kHandle; t.bits = 0; t.lanes = 0; + if (type_code_ == kTVMNullptr) { + DLDataType t; + t.code = kTVMOpaqueHandle; t.bits = 0; t.lanes = 0; return t; } - TVM_CHECK_TYPE_CODE(type_code_, kTVMType); + TVM_CHECK_TYPE_CODE(type_code_, kTVMDataType); return value_.v_type; } operator DataType() const { return DataType(operator DLDataType()); } operator PackedFunc() const { - if (type_code_ == kNull) return PackedFunc(); - TVM_CHECK_TYPE_CODE(type_code_, kFuncHandle); + if (type_code_ == kTVMNullptr) return PackedFunc(); + TVM_CHECK_TYPE_CODE(type_code_, kTVMPackedFuncHandle); return *ptr(); } template @@ -610,7 +610,7 @@ class TVMRetValue : public TVMPODValue_ { TVMRetValue(TVMRetValue&& other) : TVMPODValue_(other.value_, other.type_code_) { other.value_.v_handle = nullptr; - other.type_code_ = kNull; + other.type_code_ = kTVMNullptr; } /*! \brief destructor */ ~TVMRetValue() { @@ -637,27 +637,27 @@ class TVMRetValue : public TVMPODValue_ { } // conversion operators operator std::string() const { - if (type_code_ == kTVMType) { - return TVMType2String(operator TVMType()); - } else if (type_code_ == kBytes) { + if (type_code_ == kTVMDataType) { + return DLDataType2String(operator DLDataType()); + } else if (type_code_ == kTVMBytes) { return *ptr(); } - TVM_CHECK_TYPE_CODE(type_code_, kStr); + TVM_CHECK_TYPE_CODE(type_code_, kTVMStr); return *ptr(); } - operator TVMType() const { - if (type_code_ == kStr) { - return String2TVMType(operator std::string()); + operator DLDataType() const { + if (type_code_ == kTVMStr) { + return String2DLDataType(operator std::string()); } - TVM_CHECK_TYPE_CODE(type_code_, kTVMType); + TVM_CHECK_TYPE_CODE(type_code_, kTVMDataType); return value_.v_type; } operator DataType() const { return DataType(operator DLDataType()); } operator PackedFunc() const { - if (type_code_ == kNull) return PackedFunc(); - TVM_CHECK_TYPE_CODE(type_code_, kFuncHandle); + if (type_code_ == kTVMNullptr) return PackedFunc(); + TVM_CHECK_TYPE_CODE(type_code_, kTVMPackedFuncHandle); return *ptr(); } template @@ -669,7 +669,7 @@ class TVMRetValue : public TVMPODValue_ { this->Clear(); value_ = other.value_; type_code_ = other.type_code_; - other.type_code_ = kNull; + other.type_code_ = kTVMNullptr; return *this; } TVMRetValue& operator=(double value) { @@ -678,12 +678,12 @@ class TVMRetValue : public TVMPODValue_ { return *this; } TVMRetValue& operator=(std::nullptr_t value) { - this->SwitchToPOD(kNull); + this->SwitchToPOD(kTVMNullptr); value_.v_handle = value; return *this; } TVMRetValue& operator=(void* value) { - this->SwitchToPOD(kHandle); + this->SwitchToPOD(kTVMOpaqueHandle); value_.v_handle = value; return *this; } @@ -702,8 +702,8 @@ class TVMRetValue : public TVMPODValue_ { value_.v_ctx = value; return *this; } - TVMRetValue& operator=(TVMType t) { - this->SwitchToPOD(kTVMType); + TVMRetValue& operator=(DLDataType t) { + this->SwitchToPOD(kTVMDataType); value_.v_type = t; return *this; } @@ -716,30 +716,30 @@ class TVMRetValue : public TVMPODValue_ { return *this; } TVMRetValue& operator=(std::string value) { - this->SwitchToClass(kStr, value); + this->SwitchToClass(kTVMStr, value); return *this; } TVMRetValue& operator=(TVMByteArray value) { - this->SwitchToClass(kBytes, std::string(value.data, value.size)); + this->SwitchToClass(kTVMBytes, std::string(value.data, value.size)); return *this; } TVMRetValue& operator=(NDArray other) { if (other.data_ != nullptr) { this->Clear(); - type_code_ = kNDArrayContainer; + type_code_ = kTVMNDArrayHandle; value_.v_handle = NDArray::FFIGetHandle(other); ObjectRef::FFIClearAfterMove(&other); } else { - SwitchToPOD(kNull); + SwitchToPOD(kTVMNullptr); } return *this; } TVMRetValue& operator=(Module m) { - SwitchToObject(kModuleHandle, std::move(m.data_)); + SwitchToObject(kTVMModuleHandle, std::move(m.data_)); return *this; } TVMRetValue& operator=(PackedFunc f) { - this->SwitchToClass(kFuncHandle, f); + this->SwitchToClass(kTVMPackedFuncHandle, f); return *this; } template @@ -766,10 +766,10 @@ class TVMRetValue : public TVMPODValue_ { void MoveToCHost(TVMValue* ret_value, int* ret_type_code) { // cannot move str; need specially handle. - CHECK(type_code_ != kStr && type_code_ != kBytes); + CHECK(type_code_ != kTVMStr && type_code_ != kTVMBytes); *ret_value = value_; *ret_type_code = type_code_; - type_code_ = kNull; + type_code_ = kTVMNullptr; } /*! * \brief Construct a new TVMRetValue by @@ -781,8 +781,8 @@ class TVMRetValue : public TVMPODValue_ { static TVMRetValue MoveFromCHost(TVMValue value, int type_code) { // Can move POD and everything under the object system. - CHECK(type_code <= kFuncHandle || - type_code == kNDArrayContainer); + CHECK(type_code <= kTVMPackedFuncHandle || + type_code == kTVMNDArrayHandle); TVMRetValue ret; ret.value_ = value; ret.type_code_ = type_code; @@ -790,10 +790,10 @@ class TVMRetValue : public TVMPODValue_ { } /*! \return The value field, if the data is POD */ const TVMValue& value() const { - CHECK(type_code_ != kObjectHandle && - type_code_ != kFuncHandle && - type_code_ != kModuleHandle && - type_code_ != kStr) << "TVMRetValue.value can only be used for POD data"; + CHECK(type_code_ != kTVMObjectHandle && + type_code_ != kTVMPackedFuncHandle && + type_code_ != kTVMModuleHandle && + type_code_ != kTVMStr) << "TVMRetValue.value can only be used for POD data"; return value_; } // ObjectRef handling @@ -810,30 +810,30 @@ class TVMRetValue : public TVMPODValue_ { template void Assign(const T& other) { switch (other.type_code()) { - case kStr: { - SwitchToClass(kStr, other); + case kTVMStr: { + SwitchToClass(kTVMStr, other); break; } - case kBytes: { - SwitchToClass(kBytes, other); + case kTVMBytes: { + SwitchToClass(kTVMBytes, other); break; } - case kFuncHandle: { - SwitchToClass(kFuncHandle, other); + case kTVMPackedFuncHandle: { + SwitchToClass(kTVMPackedFuncHandle, other); break; } - case kModuleHandle: { + case kTVMModuleHandle: { *this = other.operator Module(); break; } - case kNDArrayContainer: { + case kTVMNDArrayHandle: { *this = other.operator NDArray(); break; } - case kObjectHandle: { + case kTVMObjectHandle: { // Avoid operator ObjectRef as we already know it is not NDArray/Module SwitchToObject( - kObjectHandle, GetObjectPtr( + kTVMObjectHandle, GetObjectPtr( static_cast(other.value_.v_handle))); break; } @@ -869,28 +869,28 @@ class TVMRetValue : public TVMPODValue_ { value_.v_handle = other.data_; other.data_ = nullptr; } else { - SwitchToPOD(kNull); + SwitchToPOD(kTVMNullptr); } } void Clear() { - if (type_code_ == kNull) return; + if (type_code_ == kTVMNullptr) return; switch (type_code_) { - case kStr: delete ptr(); break; - case kFuncHandle: delete ptr(); break; - case kNDArrayContainer: { + case kTVMStr: delete ptr(); break; + case kTVMPackedFuncHandle: delete ptr(); break; + case kTVMNDArrayHandle: { NDArray::FFIDecRef(static_cast(value_.v_handle)); break; } - case kModuleHandle: { + case kTVMModuleHandle: { static_cast(value_.v_handle)->DecRef(); break; } - case kObjectHandle: { + case kTVMObjectHandle: { static_cast(value_.v_handle)->DecRef(); break; } } - type_code_ = kNull; + type_code_ = kTVMNullptr; } }; @@ -998,33 +998,33 @@ inline const char* TypeCode2Str(int type_code) { case kDLInt: return "int"; case kDLUInt: return "uint"; case kDLFloat: return "float"; - case kStr: return "str"; - case kBytes: return "bytes"; - case kHandle: return "handle"; - case kNull: return "NULL"; - case kArrayHandle: return "ArrayHandle"; - case kTVMType: return "TVMType"; + case kTVMStr: return "str"; + case kTVMBytes: return "bytes"; + case kTVMOpaqueHandle: return "handle"; + case kTVMNullptr: return "NULL"; + case kTVMDLTensorHandle: return "ArrayHandle"; + case kTVMDataType: return "DLDataType"; case kTVMContext: return "TVMContext"; - case kFuncHandle: return "FunctionHandle"; - case kModuleHandle: return "ModuleHandle"; - case kNDArrayContainer: return "NDArrayContainer"; - case kObjectHandle: return "Object"; + case kTVMPackedFuncHandle: return "FunctionHandle"; + case kTVMModuleHandle: return "ModuleHandle"; + case kTVMNDArrayHandle: return "NDArrayContainer"; + case kTVMObjectHandle: return "Object"; default: LOG(FATAL) << "unknown type_code=" << static_cast(type_code); return ""; } } #ifndef _LIBCPP_SGX_NO_IOSTREAMS -inline std::ostream& operator<<(std::ostream& os, TVMType t) { // NOLINT(*) +inline std::ostream& operator<<(std::ostream& os, DLDataType t) { // NOLINT(*) if (t.bits == 1 && t.lanes == 1 && t.code == kDLUInt) { os << "bool"; return os; } - if (t.code < kCustomBegin) { + if (t.code < kTVMCustomBegin) { os << TypeCode2Str(t.code); } else { os << "custom[" << GetCustomTypeName(t.code) << "]"; } - if (t.code == kHandle) return os; + if (t.code == kTVMOpaqueHandle) return os; os << static_cast(t.bits); if (t.lanes != 1) { os << 'x' << static_cast(t.lanes); @@ -1038,7 +1038,7 @@ inline std::ostream& operator<<(std::ostream& os, const DataType& dtype) { // NO #endif -inline std::string TVMType2String(TVMType t) { +inline std::string DLDataType2String(DLDataType t) { if (t.bits == 0) return ""; #ifndef _LIBCPP_SGX_NO_IOSTREAMS std::ostringstream os; @@ -1048,12 +1048,12 @@ inline std::string TVMType2String(TVMType t) { if (t.bits == 1 && t.lanes == 1 && t.code == kDLUInt) { return "bool"; } - if (t.code < kCustomBegin) { + if (t.code < kTVMCustomBegin) { repr += TypeCode2Str(t.code); } else { repr += "custom[" + GetCustomTypeName(t.code) + "]"; } - if (t.code == kHandle) return repr; + if (t.code == kTVMOpaqueHandle) return repr; repr += std::to_string(static_cast(t.bits)); if (t.lanes != 1) { repr += "x" + std::to_string(static_cast(t.lanes)); @@ -1062,11 +1062,11 @@ inline std::string TVMType2String(TVMType t) { #endif } -inline TVMType String2TVMType(std::string s) { - TVMType t; +inline DLDataType String2DLDataType(std::string s) { + DLDataType t; // handle None type if (s.length() == 0) { - t.bits = 0; t.lanes = 0; t.code = kHandle; + t.bits = 0; t.lanes = 0; t.code = kTVMOpaqueHandle; return t; } t.bits = 32; t.lanes = 1; @@ -1078,7 +1078,7 @@ inline TVMType String2TVMType(std::string s) { } else if (s.substr(0, 5) == "float") { t.code = kDLFloat; scan = s.c_str() + 5; } else if (s.substr(0, 6) == "handle") { - t.code = kHandle; + t.code = kTVMOpaqueHandle; t.bits = 64; // handle uses 64 bit by default. scan = s.c_str() + 6; } else if (s == "bool") { @@ -1209,7 +1209,7 @@ class TVMArgsSetter { } void operator()(size_t i, std::nullptr_t value) const { values_[i].v_handle = value; - type_codes_[i] = kNull; + type_codes_[i] = kTVMNullptr; } void operator()(size_t i, const TVMArgValue& value) const { values_[i] = value.value_; @@ -1217,50 +1217,50 @@ class TVMArgsSetter { } void operator()(size_t i, void* value) const { values_[i].v_handle = value; - type_codes_[i] = kHandle; + type_codes_[i] = kTVMOpaqueHandle; } void operator()(size_t i, DLTensor* value) const { values_[i].v_handle = value; - type_codes_[i] = kArrayHandle; + type_codes_[i] = kTVMDLTensorHandle; } void operator()(size_t i, TVMContext value) const { values_[i].v_ctx = value; type_codes_[i] = kTVMContext; } - void operator()(size_t i, TVMType value) const { + void operator()(size_t i, DLDataType value) const { values_[i].v_type = value; - type_codes_[i] = kTVMType; + type_codes_[i] = kTVMDataType; } void operator()(size_t i, DataType dtype) const { operator()(i, dtype.operator DLDataType()); } void operator()(size_t i, const char* value) const { values_[i].v_str = value; - type_codes_[i] = kStr; + type_codes_[i] = kTVMStr; } // setters for container types void operator()(size_t i, const std::string& value) const { values_[i].v_str = value.c_str(); - type_codes_[i] = kStr; + type_codes_[i] = kTVMStr; } void operator()(size_t i, const TVMByteArray& value) const { values_[i].v_handle = const_cast(&value); - type_codes_[i] = kBytes; + type_codes_[i] = kTVMBytes; } void operator()(size_t i, const PackedFunc& value) const { values_[i].v_handle = const_cast(&value); - type_codes_[i] = kFuncHandle; + type_codes_[i] = kTVMPackedFuncHandle; } template void operator()(size_t i, const TypedPackedFunc& value) const { operator()(i, value.packed()); } void operator()(size_t i, const TVMRetValue& value) const { - if (value.type_code() == kStr) { + if (value.type_code() == kTVMStr) { values_[i].v_str = value.ptr()->c_str(); - type_codes_[i] = kStr; + type_codes_[i] = kTVMStr; } else { - CHECK_NE(value.type_code(), kBytes) << "not handled."; + CHECK_NE(value.type_code(), kTVMBytes) << "not handled."; values_[i] = value.value_; type_codes_[i] = value.type_code(); } @@ -1397,7 +1397,7 @@ inline R TypedPackedFunc::operator()(Args... args) const { // ObjectRef related conversion handling // Object can have three possible type codes: -// kNDArrayContainer, kModuleHandle, kObjectHandle +// kTVMNDArrayHandle, kTVMModuleHandle, kTVMObjectHandle // // We use type traits to eliminate un-necessary checks. template @@ -1408,18 +1408,18 @@ inline void TVMArgsSetter::operator()(size_t i, const TObjectRef& value) const { (std::is_base_of::value && ptr->IsInstance())) { values_[i].v_handle = NDArray::FFIGetHandle(value); - type_codes_[i] = kNDArrayContainer; + type_codes_[i] = kTVMNDArrayHandle; } else if (std::is_base_of::value || (std::is_base_of::value && ptr->IsInstance())) { values_[i].v_handle = ptr; - type_codes_[i] = kModuleHandle; + type_codes_[i] = kTVMModuleHandle; } else { values_[i].v_handle = ptr; - type_codes_[i] = kObjectHandle; + type_codes_[i] = kTVMObjectHandle; } } else { - type_codes_[i] = kNull; + type_codes_[i] = kTVMNullptr; } } @@ -1428,18 +1428,18 @@ inline bool TVMPODValue_::IsObjectRef() const { using ContainerType = typename TObjectRef::ContainerType; // NOTE: the following code can be optimized by constant folding. if (std::is_base_of::value) { - return type_code_ == kNDArrayContainer && + return type_code_ == kTVMNDArrayHandle && TVMArrayHandleToObjectHandle( static_cast(value_.v_handle))->IsInstance(); } if (std::is_base_of::value) { - return type_code_ == kModuleHandle && + return type_code_ == kTVMModuleHandle && static_cast(value_.v_handle)->IsInstance(); } return - (std::is_base_of::value && type_code_ == kNDArrayContainer) || - (std::is_base_of::value && type_code_ == kModuleHandle) || - (type_code_ == kObjectHandle && + (std::is_base_of::value && type_code_ == kTVMNDArrayHandle) || + (std::is_base_of::value && type_code_ == kTVMModuleHandle) || + (type_code_ == kTVMObjectHandle && ObjectTypeChecker::Check(static_cast(value_.v_handle))); } @@ -1449,11 +1449,11 @@ inline TObjectRef TVMPODValue_::AsObjectRef() const { std::is_base_of::value, "Conversion only works for ObjectRef"); using ContainerType = typename TObjectRef::ContainerType; - if (type_code_ == kNull) return TObjectRef(ObjectPtr(nullptr)); + if (type_code_ == kTVMNullptr) return TObjectRef(ObjectPtr(nullptr)); // NOTE: the following code can be optimized by constant folding. if (std::is_base_of::value) { // Casting to a sub-class of NDArray - TVM_CHECK_TYPE_CODE(type_code_, kNDArrayContainer); + TVM_CHECK_TYPE_CODE(type_code_, kTVMNDArrayHandle); ObjectPtr data = NDArray::FFIDataFromHandle( static_cast(value_.v_handle)); CHECK(data->IsInstance()) @@ -1462,13 +1462,13 @@ inline TObjectRef TVMPODValue_::AsObjectRef() const { } if (std::is_base_of::value) { // Casting to a sub-class of Module - TVM_CHECK_TYPE_CODE(type_code_, kModuleHandle); + TVM_CHECK_TYPE_CODE(type_code_, kTVMModuleHandle); ObjectPtr data = GetObjectPtr(static_cast(value_.v_handle)); CHECK(data->IsInstance()) << "Expect " << ContainerType::_type_key << " but get " << data->GetTypeKey(); return TObjectRef(data); } - if (type_code_ == kObjectHandle) { + if (type_code_ == kTVMObjectHandle) { // normal object type check. Object* ptr = static_cast(value_.v_handle); CHECK(ObjectTypeChecker::Check(ptr)) @@ -1476,17 +1476,17 @@ inline TObjectRef TVMPODValue_::AsObjectRef() const { << " but get " << ptr->GetTypeKey(); return TObjectRef(GetObjectPtr(ptr)); } else if (std::is_base_of::value && - type_code_ == kNDArrayContainer) { + type_code_ == kTVMNDArrayHandle) { // Casting to a base class that NDArray can sub-class ObjectPtr data = NDArray::FFIDataFromHandle( static_cast(value_.v_handle)); return TObjectRef(data); } else if (std::is_base_of::value && - type_code_ == kModuleHandle) { + type_code_ == kTVMModuleHandle) { // Casting to a base class that Module can sub-class return TObjectRef(GetObjectPtr(static_cast(value_.v_handle))); } else { - TVM_CHECK_TYPE_CODE(type_code_, kObjectHandle); + TVM_CHECK_TYPE_CODE(type_code_, kTVMObjectHandle); return TObjectRef(ObjectPtr(nullptr)); } } @@ -1505,9 +1505,9 @@ inline TVMRetValue& TVMRetValue::operator=(TObjectRef other) { ptr->IsInstance())) { return operator=(Module(std::move(other.data_))); } - SwitchToObject(kObjectHandle, std::move(other.data_)); + SwitchToObject(kTVMObjectHandle, std::move(other.data_)); } else { - SwitchToPOD(kNull); + SwitchToPOD(kTVMNullptr); } return *this; } diff --git a/include/tvm/runtime/util.h b/include/tvm/runtime/util.h index e725524d5c2b5..8e213dd146b89 100644 --- a/include/tvm/runtime/util.h +++ b/include/tvm/runtime/util.h @@ -36,7 +36,7 @@ namespace runtime { * \param bits The number of bits to be matched. * \param lanes The number of lanes in the type. */ -inline bool TypeMatch(TVMType t, int code, int bits, int lanes = 1) { +inline bool TypeMatch(DLDataType t, int code, int bits, int lanes = 1) { return t.code == code && t.bits == bits && t.lanes == lanes; } /*! @@ -44,7 +44,7 @@ inline bool TypeMatch(TVMType t, int code, int bits, int lanes = 1) { * \param lhs The left operand. * \param rhs The right operand. */ -inline bool TypeEqual(TVMType lhs, TVMType rhs) { +inline bool TypeEqual(DLDataType lhs, DLDataType rhs) { return lhs.code == rhs.code && lhs.bits == rhs.bits && lhs.lanes == rhs.lanes; } } // namespace runtime diff --git a/jvm/native/src/main/native/jni_helper_func.h b/jvm/native/src/main/native/jni_helper_func.h index 14866206dc193..ce1979c6618b4 100644 --- a/jvm/native/src/main/native/jni_helper_func.h +++ b/jvm/native/src/main/native/jni_helper_func.h @@ -167,8 +167,8 @@ jobject newObject(JNIEnv *env, const char *clsname) { return object; } -void fromJavaDType(JNIEnv *env, jobject jdtype, TVMType *dtype) { - jclass tvmTypeClass = env->FindClass("org/apache/tvm/TVMType"); +void fromJavaDType(JNIEnv *env, jobject jdtype, DLDataType *dtype) { + jclass tvmTypeClass = env->FindClass("org/apache/tvm/DLDataType"); dtype->code = (uint8_t)(env->GetIntField(jdtype, env->GetFieldID(tvmTypeClass, "typeCode", "I"))); dtype->bits = (uint8_t)(env->GetIntField(jdtype, env->GetFieldID(tvmTypeClass, "bits", "I"))); dtype->lanes = (uint16_t)(env->GetIntField(jdtype, env->GetFieldID(tvmTypeClass, "lanes", "I"))); @@ -191,21 +191,21 @@ jobject tvmRetValueToJava(JNIEnv *env, TVMValue value, int tcode) { return newTVMValueLong(env, static_cast(value.v_int64)); case kDLFloat: return newTVMValueDouble(env, static_cast(value.v_float64)); - case kHandle: + case kTVMOpaqueHandle: return newTVMValueHandle(env, reinterpret_cast(value.v_handle)); - case kModuleHandle: + case kTVMModuleHandle: return newModule(env, reinterpret_cast(value.v_handle)); - case kFuncHandle: + case kTVMPackedFuncHandle: return newFunction(env, reinterpret_cast(value.v_handle)); - case kArrayHandle: + case kTVMDLTensorHandle: return newNDArray(env, reinterpret_cast(value.v_handle), true); - case kNDArrayContainer: + case kTVMNDArrayHandle: return newNDArray(env, reinterpret_cast(value.v_handle), false); - case kStr: + case kTVMStr: return newTVMValueString(env, value.v_str); - case kBytes: + case kTVMBytes: return newTVMValueBytes(env, reinterpret_cast(value.v_handle)); - case kNull: + case kTVMNullptr: return newObject(env, "org/apache/tvm/TVMValueNull"); default: LOG(FATAL) << "Do NOT know how to handle return type code " << tcode; diff --git a/jvm/native/src/main/native/org_apache_tvm_native_c_api.cc b/jvm/native/src/main/native/org_apache_tvm_native_c_api.cc index ecc1db666e1c1..e3446c93cc6fd 100644 --- a/jvm/native/src/main/native/org_apache_tvm_native_c_api.cc +++ b/jvm/native/src/main/native/org_apache_tvm_native_c_api.cc @@ -98,7 +98,7 @@ JNIEXPORT void JNICALL Java_org_apache_tvm_LibInfo_tvmFuncPushArgString( value.v_str = env->GetStringUTFChars(garg, 0); TVMFuncArgsThreadLocalEntry *e = TVMFuncArgsThreadLocalStore::Get(); e->tvmFuncArgValues.push_back(value); - e->tvmFuncArgTypes.push_back(kStr); + e->tvmFuncArgTypes.push_back(kTVMStr); // release string args later e->tvmFuncArgPushedStrs.push_back(std::make_pair(garg, value.v_str)); } @@ -126,7 +126,7 @@ JNIEXPORT void JNICALL Java_org_apache_tvm_LibInfo_tvmFuncPushArgBytes( TVMFuncArgsThreadLocalEntry *e = TVMFuncArgsThreadLocalStore::Get(); e->tvmFuncArgValues.push_back(value); - e->tvmFuncArgTypes.push_back(kBytes); + e->tvmFuncArgTypes.push_back(kTVMBytes); e->tvmFuncArgPushedBytes.push_back(std::make_pair(garg, byteArray)); // release (garg, data), byteArray later @@ -242,7 +242,9 @@ extern "C" int funcInvokeCallback(TVMValue *args, for (int i = 0; i < numArgs; ++i) { TVMValue arg = args[i]; int tcode = typeCodes[i]; - if (tcode == kObjectHandle || tcode == kFuncHandle || tcode == kModuleHandle) { + if (tcode == kTVMObjectHandle || + tcode == kTVMPackedFuncHandle || + tcode == kTVMModuleHandle) { TVMCbArgToReturn(&arg, tcode); } jobject jarg = tvmRetValueToJava(env, arg, tcode); @@ -393,7 +395,7 @@ JNIEXPORT jint JNICALL Java_org_apache_tvm_LibInfo_tvmArrayAlloc( JNIEXPORT jint JNICALL Java_org_apache_tvm_LibInfo_tvmArrayGetShape( JNIEnv *env, jobject obj, jlong jhandle, jobject jshape) { - TVMArray *array = reinterpret_cast(jhandle); + DLTensor *array = reinterpret_cast(jhandle); int64_t *shape = array->shape; int ndim = array->ndim; @@ -424,7 +426,7 @@ JNIEXPORT jint JNICALL Java_org_apache_tvm_LibInfo_tvmArrayCopyFromJArray( JNIEnv *env, jobject obj, jbyteArray jarr, jlong jfrom, jlong jto) { jbyte *data = env->GetByteArrayElements(jarr, NULL); - TVMArray *from = reinterpret_cast(jfrom); + DLTensor *from = reinterpret_cast(jfrom); from->data = static_cast(data); int ret = TVMArrayCopyFromTo(static_cast(from), @@ -438,7 +440,7 @@ JNIEXPORT jint JNICALL Java_org_apache_tvm_LibInfo_tvmArrayCopyFromJArray( JNIEXPORT jint JNICALL Java_org_apache_tvm_LibInfo_tvmArrayCopyToJArray( JNIEnv *env, jobject obj, jlong jfrom, jbyteArray jarr) { - TVMArray *from = reinterpret_cast(jfrom); + DLTensor *from = reinterpret_cast(jfrom); int size = static_cast(env->GetArrayLength(jarr)); jbyte *pdata = env->GetByteArrayElements(jarr, NULL); int ret = 0; diff --git a/python/tvm/_ffi/_ctypes/function.py b/python/tvm/_ffi/_ctypes/function.py index 45048c5768a9a..ee3deada7ce57 100644 --- a/python/tvm/_ffi/_ctypes/function.py +++ b/python/tvm/_ffi/_ctypes/function.py @@ -115,8 +115,8 @@ def _make_tvm_args(args, temp_args): type_codes[i] = TypeCode.NULL elif isinstance(arg, NDArrayBase): values[i].v_handle = ctypes.cast(arg.handle, ctypes.c_void_p) - type_codes[i] = (TypeCode.NDARRAY_CONTAINER - if not arg.is_view else TypeCode.ARRAY_HANDLE) + type_codes[i] = (TypeCode.NDARRAY_HANDLE + if not arg.is_view else TypeCode.DLTENSOR_HANDLE) elif isinstance(arg, _nd._TVM_COMPATS): values[i].v_handle = ctypes.c_void_p(arg._tvm_handle) type_codes[i] = arg.__class__._tvm_tcode @@ -154,14 +154,14 @@ def _make_tvm_args(args, temp_args): type_codes[i] = TypeCode.MODULE_HANDLE elif isinstance(arg, FunctionBase): values[i].v_handle = arg.handle - type_codes[i] = TypeCode.FUNC_HANDLE + type_codes[i] = TypeCode.PACKED_FUNC_HANDLE elif isinstance(arg, ctypes.c_void_p): values[i].v_handle = arg type_codes[i] = TypeCode.HANDLE elif callable(arg): arg = convert_to_tvm_func(arg) values[i].v_handle = arg.handle - type_codes[i] = TypeCode.FUNC_HANDLE + type_codes[i] = TypeCode.PACKED_FUNC_HANDLE temp_args.append(arg) else: raise TypeError("Don't know how to handle type %s" % type(arg)) @@ -244,15 +244,15 @@ def _handle_return_func(x): # setup return handle for function type _object.__init_by_constructor__ = __init_handle_by_constructor__ -RETURN_SWITCH[TypeCode.FUNC_HANDLE] = _handle_return_func +RETURN_SWITCH[TypeCode.PACKED_FUNC_HANDLE] = _handle_return_func RETURN_SWITCH[TypeCode.MODULE_HANDLE] = _return_module -RETURN_SWITCH[TypeCode.NDARRAY_CONTAINER] = lambda x: _make_array(x.v_handle, False, True) -C_TO_PY_ARG_SWITCH[TypeCode.FUNC_HANDLE] = _wrap_arg_func( - _handle_return_func, TypeCode.FUNC_HANDLE) +RETURN_SWITCH[TypeCode.NDARRAY_HANDLE] = lambda x: _make_array(x.v_handle, False, True) +C_TO_PY_ARG_SWITCH[TypeCode.PACKED_FUNC_HANDLE] = _wrap_arg_func( + _handle_return_func, TypeCode.PACKED_FUNC_HANDLE) C_TO_PY_ARG_SWITCH[TypeCode.MODULE_HANDLE] = _wrap_arg_func( _return_module, TypeCode.MODULE_HANDLE) -C_TO_PY_ARG_SWITCH[TypeCode.ARRAY_HANDLE] = lambda x: _make_array(x.v_handle, True, False) -C_TO_PY_ARG_SWITCH[TypeCode.NDARRAY_CONTAINER] = lambda x: _make_array(x.v_handle, False, True) +C_TO_PY_ARG_SWITCH[TypeCode.DLTENSOR_HANDLE] = lambda x: _make_array(x.v_handle, True, False) +C_TO_PY_ARG_SWITCH[TypeCode.NDARRAY_HANDLE] = lambda x: _make_array(x.v_handle, False, True) _CLASS_MODULE = None _CLASS_FUNCTION = None diff --git a/python/tvm/_ffi/_cython/base.pxi b/python/tvm/_ffi/_cython/base.pxi index 7ccb6279fed00..420ec6221ad9b 100644 --- a/python/tvm/_ffi/_cython/base.pxi +++ b/python/tvm/_ffi/_cython/base.pxi @@ -26,18 +26,18 @@ cdef enum TVMTypeCode: kInt = 0 kUInt = 1 kFloat = 2 - kHandle = 3 - kNull = 4 - kTVMType = 5 + kTVMOpaqueHandle = 3 + kTVMNullptr = 4 + kTVMDataType = 5 kTVMContext = 6 - kArrayHandle = 7 - kObjectHandle = 8 - kModuleHandle = 9 - kFuncHandle = 10 - kStr = 11 - kBytes = 12 - kNDArrayContainer = 13 - kExtBegin = 15 + kTVMDLTensorHandle = 7 + kTVMObjectHandle = 8 + kTVMModuleHandle = 9 + kTVMPackedFuncHandle = 10 + kTVMStr = 11 + kTVMBytes = 12 + kTVMNDArrayHandle = 13 + kTVMExtBegin = 15 cdef extern from "tvm/runtime/c_runtime_api.h": ctypedef struct DLDataType: diff --git a/python/tvm/_ffi/_cython/function.pxi b/python/tvm/_ffi/_cython/function.pxi index 7789769a39014..bde672f02168d 100644 --- a/python/tvm/_ffi/_cython/function.pxi +++ b/python/tvm/_ffi/_cython/function.pxi @@ -41,13 +41,13 @@ cdef int tvm_callback(TVMValue* args, for i in range(num_args): value = args[i] tcode = type_codes[i] - if (tcode == kObjectHandle or - tcode == kFuncHandle or - tcode == kModuleHandle or - tcode > kExtBegin): + if (tcode == kTVMObjectHandle or + tcode == kTVMPackedFuncHandle or + tcode == kTVMModuleHandle or + tcode > kTVMExtBegin): CALL(TVMCbArgToReturn(&value, tcode)) - if tcode != kArrayHandle: + if tcode != kTVMDLTensorHandle: pyargs.append(make_ret(value, tcode)) else: pyargs.append(c_make_array(value.v_handle, True, False)) @@ -99,11 +99,11 @@ cdef inline int make_arg(object arg, cdef unsigned long long ptr if isinstance(arg, ObjectBase): value[0].v_handle = (arg).chandle - tcode[0] = kObjectHandle + tcode[0] = kTVMObjectHandle elif isinstance(arg, NDArrayBase): value[0].v_handle = (arg).chandle - tcode[0] = (kNDArrayContainer if - not (arg).c_is_view else kArrayHandle) + tcode[0] = (kTVMNDArrayHandle if + not (arg).c_is_view else kTVMDLTensorHandle) elif isinstance(arg, _TVM_COMPATS): ptr = arg._tvm_handle value[0].v_handle = (ptr) @@ -117,18 +117,18 @@ cdef inline int make_arg(object arg, elif isinstance(arg, str): tstr = c_str(arg) value[0].v_str = tstr - tcode[0] = kStr + tcode[0] = kTVMStr temp_args.append(tstr) elif arg is None: value[0].v_handle = NULL - tcode[0] = kNull + tcode[0] = kTVMNullptr elif isinstance(arg, Number): value[0].v_float64 = arg tcode[0] = kFloat elif isinstance(arg, TVMType): tstr = c_str(str(arg)) value[0].v_str = tstr - tcode[0] = kStr + tcode[0] = kTVMStr temp_args.append(tstr) elif isinstance(arg, TVMContext): value[0].v_ctx = (( @@ -142,31 +142,31 @@ cdef inline int make_arg(object arg, arr.size = len(arg) value[0].v_handle = ( ctypes.addressof(arr)) - tcode[0] = kBytes + tcode[0] = kTVMBytes temp_args.append(arr) elif isinstance(arg, string_types): tstr = c_str(arg) value[0].v_str = tstr - tcode[0] = kStr + tcode[0] = kTVMStr temp_args.append(tstr) elif isinstance(arg, (list, tuple, dict, ObjectGeneric)): arg = convert_to_object(arg) value[0].v_handle = (arg).chandle - tcode[0] = kObjectHandle + tcode[0] = kTVMObjectHandle temp_args.append(arg) elif isinstance(arg, _CLASS_MODULE): value[0].v_handle = c_handle(arg.handle) - tcode[0] = kModuleHandle + tcode[0] = kTVMModuleHandle elif isinstance(arg, FunctionBase): value[0].v_handle = (arg).chandle - tcode[0] = kFuncHandle + tcode[0] = kTVMPackedFuncHandle elif isinstance(arg, ctypes.c_void_p): value[0].v_handle = c_handle(arg) - tcode[0] = kHandle + tcode[0] = kTVMOpaqueHandle elif callable(arg): arg = convert_to_tvm_func(arg) value[0].v_handle = (arg).chandle - tcode[0] = kFuncHandle + tcode[0] = kTVMPackedFuncHandle temp_args.append(arg) else: raise TypeError("Don't know how to handle type %s" % type(arg)) @@ -184,27 +184,27 @@ cdef inline bytearray make_ret_bytes(void* chandle): cdef inline object make_ret(TVMValue value, int tcode): """convert result to return value.""" - if tcode == kObjectHandle: + if tcode == kTVMObjectHandle: return make_ret_object(value.v_handle) - elif tcode == kNull: + elif tcode == kTVMNullptr: return None elif tcode == kInt: return value.v_int64 elif tcode == kFloat: return value.v_float64 - elif tcode == kNDArrayContainer: + elif tcode == kTVMNDArrayHandle: return c_make_array(value.v_handle, False, True) - elif tcode == kStr: + elif tcode == kTVMStr: return py_str(value.v_str) - elif tcode == kBytes: + elif tcode == kTVMBytes: return make_ret_bytes(value.v_handle) - elif tcode == kHandle: + elif tcode == kTVMOpaqueHandle: return ctypes_handle(value.v_handle) elif tcode == kTVMContext: return TVMContext(value.v_ctx.device_type, value.v_ctx.device_id) - elif tcode == kModuleHandle: + elif tcode == kTVMModuleHandle: return _CLASS_MODULE(ctypes_handle(value.v_handle)) - elif tcode == kFuncHandle: + elif tcode == kTVMPackedFuncHandle: fobj = _CLASS_FUNCTION(None, False) (fobj).chandle = value.v_handle return fobj diff --git a/python/tvm/_ffi/_cython/object.pxi b/python/tvm/_ffi/_cython/object.pxi index 1392f99448351..494c3ff47c8e1 100644 --- a/python/tvm/_ffi/_cython/object.pxi +++ b/python/tvm/_ffi/_cython/object.pxi @@ -97,5 +97,5 @@ cdef class ObjectBase: cdef void* chandle ConstructorCall( (fconstructor).chandle, - kObjectHandle, args, &chandle) + kTVMObjectHandle, args, &chandle) self.chandle = chandle diff --git a/python/tvm/_ffi/runtime_ctypes.py b/python/tvm/_ffi/runtime_ctypes.py index a7947dbc38a2f..93c260a4f505b 100644 --- a/python/tvm/_ffi/runtime_ctypes.py +++ b/python/tvm/_ffi/runtime_ctypes.py @@ -35,13 +35,13 @@ class TypeCode(object): NULL = 4 TVM_TYPE = 5 TVM_CONTEXT = 6 - ARRAY_HANDLE = 7 + DLTENSOR_HANDLE = 7 OBJECT_HANDLE = 8 MODULE_HANDLE = 9 - FUNC_HANDLE = 10 + PACKED_FUNC_HANDLE = 10 STR = 11 BYTES = 12 - NDARRAY_CONTAINER = 13 + NDARRAY_HANDLE = 13 EXT_BEGIN = 15 diff --git a/rust/runtime/src/graph.rs b/rust/runtime/src/graph.rs index 42b9458223a68..5fa111ca45ea8 100644 --- a/rust/runtime/src/graph.rs +++ b/rust/runtime/src/graph.rs @@ -352,7 +352,7 @@ impl<'m, 't> GraphExecutor<'m, 't> { } } -// Converts a string to TVM DLDataTypeCode. @see `String2TVMType` in packed_func.h +// Converts a string to TVM DLDataTypeCode. @see `String2DLDataType` in packed_func.h named!( tvm_str_to_type, do_parse!( diff --git a/src/api/api_base.cc b/src/api/api_base.cc index aa5fb784e9686..131ac363bb8b2 100644 --- a/src/api/api_base.cc +++ b/src/api/api_base.cc @@ -32,7 +32,7 @@ namespace tvm { TVM_REGISTER_GLOBAL("_format_str") .set_body([](TVMArgs args, TVMRetValue *ret) { - CHECK(args[0].type_code() == kObjectHandle); + CHECK(args[0].type_code() == kTVMObjectHandle); std::ostringstream os; os << args[0].operator ObjectRef(); *ret = os.str(); @@ -40,7 +40,7 @@ TVM_REGISTER_GLOBAL("_format_str") TVM_REGISTER_GLOBAL("_raw_ptr") .set_body([](TVMArgs args, TVMRetValue *ret) { - CHECK(args[0].type_code() == kObjectHandle); + CHECK(args[0].type_code() == kTVMObjectHandle); *ret = reinterpret_cast(args[0].value().v_handle); }); diff --git a/src/api/api_lang.cc b/src/api/api_lang.cc index fa7b59d36b881..2c7eb3cc0270d 100644 --- a/src/api/api_lang.cc +++ b/src/api/api_lang.cc @@ -64,7 +64,7 @@ TVM_REGISTER_GLOBAL("_Array") .set_body([](TVMArgs args, TVMRetValue* ret) { std::vector data; for (int i = 0; i < args.size(); ++i) { - if (args[i].type_code() != kNull) { + if (args[i].type_code() != kTVMNullptr) { data.push_back(args[i].operator ObjectRef()); } else { data.push_back(ObjectRef(nullptr)); @@ -78,7 +78,7 @@ TVM_REGISTER_GLOBAL("_Array") TVM_REGISTER_GLOBAL("_ArrayGetItem") .set_body([](TVMArgs args, TVMRetValue* ret) { int64_t i = args[1]; - CHECK_EQ(args[0].type_code(), kObjectHandle); + CHECK_EQ(args[0].type_code(), kTVMObjectHandle); Object* ptr = static_cast(args[0].value().v_handle); CHECK(ptr->IsInstance()); auto* n = static_cast(ptr); @@ -89,7 +89,7 @@ TVM_REGISTER_GLOBAL("_ArrayGetItem") TVM_REGISTER_GLOBAL("_ArraySize") .set_body([](TVMArgs args, TVMRetValue* ret) { - CHECK_EQ(args[0].type_code(), kObjectHandle); + CHECK_EQ(args[0].type_code(), kTVMObjectHandle); Object* ptr = static_cast(args[0].value().v_handle); CHECK(ptr->IsInstance()); *ret = static_cast( @@ -99,11 +99,11 @@ TVM_REGISTER_GLOBAL("_ArraySize") TVM_REGISTER_GLOBAL("_Map") .set_body([](TVMArgs args, TVMRetValue* ret) { CHECK_EQ(args.size() % 2, 0); - if (args.size() != 0 && args[0].type_code() == kStr) { + if (args.size() != 0 && args[0].type_code() == kTVMStr) { // StrMap StrMapNode::ContainerType data; for (int i = 0; i < args.num_args; i += 2) { - CHECK(args[i].type_code() == kStr) + CHECK(args[i].type_code() == kTVMStr) << "key of str map need to be str"; CHECK(args[i + 1].IsObjectRef()) << "value of the map to be NodeRef"; @@ -132,7 +132,7 @@ TVM_REGISTER_GLOBAL("_Map") TVM_REGISTER_GLOBAL("_MapSize") .set_body([](TVMArgs args, TVMRetValue* ret) { - CHECK_EQ(args[0].type_code(), kObjectHandle); + CHECK_EQ(args[0].type_code(), kTVMObjectHandle); Object* ptr = static_cast(args[0].value().v_handle); if (ptr->IsInstance()) { auto* n = static_cast(ptr); @@ -146,11 +146,11 @@ TVM_REGISTER_GLOBAL("_MapSize") TVM_REGISTER_GLOBAL("_MapGetItem") .set_body([](TVMArgs args, TVMRetValue* ret) { - CHECK_EQ(args[0].type_code(), kObjectHandle); + CHECK_EQ(args[0].type_code(), kTVMObjectHandle); Object* ptr = static_cast(args[0].value().v_handle); if (ptr->IsInstance()) { - CHECK(args[1].type_code() == kObjectHandle); + CHECK(args[1].type_code() == kTVMObjectHandle); auto* n = static_cast(ptr); auto it = n->data.find(args[1].operator ObjectRef()); CHECK(it != n->data.end()) @@ -168,12 +168,12 @@ TVM_REGISTER_GLOBAL("_MapGetItem") TVM_REGISTER_GLOBAL("_MapCount") .set_body([](TVMArgs args, TVMRetValue* ret) { - CHECK_EQ(args[0].type_code(), kObjectHandle); + CHECK_EQ(args[0].type_code(), kTVMObjectHandle); Object* ptr = static_cast(args[0].value().v_handle); if (ptr->IsInstance()) { auto* n = static_cast(ptr); - CHECK_EQ(args[0].type_code(), kObjectHandle); + CHECK_EQ(args[0].type_code(), kTVMObjectHandle); *ret = static_cast( n->data.count(args[1].operator ObjectRef())); } else { @@ -186,7 +186,7 @@ TVM_REGISTER_GLOBAL("_MapCount") TVM_REGISTER_GLOBAL("_MapItems") .set_body([](TVMArgs args, TVMRetValue* ret) { - CHECK_EQ(args[0].type_code(), kObjectHandle); + CHECK_EQ(args[0].type_code(), kTVMObjectHandle); Object* ptr = static_cast(args[0].value().v_handle); if (ptr->IsInstance()) { diff --git a/src/codegen/codegen_c.cc b/src/codegen/codegen_c.cc index d9b7f7f08d123..5ecf97056ea93 100644 --- a/src/codegen/codegen_c.cc +++ b/src/codegen/codegen_c.cc @@ -216,7 +216,7 @@ std::string CodeGenC::GetStructRef( DataType t, const PrimExpr& buffer, const PrimExpr& index, int kind) { if (kind < intrinsic::kArrKindBound_) { std::ostringstream os; - os << "(((TVMArray*)"; + os << "(((DLTensor*)"; this->PrintExpr(buffer, os); os << ")"; if (kind == intrinsic::kArrAddr) { diff --git a/src/codegen/codegen_c_host.cc b/src/codegen/codegen_c_host.cc index 85751c2cfcfe8..083b25beddf32 100644 --- a/src/codegen/codegen_c_host.cc +++ b/src/codegen/codegen_c_host.cc @@ -200,7 +200,7 @@ void CodeGenCHost::VisitExpr_(const CallNode *op, std::ostream& os) { // NOLINT( const std::string& type = op->args[0].as()->value; const IntImmNode* num = op->args[1].as(); CHECK(num != nullptr); - static_assert(alignof(TVMValue) % alignof(TVMArray) == 0, "invariant"); + static_assert(alignof(TVMValue) % alignof(DLTensor) == 0, "invariant"); size_t unit = sizeof(TVMValue); size_t size = 0; if (type == "shape") { @@ -210,7 +210,7 @@ void CodeGenCHost::VisitExpr_(const CallNode *op, std::ostream& os) { // NOLINT( } else if (type == "arg_tcode") { size = (num->value * sizeof(int) + unit - 1) / unit; } else if (type == "array") { - size = (num->value * sizeof(TVMArray) + unit - 1) / unit; + size = (num->value * sizeof(DLTensor) + unit - 1) / unit; } else { LOG(FATAL) << "Unknown stack alloca type " << type; } diff --git a/src/codegen/datatype/registry.cc b/src/codegen/datatype/registry.cc index 62d36c431efc9..62a75500646ad 100644 --- a/src/codegen/datatype/registry.cc +++ b/src/codegen/datatype/registry.cc @@ -25,19 +25,23 @@ namespace tvm { namespace datatype { -TVM_REGISTER_GLOBAL("_datatype_register").set_body([](TVMArgs args, TVMRetValue* ret) { +TVM_REGISTER_GLOBAL("_datatype_register") +.set_body([](TVMArgs args, TVMRetValue* ret) { datatype::Registry::Global()->Register(args[0], static_cast(args[1].operator int())); }); -TVM_REGISTER_GLOBAL("_datatype_get_type_code").set_body([](TVMArgs args, TVMRetValue* ret) { +TVM_REGISTER_GLOBAL("_datatype_get_type_code") +.set_body([](TVMArgs args, TVMRetValue* ret) { *ret = datatype::Registry::Global()->GetTypeCode(args[0]); }); -TVM_REGISTER_GLOBAL("_datatype_get_type_name").set_body([](TVMArgs args, TVMRetValue* ret) { +TVM_REGISTER_GLOBAL("_datatype_get_type_name") +.set_body([](TVMArgs args, TVMRetValue* ret) { *ret = Registry::Global()->GetTypeName(args[0].operator int()); }); -TVM_REGISTER_GLOBAL("_datatype_get_type_registered").set_body([](TVMArgs args, TVMRetValue* ret) { +TVM_REGISTER_GLOBAL("_datatype_get_type_registered") +.set_body([](TVMArgs args, TVMRetValue* ret) { *ret = Registry::Global()->GetTypeRegistered(args[0].operator int()); }); @@ -47,7 +51,8 @@ Registry* Registry::Global() { } void Registry::Register(const std::string& type_name, uint8_t type_code) { - CHECK(type_code >= kCustomBegin) << "Please choose a type code >= kCustomBegin for custom types"; + CHECK(type_code >= kTVMCustomBegin) + << "Please choose a type code >= kTVMCustomBegin for custom types"; code_to_name_[type_code] = type_name; name_to_code_[type_name] = type_code; } diff --git a/src/codegen/datatype/registry.h b/src/codegen/datatype/registry.h index d2e615765a18a..697bd47f27a2a 100644 --- a/src/codegen/datatype/registry.h +++ b/src/codegen/datatype/registry.h @@ -60,7 +60,7 @@ class Registry { * same code. Generally, this should be straightforward, as the user will be manually registering * all of their custom types. * \param type_name The name of the type, e.g. "bfloat" - * \param type_code The type code, which should be greater than TVMTypeCode::kExtEnd + * \param type_code The type code, which should be greater than TVMTypeCode::kTVMExtEnd */ void Register(const std::string& type_name, uint8_t type_code); diff --git a/src/codegen/llvm/codegen_cpu.cc b/src/codegen/llvm/codegen_cpu.cc index 39d8c7fb28e4f..6c0b6846bedf4 100644 --- a/src/codegen/llvm/codegen_cpu.cc +++ b/src/codegen/llvm/codegen_cpu.cc @@ -731,7 +731,7 @@ llvm::Value *CodeGenCPU::CreateCallTracePacked(const CallNode *op) { llvm::Value *ret_tcode_value = builder_->CreateAlignedLoad(ret_tcode, 8); // Check the ret_type_code and create cmp instruction. llvm::Value *cmp = builder_->CreateICmpNE( - ret_tcode_value, llvm::ConstantInt::get(t_int_, kNull)); + ret_tcode_value, llvm::ConstantInt::get(t_int_, kTVMNullptr)); builder_->CreateCondBr(cmp, update_block, continue_block); builder_->SetInsertPoint(update_block); builder_->CreateBr(continue_block); diff --git a/src/codegen/stackvm/codegen_stackvm.cc b/src/codegen/stackvm/codegen_stackvm.cc index 01096ae1dd469..f4b8fbe7ff1db 100644 --- a/src/codegen/stackvm/codegen_stackvm.cc +++ b/src/codegen/stackvm/codegen_stackvm.cc @@ -199,7 +199,7 @@ void CodeGenStackVM::VisitExpr_(const CallNode* op) { const std::string& type = op->args[0].as()->value; const IntImmNode* num = op->args[1].as(); CHECK(num != nullptr); - static_assert(alignof(TVMValue) % alignof(TVMArray) == 0, "invariant"); + static_assert(alignof(TVMValue) % alignof(DLTensor) == 0, "invariant"); // static_assert(alignof(TVMValue) % alignof(tvm_index_t) == 0, "invariant"); size_t unit = sizeof(TVMValue); size_t size = 0; @@ -210,7 +210,7 @@ void CodeGenStackVM::VisitExpr_(const CallNode* op) { } else if (type == "arg_tcode") { size = (num->value * sizeof(int) + unit - 1) / unit; } else if (type == "array") { - size = (num->value * sizeof(TVMArray) + unit - 1) / unit; + size = (num->value * sizeof(DLTensor) + unit - 1) / unit; } else { LOG(FATAL) << "Unknown stack alloca type " << type; } diff --git a/src/ir/attrs.cc b/src/ir/attrs.cc index a4879954b9826..f2f923359efae 100644 --- a/src/ir/attrs.cc +++ b/src/ir/attrs.cc @@ -43,7 +43,7 @@ void DictAttrsNode::InitByPackedArgs( runtime::TVMArgValue val = args[i + 1]; if (val.IsObjectRef()) { dict.Set(key, val.operator ObjectRef()); - } else if (val.type_code() == kStr) { + } else if (val.type_code() == kTVMStr) { dict.Set(key, PrimExpr(val.operator std::string())); } else { dict.Set(key, val.operator PrimExpr()); diff --git a/src/ir/op.cc b/src/ir/op.cc index f1be38334e91e..2bdb04d729ac0 100644 --- a/src/ir/op.cc +++ b/src/ir/op.cc @@ -129,10 +129,10 @@ void OpRegistry::UpdateAttr(const std::string& key, CHECK(p.second != plevel) << "Attribute " << key << " of operator " << this->name << " is already registered with same plevel=" << plevel; - CHECK(value.type_code() != kNull) + CHECK(value.type_code() != kTVMNullptr) << "Registered packed_func is Null for " << key << " of operator " << this->name; - if (p.second < plevel && value.type_code() != kNull) { + if (p.second < plevel && value.type_code() != kTVMNullptr) { op_map->data_[index] = std::make_pair(value, plevel); } } @@ -195,7 +195,7 @@ TVM_REGISTER_GLOBAL("relay.op._Register") LOG(FATAL) << "attrs type key no longer supported"; } else { // normal attr table override. - if (args[2].type_code() == kFuncHandle) { + if (args[2].type_code() == kTVMPackedFuncHandle) { // do an eager copy of the PackedFunc PackedFunc f = args[2]; // If we get a function from frontend, avoid deleting it. diff --git a/src/node/reflection.cc b/src/node/reflection.cc index df162cf17071b..7c0fb8faf5eb6 100644 --- a/src/node/reflection.cc +++ b/src/node/reflection.cc @@ -97,7 +97,7 @@ runtime::TVMRetValue ReflectionVTable::GetAttr( success = true; } else if (!self->IsInstance()) { VisitAttrs(self, &getter); - success = getter.found_ref_object || ret.type_code() != kNull; + success = getter.found_ref_object || ret.type_code() != kTVMNullptr; } else { // specially handle dict attr DictAttrsNode* dnode = static_cast(self); @@ -258,13 +258,13 @@ void InitNodeByPackedArgs(Object* n, const TVMArgs& args) { // Expose to FFI APIs. void NodeGetAttr(TVMArgs args, TVMRetValue* ret) { - CHECK_EQ(args[0].type_code(), kObjectHandle); + CHECK_EQ(args[0].type_code(), kTVMObjectHandle); Object* self = static_cast(args[0].value().v_handle); *ret = ReflectionVTable::Global()->GetAttr(self, args[1]); } void NodeListAttrNames(TVMArgs args, TVMRetValue* ret) { - CHECK_EQ(args[0].type_code(), kObjectHandle); + CHECK_EQ(args[0].type_code(), kTVMObjectHandle); Object* self = static_cast(args[0].value().v_handle); auto names = std::make_shared >( diff --git a/src/node/serialization.cc b/src/node/serialization.cc index 647700bfa14b8..91b5e1a6cf217 100644 --- a/src/node/serialization.cc +++ b/src/node/serialization.cc @@ -39,11 +39,11 @@ namespace tvm { inline std::string Type2String(const DataType& t) { - return runtime::TVMType2String(t); + return runtime::DLDataType2String(t); } inline DataType String2Type(std::string s) { - return DataType(runtime::String2TVMType(s)); + return DataType(runtime::String2DLDataType(s)); } // indexer to index all the nodes diff --git a/src/pass/lower_tvm_builtin.cc b/src/pass/lower_tvm_builtin.cc index 01a97b7878bee..59a6473728d61 100644 --- a/src/pass/lower_tvm_builtin.cc +++ b/src/pass/lower_tvm_builtin.cc @@ -260,9 +260,9 @@ class BuiltinLower : public StmtExprMutator { intrinsic::kTVMValueContent, arg)); int arg_tcode = api_type.code(); if (api_type.is_handle() && arg.as()) { - arg_tcode = kStr; + arg_tcode = kTVMStr; } - if (IsArrayHandle(arg)) arg_tcode = kArrayHandle; + if (IsArrayHandle(arg)) arg_tcode = kTVMDLTensorHandle; prep_seq_.emplace_back( StoreNode::make(stack_tcode_, ConstInt32(arg_tcode), diff --git a/src/pass/make_api.cc b/src/pass/make_api.cc index 5df36d0b2423b..fa2965168c854 100644 --- a/src/pass/make_api.cc +++ b/src/pass/make_api.cc @@ -124,10 +124,10 @@ LoweredFunc MakeAPI(Stmt body, std::ostringstream msg; msg << name << ": Expect arg[" << i << "] to be pointer"; seq_check.emplace_back( - AssertStmtNode::make(tcode == kHandle || - tcode == kNDArrayContainer || - tcode == kArrayHandle || - tcode == kNull, msg.str(), nop)); + AssertStmtNode::make(tcode == kTVMOpaqueHandle || + tcode == kTVMNDArrayHandle || + tcode == kTVMDLTensorHandle || + tcode == kTVMNullptr, msg.str(), nop)); } else if (t.is_int() || t.is_uint()) { std::ostringstream msg; msg << name << ": Expect arg[" << i << "] to be int"; diff --git a/src/relay/ir/doc.cc b/src/relay/ir/doc.cc index cc2f40f7cb9ad..26aec39e5282b 100644 --- a/src/relay/ir/doc.cc +++ b/src/relay/ir/doc.cc @@ -108,7 +108,7 @@ Doc PrintBool(bool value) { } Doc PrintDType(DataType dtype) { - return Doc(runtime::TVMType2String(dtype)); + return Doc(runtime::DLDataType2String(dtype)); } Doc PrintString(const std::string& value) { diff --git a/src/relay/ir/pretty_printer.cc b/src/relay/ir/pretty_printer.cc index 31f1e71ad7e17..a22a4a24bc2fe 100644 --- a/src/relay/ir/pretty_printer.cc +++ b/src/relay/ir/pretty_printer.cc @@ -932,7 +932,7 @@ class PrettyPrinter::AttrPrinter : public AttrVisitor { LOG(FATAL) << "do not allow void as argument"; } void Visit(const char* key, DataType* value) final { - PrintKV(key, PrintString(runtime::TVMType2String(*value))); + PrintKV(key, PrintString(runtime::DLDataType2String(*value))); } void Visit(const char* key, runtime::NDArray* value) final { LOG(FATAL) << "do not allow NDarray as argument"; diff --git a/src/relay/op/tensor/transform.cc b/src/relay/op/tensor/transform.cc index b5383cd3339b3..0d4e0a4bfb4f5 100644 --- a/src/relay/op/tensor/transform.cc +++ b/src/relay/op/tensor/transform.cc @@ -1182,7 +1182,7 @@ double ToScalar(const runtime::NDArray& array) { return reinterpret_cast(array->data)[0]; } } - LOG(FATAL) << "Unknown data type: " << tvm::runtime::TVMType2String(array->dtype); + LOG(FATAL) << "Unknown data type: " << tvm::runtime::DLDataType2String(array->dtype); // make compiler happy return -std::numeric_limits::infinity(); } diff --git a/src/runtime/c_runtime_api.cc b/src/runtime/c_runtime_api.cc index f1d543537e190..ba762c012fac3 100644 --- a/src/runtime/c_runtime_api.cc +++ b/src/runtime/c_runtime_api.cc @@ -151,7 +151,7 @@ DeviceAPI* DeviceAPI::Get(TVMContext ctx, bool allow_missing) { void* DeviceAPI::AllocWorkspace(TVMContext ctx, size_t size, - TVMType type_hint) { + DLDataType type_hint) { return AllocDataSpace(ctx, size, kTempAllocaAlignment, type_hint); } @@ -431,7 +431,7 @@ void* TVMBackendAllocWorkspace(int device_type, ctx.device_type = static_cast(device_type); ctx.device_id = device_id; - TVMType type_hint; + DLDataType type_hint; type_hint.code = static_cast(dtype_code_hint); type_hint.bits = static_cast(dtype_bits_hint); type_hint.lanes = 1; @@ -479,22 +479,22 @@ int TVMFuncCall(TVMFunctionHandle func, (*static_cast(func)).CallPacked( TVMArgs(args, arg_type_codes, num_args), &rv); // handle return string. - if (rv.type_code() == kStr || - rv.type_code() == kTVMType || - rv.type_code() == kBytes) { + if (rv.type_code() == kTVMStr || + rv.type_code() == kTVMDataType || + rv.type_code() == kTVMBytes) { TVMRuntimeEntry* e = TVMAPIRuntimeStore::Get(); - if (rv.type_code() != kTVMType) { + if (rv.type_code() != kTVMDataType) { e->ret_str = *rv.ptr(); } else { e->ret_str = rv.operator std::string(); } - if (rv.type_code() == kBytes) { + if (rv.type_code() == kTVMBytes) { e->ret_bytes.data = e->ret_str.c_str(); e->ret_bytes.size = e->ret_str.length(); - *ret_type_code = kBytes; + *ret_type_code = kTVMBytes; ret_val->v_handle = &(e->ret_bytes); } else { - *ret_type_code = kStr; + *ret_type_code = kTVMStr; ret_val->v_str = e->ret_str.c_str(); } } else { diff --git a/src/runtime/contrib/cudnn/conv_forward.cc b/src/runtime/contrib/cudnn/conv_forward.cc index 37bafa225b99a..b9609b9d1047c 100644 --- a/src/runtime/contrib/cudnn/conv_forward.cc +++ b/src/runtime/contrib/cudnn/conv_forward.cc @@ -52,7 +52,7 @@ void ConvolutionForward( // Set Ctx entry_ptr->conv_entry.ctx = x->ctx; // Set Data Type - entry_ptr->conv_entry.data_type = CuDNNDataType::DLTypeToCuDNNType(String2TVMType(conv_dtype)); + entry_ptr->conv_entry.data_type = CuDNNDataType::DLTypeToCuDNNType(String2DLDataType(conv_dtype)); cudnnDataType_t data_type = CuDNNDataType::DLTypeToCuDNNType(x->dtype); // Dims includes N and C int full_dims = dims + 2; @@ -194,8 +194,8 @@ void OutputShape( CuDNNThreadEntry* entry_ptr = CuDNNThreadEntry::ThreadLocal(); // Set Data Type - entry_ptr->conv_entry.data_type = CuDNNDataType::DLTypeToCuDNNType(String2TVMType(conv_dtype)); - cudnnDataType_t data_type = CuDNNDataType::DLTypeToCuDNNType(String2TVMType(data_dtype)); + entry_ptr->conv_entry.data_type = CuDNNDataType::DLTypeToCuDNNType(String2DLDataType(conv_dtype)); + cudnnDataType_t data_type = CuDNNDataType::DLTypeToCuDNNType(String2DLDataType(data_dtype)); // Set Format entry_ptr->conv_entry.tensor_format = static_cast(format); // Dims includes N and C @@ -276,8 +276,8 @@ void FindAlgo( CuDNNThreadEntry* entry_ptr = CuDNNThreadEntry::ThreadLocal(); // Set Data Type - entry_ptr->conv_entry.data_type = CuDNNDataType::DLTypeToCuDNNType(String2TVMType(conv_dtype)); - cudnnDataType_t data_type = CuDNNDataType::DLTypeToCuDNNType(String2TVMType(data_dtype)); + entry_ptr->conv_entry.data_type = CuDNNDataType::DLTypeToCuDNNType(String2DLDataType(conv_dtype)); + cudnnDataType_t data_type = CuDNNDataType::DLTypeToCuDNNType(String2DLDataType(data_dtype)); // Set Format entry_ptr->conv_entry.tensor_format = static_cast(format); // Dims includes N and C diff --git a/src/runtime/contrib/example_ext_runtime/example_ext_runtime.cc b/src/runtime/contrib/example_ext_runtime/example_ext_runtime.cc index ef6fc870f7f07..28c6841207d85 100644 --- a/src/runtime/contrib/example_ext_runtime/example_ext_runtime.cc +++ b/src/runtime/contrib/example_ext_runtime/example_ext_runtime.cc @@ -142,10 +142,11 @@ class ExampleJsonModule : public ModuleNode { this->curr_subgraph_ = name; return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { for (auto i = 0; i < args.size(); ++i) { - CHECK(args[i].type_code() == kNDArrayContainer || args[i].type_code() == kArrayHandle) + CHECK(args[i].type_code() == kTVMNDArrayHandle || + args[i].type_code() == kTVMDLTensorHandle) << "Expect NDArray or DLTensor as inputs" << "\n"; - if (args[i].type_code() == kArrayHandle) { + if (args[i].type_code() == kTVMDLTensorHandle) { DLTensor* arg = args[i]; this->data_entry_[i].CopyFrom(arg); } else { @@ -158,7 +159,7 @@ class ExampleJsonModule : public ModuleNode { } CHECK_GT(graph_.count(this->curr_subgraph_), 0U); auto out_idx = graph_[this->curr_subgraph_].back().output; - if (args[args.size() - 1].type_code() == kArrayHandle) { + if (args[args.size() - 1].type_code() == kTVMDLTensorHandle) { DLTensor* arg = args[args.size() - 1]; this->data_entry_[out_idx].CopyTo(arg); } else { @@ -341,4 +342,3 @@ TVM_REGISTER_GLOBAL("module.loadbinary_examplejson") } // namespace runtime } // namespace tvm - diff --git a/src/runtime/contrib/nnpack/convolution.cc b/src/runtime/contrib/nnpack/convolution.cc index cf8488185d525..8934693973b4a 100644 --- a/src/runtime/contrib/nnpack/convolution.cc +++ b/src/runtime/contrib/nnpack/convolution.cc @@ -6,9 +6,9 @@ * 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 @@ -40,7 +40,7 @@ TVM_REGISTER_GLOBAL("tvm.contrib.nnpack.convolution_inference") DLTensor *input = args[0]; DLTensor *kernel = args[1]; DLTensor *bias = nullptr; - if (args[2].type_code() == kArrayHandle) { + if (args[2].type_code() == kTVMDLTensorHandle) { bias = args[2]; } DLTensor *output = args[3]; @@ -103,7 +103,7 @@ TVM_REGISTER_GLOBAL("tvm.contrib.nnpack.convolution_inference") const size_t workspace_elements = (workspace_size + sizeof(float) - 1) / sizeof(float); TVMContext ctx = input->ctx; - TVMType type_hint = input->dtype; + DLDataType type_hint = input->dtype; DeviceAPI* cpu_api = DeviceAPI::Get(ctx); void* workspace_buffer = @@ -140,7 +140,7 @@ TVM_REGISTER_GLOBAL("tvm.contrib.nnpack.convolution_inference_without_weight_tra DLTensor *input = args[0]; DLTensor *transformed_kernel = args[1]; DLTensor *bias = nullptr; - if (args[2].type_code() == kArrayHandle) { + if (args[2].type_code() == kTVMDLTensorHandle) { bias = args[2]; } DLTensor *output = args[3]; @@ -199,7 +199,7 @@ TVM_REGISTER_GLOBAL("tvm.contrib.nnpack.convolution_inference_without_weight_tra const size_t workspace_elements = (workspace_size + sizeof(float) - 1) / sizeof(float); TVMContext ctx = input->ctx; - TVMType type_hint = input->dtype; + DLDataType type_hint = input->dtype; DeviceAPI* cpu_api = DeviceAPI::Get(ctx); void* workspace_buffer = diff --git a/src/runtime/contrib/sort/sort.cc b/src/runtime/contrib/sort/sort.cc index 2552d13a63818..68f70c15b4d6d 100644 --- a/src/runtime/contrib/sort/sort.cc +++ b/src/runtime/contrib/sort/sort.cc @@ -6,9 +6,9 @@ * 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 @@ -182,8 +182,8 @@ TVM_REGISTER_GLOBAL("tvm.contrib.sort.argsort") CHECK_LT(axis, input->ndim) << "Axis out of boundary for " "input ndim " << input->ndim; - auto data_dtype = TVMType2String(input->dtype); - auto out_dtype = TVMType2String(output->dtype); + auto data_dtype = DLDataType2String(input->dtype); + auto out_dtype = DLDataType2String(output->dtype); if (data_dtype == "float32") { if (out_dtype == "int32") { @@ -333,8 +333,8 @@ TVM_REGISTER_GLOBAL("tvm.contrib.sort.topk") } CHECK(axis >= 0 && axis < input->ndim) << "Axis out of boundary for input ndim " << input->ndim; - auto data_dtype = TVMType2String(input->dtype); - auto out_dtype = (indices_out == nullptr) ? "int64" : TVMType2String(indices_out->dtype); + auto data_dtype = DLDataType2String(input->dtype); + auto out_dtype = (indices_out == nullptr) ? "int64" : DLDataType2String(indices_out->dtype); if (data_dtype == "float32") { if (out_dtype == "int32") { diff --git a/src/runtime/cpu_device_api.cc b/src/runtime/cpu_device_api.cc index f4e9a97093797..ea7d7d05de246 100644 --- a/src/runtime/cpu_device_api.cc +++ b/src/runtime/cpu_device_api.cc @@ -45,7 +45,7 @@ class CPUDeviceAPI final : public DeviceAPI { void* AllocDataSpace(TVMContext ctx, size_t nbytes, size_t alignment, - TVMType type_hint) final { + DLDataType type_hint) final { void* ptr; #if _MSC_VER ptr = _aligned_malloc(nbytes, alignment); @@ -76,7 +76,7 @@ class CPUDeviceAPI final : public DeviceAPI { size_t size, TVMContext ctx_from, TVMContext ctx_to, - TVMType type_hint, + DLDataType type_hint, TVMStreamHandle stream) final { memcpy(static_cast(to) + to_offset, static_cast(from) + from_offset, @@ -86,7 +86,7 @@ class CPUDeviceAPI final : public DeviceAPI { void StreamSync(TVMContext ctx, TVMStreamHandle stream) final { } - void* AllocWorkspace(TVMContext ctx, size_t size, TVMType type_hint) final; + void* AllocWorkspace(TVMContext ctx, size_t size, DLDataType type_hint) final; void FreeWorkspace(TVMContext ctx, void* data) final; static const std::shared_ptr& Global() { @@ -103,7 +103,7 @@ struct CPUWorkspacePool : public WorkspacePool { void* CPUDeviceAPI::AllocWorkspace(TVMContext ctx, size_t size, - TVMType type_hint) { + DLDataType type_hint) { return dmlc::ThreadLocalStore::Get() ->AllocWorkspace(ctx, size); } diff --git a/src/runtime/cuda/cuda_device_api.cc b/src/runtime/cuda/cuda_device_api.cc index 88578c4ad7485..86b52518354c2 100644 --- a/src/runtime/cuda/cuda_device_api.cc +++ b/src/runtime/cuda/cuda_device_api.cc @@ -6,9 +6,9 @@ * 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 @@ -111,7 +111,7 @@ class CUDADeviceAPI final : public DeviceAPI { void* AllocDataSpace(TVMContext ctx, size_t nbytes, size_t alignment, - TVMType type_hint) final { + DLDataType type_hint) final { CUDA_CALL(cudaSetDevice(ctx.device_id)); CHECK_EQ(256 % alignment, 0U) << "CUDA space is aligned at 256 bytes"; @@ -132,7 +132,7 @@ class CUDADeviceAPI final : public DeviceAPI { size_t size, TVMContext ctx_from, TVMContext ctx_to, - TVMType type_hint, + DLDataType type_hint, TVMStreamHandle stream) final { cudaStream_t cu_stream = static_cast(stream); from = static_cast(from) + from_offset; @@ -191,7 +191,7 @@ class CUDADeviceAPI final : public DeviceAPI { ->stream = static_cast(stream); } - void* AllocWorkspace(TVMContext ctx, size_t size, TVMType type_hint) final { + void* AllocWorkspace(TVMContext ctx, size_t size, DLDataType type_hint) final { return CUDAThreadEntry::ThreadLocal()->pool.AllocWorkspace(ctx, size); } diff --git a/src/runtime/file_util.cc b/src/runtime/file_util.cc index 61fbed7bb7381..80dad8d40c08b 100644 --- a/src/runtime/file_util.cc +++ b/src/runtime/file_util.cc @@ -6,9 +6,9 @@ * 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 @@ -34,7 +34,7 @@ namespace runtime { void FunctionInfo::Save(dmlc::JSONWriter* writer) const { std::vector sarg_types(arg_types.size()); for (size_t i = 0; i < arg_types.size(); ++i) { - sarg_types[i] = TVMType2String(arg_types[i]); + sarg_types[i] = DLDataType2String(arg_types[i]); } writer->BeginObject(); writer->WriteObjectKeyValue("name", name); @@ -52,7 +52,7 @@ void FunctionInfo::Load(dmlc::JSONReader* reader) { helper.ReadAllFields(reader); arg_types.resize(sarg_types.size()); for (size_t i = 0; i < arg_types.size(); ++i) { - arg_types[i] = String2TVMType(sarg_types[i]); + arg_types[i] = String2DLDataType(sarg_types[i]); } } diff --git a/src/runtime/graph/debug/graph_runtime_debug.cc b/src/runtime/graph/debug/graph_runtime_debug.cc index 314ddabe2c7b0..1c85de8592739 100644 --- a/src/runtime/graph/debug/graph_runtime_debug.cc +++ b/src/runtime/graph/debug/graph_runtime_debug.cc @@ -176,7 +176,7 @@ PackedFunc GraphRuntimeDebug::GetFunction( }); } else if (name == "debug_get_output") { return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { - if (args[0].type_code() == kStr) { + if (args[0].type_code() == kTVMStr) { this->DebugGetNodeOutput(this->GetNodeIndex(args[0]), args[1]); } else { this->DebugGetNodeOutput(args[0], args[1]); diff --git a/src/runtime/graph/graph_runtime.cc b/src/runtime/graph/graph_runtime.cc index cc2478f27d198..e16497f7324c9 100644 --- a/src/runtime/graph/graph_runtime.cc +++ b/src/runtime/graph/graph_runtime.cc @@ -276,9 +276,9 @@ void GraphRuntime::ShareParams(const GraphRuntime& other, dmlc::Stream* strm) { void GraphRuntime::SetupStorage() { // Grab saved optimization plan from graph. - std::vector vtype; + std::vector vtype; for (const std::string& s_type : attrs_.dltype) { - vtype.push_back(tvm::runtime::String2TVMType(s_type)); + vtype.push_back(tvm::runtime::String2DLDataType(s_type)); } // Size and device type of each storage pool entry. @@ -409,7 +409,7 @@ std::pair, std::shared_ptr > GraphRu DLTensor* t = &arg_ptr->args[i]; v.v_handle = t; arg_ptr->arg_values.push_back(v); - arg_ptr->arg_tcodes.push_back(kArrayHandle); + arg_ptr->arg_tcodes.push_back(kTVMDLTensorHandle); if (param.flatten_data) { arg_ptr->shape_data[i] = std::accumulate( t->shape, t->shape + t->ndim, 1, std::multiplies()); @@ -454,7 +454,7 @@ PackedFunc GraphRuntime::GetFunction( // Return member functions during query. if (name == "set_input") { return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { - if (args[0].type_code() == kStr) { + if (args[0].type_code() == kTVMStr) { int in_idx = this->GetInputIndex(args[0]); if (in_idx >= 0) this->SetInput(in_idx, args[1]); } else { @@ -463,7 +463,7 @@ PackedFunc GraphRuntime::GetFunction( }); } else if (name == "set_input_zero_copy") { return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { - if (args[0].type_code() == kStr) { + if (args[0].type_code() == kTVMStr) { int in_idx = this->GetInputIndex(args[0]); if (in_idx >= 0) this->SetInputZeroCopy(in_idx, args[1]); } else { @@ -481,7 +481,7 @@ PackedFunc GraphRuntime::GetFunction( } else if (name == "get_input") { return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { int in_idx = 0; - if (args[0].type_code() == kStr) { + if (args[0].type_code() == kTVMStr) { in_idx = this->GetInputIndex(args[0]); } else { in_idx = args[0]; diff --git a/src/runtime/library_module.cc b/src/runtime/library_module.cc index 2fabe1bec9525..5b364fc9e006e 100644 --- a/src/runtime/library_module.cc +++ b/src/runtime/library_module.cc @@ -81,7 +81,7 @@ PackedFunc WrapPackedFunc(TVMBackendPackedCFunc faddr, const ObjectPtr& sptr_to_self) { return PackedFunc([faddr, sptr_to_self](TVMArgs args, TVMRetValue* rv) { TVMValue ret_value; - int ret_type_code = kNull; + int ret_type_code = kTVMNullptr; int ret = (*faddr)( const_cast(args.values), const_cast(args.type_codes), @@ -89,7 +89,7 @@ PackedFunc WrapPackedFunc(TVMBackendPackedCFunc faddr, &ret_value, &ret_type_code); CHECK_EQ(ret, 0) << TVMGetLastError(); - if (ret_type_code != kNull) { + if (ret_type_code != kTVMNullptr) { *rv = TVMRetValue::MoveFromCHost(ret_value, ret_type_code); } }); diff --git a/src/runtime/meta_data.h b/src/runtime/meta_data.h index 5d8896826a4c9..22f2e9aa0909b 100644 --- a/src/runtime/meta_data.h +++ b/src/runtime/meta_data.h @@ -6,9 +6,9 @@ * 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 @@ -37,7 +37,7 @@ namespace runtime { /*! \brief function information needed by device */ struct FunctionInfo { std::string name; - std::vector arg_types; + std::vector arg_types; std::vector thread_axis_tags; void Save(dmlc::JSONWriter *writer) const; diff --git a/src/runtime/metal/metal_common.h b/src/runtime/metal/metal_common.h index 30380bcc9f19a..8a7c9fe53018a 100644 --- a/src/runtime/metal/metal_common.h +++ b/src/runtime/metal/metal_common.h @@ -6,9 +6,9 @@ * 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 @@ -84,7 +84,7 @@ class MetalWorkspace final : public DeviceAPI { void* AllocDataSpace(TVMContext ctx, size_t nbytes, size_t alignment, - TVMType type_hint) final; + DLDataType type_hint) final; void FreeDataSpace(TVMContext ctx, void* ptr) final; void CopyDataFromTo(const void* from, size_t from_size, @@ -93,10 +93,10 @@ class MetalWorkspace final : public DeviceAPI { size_t size, TVMContext ctx_from, TVMContext ctx_to, - TVMType type_hint, + DLDataType type_hint, TVMStreamHandle stream) final; void StreamSync(TVMContext ctx, TVMStreamHandle stream) final; - void* AllocWorkspace(TVMContext ctx, size_t size, TVMType type_hint) final; + void* AllocWorkspace(TVMContext ctx, size_t size, DLDataType type_hint) final; void FreeWorkspace(TVMContext ctx, void* data) final; // get the global workspace static const std::shared_ptr& Global(); diff --git a/src/runtime/metal/metal_device_api.mm b/src/runtime/metal/metal_device_api.mm index ecac50645575e..a49f8a5cfc96b 100644 --- a/src/runtime/metal/metal_device_api.mm +++ b/src/runtime/metal/metal_device_api.mm @@ -62,7 +62,7 @@ case kMultiProcessorCount: return; case kMaxThreadDimensions: return; case kExist: break; - case kGcnArch: return; + case kGcnArch: return; } } @@ -145,7 +145,7 @@ int GetWarpSize(id dev) { } void* MetalWorkspace::AllocDataSpace( - TVMContext ctx, size_t nbytes, size_t alignment, TVMType type_hint) { + TVMContext ctx, size_t nbytes, size_t alignment, DLDataType type_hint) { this->Init(); id dev = GetDevice(ctx); // GPU memory only @@ -176,7 +176,7 @@ int GetWarpSize(id dev) { size_t size, TVMContext ctx_from, TVMContext ctx_to, - TVMType type_hint, + DLDataType type_hint, TVMStreamHandle stream) { this->Init(); CHECK(stream == nullptr); @@ -261,7 +261,7 @@ int GetWarpSize(id dev) { void* MetalWorkspace::AllocWorkspace(TVMContext ctx, size_t size, - TVMType type_hint) { + DLDataType type_hint) { return MetalThreadEntry::ThreadLocal()->pool.AllocWorkspace(ctx, size); } diff --git a/src/runtime/micro/micro_device_api.cc b/src/runtime/micro/micro_device_api.cc index de2e03155a04d..3d0a6889c4f7d 100644 --- a/src/runtime/micro/micro_device_api.cc +++ b/src/runtime/micro/micro_device_api.cc @@ -48,7 +48,7 @@ class MicroDeviceAPI final : public DeviceAPI { void* AllocDataSpace(TVMContext ctx, size_t nbytes, size_t alignment, - TVMType type_hint) final { + DLDataType type_hint) final { ObjectPtr& session = MicroSession::Current(); void* data = session->AllocateInSection(SectionKind::kHeap, nbytes).cast_to(); CHECK(data != nullptr) << "unable to allocate " << nbytes << " bytes on device heap"; @@ -72,7 +72,7 @@ class MicroDeviceAPI final : public DeviceAPI { size_t size, TVMContext ctx_from, TVMContext ctx_to, - TVMType type_hint, + DLDataType type_hint, TVMStreamHandle stream) final { std::tuple type_from_to(ctx_from.device_type, ctx_to.device_type); if (type_from_to == std::make_tuple(kDLMicroDev, kDLMicroDev)) { @@ -123,7 +123,7 @@ class MicroDeviceAPI final : public DeviceAPI { void StreamSync(TVMContext ctx, TVMStreamHandle stream) final { } - void* AllocWorkspace(TVMContext ctx, size_t size, TVMType type_hint) final { + void* AllocWorkspace(TVMContext ctx, size_t size, DLDataType type_hint) final { ObjectPtr& session = MicroSession::Current(); void* data = session->AllocateInSection(SectionKind::kWorkspace, size).cast_to(); diff --git a/src/runtime/micro/micro_session.cc b/src/runtime/micro/micro_session.cc index 06ffa73e79df8..4bdc8ed697975 100644 --- a/src/runtime/micro/micro_session.cc +++ b/src/runtime/micro/micro_session.cc @@ -333,9 +333,9 @@ std::tuple MicroSession::EncoderAppend( for (int i = 0; i < num_args; i++) { switch (type_codes[i]) { - case kNDArrayContainer: - case kArrayHandle: { - TVMArray* base_arr_handle = args[i]; + case kTVMNDArrayHandle: + case kTVMDLTensorHandle: { + DLTensor* base_arr_handle = args[i]; // All uTVM arrays store a `MicroDevSpace` struct in their `data` field, // which wraps the actual data and stores a reference to the session, in // order to prevent premature session destruction. @@ -371,7 +371,7 @@ std::tuple MicroSession::EncoderAppend( } template -DevPtr MicroSession::EncoderAppend(TargetDataLayoutEncoder* encoder, const TVMArray& arr) { +DevPtr MicroSession::EncoderAppend(TargetDataLayoutEncoder* encoder, const DLTensor& arr) { auto tvm_arr_slot = encoder->Alloc(); auto shape_slot = encoder->Alloc(arr.ndim); @@ -396,7 +396,7 @@ DevPtr MicroSession::EncoderAppend(TargetDataLayoutEncoder* encoder, const TVMAr strides_dev_addr.value(), TargetVal { .val64 = arr.byte_offset }); CHECK(dev_arr.ctx.device_type == static_cast(kDLMicroDev)) - << "attempt to write TVMArray with non-micro device type"; + << "attempt to write DLTensor with non-micro device type"; // Update the device type to CPU, because from the microcontroller's // perspective, it is. dev_arr.ctx.device_type = DLDeviceType::kDLCPU; diff --git a/src/runtime/micro/micro_session.h b/src/runtime/micro/micro_session.h index 495fc74aa1776..9e844e8b21408 100644 --- a/src/runtime/micro/micro_session.h +++ b/src/runtime/micro/micro_session.h @@ -231,13 +231,13 @@ class MicroSession : public ModuleNode { std::tuple EncoderAppend(TargetDataLayoutEncoder* encoder, const TVMArgs& args); /*! - * \brief appends a `TVMArray` to the host-side buffer of `encoder` + * \brief appends a `DLTensor` to the host-side buffer of `encoder` * \param encoder encoder being used to append `arr` - * \param arr TVMArray to be appended - * \return device address of the allocated `TVMArray` + * \param arr DLTensor to be appended + * \return device address of the allocated `DLTensor` */ template - DevPtr EncoderAppend(TargetDataLayoutEncoder* encoder, const TVMArray& arr); + DevPtr EncoderAppend(TargetDataLayoutEncoder* encoder, const DLTensor& arr); /*! * \brief checks and logs if there was an error during the device's most recent execution diff --git a/src/runtime/micro/standalone/utvm_graph_runtime.cc b/src/runtime/micro/standalone/utvm_graph_runtime.cc index edfb1ffd7144a..546ed7d4988b9 100644 --- a/src/runtime/micro/standalone/utvm_graph_runtime.cc +++ b/src/runtime/micro/standalone/utvm_graph_runtime.cc @@ -324,7 +324,7 @@ std::function CreateTVMOp(const DSOModule& module, const TVMOpParam& par void* v_handle; } TVMValue; /*typedef*/ enum { - kArrayHandle = 7U, + kTVMDLTensorHandle = 7U, } /*TVMTypeCode*/; struct OpArgs { DynArray args; @@ -345,7 +345,7 @@ std::function CreateTVMOp(const DSOModule& module, const TVMOpParam& par DLTensor* t = &(arg_ptr->args[i]); v.v_handle = t; arg_ptr->arg_values[i] = v; - arg_ptr->arg_tcodes[i] = kArrayHandle; + arg_ptr->arg_tcodes[i] = kTVMDLTensorHandle; if (param.flatten_data) { arg_ptr->shape_data[i] = std::accumulate(t->shape, t->shape + t->ndim, 1, std::multiplies()); diff --git a/src/runtime/opencl/opencl_common.h b/src/runtime/opencl/opencl_common.h index 9b8078ef85445..8f9d5d6352bac 100644 --- a/src/runtime/opencl/opencl_common.h +++ b/src/runtime/opencl/opencl_common.h @@ -193,7 +193,7 @@ class OpenCLWorkspace : public DeviceAPI { void* AllocDataSpace(TVMContext ctx, size_t size, size_t alignment, - TVMType type_hint) final; + DLDataType type_hint) final; void FreeDataSpace(TVMContext ctx, void* ptr) final; void CopyDataFromTo(const void* from, size_t from_offset, @@ -202,10 +202,10 @@ class OpenCLWorkspace : public DeviceAPI { size_t size, TVMContext ctx_from, TVMContext ctx_to, - TVMType type_hint, + DLDataType type_hint, TVMStreamHandle stream) final; void StreamSync(TVMContext ctx, TVMStreamHandle stream) final; - void* AllocWorkspace(TVMContext ctx, size_t size, TVMType type_hint) final; + void* AllocWorkspace(TVMContext ctx, size_t size, DLDataType type_hint) final; void FreeWorkspace(TVMContext ctx, void* data) final; /*! diff --git a/src/runtime/opencl/opencl_device_api.cc b/src/runtime/opencl/opencl_device_api.cc index 4bfada7b2ef96..99d2b0cb24e6c 100644 --- a/src/runtime/opencl/opencl_device_api.cc +++ b/src/runtime/opencl/opencl_device_api.cc @@ -6,9 +6,9 @@ * 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 @@ -118,7 +118,7 @@ void OpenCLWorkspace::GetAttr( } void* OpenCLWorkspace::AllocDataSpace( - TVMContext ctx, size_t size, size_t alignment, TVMType type_hint) { + TVMContext ctx, size_t size, size_t alignment, DLDataType type_hint) { this->Init(); CHECK(context != nullptr) << "No OpenCL device"; cl_int err_code; @@ -144,7 +144,7 @@ void OpenCLWorkspace::CopyDataFromTo(const void* from, size_t size, TVMContext ctx_from, TVMContext ctx_to, - TVMType type_hint, + DLDataType type_hint, TVMStreamHandle stream) { this->Init(); CHECK(stream == nullptr); @@ -182,7 +182,7 @@ void OpenCLWorkspace::StreamSync(TVMContext ctx, TVMStreamHandle stream) { void* OpenCLWorkspace::AllocWorkspace(TVMContext ctx, size_t size, - TVMType type_hint) { + DLDataType type_hint) { return GetThreadEntry()->pool.AllocWorkspace(ctx, size); } diff --git a/src/runtime/opencl/opencl_module.cc b/src/runtime/opencl/opencl_module.cc index 24687db46ce67..b530d0e2e01a1 100644 --- a/src/runtime/opencl/opencl_module.cc +++ b/src/runtime/opencl/opencl_module.cc @@ -131,9 +131,9 @@ PackedFunc OpenCLModuleNode::GetFunction( OpenCLWrappedFunc f; std::vector arg_size(info.arg_types.size()); for (size_t i = 0; i < info.arg_types.size(); ++i) { - TVMType t = info.arg_types[i]; + DLDataType t = info.arg_types[i]; CHECK_EQ(t.lanes, 1U); - if (t.code == kHandle) { + if (t.code == kTVMOpaqueHandle) { // specially store pointer type size in OpenCL driver arg_size[i] = sizeof(void*); } else { diff --git a/src/runtime/opengl/opengl_common.h b/src/runtime/opengl/opengl_common.h index 9bc0df2744697..009ea6c9111d2 100644 --- a/src/runtime/opengl/opengl_common.h +++ b/src/runtime/opengl/opengl_common.h @@ -6,9 +6,9 @@ * 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 @@ -184,7 +184,7 @@ class OpenGLWorkspace final : public DeviceAPI { void* AllocDataSpace(TVMContext ctx, size_t nbytes, size_t alignment, - TVMType type_hint) final; + DLDataType type_hint) final; void FreeDataSpace(TVMContext ctx, void* ptr) final; void CopyDataFromTo(const void* from, size_t from_offset, @@ -193,7 +193,7 @@ class OpenGLWorkspace final : public DeviceAPI { size_t size, TVMContext ctx_from, TVMContext ctx_to, - TVMType type_hint, + DLDataType type_hint, TVMStreamHandle stream) final; void StreamSync(TVMContext ctx, TVMStreamHandle stream) final; @@ -216,7 +216,7 @@ class OpenGLWorkspace final : public DeviceAPI { * \param nbytes Number of bytes in the array. * \return The OpenGL texture. */ - Texture CreateTexture(TVMType type, size_t nbytes); + Texture CreateTexture(DLDataType type, size_t nbytes); /*! * \brief Upload user data into a sub-region of an OpenGL texture. @@ -256,7 +256,7 @@ class OpenGLWorkspace final : public DeviceAPI { */ void SetUniform(const Program& program, const std::string& name, - TVMType type, + DLDataType type, void* value); /*! diff --git a/src/runtime/opengl/opengl_device_api.cc b/src/runtime/opengl/opengl_device_api.cc index beabb96b6678b..0be921cb4ae58 100644 --- a/src/runtime/opengl/opengl_device_api.cc +++ b/src/runtime/opengl/opengl_device_api.cc @@ -6,9 +6,9 @@ * 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 @@ -121,7 +121,7 @@ void OpenGLWorkspace::GetAttr( } void* OpenGLWorkspace::AllocDataSpace( - TVMContext ctx, size_t nbytes, size_t alignment, TVMType type_hint) { + TVMContext ctx, size_t nbytes, size_t alignment, DLDataType type_hint) { return reinterpret_cast(new Texture(CreateTexture(type_hint, nbytes))); } @@ -136,7 +136,7 @@ void OpenGLWorkspace::CopyDataFromTo(const void* from, size_t size, TVMContext ctx_from, TVMContext ctx_to, - TVMType type_hint, + DLDataType type_hint, TVMStreamHandle stream) { CHECK(stream == nullptr); @@ -312,7 +312,7 @@ GLuint OpenGLWorkspace::CreateShader(GLenum shader_kind, return shader; } -static TextureFormat GetTextureFormat(TVMType type) { +static TextureFormat GetTextureFormat(DLDataType type) { CHECK_EQ(type.lanes, 1) << "Not supporting multi-lane types."; switch (type.code) { @@ -355,7 +355,7 @@ static TextureFormat GetTextureFormat(TVMType type) { return {GL_R32F, GL_RED, GL_FLOAT}; } -Texture OpenGLWorkspace::CreateTexture(TVMType type, size_t nbytes) { +Texture OpenGLWorkspace::CreateTexture(DLDataType type, size_t nbytes) { // Create a texture. GLuint texture; OPENGL_CALL(gl->GenTextures(1, &texture)); @@ -555,7 +555,7 @@ void OpenGLWorkspace::SetCurrentProgram(const Program& program) { void OpenGLWorkspace::SetUniform(const Program& program, const std::string& name, - TVMType type, + DLDataType type, void* value) { GLint location = gl->GetUniformLocation(program.program(), name.c_str()); switch (type.code) { diff --git a/src/runtime/opengl/opengl_module.cc b/src/runtime/opengl/opengl_module.cc index f2b0dc31ef4f3..63d9d21891b5b 100644 --- a/src/runtime/opengl/opengl_module.cc +++ b/src/runtime/opengl/opengl_module.cc @@ -120,7 +120,7 @@ PackedFunc OpenGLModuleNode::GetFunction( std::vector arg_size(func_info.arg_types.size()); for (size_t i = 0; i < func_info.arg_types.size(); ++i) { - TVMType t = func_info.arg_types[i]; + DLDataType t = func_info.arg_types[i]; CHECK_EQ(t.lanes, 1U); uint32_t bits = t.bits; CHECK_EQ(bits % 8, 0U); @@ -222,14 +222,14 @@ void OpenGLWrappedFunc::operator()(TVMArgs args, TVMRetValue* rv, break; } case OpenGLArgKind::kInputTexture: { - CHECK_EQ(type.code, kHandle) << "Type is not handle?"; + CHECK_EQ(type.code, kTVMOpaqueHandle) << "Type is not handle?"; auto texture = *static_cast(void_args[i]); m_->workspace().SetInputTexture(program, name, texture_unit, texture); ++texture_unit; break; } case OpenGLArgKind::kOutputTexture: { - CHECK_EQ(type.code, kHandle) << "Type is not handle?"; + CHECK_EQ(type.code, kTVMOpaqueHandle) << "Type is not handle?"; CHECK(output == nullptr) << "Can only have one output texture."; output = *static_cast(void_args[i]); break; @@ -241,7 +241,7 @@ void OpenGLWrappedFunc::operator()(TVMArgs args, TVMRetValue* rv, ThreadWorkLoad wl = thread_axis_cfg_.Extract(args); std::unique_ptr thread_extent(new GLint(wl.block_dim(0))); m_->workspace().SetUniform(program, shader.thread_extent_var, - TVMType{kDLInt, 32, 1}, + DLDataType{kDLInt, 32, 1}, static_cast(thread_extent.get())); m_->workspace().Render(output); diff --git a/src/runtime/pack_args.h b/src/runtime/pack_args.h index 6e4fb140e8136..9d24ca9072b4d 100644 --- a/src/runtime/pack_args.h +++ b/src/runtime/pack_args.h @@ -6,9 +6,9 @@ * 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 @@ -56,7 +56,7 @@ union ArgUnion { * \return The wrapped packed function. */ template -inline PackedFunc PackFuncVoidAddr(F f, const std::vector& arg_types); +inline PackedFunc PackFuncVoidAddr(F f, const std::vector& arg_types); /*! * \brief Create a packed function that from function only packs buffer arguments. * @@ -67,7 +67,7 @@ inline PackedFunc PackFuncVoidAddr(F f, const std::vector& arg_types); * \return The wrapped packed function. */ template -inline PackedFunc PackFuncNonBufferArg(F f, const std::vector& arg_types); +inline PackedFunc PackFuncNonBufferArg(F f, const std::vector& arg_types); /*! * \brief Create a packed function that from function that takes a packed arguments. * @@ -78,13 +78,13 @@ inline PackedFunc PackFuncNonBufferArg(F f, const std::vector& arg_type * \return The wrapped packed function. */ template -inline PackedFunc PackFuncPackedArg(F f, const std::vector& arg_types); +inline PackedFunc PackFuncPackedArg(F f, const std::vector& arg_types); /*! * \brief Extract number of buffer argument from the argument types. * \param arg_types The argument types. * \return number of buffer arguments */ -inline size_t NumBufferArgs(const std::vector& arg_types); +inline size_t NumBufferArgs(const std::vector& arg_types); // implementations details namespace detail { @@ -119,7 +119,7 @@ enum ArgConvertCode { HANDLE_TO_HANDLE }; -inline ArgConvertCode GetArgConvertCode(TVMType t) { +inline ArgConvertCode GetArgConvertCode(DLDataType t) { CHECK_EQ(t.lanes, 1U) << "Cannot pass vector type argument to devic function for now"; if (t.code == kDLInt) { @@ -130,7 +130,7 @@ inline ArgConvertCode GetArgConvertCode(TVMType t) { } else if (t.code == kDLFloat) { if (t.bits == 64U) return FLOAT64_TO_FLOAT64; if (t.bits == 32U) return FLOAT64_TO_FLOAT32; - } else if (t.code == kHandle) { + } else if (t.code == kTVMOpaqueHandle) { return HANDLE_TO_HANDLE; } LOG(FATAL) << "Cannot handle " << t << " as device function argument"; @@ -262,7 +262,7 @@ inline PackedFunc PackFuncPackedArg_( } // namespace detail template -inline PackedFunc PackFuncVoidAddr(F f, const std::vector& arg_types) { +inline PackedFunc PackFuncVoidAddr(F f, const std::vector& arg_types) { std::vector codes(arg_types.size()); for (size_t i = 0; i < arg_types.size(); ++i) { codes[i] = detail::GetArgConvertCode(arg_types[i]); @@ -278,22 +278,22 @@ inline PackedFunc PackFuncVoidAddr(F f, const std::vector& arg_types) { } } -inline size_t NumBufferArgs(const std::vector& arg_types) { +inline size_t NumBufferArgs(const std::vector& arg_types) { size_t base = arg_types.size(); for (size_t i = 0; i < arg_types.size(); ++i) { - if (arg_types[i].code != kHandle) { + if (arg_types[i].code != kTVMOpaqueHandle) { base = i; break; } } for (size_t i = base; i < arg_types.size(); ++i) { - CHECK(arg_types[i].code != kHandle) + CHECK(arg_types[i].code != kTVMOpaqueHandle) << "Device function need to be organized"; } return base; } template -inline PackedFunc PackFuncNonBufferArg(F f, const std::vector& arg_types) { +inline PackedFunc PackFuncNonBufferArg(F f, const std::vector& arg_types) { size_t num_buffer = NumBufferArgs(arg_types); std::vector codes; for (size_t i = num_buffer; i < arg_types.size(); ++i) { @@ -310,7 +310,7 @@ inline PackedFunc PackFuncNonBufferArg(F f, const std::vector& arg_type } template -inline PackedFunc PackFuncPackedArg(F f, const std::vector& arg_types) { +inline PackedFunc PackFuncPackedArg(F f, const std::vector& arg_types) { std::vector codes; for (size_t i = 0; i < arg_types.size(); ++i) { codes.push_back(detail::GetArgConvertCode(arg_types[i])); diff --git a/src/runtime/rocm/rocm_device_api.cc b/src/runtime/rocm/rocm_device_api.cc index b4c4682d10f65..25e1ac70c2416 100644 --- a/src/runtime/rocm/rocm_device_api.cc +++ b/src/runtime/rocm/rocm_device_api.cc @@ -119,7 +119,7 @@ class ROCMDeviceAPI final : public DeviceAPI { *rv = value; } void* AllocDataSpace(TVMContext ctx, size_t nbytes, size_t alignment, - TVMType type_hint) final { + DLDataType type_hint) final { ROCM_CALL(hipSetDevice(ctx.device_id)); CHECK_EQ(256 % alignment, 0U) << "ROCM space is aligned at 256 bytes"; void* ret; @@ -134,7 +134,7 @@ class ROCMDeviceAPI final : public DeviceAPI { void CopyDataFromTo(const void* from, size_t from_offset, void* to, size_t to_offset, size_t size, TVMContext ctx_from, - TVMContext ctx_to, TVMType type_hint, + TVMContext ctx_to, DLDataType type_hint, TVMStreamHandle stream) final { hipStream_t hip_stream = static_cast(stream); from = static_cast(from) + from_offset; @@ -169,7 +169,7 @@ class ROCMDeviceAPI final : public DeviceAPI { ROCMThreadEntry::ThreadLocal()->stream = static_cast(stream); } - void* AllocWorkspace(TVMContext ctx, size_t size, TVMType type_hint) final { + void* AllocWorkspace(TVMContext ctx, size_t size, DLDataType type_hint) final { return ROCMThreadEntry::ThreadLocal()->pool.AllocWorkspace(ctx, size); } diff --git a/src/runtime/rpc/rpc_device_api.cc b/src/runtime/rpc/rpc_device_api.cc index a463014b3f4cd..9fd45acd14bf4 100644 --- a/src/runtime/rpc/rpc_device_api.cc +++ b/src/runtime/rpc/rpc_device_api.cc @@ -6,9 +6,9 @@ * 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 @@ -41,7 +41,7 @@ class RPCDeviceAPI final : public DeviceAPI { void* AllocDataSpace(TVMContext ctx, size_t nbytes, size_t alignment, - TVMType type_hint) final { + DLDataType type_hint) final { auto sess = GetSess(ctx); void *data = sess->CallRemote( RPCCode::kDevAllocData, ctx, nbytes, alignment, type_hint); @@ -67,7 +67,7 @@ class RPCDeviceAPI final : public DeviceAPI { size_t size, TVMContext ctx_from, TVMContext ctx_to, - TVMType type_hint, + DLDataType type_hint, TVMStreamHandle stream) final { int from_dev_type = ctx_from.device_type; int to_dev_type = ctx_to.device_type; diff --git a/src/runtime/rpc/rpc_module.cc b/src/runtime/rpc/rpc_module.cc index 881788a5292c6..a28e4b1b5efbf 100644 --- a/src/runtime/rpc/rpc_module.cc +++ b/src/runtime/rpc/rpc_module.cc @@ -187,7 +187,7 @@ class RPCModuleNode final : public ModuleNode { void* RPCWrappedFunc::UnwrapRemote(int rpc_sess_table_index, const TVMArgValue& arg) { - if (arg.type_code() == kModuleHandle) { + if (arg.type_code() == kTVMModuleHandle) { Module mod = arg; std::string tkey = mod->type_key(); CHECK_EQ(tkey, "rpc") @@ -211,15 +211,15 @@ void RPCWrappedFunc::WrapRemote(std::shared_ptr sess, int tcode = args.type_codes[0]; if (handle == nullptr) return; - if (tcode == kFuncHandle) { + if (tcode == kTVMPackedFuncHandle) { auto wf = std::make_shared(handle, sess); *rv = PackedFunc([wf](TVMArgs args, TVMRetValue* rv) { return wf->operator()(args, rv); }); - } else if (tcode == kModuleHandle) { + } else if (tcode == kTVMModuleHandle) { auto n = make_object(handle, sess); *rv = Module(n); - } else if (tcode == kArrayHandle || tcode == kNDArrayContainer) { + } else if (tcode == kTVMDLTensorHandle || tcode == kTVMNDArrayHandle) { CHECK_EQ(args.size(), 2); DLTensor* tensor = args[0]; void* nd_handle = args[1]; diff --git a/src/runtime/rpc/rpc_session.cc b/src/runtime/rpc/rpc_session.cc index 6d1c8f03a36b1..43ca630f94963 100644 --- a/src/runtime/rpc/rpc_session.cc +++ b/src/runtime/rpc/rpc_session.cc @@ -159,9 +159,9 @@ class RPCSession::EventHandler : public dmlc::Stream { CHECK_GE(arg_buf_->value.size(), 1U); TVMArgValue argv = arg_buf_->AsTVMArgs()[0]; - if (argv.type_code() == kFuncHandle || - argv.type_code() == kModuleHandle || - argv.type_code() == kArrayHandle) { + if (argv.type_code() == kTVMPackedFuncHandle || + argv.type_code() == kTVMModuleHandle || + argv.type_code() == kTVMDLTensorHandle) { CHECK(fwrap != nullptr) << "function/module wrapper not available"; fwrap->CallPacked(arg_buf_->AsTVMArgs(), rv); } else { @@ -223,7 +223,7 @@ class RPCSession::EventHandler : public dmlc::Stream { this->Write(num_args); for (int i = 0; i < num_args; ++i) { int tcode = type_codes[i]; - if (tcode == kNDArrayContainer) tcode = kArrayHandle; + if (tcode == kTVMNDArrayHandle) tcode = kTVMDLTensorHandle; this->Write(tcode); } @@ -238,7 +238,7 @@ class RPCSession::EventHandler : public dmlc::Stream { this->Write(value.v_int64); break; } - case kTVMType: { + case kTVMDataType: { this->Write(value.v_type); // padding int32_t padding = 0; @@ -250,8 +250,8 @@ class RPCSession::EventHandler : public dmlc::Stream { this->Write(value.v_ctx); break; } - case kFuncHandle: - case kModuleHandle: { + case kTVMPackedFuncHandle: + case kTVMModuleHandle: { // always send handle in 64 bit. uint64_t handle; // allow pass module as argument to remote. @@ -268,14 +268,14 @@ class RPCSession::EventHandler : public dmlc::Stream { this->Write(handle); break; } - case kHandle: { + case kTVMOpaqueHandle: { // always send handle in 64 bit. uint64_t handle = reinterpret_cast(value.v_handle); this->Write(handle); break; } - case kNDArrayContainer: - case kArrayHandle: { + case kTVMNDArrayHandle: + case kTVMDLTensorHandle: { DLTensor* arr = static_cast(value.v_handle); TVMContext ctx; uint64_t data; @@ -305,15 +305,15 @@ class RPCSession::EventHandler : public dmlc::Stream { << "Do not support send byte offset"; break; } - case kNull: break; - case kStr: { + case kTVMNullptr: break; + case kTVMStr: { const char* s = value.v_str; uint64_t len = strlen(s); this->Write(len); this->WriteArray(s, len); break; } - case kBytes: { + case kTVMBytes: { TVMByteArray* bytes = static_cast(arg_values[i].v_handle); uint64_t len = bytes->size; this->Write(len); @@ -386,7 +386,7 @@ class RPCSession::EventHandler : public dmlc::Stream { std::string temp_data_; // Temp variables for copy request state. TVMContext copy_ctx_; - TVMType copy_dtype_; + DLDataType copy_dtype_; uint64_t copy_handle_, copy_offset_, copy_size_; // State switcher void SwitchToState(State state) { @@ -428,13 +428,13 @@ class RPCSession::EventHandler : public dmlc::Stream { case kDoCopyFromRemote: { this->RequestBytes(sizeof(uint64_t) * 3); this->RequestBytes(sizeof(TVMContext)); - this->RequestBytes(sizeof(TVMType)); + this->RequestBytes(sizeof(DLDataType)); break; } case kDoCopyToRemote: { this->RequestBytes(sizeof(uint64_t) * 3); this->RequestBytes(sizeof(TVMContext)); - this->RequestBytes(sizeof(TVMType)); + this->RequestBytes(sizeof(DLDataType)); break; } case kCopyAckReceived: @@ -453,21 +453,21 @@ class RPCSession::EventHandler : public dmlc::Stream { case kDLInt: case kDLUInt: case kDLFloat: - case kTVMType: - case kHandle: - case kStr: - case kBytes: - case kModuleHandle: + case kTVMDataType: + case kTVMOpaqueHandle: + case kTVMStr: + case kTVMBytes: + case kTVMModuleHandle: case kTVMContext: { this->RequestBytes(sizeof(TVMValue)); break; } - case kFuncHandle: { + case kTVMPackedFuncHandle: { CHECK(client_mode_) << "Only client can receive remote functions"; this->RequestBytes(sizeof(TVMValue)); break; } - case kNull: break; - case kArrayHandle: { + case kTVMNullptr: break; + case kTVMDLTensorHandle: { this->RequestBytes(sizeof(uint64_t)); this->RequestBytes(sizeof(TVMContext)); this->RequestBytes(sizeof(int)); @@ -495,7 +495,7 @@ class RPCSession::EventHandler : public dmlc::Stream { this->SwitchToState(kRecvPackedSeqArg); break; } - case kTVMType: { + case kTVMDataType: { this->Read(&(value.v_type)); int32_t padding = 0; this->Read(&padding); @@ -509,9 +509,9 @@ class RPCSession::EventHandler : public dmlc::Stream { this->SwitchToState(kRecvPackedSeqArg); break; } - case kFuncHandle: - case kModuleHandle: - case kHandle: { + case kTVMPackedFuncHandle: + case kTVMModuleHandle: + case kTVMOpaqueHandle: { // always send handle in 64 bit. uint64_t handle; this->Read(&handle); @@ -520,14 +520,14 @@ class RPCSession::EventHandler : public dmlc::Stream { this->SwitchToState(kRecvPackedSeqArg); break; } - case kNull: { + case kTVMNullptr: { value.v_handle = nullptr; ++arg_index_; this->SwitchToState(kRecvPackedSeqArg); break; } - case kStr: - case kBytes: { + case kTVMStr: + case kTVMBytes: { uint64_t len; this->Read(&len); temp_bytes_.reset( new RPCByteArrayBuffer()); @@ -536,7 +536,7 @@ class RPCSession::EventHandler : public dmlc::Stream { this->RequestBytes(len); break; } - case kArrayHandle: { + case kTVMDLTensorHandle: { temp_array_.reset(new RPCDataArrayBuffer()); uint64_t handle; this->Read(&handle); @@ -560,11 +560,11 @@ class RPCSession::EventHandler : public dmlc::Stream { } } else { CHECK_EQ(arg_recv_stage_, 1); - if (tcode == kStr || tcode == kBytes) { + if (tcode == kTVMStr || tcode == kTVMBytes) { if (temp_bytes_->data.size() != 0) { this->ReadArray(&(temp_bytes_->data[0]), temp_bytes_->data.size()); } - if (tcode == kStr) { + if (tcode == kTVMStr) { value.v_str = temp_bytes_->data.c_str(); } else { temp_bytes_->arr.size = static_cast(temp_bytes_->data.size()); @@ -573,7 +573,7 @@ class RPCSession::EventHandler : public dmlc::Stream { } arg_buf_->temp_bytes.emplace_back(std::move(temp_bytes_)); } else { - CHECK_EQ(tcode, kArrayHandle); + CHECK_EQ(tcode, kTVMDLTensorHandle); DLTensor& tensor = temp_array_->tensor; this->ReadArray(tensor.shape, tensor.ndim); value.v_handle = &tensor; @@ -641,7 +641,7 @@ class RPCSession::EventHandler : public dmlc::Stream { void HandleCopyFromRemote() { uint64_t handle, offset, num_bytes; TVMContext ctx; - TVMType type_hint; + DLDataType type_hint; this->Read(&handle); this->Read(&offset); this->Read(&num_bytes); @@ -682,7 +682,7 @@ class RPCSession::EventHandler : public dmlc::Stream { this->Write(code); TVMValue ret_value; ret_value.v_str = e.what(); - int ret_tcode = kStr; + int ret_tcode = kTVMStr; SendPackedSeq(&ret_value, &ret_tcode, 1, false); } } @@ -705,7 +705,7 @@ class RPCSession::EventHandler : public dmlc::Stream { CHECK_EQ(arg_recv_stage_, 1); TVMValue ret_value; ret_value.v_handle = nullptr; - int ret_tcode = kNull; + int ret_tcode = kTVMNullptr; RPCCode code = RPCCode::kReturn; std::string errmsg; @@ -734,7 +734,7 @@ class RPCSession::EventHandler : public dmlc::Stream { code = RPCCode::kException; errmsg = e.what(); ret_value.v_str = errmsg.c_str(); - ret_tcode = kStr; + ret_tcode = kTVMStr; } } this->Write(code); @@ -758,26 +758,26 @@ class RPCSession::EventHandler : public dmlc::Stream { f(args->AsTVMArgs(), &rv); RPCCode code = RPCCode::kReturn; this->Write(code); - if (rv.type_code() == kStr) { + if (rv.type_code() == kTVMStr) { ret_value.v_str = rv.ptr()->c_str(); - ret_tcode = kStr; + ret_tcode = kTVMStr; SendPackedSeq(&ret_value, &ret_tcode, 1, false); - } else if (rv.type_code() == kBytes) { + } else if (rv.type_code() == kTVMBytes) { std::string* bytes = rv.ptr(); TVMByteArray arr; arr.data = bytes->c_str(); arr.size = bytes->length(); ret_value.v_handle = &arr; - ret_tcode = kBytes; + ret_tcode = kTVMBytes; SendPackedSeq(&ret_value, &ret_tcode, 1, false); - } else if (rv.type_code() == kFuncHandle || - rv.type_code() == kModuleHandle) { + } else if (rv.type_code() == kTVMPackedFuncHandle || + rv.type_code() == kTVMModuleHandle) { // always send handle in 64 bit. CHECK(!client_mode_) << "Only server can send function and module handle back."; rv.MoveToCHost(&ret_value, &ret_tcode); SendPackedSeq(&ret_value, &ret_tcode, 1, false); - } else if (rv.type_code() == kNDArrayContainer) { + } else if (rv.type_code() == kTVMNDArrayHandle) { // always send handle in 64 bit. CHECK(!client_mode_) << "Only server can send NDArray back"; @@ -788,7 +788,7 @@ class RPCSession::EventHandler : public dmlc::Stream { int ret_tcode_pack[2]; rv.MoveToCHost(&ret_value_pack[0], &ret_tcode_pack[0]); ret_value_pack[1].v_handle = ret_value_pack[0].v_handle; - ret_tcode_pack[1] = kHandle; + ret_tcode_pack[1] = kTVMOpaqueHandle; SendPackedSeq(ret_value_pack, ret_tcode_pack, 2, false, nullptr, true); } else { ret_value = rv.value(); @@ -799,7 +799,7 @@ class RPCSession::EventHandler : public dmlc::Stream { RPCCode code = RPCCode::kException; this->Write(code); ret_value.v_str = e.what(); - ret_tcode = kStr; + ret_tcode = kTVMStr; SendPackedSeq(&ret_value, &ret_tcode, 1, false); } } @@ -999,7 +999,7 @@ void RPCSession::CopyToRemote(void* from, size_t to_offset, size_t data_size, TVMContext ctx_to, - TVMType type_hint) { + DLDataType type_hint) { std::lock_guard lock(mutex_); ctx_to = handler_->StripSessMask(ctx_to); RPCCode code = RPCCode::kCopyToRemote; @@ -1023,7 +1023,7 @@ void RPCSession::CopyFromRemote(void* from, size_t to_offset, size_t data_size, TVMContext ctx_from, - TVMType type_hint) { + DLDataType type_hint) { std::lock_guard lock(mutex_); ctx_from = handler_->StripSessMask(ctx_from); RPCCode code = RPCCode::kCopyFromRemote; @@ -1099,7 +1099,7 @@ void RPCDevAllocData(TVMArgs args, TVMRetValue *rv) { TVMContext ctx = args[0]; uint64_t nbytes = args[1]; uint64_t alignment = args[2]; - TVMType type_hint = args[3]; + DLDataType type_hint = args[3]; void* data = DeviceAPI::Get(ctx)->AllocDataSpace( ctx, nbytes, alignment, type_hint); *rv = data; @@ -1125,7 +1125,7 @@ void RPCCopyAmongRemote(TVMArgs args, TVMRetValue *rv) { uint64_t size = args[4]; TVMContext ctx_from = args[5]; TVMContext ctx_to = args[6]; - TVMType type_hint = args[7]; + DLDataType type_hint = args[7]; TVMStreamHandle stream = args[8]; TVMContext ctx = ctx_from; if (ctx.device_type == kDLCPU) { @@ -1153,7 +1153,7 @@ void RPCModuleLoad(TVMArgs args, TVMRetValue *rv) { TVMValue value; int rcode; ret.MoveToCHost(&value, &rcode); - CHECK_EQ(rcode, kModuleHandle); + CHECK_EQ(rcode, kTVMModuleHandle); *rv = static_cast(value.v_handle); } @@ -1218,7 +1218,7 @@ void RPCSession::EventHandler::HandlePackedCall() { } case RPCCode::kException: { CHECK_EQ(arg_buf_->value.size(), 1U); - CHECK_EQ(arg_buf_->tcode[0], kStr); + CHECK_EQ(arg_buf_->tcode[0], kTVMStr); std::ostringstream os; os << "Except caught from RPC call: " << arg_buf_->value[0].v_str; arg_buf_.reset(); @@ -1343,7 +1343,8 @@ size_t CallbackChannel::Send(const void* data, size_t size) { size_t CallbackChannel::Recv(void* data, size_t size) { TVMRetValue ret = frecv_(size); - if (ret.type_code() != kBytes) { + + if (ret.type_code() != kTVMBytes) { support::Socket::Error("CallbackChannel::Recv"); } std::string* bytes = ret.ptr(); diff --git a/src/runtime/rpc/rpc_session.h b/src/runtime/rpc/rpc_session.h index 888df8ffde653..db63be4be74da 100644 --- a/src/runtime/rpc/rpc_session.h +++ b/src/runtime/rpc/rpc_session.h @@ -178,7 +178,7 @@ class RPCSession { size_t to_offset, size_t nbytes, TVMContext ctx_to, - TVMType type_hint); + DLDataType type_hint); /*! * \brief Copy bytes from remote array content. * \param from The source host data. @@ -195,7 +195,7 @@ class RPCSession { size_t to_offset, size_t nbytes, TVMContext ctx_from, - TVMType type_hint); + DLDataType type_hint); /*! * \brief Get a remote timer function on ctx. * This function consumes fhandle, caller should not call Free on fhandle. diff --git a/src/runtime/sgx/trusted/runtime.cc b/src/runtime/sgx/trusted/runtime.cc index bf02281da332e..05f949c39001a 100644 --- a/src/runtime/sgx/trusted/runtime.cc +++ b/src/runtime/sgx/trusted/runtime.cc @@ -6,9 +6,9 @@ * 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 @@ -54,10 +54,10 @@ void tvm_ecall_packed_func(int func_id, f->CallPacked(TVMArgs(arg_values, type_codes, num_args), &rv); int ret_type_code = rv.type_code(); - if (ret_type_code == kNull) return; + if (ret_type_code == kTVMNullptr) return; TVMValue ret_value; - if (ret_type_code == kBytes || ret_type_code == kStr) { + if (ret_type_code == kTVMBytes || ret_type_code == kTVMStr) { // allocate a buffer in untrusted, copy the values in std::string bytes = rv; @@ -73,7 +73,7 @@ void tvm_ecall_packed_func(int func_id, arr->size = bytes.size(); ret_value = TVMValue{.v_handle = arr}; - ret_type_code = kBytes; + ret_type_code = kTVMBytes; } else { rv.MoveToCHost(&ret_value, &ret_type_code); } diff --git a/src/runtime/sgx/untrusted/sgx_module.cc b/src/runtime/sgx/untrusted/sgx_module.cc index e55b6824ba532..541ab420412ca 100644 --- a/src/runtime/sgx/untrusted/sgx_module.cc +++ b/src/runtime/sgx/untrusted/sgx_module.cc @@ -6,9 +6,9 @@ * 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 @@ -187,8 +187,8 @@ TVM_REGISTER_GLOBAL("__sgx_println__") case kDLInt: msg << static_cast(args[i]); break; case kDLUInt: msg << static_cast(args[i]); break; case kDLFloat: msg << static_cast(args[i]); break; - case kStr: - case kBytes: { + case kTVMStr: + case kTVMBytes: { std::string val = args[i]; msg << val; } diff --git a/src/runtime/stackvm/stackvm.cc b/src/runtime/stackvm/stackvm.cc index 07014a63110c3..06b154e8d4df5 100644 --- a/src/runtime/stackvm/stackvm.cc +++ b/src/runtime/stackvm/stackvm.cc @@ -395,7 +395,7 @@ void StackVM::Run(State* s) const { using namespace ir; int index = code[pc + 1].v_int; int kind = code[pc + 2].v_int; - TVMArray* arr = static_cast(stack[sp].v_handle); + DLTensor* arr = static_cast(stack[sp].v_handle); switch (kind) { case intrinsic::kArrData: { stack[sp].v_handle = arr[index].data; break; @@ -447,7 +447,7 @@ void StackVM::Run(State* s) const { using namespace ir; int index = code[pc + 1].v_int; int kind = code[pc + 2].v_int; - TVMArray* arr = static_cast(stack[sp - 1].v_handle); + DLTensor* arr = static_cast(stack[sp - 1].v_handle); switch (kind) { case intrinsic::kArrData: { arr[index].data = stack[sp].v_handle; break; diff --git a/src/runtime/stackvm/stackvm.h b/src/runtime/stackvm/stackvm.h index c7db11e890cb4..6ed9647e2da93 100644 --- a/src/runtime/stackvm/stackvm.h +++ b/src/runtime/stackvm/stackvm.h @@ -6,9 +6,9 @@ * 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 @@ -358,9 +358,9 @@ class StackVM { * \param t the type code. * \return The load opcode */ - static OpCode GetLoad(TVMType t) { + static OpCode GetLoad(DLDataType t) { CHECK_EQ(t.lanes, 1U); - if (t.code == kHandle) return ARRAY_LOAD_HANDLE; + if (t.code == kTVMOpaqueHandle) return ARRAY_LOAD_HANDLE; if (t.code == kDLInt) { switch (t.bits) { case 32 : return ARRAY_LOAD_INT32; @@ -383,9 +383,9 @@ class StackVM { * \param t the type code. * \return The load opcode */ - static OpCode GetStore(TVMType t) { + static OpCode GetStore(DLDataType t) { CHECK_EQ(t.lanes, 1U); - if (t.code == kHandle) return ARRAY_STORE_HANDLE; + if (t.code == kTVMOpaqueHandle) return ARRAY_STORE_HANDLE; if (t.code == kDLInt) { switch (t.bits) { case 32 : return ARRAY_STORE_INT32; diff --git a/src/runtime/vm/memory_manager.h b/src/runtime/vm/memory_manager.h index 95a154ce6beee..b4453524d9961 100644 --- a/src/runtime/vm/memory_manager.h +++ b/src/runtime/vm/memory_manager.h @@ -82,7 +82,7 @@ class Allocator { * \param type_hint A type hint to the allocator. * \return A sized allocation in the form of a buffer. */ - virtual Buffer Alloc(size_t nbytes, size_t alignment, TVMType type_hint) = 0; + virtual Buffer Alloc(size_t nbytes, size_t alignment, DLDataType type_hint) = 0; /*! \brief Free a buffer allocated by the allocator. * \param buffer The buffer to free. */ diff --git a/src/runtime/vm/naive_allocator.h b/src/runtime/vm/naive_allocator.h index bdc8ecf2859b6..db47a62a7c399 100644 --- a/src/runtime/vm/naive_allocator.h +++ b/src/runtime/vm/naive_allocator.h @@ -36,7 +36,7 @@ class NaiveAllocator final : public Allocator { public: explicit NaiveAllocator(TVMContext ctx) : Allocator(), used_memory_(0), ctx_(ctx) {} - Buffer Alloc(size_t nbytes, size_t alignment, TVMType type_hint) override { + Buffer Alloc(size_t nbytes, size_t alignment, DLDataType type_hint) override { Buffer buf; buf.ctx = ctx_; buf.size = nbytes; diff --git a/src/runtime/vm/pooled_allocator.h b/src/runtime/vm/pooled_allocator.h index e373f06bbd420..5965a4e8cf233 100644 --- a/src/runtime/vm/pooled_allocator.h +++ b/src/runtime/vm/pooled_allocator.h @@ -44,7 +44,7 @@ class PooledAllocator final : public Allocator { ~PooledAllocator() { ReleaseAll(); } - Buffer Alloc(size_t nbytes, size_t alignment, TVMType type_hint) override { + Buffer Alloc(size_t nbytes, size_t alignment, DLDataType type_hint) override { std::lock_guard lock(mu_); size_t size = ((nbytes + page_size_ - 1) / page_size_) * page_size_; auto&& it = memory_pool_.find(size); diff --git a/src/runtime/vm/vm.cc b/src/runtime/vm/vm.cc index 5349a97bd83c8..c5ab1fdb4b62d 100644 --- a/src/runtime/vm/vm.cc +++ b/src/runtime/vm/vm.cc @@ -46,7 +46,7 @@ namespace runtime { namespace vm { -inline Storage make_storage(size_t size, size_t alignment, TVMType dtype_hint, TVMContext ctx) { +inline Storage make_storage(size_t size, size_t alignment, DLDataType dtype_hint, TVMContext ctx) { // We could put cache in here, from ctx to storage allocator. auto storage_obj = SimpleObjAllocator().make_object(); auto alloc = MemoryManager::Global()->GetAllocator(ctx); @@ -336,7 +336,7 @@ Instruction Instruction::AllocTensorReg( Instruction Instruction::AllocStorage(RegName size, Index alignment, - TVMType dtype_hint, + DLDataType dtype_hint, Index dst) { Instruction instr; instr.op = Opcode::AllocStorage; @@ -587,7 +587,7 @@ void InstructionPrint(std::ostream& os, const Instruction& instr) { instr.dst << " $" << instr.alloc_storage.allocation_size << " $" << instr.alloc_storage.alignment << " " << - TVMType2String(instr.alloc_storage.dtype_hint); + DLDataType2String(instr.alloc_storage.dtype_hint); break; } default: @@ -1019,7 +1019,7 @@ void VirtualMachine::RunLoop() { DLOG(INFO) << "AllocStorage: allocation_size=" << size << "alignment=" << alignment << - "dtype_hint=" << TVMType2String(instr.alloc_storage.dtype_hint); + "dtype_hint=" << DLDataType2String(instr.alloc_storage.dtype_hint); auto storage = make_storage(size, alignment, instr.alloc_storage.dtype_hint, ctxs_[0]); WriteRegister(instr.dst, storage); diff --git a/src/runtime/vulkan/vulkan.cc b/src/runtime/vulkan/vulkan.cc index 9ab1d77e05546..6f91b8684660e 100644 --- a/src/runtime/vulkan/vulkan.cc +++ b/src/runtime/vulkan/vulkan.cc @@ -117,7 +117,10 @@ class VulkanDeviceAPI final : public DeviceAPI { } void SetDevice(TVMContext ctx) final { VulkanThreadEntry::ThreadLocal()->ctx = ctx; } void GetAttr(TVMContext ctx, DeviceAttrKind kind, TVMRetValue* rv) final; - void* AllocDataSpace(TVMContext ctx, size_t nbytes, size_t alignment, TVMType type_hint) final { + void* AllocDataSpace(TVMContext ctx, + size_t nbytes, + size_t alignment, + DLDataType type_hint) final { const auto& vctx = context(ctx.device_id); VkBufferCreateInfo info; info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; @@ -194,7 +197,7 @@ class VulkanDeviceAPI final : public DeviceAPI { } void CopyDataFromTo(const void* from, size_t from_offset, void* to, size_t to_offset, size_t size, - TVMContext ctx_from, TVMContext ctx_to, TVMType type_hint, + TVMContext ctx_from, TVMContext ctx_to, DLDataType type_hint, TVMStreamHandle stream) final { CHECK(stream == nullptr); TVMContext ctx = ctx_from; @@ -327,7 +330,7 @@ class VulkanDeviceAPI final : public DeviceAPI { return; } - void* AllocWorkspace(TVMContext ctx, size_t size, TVMType type_hint) final { + void* AllocWorkspace(TVMContext ctx, size_t size, DLDataType type_hint) final { return VulkanThreadEntry::ThreadLocal()->pool.AllocWorkspace(ctx, size); } @@ -772,8 +775,8 @@ class VulkanModuleNode final : public runtime::ModuleNode { { auto fit = fmap_.find(func_name); CHECK(fit != fmap_.end()); - for (TVMType arg_type : fit->second.arg_types) { - if (arg_type.code == kHandle) { + for (DLDataType arg_type : fit->second.arg_types) { + if (arg_type.code == kTVMOpaqueHandle) { { VkDescriptorSetLayoutBinding bd; bd.binding = num_buffer; diff --git a/src/runtime/workspace_pool.cc b/src/runtime/workspace_pool.cc index a32a42a4ef220..fc316cdeded10 100644 --- a/src/runtime/workspace_pool.cc +++ b/src/runtime/workspace_pool.cc @@ -6,9 +6,9 @@ * 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 @@ -47,7 +47,7 @@ class WorkspacePool::Pool { nbytes = (nbytes + (kWorkspacePageSize - 1)) / kWorkspacePageSize * kWorkspacePageSize; if (nbytes == 0) nbytes = kWorkspacePageSize; Entry e; - TVMType type; + DLDataType type; type.code = kDLUInt; type.bits = 8; type.lanes = 1; diff --git a/tests/cpp/packed_func_test.cc b/tests/cpp/packed_func_test.cc index b0e5f2450c4b0..f4f960144be12 100644 --- a/tests/cpp/packed_func_test.cc +++ b/tests/cpp/packed_func_test.cc @@ -30,16 +30,16 @@ TEST(PackedFunc, Basic) { using namespace tvm::runtime; int x = 0; void* handle = &x; - TVMArray a; + DLTensor a; Var v = PackedFunc([&](TVMArgs args, TVMRetValue* rv) { CHECK(args.num_args == 3); CHECK(args.values[0].v_float64 == 1.0); CHECK(args.type_codes[0] == kDLFloat); CHECK(args.values[1].v_handle == &a); - CHECK(args.type_codes[1] == kArrayHandle); + CHECK(args.type_codes[1] == kTVMDLTensorHandle); CHECK(args.values[2].v_handle == &x); - CHECK(args.type_codes[2] == kHandle); + CHECK(args.type_codes[2] == kTVMOpaqueHandle); *rv = Var("a"); })(1.0, &a, handle); CHECK(v->name_hint == "a"); @@ -51,7 +51,7 @@ TEST(PackedFunc, Node) { Var x; Var t = PackedFunc([&](TVMArgs args, TVMRetValue* rv) { CHECK(args.num_args == 1); - CHECK(args.type_codes[0] == kObjectHandle); + CHECK(args.type_codes[0] == kTVMObjectHandle); Var b = args[0]; CHECK(x.same_as(b)); *rv = b; @@ -63,7 +63,7 @@ TEST(PackedFunc, NDArray) { using namespace tvm; using namespace tvm::runtime; auto x = NDArray::Empty( - {}, String2TVMType("float32"), + {}, String2DLDataType("float32"), TVMContext{kDLCPU, 0}); reinterpret_cast(x->data)[0] = 10.0f; CHECK(x.use_count() == 1); @@ -203,25 +203,25 @@ TEST(PackedFunc, ObjectConversion) { using namespace tvm::runtime; TVMRetValue rv; auto x = NDArray::Empty( - {}, String2TVMType("float32"), + {}, String2DLDataType("float32"), TVMContext{kDLCPU, 0}); // assign null rv = ObjectRef(); - CHECK_EQ(rv.type_code(), kNull); + CHECK_EQ(rv.type_code(), kTVMNullptr); // Can assign NDArray to ret type rv = x; - CHECK_EQ(rv.type_code(), kNDArrayContainer); + CHECK_EQ(rv.type_code(), kTVMNDArrayHandle); // Even if we assign base type it still shows as NDArray rv = ObjectRef(x); - CHECK_EQ(rv.type_code(), kNDArrayContainer); + CHECK_EQ(rv.type_code(), kTVMNDArrayHandle); // Check convert back CHECK(rv.operator NDArray().same_as(x)); CHECK(rv.operator ObjectRef().same_as(x)); CHECK(!rv.IsObjectRef()); auto pf1 = PackedFunc([&](TVMArgs args, TVMRetValue* rv) { - CHECK_EQ(args[0].type_code(), kNDArrayContainer); + CHECK_EQ(args[0].type_code(), kTVMNDArrayHandle); CHECK(args[0].operator NDArray().same_as(x)); CHECK(args[0].operator ObjectRef().same_as(x)); CHECK(args[1].operator ObjectRef().get() == nullptr); @@ -238,17 +238,17 @@ TEST(PackedFunc, ObjectConversion) { CHECK(pf != nullptr); Module m = (*pf)("", "xyz"); rv = m; - CHECK_EQ(rv.type_code(), kModuleHandle); + CHECK_EQ(rv.type_code(), kTVMModuleHandle); // Even if we assign base type it still shows as NDArray rv = ObjectRef(m); - CHECK_EQ(rv.type_code(), kModuleHandle); + CHECK_EQ(rv.type_code(), kTVMModuleHandle); // Check convert back CHECK(rv.operator Module().same_as(m)); CHECK(rv.operator ObjectRef().same_as(m)); CHECK(!rv.IsObjectRef()); auto pf2 = PackedFunc([&](TVMArgs args, TVMRetValue* rv) { - CHECK_EQ(args[0].type_code(), kModuleHandle); + CHECK_EQ(args[0].type_code(), kTVMModuleHandle); CHECK(args[0].operator Module().same_as(m)); CHECK(args[0].operator ObjectRef().same_as(m)); CHECK(args[1].operator ObjectRef().get() == nullptr); diff --git a/tests/python/unittest/test_runtime_extension.py b/tests/python/unittest/test_runtime_extension.py index 205e5caadd607..38a7b43761b58 100644 --- a/tests/python/unittest/test_runtime_extension.py +++ b/tests/python/unittest/test_runtime_extension.py @@ -19,7 +19,7 @@ @tvm.register_extension class MyTensorView(object): - _tvm_tcode = tvm.TypeCode.ARRAY_HANDLE + _tvm_tcode = tvm.TypeCode.DLTENSOR_HANDLE def __init__(self, arr): self.arr = arr diff --git a/topi/src/topi.cc b/topi/src/topi.cc index f61ca6e516bcf..21e61cfa4816f 100644 --- a/topi/src/topi.cc +++ b/topi/src/topi.cc @@ -91,7 +91,7 @@ Array ArrayOrInt(TVMArgValue arg) { } inline bool IsTensorType(TVMArgValue arg) { - return (arg.type_code() == kObjectHandle && + return (arg.type_code() == kTVMObjectHandle && static_cast( arg.value().v_handle)->IsInstance()); } diff --git a/vta/src/device_api.cc b/vta/src/device_api.cc index 0c3b3fad2d821..34e3ff0f41fcf 100644 --- a/vta/src/device_api.cc +++ b/vta/src/device_api.cc @@ -45,7 +45,7 @@ class VTADeviceAPI final : public DeviceAPI { void* AllocDataSpace(TVMContext ctx, size_t size, size_t alignment, - TVMType type_hint) final { + DLDataType type_hint) final { return VTABufferAlloc(size); } @@ -60,7 +60,7 @@ class VTADeviceAPI final : public DeviceAPI { size_t size, TVMContext ctx_from, TVMContext ctx_to, - TVMType type_hint, + DLDataType type_hint, TVMStreamHandle stream) final { int kind_mask = 0; if (ctx_from.device_type != kDLCPU) { @@ -77,7 +77,7 @@ class VTADeviceAPI final : public DeviceAPI { void StreamSync(TVMContext ctx, TVMStreamHandle stream) final { } - void* AllocWorkspace(TVMContext ctx, size_t size, TVMType type_hint) final; + void* AllocWorkspace(TVMContext ctx, size_t size, DLDataType type_hint) final; void FreeWorkspace(TVMContext ctx, void* data) final; @@ -93,7 +93,7 @@ struct VTAWorkspacePool : public WorkspacePool { WorkspacePool(kDLExtDev, VTADeviceAPI::Global()) {} }; -void* VTADeviceAPI::AllocWorkspace(TVMContext ctx, size_t size, TVMType type_hint) { +void* VTADeviceAPI::AllocWorkspace(TVMContext ctx, size_t size, DLDataType type_hint) { return dmlc::ThreadLocalStore::Get() ->AllocWorkspace(ctx, size); } diff --git a/web/tvm_runtime.js b/web/tvm_runtime.js index c90587823c9d6..9515a2ec601af 100644 --- a/web/tvm_runtime.js +++ b/web/tvm_runtime.js @@ -95,16 +95,16 @@ var tvm_runtime = tvm_runtime || {}; var kInt = 0; var kUInt = 1; var kFloat = 2; - var kHandle = 3; + var kTVMOpaqueHandle = 3; var kNull = 4; - var kTVMType = 5; + var kTVMDataType = 5; var kTVMContext = 6; - var kArrayHandle = 7; - var kObjectHandle = 8; - var kModuleHandle = 9; - var kFuncHandle = 10; - var kStr = 11; - var kBytes = 12; + var kTVMDLTensorHandle = 7; + var kTVMObjectHandle = 8; + var kTVMModuleHandle = 9; + var kTVMPackedFuncHandle = 10; + var kTVMStr = 11; + var kTVMBytes = 12; //----------------------------------------- // TVM CWrap library // ---------------------------------------- @@ -427,7 +427,7 @@ var tvm_runtime = tvm_runtime || {}; code = kUInt; } else if (pattern.substring(0, 6) == "handle") { pattern = pattern.substring(5, pattern.length); - code = kHandle; + code = kTVMOpaqueHandle; bits = 64; } else { throw throwError("Unknown dtype " + dtype); @@ -453,11 +453,11 @@ var tvm_runtime = tvm_runtime || {}; case kInt: case kUInt: return Module.getValue(vptr, "i64"); case kFloat: return Module.getValue(vptr, "double"); - case kFuncHandle: return makeTVMFunction(Module.getValue(vptr, "*")); - case kModuleHandle: return new TVMModule(Module.getValue(vptr, "*")); + case kTVMPackedFuncHandle: return makeTVMFunction(Module.getValue(vptr, "*")); + case kTVMModuleHandle: return new TVMModule(Module.getValue(vptr, "*")); case kNull: return null; - case kStr: return CStringToJS(Module.getValue(vptr, "*")); - case kBytes: return CBytesToJS(Module.getValue(vptr, "*")); + case kTVMStr: return CStringToJS(Module.getValue(vptr, "*")); + case kTVMBytes: return CBytesToJS(Module.getValue(vptr, "*")); default: throwError("Unsupported return type code=" + tcode); } } @@ -497,9 +497,9 @@ var tvm_runtime = tvm_runtime || {}; for (var i = 0; i < nargs; ++i) { var vptr = arg_value + i * SIZEOF_TVMVALUE; var tcode = Module.getValue(arg_tcode + i * SIZEOF_INT, "i32"); - if (tcode == kObjectHandle || - tcode == kFuncHandle || - tcode == kModuleHandle) { + if (tcode == kTVMObjectHandle || + tcode == kTVMPackedFuncHandle || + tcode == kTVMModuleHandle) { TVM_CALL(TVMCbArgToReturn(vptr, tcode)); } args.push(TVMRetValueToJS(vptr, tcode)); @@ -630,7 +630,7 @@ var tvm_runtime = tvm_runtime || {}; var sdata = new CBuffer(value.length + 1); Module.HEAPU8.set(StringToUint8Array(value), sdata.data); this.temp.push(sdata); - Module.setValue(this.tcode + index * SIZEOF_INT, kStr, "i32"); + Module.setValue(this.tcode + index * SIZEOF_INT, kTVMStr, "i32"); Module.setValue(this.value + index * SIZEOF_TVMVALUE, sdata.data, "*"); }, setBytes : function(index, value) { @@ -642,7 +642,7 @@ var tvm_runtime = tvm_runtime || {}; Module.setValue(sheader.data + SIZEOF_POINTER, value.length, "i32"); this.temp.push(sdata); this.temp.push(sheader); - Module.setValue(this.tcode + index * SIZEOF_INT, kBytes, "i32"); + Module.setValue(this.tcode + index * SIZEOF_INT, kTVMBytes, "i32"); Module.setValue(this.value + index * SIZEOF_TVMVALUE, sheader.data, "*"); }, setArguments : function(args) { @@ -650,7 +650,7 @@ var tvm_runtime = tvm_runtime || {}; var v = args[i]; var tp = typeof v; if (v instanceof NDArray) { - this.setHandle(i, v.handle, kArrayHandle); + this.setHandle(i, v.handle, kTVMDLTensorHandle); } else if (v instanceof TVMConstant) { var code = getTVMType(v.dtype).code; if (code == kInt || code == kUInt) { @@ -658,13 +658,13 @@ var tvm_runtime = tvm_runtime || {}; } else if (code == kFloat) { this.setDouble(i, v.value); } else { - CHECK(code == kHandle); - this.setHandle(i, v.value, kHandle); + CHECK(code == kTVMOpaqueHandle); + this.setHandle(i, v.value, kTVMOpaqueHandle); } } else if (tp == "number") { this.setDouble(i, v); } else if (tp == "function" && v.hasOwnProperty("_tvm_function")) { - this.setString(i, v._tvm_function.handle, kFuncHandle); + this.setString(i, v._tvm_function.handle, kTVMPackedFuncHandle); } else if (v === null) { this.setHandle(i, 0, kNull); } else if (tp == "string") { @@ -674,9 +674,9 @@ var tvm_runtime = tvm_runtime || {}; } else if (v instanceof Function) { v = convertFunc(v); this.temp.push(v); - this.setHandle(i, v._tvm_function.handle, kFuncHandle); + this.setHandle(i, v._tvm_function.handle, kTVMPackedFuncHandle); } else if (v instanceof TVMModule) { - this.setHandle(i, v.handle, kModuleHandle); + this.setHandle(i, v.handle, kTVMModuleHandle); } else { throwError("Unsupported argument type " + tp); }