-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SharedArrayBuffer is not GPU data #7344
Conversation
tfjs-core/src/types.ts
Outdated
if ('texture' in values) { | ||
return GPUDataType.WebGL; | ||
} else if ( | ||
'buffer' in values && !(values.buffer instanceof ArrayBuffer) && | ||
!(values.buffer instanceof SharedArrayBuffer)) { | ||
return GPUDataType.WebGPU; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, thanks you!
I am considering, rather than excluding cases, what about we do checks like:?
if ('texture' in values && values.texture instanceof WebGLTexture) {
return GPUDataType.WebGL;
} else if ( 'buffer' in values && values.buffer instanceof GPUBuffer) {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Linchenn, if use 'buffer' in values && values.buffer instanceof GPUBuffer, some bots targets (cpu, wasm...) will complain: ReferenceError: GPUBuffer is not defined.
BTW, I am trying to add a test case 'tensor from ShardArrayBuffer', however, chrome complains 'ReferenceError: SharedArrayBuffer is not defined.' It seems 'yarn karma start' doesn't support SharedArrayBuffer . This can be workaround by https://github.com/Honry/webnn-samples/blob/tflite-deeplab/server.js.
@qjia7 @xhcao @haoyunfeix @gyagp , PTAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that 'buffer' in values
is hard to distinguish WebGPUData
from other objects with buffer
key.
Could we rename WebGPUData
's buffer
filed to something else? but it might have to change lots of codes. I am just providing a candidate idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this idiom (though I don't feel parenthesis is needed around the operand of typeof
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fa3bd96
to
b20ab98
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice workaround. LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review!
Co-authored-by: Matthew Soulanille <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Bug: #7343
TODO: Add test case for ShardArrayBuffer.
This change is