Conversation
dsmilkov
left a comment
There was a problem hiding this comment.
Thanks! Can you run the node benchmarks (cc @caisq) by linking to this build?
Reviewed 3 of 3 files at r1.
Reviewable status: 0 of 1 approvals obtained (waiting on @dsmilkov, @kangyizhang, @nkreeger, and @nsthorat)
binding/tfjs_backend.cc, line 43 at r1 (raw file):
fprintf(stderr, "Invalid NapiAutoRef reference passed to V8 cleanup\n"); #endif return;
for my own understanding of C++: looks like if debug is enabled, we log an error, and when it is disabled, we are silent. Should we return an error code and fail somewhere in the stack instead?
binding/tfjs_backend.cc, line 160 at r1 (raw file):
nstatus = auto_ref->Init(env, array_value); if (nstatus != napi_ok) { delete auto_ref;
when does this condition happen? Should we fail if the Init() fails?
binding/tfjs_backend.cc, line 177 at r1 (raw file):
TFE_NewTensorHandle(tensor.tensor, tf_status.status); if (TF_GetCode(tf_status.status) != TF_OK) { delete auto_ref;
same here. When would the status not be ok?
nkreeger
left a comment
There was a problem hiding this comment.
I tried - the benchmarks are still very WIP and missing details for bootstrapping the environment.
Reviewable status: 0 of 1 approvals obtained (waiting on @dsmilkov, @kangyizhang, and @nsthorat)
binding/tfjs_backend.cc, line 43 at r1 (raw file):
Previously, dsmilkov (Daniel Smilkov) wrote…
for my own understanding of C++: looks like if debug is enabled, we log an error, and when it is disabled, we are silent. Should we return an error code and fail somewhere in the stack instead?
Normally we do, but we suppress most build warnings/runtime warnings unless in developer-debug mode.
Also, N-API requires an napi_env instance to bubble the exception up. We do that whenever possible - the static scope of this callback doesn't allow that here.
binding/tfjs_backend.cc, line 160 at r1 (raw file):
Previously, dsmilkov (Daniel Smilkov) wrote…
when does this condition happen? Should we fail if the Init() fails?
This happens whenever V8 won't allow a napi_ref instance - it is not normally expected, but we need to check every call into n-api and return as early as possible to bubble up exceptions.
binding/tfjs_backend.cc, line 177 at r1 (raw file):
Previously, dsmilkov (Daniel Smilkov) wrote…
same here. When would the status not be ok?
When TensorFlow can not allocate a Tensor. This is another a check-every-call style API.
ENSURE_TF_OK_RETVAL attempts to get a message and return it to the user as a JS exception (same with the ENSURE_NAPI_OK_*) methods.
dsmilkov
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 1 approvals obtained (waiting on @kangyizhang, @nkreeger, and @nsthorat)
binding/tfjs_backend.cc, line 177 at r1 (raw file):
Previously, nkreeger (Nick Kreeger) wrote…
When TensorFlow can not allocate a Tensor. This is another a check-every-call style API.
ENSURE_TF_OK_RETVAL attempts to get a message and return it to the user as a JS exception (same with the ENSURE_NAPI_OK_*) methods.
Thanks for explaining!
|
@caisq that would be great. LGTM, but let's run the benchmarks before submitting (it is a great opportunity to dogfood our benchmarks :) |
|
FYI, I ran the benchmarks on this PR here are the results I got. predict() times changes:
fit() time changes:
So in most cases, there are very nice speedups (up to ~30%). |
This PR introduces a new change to use V8 memory for Tensor memory allocation.
Previously, Tensor data was allocated off of the heap and
memcpy'd from host V8 memory to the allocated Tensor data. Since the TF C API provides a callback whenTF_Tensorinstances are cleaned up, we can share host memory with V8 by simple adding and additional reference count to the represented JS typed-array.This change is