diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..92a2323 --- /dev/null +++ b/build.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +swig -php7 tensorflow.i +echo "build wrap" +gcc `php-config --includes` -fpic -c tensorflow_wrap.c +echo "build interface" +gcc -fpic -c tensorflow_.c -o tensorflow_.o +echo "link" +gcc -shared tensorflow_wrap.o tensorflow_.o -o tensorflow.so -L. -ltensorflow diff --git a/tensorflow.i b/tensorflow.i new file mode 100644 index 0000000..4c1cfb8 --- /dev/null +++ b/tensorflow.i @@ -0,0 +1,359 @@ +%module tensorflow +%include "typemaps.i" + +%{ +#include "tensorflow_.h" +%} + + +%inline %{ + +TF_Status* TF_NewStatus(); +void TF_DeleteStatus(TF_Status*); +void TF_SetStatus(TF_Status* s, TF_Code code, const char* msg); +TF_Code TF_GetCode(const TF_Status* s); +const char* TF_Message(const TF_Status* s); +TF_Buffer* TF_NewBufferFromString(const void* proto, size_t proto_len); +TF_Buffer* TF_NewBuffer(); +void TF_DeleteBuffer(TF_Buffer*); +TF_Buffer TF_GetBuffer(TF_Buffer* buffer); +TF_Tensor* TF_NewTensor(TF_DataType, const int64_t* dims, int num_dims, + void* data, size_t len, + void (*deallocator)(void* data, size_t len, + void* arg), + void* deallocator_arg); + +extern TF_Tensor* TF_AllocateTensor(TF_DataType, const int64_t* dims, + int num_dims, size_t len); +extern void TF_DeleteTensor(TF_Tensor*); +extern TF_DataType TF_TensorType(const TF_Tensor*); +extern int TF_NumDims(const TF_Tensor*); +extern int64_t TF_Dim(const TF_Tensor* tensor, int dim_index); +extern size_t TF_TensorByteSize(const TF_Tensor*); +extern void* TF_TensorData(const TF_Tensor*); +extern size_t TF_StringEncode(const char* src, size_t src_len, char* dst, + size_t dst_len, TF_Status* status); +extern size_t TF_StringDecode(const char* src, size_t src_len, const char** dst, + size_t* dst_len, TF_Status* status); + +extern size_t TF_StringEncodedSize(size_t len); +extern TF_SessionOptions* TF_NewSessionOptions(); +extern void TF_SetTarget(TF_SessionOptions* options, const char* target); +extern void TF_SetConfig(TF_SessionOptions* options, const void* proto, + size_t proto_len, TF_Status* status); +extern void TF_DeleteSessionOptions(TF_SessionOptions*); +extern TF_Graph* TF_NewGraph(); +extern void TF_DeleteGraph(TF_Graph*); +extern void TF_GraphSetTensorShape(TF_Graph* graph, TF_Output output, + const int64_t* dims, const int num_dims, + TF_Status* status); +extern int TF_GraphGetTensorNumDims(TF_Graph* graph, TF_Output output, + TF_Status* status); +extern void TF_GraphGetTensorShape(TF_Graph* graph, TF_Output output, + int64_t* dims, int num_dims, + TF_Status* status); +extern TF_OperationDescription* TF_NewOperation(TF_Graph* graph, + const char* op_type, + const char* oper_name); +extern void TF_SetDevice(TF_OperationDescription* desc, const char* device); +extern void TF_AddInput(TF_OperationDescription* desc, TF_Output input); +extern void TF_AddInputList(TF_OperationDescription* desc, + const TF_Output* inputs, int num_inputs); +extern void TF_AddControlInput(TF_OperationDescription* desc, + TF_Operation* input); +extern void TF_ColocateWith(TF_OperationDescription* desc, TF_Operation* op); +extern void TF_SetAttrString(TF_OperationDescription* desc, + const char* attr_name, const void* value, + size_t length); +extern void TF_SetAttrStringList(TF_OperationDescription* desc, + const char* attr_name, + const void* const* values, + const size_t* lengths, int num_values); +extern void TF_SetAttrInt(TF_OperationDescription* desc, const char* attr_name, + int64_t value); +extern void TF_SetAttrIntList(TF_OperationDescription* desc, + const char* attr_name, const int64_t* values, + int num_values); +extern void TF_SetAttrFloat(TF_OperationDescription* desc, + const char* attr_name, float value); +extern void TF_SetAttrFloatList(TF_OperationDescription* desc, + const char* attr_name, const float* values, + int num_values); +extern void TF_SetAttrBool(TF_OperationDescription* desc, const char* attr_name, + unsigned char value); +extern void TF_SetAttrBoolList(TF_OperationDescription* desc, + const char* attr_name, + const unsigned char* values, int num_values); +extern void TF_SetAttrType(TF_OperationDescription* desc, const char* attr_name, + TF_DataType value); +extern void TF_SetAttrTypeList(TF_OperationDescription* desc, + const char* attr_name, const TF_DataType* values, + int num_values); +extern void TF_SetAttrShape(TF_OperationDescription* desc, + const char* attr_name, const int64_t* dims, + int num_dims); +extern void TF_SetAttrShapeList(TF_OperationDescription* desc, + const char* attr_name, + const int64_t* const* dims, const int* num_dims, + int num_shapes); +extern void TF_SetAttrTensorShapeProto(TF_OperationDescription* desc, + const char* attr_name, const void* proto, + size_t proto_len, TF_Status* status); +extern void TF_SetAttrTensorShapeProtoList(TF_OperationDescription* desc, + const char* attr_name, + const void* const* protos, + const size_t* proto_lens, + int num_shapes, TF_Status* status); +extern void TF_SetAttrTensor(TF_OperationDescription* desc, + const char* attr_name, TF_Tensor* value, + TF_Status* status); +extern void TF_SetAttrTensorList(TF_OperationDescription* desc, + const char* attr_name, + TF_Tensor* const* values, int num_values, + TF_Status* status); +extern void TF_SetAttrValueProto(TF_OperationDescription* desc, + const char* attr_name, const void* proto, + size_t proto_len, TF_Status* status); +extern TF_Operation* TF_FinishOperation(TF_OperationDescription* desc, + TF_Status* status); +extern const char* TF_OperationName(TF_Operation* oper); +extern const char* TF_OperationOpType(TF_Operation* oper); +extern const char* TF_OperationDevice(TF_Operation* oper); + +extern int TF_OperationNumOutputs(TF_Operation* oper); +extern TF_DataType TF_OperationOutputType(TF_Output oper_out); +extern int TF_OperationOutputListLength(TF_Operation* oper, + const char* arg_name, + TF_Status* status); + +extern int TF_OperationNumInputs(TF_Operation* oper); +extern TF_DataType TF_OperationInputType(TF_Input oper_in); +extern int TF_OperationInputListLength(TF_Operation* oper, const char* arg_name, + TF_Status* status); +extern TF_Output TF_OperationInput(TF_Input oper_in); +extern int TF_OperationOutputNumConsumers(TF_Output oper_out); +extern int TF_OperationOutputConsumers(TF_Output oper_out, TF_Input* consumers, + int max_consumers); +extern int TF_OperationNumControlInputs(TF_Operation* oper); +extern int TF_OperationGetControlInputs(TF_Operation* oper, + TF_Operation** control_inputs, + int max_control_inputs); +extern int TF_OperationNumControlOutputs(TF_Operation* oper); +extern int TF_OperationGetControlOutputs(TF_Operation* oper, + TF_Operation** control_outputs, + int max_control_outputs); +extern TF_AttrMetadata TF_OperationGetAttrMetadata(TF_Operation* oper, + const char* attr_name, + TF_Status* status); +extern void TF_OperationGetAttrString(TF_Operation* oper, const char* attr_name, + void* value, size_t max_length, + TF_Status* status); +extern void TF_OperationGetAttrStringList(TF_Operation* oper, + const char* attr_name, void** values, + size_t* lengths, int max_values, + void* storage, size_t storage_size, + TF_Status* status); +extern void TF_OperationGetAttrInt(TF_Operation* oper, const char* attr_name, + int64_t* value, TF_Status* status); +extern void TF_OperationGetAttrIntList(TF_Operation* oper, + const char* attr_name, int64_t* values, + int max_values, TF_Status* status); +extern void TF_OperationGetAttrFloat(TF_Operation* oper, const char* attr_name, + float* value, TF_Status* status); +extern void TF_OperationGetAttrFloatList(TF_Operation* oper, + const char* attr_name, float* values, + int max_values, TF_Status* status); +extern void TF_OperationGetAttrBool(TF_Operation* oper, const char* attr_name, + unsigned char* value, TF_Status* status); +extern void TF_OperationGetAttrBoolList(TF_Operation* oper, + const char* attr_name, + unsigned char* values, int max_values, + TF_Status* status); +extern void TF_OperationGetAttrType(TF_Operation* oper, const char* attr_name, + TF_DataType* value, TF_Status* status); +extern void TF_OperationGetAttrTypeList(TF_Operation* oper, + const char* attr_name, + TF_DataType* values, int max_values, + TF_Status* status); +extern void TF_OperationGetAttrShape(TF_Operation* oper, const char* attr_name, + int64_t* value, int num_dims, + TF_Status* status); +extern void TF_OperationGetAttrShapeList(TF_Operation* oper, + const char* attr_name, int64_t** dims, + int* num_dims, int num_shapes, + int64_t* storage, int storage_size, + TF_Status* status); +extern void TF_OperationGetAttrTensorShapeProto(TF_Operation* oper, + const char* attr_name, + TF_Buffer* value, + TF_Status* status); +extern void TF_OperationGetAttrTensorShapeProtoList(TF_Operation* oper, + const char* attr_name, + TF_Buffer** values, + int max_values, + TF_Status* status); +extern void TF_OperationGetAttrTensor(TF_Operation* oper, const char* attr_name, + TF_Tensor** value, TF_Status* status); +extern void TF_OperationGetAttrTensorList(TF_Operation* oper, + const char* attr_name, + TF_Tensor** values, int max_values, + TF_Status* status); +extern void TF_OperationGetAttrValueProto(TF_Operation* oper, + const char* attr_name, + TF_Buffer* output_attr_value, + TF_Status* status); +extern TF_Operation* TF_GraphOperationByName(TF_Graph* graph, + const char* oper_name); +extern TF_Operation* TF_GraphNextOperation(TF_Graph* graph, size_t* pos); +extern void TF_GraphToGraphDef(TF_Graph* graph, TF_Buffer* output_graph_def, + TF_Status* status); +extern TF_ImportGraphDefOptions* TF_NewImportGraphDefOptions(); +extern void TF_DeleteImportGraphDefOptions(TF_ImportGraphDefOptions* opts); +extern void TF_ImportGraphDefOptionsSetPrefix(TF_ImportGraphDefOptions* opts, + const char* prefix); +extern void TF_ImportGraphDefOptionsAddInputMapping( + TF_ImportGraphDefOptions* opts, const char* src_name, int src_index, + TF_Output dst); +extern void TF_ImportGraphDefOptionsAddControlDependency( + TF_ImportGraphDefOptions* opts, TF_Operation* oper); +extern void TF_ImportGraphDefOptionsAddReturnOutput( + TF_ImportGraphDefOptions* opts, const char* oper_name, int index); +extern int TF_ImportGraphDefOptionsNumReturnOutputs( + const TF_ImportGraphDefOptions* opts); +extern void TF_GraphImportGraphDefWithReturnOutputs( + TF_Graph* graph, const TF_Buffer* graph_def, + const TF_ImportGraphDefOptions* options, TF_Output* return_outputs, + int num_return_outputs, TF_Status* status); +extern void TF_GraphImportGraphDef(TF_Graph* graph, const TF_Buffer* graph_def, + const TF_ImportGraphDefOptions* options, + TF_Status* status); +extern void TF_OperationToNodeDef(TF_Operation* oper, + TF_Buffer* output_node_def, + TF_Status* status); +extern TF_Session* TF_NewSession(TF_Graph* graph, const TF_SessionOptions* opts, + TF_Status* status); +TF_Session* TF_LoadSessionFromSavedModel( + const TF_SessionOptions* session_options, const TF_Buffer* run_options, + const char* export_dir, const char* const* tags, int tags_len, + TF_Graph* graph, TF_Buffer* meta_graph_def, TF_Status* status); +extern void TF_CloseSession(TF_Session*, TF_Status* status); + +extern void TF_DeleteSession(TF_Session*, TF_Status* status); +extern void TF_SessionRun(TF_Session* session, + // RunOptions + const TF_Buffer* run_options, + // Input tensors + const TF_Output* inputs, + TF_Tensor* const* input_values, int ninputs, + // Output tensors + const TF_Output* outputs, TF_Tensor** output_values, + int noutputs, + // Target operations + const TF_Operation* const* target_opers, int ntargets, + // RunMetadata + TF_Buffer* run_metadata, + // Output status + TF_Status*); +extern void TF_SessionPRunSetup(TF_Session*, + // Input names + const TF_Output* inputs, int ninputs, + // Output names + const TF_Output* outputs, int noutputs, + // Target operations + const TF_Operation* const* target_opers, + int ntargets, + // Output handle + const char** handle, + // Output status + TF_Status*); +extern void TF_SessionPRun(TF_Session*, const char* handle, + // Input tensors + const TF_Output* inputs, + TF_Tensor* const* input_values, int ninputs, + // Output tensors + const TF_Output* outputs, TF_Tensor** output_values, + int noutputs, + // Target operations + const TF_Operation* const* target_opers, + int ntargets, + // Output status + TF_Status*); +extern TF_DeprecatedSession* TF_NewDeprecatedSession(const TF_SessionOptions*, + TF_Status* status); +extern void TF_CloseDeprecatedSession(TF_DeprecatedSession*, TF_Status* status); +extern void TF_DeleteDeprecatedSession(TF_DeprecatedSession*, + TF_Status* status); +extern void TF_Reset(const TF_SessionOptions* opt, const char** containers, + int ncontainers, TF_Status* status); +extern void TF_ExtendGraph(TF_DeprecatedSession*, const void* proto, + size_t proto_len, TF_Status*); +extern void TF_Run(TF_DeprecatedSession*, const TF_Buffer* run_options, + const char** input_names, TF_Tensor** inputs, int ninputs, + const char** output_names, TF_Tensor** outputs, int noutputs, + const char** target_oper_names, int ntargets, + TF_Buffer* run_metadata, TF_Status*); +extern void TF_PRunSetup(TF_DeprecatedSession*, const char** input_names, + int ninputs, const char** output_names, int noutputs, + const char** target_oper_names, int ntargets, + const char** handle, TF_Status*); +extern void TF_PRun(TF_DeprecatedSession*, const char* handle, + const char** input_names, TF_Tensor** inputs, int ninputs, + const char** output_names, TF_Tensor** outputs, + int noutputs, const char** target_oper_names, int ntargets, + TF_Status*); +extern TF_Library* TF_LoadLibrary(const char* library_filename, + TF_Status* status); +extern TF_Buffer TF_GetOpList(TF_Library* lib_handle); +extern void TF_DeleteLibraryHandle(TF_Library* lib_handle); +extern TF_Buffer* TF_GetAllOpList(); + +%} + + +/*TF_DataType*/ + +#define PHP_TF_FLOAT 1 +#define PHP_TF_DOUBLE 2 +#define PHP_TF_INT32 3 /* Int32 tensors are always in 'host' memory*/ +#define PHP_TF_UINT8 4 +#define PHP_TF_INT16 5 +#define PHP_TF_INT8 6 +#define PHP_TF_STRING 7 +#define PHP_TF_COMPLEX64 8 /* Single-precision complex*/ +#define PHP_TF_COMPLEX 8 /* Old identifier kept for API backwards compatibility*/ +#define PHP_TF_INT64 9 +#define PHP_TF_BOOL 10 +#define PHP_TF_QINT8 11 /* Quantized int8*/ +#define PHP_TF_QUINT8 12 /* Quantized uint8*/ +#define PHP_TF_QINT32 13 /* Quantized int32*/ +#define PHP_TF_BFLOAT16 14 /* Float32 truncated to 16 bits. Only for cast ops.*/ +#define PHP_TF_QINT16 15 /* Quantized int16*/ +#define PHP_TF_QUINT16 16 /* Quantized uint16*/ +#define PHP_TF_UINT16 17 +#define PHP_TF_COMPLEX128 18 /* Double-precision complex*/ +#define PHP_TF_HALF 19 +#define PHP_TF_RESOURCE 20 + + +/*TF_Code*/ + +#define PHP_TF_OK 0 +#define PHP_TF_CANCELLED 1 +#define PHP_TF_UNKNOWN 2 +#define PHP_TF_INVALID_ARGUMENT 3 +#define PHP_TF_DEADLINE_EXCEEDED 4 +#define PHP_TF_NOT_FOUND 5 +#define PHP_TF_ALREADY_EXISTS 6 +#define PHP_TF_PERMISSION_DENIED 7 +#define PHP_TF_UNAUTHENTICATED 16 +#define PHP_TF_RESOURCE_EXHAUSTED 8 +#define PHP_TF_FAILED_PRECONDITION 9 +#define PHP_TF_ABORTED 10 +#define PHP_TF_OUT_OF_RANGE 11 +#define PHP_TF_UNIMPLEMENTED 12 +#define PHP_TF_INTERNAL 13 +#define PHP_TF_UNAVAILABLE 14 +#define PHP_TF_DATA_LOSS 15 + + + diff --git a/tensorflow.php b/tensorflow.php new file mode 100644 index 0000000..7d3b74d --- /dev/null +++ b/tensorflow.php @@ -0,0 +1,585 @@ + diff --git a/tensorflow_.c b/tensorflow_.c new file mode 100644 index 0000000..02bd771 --- /dev/null +++ b/tensorflow_.c @@ -0,0 +1,13 @@ + +#include "tensorflow/tensorflow/c/c_api.h" + +/* +int * PHP_TF_NewStatus(){ + return (int*)TF_NewStatus(); +} + +int PHP_TF_DataTypeSize(int dt){ + TF_DataTypeSize(dt); +} + +*/ diff --git a/tensorflow_.h b/tensorflow_.h new file mode 100644 index 0000000..7883b96 --- /dev/null +++ b/tensorflow_.h @@ -0,0 +1,236 @@ +/* Copyright 2015 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW__H_ +#define TENSORFLOW__H_ + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +// -------------------------------------------------------------------------- +// TF_Version returns a string describing version information of the +// TensorFlow library. TensorFlow using semantic versioning. +extern const char* TF_Version(); + +// -------------------------------------------------------------------------- +// 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. +typedef enum { + TF_FLOAT = 1, + TF_DOUBLE = 2, + TF_INT32 = 3, // Int32 tensors are always in 'host' memory. + TF_UINT8 = 4, + TF_INT16 = 5, + TF_INT8 = 6, + TF_STRING = 7, + TF_COMPLEX64 = 8, // Single-precision complex + TF_COMPLEX = 8, // Old identifier kept for API backwards compatibility + TF_INT64 = 9, + TF_BOOL = 10, + TF_QINT8 = 11, // Quantized int8 + TF_QUINT8 = 12, // Quantized uint8 + TF_QINT32 = 13, // Quantized int32 + TF_BFLOAT16 = 14, // Float32 truncated to 16 bits. Only for cast ops. + TF_QINT16 = 15, // Quantized int16 + TF_QUINT16 = 16, // Quantized uint16 + TF_UINT16 = 17, + TF_COMPLEX128 = 18, // Double-precision complex + TF_HALF = 19, + TF_RESOURCE = 20, +} TF_DataType; + +// 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. +extern size_t TF_DataTypeSize(TF_DataType dt); + +// -------------------------------------------------------------------------- +// TF_Code holds an error code. The enum values here are identical to +// corresponding values in error_codes.proto. +typedef enum { + TF_OK = 0, + TF_CANCELLED = 1, + TF_UNKNOWN = 2, + TF_INVALID_ARGUMENT = 3, + TF_DEADLINE_EXCEEDED = 4, + TF_NOT_FOUND = 5, + TF_ALREADY_EXISTS = 6, + TF_PERMISSION_DENIED = 7, + TF_UNAUTHENTICATED = 16, + TF_RESOURCE_EXHAUSTED = 8, + TF_FAILED_PRECONDITION = 9, + TF_ABORTED = 10, + TF_OUT_OF_RANGE = 11, + TF_UNIMPLEMENTED = 12, + TF_INTERNAL = 13, + TF_UNAVAILABLE = 14, + TF_DATA_LOSS = 15, +} TF_Code; + +// -------------------------------------------------------------------------- +// TF_Status holds error information. It either has an OK code, or +// else an error code with an associated error message. +typedef struct TF_Status TF_Status; + + + +// -------------------------------------------------------------------------- +// 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. +typedef struct TF_Buffer { + const void* data; + size_t length; + void (*data_deallocator)(void* data, size_t length); +} TF_Buffer; + + +// -------------------------------------------------------------------------- +// TF_Tensor holds a multi-dimensional array of elements of a single data type. +// For all types other than TF_STRING, the data buffer stores elements +// in row major order. E.g. if data is treated as a vector of TF_DataType: +// +// element 0: index (0, ..., 0) +// element 1: index (0, ..., 1) +// ... +// +// The format for TF_STRING tensors is: +// start_offset: array[uint64] +// data: byte[...] +// +// The string length (as a varint), followed by the contents of the string +// is encoded at data[start_offset[i]]]. TF_StringEncode and TF_StringDecode +// facilitate this encoding. + +typedef struct TF_Tensor TF_Tensor; + +// 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. + +// 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. + +// -------------------------------------------------------------------------- +// TF_SessionOptions holds options that can be passed during session creation. +typedef struct TF_SessionOptions TF_SessionOptions; + + +// TODO(jeff,sanjay): +// - export functions to set Config fields + +// -------------------------------------------------------------------------- +// The new graph construction API, still under development. + +// Represents a computation graph. Graphs may be shared between sessions. +// Graphs are thread-safe when used as directed below. +typedef struct TF_Graph TF_Graph; + + +// Operation being built. The underlying graph must outlive this. +typedef struct TF_OperationDescription TF_OperationDescription; + +// Operation that has been added to the graph. Valid until the graph is +// deleted -- in particular adding a new operation to the graph does not +// invalidate old TF_Operation* pointers. +typedef struct TF_Operation TF_Operation; + +// Represents a specific input of an operation. +typedef struct TF_Input { + TF_Operation* oper; + int index; // The index of the input within oper. +} TF_Input; + +// Represents a specific output of an operation. +typedef struct TF_Output { + TF_Operation* oper; + int index; // The index of the output within oper. +} TF_Output; + + +// TF_AttrType describes the type of the value of an attribute on an operation. +typedef enum { + TF_ATTR_STRING = 0, + TF_ATTR_INT = 1, + TF_ATTR_FLOAT = 2, + TF_ATTR_BOOL = 3, + TF_ATTR_TYPE = 4, + TF_ATTR_SHAPE = 5, + TF_ATTR_TENSOR = 6, + TF_ATTR_PLACEHOLDER = 7, + TF_ATTR_FUNC = 8, +} TF_AttrType; + +// TF_AttrMetadata describes the value of an attribute on an operation. +typedef struct TF_AttrMetadata { + // A boolean: 1 if the attribute value is a list, 0 otherwise. + unsigned char is_list; + + // Length of the list if is_list is true. Undefined otherwise. + int64_t list_size; + + // Type of elements of the list if is_list != 0. + // Type of the single value stored in the attribute if is_list == 0. + TF_AttrType type; + + // 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. + int64_t total_size; +} TF_AttrMetadata; + +typedef struct TF_ImportGraphDefOptions TF_ImportGraphDefOptions; +typedef struct TF_Session TF_Session; +typedef struct TF_DeprecatedSession TF_DeprecatedSession; +typedef struct TF_Library TF_Library; + + +#ifdef __cplusplus +} /* end extern "C" */ +#endif + +#endif // TENSORFLOW_C_C_API_H_ diff --git a/test_tensorflow.c b/test_tensorflow.c new file mode 100644 index 0000000..405edef --- /dev/null +++ b/test_tensorflow.c @@ -0,0 +1,11 @@ +#include "include/tensorflow/c/c_api.h" + +int main() { + TF_Status* s = TF_NewStatus(); + TF_SetStatus(s, TF_UNKNOWN, "Some error"); + if (TF_GetCode(s) != TF_UNKNOWN) { + return 1; + } + TF_DeleteStatus(s); + return 0; +} diff --git a/test_tensorflow.php b/test_tensorflow.php new file mode 100644 index 0000000..0653f0a --- /dev/null +++ b/test_tensorflow.php @@ -0,0 +1,7 @@ +