Skip to content

Instantly share code, notes, and snippets.

@genotrance
Created July 3, 2020 06:42
Show Gist options
  • Save genotrance/9214b1c1762c1fc85e62bac1de67725f to your computer and use it in GitHub Desktop.
Save genotrance/9214b1c1762c1fc85e62bac1de67725f to your computer and use it in GitHub Desktop.
Nim wrapper for tensorflow using nimterop
# nim c -d:FLAGS tensorflow.nim
#
# FLAGS
# -d:capiDL
# -d:capiSetVer=
import os
import nimterop/[build, cimport]
const
baseDir = getProjectCacheDir("nimtensorflow")
osname =
when defined(Linux):
"linux"
elif defined(OSX):
"darwin"
elif defined(Windows):
"windows"
static:
cDisableCaching()
cSkipSymbol(@[
"TF_ATTR_TYPE"
])
getHeader(
header = "c_api.h",
dlurl = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-" & osname & "-x86_64-$1.tar.gz",
outdir = baseDir,
altNames = "tensorflow"
)
cIncludeDir(baseDir / "include")
cImport(capiPath, recurse = true, flags = "-E_")
# Generated @ 2020-07-03T01:40:44-05:00
# Command line:
# /home/gt/nimterop/nimterop/toast --preprocess -m:c --recurse -E_ --includeDirs+=/home/gt/.cache/nim/nimterop/nimtensorflow/include --pnim --symOverride=TF_ATTR_TYPE --nim:/home/gt/programming/nimdevel/bin/nim /home/gt/.cache/nim/nimterop/nimtensorflow/include/tensorflow/c/c_api.h -o /home/gt/.cache/nim/nimterop/toastCache/nimterop_438627397.nim
# const 'TF_CAPI_EXPORT' has unsupported value '__attribute__((visibility("default")))'
# const 'TF_CAPI_EXPORT' has unsupported value '__attribute__((visibility("default")))'
# const 'TF_CAPI_EXPORT' has unsupported value '__attribute__((visibility("default")))'
# const 'TF_CAPI_EXPORT' has unsupported value '__attribute__((visibility("default")))'
{.push hint[ConvFromXtoItselfNotNeeded]: off.}
import macros
macro defineEnum(typ: untyped): untyped =
result = newNimNode(nnkStmtList)
# Enum mapped to distinct cint
result.add quote do:
type `typ`* = distinct cint
for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]:
let
ni = newIdentNode(i)
typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool
if i[0] == '>': # cannot borrow `>` and `>=` from templates
let
nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<")
result.add quote do:
proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x)
proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x)
proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x)
else:
result.add quote do:
proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.}
proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.}
proc `ni`*(x, y: `typ`): `typout` {.borrow.}
result.add quote do:
proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint)
proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y)
let
divop = newIdentNode("/") # `/`()
dlrop = newIdentNode("$") # `$`()
notop = newIdentNode("not") # `not`()
result.add quote do:
proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint)
proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y))
proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y)
proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint)
proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y)
proc `dlrop`*(x: `typ`): string {.borrow.}
proc `notop`*(x: `typ`): `typ` {.borrow.}
{.pragma: impc_apiHdr, header: "/home/gt/.cache/nim/nimterop/nimtensorflow/include/tensorflow/c/c_api.h".}
{.experimental: "codeReordering".}
defineEnum(TF_AttrType) ## ```
## TF_AttrType describes the type of the value of an attribute on an operation.
## ```
defineEnum(TF_DataType) ## ```
## --------------------------------------------------------------------------
## TF_DataType holds the type for a scalar value. E.g., one slot in a tensor.
## The enum values here are identical to corresponding values in types.proto.
## ```
defineEnum(TF_Code) ## ```
## --------------------------------------------------------------------------
## TF_Code holds an error code. The enum values here are identical to
## corresponding values in error_codes.proto.
## ```
const
TF_ATTR_STRING* = (0).TF_AttrType
TF_ATTR_INT* = (1).TF_AttrType
TF_ATTR_FLOAT* = (2).TF_AttrType
TF_ATTR_BOOL* = (3).TF_AttrType
TF_ATTR_SHAPE* = (5).TF_AttrType
TF_ATTR_TENSOR* = (6).TF_AttrType
TF_ATTR_PLACEHOLDER* = (7).TF_AttrType
TF_ATTR_FUNC* = (8).TF_AttrType
TF_FLOAT* = (1).TF_DataType
TF_DOUBLE* = (2).TF_DataType
TF_INT32* = (3).TF_DataType ## ```
## Int32 tensors are always in 'host' memory.
## ```
TF_UINT8* = (4).TF_DataType ## ```
## Int32 tensors are always in 'host' memory.
## ```
TF_INT16* = (5).TF_DataType
TF_INT8* = (6).TF_DataType
TF_STRING* = (7).TF_DataType
TF_COMPLEX64* = (8).TF_DataType ## ```
## Single-precision complex
## ```
TF_COMPLEX* = (8).TF_DataType ## ```
## Old identifier kept for API backwards compatibility
## ```
TF_INT64* = (9).TF_DataType ## ```
## Old identifier kept for API backwards compatibility
## ```
TF_BOOL* = (10).TF_DataType
TF_QINT8* = (11).TF_DataType ## ```
## Quantized int8
## ```
TF_QUINT8* = (12).TF_DataType ## ```
## Quantized uint8
## ```
TF_QINT32* = (13).TF_DataType ## ```
## Quantized int32
## ```
TF_BFLOAT16* = (14).TF_DataType ## ```
## Float32 truncated to 16 bits. Only for cast ops.
## ```
TF_QINT16* = (15).TF_DataType ## ```
## Quantized int16
## ```
TF_QUINT16* = (16).TF_DataType ## ```
## Quantized uint16
## ```
TF_UINT16* = (17).TF_DataType ## ```
## Quantized uint16
## ```
TF_COMPLEX128* = (18).TF_DataType ## ```
## Double-precision complex
## ```
TF_HALF* = (19).TF_DataType ## ```
## Double-precision complex
## ```
TF_RESOURCE* = (20).TF_DataType
TF_VARIANT* = (21).TF_DataType
TF_UINT32* = (22).TF_DataType
TF_UINT64* = (23).TF_DataType
TF_OK* = (0).TF_Code
TF_CANCELLED* = (1).TF_Code
TF_UNKNOWN* = (2).TF_Code
TF_INVALID_ARGUMENT* = (3).TF_Code
TF_DEADLINE_EXCEEDED* = (4).TF_Code
TF_NOT_FOUND* = (5).TF_Code
TF_ALREADY_EXISTS* = (6).TF_Code
TF_PERMISSION_DENIED* = (7).TF_Code
TF_UNAUTHENTICATED* = (16).TF_Code
TF_RESOURCE_EXHAUSTED* = (8).TF_Code
TF_FAILED_PRECONDITION* = (9).TF_Code
TF_ABORTED* = (10).TF_Code
TF_OUT_OF_RANGE* = (11).TF_Code
TF_UNIMPLEMENTED* = (12).TF_Code
TF_INTERNAL* = (13).TF_Code
TF_UNAVAILABLE* = (14).TF_Code
TF_DATA_LOSS* = (15).TF_Code
type
TF_Status* {.importc, impc_apiHdr, incompleteStruct.} = object
TF_Tensor* {.importc, impc_apiHdr, incompleteStruct.} = object
TF_Buffer* {.bycopy, impc_apiHdr, importc: "struct TF_Buffer".} = object ## ```
## --------------------------------------------------------------------------
## TF_Buffer holds a pointer to a block of data and its associated length.
## Typically, the data consists of a serialized protocol buffer, but other data
## may also be held in a buffer.
##
## By default, TF_Buffer itself does not do any memory management of the
## pointed-to block. If need be, users of this struct should specify how to
## deallocate the block by setting the data_deallocator function pointer.
## ```
data*: pointer
length*: uint
data_deallocator*: proc (data: pointer; length: uint) {.cdecl.}
TF_SessionOptions* {.importc, impc_apiHdr, incompleteStruct.} = object
TF_Graph* {.importc, impc_apiHdr, incompleteStruct.} = object
TF_OperationDescription* {.importc, impc_apiHdr, incompleteStruct.} = object
TF_Operation* {.importc, impc_apiHdr, incompleteStruct.} = object
TF_Input* {.bycopy, impc_apiHdr, importc: "struct TF_Input".} = object ## ```
## Represents a specific input of an operation.
## ```
oper*: ptr TF_Operation
index*: cint ## ```
## The index of the input within oper.
## ```
TF_Output* {.bycopy, impc_apiHdr, importc: "struct TF_Output".} = object ## ```
## Represents a specific output of an operation.
## ```
oper*: ptr TF_Operation
index*: cint ## ```
## The index of the output within oper.
## ```
TF_Function* {.importc, impc_apiHdr, incompleteStruct.} = object
TF_FunctionOptions* {.importc, impc_apiHdr, incompleteStruct.} = object
TF_AttrMetadata* {.bycopy, impc_apiHdr, importc: "struct TF_AttrMetadata".} = object ## ```
## TF_AttrMetadata describes the value of an attribute on an operation.
## ```
is_list*: cuchar ## ```
## A boolean: 1 if the attribute value is a list, 0 otherwise.
## ```
list_size*: int64 ## ```
## Length of the list if is_list is true. Undefined otherwise.
## ```
`type`*: TF_AttrType ## ```
## Type of elements of the list if is_list != 0.
## Type of the single value stored in the attribute if is_list == 0.
## ```
total_size*: int64 ## ```
## Total size the attribute value.
## The units of total_size depend on is_list and type.
## (1) If type == TF_ATTR_STRING and is_list == 0
## then total_size is the byte size of the string
## valued attribute.
## (2) If type == TF_ATTR_STRING and is_list == 1
## then total_size is the cumulative byte size
## of all the strings in the list.
## (3) If type == TF_ATTR_SHAPE and is_list == 0
## then total_size is the number of dimensions
## of the shape valued attribute, or -1
## if its rank is unknown.
## (4) If type == TF_ATTR_SHAPE and is_list == 1
## then total_size is the cumulative number
## of dimensions of all shapes in the list.
## (5) Otherwise, total_size is undefined.
## ```
TF_ImportGraphDefOptions* {.importc, impc_apiHdr, incompleteStruct.} = object
TF_ImportGraphDefResults* {.importc, impc_apiHdr, incompleteStruct.} = object
TF_WhileParams* {.bycopy, impc_apiHdr, importc: "struct TF_WhileParams".} = object
ninputs*: cint ## ```
## The number of inputs to the while loop, i.e. the number of loop variables.
## This is the size of cond_inputs, body_inputs, and body_outputs.
## ```
cond_graph*: ptr TF_Graph ## ```
## The while condition graph. The inputs are the current values of the loop
## variables. The output should be a scalar boolean.
## ```
cond_inputs*: ptr TF_Output
cond_output*: TF_Output
body_graph*: ptr TF_Graph ## ```
## The loop body graph. The inputs are the current values of the loop
## variables. The outputs are the updated values of the loop variables.
## ```
body_inputs*: ptr TF_Output
body_outputs*: ptr TF_Output
name*: cstring ## ```
## Unique null-terminated name for this while loop. This is used as a prefix
## for created operations.
## ```
TF_Session* {.importc, impc_apiHdr, incompleteStruct.} = object
TF_DeprecatedSession* {.importc, impc_apiHdr, incompleteStruct.} = object
TF_DeviceList* {.importc, impc_apiHdr, incompleteStruct.} = object
TF_Library* {.importc, impc_apiHdr, incompleteStruct.} = object
TF_ApiDefMap* {.importc, impc_apiHdr, incompleteStruct.} = object
TF_Server* {.importc, impc_apiHdr, incompleteStruct.} = object
proc TF_DataTypeSize*(dt: TF_DataType): uint {.importc, cdecl, impc_apiHdr.}
## ```
## TF_DataTypeSize returns the sizeof() for the underlying type corresponding
## to the given TF_DataType enum value. Returns 0 for variable length types
## (eg. TF_STRING) or on failure.
## ```
proc TF_NewStatus*(): ptr TF_Status {.importc, cdecl, impc_apiHdr.}
## ```
## --------------------------------------------------------------------------
## Return a new status object.
## ```
proc TF_DeleteStatus*(a1: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## Delete a previously created status object.
## ```
proc TF_SetStatus*(s: ptr TF_Status; code: TF_Code; msg: cstring) {.importc, cdecl,
impc_apiHdr.}
## ```
## Record <code, msg> ins. Any previous information is lost.
## A common use is to clear a status: TF_SetStatus(s, TF_OK, "");
## ```
proc TF_GetCode*(s: ptr TF_Status): TF_Code {.importc, cdecl, impc_apiHdr.}
## ```
## Return the code record ins.
## ```
proc TF_Message*(s: ptr TF_Status): cstring {.importc, cdecl, impc_apiHdr.}
## ```
## Return a pointer to the (null-terminated) error message ins. The
## return value points to memory that is only usable until the next
## mutation tos. Always returns an empty string if TF_GetCode(s) is
## TF_OK.
## ```
proc TF_NewTensor*(a1: TF_DataType; dims: ptr int64; num_dims: cint; data: pointer;
len: uint; deallocator: proc (data: pointer; len: uint; arg: pointer) {.
cdecl.}; deallocator_arg: pointer): ptr TF_Tensor {.importc, cdecl, impc_apiHdr.}
## ```
## Return a new tensor that holds the bytes data[0,len-1].
##
## The data will be deallocated by a subsequent call to TF_DeleteTensor via:
## (*deallocator)(data, len, deallocator_arg)
## Clients must provide a custom deallocator function so they can pass in
## memory managed by something like numpy.
##
## May return NULL (and invoke the deallocator) if the provided data buffer
## (data, len) is inconsistent with a tensor of the given TF_DataType
## and the shape specified by (dima, num_dims).
## ```
proc TF_AllocateTensor*(a1: TF_DataType; dims: ptr int64; num_dims: cint; len: uint): ptr TF_Tensor {.
importc, cdecl, impc_apiHdr.}
## ```
## Allocate and return a new Tensor.
##
## This function is an alternative to TF_NewTensor and should be used when
## memory is allocated to pass the Tensor to the C API. The allocated memory
## satisfies TensorFlow's memory alignment preferences and should be preferred
## over calling malloc and free.
##
## The caller must set the Tensor values by writing them to the pointer returned
## by TF_TensorData with length TF_TensorByteSize.
## ```
proc TF_TensorMaybeMove*(tensor: ptr TF_Tensor): ptr TF_Tensor {.importc, cdecl,
impc_apiHdr.}
## ```
## Deletes tensor and returns a new TF_Tensor with the same content if
## possible. Returns nullptr and leaves tensor untouched if not.
## ```
proc TF_DeleteTensor*(a1: ptr TF_Tensor) {.importc, cdecl, impc_apiHdr.}
## ```
## Destroy a tensor.
## ```
proc TF_TensorType*(a1: ptr TF_Tensor): TF_DataType {.importc, cdecl, impc_apiHdr.}
## ```
## Return the type of a tensor element.
## ```
proc TF_NumDims*(a1: ptr TF_Tensor): cint {.importc, cdecl, impc_apiHdr.}
## ```
## Return the number of dimensions that the tensor has.
## ```
proc TF_Dim*(tensor: ptr TF_Tensor; dim_index: cint): int64 {.importc, cdecl, impc_apiHdr.}
## ```
## Return the length of the tensor in the "dim_index" dimension.
## REQUIRES: 0 <= dim_index < TF_NumDims(tensor)
## ```
proc TF_TensorByteSize*(a1: ptr TF_Tensor): uint {.importc, cdecl, impc_apiHdr.}
## ```
## Return the size of the underlying data in bytes.
## ```
proc TF_TensorData*(a1: ptr TF_Tensor): pointer {.importc, cdecl, impc_apiHdr.}
## ```
## Return a pointer to the underlying data buffer.
## ```
proc TF_TensorElementCount*(tensor: ptr TF_Tensor): int64 {.importc, cdecl, impc_apiHdr.}
## ```
## Returns the number of elements in the tensor.
## ```
proc TF_TensorBitcastFrom*(`from`: ptr TF_Tensor; `type`: TF_DataType;
to: ptr TF_Tensor; new_dims: ptr int64; num_new_dims: cint;
status: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## Copy the internal data representation of from to to. new_dims and
## num_new_dims specify the new shape of the to tensor, type specifies its
## data type. On success,status is set to TF_OK and the two tensors share the
## same data buffer.
##
## This call requires that the from tensor and the given type and shape (dims
## and num_dims) are "compatible" (i.e. they occupy the same number of bytes).
## Specifically, given from_type_size = TF_DataTypeSize(TF_TensorType(from)):
##
## ShapeElementCount(dims, num_dims) TF_DataTypeSize(type)
##
## must equal
##
## TF_TensorElementCount(from) from_type_size
##
## where TF_ShapeElementCount would be the number of elements in a tensor with
## the given shape.
##
## In addition, this function requires:
## TF_DataTypeSize(TF_TensorType(from)) != 0
## TF_DataTypeSize(type) != 0
##
## If any of the requirements are not met,status is set to
## TF_INVALID_ARGUMENT.
## ```
proc TF_StringEncode*(src: cstring; src_len: uint; dst: cstring; dst_len: uint;
status: ptr TF_Status): uint {.importc, cdecl, impc_apiHdr.}
## ```
## --------------------------------------------------------------------------
## Encode the string src (src_len bytes long) into dst in the format
## required by TF_STRING tensors. Does not write to memory more than dst_len
## bytes beyonddst. dst_len should be at least
## TF_StringEncodedSize(src_len).
##
## On success returns the size in bytes of the encoded string.
## Returns an error into status otherwise.
## ```
proc TF_StringDecode*(src: cstring; src_len: uint; dst: ptr cstring; dst_len: ptr uint;
status: ptr TF_Status): uint {.importc, cdecl, impc_apiHdr.}
## ```
## Decode a string encoded using TF_StringEncode.
##
## On success, setsdst to the start of the decoded string anddst_len to
## its length. Returns the number of bytes starting at src consumed while
## decoding.dst points to memory within the encoded buffer. On failure,
## dst anddst_len are undefined and an error is set in status.
##
## Does not read memory more than src_len bytes beyond src.
## ```
proc TF_StringEncodedSize*(len: uint): uint {.importc, cdecl, impc_apiHdr.}
## ```
## Return the size in bytes required to encode a string len bytes long into a
## TF_STRING tensor.
## ```
proc TF_TensorIsAligned*(a1: ptr TF_Tensor): bool {.importc, cdecl, impc_apiHdr.}
## ```
## Returns bool iff this tensor is aligned.
## ```
proc TF_Version*(): cstring {.importc, cdecl, impc_apiHdr.}
## ```
## --------------------------------------------------------------------------
## TF_Version returns a string describing version information of the
## TensorFlow library. TensorFlow using semantic versioning.
## ```
proc TF_NewBufferFromString*(proto: pointer; proto_len: uint): ptr TF_Buffer {.importc,
cdecl, impc_apiHdr.}
## ```
## Makes a copy of the input and sets an appropriate deallocator. Useful for
## passing in read-only, input protobufs.
## ```
proc TF_NewBuffer*(): ptr TF_Buffer {.importc, cdecl, impc_apiHdr.}
## ```
## Useful for passingout* a protobuf.
## ```
proc TF_DeleteBuffer*(a1: ptr TF_Buffer) {.importc, cdecl, impc_apiHdr.}
proc TF_GetBuffer*(buffer: ptr TF_Buffer): TF_Buffer {.importc, cdecl, impc_apiHdr.}
proc TF_NewSessionOptions*(): ptr TF_SessionOptions {.importc, cdecl, impc_apiHdr.}
## ```
## Return a new options object.
## ```
proc TF_SetTarget*(options: ptr TF_SessionOptions; target: cstring) {.importc, cdecl,
impc_apiHdr.}
## ```
## Set the target in TF_SessionOptions.options.
## target can be empty, a single entry, or a comma separated list of entries.
## Each entry is in one of the following formats :
## "local"
## ip:port
## host:port
## ```
proc TF_SetConfig*(options: ptr TF_SessionOptions; proto: pointer; proto_len: uint;
status: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## Set the config in TF_SessionOptions.options.
## config should be a serialized tensorflow.ConfigProto proto.
## If config was not parsed successfully as a ConfigProto, record the
## error information instatus.
## ```
proc TF_DeleteSessionOptions*(a1: ptr TF_SessionOptions) {.importc, cdecl, impc_apiHdr.}
## ```
## Destroy an options object.
## ```
proc TF_NewGraph*(): ptr TF_Graph {.importc, cdecl, impc_apiHdr.}
## ```
## Return a new graph object.
## ```
proc TF_DeleteGraph*(a1: ptr TF_Graph) {.importc, cdecl, impc_apiHdr.}
## ```
## Destroy an options object. Graph will be deleted once no more
## TFSession's are referencing it.
## ```
proc TF_GraphSetTensorShape*(graph: ptr TF_Graph; output: TF_Output; dims: ptr int64;
num_dims: cint; status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## Sets the shape of the Tensor referenced by output in graph to
## the shape described by dims and num_dims.
##
## If the number of dimensions is unknown, num_dims must be set to
## -1 and dims can be null. If a dimension is unknown, the
## corresponding entry in the dims array must be -1.
##
## This does not overwrite the existing shape associated with output,
## but merges the input shape with the existing shape. For example,
## setting a shape of [-1, 2] with an existing shape [2, -1] would set
## a final shape of [2, 2] based on shape merging semantics.
##
## Returns an error into status if:
## output is not in graph.
## An invalid shape is being set (e.g., the shape being set
## is incompatible with the existing shape).
## ```
proc TF_GraphGetTensorNumDims*(graph: ptr TF_Graph; output: TF_Output;
status: ptr TF_Status): cint {.importc, cdecl,
impc_apiHdr.}
## ```
## Returns the number of dimensions of the Tensor referenced by output
## in graph.
##
## If the number of dimensions in the shape is unknown, returns -1.
##
## Returns an error into status if:
## output is not in graph.
## ```
proc TF_GraphGetTensorShape*(graph: ptr TF_Graph; output: TF_Output; dims: ptr int64;
num_dims: cint; status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## Returns the shape of the Tensor referenced by output in graph
## into dims. dims must be an array large enough to hold num_dims
## entries (e.g., the return value of TF_GraphGetTensorNumDims).
##
## If the number of dimensions in the shape is unknown or the shape is
## a scalar, dims will remain untouched. Otherwise, each element of
## dims will be set corresponding to the size of the dimension. An
## unknown dimension is represented by -1.
##
## Returns an error into status if:
## output is not in graph.
## num_dims does not match the actual number of dimensions.
## ```
proc TF_NewOperation*(graph: ptr TF_Graph; op_type: cstring; oper_name: cstring): ptr TF_OperationDescription {.
importc, cdecl, impc_apiHdr.}
## ```
## Operation will only be added tograph when TF_FinishOperation() is
## called (assuming TF_FinishOperation() does not return an error).
## graph must not be deleted until after TF_FinishOperation() is
## called.
## ```
proc TF_SetDevice*(desc: ptr TF_OperationDescription; device: cstring) {.importc,
cdecl, impc_apiHdr.}
## ```
## Specify the device for desc. Defaults to empty, meaning unconstrained.
## ```
proc TF_AddInput*(desc: ptr TF_OperationDescription; input: TF_Output) {.importc,
cdecl, impc_apiHdr.}
## ```
## The calls to TF_AddInput and TF_AddInputList must match (in number,
## order, and type) the op declaration. For example, the "Concat" op
## has registration:
## REGISTER_OP("Concat")
## .Input("concat_dim: int32")
## .Input("values: N T")
## .Output("output: T")
## .Attr("N: int >= 2")
## .Attr("T: type");
## that defines two inputs, "concat_dim" and "values" (in that order).
## You must use TF_AddInput() for the first input (since it takes a
## single tensor), and TF_AddInputList() for the second input (since
## it takes a list, even if you were to pass a list with a single
## tensor), as in:
## TF_OperationDescription* desc = TF_NewOperation(graph, "Concat", "c");
## TF_Output concat_dim_input = {...};
## TF_AddInput(desc, concat_dim_input);
## TF_Output values_inputs[5] = {{...}, ..., {...}};
## TF_AddInputList(desc, values_inputs, 5);
## For inputs that take a single tensor.
## ```
proc TF_AddInputList*(desc: ptr TF_OperationDescription; inputs: ptr TF_Output;
num_inputs: cint) {.importc, cdecl, impc_apiHdr.}
## ```
## For inputs that take a list of tensors.
## inputs must point to TF_Output[num_inputs].
## ```
proc TF_AddControlInput*(desc: ptr TF_OperationDescription; input: ptr TF_Operation) {.
importc, cdecl, impc_apiHdr.}
## ```
## Call once per control input to desc.
## ```
proc TF_ColocateWith*(desc: ptr TF_OperationDescription; op: ptr TF_Operation) {.
importc, cdecl, impc_apiHdr.}
## ```
## Request that desc be co-located on the device where op
## is placed.
##
## Use of this is discouraged since the implementation of device placement is
## subject to change. Primarily intended for internal libraries
## ```
proc TF_SetAttrString*(desc: ptr TF_OperationDescription; attr_name: cstring;
value: pointer; length: uint) {.importc, cdecl, impc_apiHdr.}
## ```
## Call some TF_SetAttr*() function for every attr that is not
## inferred from an input and doesn't have a default value you wish to
## keep.
## value must point to a string of length length bytes.
## ```
proc TF_SetAttrStringList*(desc: ptr TF_OperationDescription; attr_name: cstring;
values: ptr pointer; lengths: ptr uint; num_values: cint) {.
importc, cdecl, impc_apiHdr.}
## ```
## values and lengths each must have lengths num_values.
## values[i] must point to a string of length lengths[i] bytes.
## ```
proc TF_SetAttrInt*(desc: ptr TF_OperationDescription; attr_name: cstring;
value: int64) {.importc, cdecl, impc_apiHdr.}
proc TF_SetAttrIntList*(desc: ptr TF_OperationDescription; attr_name: cstring;
values: ptr int64; num_values: cint) {.importc, cdecl,
impc_apiHdr.}
proc TF_SetAttrFloat*(desc: ptr TF_OperationDescription; attr_name: cstring;
value: cfloat) {.importc, cdecl, impc_apiHdr.}
proc TF_SetAttrFloatList*(desc: ptr TF_OperationDescription; attr_name: cstring;
values: ptr cfloat; num_values: cint) {.importc, cdecl,
impc_apiHdr.}
proc TF_SetAttrBool*(desc: ptr TF_OperationDescription; attr_name: cstring;
value: cuchar) {.importc, cdecl, impc_apiHdr.}
proc TF_SetAttrBoolList*(desc: ptr TF_OperationDescription; attr_name: cstring;
values: ptr cuchar; num_values: cint) {.importc, cdecl,
impc_apiHdr.}
proc TF_SetAttrType*(desc: ptr TF_OperationDescription; attr_name: cstring;
value: TF_DataType) {.importc, cdecl, impc_apiHdr.}
proc TF_SetAttrTypeList*(desc: ptr TF_OperationDescription; attr_name: cstring;
values: ptr TF_DataType; num_values: cint) {.importc, cdecl,
impc_apiHdr.}
proc TF_SetAttrPlaceholder*(desc: ptr TF_OperationDescription; attr_name: cstring;
placeholder: cstring) {.importc, cdecl, impc_apiHdr.}
proc TF_SetAttrFuncName*(desc: ptr TF_OperationDescription; attr_name: cstring;
value: cstring; length: uint) {.importc, cdecl, impc_apiHdr.}
## ```
## Set a 'func' attribute to the specified name.
## value must point to a string of length length bytes.
## ```
proc TF_SetAttrShape*(desc: ptr TF_OperationDescription; attr_name: cstring;
dims: ptr int64; num_dims: cint) {.importc, cdecl, impc_apiHdr.}
## ```
## Set num_dims to -1 to represent "unknown rank". Otherwise,
## dims points to an array of length num_dims. dims[i] must be
## >= -1, with -1 meaning "unknown dimension".
## ```
proc TF_SetAttrShapeList*(desc: ptr TF_OperationDescription; attr_name: cstring;
dims: ptr ptr int64; num_dims: ptr cint; num_shapes: cint) {.
importc, cdecl, impc_apiHdr.}
## ```
## dims and num_dims must point to arrays of length num_shapes.
## Set num_dims[i] to -1 to represent "unknown rank". Otherwise,
## dims[i] points to an array of length num_dims[i]. dims[i][j]
## must be >= -1, with -1 meaning "unknown dimension".
## ```
proc TF_SetAttrTensorShapeProto*(desc: ptr TF_OperationDescription;
attr_name: cstring; proto: pointer; proto_len: uint;
status: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## proto must point to an array of proto_len bytes representing a
## binary-serialized TensorShapeProto.
## ```
proc TF_SetAttrTensorShapeProtoList*(desc: ptr TF_OperationDescription;
attr_name: cstring; protos: ptr pointer;
proto_lens: ptr uint; num_shapes: cint;
status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## protos and proto_lens must point to arrays of length num_shapes.
## protos[i] must point to an array of proto_lens[i] bytes
## representing a binary-serialized TensorShapeProto.
## ```
proc TF_SetAttrTensor*(desc: ptr TF_OperationDescription; attr_name: cstring;
value: ptr TF_Tensor; status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
proc TF_SetAttrTensorList*(desc: ptr TF_OperationDescription; attr_name: cstring;
values: ptr ptr TF_Tensor; num_values: cint;
status: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
proc TF_SetAttrValueProto*(desc: ptr TF_OperationDescription; attr_name: cstring;
proto: pointer; proto_len: uint; status: ptr TF_Status) {.
importc, cdecl, impc_apiHdr.}
## ```
## proto should point to a sequence of bytes of length proto_len
## representing a binary serialization of an AttrValue protocol
## buffer.
## ```
proc TF_FinishOperation*(desc: ptr TF_OperationDescription; status: ptr TF_Status): ptr TF_Operation {.
importc, cdecl, impc_apiHdr.}
## ```
## If this function succeeds:
## status is set to an OK value,
## a TF_Operation is added to the graph,
## a non-null value pointing to the added operation is returned --
## this value is valid until the underlying graph is deleted.
## Otherwise:
## status is set to a non-OK value,
## the graph is not modified,
## a null value is returned.
## In either case, it deletes desc.
## ```
proc TF_OperationName*(oper: ptr TF_Operation): cstring {.importc, cdecl, impc_apiHdr.}
proc TF_OperationOpType*(oper: ptr TF_Operation): cstring {.importc, cdecl, impc_apiHdr.}
proc TF_OperationDevice*(oper: ptr TF_Operation): cstring {.importc, cdecl, impc_apiHdr.}
proc TF_OperationNumOutputs*(oper: ptr TF_Operation): cint {.importc, cdecl,
impc_apiHdr.}
proc TF_OperationOutputType*(oper_out: TF_Output): TF_DataType {.importc, cdecl,
impc_apiHdr.}
proc TF_OperationOutputListLength*(oper: ptr TF_Operation; arg_name: cstring;
status: ptr TF_Status): cint {.importc, cdecl,
impc_apiHdr.}
proc TF_OperationNumInputs*(oper: ptr TF_Operation): cint {.importc, cdecl, impc_apiHdr.}
proc TF_OperationInputType*(oper_in: TF_Input): TF_DataType {.importc, cdecl,
impc_apiHdr.}
proc TF_OperationInputListLength*(oper: ptr TF_Operation; arg_name: cstring;
status: ptr TF_Status): cint {.importc, cdecl,
impc_apiHdr.}
proc TF_OperationInput*(oper_in: TF_Input): TF_Output {.importc, cdecl, impc_apiHdr.}
## ```
## In this code:
## TF_Output producer = TF_OperationInput(consumer);
## There is an edge from producer.oper's output (given by
## producer.index) to consumer.oper's input (given by consumer.index).
## ```
proc TF_OperationOutputNumConsumers*(oper_out: TF_Output): cint {.importc, cdecl,
impc_apiHdr.}
## ```
## Get the number of current consumers of a specific output of an
## operation. Note that this number can change when new operations
## are added to the graph.
## ```
proc TF_OperationOutputConsumers*(oper_out: TF_Output; consumers: ptr TF_Input;
max_consumers: cint): cint {.importc, cdecl,
impc_apiHdr.}
## ```
## Get list of all current consumers of a specific output of an
## operation. consumers must point to an array of length at least
## max_consumers (ideally set to
## TF_OperationOutputNumConsumers(oper_out)). Beware that a concurrent
## modification of the graph can increase the number of consumers of
## an operation. Returns the number of output consumers (should match
## TF_OperationOutputNumConsumers(oper_out)).
## ```
proc TF_OperationNumControlInputs*(oper: ptr TF_Operation): cint {.importc, cdecl,
impc_apiHdr.}
## ```
## Get the number of control inputs to an operation.
## ```
proc TF_OperationGetControlInputs*(oper: ptr TF_Operation;
control_inputs: ptr ptr TF_Operation;
max_control_inputs: cint): cint {.importc, cdecl,
impc_apiHdr.}
## ```
## Get list of all control inputs to an operation. control_inputs must
## point to an array of length max_control_inputs (ideally set to
## TF_OperationNumControlInputs(oper)). Returns the number of control
## inputs (should match TF_OperationNumControlInputs(oper)).
## ```
proc TF_OperationNumControlOutputs*(oper: ptr TF_Operation): cint {.importc, cdecl,
impc_apiHdr.}
## ```
## Get the number of operations that haveoper as a control input.
## Note that this number can change when new operations are added to
## the graph.
## ```
proc TF_OperationGetControlOutputs*(oper: ptr TF_Operation;
control_outputs: ptr ptr TF_Operation;
max_control_outputs: cint): cint {.importc,
cdecl, impc_apiHdr.}
## ```
## Get the list of operations that haveoper as a control input.
## control_outputs must point to an array of length at least
## max_control_outputs (ideally set to
## TF_OperationNumControlOutputs(oper)). Beware that a concurrent
## modification of the graph can increase the number of control
## outputs. Returns the number of control outputs (should match
## TF_OperationNumControlOutputs(oper)).
## ```
proc TF_OperationGetAttrMetadata*(oper: ptr TF_Operation; attr_name: cstring;
status: ptr TF_Status): TF_AttrMetadata {.importc,
cdecl, impc_apiHdr.}
## ```
## Returns metadata about the value of the attribute attr_name of oper.
## ```
proc TF_OperationGetAttrString*(oper: ptr TF_Operation; attr_name: cstring;
value: pointer; max_length: uint;
status: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## Fills in value with the value of the attribute attr_name. value must
## point to an array of length at least max_length (ideally set to
## TF_AttrMetadata.total_size from TF_OperationGetAttrMetadata(oper,
## attr_name)).
## ```
proc TF_OperationGetAttrStringList*(oper: ptr TF_Operation; attr_name: cstring;
values: ptr pointer; lengths: ptr uint;
max_values: cint; storage: pointer;
storage_size: uint; status: ptr TF_Status) {.
importc, cdecl, impc_apiHdr.}
## ```
## Get the list of strings in the value of the attribute attr_name. Fills in
## values and lengths, each of which must point to an array of length at
## least max_values.
##
## The elements of values will point to addresses in storage which must be at
## least storage_size bytes in length. Ideally, max_values would be set to
## TF_AttrMetadata.list_size and storage would be at least
## TF_AttrMetadata.total_size, obtained from TF_OperationGetAttrMetadata(oper,
## attr_name).
##
## Fails if storage_size is too small to hold the requested number of strings.
## ```
proc TF_OperationGetAttrInt*(oper: ptr TF_Operation; attr_name: cstring;
value: ptr int64; status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
proc TF_OperationGetAttrIntList*(oper: ptr TF_Operation; attr_name: cstring;
values: ptr int64; max_values: cint;
status: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## Fills in values with the value of the attribute attr_name of oper.
## values must point to an array of length at least max_values (ideally set
## TF_AttrMetadata.list_size from TF_OperationGetAttrMetadata(oper,
## attr_name)).
## ```
proc TF_OperationGetAttrFloat*(oper: ptr TF_Operation; attr_name: cstring;
value: ptr cfloat; status: ptr TF_Status) {.importc,
cdecl, impc_apiHdr.}
proc TF_OperationGetAttrFloatList*(oper: ptr TF_Operation; attr_name: cstring;
values: ptr cfloat; max_values: cint;
status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## Fills in values with the value of the attribute attr_name of oper.
## values must point to an array of length at least max_values (ideally set
## to TF_AttrMetadata.list_size from TF_OperationGetAttrMetadata(oper,
## attr_name)).
## ```
proc TF_OperationGetAttrBool*(oper: ptr TF_Operation; attr_name: cstring;
value: ptr cuchar; status: ptr TF_Status) {.importc,
cdecl, impc_apiHdr.}
proc TF_OperationGetAttrBoolList*(oper: ptr TF_Operation; attr_name: cstring;
values: ptr cuchar; max_values: cint;
status: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## Fills in values with the value of the attribute attr_name of oper.
## values must point to an array of length at least max_values (ideally set
## to TF_AttrMetadata.list_size from TF_OperationGetAttrMetadata(oper,
## attr_name)).
## ```
proc TF_OperationGetAttrType*(oper: ptr TF_Operation; attr_name: cstring;
value: ptr TF_DataType; status: ptr TF_Status) {.importc,
cdecl, impc_apiHdr.}
proc TF_OperationGetAttrTypeList*(oper: ptr TF_Operation; attr_name: cstring;
values: ptr TF_DataType; max_values: cint;
status: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## Fills in values with the value of the attribute attr_name of oper.
## values must point to an array of length at least max_values (ideally set
## to TF_AttrMetadata.list_size from TF_OperationGetAttrMetadata(oper,
## attr_name)).
## ```
proc TF_OperationGetAttrShape*(oper: ptr TF_Operation; attr_name: cstring;
value: ptr int64; num_dims: cint; status: ptr TF_Status) {.
importc, cdecl, impc_apiHdr.}
## ```
## Fills in value with the value of the attribute attr_name of oper.
## values must point to an array of length at least num_dims (ideally set to
## TF_Attr_Meta.size from TF_OperationGetAttrMetadata(oper, attr_name)).
## ```
proc TF_OperationGetAttrShapeList*(oper: ptr TF_Operation; attr_name: cstring;
dims: ptr ptr int64; num_dims: ptr cint;
num_shapes: cint; storage: ptr int64;
storage_size: cint; status: ptr TF_Status) {.
importc, cdecl, impc_apiHdr.}
## ```
## Fills in dims with the list of shapes in the attribute attr_name of
## oper and num_dims with the corresponding number of dimensions. On return,
## for every i where num_dims[i] > 0, dims[i] will be an array of
## num_dims[i] elements. A value of -1 for num_dims[i] indicates that the
## i-th shape in the list is unknown.
##
## The elements of dims will point to addresses in storage which must be
## large enough to hold at least storage_size int64_ts. Ideally, num_shapes
## would be set to TF_AttrMetadata.list_size and storage_size would be set to
## TF_AttrMetadata.total_size from TF_OperationGetAttrMetadata(oper,
## attr_name).
##
## Fails if storage_size is insufficient to hold the requested shapes.
## ```
proc TF_OperationGetAttrTensorShapeProto*(oper: ptr TF_Operation;
attr_name: cstring; value: ptr TF_Buffer; status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## Sets value to the binary-serialized TensorShapeProto of the value of
## attr_name attribute of oper'.
## ```
proc TF_OperationGetAttrTensorShapeProtoList*(oper: ptr TF_Operation;
attr_name: cstring; values: ptr ptr TF_Buffer; max_values: cint;
status: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## Fills in values with binary-serialized TensorShapeProto values of the
## attribute attr_name of oper. values must point to an array of length at
## least num_values (ideally set to TF_AttrMetadata.list_size from
## TF_OperationGetAttrMetadata(oper, attr_name)).
## ```
proc TF_OperationGetAttrTensor*(oper: ptr TF_Operation; attr_name: cstring;
value: ptr ptr TF_Tensor; status: ptr TF_Status) {.
importc, cdecl, impc_apiHdr.}
## ```
## Gets the TF_Tensor valued attribute of attr_name of oper.
##
## Allocates a new TF_Tensor which the caller is expected to take
## ownership of (and can deallocate using TF_DeleteTensor).
## ```
proc TF_OperationGetAttrTensorList*(oper: ptr TF_Operation; attr_name: cstring;
values: ptr ptr TF_Tensor; max_values: cint;
status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## Fills in values with the TF_Tensor values of the attribute attr_name of
## oper. values must point to an array of TF_Tensor* of length at least
## max_values (ideally set to TF_AttrMetadata.list_size from
## TF_OperationGetAttrMetadata(oper, attr_name)).
##
## The caller takes ownership of all the non-null TF_Tensor* entries in values
## (which can be deleted using TF_DeleteTensor(values[i])).
## ```
proc TF_OperationGetAttrValueProto*(oper: ptr TF_Operation; attr_name: cstring;
output_attr_value: ptr TF_Buffer;
status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## Sets output_attr_value to the binary-serialized AttrValue proto
## representation of the value of the attr_name attr of oper.
## ```
proc TF_GraphOperationByName*(graph: ptr TF_Graph; oper_name: cstring): ptr TF_Operation {.
importc, cdecl, impc_apiHdr.}
## ```
## Returns the operation in the graph with oper_name. Returns nullptr if
## no operation found.
## ```
proc TF_GraphNextOperation*(graph: ptr TF_Graph; pos: ptr uint): ptr TF_Operation {.
importc, cdecl, impc_apiHdr.}
## ```
## Iterate through the operations of a graph. To use:
## size_t pos = 0;
## TF_Operation* oper;
## while ((oper = TF_GraphNextOperation(graph, &pos)) != nullptr) {
## DoSomethingWithOperation(oper);
## }
## ```
proc TF_GraphToGraphDef*(graph: ptr TF_Graph; output_graph_def: ptr TF_Buffer;
status: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## Write out a serialized representation of graph (as a GraphDef protocol
## message) to output_graph_def (allocated by TF_NewBuffer()).
## output_graph_def's underlying buffer will be freed when TF_DeleteBuffer()
## is called.
##
## May fail on very large graphs in the future.
## ```
proc TF_GraphGetOpDef*(graph: ptr TF_Graph; op_name: cstring;
output_op_def: ptr TF_Buffer; status: ptr TF_Status) {.importc,
cdecl, impc_apiHdr.}
## ```
## Returns the serialized OpDef proto with name op_name, or a bad status if no
## such op exists. This can return OpDefs of functions copied into the graph.
## ```
proc TF_GraphVersions*(graph: ptr TF_Graph; output_version_def: ptr TF_Buffer;
status: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## Returns the serialized VersionDef proto for this graph.
## ```
proc TF_NewImportGraphDefOptions*(): ptr TF_ImportGraphDefOptions {.importc, cdecl,
impc_apiHdr.}
proc TF_DeleteImportGraphDefOptions*(opts: ptr TF_ImportGraphDefOptions) {.importc,
cdecl, impc_apiHdr.}
proc TF_ImportGraphDefOptionsSetPrefix*(opts: ptr TF_ImportGraphDefOptions;
prefix: cstring) {.importc, cdecl,
impc_apiHdr.}
## ```
## Set the prefix to be prepended to the names of nodes in graph_def that will
## be imported into graph. prefix is copied and has no lifetime
## requirements.
## ```
proc TF_ImportGraphDefOptionsSetDefaultDevice*(
opts: ptr TF_ImportGraphDefOptions; device: cstring) {.importc, cdecl, impc_apiHdr.}
## ```
## Set the execution device for nodes in graph_def.
## Only applies to nodes where a device was not already explicitly specified.
## device is copied and has no lifetime requirements.
## ```
proc TF_ImportGraphDefOptionsSetUniquifyNames*(
opts: ptr TF_ImportGraphDefOptions; uniquify_names: cuchar) {.importc, cdecl,
impc_apiHdr.}
## ```
## Set whether to uniquify imported operation names. If true, imported operation
## names will be modified if their name already exists in the graph. If false,
## conflicting names will be treated as an error. Note that this option has no
## effect if a prefix is set, since the prefix will guarantee all names are
## unique. Defaults to false.
## ```
proc TF_ImportGraphDefOptionsSetUniquifyPrefix*(
opts: ptr TF_ImportGraphDefOptions; uniquify_prefix: cuchar) {.importc, cdecl,
impc_apiHdr.}
## ```
## If true, the specified prefix will be modified if it already exists as an
## operation name or prefix in the graph. If false, a conflicting prefix will be
## treated as an error. This option has no effect if no prefix is specified.
## ```
proc TF_ImportGraphDefOptionsAddInputMapping*(opts: ptr TF_ImportGraphDefOptions;
src_name: cstring; src_index: cint; dst: TF_Output) {.importc, cdecl, impc_apiHdr.}
## ```
## Set any imported nodes with input src_name:src_index to have that input
## replaced with dst. src_name refers to a node in the graph to be imported,
## dst references a node already existing in the graph being imported into.
## src_name is copied and has no lifetime requirements.
## ```
proc TF_ImportGraphDefOptionsRemapControlDependency*(
opts: ptr TF_ImportGraphDefOptions; src_name: cstring; dst: ptr TF_Operation) {.
importc, cdecl, impc_apiHdr.}
## ```
## Set any imported nodes with control input src_name to have that input
## replaced with dst. src_name refers to a node in the graph to be imported,
## dst references an operation already existing in the graph being imported
## into. src_name is copied and has no lifetime requirements.
## ```
proc TF_ImportGraphDefOptionsAddControlDependency*(
opts: ptr TF_ImportGraphDefOptions; oper: ptr TF_Operation) {.importc, cdecl,
impc_apiHdr.}
## ```
## Cause the imported graph to have a control dependency on oper. oper
## should exist in the graph being imported into.
## ```
proc TF_ImportGraphDefOptionsAddReturnOutput*(opts: ptr TF_ImportGraphDefOptions;
oper_name: cstring; index: cint) {.importc, cdecl, impc_apiHdr.}
## ```
## Add an output in graph_def to be returned via the return_outputs output
## parameter of TF_GraphImportGraphDef(). If the output is remapped via an input
## mapping, the corresponding existing tensor in graph will be returned.
## oper_name is copied and has no lifetime requirements.
## ```
proc TF_ImportGraphDefOptionsNumReturnOutputs*(opts: ptr TF_ImportGraphDefOptions): cint {.
importc, cdecl, impc_apiHdr.}
## ```
## Returns the number of return outputs added via
## TF_ImportGraphDefOptionsAddReturnOutput().
## ```
proc TF_ImportGraphDefOptionsAddReturnOperation*(
opts: ptr TF_ImportGraphDefOptions; oper_name: cstring) {.importc, cdecl,
impc_apiHdr.}
## ```
## Add an operation in graph_def to be returned via the return_opers output
## parameter of TF_GraphImportGraphDef(). oper_name is copied and has no
## lifetime requirements.
## ```
proc TF_ImportGraphDefOptionsNumReturnOperations*(
opts: ptr TF_ImportGraphDefOptions): cint {.importc, cdecl, impc_apiHdr.}
## ```
## Returns the number of return operations added via
## TF_ImportGraphDefOptionsAddReturnOperation().
## ```
proc TF_ImportGraphDefResultsReturnOutputs*(
results: ptr TF_ImportGraphDefResults; num_outputs: ptr cint;
outputs: ptr ptr TF_Output) {.importc, cdecl, impc_apiHdr.}
## ```
## Fetches the return outputs requested via
## TF_ImportGraphDefOptionsAddReturnOutput(). The number of fetched outputs is
## returned in num_outputs. The array of return outputs is returned in
## outputs.outputs is owned by and has the lifetime of results.
## ```
proc TF_ImportGraphDefResultsReturnOperations*(
results: ptr TF_ImportGraphDefResults; num_opers: ptr cint;
opers: ptr ptr ptr TF_Operation) {.importc, cdecl, impc_apiHdr.}
## ```
## Fetches the return operations requested via
## TF_ImportGraphDefOptionsAddReturnOperation(). The number of fetched
## operations is returned in num_opers. The array of return operations is
## returned in opers.opers is owned by and has the lifetime of results.
## ```
proc TF_ImportGraphDefResultsMissingUnusedInputMappings*(
results: ptr TF_ImportGraphDefResults;
num_missing_unused_input_mappings: ptr cint; src_names: ptr ptr cstring;
src_indexes: ptr ptr cint) {.importc, cdecl, impc_apiHdr.}
## ```
## Fetches any input mappings requested via
## TF_ImportGraphDefOptionsAddInputMapping() that didn't appear in the GraphDef
## and weren't used as input to any node in the imported graph def. The number
## of fetched mappings is returned in num_missing_unused_input_mappings. The
## array of each mapping's source node name is returned in src_names, and the
## array of each mapping's source index is returned in src_indexes.
##
## src_names,src_indexes, and the memory backing each string in
## src_names are owned by and have the lifetime of results.
## ```
proc TF_DeleteImportGraphDefResults*(results: ptr TF_ImportGraphDefResults) {.
importc, cdecl, impc_apiHdr.}
## ```
## Deletes a results object returned by TF_GraphImportGraphDefWithResults().
## ```
proc TF_GraphImportGraphDefWithResults*(graph: ptr TF_Graph;
graph_def: ptr TF_Buffer;
options: ptr TF_ImportGraphDefOptions;
status: ptr TF_Status): ptr TF_ImportGraphDefResults {.
importc, cdecl, impc_apiHdr.}
## ```
## Import the graph serialized in graph_def into graph. Returns nullptr and
## a bad status on error. Otherwise, returns a populated
## TF_ImportGraphDefResults instance. The returned instance must be deleted via
## TF_DeleteImportGraphDefResults().
## ```
proc TF_GraphImportGraphDefWithReturnOutputs*(graph: ptr TF_Graph;
graph_def: ptr TF_Buffer; options: ptr TF_ImportGraphDefOptions;
return_outputs: ptr TF_Output; num_return_outputs: cint; status: ptr TF_Status) {.
importc, cdecl, impc_apiHdr.}
## ```
## Import the graph serialized in graph_def into graph.
## Convenience function for when only return outputs are needed.
##
## num_return_outputs must be the number of return outputs added (i.e. the
## result of TF_ImportGraphDefOptionsNumReturnOutputs()). If
## num_return_outputs is non-zero, return_outputs must be of length
## num_return_outputs. Otherwise it can be null.
## ```
proc TF_GraphImportGraphDef*(graph: ptr TF_Graph; graph_def: ptr TF_Buffer;
options: ptr TF_ImportGraphDefOptions;
status: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## Import the graph serialized in graph_def into graph.
## Convenience function for when no results are needed.
## ```
proc TF_GraphCopyFunction*(g: ptr TF_Graph; `func`: ptr TF_Function;
grad: ptr TF_Function; status: ptr TF_Status) {.importc,
cdecl, impc_apiHdr.}
## ```
## Adds a copy of function func and optionally its gradient function grad
## to g. Once func/grad is added to g, it can be called by creating
## an operation using the function's name.
## Any changes to func/grad (including deleting it) done after this method
## returns, won't affect the copy of func/grad in g.
## If func or grad are already in g, TF_GraphCopyFunction has no
## effect on them, but can establish the function->gradient relationship
## between them if func does not already have a gradient. If func already
## has a gradient different from grad, an error is returned.
##
## func must not be null.
## If grad is null and func is not in g, func is added without a
## gradient.
## If grad is null and func is in g, TF_GraphCopyFunction is a noop.
## grad must have appropriate signature as described in the doc of
## GradientDef in tensorflow/core/framework/function.proto.
##
## If successful, status is set to OK and func and grad are added to g.
## Otherwise, status is set to the encountered error and g is unmodified.
## ```
proc TF_GraphNumFunctions*(g: ptr TF_Graph): cint {.importc, cdecl, impc_apiHdr.}
## ```
## Returns the number of TF_Functions registered in g.
## ```
proc TF_GraphGetFunctions*(g: ptr TF_Graph; funcs: ptr ptr TF_Function; max_func: cint;
status: ptr TF_Status): cint {.importc, cdecl, impc_apiHdr.}
## ```
## Fills in funcs with the TF_Function* registered in g.
## funcs must point to an array of TF_Function* of length at least
## max_func. In usual usage, max_func should be set to the result of
## TF_GraphNumFunctions(g). In this case, all the functions registered in
## g will be returned. Else, an unspecified subset.
##
## If successful, returns the number of TF_Function* successfully set in
## funcs and sets status to OK. The caller takes ownership of
## all the returned TF_Functions. They must be deleted with TF_DeleteFunction.
## On error, returns 0, sets status to the encountered error, and the contents
## of funcs will be undefined.
## ```
proc TF_OperationToNodeDef*(oper: ptr TF_Operation; output_node_def: ptr TF_Buffer;
status: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
proc TF_NewWhile*(g: ptr TF_Graph; inputs: ptr TF_Output; ninputs: cint;
status: ptr TF_Status): TF_WhileParams {.importc, cdecl, impc_apiHdr.}
## ```
## Creates a TF_WhileParams for creating a while loop in g. inputs are
## outputs that already exist in g used as initial values for the loop
## variables.
##
## The returned TF_WhileParams will have all fields initialized except
## cond_output, body_outputs, and name. The body_outputs buffer will be
## allocated to size ninputs. The caller should build cond_graph and
## body_graph starting from the inputs, and store the final outputs in
## cond_output and body_outputs.
##
## If status is OK, the caller must call either TF_FinishWhile or
## TF_AbortWhile on the returned TF_WhileParams. If status isn't OK, the
## returned TF_WhileParams is not valid, and the caller should not call
## TF_FinishWhile() or TF_AbortWhile().
##
## Missing functionality (TODO):
## - Gradients
## - Reference-type inputs
## - Directly referencing external tensors from the cond/body graphs (this is
## possible in the Python API)
## ```
proc TF_FinishWhile*(params: ptr TF_WhileParams; status: ptr TF_Status;
outputs: ptr TF_Output) {.importc, cdecl, impc_apiHdr.}
## ```
## Builds the while loop specified by params and returns the output tensors of
## the while loop in outputs. outputs should be allocated to size
## params.ninputs.
##
## params is no longer valid once this returns.
##
## Either this or TF_AbortWhile() must be called after a successful
## TF_NewWhile() call.
## ```
proc TF_AbortWhile*(params: ptr TF_WhileParams) {.importc, cdecl, impc_apiHdr.}
## ```
## Frees paramss resources without building a while loop. params is no
## longer valid after this returns. Either this or TF_FinishWhile() must be
## called after a successful TF_NewWhile() call.
## ```
proc TF_AddGradients*(g: ptr TF_Graph; y: ptr TF_Output; ny: cint; x: ptr TF_Output;
nx: cint; dx: ptr TF_Output; status: ptr TF_Status;
dy: ptr TF_Output) {.importc, cdecl, impc_apiHdr.}
## ```
## Adds operations to compute the partial derivatives of sum of ys w.r.t xs,
## i.e., d(y_1 + y_2 + ...)/dx_1, d(y_1 + y_2 + ...)/dx_2...
##
## dx are used as initial gradients (which represent the symbolic partial
## derivatives of some loss function L w.r.t. y).
## dx must be nullptr or have size ny.
## If dx is nullptr, the implementation will use dx of OnesLike for all
## shapes in y.
## The partial derivatives are returned in dy. dy should be allocated to
## size nx.
##
## Gradient nodes are automatically named under the "gradients/" prefix. To
## guarantee name uniqueness, subsequent calls to the same graph will
## append an incremental tag to the prefix: "gradients_1/", "gradients_2/", ...
## See TF_AddGradientsWithPrefix, which provides a means to specify a custom
## name prefix for operations added to a graph to compute the gradients.
##
## WARNING: This function does not yet support all the gradients that python
## supports. See
## https:www.tensorflow.org/code/tensorflow/cc/gradients/README.md
## for instructions on how to add C++ more gradients.
## ```
proc TF_AddGradientsWithPrefix*(g: ptr TF_Graph; prefix: cstring; y: ptr TF_Output;
ny: cint; x: ptr TF_Output; nx: cint; dx: ptr TF_Output;
status: ptr TF_Status; dy: ptr TF_Output) {.importc,
cdecl, impc_apiHdr.}
## ```
## Adds operations to compute the partial derivatives of sum of ys w.r.t xs,
## i.e., d(y_1 + y_2 + ...)/dx_1, d(y_1 + y_2 + ...)/dx_2...
## This is a variant of TF_AddGradients that allows to caller to pass a custom
## name prefix to the operations added to a graph to compute the gradients.
##
## dx are used as initial gradients (which represent the symbolic partial
## derivatives of some loss function L w.r.t. y).
## dx must be nullptr or have size ny.
## If dx is nullptr, the implementation will use dx of OnesLike for all
## shapes in y.
## The partial derivatives are returned in dy. dy should be allocated to
## size nx.
## prefix names the scope into which all gradients operations are being added.
## prefix must be unique within the provided graph otherwise this operation
## will fail. If prefix is nullptr, the default prefixing behaviour takes
## place, see TF_AddGradients for more details.
##
## WARNING: This function does not yet support all the gradients that python
## supports. See
## https:www.tensorflow.org/code/tensorflow/cc/gradients/README.md
## for instructions on how to add C++ more gradients.
## ```
proc TF_GraphToFunction*(fn_body: ptr TF_Graph; fn_name: cstring;
append_hash_to_fn_name: cuchar; num_opers: cint;
opers: ptr ptr TF_Operation; ninputs: cint;
inputs: ptr TF_Output; noutputs: cint;
outputs: ptr TF_Output; output_names: ptr cstring;
opts: ptr TF_FunctionOptions; description: cstring;
status: ptr TF_Status): ptr TF_Function {.importc, cdecl,
impc_apiHdr.}
## ```
## Create a TF_Function from a TF_Graph
##
## Params:
## fn_body - the graph whose operations (or subset of whose operations) will be
## converted to TF_Function.
## fn_name - the name of the new TF_Function. Should match the operation
## name (OpDef.name) regexp [A-Z][A-Za-z0-9_.\\-/]*.
## If append_hash_to_fn_name is false, fn_name must be distinct
## from other function and operation names (at least those
## registered in graphs where this function will be used).
## append_hash_to_fn_name - Must be 0 or 1. If set to 1, the actual name
## of the function will be fn_name appended with
## '_<hash_of_this_function's_definition>'.
## If set to 0, the function's name will be fn_name.
## num_opers - num_opers contains the number of elements in the opers array
## or a special value of -1 meaning that no array is given.
## The distinction between an empty array of operations and no
## array of operations is necessary to distinguish the case of
## creating a function with no body (e.g. identity or permutation)
## and the case of creating a function whose body contains all
## the nodes in the graph (except for the automatic skipping, see
## below).
## opers - Array of operations to become the body of the function or null.
## - If no array is given (num_opers = -1), all the
## operations in fn_body will become part of the function
## except operations referenced in inputs. These operations
## must have a single output (these operations are typically
## placeholders created for the sole purpose of representing
## an input. We can relax this constraint if there are
## compelling use cases).
## - If an array is given (num_opers >= 0), all operations
## in it will become part of the function. In particular, no
## automatic skipping of dummy input operations is performed.
## ninputs - number of elements in inputs array
## inputs - array of TF_Outputs that specify the inputs to the function.
## If ninputs is zero (the function takes no inputs), inputs
## can be null. The names used for function inputs are normalized
## names of the operations (usually placeholders) pointed to by
## inputs. These operation names should start with a letter.
## Normalization will convert all letters to lowercase and
## non-alphanumeric characters to '_' to make resulting names match
## the "[a-z][a-z0-9_]*" pattern for operation argument names.
## inputs cannot contain the same tensor twice.
## noutputs - number of elements in outputs array
## outputs - array of TF_Outputs that specify the outputs of the function.
## If noutputs is zero (the function returns no outputs), outputs
## can be null. outputs can contain the same tensor more than once.
## output_names - The names of the function's outputs. output_names array
## must either have the same length as outputs
## (i.e. noutputs) or be null. In the former case,
## the names should match the regular expression for ArgDef
## names - "[a-z][a-z0-9_]*". In the latter case,
## names for outputs will be generated automatically.
## opts - various options for the function, e.g. XLA's inlining control.
## description - optional human-readable description of this function.
## status - Set to OK on success and an appropriate error on failure.
##
## Note that when the same TF_Output is listed as both an input and an output,
## the corresponding function's output will equal to this input,
## instead of the original node's output.
##
## Callers must also satisfy the following constraints:
## - inputs cannot refer to TF_Outputs within a control flow context. For
## example, one cannot use the output of "switch" node as input.
## - inputs and outputs cannot have reference types. Reference types are
## not exposed through C API and are being replaced with Resources. We support
## reference types inside function's body to support legacy code. Do not
## use them in new code.
## - Every node in the function's body must have all of its inputs (including
## control inputs). In other words, for every node in the body, each input
## must be either listed in inputs or must come from another node in
## the body. In particular, it is an error to have a control edge going from
## a node outside of the body into a node in the body. This applies to control
## edges going from nodes referenced in inputs to nodes in the body when
## the former nodes are not in the body (automatically skipped or not
## included in explicitly specified body).
##
## Returns:
## On success, a newly created TF_Function instance. It must be deleted by
## calling TF_DeleteFunction.
##
## On failure, null.
## ```
proc TF_GraphToFunctionWithControlOutputs*(fn_body: ptr TF_Graph; fn_name: cstring;
append_hash_to_fn_name: cuchar; num_opers: cint; opers: ptr ptr TF_Operation;
ninputs: cint; inputs: ptr TF_Output; noutputs: cint; outputs: ptr TF_Output;
output_names: ptr cstring; ncontrol_outputs: cint;
control_outputs: ptr ptr TF_Operation; control_output_names: ptr cstring;
opts: ptr TF_FunctionOptions; description: cstring; status: ptr TF_Status): ptr TF_Function {.
importc, cdecl, impc_apiHdr.}
## ```
## Similar to TF_GraphToFunction but allows specifying control outputs of the
## function.
##
## The arguments of TF_GraphToFunction have the same meaning, but the new
## arguments are as follows:
##
## ncontrol_outputs: Number of control outputs of the function.
## control_outputs: vector of TF_Operation objects to be marked as control
## outputs of the function. Operations marked as control outputs are
## guaranteed to execute.
## control_output_names: Optional. If not nullptr, vector of strings, one
## per control output, with their names to be added to the function's
## OpDef.
## ```
proc TF_FunctionName*(`func`: ptr TF_Function): cstring {.importc, cdecl, impc_apiHdr.}
## ```
## Returns the name of the graph function.
## The return value points to memory that is only usable until the next
## mutation tofunc.
## ```
proc TF_FunctionToFunctionDef*(`func`: ptr TF_Function;
output_func_def: ptr TF_Buffer; status: ptr TF_Status) {.
importc, cdecl, impc_apiHdr.}
## ```
## Write out a serialized representation of func (as a FunctionDef protocol
## message) to output_func_def (allocated by TF_NewBuffer()).
## output_func_def's underlying buffer will be freed when TF_DeleteBuffer()
## is called.
##
## May fail on very large graphs in the future.
## ```
proc TF_FunctionImportFunctionDef*(proto: pointer; proto_len: uint;
status: ptr TF_Status): ptr TF_Function {.importc,
cdecl, impc_apiHdr.}
## ```
## Construct and return the function whose FunctionDef representation is
## serialized in proto. proto_len must equal the number of bytes
## pointed to by proto.
## Returns:
## On success, a newly created TF_Function instance. It must be deleted by
## calling TF_DeleteFunction.
##
## On failure, null.
## ```
proc TF_FunctionSetAttrValueProto*(`func`: ptr TF_Function; attr_name: cstring;
proto: pointer; proto_len: uint;
status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## Sets function attribute named attr_name to value stored in proto.
## If this attribute is already set to another value, it is overridden.
## proto should point to a sequence of bytes of length proto_len
## representing a binary serialization of an AttrValue protocol
## buffer.
## ```
proc TF_FunctionGetAttrValueProto*(`func`: ptr TF_Function; attr_name: cstring;
output_attr_value: ptr TF_Buffer;
status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## Sets output_attr_value to the binary-serialized AttrValue proto
## representation of the value of the attr_name attr of func.
## If attr_name attribute is not present, status is set to an error.
## ```
proc TF_DeleteFunction*(`func`: ptr TF_Function) {.importc, cdecl, impc_apiHdr.}
## ```
## Frees the memory used by the func struct.
## TF_DeleteFunction is a noop if func is null.
## Deleting a function does not remove it from any graphs it was copied to.
## ```
proc TF_TryEvaluateConstant*(graph: ptr TF_Graph; output: TF_Output;
result: ptr ptr TF_Tensor; status: ptr TF_Status): cuchar {.
importc, cdecl, impc_apiHdr.}
## ```
## Attempts to evaluate output. This will only be possible if output doesn't
## depend on any graph inputs (this function is safe to call if this isn't the
## case though).
##
## If the evaluation is successful, this function returns true and outputs
## value is returned in result. Otherwise returns false. An error status is
## returned if something is wrong with the graph or input. Note that this may
## return false even if no error status is set.
## ```
proc TF_NewSession*(graph: ptr TF_Graph; opts: ptr TF_SessionOptions;
status: ptr TF_Status): ptr TF_Session {.importc, cdecl, impc_apiHdr.}
## ```
## Return a new execution session with the associated graph, or NULL on
## error. Does not take ownership of any input parameters.
##
## graph must be a valid graph (not deleted or nullptr). graph will be be
## kept alive for the lifetime of the returned TF_Session. New nodes can still
## be added to graph after this call.
## ```
proc TF_LoadSessionFromSavedModel*(session_options: ptr TF_SessionOptions;
run_options: ptr TF_Buffer; export_dir: cstring;
tags: ptr cstring; tags_len: cint;
graph: ptr TF_Graph;
meta_graph_def: ptr TF_Buffer;
status: ptr TF_Status): ptr TF_Session {.importc,
cdecl, impc_apiHdr.}
## ```
## This function creates a new TF_Session (which is created on success) using
## session_options, and then initializes state (restoring tensors and other
## assets) using run_options.
##
## Any NULL and non-NULL value combinations for (run_options, meta_graph_def)
## are valid.
##
## - export_dir must be set to the path of the exported SavedModel.
## - tags must include the set of tags used to identify one MetaGraphDef in
## the SavedModel.
## - graph must be a graph newly allocated with TF_NewGraph().
##
## If successful, populates graph with the contents of the Graph and
## meta_graph_def with the MetaGraphDef of the loaded model.
## ```
proc TF_CloseSession*(a1: ptr TF_Session; status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## Close a session.
##
## Contacts any other processes associated with the session, if applicable.
## May not be called after TF_DeleteSession().
## ```
proc TF_DeleteSession*(a1: ptr TF_Session; status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## Destroy a session object.
##
## Even if error information is recorded instatus, this call discards all
## local resources associated with the session. The session may not be used
## during or after this call (and the session drops its reference to the
## corresponding graph).
## ```
proc TF_SessionRun*(session: ptr TF_Session; run_options: ptr TF_Buffer;
inputs: ptr TF_Output; input_values: ptr ptr TF_Tensor;
ninputs: cint; outputs: ptr TF_Output;
output_values: ptr ptr TF_Tensor; noutputs: cint;
target_opers: ptr ptr TF_Operation; ntargets: cint;
run_metadata: ptr TF_Buffer; a18: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## 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]).
##
## Any NULL and non-NULL value combinations for (run_options,
## run_metadata) are valid.
##
## - run_options may be NULL, in which case it will be ignored; or
## non-NULL, in which case it must point to a TF_Buffer containing the
## serialized representation of a RunOptions protocol buffer.
## - run_metadata may be NULL, in which case it will be ignored; or
## non-NULL, in which case it must point to an empty, freshly allocated
## TF_Buffer that may be updated to contain the serialized representation
## of a RunMetadata protocol buffer.
##
## The caller retains ownership of input_values (which can be deleted using
## TF_DeleteTensor). The caller also retains ownership of run_options and/or
## run_metadata (when not NULL) and should manually call TF_DeleteBuffer on
## them.
##
## On success, the tensors corresponding to outputs[0,noutputs-1] are placed in
## output_values[]. Ownership of the elements of output_values[] is transferred
## to the caller, which must eventually call TF_DeleteTensor on them.
##
## On failure, output_values[] contains NULLs.
## ```
proc TF_SessionPRunSetup*(a1: ptr TF_Session; inputs: ptr TF_Output; ninputs: cint;
outputs: ptr TF_Output; noutputs: cint;
target_opers: ptr ptr TF_Operation; ntargets: cint;
handle: ptr cstring; a14: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## Set up the graph with the intended feeds (inputs) and fetches (outputs) for a
## sequence of partial run calls.
##
## On success, returns a handle that is used for subsequent PRun calls. The
## handle should be deleted with TF_DeletePRunHandle when it is no longer
## needed.
##
## On failure, out_status contains a tensorflow::Status with an error
## message.handle is set to nullptr.
## ```
proc TF_SessionPRun*(a1: ptr TF_Session; handle: cstring; inputs: ptr TF_Output;
input_values: ptr ptr TF_Tensor; ninputs: cint;
outputs: ptr TF_Output; output_values: ptr ptr TF_Tensor;
noutputs: cint; target_opers: ptr ptr TF_Operation;
ntargets: cint; a15: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## Continue to run the graph with additional feeds and fetches. The
## execution state is uniquely identified by the handle.
## ```
proc TF_DeletePRunHandle*(handle: cstring) {.importc, cdecl, impc_apiHdr.}
## ```
## Deletes a handle allocated by TF_SessionPRunSetup.
## Once called, no more calls to TF_SessionPRun should be made.
## ```
proc TF_NewDeprecatedSession*(a1: ptr TF_SessionOptions; status: ptr TF_Status): ptr TF_DeprecatedSession {.
importc, cdecl, impc_apiHdr.}
proc TF_CloseDeprecatedSession*(a1: ptr TF_DeprecatedSession; status: ptr TF_Status) {.
importc, cdecl, impc_apiHdr.}
proc TF_DeleteDeprecatedSession*(a1: ptr TF_DeprecatedSession; status: ptr TF_Status) {.
importc, cdecl, impc_apiHdr.}
proc TF_Reset*(opt: ptr TF_SessionOptions; containers: ptr cstring; ncontainers: cint;
status: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
proc TF_ExtendGraph*(a1: ptr TF_DeprecatedSession; proto: pointer; proto_len: uint;
a4: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## Treat the bytes proto[0,proto_len-1] as a serialized GraphDef and
## add the nodes in that GraphDef to the graph for the session.
##
## Prefer use of TF_Session and TF_GraphImportGraphDef over this.
## ```
proc TF_Run*(a1: ptr TF_DeprecatedSession; run_options: ptr TF_Buffer;
input_names: ptr cstring; inputs: ptr ptr TF_Tensor; ninputs: cint;
output_names: ptr cstring; outputs: ptr ptr TF_Tensor; noutputs: cint;
target_oper_names: ptr cstring; ntargets: cint;
run_metadata: ptr TF_Buffer; a12: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## See TF_SessionRun() above.
## ```
proc TF_PRunSetup*(a1: ptr TF_DeprecatedSession; input_names: ptr cstring;
ninputs: cint; output_names: ptr cstring; noutputs: cint;
target_oper_names: ptr cstring; ntargets: cint;
handle: ptr cstring; a9: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## See TF_SessionPRunSetup() above.
## ```
proc TF_PRun*(a1: ptr TF_DeprecatedSession; handle: cstring; input_names: ptr cstring;
inputs: ptr ptr TF_Tensor; ninputs: cint; output_names: ptr cstring;
outputs: ptr ptr TF_Tensor; noutputs: cint;
target_oper_names: ptr cstring; ntargets: cint; a11: ptr TF_Status) {.
importc, cdecl, impc_apiHdr.}
## ```
## See TF_SessionPRun above.
## ```
proc TF_SessionListDevices*(session: ptr TF_Session; status: ptr TF_Status): ptr TF_DeviceList {.
importc, cdecl, impc_apiHdr.}
## ```
## Lists all devices in a TF_Session.
##
## Caller takes ownership of the returned TF_DeviceList* which must eventually
## be freed with a call to TF_DeleteDeviceList.
## ```
proc TF_DeprecatedSessionListDevices*(session: ptr TF_DeprecatedSession;
status: ptr TF_Status): ptr TF_DeviceList {.
importc, cdecl, impc_apiHdr.}
## ```
## Lists all devices in a TF_Session.
##
## Caller takes ownership of the returned TF_DeviceList* which must eventually
## be freed with a call to TF_DeleteDeviceList.
## ```
proc TF_DeleteDeviceList*(list: ptr TF_DeviceList) {.importc, cdecl, impc_apiHdr.}
## ```
## Deallocates the device list.
## ```
proc TF_DeviceListCount*(list: ptr TF_DeviceList): cint {.importc, cdecl, impc_apiHdr.}
## ```
## Counts the number of elements in the device list.
## ```
proc TF_DeviceListName*(list: ptr TF_DeviceList; index: cint; status: ptr TF_Status): cstring {.
importc, cdecl, impc_apiHdr.}
## ```
## Retrieves the full name of the device (e.g. /job:worker/replica:0/...)
## The return value will be a pointer to a null terminated string. The caller
## must not modify or delete the string. It will be deallocated upon a call to
## TF_DeleteDeviceList.
##
## If index is out of bounds, an error code will be set in the status object,
## and a null pointer will be returned.
## ```
proc TF_DeviceListType*(list: ptr TF_DeviceList; index: cint; status: ptr TF_Status): cstring {.
importc, cdecl, impc_apiHdr.}
## ```
## Retrieves the type of the device at the given index.
##
## The caller must not modify or delete the string. It will be deallocated upon
## a call to TF_DeleteDeviceList.
##
## If index is out of bounds, an error code will be set in the status object,
## and a null pointer will be returned.
## ```
proc TF_DeviceListMemoryBytes*(list: ptr TF_DeviceList; index: cint;
status: ptr TF_Status): int64 {.importc, cdecl,
impc_apiHdr.}
## ```
## Retrieve the amount of memory associated with a given device.
##
## If index is out of bounds, an error code will be set in the status object,
## and -1 will be returned.
## ```
proc TF_DeviceListIncarnation*(list: ptr TF_DeviceList; index: cint;
status: ptr TF_Status): uint64 {.importc, cdecl,
impc_apiHdr.}
## ```
## Retrieve the incarnation number of a given device.
##
## If index is out of bounds, an error code will be set in the status object,
## and 0 will be returned.
## ```
proc TF_LoadLibrary*(library_filename: cstring; status: ptr TF_Status): ptr TF_Library {.
importc, cdecl, impc_apiHdr.}
## ```
## Load the library specified by library_filename and register the ops and
## kernels present in that library.
##
## Pass "library_filename" to a platform-specific mechanism for dynamically
## loading a library. The rules for determining the exact location of the
## library are platform-specific and are not documented here.
##
## On success, place OK in status and return the newly created library handle.
## The caller owns the library handle.
##
## On failure, place an error status in status and return NULL.
## ```
proc TF_GetOpList*(lib_handle: ptr TF_Library): TF_Buffer {.importc, cdecl, impc_apiHdr.}
## ```
## Get the OpList of OpDefs defined in the library pointed by lib_handle.
##
## Returns a TF_Buffer. The memory pointed to by the result is owned by
## lib_handle. The data in the buffer will be the serialized OpList proto for
## ops defined in the library.
## ```
proc TF_DeleteLibraryHandle*(lib_handle: ptr TF_Library) {.importc, cdecl, impc_apiHdr.}
## ```
## Frees the memory associated with the library handle.
## Does NOT unload the library.
## ```
proc TF_GetAllOpList*(): ptr TF_Buffer {.importc, cdecl, impc_apiHdr.}
## ```
## Get the OpList of all OpDefs defined in this address space.
## Returns a TF_Buffer, ownership of which is transferred to the caller
## (and can be freed using TF_DeleteBuffer).
##
## The data in the buffer will be the serialized OpList proto for ops registered
## in this address space.
## ```
proc TF_NewApiDefMap*(op_list_buffer: ptr TF_Buffer; status: ptr TF_Status): ptr TF_ApiDefMap {.
importc, cdecl, impc_apiHdr.}
## ```
## Creates a new TF_ApiDefMap instance.
##
## Params:
## op_list_buffer - TF_Buffer instance containing serialized OpList
## protocol buffer. (See
## https:www.tensorflow.org/code/tensorflow/core/framework/op_def.proto
## for the OpList proto definition).
## status - Set to OK on success and an appropriate error on failure.
## ```
proc TF_DeleteApiDefMap*(apimap: ptr TF_ApiDefMap) {.importc, cdecl, impc_apiHdr.}
## ```
## Deallocates a TF_ApiDefMap.
## ```
proc TF_ApiDefMapPut*(api_def_map: ptr TF_ApiDefMap; text: cstring; text_len: uint;
status: ptr TF_Status) {.importc, cdecl, impc_apiHdr.}
## ```
## Add ApiDefs to the map.
##
## text corresponds to a text representation of an ApiDefs protocol message.
## (https:www.tensorflow.org/code/tensorflow/core/framework/api_def.proto).
##
## The provided ApiDefs will be merged with existing ones in the map, with
## precedence given to the newly added version in case of conflicts with
## previous calls to TF_ApiDefMapPut.
## ```
proc TF_ApiDefMapGet*(api_def_map: ptr TF_ApiDefMap; name: cstring; name_len: uint;
status: ptr TF_Status): ptr TF_Buffer {.importc, cdecl,
impc_apiHdr.}
## ```
## Returns a serialized ApiDef protocol buffer for the TensorFlow operation
## named name.
## ```
proc TF_GetAllRegisteredKernels*(status: ptr TF_Status): ptr TF_Buffer {.importc,
cdecl, impc_apiHdr.}
## ```
## --------------------------------------------------------------------------
## Kernel definition information.
## Returns a serialized KernelList protocol buffer containing KernelDefs for all
## registered kernels.
## ```
proc TF_GetRegisteredKernelsForOp*(name: cstring; status: ptr TF_Status): ptr TF_Buffer {.
importc, cdecl, impc_apiHdr.}
## ```
## Returns a serialized KernelList protocol buffer containing KernelDefs for all
## kernels registered for the operation named name.
## ```
proc TF_NewServer*(proto: pointer; proto_len: uint; status: ptr TF_Status): ptr TF_Server {.
importc, cdecl, impc_apiHdr.}
## ```
## Creates a new in-process TensorFlow server configured using a serialized
## ServerDef protocol buffer provided via proto and proto_len.
##
## The server will not serve any requests until TF_ServerStart is invoked.
## The server will stop serving requests once TF_ServerStop or
## TF_DeleteServer is invoked.
## ```
proc TF_ServerStart*(server: ptr TF_Server; status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## Starts an in-process TensorFlow server.
## ```
proc TF_ServerStop*(server: ptr TF_Server; status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## Stops an in-process TensorFlow server.
## ```
proc TF_ServerJoin*(server: ptr TF_Server; status: ptr TF_Status) {.importc, cdecl,
impc_apiHdr.}
## ```
## Blocks until the server has been successfully stopped (via TF_ServerStop or
## TF_ServerClose).
## ```
proc TF_ServerTarget*(server: ptr TF_Server): cstring {.importc, cdecl, impc_apiHdr.}
## ```
## Returns the target string that can be provided to TF_SetTarget() to connect
## a TF_Session to server.
##
## The returned string is valid only until TF_DeleteServer is invoked.
## ```
proc TF_DeleteServer*(server: ptr TF_Server) {.importc, cdecl, impc_apiHdr.}
## ```
## Destroy an in-process TensorFlow server, frees memory. If server is running
## it will be stopped and joined.
## ```
proc TF_RegisterLogListener*(listener: proc (a1: cstring) {.cdecl.}) {.importc, cdecl,
impc_apiHdr.}
## ```
## Register a listener method that processes printed messages.
##
## If any listeners are registered, the print operator will call all listeners
## with the printed messages and immediately return without writing to the
## logs.
## ```
{.pop.}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment