| @@ -335,3 +335,8 @@ ASALocalRun/ | |||||
| /tensorflowlib/linux/native/libtensorflow.so | /tensorflowlib/linux/native/libtensorflow.so | ||||
| /src/TensorFlowNET.Core/tensorflow.dll | /src/TensorFlowNET.Core/tensorflow.dll | ||||
| /docs/build | /docs/build | ||||
| src/TensorFlowNET.Native/libtensorflow.dll | |||||
| src/TensorFlowNET.Native/bazel-* | |||||
| /src/TensorFlowNET.Native/libtensorflow.lib | |||||
| src/TensorFlowNET.Native/c_api.h | |||||
| /.vscode | |||||
| @@ -0,0 +1,19 @@ | |||||
| # Description: | |||||
| # CSharp Native Interface library intended for implementing the | |||||
| # TensorFlow .NET Standard API using the TensorFlow C library. | |||||
| licenses(["notice"]) # Apache 2.0 | |||||
| cc_import( | |||||
| name = "libtensorflow", | |||||
| hdrs = ["c_api.h"], | |||||
| interface_library = "libtensorflow.lib", | |||||
| shared_library = "libtensorflow.dll", | |||||
| ) | |||||
| cc_binary( | |||||
| name = "csni", | |||||
| srcs = ["csni.cc"], | |||||
| deps = [":libtensorflow"], | |||||
| linkstatic = 0 | |||||
| ) | |||||
| @@ -0,0 +1,21 @@ | |||||
| #include <windows.h> | |||||
| #include <iostream> | |||||
| #include "c_api.h" | |||||
| typedef char* (__stdcall *TFFunc)(); | |||||
| int main() { | |||||
| HINSTANCE hinstLib = LoadLibrary(TEXT("libtensorflow.dll")); | |||||
| if (!hinstLib) { | |||||
| std::cout << "could not load the dynamic library" << std::endl; | |||||
| return EXIT_FAILURE; | |||||
| } | |||||
| TFFunc version = (TFFunc) GetProcAddress(hinstLib, "TF_Version"); | |||||
| if (!version) { | |||||
| std::cout << "could not locate the function" << std::endl; | |||||
| return EXIT_FAILURE; | |||||
| } | |||||
| printf("Hello from TensorFlow C library version %s", version()); | |||||
| return 0; | |||||
| } | |||||
| @@ -0,0 +1,12 @@ | |||||
| ### How to compile CSharp Native Interface | |||||
| git clone https://github.com/tensorflow/tensorflow | |||||
| `cd tensorflow/tensorflow` | |||||
| copy `csharp` folder to `tensorflow`, the csharp folder should be in the same parent directory with other language binding. | |||||
| `cd csharp` | |||||
| `bazel build //tensorflow/csharp:csni` | |||||
| @@ -0,0 +1,23 @@ | |||||
| # Description: | |||||
| # CSharp Native Interface library intended for implementing the | |||||
| # TensorFlow .NET Standard API using the TensorFlow C library. | |||||
| package( | |||||
| default_visibility = ["//visibility:private"], | |||||
| ) | |||||
| licenses(["notice"]) # Apache 2.0 | |||||
| load( | |||||
| "//tensorflow:tensorflow.bzl", | |||||
| "tf_cc_binary" | |||||
| ) | |||||
| tf_cc_binary( | |||||
| name = "csni", | |||||
| srcs = ["csni.cc"], | |||||
| deps = [ | |||||
| "//tensorflow/c:c_api", | |||||
| "//tensorflow/csharp/eager:cswrap_tfe_lib"], | |||||
| ) | |||||
| @@ -0,0 +1,7 @@ | |||||
| #include <iostream> | |||||
| #include "tensorflow/c/c_api.h" | |||||
| int main() { | |||||
| printf("Hello from TensorFlow C library version %s", TF_Version()); | |||||
| return 0; | |||||
| } | |||||
| @@ -0,0 +1,19 @@ | |||||
| load("//tensorflow:tensorflow.bzl", "tf_cc_binary") | |||||
| cc_library( | |||||
| name = "cswrap_tfe_lib", | |||||
| srcs = [ | |||||
| "cswrap_tfe_src.cc", | |||||
| ], | |||||
| hdrs = [ | |||||
| "cswrap_tfe.h", | |||||
| ], | |||||
| visibility = [ | |||||
| "//learning/deepmind/courier:__subpackages__", | |||||
| "//tensorflow:internal", | |||||
| ], | |||||
| deps = [ | |||||
| "//tensorflow/c:c_api", | |||||
| ], | |||||
| ) | |||||
| @@ -0,0 +1,4 @@ | |||||
| // Record the gradient for a given op. | |||||
| extern void TFE_Py_RecordGradient(const char* op_name, void* inputs, | |||||
| void* attrs, void* results, | |||||
| const char* name); | |||||
| @@ -0,0 +1,23 @@ | |||||
| #include <cstring> | |||||
| #include <thread> | |||||
| #include "tensorflow/core/lib/core/errors.h" | |||||
| #include "cswrap_tfe.h" | |||||
| #include "tensorflow/c/c_api.h" | |||||
| #include "tensorflow/c/c_api_internal.h" | |||||
| #include "tensorflow/core/platform/protobuf.h" | |||||
| #include "tensorflow/core/platform/types.h" | |||||
| namespace { | |||||
| void RecordGradient(const char* op_name, void* inputs, | |||||
| void* attrs, void* results, | |||||
| const char* name) { | |||||
| // std::vector<tensorflow::int64> input_ids = MakeTensorIDList(inputs); | |||||
| } | |||||
| } | |||||