Implement SafeStatusHandletags/v0.20
| @@ -32,7 +32,7 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern TF_AttrMetadata TF_OperationGetAttrMetadata(IntPtr oper, string attr_name, IntPtr status); | |||||
| public static extern TF_AttrMetadata TF_OperationGetAttrMetadata(IntPtr oper, string attr_name, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Fills in `value` with the value of the attribute `attr_name`. `value` must | /// Fills in `value` with the value of the attribute `attr_name`. `value` must | ||||
| @@ -46,7 +46,7 @@ namespace Tensorflow | |||||
| /// <param name="max_length">size_t</param> | /// <param name="max_length">size_t</param> | ||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_OperationGetAttrString(IntPtr oper, string attr_name, IntPtr value, uint max_length, IntPtr status); | |||||
| public static extern void TF_OperationGetAttrString(IntPtr oper, string attr_name, IntPtr value, uint max_length, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Sets `output_attr_value` to the binary-serialized AttrValue proto | /// Sets `output_attr_value` to the binary-serialized AttrValue proto | ||||
| @@ -55,13 +55,13 @@ namespace Tensorflow | |||||
| /// <param name="oper"></param> | /// <param name="oper"></param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern int TF_OperationGetAttrValueProto(IntPtr oper, string attr_name, IntPtr output_attr_value, IntPtr status); | |||||
| public static extern int TF_OperationGetAttrValueProto(IntPtr oper, string attr_name, IntPtr output_attr_value, SafeStatusHandle status); | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_SetAttrBool(IntPtr desc, string attr_name, bool value); | public static extern void TF_SetAttrBool(IntPtr desc, string attr_name, bool value); | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_SetAttrValueProto(IntPtr desc, string attr_name, IntPtr proto, uint proto_len, IntPtr status); | |||||
| public static extern void TF_SetAttrValueProto(IntPtr desc, string attr_name, IntPtr proto, uint proto_len, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Set `num_dims` to -1 to represent "unknown rank". | /// Set `num_dims` to -1 to represent "unknown rank". | ||||
| @@ -99,7 +99,7 @@ namespace Tensorflow | |||||
| public static extern void TF_SetAttrStringList(IntPtr desc, string attr_name, IntPtr[] values, uint[] lengths, int num_values); | public static extern void TF_SetAttrStringList(IntPtr desc, string attr_name, IntPtr[] values, uint[] lengths, int num_values); | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_SetAttrTensor(IntPtr desc, string attr_name, IntPtr value, IntPtr status); | |||||
| public static extern void TF_SetAttrTensor(IntPtr desc, string attr_name, IntPtr value, SafeStatusHandle status); | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_SetAttrType(IntPtr desc, string attr_name, TF_DataType value); | public static extern void TF_SetAttrType(IntPtr desc, string attr_name, TF_DataType value); | ||||
| @@ -45,7 +45,7 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TF_DeviceListType(IntPtr list, int index, IntPtr status); | |||||
| public static extern IntPtr TF_DeviceListType(IntPtr list, int index, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Deallocates the device list. | /// Deallocates the device list. | ||||
| @@ -64,7 +64,7 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns>TFE_TensorHandle*</returns> | /// <returns>TFE_TensorHandle*</returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TFE_TensorHandleCopyToDevice(IntPtr h, IntPtr ctx, string device_name, IntPtr status); | |||||
| public static extern IntPtr TFE_TensorHandleCopyToDevice(IntPtr h, IntPtr ctx, string device_name, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Retrieves the full name of the device (e.g. /job:worker/replica:0/...) | /// Retrieves the full name of the device (e.g. /job:worker/replica:0/...) | ||||
| @@ -76,6 +76,6 @@ namespace Tensorflow | |||||
| /// <param name="index"></param> | /// <param name="index"></param> | ||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TF_DeviceListName(IntPtr list, int index, IntPtr status); | |||||
| public static extern IntPtr TF_DeviceListName(IntPtr list, int index, SafeStatusHandle status); | |||||
| } | } | ||||
| } | } | ||||
| @@ -14,7 +14,7 @@ namespace Tensorflow.Eager | |||||
| public Context(ContextOptions opts, Status status) | public Context(ContextOptions opts, Status status) | ||||
| { | { | ||||
| _handle = c_api.TFE_NewContext(opts, status); | |||||
| _handle = c_api.TFE_NewContext(opts, status.Handle); | |||||
| status.Check(true); | status.Check(true); | ||||
| } | } | ||||
| @@ -53,7 +53,7 @@ namespace Tensorflow.Eager | |||||
| { | { | ||||
| object value = null; | object value = null; | ||||
| byte isList = 0; | byte isList = 0; | ||||
| var attrType = c_api.TFE_OpNameGetAttrType(tf.context, Name, attr_name, ref isList, tf.status); | |||||
| var attrType = c_api.TFE_OpNameGetAttrType(tf.context, Name, attr_name, ref isList, tf.status.Handle); | |||||
| switch (attrType) | switch (attrType) | ||||
| { | { | ||||
| case TF_AttrType.TF_ATTR_BOOL: | case TF_AttrType.TF_ATTR_BOOL: | ||||
| @@ -22,13 +22,13 @@ namespace Tensorflow.Eager | |||||
| public EagerTensor(string value, string device_name) : base(value) | public EagerTensor(string value, string device_name) : base(value) | ||||
| { | { | ||||
| EagerTensorHandle = c_api.TFE_NewTensorHandle(_handle, tf.status); | |||||
| EagerTensorHandle = c_api.TFE_NewTensorHandle(_handle, tf.status.Handle); | |||||
| Resolve(); | Resolve(); | ||||
| } | } | ||||
| public EagerTensor(NDArray value, string device_name) : base(value) | public EagerTensor(NDArray value, string device_name) : base(value) | ||||
| { | { | ||||
| EagerTensorHandle = c_api.TFE_NewTensorHandle(_handle, tf.status); | |||||
| EagerTensorHandle = c_api.TFE_NewTensorHandle(_handle, tf.status.Handle); | |||||
| Resolve(); | Resolve(); | ||||
| } | } | ||||
| @@ -37,7 +37,7 @@ namespace Tensorflow.Eager | |||||
| _id = get_uid(); | _id = get_uid(); | ||||
| if (_handle == IntPtr.Zero) | if (_handle == IntPtr.Zero) | ||||
| _handle = c_api.TFE_TensorHandleResolve(EagerTensorHandle, tf.status); | |||||
| _handle = c_api.TFE_TensorHandleResolve(EagerTensorHandle, tf.status.Handle); | |||||
| //print($"new Tensor {Id} {_handle.ToString("x16")}"); | //print($"new Tensor {Id} {_handle.ToString("x16")}"); | ||||
| //print($"new TensorHandle {Id} {EagerTensorHandle.ToString("x16")}"); | //print($"new TensorHandle {Id} {EagerTensorHandle.ToString("x16")}"); | ||||
| @@ -9,22 +9,22 @@ namespace Tensorflow.Eager | |||||
| public partial class EagerTensor : Tensor | public partial class EagerTensor : Tensor | ||||
| { | { | ||||
| public IntPtr EagerTensorHandle; | public IntPtr EagerTensorHandle; | ||||
| public override string Device => c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(EagerTensorHandle, tf.status)); | |||||
| public override string Device => c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(EagerTensorHandle, tf.status.Handle)); | |||||
| public override int rank => c_api.TFE_TensorHandleNumDims(EagerTensorHandle, tf.status); | |||||
| public override int rank => c_api.TFE_TensorHandleNumDims(EagerTensorHandle, tf.status.Handle); | |||||
| public static int GetRank(IntPtr handle) | public static int GetRank(IntPtr handle) | ||||
| { | { | ||||
| var tfe_tensor_handle = c_api.TFE_EagerTensorHandle(handle); | var tfe_tensor_handle = c_api.TFE_EagerTensorHandle(handle); | ||||
| return c_api.TFE_TensorHandleNumDims(tfe_tensor_handle, tf.status); | |||||
| return c_api.TFE_TensorHandleNumDims(tfe_tensor_handle, tf.status.Handle); | |||||
| } | } | ||||
| public static int[] GetDims(IntPtr handle) | public static int[] GetDims(IntPtr handle) | ||||
| { | { | ||||
| var tfe_tensor_handle = c_api.TFE_EagerTensorHandle(handle); | var tfe_tensor_handle = c_api.TFE_EagerTensorHandle(handle); | ||||
| var dims = new int[c_api.TFE_TensorHandleNumDims(tfe_tensor_handle, tf.status)]; | |||||
| var dims = new int[c_api.TFE_TensorHandleNumDims(tfe_tensor_handle, tf.status.Handle)]; | |||||
| for (int i = 0; i < dims.Length; i++) | for (int i = 0; i < dims.Length; i++) | ||||
| dims[i] = c_api.TFE_TensorHandleDim(tfe_tensor_handle, i, tf.status); | |||||
| dims[i] = c_api.TFE_TensorHandleDim(tfe_tensor_handle, i, tf.status.Handle); | |||||
| return dims; | return dims; | ||||
| } | } | ||||
| @@ -70,10 +70,10 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern TF_AttrType TFE_OpGetAttrType(IntPtr op, string attr_name, ref byte is_list, IntPtr status); | |||||
| public static extern TF_AttrType TFE_OpGetAttrType(IntPtr op, string attr_name, ref byte is_list, SafeStatusHandle status); | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern TF_AttrType TFE_OpNameGetAttrType(IntPtr ct, string op_or_function_name, string attr_name, ref byte is_list, IntPtr status); | |||||
| public static extern TF_AttrType TFE_OpNameGetAttrType(IntPtr ct, string op_or_function_name, string attr_name, ref byte is_list, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Returns the length (number of tensors) of the input argument `input_name` | /// Returns the length (number of tensors) of the input argument `input_name` | ||||
| @@ -83,7 +83,7 @@ namespace Tensorflow | |||||
| /// <param name="input_name">const char*</param> | /// <param name="input_name">const char*</param> | ||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern int TFE_OpGetInputLength(IntPtr op, string input_name, IntPtr status); | |||||
| public static extern int TFE_OpGetInputLength(IntPtr op, string input_name, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Returns the length (number of tensors) of the output argument `output_name` | /// Returns the length (number of tensors) of the output argument `output_name` | ||||
| @@ -94,7 +94,7 @@ namespace Tensorflow | |||||
| /// <param name="status"></param> | /// <param name="status"></param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern int TFE_OpGetOutputLength(IntPtr op, string input_name, IntPtr status); | |||||
| public static extern int TFE_OpGetOutputLength(IntPtr op, string input_name, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// | /// | ||||
| @@ -105,7 +105,7 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern int TFE_OpAddInputList(IntPtr op, IntPtr[] inputs, int num_inputs, IntPtr status); | |||||
| public static extern int TFE_OpAddInputList(IntPtr op, IntPtr[] inputs, int num_inputs, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// | /// | ||||
| @@ -114,7 +114,7 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns>TFE_Context*</returns> | /// <returns>TFE_Context*</returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern TFE_Context TFE_NewContext(IntPtr opts, IntPtr status); | |||||
| public static extern TFE_Context TFE_NewContext(IntPtr opts, SafeStatusHandle status); | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern TFE_Context TFE_ContextStartStep(IntPtr ctx); | public static extern TFE_Context TFE_ContextStartStep(IntPtr ctx); | ||||
| @@ -138,7 +138,7 @@ namespace Tensorflow | |||||
| /// <param name="num_retvals">int*</param> | /// <param name="num_retvals">int*</param> | ||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TFE_Execute(IntPtr op, IntPtr[] retvals, ref int num_retvals, IntPtr status); | |||||
| public static extern void TFE_Execute(IntPtr op, IntPtr[] retvals, ref int num_retvals, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// | /// | ||||
| @@ -148,7 +148,7 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern TFE_Op TFE_NewOp(IntPtr ctx, string op_or_function_name, IntPtr status); | |||||
| public static extern TFE_Op TFE_NewOp(IntPtr ctx, string op_or_function_name, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Resets `op_to_reset` with `op_or_function_name` and `raw_device_name`. This | /// Resets `op_to_reset` with `op_or_function_name` and `raw_device_name`. This | ||||
| @@ -164,7 +164,7 @@ namespace Tensorflow | |||||
| /// <param name="raw_device_name">const char*</param> | /// <param name="raw_device_name">const char*</param> | ||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TFE_OpReset(IntPtr op_to_reset, string op_or_function_name, string raw_device_name, IntPtr status); | |||||
| public static extern void TFE_OpReset(IntPtr op_to_reset, string op_or_function_name, string raw_device_name, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// | /// | ||||
| @@ -194,7 +194,7 @@ namespace Tensorflow | |||||
| /// <param name="num_dims">const int</param> | /// <param name="num_dims">const int</param> | ||||
| /// <param name="out_status">TF_Status*</param> | /// <param name="out_status">TF_Status*</param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TFE_OpSetAttrShape(IntPtr op, string attr_name, long[] dims, int num_dims, IntPtr out_status); | |||||
| public static extern void TFE_OpSetAttrShape(IntPtr op, string attr_name, long[] dims, int num_dims, SafeStatusHandle out_status); | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TFE_OpSetAttrBool(IntPtr op, string attr_name, bool value); | public static extern void TFE_OpSetAttrBool(IntPtr op, string attr_name, bool value); | ||||
| @@ -216,7 +216,7 @@ namespace Tensorflow | |||||
| /// <param name="device_name"></param> | /// <param name="device_name"></param> | ||||
| /// <param name="status"></param> | /// <param name="status"></param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TFE_OpSetDevice(TFE_Op op, string device_name, IntPtr status); | |||||
| public static extern void TFE_OpSetDevice(TFE_Op op, string device_name, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// | /// | ||||
| @@ -225,7 +225,7 @@ namespace Tensorflow | |||||
| /// <param name="h">TFE_TensorHandle*</param> | /// <param name="h">TFE_TensorHandle*</param> | ||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TFE_OpAddInput(IntPtr op, IntPtr h, IntPtr status); | |||||
| public static extern void TFE_OpAddInput(IntPtr op, IntPtr h, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// | /// | ||||
| @@ -233,7 +233,7 @@ namespace Tensorflow | |||||
| /// <param name="t">const tensorflow::Tensor&</param> | /// <param name="t">const tensorflow::Tensor&</param> | ||||
| /// <returns>TFE_TensorHandle*</returns> | /// <returns>TFE_TensorHandle*</returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern TFE_TensorHandle TFE_NewTensorHandle(IntPtr t, IntPtr status); | |||||
| public static extern TFE_TensorHandle TFE_NewTensorHandle(IntPtr t, SafeStatusHandle status); | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TFE_EagerTensorHandle(IntPtr t); | public static extern IntPtr TFE_EagerTensorHandle(IntPtr t); | ||||
| @@ -273,7 +273,7 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TFE_TensorHandleResolve(IntPtr h, IntPtr status); | |||||
| public static extern IntPtr TFE_TensorHandleResolve(IntPtr h, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| @@ -283,10 +283,10 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern int TFE_TensorHandleNumDims(IntPtr h, IntPtr status); | |||||
| public static extern int TFE_TensorHandleNumDims(IntPtr h, SafeStatusHandle status); | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern int TFE_TensorHandleDim(IntPtr h, int dim, IntPtr status); | |||||
| public static extern int TFE_TensorHandleDim(IntPtr h, int dim, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Returns the device of the operation that produced `h`. If `h` was produced by | /// Returns the device of the operation that produced `h`. If `h` was produced by | ||||
| @@ -299,7 +299,7 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TFE_TensorHandleDeviceName(IntPtr h, IntPtr status); | |||||
| public static extern IntPtr TFE_TensorHandleDeviceName(IntPtr h, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Returns the name of the device in whose memory `h` resides. | /// Returns the name of the device in whose memory `h` resides. | ||||
| @@ -308,7 +308,7 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TFE_TensorHandleBackingDeviceName(IntPtr h, IntPtr status); | |||||
| public static extern IntPtr TFE_TensorHandleBackingDeviceName(IntPtr h, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// | /// | ||||
| @@ -317,7 +317,7 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TFE_ContextListDevices(IntPtr ctx, IntPtr status); | |||||
| public static extern IntPtr TFE_ContextListDevices(IntPtr ctx, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// | /// | ||||
| @@ -370,7 +370,7 @@ namespace Tensorflow | |||||
| /// <param name="executor">TFE_Executor*</param> | /// <param name="executor">TFE_Executor*</param> | ||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TFE_ExecutorWaitForAllPendingNodes(TFE_Executor executor, IntPtr status); | |||||
| public static extern void TFE_ExecutorWaitForAllPendingNodes(TFE_Executor executor, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Sets a custom Executor for current thread. All nodes created by this thread | /// Sets a custom Executor for current thread. All nodes created by this thread | ||||
| @@ -402,7 +402,7 @@ namespace Tensorflow | |||||
| /// <param name="status"></param> | /// <param name="status"></param> | ||||
| /// <returns>EagerTensorHandle</returns> | /// <returns>EagerTensorHandle</returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TFE_FastPathExecute(IntPtr ctx, | |||||
| public static extern SafeStatusHandle TFE_FastPathExecute(IntPtr ctx, | |||||
| string device_name, | string device_name, | ||||
| string op_name, | string op_name, | ||||
| string name, | string name, | ||||
| @@ -416,7 +416,7 @@ namespace Tensorflow | |||||
| public delegate void TFE_FastPathExecute_SetOpAttrs(IntPtr op); | public delegate void TFE_FastPathExecute_SetOpAttrs(IntPtr op); | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TFE_QuickExecute(IntPtr ctx, | |||||
| public static extern SafeStatusHandle TFE_QuickExecute(IntPtr ctx, | |||||
| string device_name, | string device_name, | ||||
| string op_name, | string op_name, | ||||
| IntPtr[] inputs, | IntPtr[] inputs, | ||||
| @@ -444,7 +444,7 @@ namespace Tensorflow | |||||
| public static extern IntPtr ResourceVariable_Handle(IntPtr variable); | public static extern IntPtr ResourceVariable_Handle(IntPtr variable); | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TFE_TapeGradient(IntPtr tape, | |||||
| public static extern SafeStatusHandle TFE_TapeGradient(IntPtr tape, | |||||
| IntPtr[] target, int target_size, | IntPtr[] target, int target_size, | ||||
| IntPtr[] sources, int source_size, | IntPtr[] sources, int source_size, | ||||
| IntPtr[] outputs, int output_size); | IntPtr[] outputs, int output_size); | ||||
| @@ -1,9 +0,0 @@ | |||||
| namespace Tensorflow.Framework.Models | |||||
| { | |||||
| public class ScopedTFStatus : Status | |||||
| { | |||||
| public ScopedTFStatus() : base() | |||||
| { | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -62,7 +62,7 @@ namespace Tensorflow | |||||
| { | { | ||||
| _PopulateTFImportGraphDefOptions(scoped_options, prefix, input_map, return_elements); | _PopulateTFImportGraphDefOptions(scoped_options, prefix, input_map, return_elements); | ||||
| // need to create a class ImportGraphDefWithResults with IDisposal | // need to create a class ImportGraphDefWithResults with IDisposal | ||||
| results = c_api.TF_GraphImportGraphDefWithResults(graph, buffer, scoped_options, status); | |||||
| results = c_api.TF_GraphImportGraphDefWithResults(graph, buffer, scoped_options, status.Handle); | |||||
| status.Check(true); | status.Check(true); | ||||
| } | } | ||||
| @@ -31,7 +31,7 @@ namespace Tensorflow | |||||
| /// <param name="output_func_def"></param> | /// <param name="output_func_def"></param> | ||||
| /// <param name="status"></param> | /// <param name="status"></param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_FunctionToFunctionDef(IntPtr func, IntPtr output_func_def, IntPtr status); | |||||
| public static extern void TF_FunctionToFunctionDef(IntPtr func, IntPtr output_func_def, SafeStatusHandle status); | |||||
| } | } | ||||
| @@ -41,6 +41,6 @@ namespace Tensorflow | |||||
| /// <param name="dy">TF_Output*</param> | /// <param name="dy">TF_Output*</param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_AddGradientsWithPrefix(IntPtr g, string prefix, TF_Output[] y, int ny, | public static extern void TF_AddGradientsWithPrefix(IntPtr g, string prefix, TF_Output[] y, int ny, | ||||
| TF_Output[] x, int nx, TF_Output[] dx, IntPtr status, IntPtr[] dy); | |||||
| TF_Output[] x, int nx, TF_Output[] dx, SafeStatusHandle status, IntPtr[] dy); | |||||
| } | } | ||||
| } | } | ||||
| @@ -35,7 +35,7 @@ namespace Tensorflow | |||||
| outputs_string, | outputs_string, | ||||
| transforms_string, | transforms_string, | ||||
| buffer, | buffer, | ||||
| status); | |||||
| status.Handle); | |||||
| status.Check(false); | status.Check(false); | ||||
| var bytes = buffer.ToArray(); | var bytes = buffer.ToArray(); | ||||
| @@ -28,6 +28,6 @@ namespace Tensorflow | |||||
| string outputs_string, | string outputs_string, | ||||
| string transforms_string, | string transforms_string, | ||||
| IntPtr output_buffer, | IntPtr output_buffer, | ||||
| IntPtr status); | |||||
| SafeStatusHandle status); | |||||
| } | } | ||||
| } | } | ||||
| @@ -25,7 +25,7 @@ namespace Tensorflow | |||||
| public Buffer ToGraphDef(Status s) | public Buffer ToGraphDef(Status s) | ||||
| { | { | ||||
| var buffer = new Buffer(); | var buffer = new Buffer(); | ||||
| c_api.TF_GraphToGraphDef(_handle, buffer, s); | |||||
| c_api.TF_GraphToGraphDef(_handle, buffer, s.Handle); | |||||
| s.Check(true); | s.Check(true); | ||||
| return buffer; | return buffer; | ||||
| @@ -29,7 +29,7 @@ namespace Tensorflow | |||||
| int size = Marshal.SizeOf<TF_Output>(); | int size = Marshal.SizeOf<TF_Output>(); | ||||
| var return_output_handle = Marshal.AllocHGlobal(size * num_return_outputs); | var return_output_handle = Marshal.AllocHGlobal(size * num_return_outputs); | ||||
| c_api.TF_GraphImportGraphDefWithReturnOutputs(_handle, graph_def, opts, return_output_handle, num_return_outputs, s); | |||||
| c_api.TF_GraphImportGraphDefWithReturnOutputs(_handle, graph_def, opts, return_output_handle, num_return_outputs, s.Handle); | |||||
| var tf_output_ptr = (TF_Output*) return_output_handle; | var tf_output_ptr = (TF_Output*) return_output_handle; | ||||
| for (int i = 0; i < num_return_outputs; i++) | for (int i = 0; i < num_return_outputs; i++) | ||||
| @@ -54,7 +54,7 @@ namespace Tensorflow | |||||
| { | { | ||||
| as_default(); | as_default(); | ||||
| c_api.TF_ImportGraphDefOptionsSetPrefix(opts, prefix); | c_api.TF_ImportGraphDefOptionsSetPrefix(opts, prefix); | ||||
| c_api.TF_GraphImportGraphDef(_handle, graph_def, opts, status); | |||||
| c_api.TF_GraphImportGraphDef(_handle, graph_def, opts, status.Handle); | |||||
| status.Check(true); | status.Check(true); | ||||
| return status.Code == TF_Code.TF_OK; | return status.Code == TF_Code.TF_OK; | ||||
| } | } | ||||
| @@ -513,14 +513,14 @@ namespace Tensorflow | |||||
| public TensorShape GetTensorShape(TF_Output output) | public TensorShape GetTensorShape(TF_Output output) | ||||
| { | { | ||||
| var status = tf.status; | var status = tf.status; | ||||
| var ndim = c_api.TF_GraphGetTensorNumDims(_handle, output, status); | |||||
| var ndim = c_api.TF_GraphGetTensorNumDims(_handle, output, status.Handle); | |||||
| status.Check(); | status.Check(); | ||||
| if (ndim == -1) | if (ndim == -1) | ||||
| return new TensorShape(); | return new TensorShape(); | ||||
| var dims = new long[ndim]; | var dims = new long[ndim]; | ||||
| c_api.TF_GraphGetTensorShape(_handle, output, dims, dims.Length, status); | |||||
| c_api.TF_GraphGetTensorShape(_handle, output, dims, dims.Length, status.Handle); | |||||
| status.Check(); | status.Check(); | ||||
| return new TensorShape(dims.Select(x => (int)x).ToArray()); | return new TensorShape(dims.Select(x => (int)x).ToArray()); | ||||
| @@ -47,7 +47,7 @@ namespace Tensorflow | |||||
| public static extern string TF_GraphDebugString(IntPtr graph, out int len); | public static extern string TF_GraphDebugString(IntPtr graph, out int len); | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_GraphGetOpDef(IntPtr graph, string op_name, IntPtr output_op_def, IntPtr status); | |||||
| public static extern void TF_GraphGetOpDef(IntPtr graph, string op_name, IntPtr output_op_def, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Returns the shape of the Tensor referenced by `output` in `graph` | /// Returns the shape of the Tensor referenced by `output` in `graph` | ||||
| @@ -60,7 +60,7 @@ namespace Tensorflow | |||||
| /// <param name="num_dims"></param> | /// <param name="num_dims"></param> | ||||
| /// <param name="status"></param> | /// <param name="status"></param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_GraphGetTensorShape(IntPtr graph, TF_Output output, long[] dims, int num_dims, IntPtr status); | |||||
| public static extern void TF_GraphGetTensorShape(IntPtr graph, TF_Output output, long[] dims, int num_dims, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Import the graph serialized in `graph_def` into `graph`. | /// Import the graph serialized in `graph_def` into `graph`. | ||||
| @@ -78,7 +78,7 @@ namespace Tensorflow | |||||
| /// <param name="num_return_outputs">int</param> | /// <param name="num_return_outputs">int</param> | ||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern unsafe void TF_GraphImportGraphDefWithReturnOutputs(IntPtr graph, IntPtr graph_def, IntPtr options, IntPtr return_outputs, int num_return_outputs, IntPtr status); | |||||
| public static extern unsafe void TF_GraphImportGraphDefWithReturnOutputs(IntPtr graph, IntPtr graph_def, IntPtr options, IntPtr return_outputs, int num_return_outputs, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Import the graph serialized in `graph_def` into `graph`. Returns nullptr and | /// Import the graph serialized in `graph_def` into `graph`. Returns nullptr and | ||||
| @@ -92,7 +92,7 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns>TF_ImportGraphDefResults*</returns> | /// <returns>TF_ImportGraphDefResults*</returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TF_GraphImportGraphDefWithResults(IntPtr graph, IntPtr graph_def, IntPtr options, IntPtr status); | |||||
| public static extern IntPtr TF_GraphImportGraphDefWithResults(IntPtr graph, IntPtr graph_def, IntPtr options, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Import the graph serialized in `graph_def` into `graph`. | /// Import the graph serialized in `graph_def` into `graph`. | ||||
| @@ -102,7 +102,7 @@ namespace Tensorflow | |||||
| /// <param name="options">TF_ImportGraphDefOptions*</param> | /// <param name="options">TF_ImportGraphDefOptions*</param> | ||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_GraphImportGraphDef(IntPtr graph, IntPtr graph_def, IntPtr options, IntPtr status); | |||||
| public static extern void TF_GraphImportGraphDef(IntPtr graph, IntPtr graph_def, IntPtr options, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Iterate through the operations of a graph. | /// Iterate through the operations of a graph. | ||||
| @@ -128,7 +128,7 @@ namespace Tensorflow | |||||
| /// the shape described by `dims` and `num_dims`. | /// the shape described by `dims` and `num_dims`. | ||||
| /// </summary> | /// </summary> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_GraphSetTensorShape(IntPtr graph, TF_Output output, long[] dims, int num_dims, IntPtr status); | |||||
| public static extern void TF_GraphSetTensorShape(IntPtr graph, TF_Output output, long[] dims, int num_dims, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Write out a serialized representation of `graph` (as a GraphDef protocol | /// Write out a serialized representation of `graph` (as a GraphDef protocol | ||||
| @@ -138,7 +138,7 @@ namespace Tensorflow | |||||
| /// <param name="output_graph_def">TF_Buffer*</param> | /// <param name="output_graph_def">TF_Buffer*</param> | ||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_GraphToGraphDef(IntPtr graph, IntPtr output_graph_def, IntPtr status); | |||||
| public static extern void TF_GraphToGraphDef(IntPtr graph, IntPtr output_graph_def, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Returns the number of dimensions of the Tensor referenced by `output` | /// Returns the number of dimensions of the Tensor referenced by `output` | ||||
| @@ -151,7 +151,7 @@ namespace Tensorflow | |||||
| /// <param name="status"></param> | /// <param name="status"></param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern int TF_GraphGetTensorNumDims(IntPtr graph, TF_Output output, IntPtr status); | |||||
| public static extern int TF_GraphGetTensorNumDims(IntPtr graph, TF_Output output, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Cause the imported graph to have a control dependency on `oper`. `oper` | /// Cause the imported graph to have a control dependency on `oper`. `oper` | ||||
| @@ -289,7 +289,7 @@ namespace Tensorflow | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TF_LoadSessionFromSavedModel(IntPtr session_options, IntPtr run_options, | public static extern IntPtr TF_LoadSessionFromSavedModel(IntPtr session_options, IntPtr run_options, | ||||
| string export_dir, string[] tags, int tags_len, | string export_dir, string[] tags, int tags_len, | ||||
| IntPtr graph, ref TF_Buffer meta_graph_def, IntPtr status); | |||||
| IntPtr graph, ref TF_Buffer meta_graph_def, SafeStatusHandle status); | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TF_NewGraph(); | public static extern IntPtr TF_NewGraph(); | ||||
| @@ -306,6 +306,6 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void UpdateEdge(IntPtr graph, TF_Output new_src, TF_Input dst, IntPtr status); | |||||
| public static extern void UpdateEdge(IntPtr graph, TF_Output new_src, TF_Input dst, SafeStatusHandle status); | |||||
| } | } | ||||
| } | } | ||||
| @@ -31,7 +31,7 @@ namespace Tensorflow | |||||
| public int InputListLength(string name) | public int InputListLength(string name) | ||||
| { | { | ||||
| int num = 0; | int num = 0; | ||||
| num = c_api.TF_OperationInputListLength(_handle, name, tf.status); | |||||
| num = c_api.TF_OperationInputListLength(_handle, name, tf.status.Handle); | |||||
| tf.status.Check(true); | tf.status.Check(true); | ||||
| return num; | return num; | ||||
| } | } | ||||
| @@ -28,7 +28,7 @@ namespace Tensorflow | |||||
| public int OutputListLength(string name) | public int OutputListLength(string name) | ||||
| { | { | ||||
| int num = c_api.TF_OperationOutputListLength(_handle, name, tf.status); | |||||
| int num = c_api.TF_OperationOutputListLength(_handle, name, tf.status.Handle); | |||||
| tf.status.Check(true); | tf.status.Check(true); | ||||
| return num; | return num; | ||||
| @@ -236,7 +236,7 @@ namespace Tensorflow | |||||
| lock (Locks.ProcessWide) | lock (Locks.ProcessWide) | ||||
| { | { | ||||
| using var buf = new Buffer(); | using var buf = new Buffer(); | ||||
| c_api.TF_OperationGetAttrValueProto(_handle, name, buf, tf.status); | |||||
| c_api.TF_OperationGetAttrValueProto(_handle, name, buf, tf.status.Handle); | |||||
| tf.status.Check(true); | tf.status.Check(true); | ||||
| x = AttrValue.Parser.ParseFrom(buf.MemoryBlock.Stream()); | x = AttrValue.Parser.ParseFrom(buf.MemoryBlock.Stream()); | ||||
| @@ -260,7 +260,7 @@ namespace Tensorflow | |||||
| public TF_AttrMetadata GetAttributeMetadata(string attr_name, Status s) | public TF_AttrMetadata GetAttributeMetadata(string attr_name, Status s) | ||||
| { | { | ||||
| return c_api.TF_OperationGetAttrMetadata(_handle, attr_name, s); | |||||
| return c_api.TF_OperationGetAttrMetadata(_handle, attr_name, s.Handle); | |||||
| } | } | ||||
| private NodeDef GetNodeDef() | private NodeDef GetNodeDef() | ||||
| @@ -269,7 +269,7 @@ namespace Tensorflow | |||||
| using (var s = new Status()) | using (var s = new Status()) | ||||
| using (var buffer = new Buffer()) | using (var buffer = new Buffer()) | ||||
| { | { | ||||
| c_api.TF_OperationToNodeDef(_handle, buffer, s); | |||||
| c_api.TF_OperationToNodeDef(_handle, buffer, s.Handle); | |||||
| s.Check(); | s.Check(); | ||||
| return NodeDef.Parser.ParseFrom(buffer.MemoryBlock.Stream()); | return NodeDef.Parser.ParseFrom(buffer.MemoryBlock.Stream()); | ||||
| @@ -295,11 +295,11 @@ namespace Tensorflow | |||||
| // after the c_api call next time _inputs is accessed | // after the c_api call next time _inputs is accessed | ||||
| // the updated inputs are reloaded from the c_api | // the updated inputs are reloaded from the c_api | ||||
| lock (Locks.ProcessWide) | lock (Locks.ProcessWide) | ||||
| { | |||||
| c_api.UpdateEdge(_graph, output, input, tf.status); | |||||
| //var updated_inputs = inputs; | |||||
| tf.status.Check(); | |||||
| } | |||||
| { | |||||
| c_api.UpdateEdge(_graph, output, input, tf.status.Handle); | |||||
| //var updated_inputs = inputs; | |||||
| tf.status.Check(); | |||||
| } | |||||
| } | } | ||||
| private void _assert_same_graph(Tensor tensor) | private void _assert_same_graph(Tensor tensor) | ||||
| @@ -50,7 +50,7 @@ namespace Tensorflow | |||||
| public Operation FinishOperation(Status status) | public Operation FinishOperation(Status status) | ||||
| { | { | ||||
| return c_api.TF_FinishOperation(_handle, status); | |||||
| return c_api.TF_FinishOperation(_handle, status.Handle); | |||||
| } | } | ||||
| public static implicit operator OperationDescription(IntPtr handle) | public static implicit operator OperationDescription(IntPtr handle) | ||||
| @@ -83,7 +83,7 @@ namespace Tensorflow | |||||
| public static extern void TF_AddInputList(IntPtr desc, TF_Output[] inputs, int num_inputs); | public static extern void TF_AddInputList(IntPtr desc, TF_Output[] inputs, int num_inputs); | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TF_FinishOperation(IntPtr desc, IntPtr status); | |||||
| public static extern IntPtr TF_FinishOperation(IntPtr desc, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Operation will only be added to *graph when TF_FinishOperation() is | /// Operation will only be added to *graph when TF_FinishOperation() is | ||||
| @@ -141,7 +141,7 @@ namespace Tensorflow | |||||
| public static extern TF_Output TF_OperationInput(TF_Input oper_in); | public static extern TF_Output TF_OperationInput(TF_Input oper_in); | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern int TF_OperationInputListLength(IntPtr oper, string arg_name, IntPtr status); | |||||
| public static extern int TF_OperationInputListLength(IntPtr oper, string arg_name, SafeStatusHandle status); | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern TF_DataType TF_OperationInputType(TF_Input oper_in); | public static extern TF_DataType TF_OperationInputType(TF_Input oper_in); | ||||
| @@ -204,9 +204,9 @@ namespace Tensorflow | |||||
| public static extern TF_DataType TF_OperationOutputType(TF_Output oper_out); | public static extern TF_DataType TF_OperationOutputType(TF_Output oper_out); | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_OperationToNodeDef(IntPtr oper, IntPtr buffer, IntPtr status); | |||||
| public static extern void TF_OperationToNodeDef(IntPtr oper, IntPtr buffer, SafeStatusHandle status); | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern int TF_OperationOutputListLength(IntPtr oper, string arg_name, IntPtr status); | |||||
| public static extern int TF_OperationOutputListLength(IntPtr oper, string arg_name, SafeStatusHandle status); | |||||
| } | } | ||||
| } | } | ||||
| @@ -47,7 +47,7 @@ namespace Tensorflow | |||||
| lock (Locks.ProcessWide) | lock (Locks.ProcessWide) | ||||
| { | { | ||||
| status = status ?? new Status(); | status = status ?? new Status(); | ||||
| _handle = c_api.TF_NewSession(_graph, opts, status); | |||||
| _handle = c_api.TF_NewSession(_graph, opts, status.Handle); | |||||
| status.Check(true); | status.Check(true); | ||||
| } | } | ||||
| } | } | ||||
| @@ -251,7 +251,7 @@ namespace Tensorflow | |||||
| target_opers: target_list.Select(f => (IntPtr) f).ToArray(), | target_opers: target_list.Select(f => (IntPtr) f).ToArray(), | ||||
| ntargets: target_list.Count, | ntargets: target_list.Count, | ||||
| run_metadata: IntPtr.Zero, | run_metadata: IntPtr.Zero, | ||||
| status: status); | |||||
| status: status.Handle); | |||||
| status.Check(true); | status.Check(true); | ||||
| @@ -463,7 +463,7 @@ namespace Tensorflow | |||||
| lock (Locks.ProcessWide) | lock (Locks.ProcessWide) | ||||
| using (var status = new Status()) | using (var status = new Status()) | ||||
| { | { | ||||
| c_api.TF_DeleteSession(handle, status); | |||||
| c_api.TF_DeleteSession(handle, status.Handle); | |||||
| status.Check(true); | status.Check(true); | ||||
| } | } | ||||
| } | } | ||||
| @@ -62,7 +62,7 @@ namespace Tensorflow | |||||
| tags.Length, | tags.Length, | ||||
| graph, | graph, | ||||
| ref buffer, | ref buffer, | ||||
| status); | |||||
| status.Handle); | |||||
| status.Check(true); | status.Check(true); | ||||
| } catch (TensorflowException ex) when (ex.Message.Contains("Could not find SavedModel")) | } catch (TensorflowException ex) when (ex.Message.Contains("Could not find SavedModel")) | ||||
| { | { | ||||
| @@ -73,7 +73,7 @@ namespace Tensorflow | |||||
| tags.Length, | tags.Length, | ||||
| graph, | graph, | ||||
| ref buffer, | ref buffer, | ||||
| status); | |||||
| status.Handle); | |||||
| status.Check(true); | status.Check(true); | ||||
| } | } | ||||
| @@ -46,7 +46,7 @@ namespace Tensorflow | |||||
| using (var status = new Status()) | using (var status = new Status()) | ||||
| { | { | ||||
| c_api.TF_SetConfig(_handle, proto, (ulong)bytes.Length, status); | |||||
| c_api.TF_SetConfig(_handle, proto, (ulong)bytes.Length, status.Handle); | |||||
| status.Check(false); | status.Check(false); | ||||
| } | } | ||||
| @@ -32,7 +32,7 @@ namespace Tensorflow | |||||
| /// <param name="session">TF_Session*</param> | /// <param name="session">TF_Session*</param> | ||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_DeleteSession(IntPtr session, IntPtr status); | |||||
| public static extern void TF_DeleteSession(IntPtr session, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Destroy an options object. | /// Destroy an options object. | ||||
| @@ -50,7 +50,7 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns>TF_Session*</returns> | /// <returns>TF_Session*</returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TF_NewSession(IntPtr graph, IntPtr opts, IntPtr status); | |||||
| public static extern IntPtr TF_NewSession(IntPtr graph, IntPtr opts, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Return a new options object. | /// Return a new options object. | ||||
| @@ -103,7 +103,7 @@ namespace Tensorflow | |||||
| TF_Output[] outputs, IntPtr[] output_values, int noutputs, | TF_Output[] outputs, IntPtr[] output_values, int noutputs, | ||||
| IntPtr[] target_opers, int ntargets, | IntPtr[] target_opers, int ntargets, | ||||
| IntPtr run_metadata, | IntPtr run_metadata, | ||||
| IntPtr status); | |||||
| SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Set the config in TF_SessionOptions.options. | /// Set the config in TF_SessionOptions.options. | ||||
| @@ -116,7 +116,7 @@ namespace Tensorflow | |||||
| /// <param name="proto_len">size_t</param> | /// <param name="proto_len">size_t</param> | ||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_SetConfig(IntPtr options, IntPtr proto, ulong proto_len, IntPtr status); | |||||
| public static extern void TF_SetConfig(IntPtr options, IntPtr proto, ulong proto_len, SafeStatusHandle status); | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_SetTarget(IntPtr options, string target); | public static extern void TF_SetTarget(IntPtr options, string target); | ||||
| @@ -0,0 +1,39 @@ | |||||
| /***************************************************************************** | |||||
| 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 | |||||
| { | |||||
| public sealed class SafeStatusHandle : SafeTensorflowHandle | |||||
| { | |||||
| public SafeStatusHandle() | |||||
| { | |||||
| } | |||||
| public SafeStatusHandle(IntPtr handle) | |||||
| : base(handle) | |||||
| { | |||||
| } | |||||
| protected override bool ReleaseHandle() | |||||
| { | |||||
| c_api.TF_DeleteStatus(handle); | |||||
| return true; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -17,6 +17,7 @@ | |||||
| using System; | using System; | ||||
| using System.Diagnostics; | using System.Diagnostics; | ||||
| using System.Runtime.CompilerServices; | using System.Runtime.CompilerServices; | ||||
| using Tensorflow.Util; | |||||
| using static Tensorflow.c_api; | using static Tensorflow.c_api; | ||||
| namespace Tensorflow | namespace Tensorflow | ||||
| @@ -25,31 +26,42 @@ namespace Tensorflow | |||||
| /// TF_Status holds error information. It either has an OK code, or | /// TF_Status holds error information. It either has an OK code, or | ||||
| /// else an error code with an associated error message. | /// else an error code with an associated error message. | ||||
| /// </summary> | /// </summary> | ||||
| public class Status : DisposableObject | |||||
| public sealed class Status : IDisposable | |||||
| { | { | ||||
| /// <summary> | /// <summary> | ||||
| /// Error message | /// Error message | ||||
| /// </summary> | /// </summary> | ||||
| public string Message => c_api.StringPiece(TF_Message(_handle)); | |||||
| public string Message | |||||
| { | |||||
| get | |||||
| { | |||||
| using (Handle.Lease()) | |||||
| { | |||||
| return StringPiece(TF_Message(Handle)); | |||||
| } | |||||
| } | |||||
| } | |||||
| /// <summary> | /// <summary> | ||||
| /// Error code | /// Error code | ||||
| /// </summary> | /// </summary> | ||||
| public TF_Code Code => TF_GetCode(_handle); | |||||
| public TF_Code Code => TF_GetCode(Handle); | |||||
| public SafeStatusHandle Handle { get; } | |||||
| public Status() | public Status() | ||||
| { | { | ||||
| _handle = TF_NewStatus(); | |||||
| Handle = TF_NewStatus(); | |||||
| } | } | ||||
| public Status(IntPtr handle) | |||||
| public Status(SafeStatusHandle handle) | |||||
| { | { | ||||
| _handle = handle; | |||||
| Handle = handle ?? throw new ArgumentNullException(nameof(handle)); | |||||
| } | } | ||||
| public void SetStatus(TF_Code code, string msg) | public void SetStatus(TF_Code code, string msg) | ||||
| { | { | ||||
| TF_SetStatus(_handle, code, msg); | |||||
| TF_SetStatus(Handle, code, msg); | |||||
| } | } | ||||
| public bool ok() => Code == TF_Code.TF_OK; | public bool ok() => Code == TF_Code.TF_OK; | ||||
| @@ -65,22 +77,17 @@ namespace Tensorflow | |||||
| { | { | ||||
| if (Code != TF_Code.TF_OK) | if (Code != TF_Code.TF_OK) | ||||
| { | { | ||||
| Console.WriteLine(Message); | |||||
| var message = Message; | |||||
| Console.WriteLine(message); | |||||
| if (throwException) | if (throwException) | ||||
| throw new TensorflowException(Message); | |||||
| throw new TensorflowException(message); | |||||
| } | } | ||||
| } | } | ||||
| public static implicit operator IntPtr(Status status) | |||||
| => status._handle; | |||||
| public static implicit operator Status(IntPtr handle) | |||||
| => new Status(handle); | |||||
| protected override void DisposeUnmanagedResources(IntPtr handle) | |||||
| => TF_DeleteStatus(handle); | |||||
| public void Dispose() | |||||
| => Handle.Dispose(); | |||||
| public override string ToString() | public override string ToString() | ||||
| => $"{Code} 0x{_handle.ToString("x16")}"; | |||||
| => $"{Code} 0x{Handle.DangerousGetHandle():x16}"; | |||||
| } | } | ||||
| } | } | ||||
| @@ -34,7 +34,7 @@ namespace Tensorflow | |||||
| /// <param name="s"></param> | /// <param name="s"></param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern TF_Code TF_GetCode(IntPtr s); | |||||
| public static extern TF_Code TF_GetCode(SafeStatusHandle s); | |||||
| /// <summary> | /// <summary> | ||||
| /// Return a pointer to the (null-terminated) error message in *s. | /// Return a pointer to the (null-terminated) error message in *s. | ||||
| @@ -44,14 +44,14 @@ namespace Tensorflow | |||||
| /// <param name="s"></param> | /// <param name="s"></param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TF_Message(IntPtr s); | |||||
| public static extern IntPtr TF_Message(SafeStatusHandle s); | |||||
| /// <summary> | /// <summary> | ||||
| /// Return a new status object. | /// Return a new status object. | ||||
| /// </summary> | /// </summary> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern IntPtr TF_NewStatus(); | |||||
| public static extern SafeStatusHandle TF_NewStatus(); | |||||
| /// <summary> | /// <summary> | ||||
| /// Record <code, msg> in *s. Any previous information is lost. | /// Record <code, msg> in *s. Any previous information is lost. | ||||
| @@ -61,6 +61,6 @@ namespace Tensorflow | |||||
| /// <param name="code"></param> | /// <param name="code"></param> | ||||
| /// <param name="msg"></param> | /// <param name="msg"></param> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern void TF_SetStatus(IntPtr s, TF_Code code, string msg); | |||||
| public static extern void TF_SetStatus(SafeStatusHandle s, TF_Code code, string msg); | |||||
| } | } | ||||
| } | } | ||||
| @@ -13,12 +13,12 @@ namespace Tensorflow | |||||
| public class EagerTensorV2 : DisposableObject, ITensor | public class EagerTensorV2 : DisposableObject, ITensor | ||||
| { | { | ||||
| IntPtr EagerTensorHandle; | IntPtr EagerTensorHandle; | ||||
| public string Device => c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(EagerTensorHandle, tf.status)); | |||||
| public string Device => c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(EagerTensorHandle, tf.status.Handle)); | |||||
| public EagerTensorV2(IntPtr handle) | public EagerTensorV2(IntPtr handle) | ||||
| { | { | ||||
| EagerTensorHandle = c_api.TFE_EagerTensorHandle(handle); | EagerTensorHandle = c_api.TFE_EagerTensorHandle(handle); | ||||
| _handle = c_api.TFE_TensorHandleResolve(EagerTensorHandle, tf.status); | |||||
| _handle = c_api.TFE_TensorHandleResolve(EagerTensorHandle, tf.status.Handle); | |||||
| } | } | ||||
| public unsafe EagerTensorV2(NDArray nd, string device_name = "") | public unsafe EagerTensorV2(NDArray nd, string device_name = "") | ||||
| @@ -38,7 +38,7 @@ namespace Tensorflow | |||||
| }, IntPtr.Zero); | }, IntPtr.Zero); | ||||
| EagerTensorHandle = c_api.TFE_NewTensorHandle(_handle, tf.status); | |||||
| EagerTensorHandle = c_api.TFE_NewTensorHandle(_handle, tf.status.Handle); | |||||
| } | } | ||||
| /*public unsafe EagerTensorV2(float[,] value) | /*public unsafe EagerTensorV2(float[,] value) | ||||
| @@ -70,7 +70,7 @@ namespace Tensorflow | |||||
| IntPtr stringStartAddress = IntPtr.Zero; | IntPtr stringStartAddress = IntPtr.Zero; | ||||
| UIntPtr dstLen = UIntPtr.Zero; | UIntPtr dstLen = UIntPtr.Zero; | ||||
| c_api.TF_StringDecode((byte*) this.buffer + 8, (UIntPtr) (this.bytesize), (byte**) &stringStartAddress, &dstLen, tf.status); | |||||
| c_api.TF_StringDecode((byte*) this.buffer + 8, (UIntPtr) (this.bytesize), (byte**) &stringStartAddress, &dstLen, tf.status.Handle); | |||||
| tf.status.Check(true); | tf.status.Check(true); | ||||
| var dstLenInt = checked((int) dstLen); | var dstLenInt = checked((int) dstLen); | ||||
| @@ -459,7 +459,7 @@ namespace Tensorflow | |||||
| IntPtr tensor = c_api.TF_TensorData(handle); | IntPtr tensor = c_api.TF_TensorData(handle); | ||||
| Marshal.WriteInt64(tensor, 0); | Marshal.WriteInt64(tensor, 0); | ||||
| fixed (byte* src = buffer) | fixed (byte* src = buffer) | ||||
| c_api.TF_StringEncode(src, (UIntPtr)buffer.Length, (sbyte*)(tensor + sizeof(long)), size, tf.status); | |||||
| c_api.TF_StringEncode(src, (UIntPtr)buffer.Length, (sbyte*)(tensor + sizeof(long)), size, tf.status.Handle); | |||||
| _handle = handle; | _handle = handle; | ||||
| tf.status.Check(true); | tf.status.Check(true); | ||||
| } | } | ||||
| @@ -482,7 +482,7 @@ namespace Tensorflow | |||||
| IntPtr tensor = c_api.TF_TensorData(handle); | IntPtr tensor = c_api.TF_TensorData(handle); | ||||
| Marshal.WriteInt64(tensor, 0); | Marshal.WriteInt64(tensor, 0); | ||||
| c_api.TF_StringEncode((byte*) nd.Unsafe.Address, bytesLength, (sbyte*) (tensor + sizeof(Int64)), size, tf.status); | |||||
| c_api.TF_StringEncode((byte*) nd.Unsafe.Address, bytesLength, (sbyte*) (tensor + sizeof(Int64)), size, tf.status.Handle); | |||||
| tf.status.Check(true); | tf.status.Check(true); | ||||
| _handle = handle; | _handle = handle; | ||||
| } else | } else | ||||
| @@ -496,7 +496,7 @@ namespace Tensorflow | |||||
| Marshal.WriteInt64(tensor, 0); | Marshal.WriteInt64(tensor, 0); | ||||
| fixed (byte* src = buffer) | fixed (byte* src = buffer) | ||||
| c_api.TF_StringEncode(src, (UIntPtr) buffer.Length, (sbyte*) (tensor + sizeof(Int64)), size, tf.status); | |||||
| c_api.TF_StringEncode(src, (UIntPtr) buffer.Length, (sbyte*) (tensor + sizeof(Int64)), size, tf.status.Handle); | |||||
| tf.status.Check(true); | tf.status.Check(true); | ||||
| _handle = handle; | _handle = handle; | ||||
| @@ -557,7 +557,7 @@ namespace Tensorflow | |||||
| { | { | ||||
| fixed (byte* src = &buffer[i][0]) | fixed (byte* src = &buffer[i][0]) | ||||
| { | { | ||||
| var written = TF_StringEncode(src, (UIntPtr) buffer[i].Length, (sbyte*) dst, (UIntPtr) (dstLimit.ToInt64() - dst.ToInt64()), status); | |||||
| var written = TF_StringEncode(src, (UIntPtr) buffer[i].Length, (sbyte*) dst, (UIntPtr) (dstLimit.ToInt64() - dst.ToInt64()), status.Handle); | |||||
| status.Check(true); | status.Check(true); | ||||
| pOffset += 8; | pOffset += 8; | ||||
| dst += (int) written; | dst += (int) written; | ||||
| @@ -604,7 +604,7 @@ namespace Tensorflow | |||||
| Marshal.WriteInt64(tensor, 0); | Marshal.WriteInt64(tensor, 0); | ||||
| fixed (byte* src = buffer) | fixed (byte* src = buffer) | ||||
| c_api.TF_StringEncode(src, (UIntPtr) buffer.Length, (sbyte*) (tensor + sizeof(long)), size, tf.status); | |||||
| c_api.TF_StringEncode(src, (UIntPtr) buffer.Length, (sbyte*) (tensor + sizeof(long)), size, tf.status.Handle); | |||||
| tf.status.Check(true); | tf.status.Check(true); | ||||
| return handle; | return handle; | ||||
| @@ -241,7 +241,7 @@ namespace Tensorflow | |||||
| { | { | ||||
| IntPtr dst = IntPtr.Zero; | IntPtr dst = IntPtr.Zero; | ||||
| UIntPtr dstLen = UIntPtr.Zero; | UIntPtr dstLen = UIntPtr.Zero; | ||||
| var read = c_api.TF_StringDecode((byte*)src, (UIntPtr)(srcLen.ToInt64() - src.ToInt64()), (byte**)&dst, &dstLen, tf.status); | |||||
| var read = c_api.TF_StringDecode((byte*)src, (UIntPtr)(srcLen.ToInt64() - src.ToInt64()), (byte**)&dst, &dstLen, tf.status.Handle); | |||||
| tf.status.Check(true); | tf.status.Check(true); | ||||
| buffer[i] = new byte[(int)dstLen]; | buffer[i] = new byte[(int)dstLen]; | ||||
| Marshal.Copy(dst, buffer[i], 0, buffer[i].Length); | Marshal.Copy(dst, buffer[i], 0, buffer[i].Length); | ||||
| @@ -109,7 +109,7 @@ namespace Tensorflow | |||||
| if (_handle == IntPtr.Zero) | if (_handle == IntPtr.Zero) | ||||
| { | { | ||||
| c_api.TF_GraphGetTensorShape(op.graph, _as_tf_output(), dims, rank, tf.status); | |||||
| c_api.TF_GraphGetTensorShape(op.graph, _as_tf_output(), dims, rank, tf.status.Handle); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| @@ -123,9 +123,9 @@ namespace Tensorflow | |||||
| set | set | ||||
| { | { | ||||
| if (value == null) | if (value == null) | ||||
| c_api.TF_GraphSetTensorShape(graph, _as_tf_output(), null, -1, tf.status); | |||||
| c_api.TF_GraphSetTensorShape(graph, _as_tf_output(), null, -1, tf.status.Handle); | |||||
| else | else | ||||
| c_api.TF_GraphSetTensorShape(graph, _as_tf_output(), value.Select(Convert.ToInt64).ToArray(), value.Length, tf.status); | |||||
| c_api.TF_GraphSetTensorShape(graph, _as_tf_output(), value.Select(Convert.ToInt64).ToArray(), value.Length, tf.status.Handle); | |||||
| tf.status.Check(true); | tf.status.Check(true); | ||||
| } | } | ||||
| @@ -172,7 +172,7 @@ namespace Tensorflow | |||||
| if (_handle == IntPtr.Zero) | if (_handle == IntPtr.Zero) | ||||
| { | { | ||||
| var output = _as_tf_output(); | var output = _as_tf_output(); | ||||
| int ndim = c_api.TF_GraphGetTensorNumDims(op.graph, output, tf.status); | |||||
| int ndim = c_api.TF_GraphGetTensorNumDims(op.graph, output, tf.status.Handle); | |||||
| return ndim; | return ndim; | ||||
| } | } | ||||
| @@ -189,10 +189,10 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns>On success returns the size in bytes of the encoded string.</returns> | /// <returns>On success returns the size in bytes of the encoded string.</returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern unsafe ulong TF_StringEncode(byte* src, UIntPtr src_len, sbyte* dst, UIntPtr dst_len, IntPtr status); | |||||
| public static extern unsafe ulong TF_StringEncode(byte* src, UIntPtr src_len, sbyte* dst, UIntPtr dst_len, SafeStatusHandle status); | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern unsafe ulong TF_StringEncode(IntPtr src, ulong src_len, IntPtr dst, ulong dst_len, IntPtr status); | |||||
| public static extern unsafe ulong TF_StringEncode(IntPtr src, ulong src_len, IntPtr dst, ulong dst_len, SafeStatusHandle status); | |||||
| /// <summary> | /// <summary> | ||||
| /// Decode a string encoded using TF_StringEncode. | /// Decode a string encoded using TF_StringEncode. | ||||
| @@ -204,10 +204,10 @@ namespace Tensorflow | |||||
| /// <param name="status">TF_Status*</param> | /// <param name="status">TF_Status*</param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern ulong TF_StringDecode(IntPtr src, ulong src_len, IntPtr dst, ref ulong dst_len, IntPtr status); | |||||
| public static extern ulong TF_StringDecode(IntPtr src, ulong src_len, IntPtr dst, ref ulong dst_len, SafeStatusHandle status); | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern unsafe UIntPtr TF_StringDecode(byte* src, UIntPtr src_len, byte** dst, UIntPtr* dst_len, IntPtr status); | |||||
| public static extern unsafe UIntPtr TF_StringDecode(byte* src, UIntPtr src_len, byte** dst, UIntPtr* dst_len, SafeStatusHandle status); | |||||
| public static c_api.Deallocator EmptyDeallocator = FreeNothingDeallocator; | public static c_api.Deallocator EmptyDeallocator = FreeNothingDeallocator; | ||||
| @@ -0,0 +1,54 @@ | |||||
| /***************************************************************************** | |||||
| 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 System.Runtime.InteropServices; | |||||
| namespace Tensorflow.Util | |||||
| { | |||||
| internal static class SafeHandleExtensions | |||||
| { | |||||
| /// <summary> | |||||
| /// Acquires a lease on a safe handle. This method is intended to be used in the initializer of a <c>using</c> | |||||
| /// statement. | |||||
| /// </summary> | |||||
| /// <param name="handle">The <see cref="SafeHandle"/> to lease.</param> | |||||
| /// <returns>A <see cref="SafeHandleLease"/>, which must be disposed to release the resource.</returns> | |||||
| /// <exception cref="ObjectDisposedException">If the lease could not be acquired.</exception> | |||||
| public static SafeHandleLease Lease(this SafeHandle handle) | |||||
| { | |||||
| if (handle is null) | |||||
| throw new ArgumentNullException(nameof(handle)); | |||||
| var success = false; | |||||
| try | |||||
| { | |||||
| handle.DangerousAddRef(ref success); | |||||
| if (!success) | |||||
| throw new ObjectDisposedException(handle.GetType().FullName); | |||||
| return new SafeHandleLease(handle); | |||||
| } | |||||
| catch | |||||
| { | |||||
| if (success) | |||||
| handle.DangerousRelease(); | |||||
| throw; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,36 @@ | |||||
| /***************************************************************************** | |||||
| 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 System.Runtime.InteropServices; | |||||
| namespace Tensorflow.Util | |||||
| { | |||||
| /// <summary> | |||||
| /// Represents a lease of a <see cref="SafeHandle"/>. | |||||
| /// </summary> | |||||
| /// <seealso cref="SafeHandleExtensions.Lease"/> | |||||
| public readonly struct SafeHandleLease : IDisposable | |||||
| { | |||||
| private readonly SafeHandle _handle; | |||||
| internal SafeHandleLease(SafeHandle handle) | |||||
| => _handle = handle; | |||||
| public void Dispose() | |||||
| => _handle?.DangerousRelease(); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,43 @@ | |||||
| /***************************************************************************** | |||||
| 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 System.Runtime.InteropServices; | |||||
| namespace Tensorflow.Util | |||||
| { | |||||
| public abstract class SafeTensorflowHandle : SafeHandle | |||||
| { | |||||
| private protected SafeTensorflowHandle() | |||||
| : base(IntPtr.Zero, ownsHandle: true) | |||||
| { | |||||
| } | |||||
| private protected SafeTensorflowHandle(IntPtr handle) | |||||
| : base(IntPtr.Zero, ownsHandle: true) | |||||
| { | |||||
| SetHandle(handle); | |||||
| } | |||||
| private protected SafeTensorflowHandle(IntPtr handle, bool ownsHandle) | |||||
| : base(IntPtr.Zero, ownsHandle) | |||||
| { | |||||
| SetHandle(handle); | |||||
| } | |||||
| public override bool IsInvalid => handle == IntPtr.Zero; | |||||
| } | |||||
| } | |||||
| @@ -189,12 +189,12 @@ namespace Tensorflow | |||||
| var protoHandle = Marshal.AllocHGlobal(bytes.Length); | var protoHandle = Marshal.AllocHGlobal(bytes.Length); | ||||
| Marshal.Copy(bytes, 0, protoHandle, bytes.Length); | Marshal.Copy(bytes, 0, protoHandle, bytes.Length); | ||||
| uint len = (uint)bytes.Length; | uint len = (uint)bytes.Length; | ||||
| c_api.TF_SetAttrValueProto(op_desc, attr.Key, protoHandle, proto_len: len, status: status); | |||||
| c_api.TF_SetAttrValueProto(op_desc, attr.Key, protoHandle, proto_len: len, status: status.Handle); | |||||
| status.Check(true); | status.Check(true); | ||||
| Marshal.FreeHGlobal(protoHandle); | Marshal.FreeHGlobal(protoHandle); | ||||
| } | } | ||||
| var c_op = c_api.TF_FinishOperation(op_desc, status); | |||||
| var c_op = c_api.TF_FinishOperation(op_desc, status.Handle); | |||||
| status.Check(true); | status.Check(true); | ||||
| @@ -125,45 +125,45 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| var feed_out_0 = new TF_Output(feed, 0); | var feed_out_0 = new TF_Output(feed, 0); | ||||
| // Fetch the shape, it should be completely unknown. | // Fetch the shape, it should be completely unknown. | ||||
| int num_dims = c_api.TF_GraphGetTensorNumDims(graph, feed_out_0, s); | |||||
| int num_dims = c_api.TF_GraphGetTensorNumDims(graph, feed_out_0, s.Handle); | |||||
| Assert.IsTrue(s.Code == TF_Code.TF_OK); | Assert.IsTrue(s.Code == TF_Code.TF_OK); | ||||
| EXPECT_EQ(-1, num_dims); | EXPECT_EQ(-1, num_dims); | ||||
| // Set the shape to be unknown, expect no change. | // Set the shape to be unknown, expect no change. | ||||
| c_api.TF_GraphSetTensorShape(graph, feed_out_0, null, -1, s); | |||||
| c_api.TF_GraphSetTensorShape(graph, feed_out_0, null, -1, s.Handle); | |||||
| Assert.IsTrue(s.Code == TF_Code.TF_OK); | Assert.IsTrue(s.Code == TF_Code.TF_OK); | ||||
| num_dims = c_api.TF_GraphGetTensorNumDims(graph, feed_out_0, s); | |||||
| num_dims = c_api.TF_GraphGetTensorNumDims(graph, feed_out_0, s.Handle); | |||||
| EXPECT_EQ(-1, num_dims); | EXPECT_EQ(-1, num_dims); | ||||
| // Set the shape to be 2 x Unknown | // Set the shape to be 2 x Unknown | ||||
| long[] dims = {2, -1}; | long[] dims = {2, -1}; | ||||
| c_api.TF_GraphSetTensorShape(graph, feed_out_0, dims, dims.Length, s); | |||||
| c_api.TF_GraphSetTensorShape(graph, feed_out_0, dims, dims.Length, s.Handle); | |||||
| Assert.IsTrue(s.Code == TF_Code.TF_OK); | Assert.IsTrue(s.Code == TF_Code.TF_OK); | ||||
| num_dims = c_api.TF_GraphGetTensorNumDims(graph, feed_out_0, s); | |||||
| num_dims = c_api.TF_GraphGetTensorNumDims(graph, feed_out_0, s.Handle); | |||||
| EXPECT_EQ(2, num_dims); | EXPECT_EQ(2, num_dims); | ||||
| // Get the dimension vector appropriately. | // Get the dimension vector appropriately. | ||||
| var returned_dims = new long[dims.Length]; | var returned_dims = new long[dims.Length]; | ||||
| c_api.TF_GraphGetTensorShape(graph, feed_out_0, returned_dims, num_dims, s); | |||||
| c_api.TF_GraphGetTensorShape(graph, feed_out_0, returned_dims, num_dims, s.Handle); | |||||
| Assert.IsTrue(s.Code == TF_Code.TF_OK); | Assert.IsTrue(s.Code == TF_Code.TF_OK); | ||||
| Assert.IsTrue(Enumerable.SequenceEqual(dims, returned_dims)); | Assert.IsTrue(Enumerable.SequenceEqual(dims, returned_dims)); | ||||
| // Set to a new valid shape: [2, 3] | // Set to a new valid shape: [2, 3] | ||||
| dims[1] = 3; | dims[1] = 3; | ||||
| c_api.TF_GraphSetTensorShape(graph, feed_out_0, dims, dims.Length, s); | |||||
| c_api.TF_GraphSetTensorShape(graph, feed_out_0, dims, dims.Length, s.Handle); | |||||
| Assert.IsTrue(s.Code == TF_Code.TF_OK); | Assert.IsTrue(s.Code == TF_Code.TF_OK); | ||||
| // Fetch and see that the new value is returned. | // Fetch and see that the new value is returned. | ||||
| c_api.TF_GraphGetTensorShape(graph, feed_out_0, returned_dims, num_dims, s); | |||||
| c_api.TF_GraphGetTensorShape(graph, feed_out_0, returned_dims, num_dims, s.Handle); | |||||
| Assert.IsTrue(s.Code == TF_Code.TF_OK); | Assert.IsTrue(s.Code == TF_Code.TF_OK); | ||||
| Assert.IsTrue(Enumerable.SequenceEqual(dims, returned_dims)); | Assert.IsTrue(Enumerable.SequenceEqual(dims, returned_dims)); | ||||
| // Try to set 'unknown' with unknown rank on the shape and see that | // Try to set 'unknown' with unknown rank on the shape and see that | ||||
| // it doesn't change. | // it doesn't change. | ||||
| c_api.TF_GraphSetTensorShape(graph, feed_out_0, null, -1, s); | |||||
| c_api.TF_GraphSetTensorShape(graph, feed_out_0, null, -1, s.Handle); | |||||
| Assert.IsTrue(s.Code == TF_Code.TF_OK); | Assert.IsTrue(s.Code == TF_Code.TF_OK); | ||||
| c_api.TF_GraphGetTensorShape(graph, feed_out_0, returned_dims, num_dims, s); | |||||
| c_api.TF_GraphGetTensorShape(graph, feed_out_0, returned_dims, num_dims, s.Handle); | |||||
| Assert.IsTrue(s.Code == TF_Code.TF_OK); | Assert.IsTrue(s.Code == TF_Code.TF_OK); | ||||
| EXPECT_EQ(2, num_dims); | EXPECT_EQ(2, num_dims); | ||||
| EXPECT_EQ(2, (int) returned_dims[0]); | EXPECT_EQ(2, (int) returned_dims[0]); | ||||
| @@ -173,21 +173,21 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| // it doesn't change. | // it doesn't change. | ||||
| dims[0] = -1; | dims[0] = -1; | ||||
| dims[1] = -1; | dims[1] = -1; | ||||
| c_api.TF_GraphSetTensorShape(graph, feed_out_0, dims, 2, s); | |||||
| c_api.TF_GraphSetTensorShape(graph, feed_out_0, dims, 2, s.Handle); | |||||
| Assert.IsTrue(s.Code == TF_Code.TF_OK); | Assert.IsTrue(s.Code == TF_Code.TF_OK); | ||||
| c_api.TF_GraphGetTensorShape(graph, feed_out_0, returned_dims, num_dims, s); | |||||
| c_api.TF_GraphGetTensorShape(graph, feed_out_0, returned_dims, num_dims, s.Handle); | |||||
| Assert.IsTrue(s.Code == TF_Code.TF_OK); | Assert.IsTrue(s.Code == TF_Code.TF_OK); | ||||
| EXPECT_EQ(2, num_dims); | EXPECT_EQ(2, num_dims); | ||||
| EXPECT_EQ(2, (int) returned_dims[0]); | EXPECT_EQ(2, (int) returned_dims[0]); | ||||
| EXPECT_EQ(3, (int) returned_dims[1]); | EXPECT_EQ(3, (int) returned_dims[1]); | ||||
| // Try to fetch a shape with the wrong num_dims | // Try to fetch a shape with the wrong num_dims | ||||
| c_api.TF_GraphGetTensorShape(graph, feed_out_0, returned_dims, 5, s); | |||||
| c_api.TF_GraphGetTensorShape(graph, feed_out_0, returned_dims, 5, s.Handle); | |||||
| Assert.IsTrue(s.Code == TF_Code.TF_INVALID_ARGUMENT); | Assert.IsTrue(s.Code == TF_Code.TF_INVALID_ARGUMENT); | ||||
| // Try to set an invalid shape (cannot change 2x3 to a 2x5). | // Try to set an invalid shape (cannot change 2x3 to a 2x5). | ||||
| dims[1] = 5; | dims[1] = 5; | ||||
| c_api.TF_GraphSetTensorShape(graph, feed_out_0, dims, 2, s); | |||||
| c_api.TF_GraphSetTensorShape(graph, feed_out_0, dims, 2, s.Handle); | |||||
| Assert.IsTrue(s.Code == TF_Code.TF_INVALID_ARGUMENT); | Assert.IsTrue(s.Code == TF_Code.TF_INVALID_ARGUMENT); | ||||
| // Test for a scalar. | // Test for a scalar. | ||||
| @@ -195,10 +195,10 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| Assert.IsTrue(s.Code == TF_Code.TF_OK); | Assert.IsTrue(s.Code == TF_Code.TF_OK); | ||||
| var three_out_0 = new TF_Output(three, 0); | var three_out_0 = new TF_Output(three, 0); | ||||
| num_dims = c_api.TF_GraphGetTensorNumDims(graph, three_out_0, s); | |||||
| num_dims = c_api.TF_GraphGetTensorNumDims(graph, three_out_0, s.Handle); | |||||
| Assert.IsTrue(s.Code == TF_Code.TF_OK); | Assert.IsTrue(s.Code == TF_Code.TF_OK); | ||||
| EXPECT_EQ(0, num_dims); | EXPECT_EQ(0, num_dims); | ||||
| c_api.TF_GraphGetTensorShape(graph, feed_out_0, null, num_dims, s); | |||||
| c_api.TF_GraphGetTensorShape(graph, feed_out_0, null, num_dims, s.Handle); | |||||
| //Assert.IsTrue(s.Code == TF_Code.TF_OK); | //Assert.IsTrue(s.Code == TF_Code.TF_OK); | ||||
| // graph.Dispose(); | // graph.Dispose(); | ||||
| @@ -169,7 +169,7 @@ namespace TensorFlowNET.UnitTest.Basics | |||||
| ulong dst_len = (ulong)c_api.TF_StringEncodedSize((UIntPtr)str.Length); | ulong dst_len = (ulong)c_api.TF_StringEncodedSize((UIntPtr)str.Length); | ||||
| Assert.AreEqual(dst_len, (ulong)23); | Assert.AreEqual(dst_len, (ulong)23); | ||||
| IntPtr dst = Marshal.AllocHGlobal((int)dst_len); | IntPtr dst = Marshal.AllocHGlobal((int)dst_len); | ||||
| ulong encoded_len = c_api.TF_StringEncode(handle, (ulong)str.Length, dst, dst_len, status); | |||||
| ulong encoded_len = c_api.TF_StringEncode(handle, (ulong)str.Length, dst, dst_len, status.Handle); | |||||
| Assert.AreEqual((ulong)23, encoded_len); | Assert.AreEqual((ulong)23, encoded_len); | ||||
| Assert.AreEqual(status.Code, TF_Code.TF_OK); | Assert.AreEqual(status.Code, TF_Code.TF_OK); | ||||
| string encoded_str = Marshal.PtrToStringUTF8(dst + sizeof(byte)); | string encoded_str = Marshal.PtrToStringUTF8(dst + sizeof(byte)); | ||||
| @@ -39,7 +39,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| EXPECT_EQ(attr_value.Type, DataType.DtInt32); | EXPECT_EQ(attr_value.Type, DataType.DtInt32); | ||||
| // Test not found errors in TF_Operation*() query functions. | // Test not found errors in TF_Operation*() query functions. | ||||
| EXPECT_EQ(-1, c_api.TF_OperationOutputListLength(feed, "bogus", s)); | |||||
| EXPECT_EQ(-1, c_api.TF_OperationOutputListLength(feed, "bogus", s.Handle)); | |||||
| EXPECT_EQ(TF_Code.TF_INVALID_ARGUMENT, s.Code); | EXPECT_EQ(TF_Code.TF_INVALID_ARGUMENT, s.Code); | ||||
| Assert.IsFalse(c_test_util.GetAttrValue(feed, "missing", ref attr_value, s)); | Assert.IsFalse(c_test_util.GetAttrValue(feed, "missing", ref attr_value, s)); | ||||
| EXPECT_EQ("Operation 'feed' has no attr named 'missing'.", s.Message); | EXPECT_EQ("Operation 'feed' has no attr named 'missing'.", s.Message); | ||||
| @@ -217,7 +217,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| // Export to a GraphDef. | // Export to a GraphDef. | ||||
| var graph_def = new Buffer(); | var graph_def = new Buffer(); | ||||
| c_api.TF_GraphToGraphDef(graph, graph_def, s); | |||||
| c_api.TF_GraphToGraphDef(graph, graph_def, s.Handle); | |||||
| EXPECT_EQ(TF_Code.TF_OK, s.Code); | EXPECT_EQ(TF_Code.TF_OK, s.Code); | ||||
| // Import it, with a prefix, in a fresh graph. | // Import it, with a prefix, in a fresh graph. | ||||
| @@ -225,7 +225,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| graph = new Graph().as_default(); | graph = new Graph().as_default(); | ||||
| var opts = c_api.TF_NewImportGraphDefOptions(); | var opts = c_api.TF_NewImportGraphDefOptions(); | ||||
| c_api.TF_ImportGraphDefOptionsSetPrefix(opts, "imported"); | c_api.TF_ImportGraphDefOptionsSetPrefix(opts, "imported"); | ||||
| c_api.TF_GraphImportGraphDef(graph, graph_def, opts, s); | |||||
| c_api.TF_GraphImportGraphDef(graph, graph_def, opts, s.Handle); | |||||
| EXPECT_EQ(TF_Code.TF_OK, s.Code); | EXPECT_EQ(TF_Code.TF_OK, s.Code); | ||||
| Operation scalar = graph.OperationByName("imported/scalar"); | Operation scalar = graph.OperationByName("imported/scalar"); | ||||
| @@ -268,7 +268,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| EXPECT_EQ(2, c_api.TF_ImportGraphDefOptionsNumReturnOutputs(opts)); | EXPECT_EQ(2, c_api.TF_ImportGraphDefOptionsNumReturnOutputs(opts)); | ||||
| c_api.TF_ImportGraphDefOptionsAddReturnOperation(opts, "scalar"); | c_api.TF_ImportGraphDefOptionsAddReturnOperation(opts, "scalar"); | ||||
| EXPECT_EQ(1, c_api.TF_ImportGraphDefOptionsNumReturnOperations(opts)); | EXPECT_EQ(1, c_api.TF_ImportGraphDefOptionsNumReturnOperations(opts)); | ||||
| var results = c_api.TF_GraphImportGraphDefWithResults(graph, graph_def, opts, s); | |||||
| var results = c_api.TF_GraphImportGraphDefWithResults(graph, graph_def, opts, s.Handle); | |||||
| EXPECT_EQ(TF_Code.TF_OK, s.Code); | EXPECT_EQ(TF_Code.TF_OK, s.Code); | ||||
| Operation scalar2 = graph.OperationByName("imported2/scalar"); | Operation scalar2 = graph.OperationByName("imported2/scalar"); | ||||
| @@ -300,7 +300,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| c_api.TF_ImportGraphDefOptionsSetPrefix(opts, "imported3"); | c_api.TF_ImportGraphDefOptionsSetPrefix(opts, "imported3"); | ||||
| c_api.TF_ImportGraphDefOptionsAddControlDependency(opts, feed); | c_api.TF_ImportGraphDefOptionsAddControlDependency(opts, feed); | ||||
| c_api.TF_ImportGraphDefOptionsAddControlDependency(opts, feed2); | c_api.TF_ImportGraphDefOptionsAddControlDependency(opts, feed2); | ||||
| c_api.TF_GraphImportGraphDef(graph, graph_def, opts, s); | |||||
| c_api.TF_GraphImportGraphDef(graph, graph_def, opts, s.Handle); | |||||
| EXPECT_EQ(TF_Code.TF_OK, s.Code); | EXPECT_EQ(TF_Code.TF_OK, s.Code); | ||||
| var scalar3 = graph.OperationByName("imported3/scalar"); | var scalar3 = graph.OperationByName("imported3/scalar"); | ||||
| @@ -324,7 +324,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| // Export to a graph def so we can import a graph with control dependencies | // Export to a graph def so we can import a graph with control dependencies | ||||
| graph_def = new Buffer(); | graph_def = new Buffer(); | ||||
| c_api.TF_GraphToGraphDef(graph, graph_def, s); | |||||
| c_api.TF_GraphToGraphDef(graph, graph_def, s.Handle); | |||||
| EXPECT_EQ(TF_Code.TF_OK, s.Code); | EXPECT_EQ(TF_Code.TF_OK, s.Code); | ||||
| // Import again, with remapped control dependency, into the same graph | // Import again, with remapped control dependency, into the same graph | ||||
| @@ -332,7 +332,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| opts = c_api.TF_NewImportGraphDefOptions(); | opts = c_api.TF_NewImportGraphDefOptions(); | ||||
| c_api.TF_ImportGraphDefOptionsSetPrefix(opts, "imported4"); | c_api.TF_ImportGraphDefOptionsSetPrefix(opts, "imported4"); | ||||
| c_api.TF_ImportGraphDefOptionsRemapControlDependency(opts, "imported/feed", feed); | c_api.TF_ImportGraphDefOptionsRemapControlDependency(opts, "imported/feed", feed); | ||||
| c_api.TF_GraphImportGraphDef(graph, graph_def, opts, s); | |||||
| c_api.TF_GraphImportGraphDef(graph, graph_def, opts, s.Handle); | |||||
| ASSERT_EQ(TF_Code.TF_OK, s.Code); | ASSERT_EQ(TF_Code.TF_OK, s.Code); | ||||
| var scalar4 = graph.OperationByName("imported4/imported3/scalar"); | var scalar4 = graph.OperationByName("imported4/imported3/scalar"); | ||||
| @@ -50,7 +50,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| private void EXPECT_TF_META(Operation oper, string attr_name, int expected_list_size, TF_AttrType expected_type, uint expected_total_size) | private void EXPECT_TF_META(Operation oper, string attr_name, int expected_list_size, TF_AttrType expected_type, uint expected_total_size) | ||||
| { | { | ||||
| var m = c_api.TF_OperationGetAttrMetadata(oper, attr_name, s_); | |||||
| var m = c_api.TF_OperationGetAttrMetadata(oper, attr_name, s_.Handle); | |||||
| EXPECT_EQ(TF_Code.TF_OK, s_.Code); | EXPECT_EQ(TF_Code.TF_OK, s_.Code); | ||||
| char e = expected_list_size >= 0 ? (char)1 : (char)0; | char e = expected_list_size >= 0 ? (char)1 : (char)0; | ||||
| /*EXPECT_EQ(e, m.is_list); | /*EXPECT_EQ(e, m.is_list); | ||||
| @@ -65,7 +65,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| var desc = init("string"); | var desc = init("string"); | ||||
| c_api.TF_SetAttrString(desc, "v", "bunny", 5); | c_api.TF_SetAttrString(desc, "v", "bunny", 5); | ||||
| var oper = c_api.TF_FinishOperation(desc, s_); | |||||
| var oper = c_api.TF_FinishOperation(desc, s_.Handle); | |||||
| //ASSERT_EQ(TF_Code.TF_OK, s_.Code); | //ASSERT_EQ(TF_Code.TF_OK, s_.Code); | ||||
| //EXPECT_TF_META(oper, "v", -1, TF_AttrType.TF_ATTR_STRING, 5); | //EXPECT_TF_META(oper, "v", -1, TF_AttrType.TF_ATTR_STRING, 5); | ||||
| //var value = new char[5]; | //var value = new char[5]; | ||||
| @@ -61,7 +61,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| private void VerifyCollocation(Operation op, string[] expected) | private void VerifyCollocation(Operation op, string[] expected) | ||||
| { | { | ||||
| var handle = c_api.TF_OperationGetAttrMetadata(op, "_class", s_); | |||||
| var handle = c_api.TF_OperationGetAttrMetadata(op, "_class", s_.Handle); | |||||
| TF_AttrMetadata m = new TF_AttrMetadata(); | TF_AttrMetadata m = new TF_AttrMetadata(); | ||||
| if (expected.Length == 0) | if (expected.Length == 0) | ||||
| { | { | ||||
| @@ -50,7 +50,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| { | { | ||||
| using (var buffer = new Buffer()) | using (var buffer = new Buffer()) | ||||
| { | { | ||||
| c_api.TF_GraphToGraphDef(graph, buffer, s); | |||||
| c_api.TF_GraphToGraphDef(graph, buffer, s.Handle); | |||||
| bool ret = TF_GetCode(s) == TF_OK; | bool ret = TF_GetCode(s) == TF_OK; | ||||
| EXPECT_EQ(TF_OK, TF_GetCode(s)); | EXPECT_EQ(TF_OK, TF_GetCode(s)); | ||||
| if (ret) | if (ret) | ||||
| @@ -113,7 +113,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| IntPtr[] handles = new IntPtr[2] { IntPtr.Zero, IntPtr.Zero }; | IntPtr[] handles = new IntPtr[2] { IntPtr.Zero, IntPtr.Zero }; | ||||
| c_api.TF_AddGradientsWithPrefix(graph_, prefix, outputs, noutputs, inputs, | c_api.TF_AddGradientsWithPrefix(graph_, prefix, outputs, noutputs, inputs, | ||||
| ninputs, grad_inputs, s_, handles); | |||||
| ninputs, grad_inputs, s_.Handle, handles); | |||||
| var op = new Operation(handles[0]); | var op = new Operation(handles[0]); | ||||
| } | } | ||||
| @@ -42,10 +42,10 @@ namespace TensorFlowNET.UnitTest | |||||
| => c_api.TF_AddInput(desc, input); | => c_api.TF_AddInput(desc, input); | ||||
| protected Operation TF_FinishOperation(OperationDescription desc, Status s) | protected Operation TF_FinishOperation(OperationDescription desc, Status s) | ||||
| => c_api.TF_FinishOperation(desc, s); | |||||
| => c_api.TF_FinishOperation(desc, s.Handle); | |||||
| protected void TF_SetAttrTensor(OperationDescription desc, string attrName, Tensor value, Status s) | protected void TF_SetAttrTensor(OperationDescription desc, string attrName, Tensor value, Status s) | ||||
| => c_api.TF_SetAttrTensor(desc, attrName, value, s); | |||||
| => c_api.TF_SetAttrTensor(desc, attrName, value, s.Handle); | |||||
| protected void TF_SetAttrType(OperationDescription desc, string attrName, TF_DataType dtype) | protected void TF_SetAttrType(OperationDescription desc, string attrName, TF_DataType dtype) | ||||
| => c_api.TF_SetAttrType(desc, attrName, dtype); | => c_api.TF_SetAttrType(desc, attrName, dtype); | ||||
| @@ -56,24 +56,21 @@ namespace TensorFlowNET.UnitTest | |||||
| protected TF_DataType TFE_TensorHandleDataType(IntPtr h) | protected TF_DataType TFE_TensorHandleDataType(IntPtr h) | ||||
| => c_api.TFE_TensorHandleDataType(h); | => c_api.TFE_TensorHandleDataType(h); | ||||
| protected int TFE_TensorHandleNumDims(IntPtr h, IntPtr status) | |||||
| protected int TFE_TensorHandleNumDims(IntPtr h, SafeStatusHandle status) | |||||
| => c_api.TFE_TensorHandleNumDims(h, status); | => c_api.TFE_TensorHandleNumDims(h, status); | ||||
| protected TF_Code TF_GetCode(Status s) | protected TF_Code TF_GetCode(Status s) | ||||
| => s.Code; | => s.Code; | ||||
| protected TF_Code TF_GetCode(IntPtr s) | |||||
| protected TF_Code TF_GetCode(SafeStatusHandle s) | |||||
| => c_api.TF_GetCode(s); | => c_api.TF_GetCode(s); | ||||
| protected string TF_Message(IntPtr s) | |||||
| protected string TF_Message(SafeStatusHandle s) | |||||
| => c_api.StringPiece(c_api.TF_Message(s)); | => c_api.StringPiece(c_api.TF_Message(s)); | ||||
| protected IntPtr TF_NewStatus() | |||||
| protected SafeStatusHandle TF_NewStatus() | |||||
| => c_api.TF_NewStatus(); | => c_api.TF_NewStatus(); | ||||
| protected void TF_DeleteStatus(IntPtr s) | |||||
| => c_api.TF_DeleteStatus(s); | |||||
| protected void TF_DeleteTensor(IntPtr t) | protected void TF_DeleteTensor(IntPtr t) | ||||
| => c_api.TF_DeleteTensor(t); | => c_api.TF_DeleteTensor(t); | ||||
| @@ -83,25 +80,25 @@ namespace TensorFlowNET.UnitTest | |||||
| protected ulong TF_TensorByteSize(IntPtr t) | protected ulong TF_TensorByteSize(IntPtr t) | ||||
| => c_api.TF_TensorByteSize(t); | => c_api.TF_TensorByteSize(t); | ||||
| protected void TFE_OpAddInput(IntPtr op, IntPtr h, IntPtr status) | |||||
| protected void TFE_OpAddInput(IntPtr op, IntPtr h, SafeStatusHandle status) | |||||
| => c_api.TFE_OpAddInput(op, h, status); | => c_api.TFE_OpAddInput(op, h, status); | ||||
| protected void TFE_OpSetAttrType(IntPtr op, string attr_name, TF_DataType value) | protected void TFE_OpSetAttrType(IntPtr op, string attr_name, TF_DataType value) | ||||
| => c_api.TFE_OpSetAttrType(op, attr_name, value); | => c_api.TFE_OpSetAttrType(op, attr_name, value); | ||||
| protected void TFE_OpSetAttrShape(IntPtr op, string attr_name, long[] dims, int num_dims, IntPtr out_status) | |||||
| protected void TFE_OpSetAttrShape(IntPtr op, string attr_name, long[] dims, int num_dims, SafeStatusHandle out_status) | |||||
| => c_api.TFE_OpSetAttrShape(op, attr_name, dims, num_dims, out_status); | => c_api.TFE_OpSetAttrShape(op, attr_name, dims, num_dims, out_status); | ||||
| protected void TFE_OpSetAttrString(IntPtr op, string attr_name, string value, uint length) | protected void TFE_OpSetAttrString(IntPtr op, string attr_name, string value, uint length) | ||||
| => c_api.TFE_OpSetAttrString(op, attr_name, value, length); | => c_api.TFE_OpSetAttrString(op, attr_name, value, length); | ||||
| protected IntPtr TFE_NewOp(IntPtr ctx, string op_or_function_name, IntPtr status) | |||||
| protected IntPtr TFE_NewOp(IntPtr ctx, string op_or_function_name, SafeStatusHandle status) | |||||
| => c_api.TFE_NewOp(ctx, op_or_function_name, status); | => c_api.TFE_NewOp(ctx, op_or_function_name, status); | ||||
| protected IntPtr TFE_NewTensorHandle(IntPtr t, IntPtr status) | |||||
| protected IntPtr TFE_NewTensorHandle(IntPtr t, SafeStatusHandle status) | |||||
| => c_api.TFE_NewTensorHandle(t, status); | => c_api.TFE_NewTensorHandle(t, status); | ||||
| protected void TFE_Execute(IntPtr op, IntPtr[] retvals, ref int num_retvals, IntPtr status) | |||||
| protected void TFE_Execute(IntPtr op, IntPtr[] retvals, ref int num_retvals, SafeStatusHandle status) | |||||
| => c_api.TFE_Execute(op, retvals, ref num_retvals, status); | => c_api.TFE_Execute(op, retvals, ref num_retvals, status); | ||||
| protected IntPtr TFE_NewContextOptions() | protected IntPtr TFE_NewContextOptions() | ||||
| @@ -110,19 +107,19 @@ namespace TensorFlowNET.UnitTest | |||||
| protected void TFE_DeleteContext(IntPtr t) | protected void TFE_DeleteContext(IntPtr t) | ||||
| => c_api.TFE_DeleteContext(t); | => c_api.TFE_DeleteContext(t); | ||||
| protected IntPtr TFE_NewContext(IntPtr opts, IntPtr status) | |||||
| protected IntPtr TFE_NewContext(IntPtr opts, SafeStatusHandle status) | |||||
| => c_api.TFE_NewContext(opts, status); | => c_api.TFE_NewContext(opts, status); | ||||
| protected void TFE_DeleteContextOptions(IntPtr opts) | protected void TFE_DeleteContextOptions(IntPtr opts) | ||||
| => c_api.TFE_DeleteContextOptions(opts); | => c_api.TFE_DeleteContextOptions(opts); | ||||
| protected int TFE_OpGetInputLength(IntPtr op, string input_name, IntPtr status) | |||||
| protected int TFE_OpGetInputLength(IntPtr op, string input_name, SafeStatusHandle status) | |||||
| => c_api.TFE_OpGetInputLength(op, input_name, status); | => c_api.TFE_OpGetInputLength(op, input_name, status); | ||||
| protected int TFE_OpAddInputList(IntPtr op, IntPtr[] inputs, int num_inputs, IntPtr status) | |||||
| protected int TFE_OpAddInputList(IntPtr op, IntPtr[] inputs, int num_inputs, SafeStatusHandle status) | |||||
| => c_api.TFE_OpAddInputList(op, inputs, num_inputs, status); | => c_api.TFE_OpAddInputList(op, inputs, num_inputs, status); | ||||
| protected int TFE_OpGetOutputLength(IntPtr op, string input_name, IntPtr status) | |||||
| protected int TFE_OpGetOutputLength(IntPtr op, string input_name, SafeStatusHandle status) | |||||
| => c_api.TFE_OpGetOutputLength(op, input_name, status); | => c_api.TFE_OpGetOutputLength(op, input_name, status); | ||||
| protected void TFE_DeleteTensorHandle(IntPtr h) | protected void TFE_DeleteTensorHandle(IntPtr h) | ||||
| @@ -137,37 +134,37 @@ namespace TensorFlowNET.UnitTest | |||||
| protected IntPtr TFE_ContextGetExecutorForThread(IntPtr ctx) | protected IntPtr TFE_ContextGetExecutorForThread(IntPtr ctx) | ||||
| => c_api.TFE_ContextGetExecutorForThread(ctx); | => c_api.TFE_ContextGetExecutorForThread(ctx); | ||||
| protected void TFE_ExecutorWaitForAllPendingNodes(IntPtr executor, IntPtr status) | |||||
| protected void TFE_ExecutorWaitForAllPendingNodes(IntPtr executor, SafeStatusHandle status) | |||||
| => c_api.TFE_ExecutorWaitForAllPendingNodes(executor, status); | => c_api.TFE_ExecutorWaitForAllPendingNodes(executor, status); | ||||
| protected IntPtr TFE_TensorHandleResolve(IntPtr h, IntPtr status) | |||||
| protected IntPtr TFE_TensorHandleResolve(IntPtr h, SafeStatusHandle status) | |||||
| => c_api.TFE_TensorHandleResolve(h, status); | => c_api.TFE_TensorHandleResolve(h, status); | ||||
| protected string TFE_TensorHandleDeviceName(IntPtr h, IntPtr status) | |||||
| protected string TFE_TensorHandleDeviceName(IntPtr h, SafeStatusHandle status) | |||||
| => c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(h, status)); | => c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(h, status)); | ||||
| protected string TFE_TensorHandleBackingDeviceName(IntPtr h, IntPtr status) | |||||
| protected string TFE_TensorHandleBackingDeviceName(IntPtr h, SafeStatusHandle status) | |||||
| => c_api.StringPiece(c_api.TFE_TensorHandleBackingDeviceName(h, status)); | => c_api.StringPiece(c_api.TFE_TensorHandleBackingDeviceName(h, status)); | ||||
| protected IntPtr TFE_ContextListDevices(IntPtr ctx, IntPtr status) | |||||
| protected IntPtr TFE_ContextListDevices(IntPtr ctx, SafeStatusHandle status) | |||||
| => c_api.TFE_ContextListDevices(ctx, status); | => c_api.TFE_ContextListDevices(ctx, status); | ||||
| protected int TF_DeviceListCount(IntPtr list) | protected int TF_DeviceListCount(IntPtr list) | ||||
| => c_api.TF_DeviceListCount(list); | => c_api.TF_DeviceListCount(list); | ||||
| protected string TF_DeviceListType(IntPtr list, int index, IntPtr status) | |||||
| protected string TF_DeviceListType(IntPtr list, int index, SafeStatusHandle status) | |||||
| => c_api.StringPiece(c_api.TF_DeviceListType(list, index, status)); | => c_api.StringPiece(c_api.TF_DeviceListType(list, index, status)); | ||||
| protected string TF_DeviceListName(IntPtr list, int index, IntPtr status) | |||||
| protected string TF_DeviceListName(IntPtr list, int index, SafeStatusHandle status) | |||||
| => c_api.StringPiece(c_api.TF_DeviceListName(list, index, status)); | => c_api.StringPiece(c_api.TF_DeviceListName(list, index, status)); | ||||
| protected void TF_DeleteDeviceList(IntPtr list) | protected void TF_DeleteDeviceList(IntPtr list) | ||||
| => c_api.TF_DeleteDeviceList(list); | => c_api.TF_DeleteDeviceList(list); | ||||
| protected IntPtr TFE_TensorHandleCopyToDevice(IntPtr h, IntPtr ctx, string device_name, IntPtr status) | |||||
| protected IntPtr TFE_TensorHandleCopyToDevice(IntPtr h, IntPtr ctx, string device_name, SafeStatusHandle status) | |||||
| => c_api.TFE_TensorHandleCopyToDevice(h, ctx, device_name, status); | => c_api.TFE_TensorHandleCopyToDevice(h, ctx, device_name, status); | ||||
| protected void TFE_OpSetDevice(IntPtr op, string device_name, IntPtr status) | |||||
| protected void TFE_OpSetDevice(IntPtr op, string device_name, SafeStatusHandle status) | |||||
| => c_api.TFE_OpSetDevice(op, device_name, status); | => c_api.TFE_OpSetDevice(op, device_name, status); | ||||
| } | } | ||||
| } | } | ||||
| @@ -75,7 +75,7 @@ namespace TensorFlowNET.UnitTest | |||||
| c_api.TF_SessionRun(session_, null, inputs_ptr, input_values_ptr, inputs_ptr.Length, | c_api.TF_SessionRun(session_, null, inputs_ptr, input_values_ptr, inputs_ptr.Length, | ||||
| outputs_ptr, output_values_ptr, outputs_.Count, | outputs_ptr, output_values_ptr, outputs_.Count, | ||||
| targets_ptr, targets_.Count, | targets_ptr, targets_.Count, | ||||
| IntPtr.Zero, s); | |||||
| IntPtr.Zero, s.Handle); | |||||
| s.Check(); | s.Check(); | ||||
| @@ -13,7 +13,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| [TestMethod] | [TestMethod] | ||||
| public void Context() | public void Context() | ||||
| { | { | ||||
| var status = c_api.TF_NewStatus(); | |||||
| using var status = c_api.TF_NewStatus(); | |||||
| var opts = c_api.TFE_NewContextOptions(); | var opts = c_api.TFE_NewContextOptions(); | ||||
| var ctx = c_api.TFE_NewContext(opts, status); | var ctx = c_api.TFE_NewContext(opts, status); | ||||
| @@ -34,7 +34,6 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| } | } | ||||
| c_api.TF_DeleteDeviceList(devices); | c_api.TF_DeleteDeviceList(devices); | ||||
| c_api.TF_DeleteStatus(status); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -18,7 +18,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| unsafe void Execute_MatMul_CPU(bool async) | unsafe void Execute_MatMul_CPU(bool async) | ||||
| { | { | ||||
| var status = TF_NewStatus(); | |||||
| using var status = TF_NewStatus(); | |||||
| var opts = TFE_NewContextOptions(); | var opts = TFE_NewContextOptions(); | ||||
| c_api.TFE_ContextOptionsSetAsync(opts, Convert.ToByte(async)); | c_api.TFE_ContextOptionsSetAsync(opts, Convert.ToByte(async)); | ||||
| var ctx = TFE_NewContext(opts, status); | var ctx = TFE_NewContext(opts, status); | ||||
| @@ -49,7 +49,6 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| EXPECT_EQ(10f, product[1]); | EXPECT_EQ(10f, product[1]); | ||||
| EXPECT_EQ(15f, product[2]); | EXPECT_EQ(15f, product[2]); | ||||
| EXPECT_EQ(22f, product[3]); | EXPECT_EQ(22f, product[3]); | ||||
| TF_DeleteStatus(status); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -14,7 +14,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| [TestMethod] | [TestMethod] | ||||
| public unsafe void OpGetInputAndOutputLengths() | public unsafe void OpGetInputAndOutputLengths() | ||||
| { | { | ||||
| var status = TF_NewStatus(); | |||||
| using var status = TF_NewStatus(); | |||||
| var opts = TFE_NewContextOptions(); | var opts = TFE_NewContextOptions(); | ||||
| var ctx = TFE_NewContext(opts, status); | var ctx = TFE_NewContext(opts, status); | ||||
| CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ||||
| @@ -52,7 +52,6 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| EXPECT_EQ(2, TFE_OpGetOutputLength(identityOp, "output", status)); | EXPECT_EQ(2, TFE_OpGetOutputLength(identityOp, "output", status)); | ||||
| CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ||||
| TF_DeleteStatus(status); | |||||
| TFE_DeleteOp(identityOp); | TFE_DeleteOp(identityOp); | ||||
| TFE_DeleteTensorHandle(input1); | TFE_DeleteTensorHandle(input1); | ||||
| TFE_DeleteTensorHandle(input2); | TFE_DeleteTensorHandle(input2); | ||||
| @@ -16,7 +16,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| [TestMethod] | [TestMethod] | ||||
| public unsafe void OpInferMixedTypeInputListAttrs() | public unsafe void OpInferMixedTypeInputListAttrs() | ||||
| { | { | ||||
| var status = TF_NewStatus(); | |||||
| using var status = TF_NewStatus(); | |||||
| var opts = TFE_NewContextOptions(); | var opts = TFE_NewContextOptions(); | ||||
| var ctx = TFE_NewContext(opts, status); | var ctx = TFE_NewContext(opts, status); | ||||
| CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ||||
| @@ -45,7 +45,6 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| TFE_Execute(assertOp, retvals, ref num_retvals, status); | TFE_Execute(assertOp, retvals, ref num_retvals, status); | ||||
| EXPECT_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | EXPECT_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ||||
| TF_DeleteStatus(status); | |||||
| TFE_DeleteOp(assertOp); | TFE_DeleteOp(assertOp); | ||||
| TFE_DeleteTensorHandle(condition); | TFE_DeleteTensorHandle(condition); | ||||
| TFE_DeleteTensorHandle(t1); | TFE_DeleteTensorHandle(t1); | ||||
| @@ -13,7 +13,7 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| [TestMethod] | [TestMethod] | ||||
| public unsafe void Variables() | public unsafe void Variables() | ||||
| { | { | ||||
| var status = c_api.TF_NewStatus(); | |||||
| using var status = c_api.TF_NewStatus(); | |||||
| var opts = TFE_NewContextOptions(); | var opts = TFE_NewContextOptions(); | ||||
| var ctx = TFE_NewContext(opts, status); | var ctx = TFE_NewContext(opts, status); | ||||
| ASSERT_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ASSERT_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ||||
| @@ -49,7 +49,6 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| TFE_DeleteTensorHandle(value_handle[0]); | TFE_DeleteTensorHandle(value_handle[0]); | ||||
| TFE_DeleteContext(ctx); | TFE_DeleteContext(ctx); | ||||
| CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ||||
| TF_DeleteStatus(status); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -18,17 +18,16 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| var t = c_api.TF_AllocateTensor(TF_FLOAT, dims, dims.Length, (ulong)data.Length * sizeof(float)); | var t = c_api.TF_AllocateTensor(TF_FLOAT, dims, dims.Length, (ulong)data.Length * sizeof(float)); | ||||
| tf.memcpy(c_api.TF_TensorData(t), data, data.Length * sizeof(float)); | tf.memcpy(c_api.TF_TensorData(t), data, data.Length * sizeof(float)); | ||||
| var status = c_api.TF_NewStatus(); | |||||
| using var status = c_api.TF_NewStatus(); | |||||
| var th = c_api.TFE_NewTensorHandle(t, status); | var th = c_api.TFE_NewTensorHandle(t, status); | ||||
| CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ||||
| c_api.TF_DeleteTensor(t); | c_api.TF_DeleteTensor(t); | ||||
| c_api.TF_DeleteStatus(status); | |||||
| return th; | return th; | ||||
| } | } | ||||
| IntPtr MatMulOp(IntPtr ctx, IntPtr a, IntPtr b) | IntPtr MatMulOp(IntPtr ctx, IntPtr a, IntPtr b) | ||||
| { | { | ||||
| var status = TF_NewStatus(); | |||||
| using var status = TF_NewStatus(); | |||||
| var op = TFE_NewOp(ctx, "MatMul", status); | var op = TFE_NewOp(ctx, "MatMul", status); | ||||
| CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ||||
| @@ -36,7 +35,6 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ||||
| TFE_OpAddInput(op, b, status); | TFE_OpAddInput(op, b, status); | ||||
| CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ||||
| TF_DeleteStatus(status); | |||||
| TFE_OpSetAttrType(op, "T", TFE_TensorHandleDataType(a)); | TFE_OpSetAttrType(op, "T", TFE_TensorHandleDataType(a)); | ||||
| return op; | return op; | ||||
| @@ -69,19 +67,18 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| IntPtr ShapeOp(IntPtr ctx, IntPtr a) | IntPtr ShapeOp(IntPtr ctx, IntPtr a) | ||||
| { | { | ||||
| var status = TF_NewStatus(); | |||||
| using var status = TF_NewStatus(); | |||||
| var op = TFE_NewOp(ctx, "Shape", status); | var op = TFE_NewOp(ctx, "Shape", status); | ||||
| CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ||||
| TFE_OpAddInput(op, a, status); | TFE_OpAddInput(op, a, status); | ||||
| CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ||||
| TF_DeleteStatus(status); | |||||
| TFE_OpSetAttrType(op, "T", TFE_TensorHandleDataType(a)); | TFE_OpSetAttrType(op, "T", TFE_TensorHandleDataType(a)); | ||||
| return op; | return op; | ||||
| } | } | ||||
| unsafe IntPtr CreateVariable(IntPtr ctx, float value, IntPtr status) | |||||
| unsafe IntPtr CreateVariable(IntPtr ctx, float value, SafeStatusHandle status) | |||||
| { | { | ||||
| var op = TFE_NewOp(ctx, "VarHandleOp", status); | var op = TFE_NewOp(ctx, "VarHandleOp", status); | ||||
| if (TF_GetCode(status) != TF_OK) return IntPtr.Zero; | if (TF_GetCode(status) != TF_OK) return IntPtr.Zero; | ||||
| @@ -128,11 +125,10 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| var data = new int[] { 1 }; | var data = new int[] { 1 }; | ||||
| var t = c_api.TF_AllocateTensor(TF_DataType.TF_INT32, dims, 1, sizeof(int)); | var t = c_api.TF_AllocateTensor(TF_DataType.TF_INT32, dims, 1, sizeof(int)); | ||||
| tf.memcpy(TF_TensorData(t), data, TF_TensorByteSize(t)); | tf.memcpy(TF_TensorData(t), data, TF_TensorByteSize(t)); | ||||
| var status = TF_NewStatus(); | |||||
| using var status = TF_NewStatus(); | |||||
| var th = c_api.TFE_NewTensorHandle(t, status); | var th = c_api.TFE_NewTensorHandle(t, status); | ||||
| CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ||||
| TF_DeleteTensor(t); | TF_DeleteTensor(t); | ||||
| TF_DeleteStatus(status); | |||||
| return th; | return th; | ||||
| } | } | ||||
| @@ -141,11 +137,10 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| var data = new[] { value }; | var data = new[] { value }; | ||||
| var t = c_api.TF_AllocateTensor(TF_BOOL, null, 0, sizeof(bool)); | var t = c_api.TF_AllocateTensor(TF_BOOL, null, 0, sizeof(bool)); | ||||
| tf.memcpy(TF_TensorData(t), data, TF_TensorByteSize(t)); | tf.memcpy(TF_TensorData(t), data, TF_TensorByteSize(t)); | ||||
| var status = TF_NewStatus(); | |||||
| using var status = TF_NewStatus(); | |||||
| var th = TFE_NewTensorHandle(t, status); | var th = TFE_NewTensorHandle(t, status); | ||||
| CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ||||
| TF_DeleteTensor(t); | TF_DeleteTensor(t); | ||||
| TF_DeleteStatus(status); | |||||
| return th; | return th; | ||||
| } | } | ||||
| @@ -154,11 +149,10 @@ namespace TensorFlowNET.UnitTest.NativeAPI | |||||
| var data = new [] { value }; | var data = new [] { value }; | ||||
| var t = c_api.TF_AllocateTensor(TF_FLOAT, null, 0, sizeof(float)); | var t = c_api.TF_AllocateTensor(TF_FLOAT, null, 0, sizeof(float)); | ||||
| tf.memcpy(TF_TensorData(t), data, TF_TensorByteSize(t)); | tf.memcpy(TF_TensorData(t), data, TF_TensorByteSize(t)); | ||||
| var status = TF_NewStatus(); | |||||
| using var status = TF_NewStatus(); | |||||
| var th = TFE_NewTensorHandle(t, status); | var th = TFE_NewTensorHandle(t, status); | ||||
| CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status)); | ||||
| TF_DeleteTensor(t); | TF_DeleteTensor(t); | ||||
| TF_DeleteStatus(status); | |||||
| return th; | return th; | ||||
| } | } | ||||
| } | } | ||||
| @@ -24,7 +24,7 @@ namespace TensorFlowNET.UnitTest | |||||
| c_api.TF_AddInputList(desc, inputs, inputs.Length); | c_api.TF_AddInputList(desc, inputs, inputs.Length); | ||||
| var op = c_api.TF_FinishOperation(desc, s); | |||||
| var op = c_api.TF_FinishOperation(desc, s.Handle); | |||||
| s.Check(); | s.Check(); | ||||
| return op; | return op; | ||||
| @@ -38,7 +38,7 @@ namespace TensorFlowNET.UnitTest | |||||
| { | { | ||||
| using (var buffer = new Buffer()) | using (var buffer = new Buffer()) | ||||
| { | { | ||||
| c_api.TF_OperationGetAttrValueProto(oper, attr_name, buffer, s); | |||||
| c_api.TF_OperationGetAttrValueProto(oper, attr_name, buffer, s.Handle); | |||||
| attr_value = AttrValue.Parser.ParseFrom(buffer.MemoryBlock.Stream()); | attr_value = AttrValue.Parser.ParseFrom(buffer.MemoryBlock.Stream()); | ||||
| } | } | ||||
| @@ -53,7 +53,7 @@ namespace TensorFlowNET.UnitTest | |||||
| using (var s = new Status()) | using (var s = new Status()) | ||||
| using (var buffer = new Buffer()) | using (var buffer = new Buffer()) | ||||
| { | { | ||||
| c_api.TF_GraphToGraphDef(graph, buffer, s); | |||||
| c_api.TF_GraphToGraphDef(graph, buffer, s.Handle); | |||||
| s.Check(); | s.Check(); | ||||
| return GraphDef.Parser.ParseFrom(buffer.MemoryBlock.Stream()); | return GraphDef.Parser.ParseFrom(buffer.MemoryBlock.Stream()); | ||||
| } | } | ||||
| @@ -175,7 +175,7 @@ namespace TensorFlowNET.UnitTest | |||||
| OperationDescription desc = c_api.TF_NewOperation(graph, "Neg", name); | OperationDescription desc = c_api.TF_NewOperation(graph, "Neg", name); | ||||
| var neg_input = new TF_Output(n, 0); | var neg_input = new TF_Output(n, 0); | ||||
| c_api.TF_AddInput(desc, neg_input); | c_api.TF_AddInput(desc, neg_input); | ||||
| var op = c_api.TF_FinishOperation(desc, s); | |||||
| var op = c_api.TF_FinishOperation(desc, s.Handle); | |||||
| s.Check(); | s.Check(); | ||||
| return op; | return op; | ||||
| @@ -193,7 +193,7 @@ namespace TensorFlowNET.UnitTest | |||||
| c_api.TF_SetAttrShape(desc, "shape", dims, dims.Length); | c_api.TF_SetAttrShape(desc, "shape", dims, dims.Length); | ||||
| } | } | ||||
| var op = c_api.TF_FinishOperation(desc, s); | |||||
| var op = c_api.TF_FinishOperation(desc, s.Handle); | |||||
| s.Check(); | s.Check(); | ||||
| return op; | return op; | ||||
| @@ -205,10 +205,10 @@ namespace TensorFlowNET.UnitTest | |||||
| lock (Locks.ProcessWide) | lock (Locks.ProcessWide) | ||||
| { | { | ||||
| var desc = c_api.TF_NewOperation(graph, "Const", name); | var desc = c_api.TF_NewOperation(graph, "Const", name); | ||||
| c_api.TF_SetAttrTensor(desc, "value", t, s); | |||||
| c_api.TF_SetAttrTensor(desc, "value", t, s.Handle); | |||||
| s.Check(); | s.Check(); | ||||
| c_api.TF_SetAttrType(desc, "dtype", t.dtype); | c_api.TF_SetAttrType(desc, "dtype", t.dtype); | ||||
| var op = c_api.TF_FinishOperation(desc, s); | |||||
| var op = c_api.TF_FinishOperation(desc, s.Handle); | |||||
| s.Check(); | s.Check(); | ||||
| return op; | return op; | ||||