Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ffi/include/tvm/ffi/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,25 @@ TVM_FFI_DLL int TVMFFITensorFromDLPackVersioned(DLManagedTensorVersioned* from,
*/
TVM_FFI_DLL int TVMFFITensorToDLPackVersioned(TVMFFIObjectHandle from,
DLManagedTensorVersioned** out);
//---------------------------------------------------------------
// Section: string/bytes support APIs.
// These APIs are used to simplify the string/bytes construction
//---------------------------------------------------------------
/*!
* \brief Reinterpret the content of TVMFFIByteArray to String.
* \param input The TVMFFIByteArray to convert.
* \param out The output String owned by the caller, maybe a SmallStr or a Str object.
* \return 0 on success, nonzero on failure.
*/
TVM_FFI_DLL int TVMFFIStringFromByteArray(const TVMFFIByteArray* input, TVMFFIAny* out);

/*!
* \brief Reinterpret the content of TVMFFIByteArray to Bytes.
* \param input The TVMFFIByteArray to convert.
* \param out The output Bytes owned by the caller, maybe a SmallBytes or a Bytes object.
* \return 0 on success, nonzero on failure.
*/
TVM_FFI_DLL int TVMFFIBytesFromByteArray(const TVMFFIByteArray* input, TVMFFIAny* out);

//---------------------------------------------------------------
// Section: dtype string support APIs.
Expand Down
2 changes: 1 addition & 1 deletion ffi/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

[project]
name = "apache-tvm-ffi"
version = "0.1.0a12"
version = "0.1.0a13"
description = "tvm ffi"

authors = [{ name = "TVM FFI team" }]
Expand Down
11 changes: 2 additions & 9 deletions ffi/python/tvm_ffi/_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ def convert(value: Any) -> Any:
automatically converted. So this function is mainly
only used in internal or testing scenarios.
"""
if isinstance(value, core.Object):
if isinstance(value, (core.Object, core.PyNativeObject, bool, Number)):
return value
elif isinstance(value, core.PyNativeObject):
return value
elif isinstance(value, (bool, Number)):
return value
elif isinstance(value, (list, tuple)):
elif isinstance(value, (tuple, list)):
return container.Array(value)
elif isinstance(value, dict):
return container.Map(value)
Expand All @@ -67,6 +63,3 @@ def convert(value: Any) -> Any:
else:
# in this case, it is an opaque python object
return core._convert_to_opaque_object(value)


core._set_func_convert_to_object(convert)
1 change: 0 additions & 1 deletion ffi/python/tvm_ffi/_optional_torch_c_dlpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ def load_torch_c_dlpack_extension():
],
extra_cflags=["-O3"],
extra_include_paths=libinfo.include_paths() + cpp_extension.include_paths("cuda"),
verbose=True,
)
# set the dlpack related flags
torch.Tensor.__c_dlpack_from_pyobject__ = mod.TorchDLPackFromPyObjectPtr()
Expand Down
11 changes: 11 additions & 0 deletions ffi/python/tvm_ffi/cython/base.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ cdef extern from "tvm/ffi/c_api.h":
TVMFFIByteArray* traceback) nogil

int TVMFFITypeKeyToIndex(TVMFFIByteArray* type_key, int32_t* out_tindex) nogil
int TVMFFIStringFromByteArray(TVMFFIByteArray* input_, TVMFFIAny* out) nogil
int TVMFFIBytesFromByteArray(TVMFFIByteArray* input_, TVMFFIAny* out) nogil
int TVMFFIDataTypeFromString(TVMFFIByteArray* str, DLDataType* out) nogil
int TVMFFIDataTypeToString(const DLDataType* dtype, TVMFFIAny* out) nogil
const TVMFFIByteArray* TVMFFITraceback(
Expand Down Expand Up @@ -284,6 +286,15 @@ cdef extern from "tvm_ffi_python_helpers.h":
DLPackToPyObject* out_dlpack_importer
) except -1

int TVMFFIPyConstructorCall(
TVMFFIPyArgSetterFactory setter_factory,
void* chandle,
PyObject* py_arg_tuple,
TVMFFIAny* result,
int* c_api_ret_code,
TVMFFIPyCallContext* parent_ctx
) except -1

int TVMFFIPyCallFieldSetter(
TVMFFIPyArgSetterFactory setter_factory,
TVMFFIFieldSetter field_setter,
Expand Down
Loading
Loading