我正在向 XLA 编写一个纯 C FFI 层,并希望返回一个指向 的指针GlobalData
,由xla::LocalClient.TransferToServer(...)
. 我试图GlobalData
在免费商店创建一个新的,因为源代码中的评论说
// Unregisters the wrapped handle, which causes the service to
// deallocate the associated data.
~GlobalData();
我还释放了堆栈副本的句柄,如
xla::GlobalData* fn(xla::LocalClient* client, xla::Literal literal) {
std::unique_ptr<xla::GlobalData> global_data =
client.TransferToServer(literal).ConsumeValueOrDie();
xla::GlobalData* global_data_non_stack =
new xla::GlobalData(client.stub(), global_data->handle());
std::vector<std::unique_ptr<xla::GlobalData>> to_release;
to_release.push_back(std::move(global_data));
xla::GlobalData::Release(std::move(to_release));
return global_data_non_stack;
}
但它不起作用。它似乎仍在释放句柄,所以当client.ExecuteAndTransfer(...)
我看到
2022-01-09 13:42:23.862961: F tensorflow/core/platform/statusor.cc:33] Attempting to fetch value instead of handling error Invalid argument: global data handle 1 was previously deallocated, failed to resolve allocation for parameter 0
我也试过client.Unregister(*global_data)
没有帮助。