gpu.js/examples/json-saving.js
2019-02-04 19:55:19 -05:00

18 lines
492 B
JavaScript

const { GPU } = require('../src');
const gpu1 = new GPU();
const kernel1 = gpu1.createKernel(function(value) {
return value * 100;
}, { output: [1] });
const resultFromRegularKernel = kernel1(42);
const json = kernel1.toJSON();
console.log(resultFromRegularKernel);
// Use bin/gpu-browser-core.js to get "CORE" mode, which works only with JSON
const gpu2 = new GPU();
const kernel2 = gpu2.createKernel(json);
const resultFromJsonKernel = kernel2(42);
console.log(resultFromJsonKernel);