[go: nahoru, domu]

Skip to content
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

[wasm] fix #5021: wechat webassembly support #5056

Merged
merged 6 commits into from
May 11, 2021

Conversation

deepkolos
Copy link
Contributor
@deepkolos deepkolos commented May 9, 2021

To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.

test demo in repo tfjs-wxmp-wasm-test

related issue: #5021


This change is Reviewable

@google-cla
Copy link
google-cla bot commented May 9, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no label May 9, 2021
@deepkolos
Copy link
Contributor Author

@googlebot I signed it!

@google-cla google-cla bot added cla: yes and removed cla: no labels May 9, 2021
Copy link
Collaborator
@pyu10055 pyu10055 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution, a couple of comments.

Reviewable status: 0 of 1 approvals obtained (waiting on @deepkolos)


tfjs-backend-wasm/scripts/patch-wechat-webassembly.js, line 16 at r1 (raw file):

        file.endsWith('tfjs-backend-wasm-threaded-simd.js')
      ) {
        code = code.replace(`require("worker_threads")`, 'null')

we prefer to have ';' at the end of the statement.


tfjs-backend-wasm/scripts/patch-wechat-webassembly.js, line 22 at r1 (raw file):

      // it is not a nice way, but WebAssembly.validate not working and SIMD is not support in WXWebAssembly
      if (file.endsWith('backend_wasm.ts')) {
        code = code.replace(`env().getAsync('WASM_HAS_SIMD_SUPPORT')`, 'false')

this can be done in the wechat plugin, where we can do tf.env().set('WASM_HAS_SIMD_SUPPORT', false), similar with WASM_HAS_MULTITHREAD_SUPPORT


tfjs-backend-wasm/scripts/patch-wechat-webassembly.js, line 25 at r1 (raw file):

        code = code.replace(`env().getAsync('WASM_HAS_MULTITHREAD_SUPPORT')`, 'false')
        code = code.replace(
          `function createInstantiateWasmFunc(path) {`,

This is bit of hacky to relies on treeshaking to remove the rest of the method, can you use regex to match the whole method?

});
return {};
}`)
const ast = this.parse(code);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pyu10055 a better way to replace createInstantiateWasmFunc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and test case updated

tf.env().set('WASM_HAS_SIMD_SUPPORT', false);
tf.env().set('WASM_HAS_MULTITHREAD_SUPPORT', false);

https://github.com/deepkolos/tfjs-wxmp-wasm-test/blob/ebe95a1a036c1a29ab8a7a980d5f2d2099a1ea99/pages/index/index.js#L15

Copy link
Collaborator
@pyu10055 pyu10055 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @deepkolos)


tfjs-backend-wasm/scripts/patch-wechat-webassembly.js, line 35 at r2 (raw file):

Previously, deepkolos (DeepKolos) wrote…

and test case updated

tf.env().set('WASM_HAS_SIMD_SUPPORT', false);
tf.env().set('WASM_HAS_MULTITHREAD_SUPPORT', false);

https://github.com/deepkolos/tfjs-wxmp-wasm-test/blob/ebe95a1a036c1a29ab8a7a980d5f2d2099a1ea99/pages/index/index.js#L15

This is very nice, thanks you!


tfjs-backend-wasm/src/backend_wasm.ts, line 213 at r3 (raw file):

function createInstantiateWasmFunc(path: string) {
  // this will be replace by rollup plugin patchWechatWebAssembly in minprogram's output

is this comment still needed, or should it be updated to reflect your new solution?

@pyu10055 pyu10055 merged commit f064ce4 into tensorflow:master May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants