MemoryStream GetOpsList() { unsafe { LLBuffer *ptr = TF_GetAllOpList(); var ret = new byte [(int)ptr->length]; Marshal.Copy(ptr->data, ret, 0, (int)ptr->length); return(new MemoryStream(ret)); } }
/// <summary> /// Initializes a new instance of the <see cref="T:TensorFlow.TFBuffer"/> by wrapping the unmanaged resource pointed by the buffer. /// </summary> /// <param name="buffer">Pointer to the data that will be wrapped.</param> /// <param name="size">The size of the buffer to wrap.</param> /// <param name="release">Optional, if not null, this method will be invoked to release the block.</param> /// <remarks> /// This constructor wraps the buffer as a the data to be held by the <see cref="T:TensorFlow.TFBuffer"/>, /// if the release parameter is null, then you must ensure that the data is not released before the TFBuffer /// is no longer in use. If the value is not null, the provided method will be invoked to release /// the data when the TFBuffer is disposed, or the contents of the buffer replaced. /// </remarks> unsafe public TFBuffer(IntPtr buffer, long size, BufferReleaseFunc release) : base((IntPtr)TF_NewBuffer()) { LLBuffer *buf = (LLBuffer *)handle; buf->data = buffer; buf->length = (size_t)size; if (release == null) { buf->data_deallocator = IntPtr.Zero; } else { buf->data_deallocator = Marshal.GetFunctionPointerForDelegate(release); } }
/// <summary> /// Initializes a new instance of the <see cref="T:TensorFlow.TFBuffer"/> by making a copy of the provided byte array. /// </summary> /// <param name="buffer">Buffer of data that will be wrapped.</param> /// <param name="start">Starting offset into the buffer to wrap.</param> /// <param name="count">Number of bytes from the buffer to keep.</param> /// <remarks> /// This constructor makes a copy of the data into an unmanaged buffer, /// so the byte array is not pinned. /// </remarks> public TFBuffer(byte [] buffer, int start, int count) : this() { if (start < 0 || start >= buffer.Length) { throw new ArgumentException("start"); } if (count < 0 || count > buffer.Length - start) { throw new ArgumentException("count"); } unsafe { LLBuffer *buf = LLBuffer; buf->data = Marshal.AllocHGlobal(count); Marshal.Copy(buffer, start, buf->data, count); buf->length = (size_t)count; buf->data_deallocator = FreeBufferFunc; } }
static extern unsafe LLBuffer TF_GetBuffer(LLBuffer *buffer);
static extern unsafe void TF_DeleteBuffer(LLBuffer *buffer);
static extern unsafe TF_Session TF_LoadSessionFromSavedModelOnDevice(TF_SessionOptions session_options, LLBuffer *run_options, string export_dir, string[] tags, int tags_len, TF_Graph graph, string device, TF_Status status);