@@ -30,6 +30,7 @@ namespace Tensorflow
30
30
public class BaseSession : DisposableObject
31
31
{
32
32
protected Graph _graph ;
33
+ protected Status _status ;
33
34
public Graph graph => _graph ;
34
35
35
36
public BaseSession ( IntPtr handle , Graph g )
@@ -48,9 +49,9 @@ public BaseSession(string target = "", Graph g = null, ConfigProto config = null
48
49
}
49
50
50
51
using var opts = new SessionOptions ( target , config ) ;
51
- status = status ?? tf . Status ;
52
- _handle = c_api . TF_NewSession ( _graph , opts . Handle , status . Handle ) ;
53
- status . Check ( true ) ;
52
+ _status = status ?? tf . Status ;
53
+ _handle = c_api . TF_NewSession ( _graph , opts . Handle , _status . Handle ) ;
54
+ _status . Check ( true ) ;
54
55
}
55
56
56
57
public virtual void run ( Operation op , params FeedItem [ ] feed_dict )
@@ -217,8 +218,6 @@ private unsafe NDArray[] _call_tf_sessionrun(KeyValuePair<TF_Output, Tensor>[] f
217
218
// Ensure any changes to the graph are reflected in the runtime.
218
219
_extend_graph ( ) ;
219
220
220
- var status = tf . Status ;
221
-
222
221
var output_values = fetch_list . Select ( x => IntPtr . Zero ) . ToArray ( ) ;
223
222
224
223
c_api . TF_SessionRun ( _handle ,
@@ -232,9 +231,9 @@ private unsafe NDArray[] _call_tf_sessionrun(KeyValuePair<TF_Output, Tensor>[] f
232
231
target_opers : target_list . Select ( f => ( IntPtr ) f ) . ToArray ( ) ,
233
232
ntargets : target_list . Count ,
234
233
run_metadata : IntPtr . Zero ,
235
- status : status . Handle ) ;
234
+ status : _status . Handle ) ;
236
235
237
- status . Check ( true ) ;
236
+ _status . Check ( true ) ;
238
237
239
238
var result = new NDArray [ fetch_list . Length ] ;
240
239
@@ -246,8 +245,6 @@ private unsafe NDArray[] _call_tf_sessionrun(KeyValuePair<TF_Output, Tensor>[] f
246
245
247
246
public unsafe Tensor eval ( Tensor tensor )
248
247
{
249
- var status = tf . Status ;
250
-
251
248
var output_values = new IntPtr [ 1 ] ;
252
249
var fetch_list = new [ ] { tensor . _as_tf_output ( ) } ;
253
250
@@ -262,9 +259,9 @@ public unsafe Tensor eval(Tensor tensor)
262
259
target_opers : new IntPtr [ 0 ] ,
263
260
ntargets : 0 ,
264
261
run_metadata : IntPtr . Zero ,
265
- status : status . Handle ) ;
262
+ status : _status . Handle ) ;
266
263
267
- status . Check ( true ) ;
264
+ _status . Check ( true ) ;
268
265
269
266
return new Tensor ( new SafeTensorHandle ( output_values [ 0 ] ) ) ;
270
267
}
@@ -291,15 +288,7 @@ private void _extend_graph()
291
288
protected override void DisposeUnmanagedResources ( IntPtr handle )
292
289
{
293
290
// c_api.TF_CloseSession(handle, tf.Status.Handle);
294
- if ( tf . Status == null || tf . Status . Handle . IsInvalid )
295
- {
296
- using var status = new Status ( ) ;
297
- c_api . TF_DeleteSession ( handle , status . Handle ) ;
298
- }
299
- else
300
- {
301
- c_api . TF_DeleteSession ( handle , tf . Status . Handle ) ;
302
- }
291
+ c_api . TF_DeleteSession ( handle , _status . Handle ) ;
303
292
}
304
293
}
305
294
}
0 commit comments