CARVIEW |
Select Language
HTTP/2 200
date: Mon, 21 Jul 2025 14:20:29 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-repository-download: git clone https://github.com/opencv/opencv.git
etag: W/"330d194398db78fa65071213474c9a4c"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=018%2BTEEeI7Kpzy6WBaWT98GaZFBUYAiikZRZ9mDUrXH2%2F9nvPiLl9p4HNyw9EoN7LSH7J9D0MRjf9QOiRSmYLHm1WPV6aLJq6A3MnlYR%2Ffdtplk3leaJVnBSspYIsnzhmQHvayIFCbGCmceCrr0Jj3Yps83oGpHLh3lFnx1r%2BsqhRLOExzMUutOBQ3vABwGWrINjkFvwJhZmiWhQtOw6zfs1QeoJm82REn7bNsBzIZ7YlI4a%2F1bvGbCzWR%2Bw%2BBMYc4k%2FPkL83N1LiChN5yg9Aw%3D%3D--yUCpefMzd1yvsdRB--IUgHpxGimD9xDks0Oxh4nA%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1272793831.1753107629; Path=/; Domain=github.com; Expires=Tue, 21 Jul 2026 14:20:29 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Tue, 21 Jul 2026 14:20:29 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: BC3C:1A6C04:1F6F238:2762ADA:687E4CAD
Merge pull request #25238 from fengyuentau:optimized_const · opencv/opencv@accf200 · GitHub
Copy file name to clipboardExpand all lines: modules/dnn/src/cuda4dnn/primitives/layer_norm.hpp
Copy file name to clipboardExpand all lines: modules/dnn/src/layers/attention_layer.cpp
Copy file name to clipboardExpand all lines: modules/dnn/src/layers/layer_norm.cpp
Skip to content
Navigation Menu
{{ message }}
-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
Commit accf200
authored
Merge pull request #25238 from fengyuentau:optimized_const
dnn: avoid const layer forwarding in layer norm layer and attention layer #25238
While profiling ViTs with dnn, I found `ConstLayer` can take a proportion of the inference time, which is weird. This comes from the data copy during the inference of `ConstLayer`. There is a chance that we can improve the efficiency of data copying but the easiest and most convenient way is to avoid `ConstLayer`. This PR change the way how we handle constants in layer normalization layer and attention layer, which is storing in the layer blobs instead of making constant layers for them.
Checklists:
- [x] Backend compatibility in layer normalization layer.
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake1 parent 6e9dcb8 commit accf200Copy full SHA for accf200
File tree
Expand file treeCollapse file tree
4 files changed
+150
-77
lines changedFilter options
- modules/dnn/src
- cuda4dnn/primitives
- layers
- onnx
Expand file treeCollapse file tree
4 files changed
+150
-77
lines changedmodules/dnn/src/cuda4dnn/primitives/layer_norm.hpp
Copy file name to clipboardExpand all lines: modules/dnn/src/cuda4dnn/primitives/layer_norm.hpp+31-7Lines changed: 31 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
28 | 28 |
| |
29 | 29 |
| |
30 | 30 |
| |
31 |
| - | |
| 31 | + | |
32 | 32 |
| |
33 | 33 |
| |
34 | 34 |
| |
35 | 35 |
| |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
36 | 45 |
| |
37 | 46 |
| |
38 | 47 |
| |
| |||
43 | 52 |
| |
44 | 53 |
| |
45 | 54 |
| |
46 |
| - | |
47 |
| - | |
48 | 55 |
| |
49 |
| - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
50 | 74 |
| |
51 | 75 |
| |
52 | 76 |
| |
| |||
67 | 91 |
| |
68 | 92 |
| |
69 | 93 |
| |
70 |
| - | |
71 |
| - | |
72 |
| - | |
| 94 | + | |
73 | 95 |
| |
74 | 96 |
| |
75 | 97 |
| |
| |||
81 | 103 |
| |
82 | 104 |
| |
83 | 105 |
| |
| 106 | + | |
| 107 | + | |
84 | 108 |
| |
85 | 109 |
| |
86 | 110 |
| |
|
modules/dnn/src/layers/attention_layer.cpp
Copy file name to clipboardExpand all lines: modules/dnn/src/layers/attention_layer.cpp+17-7Lines changed: 17 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
63 | 63 |
| |
64 | 64 |
| |
65 | 65 |
| |
66 |
| - | |
| 66 | + | |
| 67 | + | |
67 | 68 |
| |
68 |
| - | |
69 |
| - | |
| 69 | + | |
| 70 | + | |
70 | 71 |
| |
71 | 72 |
| |
72 | 73 |
| |
| |||
109 | 110 |
| |
110 | 111 |
| |
111 | 112 |
| |
112 |
| - | |
| 113 | + | |
| 114 | + | |
113 | 115 |
| |
114 | 116 |
| |
115 | 117 |
| |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
116 | 127 |
| |
117 | 128 |
| |
118 | 129 |
| |
| |||
132 | 143 |
| |
133 | 144 |
| |
134 | 145 |
| |
135 |
| - | |
136 |
| - | |
| 146 | + | |
137 | 147 |
| |
138 | 148 |
| |
139 | 149 |
| |
| |||
153 | 163 |
| |
154 | 164 |
| |
155 | 165 |
| |
156 |
| - | |
| 166 | + | |
157 | 167 |
| |
158 | 168 |
| |
159 | 169 |
| |
|
modules/dnn/src/layers/layer_norm.cpp
Copy file name to clipboardExpand all lines: modules/dnn/src/layers/layer_norm.cpp+97-41Lines changed: 97 additions & 41 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
31 | 31 |
| |
32 | 32 |
| |
33 | 33 |
| |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
34 | 38 |
| |
35 | 39 |
| |
36 | 40 |
| |
| |||
58 | 62 |
| |
59 | 63 |
| |
60 | 64 |
| |
61 |
| - | |
62 |
| - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
63 | 68 |
| |
64 | 69 |
| |
65 | 70 |
| |
66 | 71 |
| |
67 |
| - | |
| 72 | + | |
| 73 | + | |
68 | 74 |
| |
69 | 75 |
| |
70 | 76 |
| |
71 | 77 |
| |
72 | 78 |
| |
73 | 79 |
| |
74 |
| - | |
| 80 | + | |
75 | 81 |
| |
76 |
| - | |
| 82 | + | |
77 | 83 |
| |
78 | 84 |
| |
79 | 85 |
| |
| |||
89 | 95 |
| |
90 | 96 |
| |
91 | 97 |
| |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
92 | 103 |
| |
93 | 104 |
| |
94 | 105 |
| |
| |||
110 | 121 |
| |
111 | 122 |
| |
112 | 123 |
| |
113 |
| - | |
| 124 | + | |
114 | 125 |
| |
115 | 126 |
| |
116 |
| - | |
117 |
| - | |
| 127 | + | |
| 128 | + | |
118 | 129 |
| |
119 | 130 |
| |
120 | 131 |
| |
| |||
129 | 140 |
| |
130 | 141 |
| |
131 | 142 |
| |
132 |
| - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
133 | 150 |
| |
134 | 151 |
| |
135 | 152 |
| |
136 | 153 |
| |
137 | 154 |
| |
138 | 155 |
| |
139 | 156 |
| |
140 |
| - | |
141 |
| - | |
142 |
| - | |
143 |
| - | |
144 |
| - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
145 | 174 |
| |
146 | 175 |
| |
147 | 176 |
| |
| |||
179 | 208 |
| |
180 | 209 |
| |
181 | 210 |
| |
182 |
| - | |
| 211 | + | |
183 | 212 |
| |
184 | 213 |
| |
185 | 214 |
| |
| |||
192 | 221 |
| |
193 | 222 |
| |
194 | 223 |
| |
195 |
| - | |
196 |
| - | |
| 224 | + | |
| 225 | + | |
197 | 226 |
| |
198 | 227 |
| |
199 | 228 |
| |
| |||
218 | 247 |
| |
219 | 248 |
| |
220 | 249 |
| |
221 |
| - | |
222 |
| - | |
223 |
| - | |
224 |
| - | |
225 |
| - | |
226 |
| - | |
227 | 250 |
| |
228 |
| - | |
229 |
| - | |
230 | 251 |
| |
231 | 252 |
| |
232 | 253 |
| |
| |||
239 | 260 |
| |
240 | 261 |
| |
241 | 262 |
| |
242 |
| - | |
243 |
| - | |
244 |
| - | |
245 |
| - | |
246 |
| - | |
247 |
| - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
248 | 291 |
| |
249 | 292 |
| |
250 | 293 |
| |
| |||
264 | 307 |
| |
265 | 308 |
| |
266 | 309 |
| |
| 310 | + | |
267 | 311 |
| |
268 | 312 |
| |
269 | 313 |
| |
| |||
274 | 318 |
| |
275 | 319 |
| |
276 | 320 |
| |
277 |
| - | |
278 |
| - | |
279 |
| - | |
280 |
| - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
281 | 335 |
| |
282 | 336 |
| |
283 | 337 |
| |
284 | 338 |
| |
285 | 339 |
| |
286 |
| - | |
287 |
| - | |
288 |
| - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
289 | 343 |
| |
290 | 344 |
| |
291 | 345 |
| |
292 | 346 |
| |
293 |
| - | |
| 347 | + | |
294 | 348 |
| |
295 | 349 |
| |
296 | 350 |
| |
| |||
308 | 362 |
| |
309 | 363 |
| |
310 | 364 |
| |
311 |
| - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
312 | 369 |
| |
313 | 370 |
| |
314 |
| - | |
315 | 371 |
| |
316 | 372 |
| |
317 | 373 |
| |
|
You can’t perform that action at this time.
0 commit comments