Browse Source

Use leases to ensure handles are not released before calling StringPiece

pull/582/head
Sam Harwell 5 years ago
parent
commit
f59578a412
2 changed files with 18 additions and 8 deletions
  1. +9
    -3
      src/TensorFlowNET.Core/Eager/EagerTensor.cs
  2. +9
    -5
      src/TensorFlowNET.Core/Tensors/EagerTensorV2.cs

+ 9
- 3
src/TensorFlowNET.Core/Eager/EagerTensor.cs View File

@@ -1,15 +1,21 @@
using NumSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tensorflow.Util;
using static Tensorflow.Binding;

namespace Tensorflow.Eager
{
public partial class EagerTensor : Tensor
{
public override string Device => c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(EagerTensorHandle, tf.status.Handle));
public override string Device
{
get
{
using var _ = EagerTensorHandle.Lease();
return c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(EagerTensorHandle, tf.status.Handle));
}
}

public override int rank => c_api.TFE_TensorHandleNumDims(EagerTensorHandle, tf.status.Handle);



+ 9
- 5
src/TensorFlowNET.Core/Tensors/EagerTensorV2.cs View File

@@ -1,11 +1,8 @@
using NumSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using Tensorflow.Eager;
using Tensorflow.Util;
using static Tensorflow.Binding;

namespace Tensorflow
@@ -13,7 +10,14 @@ namespace Tensorflow
public class EagerTensorV2 : DisposableObject, ITensor
{
SafeTensorHandleHandle EagerTensorHandle;
public string Device => c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(EagerTensorHandle, tf.status.Handle));
public string Device
{
get
{
using var _ = EagerTensorHandle.Lease();
return c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(EagerTensorHandle, tf.status.Handle));
}
}

public EagerTensorV2(IntPtr handle)
{


Loading…
Cancel
Save