(
inputInfo: InputInfo, outShape: number[], component: number,
isFlatDispatchLayout: boolean)
| 532 | } |
| 533 | |
| 534 | function getInputByOutputSnippet( |
| 535 | inputInfo: InputInfo, outShape: number[], component: number, |
| 536 | isFlatDispatchLayout: boolean): string { |
| 537 | const texName = inputInfo.name; |
| 538 | const texFuncSnippet = texName.charAt(0).toUpperCase() + texName.slice(1); |
| 539 | |
| 540 | const funcName = 'get' + texFuncSnippet + 'ByOutput'; |
| 541 | |
| 542 | const inRank = inputInfo.shape.length; |
| 543 | const outRank = outShape.length; |
| 544 | const type = getCoordsDataType(outRank); |
| 545 | |
| 546 | // If the inShape equals the outShape and the dispatch layout is flat, we can |
| 547 | // directly use |gl_GlobalInvocationID.x| as the index and don't need coords |
| 548 | // conversion between these two shapes. |
| 549 | if (util.arraysEqual(inputInfo.shape, outShape) && isFlatDispatchLayout) { |
| 550 | return ` |
| 551 | fn ${funcName}Index(globalIndex : i32) -> ${typeSnippet(component)} { |
| 552 | return ${typeSnippet(component)}(${texName}[globalIndex]); |
| 553 | } |
| 554 | |
| 555 | fn ${funcName}Coords(coords : ${type}) -> ${typeSnippet(component)} { |
| 556 | return ${typeSnippet(component)}(${texName}[${ |
| 557 | outRank > 1 ? 'getOutputIndexFromCoords(coords)' : |
| 558 | 'coords'}${component === 1 ? '' : ` / ${component}`}]); |
| 559 | } |
| 560 | `; |
| 561 | } |
| 562 | |
| 563 | const broadcastDims = |
| 564 | backend_util.getBroadcastDims(inputInfo.shape, outShape); |
| 565 | const rankDiff = outRank - inRank; |
| 566 | |
| 567 | let coordsSnippet = ''; |
| 568 | |
| 569 | if (inRank === 0) { |
| 570 | return ` |
| 571 | fn ${funcName}Index(globalIndex : i32) -> ${typeSnippet(component)}{ |
| 572 | return get${texFuncSnippet}(); |
| 573 | } |
| 574 | |
| 575 | fn ${funcName}Coords(coords : ${type}) -> ${typeSnippet(component)}{ |
| 576 | return get${texFuncSnippet}(); |
| 577 | } |
| 578 | `; |
| 579 | } else { |
| 580 | if (outRank < 2 && broadcastDims.length >= 1) { |
| 581 | coordsSnippet = 'coords = 0;'; |
| 582 | } else { |
| 583 | coordsSnippet = |
| 584 | broadcastDims.map(d => `coords.${getCoordsXYZ(d + rankDiff)} = 0;`) |
| 585 | .join('\n'); |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | let unpackedCoordsSnippet = ''; |
| 590 | if (outRank < 2 && inRank > 0) { |
| 591 | unpackedCoordsSnippet = 'coords'; |
no test coverage detected
searching dependent graphs…