Commit ac71c30
committed
[ET-VK] Introduce
## Context
Currently when writing operators developers will save a reference to a `vTensor` retrieved from a `ComputeGraph`'s list of `values_` like so:
```
vTensor& vten = graph.get_val(vref).toTensor();
```
However, this is dangerous since if any values are added once the reference has been stored, `values_` which is a `std::vector` may have been resized and therefore have its contents moved, meaning the reference is now invalid.
To protect against this, this changeset introduces the `vTensorPtr` class which is a wrapper around a `vTensor*`. When constructed, it will increment a counter in the `ComputeGraph` instance, and when destroyed it will decrement the counter. `ComputeGraph` cannot add any values while the counter is not zero.
Since `Value` can be converted to other non-trivial types, this changeset also removes the `get_val` function entirely to guard against unsafe behaviour.
Differential Revision: [D55984187](https://our.internmc.facebook.com/intern/diff/D55984187/)
ghstack-source-id: 222072108
Pull Request resolved: #2978vTensorPtr to prevent reference invalidation and remove get_val() API1 parent a983ebc commit ac71c30
File tree
18 files changed
+374
-245
lines changed- backends/vulkan
- runtime
- graph
- containers
- ops
- impl
- utils
- utils
- test
- utils
18 files changed
+374
-245
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
337 | | - | |
| 337 | + | |
338 | 338 | | |
339 | 339 | | |
340 | | - | |
| 340 | + | |
341 | 341 | | |
342 | | - | |
| 342 | + | |
343 | 343 | | |
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
348 | | - | |
| 348 | + | |
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
| |||
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
359 | | - | |
| 359 | + | |
360 | 360 | | |
361 | | - | |
| 361 | + | |
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
| |||
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
372 | | - | |
| 372 | + | |
373 | 373 | | |
374 | 374 | | |
375 | | - | |
| 375 | + | |
376 | 376 | | |
377 | | - | |
| 377 | + | |
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
20 | 50 | | |
21 | 51 | | |
22 | 52 | | |
| |||
105 | 135 | | |
106 | 136 | | |
107 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
108 | 147 | | |
109 | 148 | | |
110 | 149 | | |
| |||
114 | 153 | | |
115 | 154 | | |
116 | 155 | | |
| 156 | + | |
117 | 157 | | |
118 | 158 | | |
119 | 159 | | |
| |||
136 | 176 | | |
137 | 177 | | |
138 | 178 | | |
139 | | - | |
| 179 | + | |
140 | 180 | | |
141 | 181 | | |
142 | 182 | | |
143 | 183 | | |
144 | 184 | | |
145 | 185 | | |
146 | | - | |
| 186 | + | |
147 | 187 | | |
148 | 188 | | |
149 | 189 | | |
| |||
160 | 200 | | |
161 | 201 | | |
162 | 202 | | |
| 203 | + | |
163 | 204 | | |
164 | 205 | | |
165 | 206 | | |
| |||
168 | 209 | | |
169 | 210 | | |
170 | 211 | | |
| 212 | + | |
171 | 213 | | |
172 | 214 | | |
173 | 215 | | |
174 | 216 | | |
175 | 217 | | |
176 | 218 | | |
| 219 | + | |
177 | 220 | | |
178 | 221 | | |
179 | 222 | | |
180 | 223 | | |
181 | 224 | | |
182 | 225 | | |
| 226 | + | |
183 | 227 | | |
184 | 228 | | |
185 | 229 | | |
186 | 230 | | |
187 | 231 | | |
188 | 232 | | |
| 233 | + | |
189 | 234 | | |
190 | 235 | | |
191 | 236 | | |
| |||
194 | 239 | | |
195 | 240 | | |
196 | 241 | | |
197 | | - | |
198 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
199 | 245 | | |
200 | 246 | | |
201 | 247 | | |
| |||
208 | 254 | | |
209 | 255 | | |
210 | 256 | | |
211 | | - | |
212 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
213 | 260 | | |
214 | 261 | | |
215 | 262 | | |
| |||
229 | 276 | | |
230 | 277 | | |
231 | 278 | | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
236 | 282 | | |
237 | 283 | | |
238 | 284 | | |
239 | 285 | | |
240 | 286 | | |
241 | 287 | | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
246 | 291 | | |
247 | 292 | | |
248 | 293 | | |
| |||
308 | 353 | | |
309 | 354 | | |
310 | 355 | | |
311 | | - | |
| 356 | + | |
312 | 357 | | |
313 | 358 | | |
314 | 359 | | |
| |||
0 commit comments