$ emcc -s WASM=1 -s SIDE_MODULE=1 -s EXPORTED_FUNCTIONS="['_add']" -O1 add.c -o add.wasm
$ zip action.zip index.js add.wasm package.json
updating: index.js (deflated 52%)
updating: add.wasm (deflated 7%)
updating: package.json (deflated 15%)
$ ibmcloud wsk action create wasm action.zip --kind nodejs:10
ok: created action wasm
$ ibmcloud wsk action invoke wasm -r -p a 2 -p b 2
{
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const INDEX_DOCUMENT = 'index.html' | |
const ERROR_DOCUMENT = '404.html' | |
addEventListener('fetch', event => { | |
event.respondWith(handleRequest(event.request)) | |
}) | |
/** | |
* @param {Request} request | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
// What percentage of invocations should randomly fail? | |
const ERROR_RATE = 0.25 | |
// Random delay to results being returned (0 -> 10 seconds) | |
const DELAY_MS = Math.random() * 10000 | |
function should_fail () { | |
return Math.random() < ERROR_RATE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const ERROR_RATE = 0.25 | |
function should_fail () { | |
return Math.random() < ERROR_RATE | |
} | |
function main(params) { | |
if (!params.a || !params.b) throw new Error('Missing input parameters (a or b).') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const { Worker, isMainThread, parentPort, workerData } = require('worker_threads'); | |
const min = 2 | |
function generatePrimes(start, range) { | |
const primes = [] | |
let isPrime = true; | |
let end = start + range; | |
for (let i = start; i < end; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const min = 2 | |
function main(params) { | |
const { start, end } = params | |
console.log(params) | |
const primes = [] | |
let isPrime = true; | |
for (let i = start; i < end; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const { Worker } = require('worker_threads'); | |
const os = require('os') | |
const threadCount = os.cpus().length | |
const compute_primes = async (start, range) => { | |
return new Promise((resolve, reject) => { | |
let primes = [] | |
console.log(`adding worker (${start} => ${start + range})`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tf = require('@tensorflow/tfjs') | |
const mobilenet = require('@tensorflow-models/mobilenet'); | |
require('@tensorflow/tfjs-node') | |
const jpeg = require('jpeg-js'); | |
const NUMBER_OF_CHANNELS = 3 | |
const MODEL_PATH = 'mobilenet/model.json' | |
let mn_model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "tf-js", | |
"version": "1.0.0", | |
"main": "script.js", | |
"license": "MIT", | |
"dependencies": { | |
"@tensorflow-models/mobilenet": "^0.2.2", | |
"@tensorflow/tfjs": "^0.12.3", | |
"@tensorflow/tfjs-node": "^0.1.9", | |
"jpeg-js": "^0.3.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"annotations": { | |
"list": [] | |
}, | |
"editable": true, | |
"gnetId": null, | |
"graphTooltip": 0, | |
"hideControls": false, | |
"id": 2309, | |
"links": [], |
NewerOlder