mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-02 03:55:34 +00:00
[js/webgpu] Replace array with string in transpose perm (#21930)
Perf test data(100000 times)
Array: 12.599999997764826ms
String: 1.6000000014901161ms
Perf test case:
```
const permFunctionBodyArray = (rank: number, input: string): string => {
const reverseFunc = [];
reverseFunc.push(`fn perm(i: int) -> int {
var a: int};`);
for (let i = 0; i < rank; ++i) {
reverseFunc.push(input);
}
reverseFunc.push('return a;}');
return reverseFunc.join('\n');
};
const permFunctionBodyString = (rank: number, input: string): string => {
let reverseFunc= `fn perm(i: int}) -> int {
var a: int;`;
for (let i = 0; i < rank; ++i) {
reverseFunc+=input;
}
reverseFunc+='return a;}';
return reverseFunc;//.join('\n');
};
const count = 100000;
let start, end
console.time('array');
start = performance.now();
for(let i =0 ; i < count; i ++) {
permFunctionBodyArray(3, 'input');
}
end = performance.now();
console.timeEnd('array');
console.log("Array: "+ (end-start));
console.time('string');
start = performance.now();
for(let i =0 ; i < count; i ++) {
permFunctionBodyString(3, 'input');
}
end = performance.now();
console.log("String: " +(end-start));
console.timeEnd('string');
```
### Description
<!-- Describe your changes. -->
### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
This commit is contained in:
parent
2db6b734f5
commit
afd642a194
1 changed files with 4 additions and 6 deletions
|
|
@ -26,14 +26,12 @@ const getOutputShape = (inputShape: readonly number[], perm: number[]): readonly
|
|||
ShapeUtil.sortBasedOnPerm(inputShape, getAdjustedPerm(inputShape.length, perm));
|
||||
|
||||
const permFunctionBody = (perm: number[], rank: number, input: IndicesHelper, output: IndicesHelper): string => {
|
||||
const reverseFunc = [];
|
||||
reverseFunc.push(`fn perm(i: ${output.type.indices}) -> ${input.type.indices} {
|
||||
var a: ${input.type.indices};`);
|
||||
let reverseFunc = `fn perm(i: ${output.type.indices}) -> ${input.type.indices} {
|
||||
var a: ${input.type.indices};`;
|
||||
for (let i = 0; i < rank; ++i) {
|
||||
reverseFunc.push(input.indicesSet('a', perm[i], `i[${i}]`));
|
||||
reverseFunc += input.indicesSet('a', perm[i], `i[${i}]`);
|
||||
}
|
||||
reverseFunc.push('return a;}');
|
||||
return reverseFunc.join('\n');
|
||||
return (reverseFunc += 'return a;}');
|
||||
};
|
||||
|
||||
const squeezeShape = (shape: readonly number[], adjustedPerm: number[]): { newShape: number[]; newPerm: number[] } => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue