@@ -1624,34 +1624,6 @@ def __tvm_ffi_env_stream__(self) -> int:
16241624 "Currently, the __tvm_ffi_env_stream__ method is only supported for GPU tensors."
16251625 )
16261626
1627- def _get_c_dlpack_exchange_api ():
1628- """
1629- Returns the C DLPack exchange API pointer for the current tensor.
1630- This is used for interoperability with other libraries that support DLPack.
1631-
1632- In tvm ffi 0.1.3 or below, this API returns the pointer directly.
1633- In newer versions, it returns a python capsule containing the pointer.
1634- """
1635- try :
1636- import tvm_ffi
1637-
1638- tvm_ffi_version = tuple (
1639- int (x ) for x in tvm_ffi .__version__ .split ("." )
1640- )
1641- # We assume version format is like '0.1.3'.
1642- # All supported releases are '0.1.0', '0.1.1', '0.1.2', '0.1.3'.
1643- # We simply assume user will not use beta/rc versions here.
1644- # TODO(dev): We should cleanup this after tvm ffi 0.1.3 is not supported.
1645- if tvm_ffi_version <= (0 , 1 , 3 ):
1646- return core .dlpack_exchange_api_ptr ()
1647- except Exception :
1648- pass
1649- # For tvm ffi 0.1.4 only, in tvm ffi 0.1.5+, replaced by `__dlpack_c_exchange_api__`
1650- return core .dlpack_exchange_api_pycapsule ()
1651-
1652- if not hasattr (core , "eager" ):
1653- return
1654-
16551627 for method_name , method in (
16561628 ("__bool__" , __bool__ ),
16571629 ("__nonzero__" , __nonzero__ ),
@@ -1698,8 +1670,9 @@ def _get_c_dlpack_exchange_api():
16981670 ("__dlpack_device__" , __dlpack_device__ ),
16991671 ("get_device" , get_device ),
17001672 ("__tvm_ffi_env_stream__" , __tvm_ffi_env_stream__ ),
1701- # For TVM FFI 0.1.0-0.1.4, replaced by `__dlpack_c_exchange_api__` in TVM FFI 0.1.5+
1702- ("__c_dlpack_exchange_api__" , _get_c_dlpack_exchange_api ()),
1673+ # For TVM FFI 0.1.0-0.1.4
1674+ ("__c_dlpack_exchange_api__" , core .dlpack_exchange_api_ptr ()),
1675+ # For TVM FFI 0.1.5+
17031676 ("__dlpack_c_exchange_api__" , core .dlpack_exchange_api_pycapsule ()),
17041677 ("device" , device ),
17051678 ):
0 commit comments