Skip to content

Commit 076ac23

Browse files
committed
[REFACTOR][FFI][Web] Upgrade Web Runtime to new FFI (apache#17946)
This PR refactors the web runtime to the new FFI protocol. Tested through RPC tests and local tests.
1 parent 296e2f7 commit 076ac23

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

include/tvm/ffi/c_api.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,10 @@ TVM_FFI_DLL int TVMFFIDataTypeFromString(const TVMFFIByteArray* str, DLDataType*
579579
* \return 0 when success, nonzero when failure happens
580580
* \note out is a String object that needs to be freed by the caller via TVMFFIObjectFree.
581581
The content of string can be accessed via TVMFFIObjectGetByteArrayPtr.
582+
583+
* \note The input dtype is a pointer to the DLDataType to avoid ABI compatibility issues.
582584
*/
583-
TVM_FFI_DLL int TVMFFIDataTypeToString(DLDataType dtype, TVMFFIObjectHandle* out);
585+
TVM_FFI_DLL int TVMFFIDataTypeToString(const DLDataType* dtype, TVMFFIObjectHandle* out);
584586

585587
//------------------------------------------------------------
586588
// Section: Backend noexcept functions for internal use

include/tvm/ffi/dtype.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ inline DLDataType StringToDLDataType(const String& str) {
121121

122122
inline String DLDataTypeToString(DLDataType dtype) {
123123
TVMFFIObjectHandle out;
124-
TVM_FFI_CHECK_SAFE_CALL(TVMFFIDataTypeToString(dtype, &out));
124+
TVM_FFI_CHECK_SAFE_CALL(TVMFFIDataTypeToString(&dtype, &out));
125125
return String(details::ObjectUnsafe::ObjectPtrFromOwned<Object>(static_cast<TVMFFIObject*>(out)));
126126
}
127127

include/tvm/ffi/error.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
#define TVM_FFI_BACKTRACE_ON_SEGFAULT 1
5252
#endif
5353

54+
#ifndef TVM_FFI_ALWAYS_LOG_BEFORE_THROW
55+
#define TVM_FFI_ALWAYS_LOG_BEFORE_THROW 0
56+
#endif
57+
5458
namespace tvm {
5559
namespace ffi {
5660

@@ -212,8 +216,10 @@ class ErrorBuilder {
212216
*
213217
* \endcode
214218
*/
215-
#define TVM_FFI_THROW(ErrorKind) \
216-
::tvm::ffi::details::ErrorBuilder(#ErrorKind, TVM_FFI_TRACEBACK_HERE, false).stream()
219+
#define TVM_FFI_THROW(ErrorKind) \
220+
::tvm::ffi::details::ErrorBuilder(#ErrorKind, TVM_FFI_TRACEBACK_HERE, \
221+
TVM_FFI_ALWAYS_LOG_BEFORE_THROW) \
222+
.stream()
217223

218224
/*!
219225
* \brief Explicitly log error in stderr and then throw the error.

src/ffi/dtype.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ int TVMFFIDataTypeFromString(const TVMFFIByteArray* str, DLDataType* out) {
320320
TVM_FFI_SAFE_CALL_END();
321321
}
322322

323-
int TVMFFIDataTypeToString(DLDataType dtype, TVMFFIObjectHandle* out) {
323+
int TVMFFIDataTypeToString(const DLDataType* dtype, TVMFFIObjectHandle* out) {
324324
TVM_FFI_SAFE_CALL_BEGIN();
325-
tvm::ffi::String out_str(tvm::ffi::DLDataTypeToString_(dtype));
325+
tvm::ffi::String out_str(tvm::ffi::DLDataTypeToString_(*dtype));
326326
*out = tvm::ffi::details::ObjectUnsafe::MoveObjectRefToTVMFFIObjectPtr(std::move(out_str));
327327
TVM_FFI_SAFE_CALL_END();
328328
}

0 commit comments

Comments
 (0)