diff --git a/src/TensorFlowNET.Core/Buffer.cs b/src/TensorFlowNET.Core/Buffers/Buffer.cs similarity index 100% rename from src/TensorFlowNET.Core/Buffer.cs rename to src/TensorFlowNET.Core/Buffers/Buffer.cs diff --git a/src/TensorFlowNET.Core/Tensorflow/TF_Buffer.cs b/src/TensorFlowNET.Core/Buffers/TF_Buffer.cs similarity index 100% rename from src/TensorFlowNET.Core/Tensorflow/TF_Buffer.cs rename to src/TensorFlowNET.Core/Buffers/TF_Buffer.cs diff --git a/src/TensorFlowNET.Core/Buffers/c_api.buffer.cs b/src/TensorFlowNET.Core/Buffers/c_api.buffer.cs new file mode 100644 index 00000000..0cc081c2 --- /dev/null +++ b/src/TensorFlowNET.Core/Buffers/c_api.buffer.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; + +namespace Tensorflow +{ + public static partial class c_api + { + [DllImport(TensorFlowLibName)] + public static extern string TF_GetBuffer(IntPtr buffer); + } +} diff --git a/src/TensorFlowNET.Core/Graph.cs b/src/TensorFlowNET.Core/Graphs/Graph.cs similarity index 100% rename from src/TensorFlowNET.Core/Graph.cs rename to src/TensorFlowNET.Core/Graphs/Graph.cs diff --git a/src/TensorFlowNET.Core/Tensorflow/TF_Input.cs b/src/TensorFlowNET.Core/Graphs/TF_Input.cs similarity index 100% rename from src/TensorFlowNET.Core/Tensorflow/TF_Input.cs rename to src/TensorFlowNET.Core/Graphs/TF_Input.cs diff --git a/src/TensorFlowNET.Core/Tensorflow/TF_Output.cs b/src/TensorFlowNET.Core/Graphs/TF_Output.cs similarity index 100% rename from src/TensorFlowNET.Core/Tensorflow/TF_Output.cs rename to src/TensorFlowNET.Core/Graphs/TF_Output.cs diff --git a/src/TensorFlowNET.Core/Graphs/c_api.graph.cs b/src/TensorFlowNET.Core/Graphs/c_api.graph.cs new file mode 100644 index 00000000..337fdea9 --- /dev/null +++ b/src/TensorFlowNET.Core/Graphs/c_api.graph.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; + +namespace Tensorflow +{ + public static partial class c_api + { + [DllImport(TensorFlowLibName)] + public static extern void TF_GraphGetOpDef(IntPtr graph, string op_name, IntPtr output_op_def, IntPtr status); + + [DllImport(TensorFlowLibName)] + public static unsafe extern IntPtr TF_NewGraph(); + } +} diff --git a/src/TensorFlowNET.Core/MonoPInvokeCallbackAttribute.cs b/src/TensorFlowNET.Core/MonoPInvokeCallbackAttribute.cs deleted file mode 100644 index 201e92c8..00000000 --- a/src/TensorFlowNET.Core/MonoPInvokeCallbackAttribute.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow -{ - public sealed class MonoPInvokeCallbackAttribute : Attribute - { - /// - /// Use this constructor to annotate the type of the callback function that - /// will be invoked from unmanaged code. - /// - /// T. - public MonoPInvokeCallbackAttribute(Type t) { } - } -} diff --git a/src/TensorFlowNET.Core/OpDefLibrary.cs b/src/TensorFlowNET.Core/Operations/OpDefLibrary.cs similarity index 100% rename from src/TensorFlowNET.Core/OpDefLibrary.cs rename to src/TensorFlowNET.Core/Operations/OpDefLibrary.cs diff --git a/src/TensorFlowNET.Core/Operation.cs b/src/TensorFlowNET.Core/Operations/Operation.cs similarity index 100% rename from src/TensorFlowNET.Core/Operation.cs rename to src/TensorFlowNET.Core/Operations/Operation.cs diff --git a/src/TensorFlowNET.Core/Tensorflow/TF_OperationDescription.cs b/src/TensorFlowNET.Core/Operations/TF_OperationDescription.cs similarity index 100% rename from src/TensorFlowNET.Core/Tensorflow/TF_OperationDescription.cs rename to src/TensorFlowNET.Core/Operations/TF_OperationDescription.cs diff --git a/src/TensorFlowNET.Core/Operations/c_api.ops.cs b/src/TensorFlowNET.Core/Operations/c_api.ops.cs new file mode 100644 index 00000000..0422aa75 --- /dev/null +++ b/src/TensorFlowNET.Core/Operations/c_api.ops.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; + +namespace Tensorflow +{ + public static partial class c_api + { + /// + /// For inputs that take a single tensor. + /// + /// + /// + [DllImport(TensorFlowLibName)] + public static unsafe extern void TF_AddInput(TF_OperationDescription desc, TF_Output input); + + [DllImport(TensorFlowLibName)] + public static unsafe extern IntPtr TF_FinishOperation(TF_OperationDescription desc, IntPtr status); + + [DllImport(TensorFlowLibName)] + public static unsafe extern TF_OperationDescription TF_NewOperation(IntPtr graph, string opType, string oper_name); + + [DllImport(TensorFlowLibName)] + public static extern unsafe int TF_OperationNumOutputs(IntPtr oper); + + [DllImport(TensorFlowLibName)] + public static extern unsafe void TF_SetAttrValueProto(TF_OperationDescription desc, string attr_name, IntPtr proto, UIntPtr proto_len, IntPtr status); + + [DllImport(TensorFlowLibName)] + public static extern unsafe void TF_SetAttrTensor(TF_OperationDescription desc, string attr_name, IntPtr value, IntPtr status); + + [DllImport(TensorFlowLibName)] + public static extern unsafe void TF_SetAttrType(TF_OperationDescription desc, string attr_name, TF_DataType value); + } +} diff --git a/src/TensorFlowNET.Core/ops/gen_array_ops.cs b/src/TensorFlowNET.Core/Operations/gen_array_ops.cs similarity index 100% rename from src/TensorFlowNET.Core/ops/gen_array_ops.cs rename to src/TensorFlowNET.Core/Operations/gen_array_ops.cs diff --git a/src/TensorFlowNET.Core/ops/gen_math_ops.cs b/src/TensorFlowNET.Core/Operations/gen_math_ops.cs similarity index 100% rename from src/TensorFlowNET.Core/ops/gen_math_ops.cs rename to src/TensorFlowNET.Core/Operations/gen_math_ops.cs diff --git a/src/TensorFlowNET.Core/ops.cs b/src/TensorFlowNET.Core/Operations/ops.cs similarity index 100% rename from src/TensorFlowNET.Core/ops.cs rename to src/TensorFlowNET.Core/Operations/ops.cs diff --git a/src/TensorFlowNET.Core/Tensorflow/AttrValue.cs b/src/TensorFlowNET.Core/Protobuf/AttrValue.cs similarity index 100% rename from src/TensorFlowNET.Core/Tensorflow/AttrValue.cs rename to src/TensorFlowNET.Core/Protobuf/AttrValue.cs diff --git a/src/TensorFlowNET.Core/Tensorflow/NodeDef.cs b/src/TensorFlowNET.Core/Protobuf/NodeDef.cs similarity index 100% rename from src/TensorFlowNET.Core/Tensorflow/NodeDef.cs rename to src/TensorFlowNET.Core/Protobuf/NodeDef.cs diff --git a/src/TensorFlowNET.Core/Tensorflow/OpDef.cs b/src/TensorFlowNET.Core/Protobuf/OpDef.cs similarity index 100% rename from src/TensorFlowNET.Core/Tensorflow/OpDef.cs rename to src/TensorFlowNET.Core/Protobuf/OpDef.cs diff --git a/src/TensorFlowNET.Core/Tensorflow/README.md b/src/TensorFlowNET.Core/Protobuf/README.md similarity index 100% rename from src/TensorFlowNET.Core/Tensorflow/README.md rename to src/TensorFlowNET.Core/Protobuf/README.md diff --git a/src/TensorFlowNET.Core/Tensorflow/ResourceHandle.cs b/src/TensorFlowNET.Core/Protobuf/ResourceHandle.cs similarity index 100% rename from src/TensorFlowNET.Core/Tensorflow/ResourceHandle.cs rename to src/TensorFlowNET.Core/Protobuf/ResourceHandle.cs diff --git a/src/TensorFlowNET.Core/Tensorflow/Tensor.cs b/src/TensorFlowNET.Core/Protobuf/Tensor.cs similarity index 100% rename from src/TensorFlowNET.Core/Tensorflow/Tensor.cs rename to src/TensorFlowNET.Core/Protobuf/Tensor.cs diff --git a/src/TensorFlowNET.Core/Tensorflow/TensorShape.cs b/src/TensorFlowNET.Core/Protobuf/TensorShape.cs similarity index 100% rename from src/TensorFlowNET.Core/Tensorflow/TensorShape.cs rename to src/TensorFlowNET.Core/Protobuf/TensorShape.cs diff --git a/src/TensorFlowNET.Core/Tensorflow/Types.cs b/src/TensorFlowNET.Core/Protobuf/Types.cs similarity index 100% rename from src/TensorFlowNET.Core/Tensorflow/Types.cs rename to src/TensorFlowNET.Core/Protobuf/Types.cs diff --git a/src/TensorFlowNET.Core/Tensorflow/op_list_proto_array.bin b/src/TensorFlowNET.Core/Protobuf/op_list_proto_array.bin similarity index 100% rename from src/TensorFlowNET.Core/Tensorflow/op_list_proto_array.bin rename to src/TensorFlowNET.Core/Protobuf/op_list_proto_array.bin diff --git a/src/TensorFlowNET.Core/Tensorflow/op_list_proto_math.bin b/src/TensorFlowNET.Core/Protobuf/op_list_proto_math.bin similarity index 100% rename from src/TensorFlowNET.Core/Tensorflow/op_list_proto_math.bin rename to src/TensorFlowNET.Core/Protobuf/op_list_proto_math.bin diff --git a/src/TensorFlowNET.Core/Session/BaseSession.cs b/src/TensorFlowNET.Core/Sessions/BaseSession.cs similarity index 100% rename from src/TensorFlowNET.Core/Session/BaseSession.cs rename to src/TensorFlowNET.Core/Sessions/BaseSession.cs diff --git a/src/TensorFlowNET.Core/Session/Session.cs b/src/TensorFlowNET.Core/Sessions/Session.cs similarity index 100% rename from src/TensorFlowNET.Core/Session/Session.cs rename to src/TensorFlowNET.Core/Sessions/Session.cs diff --git a/src/TensorFlowNET.Core/Session/_ElementFetchMapper.cs b/src/TensorFlowNET.Core/Sessions/_ElementFetchMapper.cs similarity index 100% rename from src/TensorFlowNET.Core/Session/_ElementFetchMapper.cs rename to src/TensorFlowNET.Core/Sessions/_ElementFetchMapper.cs diff --git a/src/TensorFlowNET.Core/Session/_FetchHandler.cs b/src/TensorFlowNET.Core/Sessions/_FetchHandler.cs similarity index 100% rename from src/TensorFlowNET.Core/Session/_FetchHandler.cs rename to src/TensorFlowNET.Core/Sessions/_FetchHandler.cs diff --git a/src/TensorFlowNET.Core/Session/_FetchMapper.cs b/src/TensorFlowNET.Core/Sessions/_FetchMapper.cs similarity index 100% rename from src/TensorFlowNET.Core/Session/_FetchMapper.cs rename to src/TensorFlowNET.Core/Sessions/_FetchMapper.cs diff --git a/src/TensorFlowNET.Core/Sessions/c_api.session.cs b/src/TensorFlowNET.Core/Sessions/c_api.session.cs new file mode 100644 index 00000000..49c32890 --- /dev/null +++ b/src/TensorFlowNET.Core/Sessions/c_api.session.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; + +namespace Tensorflow +{ + public static partial class c_api + { + /// + /// Destroy an options object. + /// + /// + [DllImport(TensorFlowLibName)] + public static unsafe extern void TF_DeleteSessionOptions(IntPtr opts); + + /// + /// Return a new execution session with the associated graph, or NULL on + /// error. Does not take ownership of any input parameters. + /// + /// + /// + /// + /// + [DllImport(TensorFlowLibName)] + public static extern IntPtr TF_NewSession(IntPtr graph, IntPtr opts, IntPtr status); + + /// + /// Return a new options object. + /// + /// + [DllImport(TensorFlowLibName)] + public static extern IntPtr TF_NewSessionOptions(); + + /// + /// Run the graph associated with the session starting with the supplied inputs + /// (inputs[0,ninputs-1] with corresponding values in input_values[0,ninputs-1]). + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + [DllImport(TensorFlowLibName)] + public static extern unsafe void TF_SessionRun(IntPtr session, IntPtr run_options, + TF_Output[] inputs, IntPtr[] input_values, int ninputs, + TF_Output[] outputs, IntPtr[] output_values, int noutputs, + IntPtr[] target_opers, int ntargets, + IntPtr run_metadata, + IntPtr status); + } +} diff --git a/src/TensorFlowNET.Core/Status.cs b/src/TensorFlowNET.Core/Status/Status.cs similarity index 100% rename from src/TensorFlowNET.Core/Status.cs rename to src/TensorFlowNET.Core/Status/Status.cs diff --git a/src/TensorFlowNET.Core/Tensorflow/TF_Code.cs b/src/TensorFlowNET.Core/Status/TF_Code.cs similarity index 100% rename from src/TensorFlowNET.Core/Tensorflow/TF_Code.cs rename to src/TensorFlowNET.Core/Status/TF_Code.cs diff --git a/src/TensorFlowNET.Core/Status/c_api.status.cs b/src/TensorFlowNET.Core/Status/c_api.status.cs new file mode 100644 index 00000000..efd2a959 --- /dev/null +++ b/src/TensorFlowNET.Core/Status/c_api.status.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; + +namespace Tensorflow +{ + public static partial class c_api + { + /// + /// Delete a previously created status object. + /// + /// + [DllImport(TensorFlowLibName)] + public static unsafe extern void TF_DeleteStatus(IntPtr s); + + /// + /// Return the code record in *s. + /// + /// + /// + [DllImport(TensorFlowLibName)] + public static extern unsafe TF_Code TF_GetCode(IntPtr s); + + /// + /// Return a pointer to the (null-terminated) error message in *s. + /// The return value points to memory that is only usable until the next + /// mutation to *s. Always returns an empty string if TF_GetCode(s) is TF_OK. + /// + /// + /// + [DllImport(TensorFlowLibName)] + public static extern unsafe string TF_Message(IntPtr s); + + /// + /// Return a new status object. + /// + /// + [DllImport(TensorFlowLibName)] + public static unsafe extern IntPtr TF_NewStatus(); + + /// + /// Record in *s. Any previous information is lost. + /// A common use is to clear a status: TF_SetStatus(s, TF_OK, ""); + /// + /// + /// + /// + [DllImport(TensorFlowLibName)] + public static extern void TF_SetStatus(IntPtr s, TF_Code code, string msg); + } +} diff --git a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj index bf591c6c..8689e8c9 100644 --- a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj +++ b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj @@ -12,7 +12,7 @@ - + @@ -27,10 +27,10 @@ PreserveNewest - + PreserveNewest - + PreserveNewest diff --git a/src/TensorFlowNET.Core/TensorShape.cs b/src/TensorFlowNET.Core/Tensors/TensorShape.cs similarity index 100% rename from src/TensorFlowNET.Core/TensorShape.cs rename to src/TensorFlowNET.Core/Tensors/TensorShape.cs diff --git a/src/TensorFlowNET.Core/Tensors/c_api.tensor.cs b/src/TensorFlowNET.Core/Tensors/c_api.tensor.cs new file mode 100644 index 00000000..a99d14bb --- /dev/null +++ b/src/TensorFlowNET.Core/Tensors/c_api.tensor.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; + +namespace Tensorflow +{ + public static partial class c_api + { + /// + /// returns the sizeof() for the underlying type corresponding to the given TF_DataType enum value. + /// + /// + /// + [DllImport(TensorFlowLibName)] + public static unsafe extern ulong TF_DataTypeSize(TF_DataType dt); + + /// + /// Destroy a tensor. + /// + /// + [DllImport(TensorFlowLibName)] + public static unsafe extern void TF_DeleteTensor(IntPtr tensor); + + /// + /// Return the length of the tensor in the "dim_index" dimension. + /// REQUIRES: 0 <= dim_index < TF_NumDims(tensor) + /// + /// + /// + /// + [DllImport(TensorFlowLibName)] + public static extern unsafe long TF_Dim(IntPtr tensor, int dim_index); + + /// + /// Return a new tensor that holds the bytes data[0,len-1] + /// + /// + /// + /// + /// + /// num_bytes, ex: 6 * sizeof(float) + /// + /// + /// + [DllImport(TensorFlowLibName)] + public static extern unsafe IntPtr TF_NewTensor(TF_DataType dataType, long[] dims, int num_dims, IntPtr data, UIntPtr len, Deallocator deallocator, ref bool deallocator_arg); + + /// + /// Return the number of dimensions that the tensor has. + /// + /// + /// + [DllImport(TensorFlowLibName)] + public static extern unsafe int TF_NumDims(IntPtr tensor); + + /// + /// Return the size of the underlying data in bytes. + /// + /// + /// + [DllImport(TensorFlowLibName)] + public static extern unsafe ulong TF_TensorByteSize(IntPtr tensor); + + /// + /// Return a pointer to the underlying data buffer. + /// + /// + /// + [DllImport(TensorFlowLibName)] + public static extern unsafe IntPtr TF_TensorData(IntPtr tensor); + + /// + /// Return the type of a tensor element. + /// + /// + /// + [DllImport(TensorFlowLibName)] + public static extern unsafe TF_DataType TF_TensorType(IntPtr tensor); + } +} diff --git a/src/TensorFlowNET.Core/c_api.cs b/src/TensorFlowNET.Core/c_api.cs index f31553b6..bb49a049 100644 --- a/src/TensorFlowNET.Core/c_api.cs +++ b/src/TensorFlowNET.Core/c_api.cs @@ -5,156 +5,18 @@ using System.Text; namespace Tensorflow { - public static class c_api + /// + /// C API for TensorFlow. + /// + /// The API leans towards simplicity and uniformity instead of convenience + /// since most usage will be by language specific wrappers. + /// + public static partial class c_api { public const string TensorFlowLibName = "tensorflow"; - /// - /// For inputs that take a single tensor. - /// - /// - /// - [DllImport(TensorFlowLibName)] - public static unsafe extern void TF_AddInput(TF_OperationDescription desc, TF_Output input); - - /// - /// returns the sizeof() for the underlying type corresponding to the given TF_DataType enum value. - /// - /// - /// - [DllImport(TensorFlowLibName)] - public static unsafe extern ulong TF_DataTypeSize(TF_DataType dt); - - [DllImport(TensorFlowLibName)] - public static unsafe extern void TF_DeleteSessionOptions(IntPtr opts); - - /// - /// Delete a previously created status object. - /// - /// - [DllImport(TensorFlowLibName)] - public static unsafe extern void TF_DeleteStatus(IntPtr s); - - /// - /// Destroy a tensor. - /// - /// - [DllImport(TensorFlowLibName)] - public static unsafe extern void TF_DeleteTensor(IntPtr tensor); - - [DllImport(TensorFlowLibName)] - public static extern unsafe long TF_Dim(IntPtr tensor, int dim_index); - - [DllImport(TensorFlowLibName)] - public static unsafe extern IntPtr TF_FinishOperation(TF_OperationDescription desc, IntPtr status); - - [DllImport(TensorFlowLibName)] - public static extern string TF_GetBuffer(IntPtr buffer); - - [DllImport(TensorFlowLibName)] - public static extern unsafe TF_Code TF_GetCode(IntPtr s); - - [DllImport(TensorFlowLibName)] - public static extern void TF_GraphGetOpDef(IntPtr graph, string op_name, IntPtr output_op_def, IntPtr status); - - [DllImport(TensorFlowLibName)] - public static extern unsafe string TF_Message(IntPtr s); - - [DllImport(TensorFlowLibName)] - public static unsafe extern IntPtr TF_NewGraph(); - - [DllImport(TensorFlowLibName)] - public static unsafe extern TF_OperationDescription TF_NewOperation(IntPtr graph, string opType, string oper_name); - - /// - /// Return a new status object. - /// - /// - [DllImport(TensorFlowLibName)] - public static unsafe extern IntPtr TF_NewStatus(); - - /// - /// Return a new tensor that holds the bytes data[0,len-1] - /// - /// - /// - /// - /// - /// num_bytes, ex: 6 * sizeof(float) - /// - /// - /// - [DllImport(TensorFlowLibName)] - public static extern unsafe IntPtr TF_NewTensor(TF_DataType dataType, long[] dims, int num_dims, IntPtr data, UIntPtr len, Deallocator deallocator, ref bool deallocator_arg); - public delegate void Deallocator(IntPtr data, IntPtr size, ref bool deallocatorData); - /// - /// Return the number of dimensions that the tensor has. - /// - /// - /// - [DllImport(TensorFlowLibName)] - public static extern unsafe int TF_NumDims(IntPtr tensor); - - [DllImport(TensorFlowLibName)] - public static extern unsafe int TF_OperationNumOutputs(IntPtr oper); - - [DllImport(TensorFlowLibName)] - public static extern unsafe void TF_SetAttrValueProto(TF_OperationDescription desc, string attr_name, IntPtr proto, UIntPtr proto_len, IntPtr status); - - [DllImport(TensorFlowLibName)] - public static extern unsafe void TF_SetAttrTensor(TF_OperationDescription desc, string attr_name, IntPtr value, IntPtr status); - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - [DllImport(TensorFlowLibName)] - public static extern unsafe void TF_SessionRun(IntPtr session, IntPtr run_options, - TF_Output[] inputs, IntPtr[] input_values, int ninputs, - TF_Output[] outputs, IntPtr[] output_values, int noutputs, - IntPtr[] target_opers, int ntargets, - IntPtr run_metadata, - IntPtr status); - - [DllImport(TensorFlowLibName)] - public static extern unsafe void TF_SetAttrType(TF_OperationDescription desc, string attr_name, TF_DataType value); - - [DllImport(TensorFlowLibName)] - public static extern void TF_SetStatus(IntPtr s, TF_Code code, string msg); - - /// - /// Return the size of the underlying data in bytes. - /// - /// - /// - [DllImport(TensorFlowLibName)] - public static extern unsafe ulong TF_TensorByteSize(IntPtr tensor); - - [DllImport(TensorFlowLibName)] - public static extern unsafe IntPtr TF_TensorData(IntPtr tensor); - - [DllImport(TensorFlowLibName)] - public static extern unsafe TF_DataType TF_TensorType(IntPtr tensor); - - [DllImport(TensorFlowLibName)] - public static extern IntPtr TF_NewSession(IntPtr graph, IntPtr opts, IntPtr status); - - [DllImport(TensorFlowLibName)] - public static extern IntPtr TF_NewSessionOptions(); - [DllImport(TensorFlowLibName)] public static unsafe extern IntPtr TF_Version(); }