diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 30124767..31880819 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,86 +1,66 @@ { - "configurations": [ - { - "name": "Mac", - "includePath": [ - "${workspaceFolder}", - "/Library/Developer/CommandLineTools/usr/include/c++/v1", - "/usr/local/include", - "/Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/include", - "/Library/Developer/CommandLineTools/usr/include", - "/usr/include", - "/usr/local/Cellar/node/9.7.1_1/include/node", - "${workspaceFolder}/deps/tensorflow/include" - ], - "defines": [], - "intelliSenseMode": "clang-x64", - "browse": { - "path": [ - "${workspaceFolder}", - "/Library/Developer/CommandLineTools/usr/include/c++/v1", - "/usr/local/include", - "/Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/include", - "/Library/Developer/CommandLineTools/usr/include", - "/usr/include" - ], - "limitSymbolsToIncludedHeaders": true, - "databaseFilename": "" - }, - "macFrameworkPath": [ - "/System/Library/Frameworks", - "/Library/Frameworks" - ], - "compilerPath": "/usr/bin/clang", - "cStandard": "c11", - "cppStandard": "c++17" - }, - { - "name": "Linux", - "includePath": [ - "/usr/include", - "/usr/local/include", - "${workspaceFolder}", - "${workspaceFolder}/../../.node-gyp/10.1.0/include/node" - ], - "defines": [], - "intelliSenseMode": "clang-x64", - "browse": { - "path": [ - "/usr/include", - "/usr/local/include", - "${workspaceFolder}", - "${workspaceFolder}/deps/tensorflow/include/tensorflow/c", - "${workspaceFolder}/deps/tensorflow/include/tensorflow/c/eager", - "${workspaceFolder}/../../.node-gyp/10.1.0/include/node" - ], - "limitSymbolsToIncludedHeaders": true, - "databaseFilename": "" - }, - "compilerPath": "/usr/bin/clang++-3.8", - "cStandard": "c11", - "cppStandard": "c++17" - }, - { - "name": "Win32", - "includePath": [ - "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include", - "${workspaceFolder}" - ], - "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE" - ], - "intelliSenseMode": "msvc-x64", - "browse": { - "path": [ - "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*", - "${workspaceFolder}" - ], - "limitSymbolsToIncludedHeaders": true, - "databaseFilename": "" - } - } - ], - "version": 4 -} + "configurations": [ + { + "name": "Mac", + "includePath": [ + "${workspaceFolder}/**", + "/Library/Developer/CommandLineTools/usr/include/c++/v1", + "/usr/local/include", + "/Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/include", + "/Library/Developer/CommandLineTools/usr/include", + "/usr/include", + "/usr/local/Cellar/node/9.7.1_1/include/node", + "${workspaceFolder}/deps/tensorflow/include" + ], + "defines": [], + "intelliSenseMode": "clang-x64", + "browse": { + "path": [ + "${workspaceFolder}", + "/Library/Developer/CommandLineTools/usr/include/c++/v1", + "/usr/local/include", + "/Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/include", + "/Library/Developer/CommandLineTools/usr/include", + "/usr/include" + ], + "limitSymbolsToIncludedHeaders": true, + "databaseFilename": "" + }, + "macFrameworkPath": [ + "/System/Library/Frameworks", + "/Library/Frameworks" + ], + "compilerPath": "/usr/bin/clang", + "cStandard": "c11", + "cppStandard": "c++17" + }, + { + "name": "Linux", + "includePath": [ + "/usr/include", + "/usr/local/include", + "${workspaceFolder}/**", + "${workspaceFolder}/../../.node-gyp/10.1.0/include/node", + "/usr/local/google/home/kreeger/.node-gyp/10.5.0/include/node" + ], + "defines": [], + "intelliSenseMode": "clang-x64", + "browse": { + "path": [ + "/usr/include", + "/usr/local/include", + "${workspaceFolder}", + "${workspaceFolder}/deps/tensorflow/include/tensorflow/c", + "${workspaceFolder}/deps/tensorflow/include/tensorflow/c/eager", + "${workspaceFolder}/../../.node-gyp/10.5.0/include/node" + ], + "limitSymbolsToIncludedHeaders": true, + "databaseFilename": "" + }, + "compilerPath": "/usr/bin/clang++-3.8", + "cStandard": "c11", + "cppStandard": "c++17" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/binding/tfjs_backend.cc b/binding/tfjs_backend.cc index 25a2552f..f58a2ac2 100644 --- a/binding/tfjs_backend.cc +++ b/binding/tfjs_backend.cc @@ -19,6 +19,7 @@ #include "tfe_auto_op.h" #include "tfe_utils.h" #include "utils.h" +#include "../deps/tensorflow/include/tensorflow/c/c_api.h" namespace tfnodejs { @@ -251,4 +252,34 @@ napi_value TFJSBackend::ExecuteOp(napi_env env, napi_value op_name_value, return output_tensor_infos; } +napi_value TFJSBackend::ExecuteOpFastPath(napi_env env, + napi_value op_name_value, + napi_value input_tensor_ids, + napi_value num_output_values) { + napi_status nstatus; + TF_AutoStatus tf_status; + + char op_name[NAPI_STRING_SIZE]; + nstatus = napi_get_value_string_utf8(env, op_name_value, op_name, + NAPI_STRING_SIZE, nullptr); + ENSURE_NAPI_OK_RETVAL(env, nstatus, nullptr); + + // Crack open and look at the op registry. + TF_Buffer* op_list_buffer = TF_GetAllOpList(); + TF_ApiDefMap* api_def_map = TF_NewApiDefMap(op_list_buffer, tf_status.status); + ENSURE_TF_OK_RETVAL(env, tf_status, nullptr); + + // // tensorflow::ApiDef api_def; + // tensorflow::ApiDef api_def; + // api_def.ParseFromArray(api_def_buffer->data, api_def_buffer->length); + // fprintf(stderr, "apidef.name: %s\n", api_def.graph_op_name.c_str()); + + // For a test - don't return anything. + napi_value output_tensor_infos; + nstatus = napi_create_array_with_length(env, 0, &output_tensor_infos); + ENSURE_NAPI_OK_RETVAL(env, nstatus, nullptr); + + return output_tensor_infos; +} + } // namespace tfnodejs diff --git a/binding/tfjs_backend.h b/binding/tfjs_backend.h index c5da9712..a22374c2 100644 --- a/binding/tfjs_backend.h +++ b/binding/tfjs_backend.h @@ -58,6 +58,11 @@ class TFJSBackend { napi_value op_attr_inputs, napi_value input_tensor_ids, napi_value num_output_values); + // TODO(kreeger): Document me. + napi_value ExecuteOpFastPath(napi_env env, napi_value op_name_value, + napi_value input_tensor_ids, + napi_value num_output_values); + private: int32_t InsertHandle(TFE_TensorHandle* tfe_handle); diff --git a/binding/tfjs_binding.cc b/binding/tfjs_binding.cc index 3839cf5a..87f21f49 100644 --- a/binding/tfjs_binding.cc +++ b/binding/tfjs_binding.cc @@ -123,6 +123,25 @@ static napi_value ExecuteOp(napi_env env, napi_callback_info info) { return gBackend->ExecuteOp(env, args[0], args[1], args[2], args[3]); } +static napi_value ExecuteOpFastPath(napi_env env, napi_callback_info info) { + napi_status nstatus; + + size_t argc = 3; + napi_value args[argc]; + napi_value js_this; + nstatus = napi_get_cb_info(env, info, &argc, args, &js_this, nullptr); + ENSURE_NAPI_OK_RETVAL(env, nstatus, nullptr); + + if (argc < 3) { + NAPI_THROW_ERROR(env, "Invalid number of args passed to executeOp()"); + return nullptr; + } + + ENSURE_VALUE_IS_STRING_RETVAL(env, args[0], nullptr); + ENSURE_VALUE_IS_ARRAY_RETVAL(env, args[1], nullptr); + ENSURE_VALUE_IS_NUMBER_RETVAL(env, args[2], nullptr); +} + static napi_value InitTFNodeJSBinding(napi_env env, napi_value exports) { napi_status nstatus;