Browse Source

Implement SafeResourceVariableHandle as a wrapper for TFE_ResourceVariable

tags/v0.20
Sam Harwell Esther Hu 5 years ago
parent
commit
028b97734d
2 changed files with 44 additions and 5 deletions
  1. +40
    -0
      src/TensorFlowNET.Core/Variables/SafeResourceVariableHandle.cs
  2. +4
    -5
      src/TensorFlowNET.Core/Variables/c_api.variable.cs

+ 40
- 0
src/TensorFlowNET.Core/Variables/SafeResourceVariableHandle.cs View File

@@ -0,0 +1,40 @@
/*****************************************************************************
Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
******************************************************************************/

using System;
using Tensorflow.Util;

namespace Tensorflow.Variables
{
public sealed class SafeResourceVariableHandle : SafeTensorflowHandle
{
private SafeResourceVariableHandle()
{
}

public SafeResourceVariableHandle(IntPtr handle)
: base(handle)
{
}

protected override bool ReleaseHandle()
{
c_api.TFE_DeleteResourceVariable(handle);
SetHandle(IntPtr.Zero);
return true;
}
}
}

+ 4
- 5
src/TensorFlowNET.Core/Variables/c_api.variable.cs View File

@@ -1,22 +1,21 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Tensorflow.Variables;

namespace Tensorflow
{
public partial class c_api
{
[DllImport(TensorFlowLibName)]
public static extern IntPtr TFE_NewResourceVariable();
public static extern SafeResourceVariableHandle TFE_NewResourceVariable();

[DllImport(TensorFlowLibName)]
public static extern void TFE_DeleteResourceVariable(IntPtr variable);

[DllImport(TensorFlowLibName)]
public static extern void TFE_SetResourceVariableHandle(IntPtr variable, IntPtr tensor);
public static extern void TFE_SetResourceVariableHandle(SafeResourceVariableHandle variable, IntPtr tensor);

[DllImport(TensorFlowLibName)]
public static extern void TFE_SetResourceVariableName(IntPtr variable, string name);
public static extern void TFE_SetResourceVariableName(SafeResourceVariableHandle variable, string name);
}
}

Loading…
Cancel
Save