Skip to content

Commit

Permalink
waifu2x: unlimited: Support for wasm multi-threading (Not enabled by …
Browse files Browse the repository at this point in the history
…default)

related to #34
  • Loading branch information
nagadomi committed May 5, 2023
1 parent 357e089 commit 149f17a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
10 changes: 10 additions & 0 deletions waifu2x/unlimited_waifu2x/appendix/unlimited.waifu2x.net
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ server {
}
location / {
add_header Cache-Control "public, max-age=3600, must-revalidate";
# If you want to enable multi-threading
#add_header Cross-Origin-Resource-Policy "cross-origin";
#add_header Cross-Origin-Embedder-Policy "require-corp";
#add_header Cross-Origin-Opener-Policy "same-origin";
}
location ~* \.(onnx|pth) {
add_header Cache-Control "public, max-age=86400, must-revalidate";
}
location ~* \.wasm$ {
types {
application/wasm wasm;
}
}

listen 80;
}
1 change: 1 addition & 0 deletions waifu2x/unlimited_waifu2x/public_html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ const onnx_runner = {
$(function () {
/* init */
ort.env.wasm.proxy = true;
ort.env.wasm.numThreads = navigator.hardwareConcurrency;

function removeAlpha(blob)
{
Expand Down
13 changes: 12 additions & 1 deletion waifu2x/unlimited_waifu2x/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@
# View at http://localhost:8812/
# Do not use this server in product environments.
import bottle
import argparse
from os import path


parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--cors", action="store_true",
help=("Add CORS header for testing wasm multi-threading."
" google-chrome does not work for security reasons (localhost CORS), use firefox"))
args = parser.parse_args()
ROOT_DIR = path.abspath(path.join(path.dirname(__file__), "public_html"))


@bottle.get("/<url:re:.*>")
def static_file(url):
if not url:
url = "index.html"
return bottle.static_file(url, root=ROOT_DIR)
response = bottle.static_file(url, root=ROOT_DIR)
if args.cors:
response.set_header("Cross-Origin-Resource-Policy", "cross-origin")
response.set_header("Cross-Origin-Embedder-Policy", "require-corp")
response.set_header("Cross-Origin-Opener-Policy", "same-origin")
return response


def main():
Expand Down

0 comments on commit 149f17a

Please sign in to comment.