From 4bc66027e23a559ba2a4faa5b98c7a0a4ffeb742 Mon Sep 17 00:00:00 2001 From: Meinrad Recheis Date: Sat, 13 Jul 2019 16:33:12 +0200 Subject: [PATCH] c_api: TF_NewTensor now allows pinned managed objects to be passed down to TF (needed different deallocator arg type) --- src/TensorFlowNET.Core/APIs/c_api.cs | 8 +++++++- src/TensorFlowNET.Core/Tensors/c_api.tensor.cs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/TensorFlowNET.Core/APIs/c_api.cs b/src/TensorFlowNET.Core/APIs/c_api.cs index 7b7ade95..1595e128 100644 --- a/src/TensorFlowNET.Core/APIs/c_api.cs +++ b/src/TensorFlowNET.Core/APIs/c_api.cs @@ -53,7 +53,13 @@ namespace Tensorflow return handle == IntPtr.Zero ? String.Empty : Marshal.PtrToStringAnsi(handle); } - public delegate void Deallocator(IntPtr data, IntPtr size, ref bool deallocator); + public delegate void Deallocator(IntPtr data, IntPtr size, ref DeallocatorArgs args); + + public struct DeallocatorArgs + { + public bool deallocator_called; + public IntPtr gc_handle; + } [DllImport(TensorFlowLibName)] public static unsafe extern IntPtr TF_Version(); diff --git a/src/TensorFlowNET.Core/Tensors/c_api.tensor.cs b/src/TensorFlowNET.Core/Tensors/c_api.tensor.cs index ea8f715a..b9735dfb 100644 --- a/src/TensorFlowNET.Core/Tensors/c_api.tensor.cs +++ b/src/TensorFlowNET.Core/Tensors/c_api.tensor.cs @@ -71,7 +71,7 @@ namespace Tensorflow /// /// [DllImport(TensorFlowLibName)] - public static extern IntPtr TF_NewTensor(TF_DataType dataType, long[] dims, int num_dims, IntPtr data, UIntPtr len, Deallocator deallocator, ref bool deallocator_arg); + public static extern IntPtr TF_NewTensor(TF_DataType dataType, long[] dims, int num_dims, IntPtr data, UIntPtr len, Deallocator deallocator, ref DeallocatorArgs deallocator_arg); /// /// Return the number of dimensions that the tensor has.