JSFiddle - React, Tailwind, and code Playground
by TomWyllie
HTML
<script src="https://unpkg.com/[email protected]/dist/gpu-browser.js"></script>
JavaScript
const gpu = new GPU({ mode: 'gpu' });
const arr1 = [0, 1, 3, 4];
const arr2 = [10, 11, 12, 13, 14];
const arrKernel = gpu.createKernel(function(arr1, arr2) {
return arr2[arr1[this.thread.x]];
}).setOutput([4]);
const result = arrKernel(arr1, arr2);
// Expected output: "10,11,13,14"
// jsfiddle output with mode: 'gpu': "0,1,4,0"
// jsfiddle output with mode: 'cpu': "10,11,13,14" (as expected)
/*
Using:
GPU.js 2.9.4
GPU: NVIDIA GeForce GTX 1060 3GB
Google Chrome Version 83.0.4103.97 (Official Build) (64-bit), but same issue in Firefox
Windows 10
Couldn't be replicated on Android Samsung Galaxy S9.
*/
console.log(result.toString());