Update/Add WASM_U-Performance_Record/run_wasm.js for WebAssembly 7.10us record
Browse files
WASM_U-Performance_Record/run_wasm.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Watermark: ip zymatica.space | astronautshe.com
|
| 2 |
+
// Node.js WebAssembly FFI Integration Script
|
| 3 |
+
|
| 4 |
+
const fs = require('fs');
|
| 5 |
+
|
| 6 |
+
async function run() {
|
| 7 |
+
// 1. Read input coordinates
|
| 8 |
+
const testInput = JSON.parse(fs.readFileSync('test_input.json', 'utf8'));
|
| 9 |
+
const count = testInput.length;
|
| 10 |
+
|
| 11 |
+
// 2. Load and compile WASM
|
| 12 |
+
const wasmBuffer = fs.readFileSync('proof_wasm.wasm');
|
| 13 |
+
const wasmModule = await WebAssembly.instantiate(wasmBuffer);
|
| 14 |
+
const exports = wasmModule.instance.exports;
|
| 15 |
+
const memory = exports.memory;
|
| 16 |
+
|
| 17 |
+
// 3. Coordinate Structure sizes:
|
| 18 |
+
// Concept6D has 6 fields of u8 (size = 6 bytes)
|
| 19 |
+
const structSize = 6;
|
| 20 |
+
const inputOffset = 102400;
|
| 21 |
+
const memView = new Uint8Array(memory.buffer);
|
| 22 |
+
|
| 23 |
+
for (let i = 0; i < count; i++) {
|
| 24 |
+
const idx = inputOffset + i * structSize;
|
| 25 |
+
const c = testInput[i];
|
| 26 |
+
memView[idx] = c.domain;
|
| 27 |
+
memView[idx + 1] = c.subdomain;
|
| 28 |
+
memView[idx + 2] = c.operation;
|
| 29 |
+
memView[idx + 3] = c.modality;
|
| 30 |
+
memView[idx + 4] = c.depth;
|
| 31 |
+
memView[idx + 5] = c.polarity;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
// 4. Invoke wasm_encode
|
| 35 |
+
const encodedBufferPtr = exports.wasm_encode(inputOffset, count);
|
| 36 |
+
const encodedBitsCount = exports.wasm_get_encoded_bits();
|
| 37 |
+
const encodedBytesCount = Math.floor((encodedBitsCount + 7) / 8);
|
| 38 |
+
|
| 39 |
+
// Read back the compressed payload bytes
|
| 40 |
+
const encodedBytes = new Uint8Array(memory.buffer, encodedBufferPtr, encodedBytesCount);
|
| 41 |
+
fs.writeFileSync('payload_wasm.bin', Buffer.from(encodedBytes));
|
| 42 |
+
|
| 43 |
+
// 5. Invoke wasm_decode
|
| 44 |
+
const decodedBufferPtr = exports.wasm_decode(encodedBufferPtr, encodedBytesCount, count);
|
| 45 |
+
|
| 46 |
+
// Read back the decoded Concept6D structs from WASM memory
|
| 47 |
+
const decodedView = new Uint8Array(memory.buffer, decodedBufferPtr, count * structSize);
|
| 48 |
+
const decodedConcepts = [];
|
| 49 |
+
|
| 50 |
+
for (let i = 0; i < count; i++) {
|
| 51 |
+
const idx = i * structSize;
|
| 52 |
+
decodedConcepts.push({
|
| 53 |
+
domain: decodedView[idx],
|
| 54 |
+
subdomain: decodedView[idx + 1],
|
| 55 |
+
operation: decodedView[idx + 2],
|
| 56 |
+
modality: decodedView[idx + 3],
|
| 57 |
+
depth: decodedView[idx + 4],
|
| 58 |
+
polarity: decodedView[idx + 5]
|
| 59 |
+
});
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
fs.writeFileSync('test_output_wasm.json', JSON.stringify(decodedConcepts, null, 2));
|
| 63 |
+
console.log(` [+] Node.js completed WASM execution. Encoded ${count} concepts into ${encodedBitsCount} bits.`);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
run().catch(err => {
|
| 67 |
+
console.error(" [-] Node.js Error:", err);
|
| 68 |
+
process.exit(1);
|
| 69 |
+
});
|