(mode)
| 453 | }); |
| 454 | |
| 455 | function testTortureTest(mode) { |
| 456 | const gpu = new GPU({ mode }); |
| 457 | function addFloatArray(addFloatArrayArgument1, addFloatArrayArgument2) { |
| 458 | return addFloatArrayArgument1 + addFloatArrayArgument2[this.thread.x]; |
| 459 | } |
| 460 | function addArrayFloat(addArrayFloatArgument1, addArrayFloatArgument2) { |
| 461 | return addArrayFloatArgument1[this.thread.x] + addArrayFloatArgument2; |
| 462 | } |
| 463 | function addArrayArray(addArrayArrayArgument1, addArrayArrayArgument2) { |
| 464 | return addArrayArrayArgument1[this.thread.x] + addArrayArrayArgument2[this.thread.x]; |
| 465 | } |
| 466 | function addFloatFloat(addFloatFloatArgument1, addFloatFloatArgument2) { |
| 467 | return addFloatFloatArgument1 + addFloatFloatArgument2; |
| 468 | } |
| 469 | gpu |
| 470 | .addFunction(addFloatArray) |
| 471 | .addFunction(addArrayFloat) |
| 472 | .addFunction(addArrayArray) |
| 473 | .addFunction(addFloatFloat); |
| 474 | |
| 475 | const texture = gpu.createKernel(function() { return 2; }, { output: [1], precision: 'single' })(); |
| 476 | // sinon.spy(FunctionBuilder.prototype, 'lookupArgumentType'); |
| 477 | sinon.spy(FunctionBuilder.prototype, 'lookupReturnType'); |
| 478 | |
| 479 | try { |
| 480 | const kernel = gpu.createKernel(function (v1, v2, v3, v4, v5) { |
| 481 | return addFloatFloat(v4, addArrayFloat(v3, addFloatArray(addArrayArray(v1, v5), v2))); |
| 482 | }, {output: [1]}); |
| 483 | |
| 484 | const result = kernel([1], texture, [3], 4, new Float32Array([5])); |
| 485 | assert.equal(result[0], 1 + 2 + 3 + 4 + 5); |
| 486 | assert.equal(FunctionBuilder.prototype.lookupReturnType.callCount, 7); |
| 487 | assert.equal(FunctionBuilder.prototype.lookupReturnType.returnValues.length, 7); |
| 488 | assert.equal(FunctionBuilder.prototype.lookupReturnType.args[0][0], 'addArrayArray'); |
| 489 | assert.equal(FunctionBuilder.prototype.lookupReturnType.returnValues[0], 'Number'); |
| 490 | assert.equal(FunctionBuilder.prototype.lookupReturnType.args[1][0], 'addFloatArray'); |
| 491 | assert.equal(FunctionBuilder.prototype.lookupReturnType.returnValues[1], 'Number'); |
| 492 | assert.equal(FunctionBuilder.prototype.lookupReturnType.args[2][0], 'addArrayFloat'); |
| 493 | assert.equal(FunctionBuilder.prototype.lookupReturnType.returnValues[2], 'Number'); |
| 494 | assert.equal(FunctionBuilder.prototype.lookupReturnType.args[3][0], 'addFloatFloat'); |
| 495 | assert.equal(FunctionBuilder.prototype.lookupReturnType.returnValues[3], 'Float'); |
| 496 | assert.equal(FunctionBuilder.prototype.lookupReturnType.args[4][0], 'addArrayFloat'); |
| 497 | assert.equal(FunctionBuilder.prototype.lookupReturnType.returnValues[4], 'Number'); |
| 498 | assert.equal(FunctionBuilder.prototype.lookupReturnType.args[5][0], 'addFloatArray'); |
| 499 | assert.equal(FunctionBuilder.prototype.lookupReturnType.returnValues[5], 'Number'); |
| 500 | assert.equal(FunctionBuilder.prototype.lookupReturnType.args[6][0], 'addArrayArray'); |
| 501 | assert.equal(FunctionBuilder.prototype.lookupReturnType.returnValues[6], 'Number'); |
| 502 | } finally { |
| 503 | FunctionBuilder.prototype.lookupReturnType.restore(); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | (GPU.isSinglePrecisionSupported ? test : skip)('torture test auto', () => { |
| 508 | testTortureTest(); |
no test coverage detected
searching dependent graphs…