@@ -47,13 +47,13 @@ cdef inline object make_ret_small_bytes(TVMFFIAny result):
4747 return PyBytes_FromStringAndSize(bytes.data, bytes.size)
4848
4949
50- cdef inline object make_ret(TVMFFIAny result, DLPackPyObjectImporter c_dlpack_importer = NULL ):
50+ cdef inline object make_ret(TVMFFIAny result, DLPackToPyObject c_dlpack_to_pyobject = NULL ):
5151 """ convert result to return value."""
5252 cdef int32_t type_index
5353 type_index = result.type_index
5454 if type_index == kTVMFFITensor:
5555 # specially handle Tensor as it needs a special dltensor field
56- return make_tensor_from_any(result, c_dlpack_importer )
56+ return make_tensor_from_any(result, c_dlpack_to_pyobject )
5757 elif type_index == kTVMFFIOpaquePyObject:
5858 return make_ret_opaque_object(result)
5959 elif type_index >= kTVMFFIStaticObjectBegin:
@@ -121,18 +121,18 @@ cdef int TVMFFIPyArgSetterDLPackCExporter_(
121121 cdef TVMFFIObjectHandle temp_chandle
122122 cdef TVMFFIStreamHandle env_stream = NULL
123123
124- if this.c_dlpack_importer != NULL :
125- ctx.c_dlpack_importer = this.c_dlpack_importer
124+ if this.c_dlpack_to_pyobject != NULL :
125+ ctx.c_dlpack_to_pyobject = this.c_dlpack_to_pyobject
126126 if this.c_dlpack_tensor_allocator != NULL :
127127 ctx.c_dlpack_tensor_allocator = this.c_dlpack_tensor_allocator
128128
129129 if ctx.device_id != - 1 :
130130 # already queried device, do not do it again, pass NULL to stream
131- if (this.c_dlpack_exporter )(arg, & temp_managed_tensor, NULL ) != 0 :
131+ if (this.c_dlpack_from_pyobject )(arg, & temp_managed_tensor, NULL ) != 0 :
132132 return - 1
133133 else :
134134 # query string on the envrionment stream
135- if (this.c_dlpack_exporter )(arg, & temp_managed_tensor, & env_stream) != 0 :
135+ if (this.c_dlpack_from_pyobject )(arg, & temp_managed_tensor, & env_stream) != 0 :
136136 return - 1
137137 # If device is not CPU, we should set the device type and id
138138 if temp_managed_tensor.dl_tensor.device.device_type != kDLCPU:
@@ -148,7 +148,7 @@ cdef int TVMFFIPyArgSetterDLPackCExporter_(
148148 return 0
149149
150150
151- cdef int TorchDLPackPyObjectImporterFallback_ (
151+ cdef int TorchDLPackToPyObjectFallback_ (
152152 DLManagedTensorVersioned* dltensor, void ** py_obj_out
153153) except - 1 :
154154 # a bit convoluted but ok as a fallback
@@ -173,7 +173,7 @@ cdef int TVMFFIPyArgSetterTorchFallback_(
173173 out.type_index = kTVMFFITensor
174174 out.v_ptr = (< Tensor> arg).chandle
175175 temp_dltensor = TVMFFITensorGetDLTensorPtr((< Tensor> arg).chandle)
176- ctx.c_dlpack_importer = TorchDLPackPyObjectImporterFallback_
176+ ctx.c_dlpack_to_pyobject = TorchDLPackToPyObjectFallback_
177177 # record the stream and device for torch context
178178 if is_cuda and ctx.device_type != - 1 :
179179 ctx.device_type = temp_dltensor.device.device_type
@@ -370,15 +370,15 @@ cdef int TVMFFIPyArgSetterFactory_(PyObject* value, TVMFFIPyArgSetter* out) exce
370370 if isinstance (arg, ObjectRValueRef):
371371 out.func = TVMFFIPyArgSetterObjectRValueRef_
372372 return 0
373- if os.environ.get(" TVM_FFI_SKIP_C_DLPACK_EXPORTER " , " 0" ) != " 1" :
373+ if os.environ.get(" TVM_FFI_SKIP_c_dlpack_from_pyobject " , " 0" ) != " 1" :
374374 # external tensors
375- if hasattr (arg, " __c_dlpack_exporter__ " ):
375+ if hasattr (arg, " __c_dlpack_from_pyobject__ " ):
376376 out.func = TVMFFIPyArgSetterDLPackCExporter_
377- temp_ptr = arg.__c_dlpack_exporter__
378- out.c_dlpack_exporter = < DLPackPyObjectExporter > temp_ptr
379- if hasattr (arg, " __c_dlpack_importer__ " ):
380- temp_ptr = arg.__c_dlpack_importer__
381- out.c_dlpack_importer = < DLPackPyObjectImporter > temp_ptr
377+ temp_ptr = arg.__c_dlpack_from_pyobject__
378+ out.c_dlpack_from_pyobject = < DLPackFromPyObject > temp_ptr
379+ if hasattr (arg, " __c_dlpack_to_pyobject__ " ):
380+ temp_ptr = arg.__c_dlpack_to_pyobject__
381+ out.c_dlpack_to_pyobject = < DLPackToPyObject > temp_ptr
382382 if hasattr (arg, " __c_dlpack_tensor_allocator__" ):
383383 temp_ptr = arg.__c_dlpack_tensor_allocator__
384384 out.c_dlpack_tensor_allocator = < DLPackTensorAllocator> temp_ptr
@@ -470,7 +470,7 @@ cdef class Function(Object):
470470 def __call__ (self , *args ):
471471 cdef TVMFFIAny result
472472 cdef int c_api_ret_code
473- cdef DLPackPyObjectImporter c_dlpack_importer = NULL
473+ cdef DLPackToPyObject c_dlpack_to_pyobject = NULL
474474 # IMPORTANT: caller need to initialize result->type_index to kTVMFFINone
475475 result.type_index = kTVMFFINone
476476 result.v_int64 = 0
@@ -480,12 +480,12 @@ cdef class Function(Object):
480480 & result,
481481 & c_api_ret_code,
482482 self .release_gil,
483- & c_dlpack_importer
483+ & c_dlpack_to_pyobject
484484 )
485485 # NOTE: logic is same as check_call
486486 # directly inline here to simplify traceback
487487 if c_api_ret_code == 0 :
488- return make_ret(result, c_dlpack_importer )
488+ return make_ret(result, c_dlpack_to_pyobject )
489489 elif c_api_ret_code == - 2 :
490490 raise_existing_error()
491491 raise move_from_last_error().py_error()
0 commit comments