33using System . Runtime . InteropServices ;
44using Tensorflow . Device ;
55using Tensorflow . Eager ;
6+ using Tensorflow . Util ;
67
78namespace Tensorflow
89{
@@ -66,7 +67,7 @@ public partial class c_api
6667 /// <param name="status">TF_Status*</param>
6768 /// <returns></returns>
6869 [ DllImport ( TensorFlowLibName ) ]
69- public static extern int TFE_OpAddInputList ( SafeOpHandle op , IntPtr [ ] inputs , int num_inputs , SafeStatusHandle status ) ;
70+ public static extern int TFE_OpAddInputList ( SafeOpHandle op , [ In , MarshalAs ( UnmanagedType . CustomMarshaler , MarshalTypeRef = typeof ( SafeHandleArrayMarshaler ) ) ] SafeTensorHandleHandle [ ] inputs , int num_inputs , SafeStatusHandle status ) ;
7071
7172 /// <summary>
7273 ///
@@ -90,6 +91,20 @@ public partial class c_api
9091 [ DllImport ( TensorFlowLibName ) ]
9192 public static extern void TFE_DeleteContext ( IntPtr ctx ) ;
9293
94+ public static void TFE_Execute ( SafeOpHandle op , SafeTensorHandleHandle [ ] retvals , out int num_retvals , SafeStatusHandle status )
95+ {
96+ unsafe
97+ {
98+ num_retvals = retvals ? . Length ?? 0 ;
99+ var rawReturns = stackalloc IntPtr [ num_retvals ] ;
100+ TFE_Execute ( op , rawReturns , ref num_retvals , status ) ;
101+ for ( var i = 0 ; i < num_retvals ; i ++ )
102+ {
103+ retvals [ i ] = new SafeTensorHandleHandle ( rawReturns [ i ] ) ;
104+ }
105+ }
106+ }
107+
93108 /// <summary>
94109 /// Execute the operation defined by 'op' and return handles to computed
95110 /// tensors in `retvals`.
@@ -99,7 +114,7 @@ public partial class c_api
99114 /// <param name="num_retvals">int*</param>
100115 /// <param name="status">TF_Status*</param>
101116 [ DllImport ( TensorFlowLibName ) ]
102- public static extern void TFE_Execute ( SafeOpHandle op , IntPtr [ ] retvals , ref int num_retvals , SafeStatusHandle status ) ;
117+ private static unsafe extern void TFE_Execute ( SafeOpHandle op , IntPtr * retvals , ref int num_retvals , SafeStatusHandle status ) ;
103118
104119 /// <summary>
105120 ///
@@ -198,18 +213,18 @@ public partial class c_api
198213 /// <param name="h">TFE_TensorHandle*</param>
199214 /// <param name="status">TF_Status*</param>
200215 [ DllImport ( TensorFlowLibName ) ]
201- public static extern void TFE_OpAddInput ( SafeOpHandle op , IntPtr h , SafeStatusHandle status ) ;
216+ public static extern void TFE_OpAddInput ( SafeOpHandle op , SafeTensorHandleHandle h , SafeStatusHandle status ) ;
202217
203218 /// <summary>
204219 ///
205220 /// </summary>
206221 /// <param name="t">const tensorflow::Tensor&</param>
207222 /// <returns>TFE_TensorHandle*</returns>
208223 [ DllImport ( TensorFlowLibName ) ]
209- public static extern TFE_TensorHandle TFE_NewTensorHandle ( IntPtr t , SafeStatusHandle status ) ;
224+ public static extern SafeTensorHandleHandle TFE_NewTensorHandle ( IntPtr t , SafeStatusHandle status ) ;
210225
211226 [ DllImport ( TensorFlowLibName ) ]
212- public static extern IntPtr TFE_EagerTensorHandle ( IntPtr t ) ;
227+ public static extern SafeTensorHandleHandle TFE_EagerTensorHandle ( IntPtr t ) ;
213228
214229 /// <summary>
215230 /// Sets the default execution mode (sync/async). Note that this can be
@@ -226,7 +241,7 @@ public partial class c_api
226241 /// <param name="h">TFE_TensorHandle*</param>
227242 /// <returns></returns>
228243 [ DllImport ( TensorFlowLibName ) ]
229- public static extern TF_DataType TFE_TensorHandleDataType ( IntPtr h ) ;
244+ public static extern TF_DataType TFE_TensorHandleDataType ( SafeTensorHandleHandle h ) ;
230245
231246 /// <summary>
232247 /// This function will block till the operation that produces `h` has
@@ -237,7 +252,7 @@ public partial class c_api
237252 /// <param name="status">TF_Status*</param>
238253 /// <returns></returns>
239254 [ DllImport ( TensorFlowLibName ) ]
240- public static extern IntPtr TFE_TensorHandleResolve ( IntPtr h , SafeStatusHandle status ) ;
255+ public static extern IntPtr TFE_TensorHandleResolve ( SafeTensorHandleHandle h , SafeStatusHandle status ) ;
241256
242257
243258 /// <summary>
@@ -247,10 +262,10 @@ public partial class c_api
247262 /// <param name="status">TF_Status*</param>
248263 /// <returns></returns>
249264 [ DllImport ( TensorFlowLibName ) ]
250- public static extern int TFE_TensorHandleNumDims ( IntPtr h , SafeStatusHandle status ) ;
265+ public static extern int TFE_TensorHandleNumDims ( SafeTensorHandleHandle h , SafeStatusHandle status ) ;
251266
252267 [ DllImport ( TensorFlowLibName ) ]
253- public static extern int TFE_TensorHandleDim ( IntPtr h , int dim , SafeStatusHandle status ) ;
268+ public static extern int TFE_TensorHandleDim ( SafeTensorHandleHandle h , int dim , SafeStatusHandle status ) ;
254269
255270 /// <summary>
256271 /// Returns the device of the operation that produced `h`. If `h` was produced by
@@ -263,7 +278,7 @@ public partial class c_api
263278 /// <param name="status">TF_Status*</param>
264279 /// <returns></returns>
265280 [ DllImport ( TensorFlowLibName ) ]
266- public static extern IntPtr TFE_TensorHandleDeviceName ( IntPtr h , SafeStatusHandle status ) ;
281+ public static extern IntPtr TFE_TensorHandleDeviceName ( SafeTensorHandleHandle h , SafeStatusHandle status ) ;
267282
268283 /// <summary>
269284 /// Returns the name of the device in whose memory `h` resides.
@@ -272,7 +287,7 @@ public partial class c_api
272287 /// <param name="status">TF_Status*</param>
273288 /// <returns></returns>
274289 [ DllImport ( TensorFlowLibName ) ]
275- public static extern IntPtr TFE_TensorHandleBackingDeviceName ( IntPtr h , SafeStatusHandle status ) ;
290+ public static extern IntPtr TFE_TensorHandleBackingDeviceName ( SafeTensorHandleHandle h , SafeStatusHandle status ) ;
276291
277292 /// <summary>
278293 ///
0 commit comments