Skip to content

Commit 7ac84e8

Browse files
committed
save
1 parent 2395cd9 commit 7ac84e8

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

binding/tfjs_backend.cc

+31
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "tfe_auto_op.h"
2020
#include "tfe_utils.h"
2121
#include "utils.h"
22+
#include "../deps/tensorflow/include/tensorflow/c/c_api.h"
2223

2324
namespace tfnodejs {
2425

@@ -251,4 +252,34 @@ napi_value TFJSBackend::ExecuteOp(napi_env env, napi_value op_name_value,
251252
return output_tensor_infos;
252253
}
253254

255+
napi_value TFJSBackend::ExecuteOpFastPath(napi_env env,
256+
napi_value op_name_value,
257+
napi_value input_tensor_ids,
258+
napi_value num_output_values) {
259+
napi_status nstatus;
260+
TF_AutoStatus tf_status;
261+
262+
char op_name[NAPI_STRING_SIZE];
263+
nstatus = napi_get_value_string_utf8(env, op_name_value, op_name,
264+
NAPI_STRING_SIZE, nullptr);
265+
ENSURE_NAPI_OK_RETVAL(env, nstatus, nullptr);
266+
267+
// Crack open and look at the op registry.
268+
TF_Buffer* op_list_buffer = TF_GetAllOpList();
269+
TF_ApiDefMap* api_def_map = TF_NewApiDefMap(op_list_buffer, tf_status.status);
270+
ENSURE_TF_OK_RETVAL(env, tf_status, nullptr);
271+
272+
// // tensorflow::ApiDef api_def;
273+
// tensorflow::ApiDef api_def;
274+
// api_def.ParseFromArray(api_def_buffer->data, api_def_buffer->length);
275+
// fprintf(stderr, "apidef.name: %s\n", api_def.graph_op_name.c_str());
276+
277+
// For a test - don't return anything.
278+
napi_value output_tensor_infos;
279+
nstatus = napi_create_array_with_length(env, 0, &output_tensor_infos);
280+
ENSURE_NAPI_OK_RETVAL(env, nstatus, nullptr);
281+
282+
return output_tensor_infos;
283+
}
284+
254285
} // namespace tfnodejs

binding/tfjs_backend.h

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ class TFJSBackend {
5858
napi_value op_attr_inputs, napi_value input_tensor_ids,
5959
napi_value num_output_values);
6060

61+
// TODO(kreeger): Document me.
62+
napi_value ExecuteOpFastPath(napi_env env, napi_value op_name_value,
63+
napi_value input_tensor_ids,
64+
napi_value num_output_values);
65+
6166
private:
6267
int32_t InsertHandle(TFE_TensorHandle* tfe_handle);
6368

binding/tfjs_binding.cc

+19
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ static napi_value ExecuteOp(napi_env env, napi_callback_info info) {
123123
return gBackend->ExecuteOp(env, args[0], args[1], args[2], args[3]);
124124
}
125125

126+
static napi_value ExecuteOpFastPath(napi_env env, napi_callback_info info) {
127+
napi_status nstatus;
128+
129+
size_t argc = 3;
130+
napi_value args[argc];
131+
napi_value js_this;
132+
nstatus = napi_get_cb_info(env, info, &argc, args, &js_this, nullptr);
133+
ENSURE_NAPI_OK_RETVAL(env, nstatus, nullptr);
134+
135+
if (argc < 3) {
136+
NAPI_THROW_ERROR(env, "Invalid number of args passed to executeOp()");
137+
return nullptr;
138+
}
139+
140+
ENSURE_VALUE_IS_STRING_RETVAL(env, args[0], nullptr);
141+
ENSURE_VALUE_IS_ARRAY_RETVAL(env, args[1], nullptr);
142+
ENSURE_VALUE_IS_NUMBER_RETVAL(env, args[2], nullptr);
143+
}
144+
126145
static napi_value InitTFNodeJSBinding(napi_env env, napi_value exports) {
127146
napi_status nstatus;
128147

0 commit comments

Comments
 (0)