Hi! there.
I met a problem in MXTVMBridge
function of MXNet. The problem of ABI compatibility in MXTVMBridge
Then I wrote a minimum reproducible example to test MXTVMBridge
.
In this example, tvm_packed_func.h
is simplyfied from TVM.
Steps to reproduce
- clone the example
- change the path of libmxnet.so in the line 55 of the code.
- make
- ./test
The example works when MXNet is built from source by myself, but it doesn’t work when MXNet is installed by PIP.
@tqchen said:
Because the bridge uses c++ std::function, it requires a common ABI between the two in order to make things work, so build from source is indeed the best way
Sometimes other programs will call PackedFunc
of TVM, so it is unavoidable to meet the problem of ABI compatibility.
Is it possible to provide an API in TVM like this?
It may be available to avoid the problem of ABI compatibility. : )
In include/tvm/runtime/packed_func.h
,
class PackedFunc {
public:
using FType = std::function<void(TVMArgs args, TVMRetValue* rv)>;
PackedFunc() {
SetRemoteCallPacked();
};
explicit PackedFunc(FType body) : body_(body) {
SetRemoteCallPacked();
}
void CallPacked(TVMArgs args, TVMRetValue* rv) const {
_RemoteCallPacked(this, args, rv);
}
template <typename... Args>
inline TVMRetValue operator()(Args&&... args) const {
const int kNumArgs = sizeof...(Args);
const int kArraySize = kNumArgs > 0 ? kNumArgs : 1;
TVMValue values[kArraySize];
int type_codes[kArraySize];
detail::for_each(TVMArgsSetter(values, type_codes),
std::forward<Args>(args)...);
TVMRetValue rv;
_RemoteCallPacked(this, TVMArgs(values, type_codes, kNumArgs), &rv);
return rv;
}
private:
void SetRemoteCallPacked() {
_RemoteCallPacked = [](const PackedFunc* func, TVMArgs args, TVMRetValue* rv) {
func->body_(args, rv);
};
}
void (*_RemoteCallPacked)(const PackedFunc* func, TVMArgs args, TVMRetValue* rv);
private:
FType body_;
...
};
Thanks!