mirror of
https://github.com/gpujs/gpu.js.git
synced 2025-12-08 20:35:56 +00:00
17 lines
527 B
TypeScript
17 lines
527 B
TypeScript
import { GPU, KernelFunction, IKernelRunShortcut } from '../src';
|
|
|
|
const gpu = new GPU({ mode: 'gpu' });
|
|
|
|
// Look ma! I can typescript on my GPU!
|
|
const kernelFunction: KernelFunction = function(anInt: number, anArray: number[], aNestedArray: number[][]) {
|
|
const x = .25 + anInt + anArray[this.thread.x] + aNestedArray[this.thread.x][this.thread.y];
|
|
return x;
|
|
};
|
|
|
|
const kernel: IKernelRunShortcut = gpu.createKernel(kernelFunction)
|
|
.setOutput([1]);
|
|
|
|
const result = kernel(1, [.25], [[1.5]]);
|
|
|
|
console.log(result[0]); // 3
|