Commit a5dc0f9
authored
[web] use shorter memory info name for WebGPU buffer and WebNN tensor (#27207)
### Description
This PR renames the following existing names for MemoryInfo:
- `WebGPU_Buffer` -> `WebGPU_Buf`
- `WebNN_Tensor` -> `WebNN_Ten`
### Motivation and Context
the `OrtMemoryInfo` uses a `std::string` to store the name. modern C++
compilers uses "small string optimization" (SSO) to avoid an extra
memory allocation if the string is small enough.
While different compiler may have different implementation, the
following test program is used to test what exact limit is for a certain
compiler:
```c++
#include <string>
#include <cstdio>
int main() {
std::string webgpu0 = "WebGPU_Buf";
std::string webgpu1 = "WebGPU_Buff";
std::string webgpu2 = "WebGPU_Buffe";
std::string webgpu3 = "WebGPU_Buffer";
printf("=========== %s\n string address: %p\n data address : %p\n\n", webgpu0.c_str(), (void*)&webgpu0, (void*)webgpu0.data());
printf("=========== %s\n string address: %p\n data address : %p\n\n", webgpu1.c_str(), (void*)&webgpu1, (void*)webgpu1.data());
printf("=========== %s\n string address: %p\n data address : %p\n\n", webgpu2.c_str(), (void*)&webgpu2, (void*)webgpu2.data());
printf("=========== %s\n string address: %p\n data address : %p\n\n", webgpu3.c_str(), (void*)&webgpu3, (void*)webgpu3.data());
return 0;
}
```
While using emscripten (targetting wasm32), the runtime result is like
this:
```
=========== WebGPU_Buf
string address: 0x10db0
data address : 0x10db0
=========== WebGPU_Buff
string address: 0x10da4
data address : 0x10dc8
=========== WebGPU_Buffe
string address: 0x10d98
data address : 0x10de0
=========== WebGPU_Buffer
string address: 0x10d8c
data address : 0x10df8
```
Which shows that the string need to be no more than 10 bytes (exclude
the '\0' at end) to enable SSO.1 parent cee825d commit a5dc0f9
File tree
5 files changed
+9
-9
lines changed- include/onnxruntime/core/framework
- js/node/src
- onnxruntime
- contrib_ops/webgpu/quantization
- wasm
5 files changed
+9
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
89 | | - | |
| 88 | + | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
| 184 | + | |
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
254 | | - | |
| 254 | + | |
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
396 | | - | |
| 396 | + | |
397 | 397 | | |
398 | 398 | | |
399 | | - | |
| 399 | + | |
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
| |||
563 | 563 | | |
564 | 564 | | |
565 | 565 | | |
566 | | - | |
| 566 | + | |
567 | 567 | | |
568 | | - | |
| 568 | + | |
569 | 569 | | |
570 | 570 | | |
571 | 571 | | |
| |||
0 commit comments