mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-11-17 17:38:18 +08:00
Compare commits
496 Commits
v11.4
...
sync/v13.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99686e0c71 | ||
|
|
aeab82ff30 | ||
|
|
a4526d5229 | ||
|
|
f69622b6b6 | ||
|
|
722c5dd069 | ||
|
|
e32d17e67e | ||
|
|
5cf83b5a98 | ||
|
|
191900a7b4 | ||
|
|
338df69d0f | ||
|
|
9b7a6f907a | ||
|
|
5bbae96fd3 | ||
|
|
ce9407c240 | ||
|
|
cdedff42d2 | ||
|
|
6c4d183ba3 | ||
|
|
af49216f0c | ||
|
|
17113ea87e | ||
|
|
70fcdd353f | ||
|
|
5b2dd19a21 | ||
|
|
37dcb9b61d | ||
|
|
1bc6774795 | ||
|
|
4f735616ba | ||
|
|
4ff552244d | ||
|
|
df6edf644e | ||
|
|
85231cd1b6 | ||
|
|
46a782fb44 | ||
|
|
d5dedb24d6 | ||
|
|
9600b04a3c | ||
|
|
4eae2ccc04 | ||
|
|
d759a16c4b | ||
|
|
b8191f860a | ||
|
|
547f65851f | ||
|
|
9df0ef6411 | ||
|
|
1411d243a6 | ||
|
|
57e870596c | ||
|
|
fd6707ccaa | ||
|
|
cf01c5bb28 | ||
|
|
1165d53ddf | ||
|
|
8c324afd63 | ||
|
|
0fae54dcd6 | ||
|
|
320c7e6392 | ||
|
|
22fafb0a7c | ||
|
|
cccbf2c284 | ||
|
|
69186dc51e | ||
|
|
d298bf3e6f | ||
|
|
27c7e19849 | ||
|
|
7c190dde53 | ||
|
|
5e9d44634b | ||
|
|
b0a2f2049f | ||
|
|
3e6d1858af | ||
|
|
12b046a80e | ||
|
|
036638b713 | ||
|
|
9d703d090b | ||
|
|
cbc075ef59 | ||
|
|
6e23a98575 | ||
|
|
5fc7a4c897 | ||
|
|
3f1c509650 | ||
|
|
fbc40da311 | ||
|
|
1b36fefcd5 | ||
|
|
13c2fd9717 | ||
|
|
775d1b4dd3 | ||
|
|
a5267b83a5 | ||
|
|
2ab16e6d15 | ||
|
|
903c840a8c | ||
|
|
24e7c5b428 | ||
|
|
b38ed29c95 | ||
|
|
4a631c9fd6 | ||
|
|
98afcd6515 | ||
|
|
eb8891b839 | ||
|
|
688fff15b2 | ||
|
|
555353b4b5 | ||
|
|
1a35902577 | ||
|
|
8013610840 | ||
|
|
2369d4c649 | ||
|
|
8433f89993 | ||
|
|
a9a4db666f | ||
|
|
87d03ef003 | ||
|
|
7c8fccc0d4 | ||
|
|
45314d7ff8 | ||
|
|
2f0a55d7dc | ||
|
|
0d61031846 | ||
|
|
225f84d433 | ||
|
|
e674cc36fe | ||
|
|
a47b422205 | ||
|
|
ce28796d6c | ||
|
|
9424c15848 | ||
|
|
9075c50a3d | ||
|
|
de5fa98e6e | ||
|
|
6c9e9d3cd2 | ||
|
|
7f5390cec3 | ||
|
|
5f6d46dfea | ||
|
|
49307463b5 | ||
|
|
859debae1b | ||
|
|
9c0d5aaae6 | ||
|
|
74a9a08887 | ||
|
|
0d08748ffa | ||
|
|
c1166d3298 | ||
|
|
27f47634a0 | ||
|
|
40d297dfe7 | ||
|
|
f19d33ddbc | ||
|
|
20b90b5063 | ||
|
|
8a9e2c830c | ||
|
|
61225e22f0 | ||
|
|
bf25251720 | ||
|
|
f47f06f077 | ||
|
|
0c78a3e0de | ||
|
|
5a1f5008ed | ||
|
|
8219570c15 | ||
|
|
5ce8b512ea | ||
|
|
fc88988f23 | ||
|
|
adacf1cffd | ||
|
|
3e631f467a | ||
|
|
1141dd7af4 | ||
|
|
da3b7a2b3c | ||
|
|
5987a9e9fa | ||
|
|
107f3f537f | ||
|
|
c1b03b9f81 | ||
|
|
ee0ee417c9 | ||
|
|
ebc1078379 | ||
|
|
2861e78272 | ||
|
|
494d598f86 | ||
|
|
c6208f5897 | ||
|
|
8f33cc6094 | ||
|
|
2ec9cf394a | ||
|
|
770e433a9e | ||
|
|
dd1a11f648 | ||
|
|
c6af90553e | ||
|
|
7989d1fcc8 | ||
|
|
611008fa86 | ||
|
|
bf628887f1 | ||
|
|
f288b2e261 | ||
|
|
330dd8472f | ||
|
|
b530f1cf42 | ||
|
|
b63fd83b6c | ||
|
|
8ee551c99a | ||
|
|
148014e709 | ||
|
|
cab7c66b4f | ||
|
|
8d400cfb7f | ||
|
|
f2645c5df8 | ||
|
|
6d6d964f97 | ||
|
|
ab68d58d59 | ||
|
|
c70d79cf3b | ||
|
|
9ac81370fa | ||
|
|
14b1bfdcc4 | ||
|
|
c14a0114d6 | ||
|
|
ee15cc0fe2 | ||
|
|
3438fd4875 | ||
|
|
b27b55ec70 | ||
|
|
49159f3739 | ||
|
|
93cafa8fe9 | ||
|
|
1680a1dc7f | ||
|
|
49daf0e4e0 | ||
|
|
a45fd3bd7c | ||
|
|
1627e96677 | ||
|
|
7e90d36120 | ||
|
|
9e50fdc01f | ||
|
|
2c0b36a967 | ||
|
|
83397dc811 | ||
|
|
640b566412 | ||
|
|
da24673a9f | ||
|
|
bded2585a4 | ||
|
|
5384563c57 | ||
|
|
01a62e2bc0 | ||
|
|
02fdb070ad | ||
|
|
278f4adbd2 | ||
|
|
d00076a7c1 | ||
|
|
4672b8ba2b | ||
|
|
0345908807 | ||
|
|
3b9c8ce2e9 | ||
|
|
e77d6eb5ab | ||
|
|
ac700327a2 | ||
|
|
56e669e2e4 | ||
|
|
17703dd426 | ||
|
|
a1b5a6f6e3 | ||
|
|
a32d5badf7 | ||
|
|
1fd22429c3 | ||
|
|
00ac0a1673 | ||
|
|
b013387a39 | ||
|
|
9d921e0fe7 | ||
|
|
7d1730f348 | ||
|
|
a4fba501a6 | ||
|
|
718fe6486d | ||
|
|
ad9908e32b | ||
|
|
952d6edf92 | ||
|
|
685709bfc7 | ||
|
|
0c92c34ca9 | ||
|
|
0d82634f70 | ||
|
|
4abbdf4e80 | ||
|
|
89789bd848 | ||
|
|
914ca00f89 | ||
|
|
8f6b189dae | ||
|
|
c8034f368a | ||
|
|
69522dd5b7 | ||
|
|
eddc6fd7e1 | ||
|
|
ceab6e8bcc | ||
|
|
2cd58fbc9a | ||
|
|
7ceb3122fc | ||
|
|
c0ab53f986 | ||
|
|
b87c243bbb | ||
|
|
e214cd29aa | ||
|
|
06d72496c2 | ||
|
|
2848d3bd21 | ||
|
|
bd0f630bf4 | ||
|
|
ab9166a6b2 | ||
|
|
62781dc15e | ||
|
|
c90a1c6981 | ||
|
|
3f97ef1288 | ||
|
|
408c9f69a8 | ||
|
|
9370f11e69 | ||
|
|
291435e0b4 | ||
|
|
5df07f114e | ||
|
|
8d901e745d | ||
|
|
990ebc01c2 | ||
|
|
541e9fc3f5 | ||
|
|
9adce9d9f2 | ||
|
|
b6f3b7add9 | ||
|
|
bcad2c9e61 | ||
|
|
e7b23470d5 | ||
|
|
310e7f2a11 | ||
|
|
7f0f63f311 | ||
|
|
acd3a015c8 | ||
|
|
a9869fd6ea | ||
|
|
3e8f91d1a1 | ||
|
|
f3b7c41ad6 | ||
|
|
29fb758e62 | ||
|
|
3bc08136ff | ||
|
|
85eefa06c4 | ||
|
|
c357dd1e6b | ||
|
|
efb46383e0 | ||
|
|
8d564d5e3a | ||
|
|
37c5bcbef4 | ||
|
|
940a4c7a91 | ||
|
|
61bd39800d | ||
|
|
8a96d2eee7 | ||
|
|
e762d58260 | ||
|
|
8fd1701744 | ||
|
|
94765c1597 | ||
|
|
c87881f02c | ||
|
|
25400b6b3c | ||
|
|
e24f62e28c | ||
|
|
db3eea2394 | ||
|
|
04f3686bbe | ||
|
|
0e87b76137 | ||
|
|
fb6fcb0110 | ||
|
|
14b8ceb56f | ||
|
|
a6737fd72b | ||
|
|
96901090bc | ||
|
|
8b2b51e2a5 | ||
|
|
dcce6e1f14 | ||
|
|
cc3d94f81c | ||
|
|
7ee6db679e | ||
|
|
24a617c043 | ||
|
|
93f1c78c5b | ||
|
|
5932d18738 | ||
|
|
5206607816 | ||
|
|
f8f3e1b347 | ||
|
|
4fcfa82d7d | ||
|
|
7a9bd38ecc | ||
|
|
9582bb03a9 | ||
|
|
11bc856cad | ||
|
|
95308ffc23 | ||
|
|
56852fbb50 | ||
|
|
152ba4b941 | ||
|
|
a8138b60fe | ||
|
|
c7bfd4418b | ||
|
|
eb378b2fce | ||
|
|
fd5674f9e5 | ||
|
|
bb2aebaad8 | ||
|
|
2539826a99 | ||
|
|
1eb3c947c3 | ||
|
|
9d03b030a6 | ||
|
|
78f83ca02d | ||
|
|
e8a041d783 | ||
|
|
c631850c15 | ||
|
|
9539ca5fa3 | ||
|
|
0f4bdfad99 | ||
|
|
e3a5ae4aca | ||
|
|
30b411ad56 | ||
|
|
941670671c | ||
|
|
be5012ef69 | ||
|
|
9824a63101 | ||
|
|
5f6e6072d9 | ||
|
|
a80688012e | ||
|
|
aad89bb0ab | ||
|
|
ab0b386ac4 | ||
|
|
5cffc8815a | ||
|
|
27c0a166f3 | ||
|
|
08fae276b4 | ||
|
|
0f697f1819 | ||
|
|
b203467419 | ||
|
|
41d5f63ec5 | ||
|
|
3de3f2f46c | ||
|
|
95128a1cf3 | ||
|
|
3848a7c63c | ||
|
|
d9633314f8 | ||
|
|
576c24f97e | ||
|
|
970a6a1151 | ||
|
|
76e2d2052c | ||
|
|
03a7300081 | ||
|
|
ccb341a5e3 | ||
|
|
421e49450f | ||
|
|
886860a123 | ||
|
|
9a454d3ba9 | ||
|
|
1a466282da | ||
|
|
545194e7aa | ||
|
|
e2d3c20bd3 | ||
|
|
48e70c8b31 | ||
|
|
b518bfe9be | ||
|
|
e633580eff | ||
|
|
df9ea79df4 | ||
|
|
eacf41c980 | ||
|
|
f8fbd04007 | ||
|
|
01956cfecc | ||
|
|
380c065a0c | ||
|
|
6c548b5d43 | ||
|
|
11c70243db | ||
|
|
415ad05c98 | ||
|
|
2d0314212b | ||
|
|
feffc60cbf | ||
|
|
d3ded4a251 | ||
|
|
62b96a65b5 | ||
|
|
450038ea73 | ||
|
|
ce045e2ae9 | ||
|
|
f753e86e7a | ||
|
|
a1cf9e4183 | ||
|
|
e8492d1a78 | ||
|
|
11355321a0 | ||
|
|
3532ede709 | ||
|
|
8f1d565faa | ||
|
|
f00f52d154 | ||
|
|
dc24cde377 | ||
|
|
2c5c6dc7d4 | ||
|
|
3fc438428a | ||
|
|
5409227cf8 | ||
|
|
e36545ac1c | ||
|
|
41a65b94c8 | ||
|
|
89a84131fb | ||
|
|
bb121fe02b | ||
|
|
e228ad9389 | ||
|
|
1e0c660f22 | ||
|
|
e52cdee6c4 | ||
|
|
9045dd3a1a | ||
|
|
3e7bb5f2e8 | ||
|
|
88e5f4a395 | ||
|
|
5c9e573ece | ||
|
|
c08a2f31ff | ||
|
|
6fe4a6bab8 | ||
|
|
66631e4f96 | ||
|
|
7e1a257265 | ||
|
|
d9efeae3bb | ||
|
|
9c4287fc51 | ||
|
|
8d06d246b3 | ||
|
|
1292881b37 | ||
|
|
a55d6682d2 | ||
|
|
f9dd4323af | ||
|
|
fcd39008ec | ||
|
|
01b7ee41f6 | ||
|
|
25b33d2d04 | ||
|
|
bfd956bc5e | ||
|
|
0f5821a8c8 | ||
|
|
c1301d000a | ||
|
|
7f5859dda9 | ||
|
|
abb97e1dfb | ||
|
|
22bedd5cf0 | ||
|
|
d54d4d7419 | ||
|
|
03719b7623 | ||
|
|
11fc617794 | ||
|
|
7d7e0777a5 | ||
|
|
a60b4a984e | ||
|
|
7b0068a433 | ||
|
|
2ad2272e3d | ||
|
|
cbfab74480 | ||
|
|
00999c1789 | ||
|
|
090f957854 | ||
|
|
ea694a4b0d | ||
|
|
281daef279 | ||
|
|
23928df4ff | ||
|
|
8d2e39c395 | ||
|
|
1bb070deba | ||
|
|
07e5fc5473 | ||
|
|
de204853cf | ||
|
|
3f0693b37e | ||
|
|
4fc7cdb95c | ||
|
|
ba77e8d23b | ||
|
|
10e9b975c4 | ||
|
|
8b5c84cd22 | ||
|
|
6929eea2ed | ||
|
|
cd485da765 | ||
|
|
223e658beb | ||
|
|
c9794ff283 | ||
|
|
035dcfd357 | ||
|
|
37922e6429 | ||
|
|
05d2f991de | ||
|
|
b6f3065605 | ||
|
|
461fc3c649 | ||
|
|
b1837c0e4e | ||
|
|
7fde420160 | ||
|
|
0d161038a2 | ||
|
|
ee8ff3cf5b | ||
|
|
7568673fa6 | ||
|
|
4543e7bbab | ||
|
|
a3be0d3cd8 | ||
|
|
89f2e5c0c3 | ||
|
|
f93a9ab81c | ||
|
|
fb1eaa8323 | ||
|
|
2f826e305a | ||
|
|
9bebdf7ef4 | ||
|
|
6fd8228242 | ||
|
|
76210c84f7 | ||
|
|
62d32b38d7 | ||
|
|
dd73281bc6 | ||
|
|
df5ff58ca4 | ||
|
|
c7fe3b2f4c | ||
|
|
cd51392c0f | ||
|
|
0eaf6d4198 | ||
|
|
551f0dbebe | ||
|
|
29bde74c86 | ||
|
|
a60926da2c | ||
|
|
039e445f93 | ||
|
|
3fd2fbce00 | ||
|
|
b284c28ce5 | ||
|
|
74107d2da1 | ||
|
|
12d096790b | ||
|
|
5fab4d73f5 | ||
|
|
8a2c175abc | ||
|
|
0dc8ecc1f6 | ||
|
|
a14d734664 | ||
|
|
56ad17f97c | ||
|
|
7013a0b70a | ||
|
|
a461e61485 | ||
|
|
769a225af3 | ||
|
|
53a02af443 | ||
|
|
9b70771583 | ||
|
|
7ce058b479 | ||
|
|
8663c8bf19 | ||
|
|
2dfdd55e29 | ||
|
|
c52cfc339f | ||
|
|
bcf4a0dd31 | ||
|
|
9efe753a74 | ||
|
|
2dee482699 | ||
|
|
29a2098575 | ||
|
|
a0774d28f1 | ||
|
|
190d0cbaa7 | ||
|
|
e53fcad712 | ||
|
|
d06e42bf06 | ||
|
|
fd2c269ce3 | ||
|
|
a1cd67ca87 | ||
|
|
9a207a910a | ||
|
|
2a4d019282 | ||
|
|
8e03cbfcf9 | ||
|
|
9d8f61431e | ||
|
|
ff264a798f | ||
|
|
274836a1a2 | ||
|
|
c15a0c4bbf | ||
|
|
912f37963a | ||
|
|
82bcada84c | ||
|
|
22424227e7 | ||
|
|
9c688d7ff7 | ||
|
|
5f97d7d0df | ||
|
|
3559ca4d08 | ||
|
|
cd3bc1fa8e | ||
|
|
42ff742bf5 | ||
|
|
8ccb13c6f0 | ||
|
|
e8568c4173 | ||
|
|
b5c84e6996 | ||
|
|
c46754b877 | ||
|
|
03309a2d42 | ||
|
|
5688ee0013 | ||
|
|
8004ad59ab | ||
|
|
e612904184 | ||
|
|
81cf058e30 | ||
|
|
26665bf33b | ||
|
|
00bb9bc367 | ||
|
|
e4789153d5 | ||
|
|
1c2efac7c8 | ||
|
|
3d553b2ea1 | ||
|
|
9316529638 | ||
|
|
2b689228b7 | ||
|
|
81992093d2 | ||
|
|
b312abaa07 | ||
|
|
8f21b899b6 | ||
|
|
0cbe5f2d82 | ||
|
|
805e60bdfc | ||
|
|
9d4c014f60 | ||
|
|
bf8c6dd043 | ||
|
|
2e41896e1b | ||
|
|
11de19f00c | ||
|
|
471dd47f84 | ||
|
|
0563025cde | ||
|
|
3a05f29b94 | ||
|
|
e64c65a0d3 | ||
|
|
af0e1af181 | ||
|
|
01789304f0 | ||
|
|
1f76a2d110 | ||
|
|
3342d604fe | ||
|
|
ba04faaf73 | ||
|
|
8789eb6266 |
49
.clang-format
Normal file
49
.clang-format
Normal file
@@ -0,0 +1,49 @@
|
||||
---
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: Consecutive
|
||||
AlignConsecutiveDeclarations: Consecutive
|
||||
AlignConsecutiveMacros: Consecutive
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: AlignAfterOperator
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterClass: true
|
||||
AfterControlStatement: false
|
||||
AfterExternBlock: true
|
||||
AfterFunction: true
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
IndentBraces: false
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeConceptDeclarations: true
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakInheritanceList: BeforeComma
|
||||
ColumnLimit: 120
|
||||
DerivePointerAlignment: false
|
||||
FixNamespaceComments: true
|
||||
IncludeCategories:
|
||||
- Regex: '^<.*>'
|
||||
Priority: 1
|
||||
- Regex: '^".*"'
|
||||
Priority: 2
|
||||
SortIncludes: true
|
||||
IncludeBlocks: Regroup
|
||||
IndentWidth: 4
|
||||
MaxEmptyLinesToKeep: 2
|
||||
PointerAlignment: Right
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
Standard: c++17
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
...
|
||||
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
build
|
||||
build-*/
|
||||
test-results*/
|
||||
.vs
|
||||
.clangd
|
||||
test
|
||||
settings.json
|
||||
launch.json
|
||||
__pycache__/
|
||||
*.py[co]
|
||||
.pytest_cache/
|
||||
116
.pre-commit-config.yaml
Normal file
116
.pre-commit-config.yaml
Normal file
@@ -0,0 +1,116 @@
|
||||
# Copyright (c) 2024, NVIDIA CORPORATION.
|
||||
ci:
|
||||
autofix_commit_msg: |
|
||||
[pre-commit.ci] auto code formatting
|
||||
autofix_prs: false
|
||||
autoupdate_branch: ''
|
||||
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
|
||||
autoupdate_schedule: quarterly
|
||||
skip: []
|
||||
submodules: false
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v5.0.0
|
||||
hooks:
|
||||
- id: end-of-file-fixer
|
||||
exclude: |
|
||||
(?x)^(
|
||||
.*\.raw$|
|
||||
.*\.bin$|
|
||||
.*\.dat$|
|
||||
.*\.nv12$|
|
||||
data/.*|
|
||||
Common/.*
|
||||
)
|
||||
files: |
|
||||
(?x)^(
|
||||
.*\.txt$|
|
||||
.*\.md$|
|
||||
.*\.cpp$|
|
||||
.*\.cxx$|
|
||||
.*\.hpp$|
|
||||
.*\.h$|
|
||||
.*\.cu$|
|
||||
.*\.cuh$|
|
||||
.*\.py$|
|
||||
.*\.json$
|
||||
)
|
||||
- id: mixed-line-ending
|
||||
exclude: |
|
||||
(?x)^(
|
||||
.*\.raw$|
|
||||
.*\.bin$|
|
||||
.*\.dat$|
|
||||
.*\.nv12$|
|
||||
data/.*|
|
||||
Common/.*
|
||||
)
|
||||
files: |
|
||||
(?x)^(
|
||||
.*\.txt$|
|
||||
.*\.md$|
|
||||
.*\.cpp$|
|
||||
.*\.cxx$|
|
||||
.*\.hpp$|
|
||||
.*\.h$|
|
||||
.*\.cu$|
|
||||
.*\.cuh$|
|
||||
.*\.py$|
|
||||
.*\.json$
|
||||
)
|
||||
- id: trailing-whitespace
|
||||
exclude: |
|
||||
(?x)^(
|
||||
.*\.raw$|
|
||||
.*\.bin$|
|
||||
.*\.dat$|
|
||||
.*\.nv12$|
|
||||
data/.*|
|
||||
Common/.*
|
||||
)
|
||||
files: |
|
||||
(?x)^(
|
||||
.*\.txt$|
|
||||
.*\.md$|
|
||||
.*\.cpp$|
|
||||
.*\.cxx$|
|
||||
.*\.hpp$|
|
||||
.*\.h$|
|
||||
.*\.cu$|
|
||||
.*\.cuh$|
|
||||
.*\.py$|
|
||||
.*\.json$
|
||||
)
|
||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||
rev: v19.1.6
|
||||
hooks:
|
||||
- id: clang-format
|
||||
types_or: [file]
|
||||
files: |
|
||||
(?x)^(
|
||||
^.*\.c$|
|
||||
^.*\.cpp$|
|
||||
^.*\.cu$|
|
||||
^.*\.cuh$|
|
||||
^.*\.cxx$|
|
||||
^.*\.h$|
|
||||
^.*\.hpp$|
|
||||
^.*\.inl$|
|
||||
^.*\.mm$
|
||||
)
|
||||
exclude: |
|
||||
(?x)^(
|
||||
Common/.*
|
||||
)
|
||||
args: ["-fallback-style=none", "-style=file", "-i"]
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.8.4
|
||||
hooks:
|
||||
- id: ruff
|
||||
name: ruff lint
|
||||
args: [--fix]
|
||||
files: ^python/.*\.py$
|
||||
- id: ruff-format
|
||||
name: ruff format
|
||||
files: ^python/.*\.py$
|
||||
300
CHANGELOG.md
Normal file
300
CHANGELOG.md
Normal file
@@ -0,0 +1,300 @@
|
||||
## Changelog
|
||||
|
||||
### CUDA 13.3
|
||||
* Added **CUDA Tile C++** samples under `cpp/9_CUDA_Tile`.
|
||||
* Added a set of **CCCL 3.3 feature samples** under `cpp/4_CUDA_Libraries/`, each built against CCCL fetched via CPM (pinned to v3.3.3, with an optional `CCCL_SOURCE_DIR` override):
|
||||
* `cubDeviceFind` - `cub::DeviceFind::FindIf`, `LowerBound`, and `UpperBound` device-wide search algorithms.
|
||||
* `cubDeviceSegmentedScan` - `cub::DeviceSegmentedScan::ExclusiveSegmentedSum` and `InclusiveSegmentedScan` with a custom binary operator.
|
||||
* `cubDeviceTransform` - N-to-M `cub::DeviceTransform::Transform` where the op returns a `cuda::std::tuple`.
|
||||
* `libcuxxRandom` - `cuda::pcg64` and `cuda::std::philox4x32` engines driving the uniform, normal, Poisson, and Bernoulli distributions from `<cuda/std/random>`.
|
||||
* `libcuxxMdspan` - DLPack <-> `cuda::std::mdspan` bridging via `cuda::to_device_mdspan` / `cuda::to_dlpack_tensor`, plus `cuda::shared_memory_mdspan` for multi-dimensional views of shared memory.
|
||||
* Added **cuda.compute 1.0 Python samples** under `python/2_CoreConcepts/`:
|
||||
* `cudaComputeLambdas` - Python lambdas / regular callables driving `reduce_into`, `unary_transform`, and `inclusive_scan` in `cuda.compute` (from the `cuda-cccl` package).
|
||||
* `binarySearch` - parallel `cuda.compute.upper_bound` / `lower_bound`, verified against `numpy.searchsorted`.
|
||||
|
||||
|
||||
### CUDA 13.2 (update)
|
||||
* Added **CUDA Python samples** under `python/`. These scripts use [CUDA Python](https://nvidia.github.io/cuda-python/) (including `cuda.core`) and are organized like the C++ tree: `1_GettingStarted`, `2_CoreConcepts`, `3_FrameworkInterop`, and `4_DistributedComputing`, plus shared helpers in `python/Utilities`. Each sample includes a `README.md` and `requirements.txt`. They are **not** built by the root CMake project; install dependencies with `pip install -r requirements.txt` in the sample directory, then run the corresponding `.py` file as documented in that sample’s README.
|
||||
* Renamed top-level `Samples` directory to `cpp` to accommodate Python samples alongside existing C++ samples; updated path references in `CMakeLists.txt`, `README.md`, and `Common` headers accordingly.
|
||||
|
||||
### CUDA 13.2
|
||||
* Added the MSVC compile flag `-Xcompiler=/Zc:preprocessor` in CMakeLists.txt to comply with CUDA13.2 CCCL. Previously, using the traditional preprocessor triggered the warning “MSVC/cl.exe with traditional preprocessor is used…”, which now leads to a build error.
|
||||
|
||||
### CUDA 13.1
|
||||
* Minor bug fixes and enhancements, no structural or functional changes
|
||||
|
||||
### CUDA 13.0
|
||||
* Updated the samples using the cudaDeviceProp fields which are deprecated and removed in CUDA 13.0, replacing the fields with the equivalents in "cudaDeviceGetAttribute":
|
||||
* Deprecated "cudaDeviceProp" fields
|
||||
`int clockRate; // - Replaced with "cudaDevAttrClockRate"`
|
||||
`int deviceOverlap; // - Replaced with "cudaDevAttrGpuOverlap */`
|
||||
`int kernelExecTimeoutEnabled; // - Replaced with "cudaDevAttrKernelExecTimeout`
|
||||
`int computeMode; // - Replaced with "cudaDevAttrComputeMode" */`
|
||||
`int memoryClockRate; // - Replaced with "cudaDevAttrMemoryClockRate"`
|
||||
`int cooperativeMultiDeviceLaunch; // - Deprecated, cudaLaunchCooperativeKernelMultiDevice is deprecated.`
|
||||
* `0_Introduction`
|
||||
* `UnifiedMemoryStreams`
|
||||
* `simpleHyperQ`
|
||||
* `simpleIPC`
|
||||
* `simpleMultiCopy`
|
||||
* `systemWideAtomics`
|
||||
* `1_Utilitie`
|
||||
* `deviceQuery`
|
||||
* `2_Concepts_and_Techniques`
|
||||
* `streamOrderedAllocationIPC`
|
||||
* `4_CUDA_Libraries`
|
||||
* `simpleCUBLASXT`
|
||||
* `5_Domain_Specific`
|
||||
* `simpleVulkan`
|
||||
* `vulkanImageCUDA`
|
||||
* Updated the samples using the CUDA driver API "cuCtxCreate" with adding the parameter "CUctxCreateParams" as "cuCtxCreate" is updated to "cuCtxCreate_v4" by default in CUDA 13.0:
|
||||
* `Common`
|
||||
* `nvrtc_helper.h`
|
||||
* `0_Introduction`
|
||||
* `UnifiedMemoryStreams`
|
||||
* `matrixMulDrv`
|
||||
* `simpleTextureDrv`
|
||||
* `vectorAddDrv`
|
||||
* `vectorAddMMAP`
|
||||
* `2_Concepts_and_Techniques`
|
||||
* `EGLStream_CUDA_CrossGPU`
|
||||
* `EGLStream_CUDA_Interop`
|
||||
* `threadMigration`
|
||||
* `3_CUDA_Features`
|
||||
* `graphMemoryFootprint`
|
||||
* `memMapIPCDrv`
|
||||
* `4_CUDA_Libraries`
|
||||
* `jitLto`
|
||||
* `7_libNVVM`
|
||||
* `cuda-c-linking`
|
||||
* `device-side-launch`
|
||||
* `simple`
|
||||
* `uvmlite`
|
||||
* `8_Platform_Specific/Tegra`
|
||||
* `EGLSync_CUDAEvent_Interop`
|
||||
* Updated the sample using CUDA API "cudaGraphAddNode"/"cudaStreamGetCaptureInfo" with adding "cudaGraphEdgeData" pointer parameter as they are updated to "cudaGraphAddNode_v2"/"cudaStreamGetCaptureInfo_v3" by default in CUDA 13.0:
|
||||
* `3_CUDA_Features`
|
||||
* `graphConditionalNodes`
|
||||
* Updated the samples using CUDA API "cudaMemAdvise"/"cudaMemPrefetchAsync" with changing the parameter "int device" to "cudaMemLocation location" as they are updated to "cudaMemAdvise_v2"/"cudaMemPrefetchAsyn_v2" by default in CUDA 13.0.
|
||||
* `4_CUDA_Libraries`
|
||||
* `conjugateGradientMultiDeviceCG`
|
||||
* `6_Performance`
|
||||
* `UnifiedMemoryPerf`
|
||||
* Replaced "thrust::identity<uint>()" with "cuda::std::identity()" as it is deprecated in CUDA 13.0.
|
||||
* `2_Concepts_and_Techniques`
|
||||
* `segmentationTreeThrust`
|
||||
* Updated the the headers file and samples for CUFFT error codes update.
|
||||
* Deprecated CUFFT errors:
|
||||
* `CUFFT_INCOMPLETE_PARAMETER_LIST`
|
||||
* `CUFFT_PARSE_ERROR`
|
||||
* `CUFFT_LICENSE_ERROR`
|
||||
* New added CUFFT errors:
|
||||
* `CUFFT_MISSING_DEPENDENCY`
|
||||
* `CUFFT_NVRTC_FAILURE`
|
||||
* `CUFFT_NVJITLINK_FAILURE`
|
||||
* `CUFFT_NVSHMEM_FAILURE`
|
||||
* Header files and samples that are related with this change:
|
||||
* `Common/helper_cuda.h`
|
||||
* `4_CUDA_Libraries`
|
||||
* `simpleCUFFT`
|
||||
* `simpleCUFFT_2d_MGPU`
|
||||
* `simpleCUFFT_MGPU`
|
||||
* `simpleCUFFT_callback`
|
||||
* Updated toolchain for cross-compilation for Tegra QNX platforms.
|
||||
|
||||
### CUDA 12.9
|
||||
* Updated toolchain for cross-compilation for Tegra Linux platforms.
|
||||
* Added `run_tests.py` utility to exercise all samples. See README.md for details
|
||||
* Repository has been updated with consistent code formatting across all samples
|
||||
* Many small code tweaks and bug fixes (see commit history for details)
|
||||
* Removed the following outdated samples:
|
||||
* `1_Utilities`
|
||||
* `bandwidthTest` - this sample was out of date and did not produce accurate results. For bandwidth
|
||||
testing of NVIDIA GPU platforms, please refer to [NVBandwidth](https://github.com/NVIDIA/nvbandwidth)
|
||||
|
||||
### CUDA 12.8
|
||||
* Updated build system across the repository to CMake. Removed Visual Studio project files and Makefiles.
|
||||
* Removed the following outdated samples:
|
||||
* `0_Introduction`
|
||||
* `c++11_cuda` demonstrating CUDA and C++ 11 interoperability (reason: obsolete)
|
||||
* `concurrentKernels` demonstrating the ability to run multiple kernels simultaneously (reason: obsolete)
|
||||
* `cppIntegration` demonstrating calling between .cu and .cpp files (reason: obsolete)
|
||||
* `cppOverload` demonstrating C++ function overloading (reason: obsolete)
|
||||
* `simpleSeparateCompilation` demonstrating NVCC compilation to a static library (reason: trivial)
|
||||
* `simpleTemplates_nvrtc` demonstrating NVRTC usage for `simpleTemplates` sample (reason: redundant)
|
||||
* `simpleVoteIntrinsics_nvrtc` demonstrating NVRTC usage for `simpleVoteIntrinsics` sample (reason: redundant)
|
||||
* `2_Concepts_and_Techniques`
|
||||
* `cuHook` demonstrating dlsym hooks. (reason: incompatible with modern `glibc`)
|
||||
* `4_CUDA_Libraries`
|
||||
* `batchedLabelMarkersAndLabelCompressionNPP` demonstrating NPP features (reason: some functionality removed from library)
|
||||
* `5_Domain_Specific`
|
||||
* Legacy Direct3D 9 and 10 interoperability samples:
|
||||
* `fluidsD3D9`
|
||||
* `simpleD3D10`
|
||||
* `simpleD3D10RenderTarget`
|
||||
* `simpleD3D10Texture`
|
||||
* `simpleD3D9`
|
||||
* `simpleD3D9Texture`
|
||||
* `SLID3D10Texture`
|
||||
* `VFlockingD3D10`
|
||||
* `8_Platform_Specific/Tegra`
|
||||
* Temporarily removed the following two samples pending updates:
|
||||
* `nbody_screen` demonstrating the nbody sample in QNX
|
||||
* `simpleGLES_screen` demonstrating GLES interop in QNX
|
||||
* Moved the following Tegra-specific samples to a dedicated subdirectory: `8_Platform_Specific/Tegra`
|
||||
* `EGLSync_CUDAEvent_Interop`
|
||||
* `cuDLAErrorReporting`
|
||||
* `cuDLAHybridMode`
|
||||
* `cuDLALayerwiseStatsHybrid`
|
||||
* `cuDLALayerwiseStatsStandalone`
|
||||
* `cuDLAStandaloneMode`
|
||||
* `cudaNvSciBufMultiplanar`
|
||||
* `cudaNvSciNvMedia`
|
||||
* `fluidsGLES`
|
||||
* `nbody_opengles`
|
||||
* `simpleGLES`
|
||||
* `simpleGLES_EGLOutput`
|
||||
|
||||
|
||||
|
||||
### CUDA 12.5
|
||||
|
||||
### CUDA 12.4
|
||||
* Added graphConditionalNodes Sample
|
||||
|
||||
### CUDA 12.3
|
||||
* Added cuDLA samples
|
||||
* Fixed jitLto regression
|
||||
|
||||
### CUDA 12.2
|
||||
* libNVVM samples received updates
|
||||
* Fixed jitLto Case issues
|
||||
* Enabled HOST_COMPILER flag to the makefiles for GCC which is untested but may still work.
|
||||
|
||||
### CUDA 12.1
|
||||
* Added new sample for Large Kernels
|
||||
|
||||
### CUDA 12.0
|
||||
* Added new flags for JIT compiling
|
||||
* Removed deprecated APIs in Hopper Architecture
|
||||
|
||||
### CUDA 11.6
|
||||
* Added new folder structure for samples
|
||||
* Added support of Visual Studio 2022 to all samples supported on [Windows](#windows-1).
|
||||
* All CUDA samples are now only available on [GitHub](https://github.com/nvidia/cuda-samples). They are no longer available via CUDA toolkit.
|
||||
|
||||
### CUDA 11.5
|
||||
* Added `cuDLAHybridMode`. Demonstrate usage of cuDLA in hybrid mode.
|
||||
* Added `cuDLAStandaloneMode`. Demonstrate usage of cuDLA in standalone mode.
|
||||
* Added `cuDLAErrorReporting`. Demonstrate DLA error detection via CUDA.
|
||||
* Added `graphMemoryNodes`. Demonstrates memory allocations and frees within CUDA graphs using Graph APIs and Stream Capture APIs.
|
||||
* Added `graphMemoryFootprint`. Demonstrates how graph memory nodes re-use virtual addresses and physical memory.
|
||||
* All samples from CUDA toolkit are now available on [GitHub](https://github.com/nvidia/cuda-samples).
|
||||
|
||||
### CUDA 11.4 update 1
|
||||
* Added support for VS Code on linux platform.
|
||||
|
||||
### CUDA 11.4
|
||||
* Added `cdpQuadtree`. Demonstrates Quad Trees implementation using CUDA Dynamic Parallelism.
|
||||
* Updated `simpleVulkan`, `simpleVulkanMMAP` and `vulkanImageCUDA`. Demonstrates use of SPIR-V shaders.
|
||||
|
||||
### CUDA 11.3
|
||||
* Added `streamOrderedAllocationIPC`. Demonstrates Inter Process Communication using one process per GPU for computation.
|
||||
* Added `simpleCUBLAS_LU`. Demonstrates batched matrix LU decomposition using cuBLAS API `cublas<t>getrfBatched()`
|
||||
* Updated `simpleVulkan`. Demonstrates use of timeline semaphore.
|
||||
* Updated multiple samples to use pinned memory using `cudaMallocHost()`.
|
||||
|
||||
### CUDA 11.2
|
||||
* Added `streamOrderedAllocation`. Demonstrates stream ordered memory allocation on a GPU using cudaMallocAsync and cudaMemPool family of APIs.
|
||||
* Added `streamOrderedAllocationP2P`. Demonstrates peer-to-peer access of stream ordered memory allocated using cudaMallocAsync and cudaMemPool family of APIs.
|
||||
* Dropped Visual Studio 2015 support from all the windows supported samples.
|
||||
* FreeImage is no longer distributed with the CUDA Samples. On Windows, see the [Dependencies](./README.md#freeimage) section for more details on how to set up FreeImage. On Linux, it is recommended to install FreeImage with your distribution's package manager.
|
||||
* All the samples using CUDA Pipeline & Arrive-wait barriers are been updated to use new `cuda::pipeline` and `cuda::barrier` interfaces.
|
||||
* Updated all the samples to build with parallel build option `--threads` of `nvcc` cuda compiler.
|
||||
* Added `cudaNvSciNvMedia`. Demonstrates CUDA-NvMedia interop via NvSciBuf/NvSciSync APIs.
|
||||
* Added `simpleGL`. Demonstrates interoperability between CUDA and OpenGL.
|
||||
|
||||
### CUDA 11.1
|
||||
* Added `watershedSegmentationNPP`. Demonstrates how to use the NPP watershed segmentation function.
|
||||
* Added `batchedLabelMarkersAndLabelCompressionNPP`. Demonstrates how to use the NPP label markers generation and label compression functions based on a Union Find (UF) algorithm including both single image and batched image versions.
|
||||
* Dropped Visual Studio 2012, 2013 support from all the windows supported samples.
|
||||
* Added kernel performing warp aggregated atomic max in multi buckets using cg::labeled_partition & cg::reduce in `warpAggregatedAtomicsCG`.
|
||||
* Added extended CG shuffle mechanics to `shfl_scan` sample.
|
||||
* Added `cudaOpenMP`. Demonstrates how to use OpenMP API to write an application for multiple GPUs.
|
||||
* Added `simpleZeroCopy`. Demonstrates how to use zero copy, kernels can read and write directly to pinned system memory.
|
||||
|
||||
### CUDA 11.0
|
||||
* Added `dmmaTensorCoreGemm`. Demonstrates double precision GEMM computation using the Double precision Warp Matrix Multiply and Accumulate (WMMA) API introduced with CUDA 11 in Ampere chip family tensor cores.
|
||||
* Added `bf16TensorCoreGemm`. Demonstrates __nv_bfloat16 (e8m7) GEMM computation using the __nv_bfloat16 WMMA API introduced with CUDA 11 in Ampere chip family tensor cores.
|
||||
* Added `tf32TensorCoreGemm`. Demonstrates tf32 (e8m10) GEMM computation using the tf32 WMMA API introduced with CUDA 11 in Ampere chip family tensor cores.
|
||||
* Added `globalToShmemAsyncCopy`. Demonstrates async copy of data from global to shared memory when on compute capability 8.0 or higher. Also demonstrates arrive-wait barrier for synchronization.
|
||||
* Added `simpleAWBarrier`. Demonstrates arrive wait barriers.
|
||||
* Added `simpleAttributes`. Demonstrates the stream attributes that affect L2 locality.
|
||||
* Added warp aggregated atomic multi bucket increments kernel using labeled_partition cooperative groups in `warpAggregatedAtomicsCG` which can be used on compute capability 7.0 and above GPU architectures.
|
||||
* Added `binaryPartitionCG`. Demonstrates binary partition cooperative groups and reduction within the thread block.
|
||||
* Added two new reduction kernels in `reduction` one which demonstrates reduce_add_sync intrinstic supported on compute capability 8.0 and another which uses cooperative_groups::reduce function which does thread_block_tile level reduction introduced from CUDA 11.0.
|
||||
* Added `cudaCompressibleMemory`. Demonstrates compressible memory allocation using cuMemMap API.
|
||||
* Added `simpleVulkanMMAP`. Demonstrates Vulkan CUDA Interop via cuMemMap APIs.
|
||||
* Added `concurrentKernels`. Demonstrates the use of CUDA streams for concurrent execution of several kernels on a GPU.
|
||||
* Dropped Mac OSX support from all samples.
|
||||
|
||||
### CUDA 10.2
|
||||
* Added `simpleD3D11`. Demonstrates CUDA-D3D11 External Resource Interoperability APIs for updating D3D11 buffers from CUDA and synchronization between D3D11 and CUDA with Keyed Mutexes.
|
||||
* Added `simpleDrvRuntime`. Demonstrates CUDA Driver and Runtime APIs working together to load fatbinary of a CUDA kernel.
|
||||
* Added `vectorAddMMAP`. Demonstrates how cuMemMap API allows the user to specify the physical properties of their memory while retaining the contiguous nature of their access.
|
||||
* Added `memMapIPCDrv`. Demonstrates Inter Process Communication using cuMemMap APIs.
|
||||
* Added `cudaNvSci`. Demonstrates CUDA-NvSciBuf/NvSciSync Interop.
|
||||
* Added `jacobiCudaGraphs`. Demonstrates Instantiated CUDA Graph Update with Jacobi Iterative Method using different approaches.
|
||||
* Added `cuSolverSp_LinearSolver`. Demonstrates cuSolverSP's LU, QR and Cholesky factorization.
|
||||
* Added `MersenneTwisterGP11213`. Demonstrates the Mersenne Twister random number generator GP11213 in cuRAND.
|
||||
|
||||
### CUDA 10.1 Update 2
|
||||
* Added `vulkanImageCUDA`. Demonstrates how to perform Vulkan image - CUDA Interop.
|
||||
* Added `nvJPEG_encoder`. Demonstrates encoding of jpeg images using NVJPEG Library.
|
||||
* Added Windows OS support to `nvJPEG` sample.
|
||||
* Added `boxFilterNPP`. Demonstrates how to use NPP FilterBox function to perform a box filter.
|
||||
* Added `cannyEdgeDetectorNPP`. Demonstrates the nppiFilterCannyBorder_8u_C1R Canny Edge Detection image filter function.
|
||||
|
||||
### CUDA 10.1 Update 1
|
||||
* Added `NV12toBGRandResize`. Demonstrates how to convert and resize NV12 frames to BGR planars frames using CUDA in batch.
|
||||
* Added `EGLStream_CUDA_Interop`. Demonstrates data exchange between CUDA and EGL Streams.
|
||||
* Added `cuSolverDn_LinearSolver`. Demonstrates cuSolverDN's LU, QR and Cholesky factorization.
|
||||
* Added support of Visual Studio 2019 to all samples supported on [Windows](./README.md#windows-1).
|
||||
|
||||
### CUDA 10.1
|
||||
* Added `immaTensorCoreGemm`. Demonstrates integer GEMM computation using the Warp Matrix Multiply and Accumulate (WMMA) API for integers employing the Tensor Cores.
|
||||
* Added `simpleIPC`. Demonstrates Inter Process Communication with one process per GPU for computation.
|
||||
* Added `nvJPEG`. Demonstrates single and batched decoding of jpeg images using NVJPEG Library.
|
||||
* Added `bandwidthTest`. It measures the memcopy bandwidth of the GPU and memcpy bandwidth across PCI-e.
|
||||
* Added `reduction`. Demonstrates several important optimization strategies for Data-Parallel Algorithms like reduction.
|
||||
* Update all the samples to support CUDA 10.1.
|
||||
|
||||
|
||||
### CUDA 10.0
|
||||
* Added `simpleCudaGraphs`. Demonstrates CUDA Graphs creation, instantiation and launch using Graphs APIs and Stream Capture APIs.
|
||||
* Added `conjugateGradientCudaGraphs`. Demonstrates conjugate gradient solver on GPU using CUBLAS and CUSPARSE library calls captured and called using CUDA Graph APIs.
|
||||
* Added `simpleVulkan`. Demonstrates Vulkan - CUDA Interop.
|
||||
* Added `simpleD3D12`. Demonstrates DX12 - CUDA Interop.
|
||||
* Added `UnifiedMemoryPerf`. Demonstrates performance comparision of various memory types involved in system.
|
||||
* Added `p2pBandwidthLatencyTest`. Demonstrates Peer-To-Peer (P2P) data transfers between pairs of GPUs and computes latency and bandwidth.
|
||||
* Added `systemWideAtomics`. Demonstrates system wide atomic instructions.
|
||||
* Added `simpleCUBLASXT`. Demonstrates CUBLAS-XT library which performs GEMM operations over multiple GPUs.
|
||||
* Added Windows OS support to `conjugateGradientMultiDeviceCG` sample.
|
||||
* Removed support of Visual Studio 2010 from all samples.
|
||||
|
||||
|
||||
### CUDA 9.2
|
||||
|
||||
This is the first release of CUDA Samples on GitHub:
|
||||
* Added `vectorAdd_nvrtc`. Demonstrates runtime compilation library using NVRTC of a simple vectorAdd kernel.
|
||||
* Added `warpAggregatedAtomicsCG`. Demonstrates warp aggregated atomics using Cooperative Groups.
|
||||
* Added `deviceQuery`. Enumerates the properties of the CUDA devices present in the system.
|
||||
* Added `matrixMul`. Demonstrates a matrix multiplication using shared memory through tiled approach.
|
||||
* Added `matrixMulDrv`. Demonstrates a matrix multiplication using shared memory through tiled approach, uses CUDA Driver API.
|
||||
* Added `cudaTensorCoreGemm`. Demonstrates a GEMM computation using the Warp Matrix Multiply and Accumulate (WMMA) API introduced in CUDA 9, as well as the new Tensor Cores introduced in the Volta chip family.
|
||||
* Added `simpleVoteIntrinsics` which uses *_sync equivalent of the vote intrinsics _any, _all added since CUDA 9.0.
|
||||
* Added `shfl_scan` which uses *_sync equivalent of the shfl intrinsics added since CUDA 9.0.
|
||||
* Added `conjugateGradientMultiBlockCG`. Demonstrates a conjugate gradient solver on GPU using Multi Block Cooperative Groups.
|
||||
* Added `conjugateGradientMultiDeviceCG`. Demonstrates a conjugate gradient solver on multiple GPUs using Multi Device Cooperative Groups, also uses unified memory prefetching and usage hints APIs.
|
||||
* Added `simpleCUBLAS`. Demonstrates how perform GEMM operations using CUBLAS library.
|
||||
* Added `simpleCUFFT`. Demonstrates how perform FFT operations using CUFFT library.
|
||||
33
CMakeLists.txt
Normal file
33
CMakeLists.txt
Normal file
@@ -0,0 +1,33 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
project(cuda-samples LANGUAGES C CXX CUDA)
|
||||
|
||||
find_package(CUDAToolkit REQUIRED)
|
||||
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(CMAKE_CUDA_STANDARD 17)
|
||||
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
|
||||
|
||||
set(CMAKE_CUDA_ARCHITECTURES 75 80 86 87 89 90 100 110 120)
|
||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
|
||||
if(ENABLE_CUDA_DEBUG)
|
||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G") # enable cuda-gdb (may significantly affect performance on some targets)
|
||||
else()
|
||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo") # add line information to all builds for debug tools (exclusive to -G option)
|
||||
endif()
|
||||
|
||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --extended-lambda")
|
||||
|
||||
# Add MSVC-specific flags for standard-conforming preprocessor (required for CCCL)
|
||||
if(MSVC)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=/Zc:preprocessor>)
|
||||
endif()
|
||||
|
||||
# Include installation configuration before processing samples
|
||||
include(cmake/InstallSamples.cmake)
|
||||
|
||||
add_subdirectory(cpp)
|
||||
103
CONTRIBUTING.md
Normal file
103
CONTRIBUTING.md
Normal file
@@ -0,0 +1,103 @@
|
||||
|
||||
# Contributing to the CUDA Samples
|
||||
|
||||
Thank you for your interest in contributing to the CUDA Samples!
|
||||
|
||||
|
||||
## Getting Started
|
||||
|
||||
1. **Fork & Clone the Repository**:
|
||||
|
||||
Fork the reporistory and clone the fork. For more information, check [GitHub's documentation on forking](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo) and [cloning a repository](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository).
|
||||
|
||||
## Making Changes
|
||||
|
||||
1. **Create a New Branch**:
|
||||
|
||||
```bash
|
||||
git checkout -b your-feature-branch
|
||||
```
|
||||
|
||||
2. **Make Changes**.
|
||||
|
||||
3. **Build and Test**:
|
||||
|
||||
Ensure changes don't break existing functionality by building and running tests.
|
||||
|
||||
For more details on building and testing, refer to the [Building and Testing](#building-and-testing) section below.
|
||||
|
||||
4. **Commit Changes**:
|
||||
|
||||
```bash
|
||||
git commit -m "Brief description of the change"
|
||||
```
|
||||
|
||||
## Building and Testing
|
||||
|
||||
For information on building a running tests on the samples, please refer to the main [README](README.md)
|
||||
|
||||
## Creating a Pull Request
|
||||
|
||||
1. Push changes to your fork
|
||||
2. Create a pull request targeting the `master` branch of the original CUDA Samples repository. Refer to [GitHub's documentation](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) for more information on creating a pull request.
|
||||
3. Describe the purpose and context of the changes in the pull request description.
|
||||
|
||||
## Code Formatting (pre-commit hooks)
|
||||
|
||||
The CUDA Samples repository uses [pre-commit](https://pre-commit.com/) to execute all code linters and formatters. These
|
||||
tools ensure a consistent coding style throughout the project. Using pre-commit ensures that linter
|
||||
versions and options are aligned for all developers. Additionally, there is a CI check in place to
|
||||
enforce that committed code follows our standards.
|
||||
|
||||
The linters used by the CUDA Samples are listed in `.pre-commit-config.yaml`.
|
||||
For example, C++ and CUDA code is formatted with [`clang-format`](https://clang.llvm.org/docs/ClangFormat.html).
|
||||
|
||||
To use `pre-commit`, install via `conda` or `pip`:
|
||||
|
||||
```bash
|
||||
conda config --add channels conda-forge
|
||||
conda install pre-commit
|
||||
```
|
||||
|
||||
```bash
|
||||
pip install pre-commit
|
||||
```
|
||||
|
||||
Then run pre-commit hooks before committing code:
|
||||
|
||||
```bash
|
||||
pre-commit run
|
||||
```
|
||||
|
||||
By default, pre-commit runs on staged files (only changes and additions that will be committed).
|
||||
To run pre-commit checks on all files, execute:
|
||||
|
||||
```bash
|
||||
pre-commit run --all-files
|
||||
```
|
||||
|
||||
Optionally, you may set up the pre-commit hooks to run automatically when you make a git commit. This can be done by running:
|
||||
|
||||
```bash
|
||||
pre-commit install
|
||||
```
|
||||
|
||||
Now code linters and formatters will be run each time you commit changes.
|
||||
|
||||
You can skip these checks with `git commit --no-verify` or with the short version `git commit -n`, althoguh please note
|
||||
that this may result in pull requests being rejected if subsequent checks fail.
|
||||
|
||||
## Review Process
|
||||
|
||||
Once submitted, maintainers will be automatically assigned to review the pull request. They might suggest changes or improvements. Constructive feedback is a part of the collaborative process, aimed at ensuring the highest quality code.
|
||||
|
||||
For constructive feedback and effective communication during reviews, we recommend following [Conventional Comments](https://conventionalcomments.org/).
|
||||
|
||||
Further recommended reading for successful PR reviews:
|
||||
|
||||
- [How to Do Code Reviews Like a Human (Part One)](https://mtlynch.io/human-code-reviews-1/)
|
||||
- [How to Do Code Reviews Like a Human (Part Two)](https://mtlynch.io/human-code-reviews-2/)
|
||||
|
||||
## Thank You
|
||||
|
||||
Your contributions enhance the CUDA Samples for the entire community. We appreciate your effort and collaboration!
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
BIN
Common/data/teapot512.pgm
Normal file
BIN
Common/data/teapot512.pgm
Normal file
Binary file not shown.
BIN
Common/data/teapot_512x512_8u.raw
Normal file
BIN
Common/data/teapot_512x512_8u.raw
Normal file
Binary file not shown.
BIN
Common/data/teapot_512x512_8u_Gray.raw
Normal file
BIN
Common/data/teapot_512x512_8u_Gray.raw
Normal file
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -138,26 +138,29 @@ static const char *_cudaGetErrorEnum(cufftResult error) {
|
||||
case CUFFT_UNALIGNED_DATA:
|
||||
return "CUFFT_UNALIGNED_DATA";
|
||||
|
||||
case CUFFT_INCOMPLETE_PARAMETER_LIST:
|
||||
return "CUFFT_INCOMPLETE_PARAMETER_LIST";
|
||||
|
||||
case CUFFT_INVALID_DEVICE:
|
||||
return "CUFFT_INVALID_DEVICE";
|
||||
|
||||
case CUFFT_PARSE_ERROR:
|
||||
return "CUFFT_PARSE_ERROR";
|
||||
|
||||
case CUFFT_NO_WORKSPACE:
|
||||
return "CUFFT_NO_WORKSPACE";
|
||||
|
||||
case CUFFT_NOT_IMPLEMENTED:
|
||||
return "CUFFT_NOT_IMPLEMENTED";
|
||||
|
||||
case CUFFT_LICENSE_ERROR:
|
||||
return "CUFFT_LICENSE_ERROR";
|
||||
|
||||
case CUFFT_NOT_SUPPORTED:
|
||||
return "CUFFT_NOT_SUPPORTED";
|
||||
|
||||
case CUFFT_MISSING_DEPENDENCY:
|
||||
return "CUFFT_MISSING_DEPENDENCY";
|
||||
|
||||
case CUFFT_NVRTC_FAILURE:
|
||||
return "CUFFT_NVRTC_FAILURE";
|
||||
|
||||
case CUFFT_NVJITLINK_FAILURE:
|
||||
return "CUFFT_NVJITLINK_FAILURE";
|
||||
|
||||
case CUFFT_NVSHMEM_FAILURE:
|
||||
return "CUFFT_NVSHMEM_FAILURE";
|
||||
}
|
||||
|
||||
return "<unknown>";
|
||||
@@ -665,6 +668,15 @@ inline int _ConvertSMVer2Cores(int major, int minor) {
|
||||
{0x75, 64},
|
||||
{0x80, 64},
|
||||
{0x86, 128},
|
||||
{0x87, 128},
|
||||
{0x89, 128},
|
||||
{0x90, 128},
|
||||
{0xa0, 128},
|
||||
{0xa1, 128},
|
||||
{0xa3, 128},
|
||||
{0xb0, 128},
|
||||
{0xc0, 128},
|
||||
{0xc1, 128},
|
||||
{-1, -1}};
|
||||
|
||||
int index = 0;
|
||||
@@ -711,6 +723,15 @@ inline const char* _ConvertSMVer2ArchName(int major, int minor) {
|
||||
{0x75, "Turing"},
|
||||
{0x80, "Ampere"},
|
||||
{0x86, "Ampere"},
|
||||
{0x87, "Ampere"},
|
||||
{0x89, "Ada"},
|
||||
{0x90, "Hopper"},
|
||||
{0xa0, "Blackwell"},
|
||||
{0xa1, "Blackwell"},
|
||||
{0xa3, "Blackwell"},
|
||||
{0xb0, "Blackwell"},
|
||||
{0xc0, "Blackwell"},
|
||||
{0xc1, "Blackwell"},
|
||||
{-1, "Graphics Device"}};
|
||||
|
||||
int index = 0;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -113,6 +113,15 @@ inline int _ConvertSMVer2CoresDRV(int major, int minor) {
|
||||
{0x75, 64},
|
||||
{0x80, 64},
|
||||
{0x86, 128},
|
||||
{0x87, 128},
|
||||
{0x89, 128},
|
||||
{0x90, 128},
|
||||
{0xa0, 128},
|
||||
{0xa1, 128},
|
||||
{0xa3, 128},
|
||||
{0xb0, 128},
|
||||
{0xc0, 128},
|
||||
{0xc1, 128},
|
||||
{-1, -1}};
|
||||
|
||||
int index = 0;
|
||||
@@ -235,7 +244,7 @@ inline int gpuGetMaxGflopsDeviceIdDRV() {
|
||||
}
|
||||
|
||||
unsigned long long compute_perf =
|
||||
(unsigned long long)(multiProcessorCount * sm_per_multiproc *
|
||||
((unsigned long long)multiProcessorCount * sm_per_multiproc *
|
||||
clockRate);
|
||||
|
||||
if (compute_perf > max_compute_perf) {
|
||||
@@ -402,4 +411,3 @@ bool inline findFatbinPath(const char *module_file, std::string &module_path, ch
|
||||
// end of CUDA Helper Functions
|
||||
|
||||
#endif // COMMON_HELPER_CUDA_DRVAPI_H_
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -168,7 +168,7 @@ int waitProcess(Process *process) {
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(__linux__)
|
||||
#if defined(__linux__) || defined(__QNX__)
|
||||
int ipcCreateSocket(ipcHandle *&handle, const char *name,
|
||||
const std::vector<Process> &processes) {
|
||||
int server_fd;
|
||||
@@ -185,25 +185,30 @@ int ipcCreateSocket(ipcHandle *&handle, const char *name,
|
||||
return -1;
|
||||
}
|
||||
|
||||
unlink(name);
|
||||
bzero(&servaddr, sizeof(servaddr));
|
||||
char path_name[50];
|
||||
|
||||
// Create unique name for the socket with path if SOCK_FOLDER is set.
|
||||
sprintf(path_name, "%s/%u", getSocketFolder().c_str(), getpid());
|
||||
|
||||
unlink(path_name);
|
||||
memset(&servaddr, 0, sizeof(servaddr));
|
||||
servaddr.sun_family = AF_UNIX;
|
||||
|
||||
size_t len = strlen(name);
|
||||
size_t len = strlen(path_name);
|
||||
if (len > (sizeof(servaddr.sun_path) - 1)) {
|
||||
perror("IPC failure: Cannot bind provided name to socket. Name too large");
|
||||
return -1;
|
||||
}
|
||||
|
||||
strncpy(servaddr.sun_path, name, len);
|
||||
strncpy(servaddr.sun_path, path_name, len);
|
||||
|
||||
if (bind(server_fd, (struct sockaddr *)&servaddr, SUN_LEN(&servaddr)) < 0) {
|
||||
perror("IPC failure: Binding socket failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
handle->socketName = new char[strlen(name) + 1];
|
||||
strcpy(handle->socketName, name);
|
||||
handle->socketName = new char[strlen(path_name) + 1];
|
||||
strcpy(handle->socketName, path_name);
|
||||
handle->socket = server_fd;
|
||||
return 0;
|
||||
}
|
||||
@@ -219,13 +224,13 @@ int ipcOpenSocket(ipcHandle *&handle) {
|
||||
perror("IPC failure:Socket creation error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
bzero(&cliaddr, sizeof(cliaddr));
|
||||
|
||||
memset(&cliaddr, 0, sizeof(cliaddr));
|
||||
cliaddr.sun_family = AF_UNIX;
|
||||
char temp[10];
|
||||
char temp[50];
|
||||
|
||||
// Create unique name for the socket.
|
||||
sprintf(temp, "%u", getpid());
|
||||
// Create unique name for the socket with path if SOCK_FOLDER is set.
|
||||
sprintf(temp, "%s/%u", getSocketFolder().c_str(), getpid());
|
||||
|
||||
strcpy(cliaddr.sun_path, temp);
|
||||
if (bind(sock, (struct sockaddr *)&cliaddr, sizeof(cliaddr)) < 0) {
|
||||
@@ -262,41 +267,48 @@ int ipcRecvShareableHandle(ipcHandle *handle, ShareableHandle *shHandle) {
|
||||
// Union to guarantee alignment requirements for control array
|
||||
union {
|
||||
struct cmsghdr cm;
|
||||
char control[CMSG_SPACE(sizeof(int))];
|
||||
// This will not work on QNX as QNX CMSG_SPACE calls __cmsg_alignbytes
|
||||
// And __cmsg_alignbytes is a runtime function instead of compile-time macros
|
||||
// char control[CMSG_SPACE(sizeof(int))]
|
||||
char* control;
|
||||
} control_un;
|
||||
|
||||
size_t sizeof_control = CMSG_SPACE(sizeof(int)) * sizeof(char);
|
||||
control_un.control = (char*) malloc(sizeof_control);
|
||||
struct cmsghdr *cmptr;
|
||||
ssize_t n;
|
||||
int receivedfd;
|
||||
char dummy_buffer[1];
|
||||
ssize_t sendResult;
|
||||
|
||||
msg.msg_control = control_un.control;
|
||||
msg.msg_controllen = sizeof(control_un.control);
|
||||
msg.msg_controllen = sizeof_control;
|
||||
|
||||
iov[0].iov_base = (void *)dummy_buffer;
|
||||
iov[0].iov_len = sizeof(dummy_buffer);
|
||||
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
if ((n = recvmsg(handle->socket, &msg, 0)) <= 0) {
|
||||
perror("IPC failure: Receiving data over socket failed");
|
||||
free(control_un.control);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (((cmptr = CMSG_FIRSTHDR(&msg)) != NULL) &&
|
||||
(cmptr->cmsg_len == CMSG_LEN(sizeof(int)))) {
|
||||
if ((cmptr->cmsg_level != SOL_SOCKET) || (cmptr->cmsg_type != SCM_RIGHTS)) {
|
||||
free(control_un.control);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memmove(&receivedfd, CMSG_DATA(cmptr), sizeof(receivedfd));
|
||||
*(int *)shHandle = receivedfd;
|
||||
} else {
|
||||
free(control_un.control);
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(control_un.control);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -319,7 +331,7 @@ int ipcSendDataToServer(ipcHandle *handle, const char *serverName,
|
||||
ssize_t sendResult;
|
||||
struct sockaddr_un serveraddr;
|
||||
|
||||
bzero(&serveraddr, sizeof(serveraddr));
|
||||
memset(&serveraddr, 0, sizeof(serveraddr));
|
||||
serveraddr.sun_family = AF_UNIX;
|
||||
strncpy(serveraddr.sun_path, serverName, sizeof(serveraddr.sun_path) - 1);
|
||||
|
||||
@@ -340,19 +352,22 @@ int ipcSendShareableHandle(ipcHandle *handle,
|
||||
|
||||
union {
|
||||
struct cmsghdr cm;
|
||||
char control[CMSG_SPACE(sizeof(int))];
|
||||
char* control;
|
||||
} control_un;
|
||||
|
||||
size_t sizeof_control = CMSG_SPACE(sizeof(int)) * sizeof(char);
|
||||
control_un.control = (char*) malloc(sizeof_control);
|
||||
|
||||
struct cmsghdr *cmptr;
|
||||
ssize_t readResult;
|
||||
struct sockaddr_un cliaddr;
|
||||
socklen_t len = sizeof(cliaddr);
|
||||
|
||||
// Construct client address to send this SHareable handle to
|
||||
bzero(&cliaddr, sizeof(cliaddr));
|
||||
memset(&cliaddr, 0, sizeof(cliaddr));
|
||||
cliaddr.sun_family = AF_UNIX;
|
||||
char temp[10];
|
||||
sprintf(temp, "%u", process);
|
||||
char temp[20];
|
||||
sprintf(temp, "%s/%u", getSocketFolder().c_str(), process);
|
||||
strcpy(cliaddr.sun_path, temp);
|
||||
len = sizeof(cliaddr);
|
||||
|
||||
@@ -360,7 +375,7 @@ int ipcSendShareableHandle(ipcHandle *handle,
|
||||
int sendfd = (int)shareableHandles[data];
|
||||
|
||||
msg.msg_control = control_un.control;
|
||||
msg.msg_controllen = sizeof(control_un.control);
|
||||
msg.msg_controllen = sizeof_control;
|
||||
|
||||
cmptr = CMSG_FIRSTHDR(&msg);
|
||||
cmptr->cmsg_len = CMSG_LEN(sizeof(int));
|
||||
@@ -380,9 +395,11 @@ int ipcSendShareableHandle(ipcHandle *handle,
|
||||
ssize_t sendResult = sendmsg(handle->socket, &msg, 0);
|
||||
if (sendResult <= 0) {
|
||||
perror("IPC failure: Sending data over socket failed");
|
||||
free(control_un.control);
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(control_un.control);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -54,6 +54,27 @@
|
||||
#endif
|
||||
#include <vector>
|
||||
|
||||
// The Unix domain sockets creating folder on QNX has been restricted to qnx6-mounted directories since QNX SDP 8.0.3.
|
||||
#if defined(__QNX__)
|
||||
#include <string>
|
||||
inline std::string getSocketFolder() {
|
||||
return "/storage";
|
||||
}
|
||||
// Simple filesystem compatibility for GCC 8.x
|
||||
#elif defined(__GNUC__) && __GNUC__ < 9
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
inline std::string getSocketFolder() {
|
||||
const char* tmpdir = std::getenv("TMPDIR");
|
||||
return tmpdir ? std::string(tmpdir) : "/tmp";
|
||||
}
|
||||
#else
|
||||
#include <filesystem>
|
||||
inline std::string getSocketFolder() {
|
||||
return std::filesystem::temp_directory_path().string();
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct sharedMemoryInfo_st {
|
||||
void *addr;
|
||||
size_t size;
|
||||
@@ -84,7 +105,7 @@ int waitProcess(Process *process);
|
||||
#define checkIpcErrors(ipcFuncResult) \
|
||||
if (ipcFuncResult == -1) { fprintf(stderr, "Failure at %u %s\n", __LINE__, __FILE__); exit(EXIT_FAILURE); }
|
||||
|
||||
#if defined(__linux__)
|
||||
#if defined(__linux__) || defined(__QNX__)
|
||||
struct ipcHandle_st {
|
||||
int socket;
|
||||
char *socketName;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -399,10 +399,10 @@ int getInputDir(std::string &input_dir, const char *executable_path) {
|
||||
// Search in default paths for input images.
|
||||
std::string pathname = "";
|
||||
const char *searchPath[] = {
|
||||
"./images", "../../../../Samples/<executable_name>/images",
|
||||
"../../../Samples/<executable_name>/images",
|
||||
"../../Samples/<executable_name>/images"};
|
||||
|
||||
"./images",
|
||||
"../../../../cpp/4_CUDA_Libraries/<executable_name>/images",
|
||||
"../../../cpp/4_CUDA_Libraries/<executable_name>/images",
|
||||
"../../cpp/4_CUDA_Libraries/<executable_name>/images"};
|
||||
|
||||
for (unsigned int i = 0; i < sizeof(searchPath) / sizeof(char *); ++i) {
|
||||
std::string pathname(searchPath[i]);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -285,17 +285,82 @@ inline char *sdkFindFilePath(const char *filename,
|
||||
// the .exe file, a .bat file launching an .exe, a browser .exe launching the
|
||||
// .exe or .bat, etc
|
||||
const char *searchPath[] = {
|
||||
"./", // same dir
|
||||
"./", // same dir
|
||||
"./data/", // same dir
|
||||
"../../../../Samples/<executable_name>/", // up 4 in tree
|
||||
"../../../Samples/<executable_name>/", // up 3 in tree
|
||||
"../../Samples/<executable_name>/", // up 2 in tree
|
||||
"../../../../Samples/<executable_name>/data/", // up 4 in tree
|
||||
"../../../Samples/<executable_name>/data/", // up 3 in tree
|
||||
"../../Samples/<executable_name>/data/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/<executable_name>/", // up 4 in tree
|
||||
"../../../cpp/<executable_name>/", // up 3 in tree
|
||||
"../../cpp/<executable_name>/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/<executable_name>/data/", // up 4 in tree
|
||||
"../../../cpp/<executable_name>/data/", // up 3 in tree
|
||||
"../../cpp/<executable_name>/data/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/0_Introduction/<executable_name>/", // up 4 in tree
|
||||
"../../../cpp/0_Introduction/<executable_name>/", // up 3 in tree
|
||||
"../../cpp/0_Introduction/<executable_name>/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/1_Utilities/<executable_name>/", // up 4 in tree
|
||||
"../../../cpp/1_Utilities/<executable_name>/", // up 3 in tree
|
||||
"../../cpp/1_Utilities/<executable_name>/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/2_Concepts_and_Techniques/<executable_name>/", // up 4 in tree
|
||||
"../../../cpp/2_Concepts_and_Techniques/<executable_name>/", // up 3 in tree
|
||||
"../../cpp/2_Concepts_and_Techniques/<executable_name>/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/3_CUDA_Features/<executable_name>/", // up 4 in tree
|
||||
"../../../cpp/3_CUDA_Features/<executable_name>/", // up 3 in tree
|
||||
"../../cpp/3_CUDA_Features/<executable_name>/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/4_CUDA_Libraries/<executable_name>/", // up 4 in tree
|
||||
"../../../cpp/4_CUDA_Libraries/<executable_name>/", // up 3 in tree
|
||||
"../../cpp/4_CUDA_Libraries/<executable_name>/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/5_Domain_Specific/<executable_name>/", // up 4 in tree
|
||||
"../../../cpp/5_Domain_Specific/<executable_name>/", // up 3 in tree
|
||||
"../../cpp/5_Domain_Specific/<executable_name>/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/6_Performance/<executable_name>/", // up 4 in tree
|
||||
"../../../cpp/6_Performance/<executable_name>/", // up 3 in tree
|
||||
"../../cpp/6_Performance/<executable_name>/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/0_Introduction/<executable_name>/data/", // up 4 in tree
|
||||
"../../../cpp/0_Introduction/<executable_name>/data/", // up 3 in tree
|
||||
"../../cpp/0_Introduction/<executable_name>/data/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/1_Utilities/<executable_name>/data/", // up 4 in tree
|
||||
"../../../cpp/1_Utilities/<executable_name>/data/", // up 3 in tree
|
||||
"../../cpp/1_Utilities/<executable_name>/data/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/2_Concepts_and_Techniques/<executable_name>/data/", // up 4 in tree
|
||||
"../../../cpp/2_Concepts_and_Techniques/<executable_name>/data/", // up 3 in tree
|
||||
"../../cpp/2_Concepts_and_Techniques/<executable_name>/data/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/3_CUDA_Features/<executable_name>/data/", // up 4 in tree
|
||||
"../../../cpp/3_CUDA_Features/<executable_name>/data/", // up 3 in tree
|
||||
"../../cpp/3_CUDA_Features/<executable_name>/data/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/4_CUDA_Libraries/<executable_name>/data/", // up 4 in tree
|
||||
"../../../cpp/4_CUDA_Libraries/<executable_name>/data/", // up 3 in tree
|
||||
"../../cpp/4_CUDA_Libraries/<executable_name>/data/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/5_Domain_Specific/<executable_name>/data/", // up 4 in tree
|
||||
"../../../cpp/5_Domain_Specific/<executable_name>/data/", // up 3 in tree
|
||||
"../../cpp/5_Domain_Specific/<executable_name>/data/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/6_Performance/<executable_name>/data/", // up 4 in tree
|
||||
"../../../cpp/6_Performance/<executable_name>/data/", // up 3 in tree
|
||||
"../../cpp/6_Performance/<executable_name>/data/", // up 2 in tree
|
||||
|
||||
"../../../../Common/data/", // up 4 in tree
|
||||
"../../../Common/data/", // up 3 in tree
|
||||
"../../Common/data/" // up 2 in tree
|
||||
"../../Common/data/", // up 2 in tree
|
||||
|
||||
"../../../../cpp/9_CUDA_Tile/<executable_name>/", // up 4 in tree
|
||||
"../../../cpp/9_CUDA_Tile/<executable_name>/", // up 3 in tree
|
||||
"../../cpp/9_CUDA_Tile/<executable_name>/", // up 2 in tree
|
||||
"../cpp/9_CUDA_Tile/<executable_name>/", // up 1 in tree
|
||||
"./cpp/9_CUDA_Tile/<executable_name>/" // up 0 in tree
|
||||
};
|
||||
|
||||
// Extract the executable name
|
||||
@@ -362,6 +427,7 @@ inline char *sdkFindFilePath(const char *filename,
|
||||
}
|
||||
|
||||
// File not found
|
||||
printf("\nerror: sdkFindFilePath: file <%s> not found!\n", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
78
Common/multithreading.cpp
Normal file
78
Common/multithreading.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <multithreading.h>
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
|
||||
// Create thread
|
||||
CUTThread cutStartThread(CUT_THREADROUTINE func, void *data) {
|
||||
return CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func, data, 0, NULL);
|
||||
}
|
||||
|
||||
// Wait for thread to finish
|
||||
void cutEndThread(CUTThread thread) {
|
||||
WaitForSingleObject(thread, INFINITE);
|
||||
CloseHandle(thread);
|
||||
}
|
||||
|
||||
// Destroy thread
|
||||
void cutDestroyThread(CUTThread thread) {
|
||||
TerminateThread(thread, 0);
|
||||
CloseHandle(thread);
|
||||
}
|
||||
|
||||
// Wait for multiple threads
|
||||
void cutWaitForThreads(const CUTThread *threads, int num) {
|
||||
WaitForMultipleObjects(num, threads, true, INFINITE);
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
CloseHandle(threads[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
// Create thread
|
||||
CUTThread cutStartThread(CUT_THREADROUTINE func, void *data) {
|
||||
pthread_t thread;
|
||||
pthread_create(&thread, NULL, func, data);
|
||||
return thread;
|
||||
}
|
||||
|
||||
// Wait for thread to finish
|
||||
void cutEndThread(CUTThread thread) { pthread_join(thread, NULL); }
|
||||
|
||||
// Destroy thread
|
||||
void cutDestroyThread(CUTThread thread) { pthread_cancel(thread); }
|
||||
|
||||
// Wait for multiple threads
|
||||
void cutWaitForThreads(const CUTThread *threads, int num) {
|
||||
for (int i = 0; i < num; i++) {
|
||||
cutEndThread(threads[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
76
Common/multithreading.h
Normal file
76
Common/multithreading.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef MULTITHREADING_H
|
||||
#define MULTITHREADING_H
|
||||
|
||||
|
||||
//Simple portable thread library.
|
||||
|
||||
//Windows threads.
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
|
||||
#include <windows.h>
|
||||
|
||||
typedef HANDLE CUTThread;
|
||||
typedef unsigned(WINAPI *CUT_THREADROUTINE)(void *);
|
||||
|
||||
#define CUT_THREADPROC unsigned WINAPI
|
||||
#define CUT_THREADEND return 0
|
||||
|
||||
#else
|
||||
//POSIX threads.
|
||||
#include <pthread.h>
|
||||
|
||||
typedef pthread_t CUTThread;
|
||||
typedef void *(*CUT_THREADROUTINE)(void *);
|
||||
|
||||
#define CUT_THREADPROC void
|
||||
#define CUT_THREADEND
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//Create thread.
|
||||
CUTThread cutStartThread(CUT_THREADROUTINE, void *data);
|
||||
|
||||
//Wait for thread to finish.
|
||||
void cutEndThread(CUTThread thread);
|
||||
|
||||
//Destroy thread.
|
||||
void cutDestroyThread(CUTThread thread);
|
||||
|
||||
//Wait for multiple threads.
|
||||
void cutWaitForThreads(const CUTThread *threads, int num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} //extern "C"
|
||||
#endif
|
||||
|
||||
#endif //MULTITHREADING_H
|
||||
111
Common/nvMath.h
Normal file
111
Common/nvMath.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
//
|
||||
// Template math library for common 3D functionality
|
||||
//
|
||||
// This code is in part deriver from glh, a cross platform glut helper library.
|
||||
// The copyright for glh follows this notice.
|
||||
//
|
||||
// Copyright (c) NVIDIA Corporation. All rights reserved.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
Copyright (c) 2000 Cass Everitt
|
||||
Copyright (c) 2000 NVIDIA Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or
|
||||
without modification, are permitted provided that the following
|
||||
conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
* The names of contributors to this software may not be used
|
||||
to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Cass Everitt - cass@r3.nu
|
||||
*/
|
||||
|
||||
#ifndef NV_MATH_H
|
||||
#define NV_MATH_H
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <nvVector.h>
|
||||
#include <nvMatrix.h>
|
||||
#include <nvQuaternion.h>
|
||||
|
||||
#define NV_PI float(3.1415926535897932384626433832795)
|
||||
|
||||
namespace nv
|
||||
{
|
||||
|
||||
typedef vec2<float> vec2f;
|
||||
typedef vec3<float> vec3f;
|
||||
typedef vec3<int> vec3i;
|
||||
typedef vec3<unsigned int> vec3ui;
|
||||
typedef vec4<float> vec4f;
|
||||
typedef matrix4<float> matrix4f;
|
||||
typedef quaternion<float> quaternionf;
|
||||
|
||||
|
||||
inline void applyRotation(const quaternionf &r)
|
||||
{
|
||||
float angle;
|
||||
vec3f axis;
|
||||
r.get_value(axis, angle);
|
||||
glRotatef(angle/3.1415926f * 180.0f, axis[0], axis[1], axis[2]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
540
Common/nvMatrix.h
Normal file
540
Common/nvMatrix.h
Normal file
@@ -0,0 +1,540 @@
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
//
|
||||
// Template math library for common 3D functionality
|
||||
//
|
||||
// nvMatrix.h - template matrix code
|
||||
//
|
||||
// This code is in part deriver from glh, a cross platform glut helper library.
|
||||
// The copyright for glh follows this notice.
|
||||
//
|
||||
// Copyright (c) NVIDIA Corporation. All rights reserved.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
Copyright (c) 2000 Cass Everitt
|
||||
Copyright (c) 2000 NVIDIA Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or
|
||||
without modification, are permitted provided that the following
|
||||
conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
* The names of contributors to this software may not be used
|
||||
to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Cass Everitt - cass@r3.nu
|
||||
*/
|
||||
|
||||
#ifndef NV_MATRIX_H
|
||||
#define NV_MATRIX_H
|
||||
|
||||
namespace nv
|
||||
{
|
||||
|
||||
template <class T> class vec2;
|
||||
template <class T> class vec3;
|
||||
template <class T> class vec4;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Matrix
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
class matrix4
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
matrix4()
|
||||
{
|
||||
make_identity();
|
||||
}
|
||||
|
||||
matrix4(T t)
|
||||
{
|
||||
set_value(t);
|
||||
}
|
||||
|
||||
matrix4(const T *m)
|
||||
{
|
||||
set_value(m);
|
||||
}
|
||||
|
||||
matrix4(T a00, T a01, T a02, T a03,
|
||||
T a10, T a11, T a12, T a13,
|
||||
T a20, T a21, T a22, T a23,
|
||||
T a30, T a31, T a32, T a33) :
|
||||
_11(a00), _12(a01), _13(a02), _14(a03),
|
||||
_21(a10), _22(a11), _23(a12), _24(a13),
|
||||
_31(a20), _32(a21), _33(a22), _34(a23),
|
||||
_41(a30), _42(a31), _43(a32), _44(a33)
|
||||
{}
|
||||
|
||||
|
||||
void get_value(T *mp) const
|
||||
{
|
||||
int c = 0;
|
||||
|
||||
for (int j=0; j < 4; j++)
|
||||
for (int i=0; i < 4; i++)
|
||||
{
|
||||
mp[c++] = element(i,j);
|
||||
}
|
||||
}
|
||||
|
||||
const T *get_value() const
|
||||
{
|
||||
return _array;
|
||||
}
|
||||
|
||||
void set_value(T *mp)
|
||||
{
|
||||
int c = 0;
|
||||
|
||||
for (int j=0; j < 4; j++)
|
||||
for (int i=0; i < 4; i++)
|
||||
{
|
||||
element(i,j) = mp[c++];
|
||||
}
|
||||
}
|
||||
|
||||
void set_value(T r)
|
||||
{
|
||||
for (int i=0; i < 4; i++)
|
||||
for (int j=0; j < 4; j++)
|
||||
{
|
||||
element(i,j) = r;
|
||||
}
|
||||
}
|
||||
|
||||
void make_identity()
|
||||
{
|
||||
element(0,0) = 1.0;
|
||||
element(0,1) = 0.0;
|
||||
element(0,2) = 0.0;
|
||||
element(0,3) = 0.0;
|
||||
|
||||
element(1,0) = 0.0;
|
||||
element(1,1) = 1.0;
|
||||
element(1,2) = 0.0;
|
||||
element(1,3) = 0.0;
|
||||
|
||||
element(2,0) = 0.0;
|
||||
element(2,1) = 0.0;
|
||||
element(2,2) = 1.0;
|
||||
element(2,3) = 0.0;
|
||||
|
||||
element(3,0) = 0.0;
|
||||
element(3,1) = 0.0;
|
||||
element(3,2) = 0.0;
|
||||
element(3,3) = 1.0;
|
||||
}
|
||||
|
||||
// set a uniform scale
|
||||
void set_scale(T s)
|
||||
{
|
||||
element(0,0) = s;
|
||||
element(1,1) = s;
|
||||
element(2,2) = s;
|
||||
}
|
||||
|
||||
void set_scale(const vec3<T> &s)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
element(i,i) = s[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void set_translate(const vec3<T> &t)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
element(i,3) = t[i];
|
||||
}
|
||||
}
|
||||
|
||||
void set_row(int r, const vec4<T> &t)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
element(r,i) = t[i];
|
||||
}
|
||||
}
|
||||
|
||||
void set_column(int c, const vec4<T> &t)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
element(i,c) = t[i];
|
||||
}
|
||||
}
|
||||
|
||||
vec4<T> get_row(int r) const
|
||||
{
|
||||
vec4<T> v;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
v[i] = element(r,i);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
vec4<T> get_column(int c) const
|
||||
{
|
||||
vec4<T> v;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
v[i] = element(i,c);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
friend matrix4 inverse(const matrix4 &m)
|
||||
{
|
||||
matrix4 minv;
|
||||
|
||||
T r1[8], r2[8], r3[8], r4[8];
|
||||
T *s[4], *tmprow;
|
||||
|
||||
s[0] = &r1[0];
|
||||
s[1] = &r2[0];
|
||||
s[2] = &r3[0];
|
||||
s[3] = &r4[0];
|
||||
|
||||
int i,j,p,jj;
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
s[i][j] = m.element(i,j);
|
||||
|
||||
if (i==j)
|
||||
{
|
||||
s[i][j+4] = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s[i][j+4] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
T scp[4];
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
scp[i] = T(fabs(s[i][0]));
|
||||
|
||||
for (j=1; j<4; j++)
|
||||
if (T(fabs(s[i][j])) > scp[i])
|
||||
{
|
||||
scp[i] = T(fabs(s[i][j]));
|
||||
}
|
||||
|
||||
if (scp[i] == 0.0)
|
||||
{
|
||||
return minv; // singular matrix!
|
||||
}
|
||||
}
|
||||
|
||||
int pivot_to;
|
||||
T scp_max;
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
// select pivot row
|
||||
pivot_to = i;
|
||||
scp_max = T(fabs(s[i][i]/scp[i]));
|
||||
|
||||
// find out which row should be on top
|
||||
for (p=i+1; p<4; p++)
|
||||
if (T(fabs(s[p][i]/scp[p])) > scp_max)
|
||||
{
|
||||
scp_max = T(fabs(s[p][i]/scp[p]));
|
||||
pivot_to = p;
|
||||
}
|
||||
|
||||
// Pivot if necessary
|
||||
if (pivot_to != i)
|
||||
{
|
||||
tmprow = s[i];
|
||||
s[i] = s[pivot_to];
|
||||
s[pivot_to] = tmprow;
|
||||
T tmpscp;
|
||||
tmpscp = scp[i];
|
||||
scp[i] = scp[pivot_to];
|
||||
scp[pivot_to] = tmpscp;
|
||||
}
|
||||
|
||||
T mji;
|
||||
|
||||
// perform gaussian elimination
|
||||
for (j=i+1; j<4; j++)
|
||||
{
|
||||
mji = s[j][i]/s[i][i];
|
||||
s[j][i] = 0.0;
|
||||
|
||||
for (jj=i+1; jj<8; jj++)
|
||||
{
|
||||
s[j][jj] -= mji*s[i][jj];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s[3][3] == 0.0)
|
||||
{
|
||||
return minv; // singular matrix!
|
||||
}
|
||||
|
||||
//
|
||||
// Now we have an upper triangular matrix.
|
||||
//
|
||||
// x x x x | y y y y
|
||||
// 0 x x x | y y y y
|
||||
// 0 0 x x | y y y y
|
||||
// 0 0 0 x | y y y y
|
||||
//
|
||||
// we'll back substitute to get the inverse
|
||||
//
|
||||
// 1 0 0 0 | z z z z
|
||||
// 0 1 0 0 | z z z z
|
||||
// 0 0 1 0 | z z z z
|
||||
// 0 0 0 1 | z z z z
|
||||
//
|
||||
|
||||
T mij;
|
||||
|
||||
for (i=3; i>0; i--)
|
||||
{
|
||||
for (j=i-1; j > -1; j--)
|
||||
{
|
||||
mij = s[j][i]/s[i][i];
|
||||
|
||||
for (jj=j+1; jj<8; jj++)
|
||||
{
|
||||
s[j][jj] -= mij*s[i][jj];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
minv(i,j) = s[i][j+4] / s[i][i];
|
||||
}
|
||||
|
||||
return minv;
|
||||
}
|
||||
|
||||
|
||||
friend matrix4 transpose(const matrix4 &m)
|
||||
{
|
||||
matrix4 mtrans;
|
||||
|
||||
for (int i=0; i<4; i++)
|
||||
for (int j=0; j<4; j++)
|
||||
{
|
||||
mtrans(i,j) = m.element(j,i);
|
||||
}
|
||||
|
||||
return mtrans;
|
||||
}
|
||||
|
||||
matrix4 &operator *= (const matrix4 &rhs)
|
||||
{
|
||||
matrix4 mt(*this);
|
||||
set_value(T(0));
|
||||
|
||||
for (int i=0; i < 4; i++)
|
||||
for (int j=0; j < 4; j++)
|
||||
for (int c=0; c < 4; c++)
|
||||
{
|
||||
element(i,j) += mt(i,c) * rhs(c,j);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend matrix4 operator * (const matrix4 &lhs, const matrix4 &rhs)
|
||||
{
|
||||
matrix4 r(T(0));
|
||||
|
||||
for (int i=0; i < 4; i++)
|
||||
for (int j=0; j < 4; j++)
|
||||
for (int c=0; c < 4; c++)
|
||||
{
|
||||
r.element(i,j) += lhs(i,c) * rhs(c,j);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// dst = M * src
|
||||
vec4<T> operator *(const vec4<T> &src) const
|
||||
{
|
||||
vec4<T> r;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
r[i] = (src[0] * element(i,0) + src[1] * element(i,1) +
|
||||
src[2] * element(i,2) + src[3] * element(i,3));
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// dst = src * M
|
||||
friend vec4<T> operator *(const vec4<T> &lhs, const matrix4 &rhs)
|
||||
{
|
||||
vec4<T> r;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
r[i] = (lhs[0] * rhs.element(0,i) + lhs[1] * rhs.element(1,i) +
|
||||
lhs[2] * rhs.element(2,i) + lhs[3] * rhs.element(3,i));
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
T &operator()(int row, int col)
|
||||
{
|
||||
return element(row,col);
|
||||
}
|
||||
|
||||
const T &operator()(int row, int col) const
|
||||
{
|
||||
return element(row,col);
|
||||
}
|
||||
|
||||
T &element(int row, int col)
|
||||
{
|
||||
return _array[row | (col<<2)];
|
||||
}
|
||||
|
||||
const T &element(int row, int col) const
|
||||
{
|
||||
return _array[row | (col<<2)];
|
||||
}
|
||||
|
||||
matrix4 &operator *= (const T &r)
|
||||
{
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
element(0,i) *= r;
|
||||
element(1,i) *= r;
|
||||
element(2,i) *= r;
|
||||
element(3,i) *= r;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
matrix4 &operator += (const matrix4 &mat)
|
||||
{
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
element(0,i) += mat.element(0,i);
|
||||
element(1,i) += mat.element(1,i);
|
||||
element(2,i) += mat.element(2,i);
|
||||
element(3,i) += mat.element(3,i);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
friend bool operator == (const matrix4 &lhs, const matrix4 &rhs)
|
||||
{
|
||||
bool r = true;
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
r &= lhs._array[i] == rhs._array[i];
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
friend bool operator != (const matrix4 &lhs, const matrix4 &rhs)
|
||||
{
|
||||
bool r = true;
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
r &= lhs._array[i] != rhs._array[i];
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
T _11, _12, _13, _14; // standard names for components
|
||||
T _21, _22, _23, _24; // standard names for components
|
||||
T _31, _32, _33, _34; // standard names for components
|
||||
T _41, _42, _43, _44; // standard names for components
|
||||
};
|
||||
T _array[16]; // array access
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
530
Common/nvQuaternion.h
Normal file
530
Common/nvQuaternion.h
Normal file
@@ -0,0 +1,530 @@
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
//
|
||||
// Template math library for common 3D functionality
|
||||
//
|
||||
// nvQuaterion.h - quaternion template and utility functions
|
||||
//
|
||||
// This code is in part deriver from glh, a cross platform glut helper library.
|
||||
// The copyright for glh follows this notice.
|
||||
//
|
||||
// Copyright (c) NVIDIA Corporation. All rights reserved.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
Copyright (c) 2000 Cass Everitt
|
||||
Copyright (c) 2000 NVIDIA Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or
|
||||
without modification, are permitted provided that the following
|
||||
conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
* The names of contributors to this software may not be used
|
||||
to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Cass Everitt - cass@r3.nu
|
||||
*/
|
||||
#ifndef NV_QUATERNION_H
|
||||
#define NV_QUATERNION_H
|
||||
|
||||
namespace nv
|
||||
{
|
||||
|
||||
template <class T> class vec2;
|
||||
template <class T> class vec3;
|
||||
template <class T> class vec4;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Quaternion
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template< class T>
|
||||
class quaternion
|
||||
{
|
||||
public:
|
||||
|
||||
quaternion() : x(0.0), y(0.0), z(0.0), w(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
quaternion(const T v[4])
|
||||
{
|
||||
set_value(v);
|
||||
}
|
||||
|
||||
|
||||
quaternion(T q0, T q1, T q2, T q3)
|
||||
{
|
||||
set_value(q0, q1, q2, q3);
|
||||
}
|
||||
|
||||
|
||||
quaternion(const matrix4<T> &m)
|
||||
{
|
||||
set_value(m);
|
||||
}
|
||||
|
||||
|
||||
quaternion(const vec3<T> &axis, T radians)
|
||||
{
|
||||
set_value(axis, radians);
|
||||
}
|
||||
|
||||
|
||||
quaternion(const vec3<T> &rotateFrom, const vec3<T> &rotateTo)
|
||||
{
|
||||
set_value(rotateFrom, rotateTo);
|
||||
}
|
||||
|
||||
quaternion(const vec3<T> &from_look, const vec3<T> &from_up,
|
||||
const vec3<T> &to_look, const vec3<T> &to_up)
|
||||
{
|
||||
set_value(from_look, from_up, to_look, to_up);
|
||||
}
|
||||
|
||||
const T *get_value() const
|
||||
{
|
||||
return &_array[0];
|
||||
}
|
||||
|
||||
void get_value(T &q0, T &q1, T &q2, T &q3) const
|
||||
{
|
||||
q0 = _array[0];
|
||||
q1 = _array[1];
|
||||
q2 = _array[2];
|
||||
q3 = _array[3];
|
||||
}
|
||||
|
||||
quaternion &set_value(T q0, T q1, T q2, T q3)
|
||||
{
|
||||
_array[0] = q0;
|
||||
_array[1] = q1;
|
||||
_array[2] = q2;
|
||||
_array[3] = q3;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void get_value(vec3<T> &axis, T &radians) const
|
||||
{
|
||||
radians = T(acos(_array[3]) * T(2.0));
|
||||
|
||||
if (radians == T(0.0))
|
||||
{
|
||||
axis = vec3<T>(0.0, 0.0, 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
axis[0] = _array[0];
|
||||
axis[1] = _array[1];
|
||||
axis[2] = _array[2];
|
||||
axis = normalize(axis);
|
||||
}
|
||||
}
|
||||
|
||||
void get_value(matrix4<T> &m) const
|
||||
{
|
||||
T s, xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz;
|
||||
|
||||
T norm = _array[0] * _array[0] + _array[1] * _array[1] + _array[2] * _array[2] + _array[3] * _array[3];
|
||||
|
||||
s = (norm == T(0.0)) ? T(0.0) : (T(2.0) / norm);
|
||||
|
||||
xs = _array[0] * s;
|
||||
ys = _array[1] * s;
|
||||
zs = _array[2] * s;
|
||||
|
||||
wx = _array[3] * xs;
|
||||
wy = _array[3] * ys;
|
||||
wz = _array[3] * zs;
|
||||
|
||||
xx = _array[0] * xs;
|
||||
xy = _array[0] * ys;
|
||||
xz = _array[0] * zs;
|
||||
|
||||
yy = _array[1] * ys;
|
||||
yz = _array[1] * zs;
|
||||
zz = _array[2] * zs;
|
||||
|
||||
m(0,0) = T(T(1.0) - (yy + zz));
|
||||
m(1,0) = T(xy + wz);
|
||||
m(2,0) = T(xz - wy);
|
||||
|
||||
m(0,1) = T(xy - wz);
|
||||
m(1,1) = T(T(1.0) - (xx + zz));
|
||||
m(2,1) = T(yz + wx);
|
||||
|
||||
m(0,2) = T(xz + wy);
|
||||
m(1,2) = T(yz - wx);
|
||||
m(2,2) = T(T(1.0) - (xx + yy));
|
||||
|
||||
m(3,0) = m(3,1) = m(3,2) = m(0,3) = m(1,3) = m(2,3) = T(0.0);
|
||||
m(3,3) = T(1.0);
|
||||
}
|
||||
|
||||
quaternion &set_value(const T *qp)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
_array[i] = qp[i];
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
quaternion &set_value(const matrix4<T> &m)
|
||||
{
|
||||
T tr, s;
|
||||
int i, j, k;
|
||||
const int nxt[3] = { 1, 2, 0 };
|
||||
|
||||
tr = m(0,0) + m(1,1) + m(2,2);
|
||||
|
||||
if (tr > T(0))
|
||||
{
|
||||
s = T(sqrt(tr + m(3,3)));
|
||||
_array[3] = T(s * 0.5);
|
||||
s = T(0.5) / s;
|
||||
|
||||
_array[0] = T((m(1,2) - m(2,1)) * s);
|
||||
_array[1] = T((m(2,0) - m(0,2)) * s);
|
||||
_array[2] = T((m(0,1) - m(1,0)) * s);
|
||||
}
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
|
||||
if (m(1,1) > m(0,0))
|
||||
{
|
||||
i = 1;
|
||||
}
|
||||
|
||||
if (m(2,2) > m(i,i))
|
||||
{
|
||||
i = 2;
|
||||
}
|
||||
|
||||
j = nxt[i];
|
||||
k = nxt[j];
|
||||
|
||||
s = T(sqrt((m(i,j) - (m(j,j) + m(k,k))) + T(1.0)));
|
||||
|
||||
_array[i] = T(s * 0.5);
|
||||
s = T(0.5 / s);
|
||||
|
||||
_array[3] = T((m(j,k) - m(k,j)) * s);
|
||||
_array[j] = T((m(i,j) + m(j,i)) * s);
|
||||
_array[k] = T((m(i,k) + m(k,i)) * s);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
quaternion &set_value(const vec3<T> &axis, T theta)
|
||||
{
|
||||
T sqnorm = square_norm(axis);
|
||||
|
||||
if (sqnorm == T(0.0))
|
||||
{
|
||||
// axis too small.
|
||||
x = y = z = T(0.0);
|
||||
w = T(1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
theta *= T(0.5);
|
||||
T sin_theta = T(sin(theta));
|
||||
|
||||
if (sqnorm != T(1))
|
||||
{
|
||||
sin_theta /= T(sqrt(sqnorm));
|
||||
}
|
||||
|
||||
x = sin_theta * axis[0];
|
||||
y = sin_theta * axis[1];
|
||||
z = sin_theta * axis[2];
|
||||
w = T(cos(theta));
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
quaternion &set_value(const vec3<T> &rotateFrom, const vec3<T> &rotateTo)
|
||||
{
|
||||
vec3<T> p1, p2;
|
||||
T alpha;
|
||||
|
||||
p1 = normalize(rotateFrom);
|
||||
p2 = normalize(rotateTo);
|
||||
|
||||
alpha = dot(p1, p2);
|
||||
|
||||
if (alpha == T(1.0))
|
||||
{
|
||||
*this = quaternion();
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ensures that the anti-parallel case leads to a positive dot
|
||||
if (alpha == T(-1.0))
|
||||
{
|
||||
vec3<T> v;
|
||||
|
||||
if (p1[0] != p1[1] || p1[0] != p1[2])
|
||||
{
|
||||
v = vec3<T>(p1[1], p1[2], p1[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
v = vec3<T>(-p1[0], p1[1], p1[2]);
|
||||
}
|
||||
|
||||
v -= p1 * dot(p1, v);
|
||||
v = normalize(v);
|
||||
|
||||
set_value(v, T(3.1415926));
|
||||
return *this;
|
||||
}
|
||||
|
||||
p1 = normalize(cross(p1, p2));
|
||||
|
||||
set_value(p1,T(acos(alpha)));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
quaternion &set_value(const vec3<T> &from_look, const vec3<T> &from_up,
|
||||
const vec3<T> &to_look, const vec3<T> &to_up)
|
||||
{
|
||||
quaternion r_look = quaternion(from_look, to_look);
|
||||
|
||||
vec3<T> rotated_from_up(from_up);
|
||||
r_look.mult_vec(rotated_from_up);
|
||||
|
||||
quaternion r_twist = quaternion(rotated_from_up, to_up);
|
||||
|
||||
*this = r_twist;
|
||||
*this *= r_look;
|
||||
return *this;
|
||||
}
|
||||
|
||||
quaternion &operator *= (const quaternion<T> &qr)
|
||||
{
|
||||
quaternion ql(*this);
|
||||
|
||||
w = ql.w * qr.w - ql.x * qr.x - ql.y * qr.y - ql.z * qr.z;
|
||||
x = ql.w * qr.x + ql.x * qr.w + ql.y * qr.z - ql.z * qr.y;
|
||||
y = ql.w * qr.y + ql.y * qr.w + ql.z * qr.x - ql.x * qr.z;
|
||||
z = ql.w * qr.z + ql.z * qr.w + ql.x * qr.y - ql.y * qr.x;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend quaternion normalize(const quaternion<T> &q)
|
||||
{
|
||||
quaternion r(q);
|
||||
T rnorm = T(1.0) / T(sqrt(q.w * q.w + q.x * q.x + q.y * q.y + q.z * q.z));
|
||||
|
||||
r.x *= rnorm;
|
||||
r.y *= rnorm;
|
||||
r.z *= rnorm;
|
||||
r.w *= rnorm;
|
||||
}
|
||||
|
||||
friend quaternion<T> conjugate(const quaternion<T> &q)
|
||||
{
|
||||
quaternion<T> r(q);
|
||||
r._array[0] *= T(-1.0);
|
||||
r._array[1] *= T(-1.0);
|
||||
r._array[2] *= T(-1.0);
|
||||
return r;
|
||||
}
|
||||
|
||||
friend quaternion<T> inverse(const quaternion<T> &q)
|
||||
{
|
||||
return conjugate(q);
|
||||
}
|
||||
|
||||
//
|
||||
// Quaternion multiplication with cartesian vector
|
||||
// v' = q*v*q(star)
|
||||
//
|
||||
void mult_vec(const vec3<T> &src, vec3<T> &dst) const
|
||||
{
|
||||
T v_coef = w * w - x * x - y * y - z * z;
|
||||
T u_coef = T(2.0) * (src[0] * x + src[1] * y + src[2] * z);
|
||||
T c_coef = T(2.0) * w;
|
||||
|
||||
dst.v[0] = v_coef * src.v[0] + u_coef * x + c_coef * (y * src.v[2] - z * src.v[1]);
|
||||
dst.v[1] = v_coef * src.v[1] + u_coef * y + c_coef * (z * src.v[0] - x * src.v[2]);
|
||||
dst.v[2] = v_coef * src.v[2] + u_coef * z + c_coef * (x * src.v[1] - y * src.v[0]);
|
||||
}
|
||||
|
||||
void mult_vec(vec3<T> &src_and_dst) const
|
||||
{
|
||||
mult_vec(vec3<T>(src_and_dst), src_and_dst);
|
||||
}
|
||||
|
||||
void scale_angle(T scaleFactor)
|
||||
{
|
||||
vec3<T> axis;
|
||||
T radians;
|
||||
|
||||
get_value(axis, radians);
|
||||
radians *= scaleFactor;
|
||||
set_value(axis, radians);
|
||||
}
|
||||
|
||||
friend quaternion<T> slerp(const quaternion<T> &p, const quaternion<T> &q, T alpha)
|
||||
{
|
||||
quaternion r;
|
||||
|
||||
T cos_omega = p.x * q.x + p.y * q.y + p.z * q.z + p.w * q.w;
|
||||
// if B is on opposite hemisphere from A, use -B instead
|
||||
|
||||
int bflip;
|
||||
|
||||
if ((bflip = (cos_omega < T(0))))
|
||||
{
|
||||
cos_omega = -cos_omega;
|
||||
}
|
||||
|
||||
// complementary interpolation parameter
|
||||
T beta = T(1) - alpha;
|
||||
|
||||
if (cos_omega >= T(1))
|
||||
{
|
||||
return p;
|
||||
}
|
||||
|
||||
T omega = T(acos(cos_omega));
|
||||
T one_over_sin_omega = T(1.0) / T(sin(omega));
|
||||
|
||||
beta = T(sin(omega*beta) * one_over_sin_omega);
|
||||
alpha = T(sin(omega*alpha) * one_over_sin_omega);
|
||||
|
||||
if (bflip)
|
||||
{
|
||||
alpha = -alpha;
|
||||
}
|
||||
|
||||
r.x = beta * p._array[0]+ alpha * q._array[0];
|
||||
r.y = beta * p._array[1]+ alpha * q._array[1];
|
||||
r.z = beta * p._array[2]+ alpha * q._array[2];
|
||||
r.w = beta * p._array[3]+ alpha * q._array[3];
|
||||
return r;
|
||||
}
|
||||
|
||||
T &operator [](int i)
|
||||
{
|
||||
return _array[i];
|
||||
}
|
||||
|
||||
const T &operator [](int i) const
|
||||
{
|
||||
return _array[i];
|
||||
}
|
||||
|
||||
|
||||
friend bool operator == (const quaternion<T> &lhs, const quaternion<T> &rhs)
|
||||
{
|
||||
bool r = true;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
r &= lhs._array[i] == rhs._array[i];
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
friend bool operator != (const quaternion<T> &lhs, const quaternion<T> &rhs)
|
||||
{
|
||||
bool r = true;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
r &= lhs._array[i] == rhs._array[i];
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
friend quaternion<T> operator * (const quaternion<T> &lhs, const quaternion<T> &rhs)
|
||||
{
|
||||
quaternion r(lhs);
|
||||
r *= rhs;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
T w;
|
||||
};
|
||||
T _array[4];
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
260
Common/nvShaderUtils.h
Normal file
260
Common/nvShaderUtils.h
Normal file
@@ -0,0 +1,260 @@
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Utility functions for compiling shaders and programs
|
||||
*
|
||||
* Author: Evan Hart
|
||||
* Copyright (c) NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NV_SHADER_UTILS_H
|
||||
#define NV_SHADER_UTILS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace nv {
|
||||
|
||||
//
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
inline GLuint CompileGLSLShader(GLenum target, const char *shader) {
|
||||
GLuint object;
|
||||
|
||||
object = glCreateShader(target);
|
||||
|
||||
if (!object) {
|
||||
return object;
|
||||
}
|
||||
|
||||
glShaderSource(object, 1, &shader, NULL);
|
||||
|
||||
glCompileShader(object);
|
||||
|
||||
// check if shader compiled
|
||||
GLint compiled = 0;
|
||||
glGetShaderiv(object, GL_COMPILE_STATUS, &compiled);
|
||||
|
||||
if (!compiled) {
|
||||
#ifdef NV_REPORT_COMPILE_ERRORS
|
||||
char temp[256] = "";
|
||||
glGetShaderInfoLog(object, 256, NULL, temp);
|
||||
fprintf(stderr, "Compile failed:\n%s\n", temp);
|
||||
#endif
|
||||
glDeleteShader(object);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
inline GLuint CompileGLSLShaderFromFile(GLenum target, const char *filename) {
|
||||
FILE *shaderFile;
|
||||
char *text;
|
||||
long size;
|
||||
size_t fsize = 0;
|
||||
|
||||
// read files as binary to prevent problems from newline translation
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
|
||||
|
||||
if (fopen_s(&shaderFile, filename, "rb") != 0)
|
||||
#else
|
||||
if ((shaderFile = fopen(filename, "rb")) == 0)
|
||||
#endif
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get the length of the file
|
||||
fseek(shaderFile, 0, SEEK_END);
|
||||
size = ftell(shaderFile);
|
||||
|
||||
// Read the file contents from the start, then close file and add a null
|
||||
// terminator
|
||||
fseek(shaderFile, 0, SEEK_SET);
|
||||
text = new char[size + 1];
|
||||
fsize = fread(text, size, 1, shaderFile);
|
||||
fclose(shaderFile);
|
||||
|
||||
if (fsize == 0) {
|
||||
printf("CompileGLSLShaderFromFile(), error... fsize = 0\n");
|
||||
}
|
||||
|
||||
text[size] = '\0';
|
||||
|
||||
GLuint object = CompileGLSLShader(target, text);
|
||||
|
||||
delete[] text;
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
// Create a program composed of vertex and fragment shaders.
|
||||
inline GLuint LinkGLSLProgram(GLuint vertexShader, GLuint fragmentShader) {
|
||||
GLuint program = glCreateProgram();
|
||||
glAttachShader(program, vertexShader);
|
||||
glAttachShader(program, fragmentShader);
|
||||
glLinkProgram(program);
|
||||
|
||||
#ifdef NV_REPORT_COMPILE_ERRORS
|
||||
// Get error log.
|
||||
GLint charsWritten, infoLogLength;
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
|
||||
char *infoLog = new char[infoLogLength];
|
||||
glGetProgramInfoLog(program, infoLogLength, &charsWritten, infoLog);
|
||||
printf(infoLog);
|
||||
delete[] infoLog;
|
||||
#endif
|
||||
|
||||
// Test linker result.
|
||||
GLint linkSucceed = GL_FALSE;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &linkSucceed);
|
||||
|
||||
if (linkSucceed == GL_FALSE) {
|
||||
glDeleteProgram(program);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
// Create a program composed of vertex, geometry and fragment shaders.
|
||||
inline GLuint LinkGLSLProgram(GLuint vertexShader, GLuint geometryShader,
|
||||
GLint inputType, GLint vertexOut,
|
||||
GLint outputType, GLuint fragmentShader) {
|
||||
GLuint program = glCreateProgram();
|
||||
glAttachShader(program, vertexShader);
|
||||
glAttachShader(program, geometryShader);
|
||||
glProgramParameteriEXT(program, GL_GEOMETRY_INPUT_TYPE_EXT, inputType);
|
||||
glProgramParameteriEXT(program, GL_GEOMETRY_VERTICES_OUT_EXT, vertexOut);
|
||||
glProgramParameteriEXT(program, GL_GEOMETRY_OUTPUT_TYPE_EXT, outputType);
|
||||
glAttachShader(program, fragmentShader);
|
||||
glLinkProgram(program);
|
||||
|
||||
#ifdef NV_REPORT_COMPILE_ERRORS
|
||||
// Get error log.
|
||||
GLint charsWritten, infoLogLength;
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
|
||||
char *infoLog = new char[infoLogLength];
|
||||
glGetProgramInfoLog(program, infoLogLength, &charsWritten, infoLog);
|
||||
printf(infoLog);
|
||||
delete[] infoLog;
|
||||
#endif
|
||||
|
||||
// Test linker result.
|
||||
GLint linkSucceed = GL_FALSE;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &linkSucceed);
|
||||
|
||||
if (linkSucceed == GL_FALSE) {
|
||||
glDeleteProgram(program);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
inline GLuint CompileASMShader(GLenum program_type, const char *code) {
|
||||
GLuint program_id;
|
||||
glGenProgramsARB(1, &program_id);
|
||||
glBindProgramARB(program_type, program_id);
|
||||
glProgramStringARB(program_type, GL_PROGRAM_FORMAT_ASCII_ARB,
|
||||
(GLsizei)strlen(code), (GLubyte *)code);
|
||||
|
||||
GLint error_pos;
|
||||
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos);
|
||||
|
||||
if (error_pos != -1) {
|
||||
#ifdef NV_REPORT_COMPILE_ERRORS
|
||||
const GLubyte *error_string;
|
||||
error_string = glGetString(GL_PROGRAM_ERROR_STRING_ARB);
|
||||
fprintf(stderr, "Program error at position: %d\n%s\n", (int)error_pos,
|
||||
error_string);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
return program_id;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
inline GLuint CompileASMShaderFromFile(GLenum target, const char *filename) {
|
||||
FILE *shaderFile;
|
||||
char *text;
|
||||
long size;
|
||||
size_t fsize = 0;
|
||||
|
||||
// read files as binary to prevent problems from newline translation
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
|
||||
|
||||
if (fopen_s(&shaderFile, filename, "rb") != 0)
|
||||
#else
|
||||
if ((shaderFile = fopen(filename, "rb")) == 0)
|
||||
#endif
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get the length of the file
|
||||
fseek(shaderFile, 0, SEEK_END);
|
||||
size = ftell(shaderFile);
|
||||
|
||||
// Read the file contents from the start, then close file and add a null
|
||||
// terminator
|
||||
fseek(shaderFile, 0, SEEK_SET);
|
||||
text = new char[size + 1];
|
||||
fsize = fread(text, size, 1, shaderFile);
|
||||
fclose(shaderFile);
|
||||
|
||||
if (fsize == 0) {
|
||||
printf("CompileGLSLShaderFromFile(), error... fsize = 0\n");
|
||||
}
|
||||
|
||||
text[size] = '\0';
|
||||
|
||||
GLuint program_id = CompileASMShader(target, text);
|
||||
|
||||
delete[] text;
|
||||
|
||||
return program_id;
|
||||
}
|
||||
|
||||
} // namespace nv
|
||||
#endif
|
||||
1074
Common/nvVector.h
Normal file
1074
Common/nvVector.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -49,6 +49,11 @@
|
||||
|
||||
void compileFileToCUBIN(char *filename, int argc, char **argv, char **cubinResult,
|
||||
size_t *cubinResultSize, int requiresCGheaders) {
|
||||
if (!filename) {
|
||||
std::cerr << "\nerror: filename is empty for compileFileToCUBIN()!\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::ifstream inputFile(filename,
|
||||
std::ios::in | std::ios::binary | std::ios::ate);
|
||||
|
||||
@@ -111,7 +116,12 @@ void compileFileToCUBIN(char *filename, int argc, char **argv, char **cubinResul
|
||||
|
||||
compileOptions = "--include-path=";
|
||||
|
||||
std::string path = sdkFindFilePath(HeaderNames, argv[0]);
|
||||
char *strPath = sdkFindFilePath(HeaderNames, argv[0]);
|
||||
if (!strPath) {
|
||||
std::cerr << "\nerror: header file " << HeaderNames << " not found!\n";
|
||||
exit(1);
|
||||
}
|
||||
std::string path = strPath;
|
||||
if (!path.empty()) {
|
||||
std::size_t found = path.find(HeaderNames);
|
||||
path.erase(found);
|
||||
@@ -120,6 +130,7 @@ void compileFileToCUBIN(char *filename, int argc, char **argv, char **cubinResul
|
||||
"\nCooperativeGroups headers not found, please install it in %s "
|
||||
"sample directory..\n Exiting..\n",
|
||||
argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
compileOptions += path.c_str();
|
||||
compileParams[numCompileOptions] = reinterpret_cast<char *>(
|
||||
@@ -176,6 +187,7 @@ CUmodule loadCUBIN(char *cubin, int argc, char **argv) {
|
||||
CUcontext context;
|
||||
int major = 0, minor = 0;
|
||||
char deviceName[256];
|
||||
CUctxCreateParams ctxCreateParams = {};
|
||||
|
||||
// Picks the best CUDA device available
|
||||
CUdevice cuDevice = findCudaDeviceDRV(argc, (const char **)argv);
|
||||
@@ -189,7 +201,7 @@ CUmodule loadCUBIN(char *cubin, int argc, char **argv) {
|
||||
printf("> GPU Device has SM %d.%d compute capability\n", major, minor);
|
||||
|
||||
checkCudaErrors(cuInit(0));
|
||||
checkCudaErrors(cuCtxCreate(&context, 0, cuDevice));
|
||||
checkCudaErrors(cuCtxCreate(&context, &ctxCreateParams, 0, cuDevice));
|
||||
|
||||
checkCudaErrors(cuModuleLoadData(&module, cubin));
|
||||
free(cubin);
|
||||
|
||||
236
Common/param.h
Normal file
236
Common/param.h
Normal file
@@ -0,0 +1,236 @@
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
Simple parameter system
|
||||
sgreen@nvidia.com 4/2001
|
||||
*/
|
||||
|
||||
#ifndef PARAM_H
|
||||
#define PARAM_H
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// base class for named parameter
|
||||
class ParamBase {
|
||||
public:
|
||||
ParamBase(const char *name) : m_name(name) {}
|
||||
virtual ~ParamBase() {}
|
||||
|
||||
std::string &GetName() { return m_name; }
|
||||
|
||||
virtual float GetFloatValue() = 0;
|
||||
virtual int GetIntValue() = 0;
|
||||
virtual std::string GetValueString() = 0;
|
||||
|
||||
virtual void Reset() = 0;
|
||||
virtual void Increment() = 0;
|
||||
virtual void Decrement() = 0;
|
||||
|
||||
virtual float GetPercentage() = 0;
|
||||
virtual void SetPercentage(float p) = 0;
|
||||
|
||||
virtual void Write(std::ostream &stream) = 0;
|
||||
virtual void Read(std::istream &stream) = 0;
|
||||
|
||||
virtual bool IsList() = 0;
|
||||
|
||||
protected:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
// derived class for single-valued parameter
|
||||
template <class T>
|
||||
class Param : public ParamBase {
|
||||
public:
|
||||
Param(const char *name, T value = 0, T min = 0, T max = 10000, T step = 1,
|
||||
T *ptr = 0)
|
||||
: ParamBase(name),
|
||||
m_default(value),
|
||||
m_min(min),
|
||||
m_max(max),
|
||||
m_step(step),
|
||||
m_precision(3) {
|
||||
if (ptr) {
|
||||
m_ptr = ptr;
|
||||
} else {
|
||||
m_ptr = &m_value;
|
||||
}
|
||||
|
||||
*m_ptr = value;
|
||||
}
|
||||
~Param() {}
|
||||
|
||||
T GetValue() const { return *m_ptr; }
|
||||
T SetValue(const T value) { *m_ptr = value; }
|
||||
|
||||
float GetFloatValue() { return (float)*m_ptr; }
|
||||
int GetIntValue() { return (int)*m_ptr; }
|
||||
|
||||
std::string GetValueString() {
|
||||
std::ostringstream ost;
|
||||
ost << std::setprecision(m_precision) << std::fixed;
|
||||
ost << *m_ptr;
|
||||
return ost.str();
|
||||
}
|
||||
|
||||
void SetPrecision(int x) { m_precision = x; }
|
||||
|
||||
float GetPercentage() { return (*m_ptr - m_min) / (float)(m_max - m_min); }
|
||||
|
||||
void SetPercentage(float p) { *m_ptr = (T)(m_min + p * (m_max - m_min)); }
|
||||
|
||||
void Reset() { *m_ptr = m_default; }
|
||||
|
||||
void Increment() {
|
||||
*m_ptr += m_step;
|
||||
|
||||
if (*m_ptr > m_max) {
|
||||
*m_ptr = m_max;
|
||||
}
|
||||
}
|
||||
|
||||
void Decrement() {
|
||||
*m_ptr -= m_step;
|
||||
|
||||
if (*m_ptr < m_min) {
|
||||
*m_ptr = m_min;
|
||||
}
|
||||
}
|
||||
|
||||
void Write(std::ostream &stream) {
|
||||
stream << m_name << " " << *m_ptr << '\n';
|
||||
}
|
||||
void Read(std::istream &stream) { stream >> m_name >> *m_ptr; }
|
||||
|
||||
bool IsList() { return false; }
|
||||
|
||||
private:
|
||||
T m_value;
|
||||
T *m_ptr; // pointer to value declared elsewhere
|
||||
T m_default, m_min, m_max, m_step;
|
||||
int m_precision; // number of digits after decimal point in string output
|
||||
};
|
||||
|
||||
const Param<int> dummy("error");
|
||||
|
||||
// list of parameters
|
||||
class ParamList : public ParamBase {
|
||||
public:
|
||||
ParamList(const char *name = "") : ParamBase(name) { active = true; }
|
||||
~ParamList() {}
|
||||
|
||||
float GetFloatValue() { return 0.0f; }
|
||||
int GetIntValue() { return 0; }
|
||||
|
||||
void AddParam(ParamBase *param) {
|
||||
m_params.push_back(param);
|
||||
m_map[param->GetName()] = param;
|
||||
m_current = m_params.begin();
|
||||
}
|
||||
|
||||
// look-up parameter based on name
|
||||
ParamBase *GetParam(char *name) {
|
||||
ParamBase *p = m_map[name];
|
||||
|
||||
if (p) {
|
||||
return p;
|
||||
} else {
|
||||
return (ParamBase *)&dummy;
|
||||
}
|
||||
}
|
||||
|
||||
ParamBase *GetParam(int i) { return m_params[i]; }
|
||||
|
||||
ParamBase *GetCurrent() { return *m_current; }
|
||||
|
||||
int GetSize() { return (int)m_params.size(); }
|
||||
|
||||
std::string GetValueString() { return m_name; }
|
||||
|
||||
// functions to traverse list
|
||||
void Reset() { m_current = m_params.begin(); }
|
||||
|
||||
void Increment() {
|
||||
m_current++;
|
||||
|
||||
if (m_current == m_params.end()) {
|
||||
m_current = m_params.begin();
|
||||
}
|
||||
}
|
||||
|
||||
void Decrement() {
|
||||
if (m_current == m_params.begin()) {
|
||||
m_current = m_params.end() - 1;
|
||||
} else {
|
||||
m_current--;
|
||||
}
|
||||
}
|
||||
|
||||
float GetPercentage() { return 0.0f; }
|
||||
void SetPercentage(float /*p*/) {}
|
||||
|
||||
void Write(std::ostream &stream) {
|
||||
stream << m_name << '\n';
|
||||
|
||||
for (std::vector<ParamBase *>::const_iterator p = m_params.begin();
|
||||
p != m_params.end(); ++p) {
|
||||
(*p)->Write(stream);
|
||||
}
|
||||
}
|
||||
|
||||
void Read(std::istream &stream) {
|
||||
stream >> m_name;
|
||||
|
||||
for (std::vector<ParamBase *>::const_iterator p = m_params.begin();
|
||||
p != m_params.end(); ++p) {
|
||||
(*p)->Read(stream);
|
||||
}
|
||||
}
|
||||
|
||||
bool IsList() { return true; }
|
||||
|
||||
void ResetAll() {
|
||||
for (std::vector<ParamBase *>::const_iterator p = m_params.begin();
|
||||
p != m_params.end(); ++p) {
|
||||
(*p)->Reset();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
bool active;
|
||||
std::vector<ParamBase *> m_params;
|
||||
std::map<std::string, ParamBase *> m_map;
|
||||
std::vector<ParamBase *>::const_iterator m_current;
|
||||
};
|
||||
|
||||
#endif
|
||||
307
Common/paramgl.h
Normal file
307
Common/paramgl.h
Normal file
@@ -0,0 +1,307 @@
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
ParamListGL
|
||||
- class derived from ParamList to do simple OpenGL rendering of a parameter
|
||||
list sgg 8/2001
|
||||
*/
|
||||
|
||||
#ifndef PARAMGL_H
|
||||
#define PARAMGL_H
|
||||
|
||||
#if defined(__APPLE__) || defined(MACOSX)
|
||||
#include <GLUT/glut.h>
|
||||
#else
|
||||
#include <GL/freeglut.h>
|
||||
#endif
|
||||
|
||||
#include <param.h>
|
||||
#include <string.h>
|
||||
|
||||
inline void beginWinCoords(void) {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.0, (GLfloat)(glutGet(GLUT_WINDOW_HEIGHT) - 1.0), 0.0);
|
||||
glScalef(1.0, -1.0, 1.0);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho(0, glutGet(GLUT_WINDOW_WIDTH), 0, glutGet(GLUT_WINDOW_HEIGHT), -1, 1);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
|
||||
inline void endWinCoords(void) {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
inline void glPrint(int x, int y, const char *s, void *font) {
|
||||
glRasterPos2f((GLfloat)x, (GLfloat)y);
|
||||
int len = (int)strlen(s);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
glutBitmapCharacter(font, s[i]);
|
||||
}
|
||||
}
|
||||
|
||||
inline void glPrintShadowed(int x, int y, const char *s, void *font,
|
||||
float *color) {
|
||||
glColor3f(0.0, 0.0, 0.0);
|
||||
glPrint(x - 1, y - 1, s, font);
|
||||
|
||||
glColor3fv((GLfloat *)color);
|
||||
glPrint(x, y, s, font);
|
||||
}
|
||||
|
||||
class ParamListGL : public ParamList {
|
||||
public:
|
||||
ParamListGL(const char *name = "")
|
||||
: ParamList(name),
|
||||
m_active(true),
|
||||
m_text_color_selected(1.0, 1.0, 1.0),
|
||||
m_text_color_unselected(0.75, 0.75, 0.75),
|
||||
m_text_color_shadow(0.0, 0.0, 0.0),
|
||||
m_bar_color_outer(0.25, 0.25, 0.25),
|
||||
m_bar_color_inner(1.0, 1.0, 1.0) {
|
||||
m_font = (void *)GLUT_BITMAP_9_BY_15; // GLUT_BITMAP_8_BY_13;
|
||||
m_font_h = 15;
|
||||
m_bar_x = 260;
|
||||
m_bar_w = 250;
|
||||
m_bar_h = 10;
|
||||
m_bar_offset = 5;
|
||||
m_text_x = 5;
|
||||
m_separation = 15;
|
||||
m_value_x = 200;
|
||||
m_start_x = 0;
|
||||
m_start_y = 0;
|
||||
}
|
||||
|
||||
void Render(int x, int y, bool shadow = false) {
|
||||
beginWinCoords();
|
||||
|
||||
m_start_x = x;
|
||||
m_start_y = y;
|
||||
|
||||
for (std::vector<ParamBase *>::const_iterator p = m_params.begin();
|
||||
p != m_params.end(); ++p) {
|
||||
if ((*p)->IsList()) {
|
||||
ParamListGL *list = (ParamListGL *)(*p);
|
||||
list->Render(x + 10, y);
|
||||
y += m_separation * list->GetSize();
|
||||
} else {
|
||||
if (p == m_current) {
|
||||
glColor3fv(&m_text_color_selected.r);
|
||||
} else {
|
||||
glColor3fv(&m_text_color_unselected.r);
|
||||
}
|
||||
|
||||
if (shadow) {
|
||||
glPrintShadowed(x + m_text_x, y + m_font_h, (*p)->GetName().c_str(),
|
||||
m_font,
|
||||
(p == m_current) ? &m_text_color_selected.r
|
||||
: &m_text_color_unselected.r);
|
||||
glPrintShadowed(x + m_value_x, y + m_font_h,
|
||||
(*p)->GetValueString().c_str(), m_font,
|
||||
(p == m_current) ? &m_text_color_selected.r
|
||||
: &m_text_color_unselected.r);
|
||||
} else {
|
||||
glPrint(x + m_text_x, y + m_font_h, (*p)->GetName().c_str(), m_font);
|
||||
glPrint(x + m_value_x, y + m_font_h, (*p)->GetValueString().c_str(),
|
||||
m_font);
|
||||
}
|
||||
|
||||
glColor3fv((GLfloat *)&m_bar_color_outer.r);
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glVertex2f((GLfloat)(x + m_bar_x), (GLfloat)(y + m_bar_offset));
|
||||
glVertex2f((GLfloat)(x + m_bar_x + m_bar_w),
|
||||
(GLfloat)(y + m_bar_offset));
|
||||
glVertex2f((GLfloat)(x + m_bar_x + m_bar_w),
|
||||
(GLfloat)(y + m_bar_offset + m_bar_h));
|
||||
glVertex2f((GLfloat)(x + m_bar_x),
|
||||
(GLfloat)(y + m_bar_offset + m_bar_h));
|
||||
glEnd();
|
||||
|
||||
glColor3fv((GLfloat *)&m_bar_color_inner.r);
|
||||
glRectf(
|
||||
(GLfloat)(x + m_bar_x), (GLfloat)(y + m_bar_offset + m_bar_h),
|
||||
(GLfloat)(x + m_bar_x + ((m_bar_w - 1) * (*p)->GetPercentage())),
|
||||
(GLfloat)(y + m_bar_offset + 1));
|
||||
|
||||
y += m_separation;
|
||||
}
|
||||
}
|
||||
|
||||
endWinCoords();
|
||||
}
|
||||
|
||||
bool Mouse(int x, int y, int button = GLUT_LEFT_BUTTON,
|
||||
int state = GLUT_DOWN) {
|
||||
if ((y < m_start_y) ||
|
||||
(y > (int)(m_start_y + (m_separation * m_params.size()) - 1))) {
|
||||
m_active = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_active = true;
|
||||
|
||||
int i = (y - m_start_y) / m_separation;
|
||||
|
||||
if ((button == GLUT_LEFT_BUTTON) && (state == GLUT_DOWN)) {
|
||||
#if defined(__GNUC__) && (__GNUC__ < 3)
|
||||
m_current = &m_params[i];
|
||||
#else
|
||||
|
||||
// MJH: workaround since the version of vector::at used here is
|
||||
// non-standard
|
||||
for (m_current = m_params.begin(); m_current != m_params.end() && i > 0;
|
||||
m_current++, i--)
|
||||
;
|
||||
|
||||
// m_current = (std::vector<ParamBase
|
||||
// *>::const_iterator)&m_params.at(i);
|
||||
#endif
|
||||
|
||||
if ((x > m_bar_x) && (x < m_bar_x + m_bar_w)) {
|
||||
Motion(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Motion(int x, int y) {
|
||||
if ((y < m_start_y) ||
|
||||
(y > m_start_y + (m_separation * (int)m_params.size()) - 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x < m_bar_x) {
|
||||
(*m_current)->SetPercentage(0.0);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (x > m_bar_x + m_bar_w) {
|
||||
(*m_current)->SetPercentage(1.0);
|
||||
return true;
|
||||
}
|
||||
|
||||
(*m_current)->SetPercentage((x - m_bar_x) / (float)m_bar_w);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Special(int key, int x, int y) {
|
||||
if (!m_active) return;
|
||||
|
||||
switch (key) {
|
||||
case GLUT_KEY_DOWN:
|
||||
Increment();
|
||||
break;
|
||||
|
||||
case GLUT_KEY_UP:
|
||||
Decrement();
|
||||
break;
|
||||
|
||||
case GLUT_KEY_RIGHT:
|
||||
GetCurrent()->Increment();
|
||||
break;
|
||||
|
||||
case GLUT_KEY_LEFT:
|
||||
GetCurrent()->Decrement();
|
||||
break;
|
||||
|
||||
case GLUT_KEY_HOME:
|
||||
GetCurrent()->Reset();
|
||||
break;
|
||||
|
||||
case GLUT_KEY_END:
|
||||
GetCurrent()->SetPercentage(1.0);
|
||||
break;
|
||||
}
|
||||
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
void SetFont(void *font, int height) {
|
||||
m_font = font;
|
||||
m_font_h = height;
|
||||
}
|
||||
|
||||
void SetSelectedColor(float r, float g, float b) {
|
||||
m_text_color_selected = Color(r, g, b);
|
||||
}
|
||||
void SetUnSelectedColor(float r, float g, float b) {
|
||||
m_text_color_unselected = Color(r, g, b);
|
||||
}
|
||||
void SetBarColorInner(float r, float g, float b) {
|
||||
m_bar_color_inner = Color(r, g, b);
|
||||
}
|
||||
void SetBarColorOuter(float r, float g, float b) {
|
||||
m_bar_color_outer = Color(r, g, b);
|
||||
}
|
||||
|
||||
void SetActive(bool b) { m_active = b; }
|
||||
|
||||
private:
|
||||
void *m_font;
|
||||
int m_font_h; // font height
|
||||
|
||||
int m_bar_x; // bar start x position
|
||||
int m_bar_w; // bar width
|
||||
int m_bar_h; // bar height
|
||||
int m_text_x; // text start x position
|
||||
int m_separation; // bar separation in y
|
||||
int m_value_x; // value text x position
|
||||
int m_bar_offset; // bar offset in y
|
||||
|
||||
int m_start_x, m_start_y;
|
||||
|
||||
bool m_active;
|
||||
|
||||
struct Color {
|
||||
Color(float _r, float _g, float _b) {
|
||||
r = _r;
|
||||
g = _g;
|
||||
b = _b;
|
||||
}
|
||||
float r, g, b;
|
||||
};
|
||||
|
||||
Color m_text_color_selected;
|
||||
Color m_text_color_unselected;
|
||||
Color m_text_color_shadow;
|
||||
Color m_bar_color_outer;
|
||||
Color m_bar_color_inner;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
1347
Common/rendercheck_gl.h
Normal file
1347
Common/rendercheck_gl.h
Normal file
File diff suppressed because it is too large
Load Diff
1312
Common/rendercheck_gles.h
Normal file
1312
Common/rendercheck_gles.h
Normal file
File diff suppressed because it is too large
Load Diff
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
64
Makefile
64
Makefile
@@ -1,64 +0,0 @@
|
||||
###############################################################################
|
||||
#
|
||||
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
###############################################################################
|
||||
#
|
||||
# CUDA Samples
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
TARGET_ARCH ?= $(shell uname -m)
|
||||
|
||||
# Project folders that contain CUDA samples
|
||||
PROJECTS ?= $(shell find Samples -name Makefile)
|
||||
|
||||
FILTER_OUT :=
|
||||
|
||||
PROJECTS := $(filter-out $(FILTER_OUT),$(PROJECTS))
|
||||
|
||||
%.ph_build :
|
||||
+@$(MAKE) -C $(dir $*) $(MAKECMDGOALS)
|
||||
|
||||
%.ph_clean :
|
||||
+@$(MAKE) -C $(dir $*) clean $(USE_DEVICE)
|
||||
|
||||
%.ph_clobber :
|
||||
+@$(MAKE) -C $(dir $*) clobber $(USE_DEVICE)
|
||||
|
||||
all: $(addsuffix .ph_build,$(PROJECTS))
|
||||
@echo "Finished building CUDA samples"
|
||||
|
||||
build: $(addsuffix .ph_build,$(PROJECTS))
|
||||
|
||||
tidy:
|
||||
@find * | egrep "#" | xargs rm -f
|
||||
@find * | egrep "\~" | xargs rm -f
|
||||
|
||||
clean: tidy $(addsuffix .ph_clean,$(PROJECTS))
|
||||
|
||||
clobber: clean $(addsuffix .ph_clobber,$(PROJECTS))
|
||||
649
README.md
649
README.md
@@ -1,119 +1,20 @@
|
||||
# CUDA Samples
|
||||
|
||||
Samples for CUDA Developers which demonstrates features in CUDA Toolkit. This version supports [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads).
|
||||
Samples for CUDA Developers which demonstrates features in CUDA Toolkit. This version supports [CUDA Toolkit 13.3](https://developer.nvidia.com/cuda-downloads).
|
||||
|
||||
## Release Notes
|
||||
|
||||
This section describes the release notes for the CUDA Samples on GitHub only.
|
||||
|
||||
### CUDA 11.4
|
||||
* Added `cdpQuadtree`. Demonstrates Quad Trees implementation using CUDA Dynamic Parallelism.
|
||||
* Updated `simpleVulkan`, `simpleVulkanMMAP` and `vulkanImageCUDA`. Demonstrates use of SPIR-V shaders.
|
||||
### Change Log
|
||||
|
||||
### CUDA 11.3
|
||||
* Added `streamOrderedAllocationIPC`. Demonstrates Inter Process Communication using one process per GPU for computation.
|
||||
* Added `simpleCUBLAS_LU`. Demonstrates batched matrix LU decomposition using cuBLAS API `cublas<t>getrfBatched()`
|
||||
* Updated `simpleVulkan`. Demonstrates use of timeline semaphore.
|
||||
* Updated multiple samples to use pinned memory using `cudaMallocHost()`.
|
||||
|
||||
### CUDA 11.2
|
||||
* Added `streamOrderedAllocation`. Demonstrates stream ordered memory allocation on a GPU using cudaMallocAsync and cudaMemPool family of APIs.
|
||||
* Added `streamOrderedAllocationP2P`. Demonstrates peer-to-peer access of stream ordered memory allocated using cudaMallocAsync and cudaMemPool family of APIs.
|
||||
* Dropped Visual Studio 2015 support from all the windows supported samples.
|
||||
* FreeImage is no longer distributed with the CUDA Samples. On Windows, see the [Dependencies](#freeimage) section for more details on how to set up FreeImage. On Linux, it is recommended to install FreeImage with your distribution's package manager.
|
||||
* All the samples using CUDA Pipeline & Arrive-wait barriers are been updated to use new `cuda::pipeline` and `cuda::barrier` interfaces.
|
||||
* Updated all the samples to build with parallel build option `--threads` of `nvcc` cuda compiler.
|
||||
* Added `cudaNvSciNvMedia`. Demonstrates CUDA-NvMedia interop via NvSciBuf/NvSciSync APIs.
|
||||
* Added `simpleGL`. Demonstrates interoperability between CUDA and OpenGL.
|
||||
|
||||
### CUDA 11.1
|
||||
* Added `watershedSegmentationNPP`. Demonstrates how to use the NPP watershed segmentation function.
|
||||
* Added `batchedLabelMarkersAndLabelCompressionNPP`. Demonstrates how to use the NPP label markers generation and label compression functions based on a Union Find (UF) algorithm including both single image and batched image versions.
|
||||
* Dropped Visual Studio 2012, 2013 support from all the windows supported samples.
|
||||
* Added kernel performing warp aggregated atomic max in multi buckets using cg::labeled_partition & cg::reduce in `warpAggregatedAtomicsCG`.
|
||||
* Added extended CG shuffle mechanics to `shfl_scan` sample.
|
||||
* Added `cudaOpenMP`. Demonstrates how to use OpenMP API to write an application for multiple GPUs.
|
||||
* Added `simpleZeroCopy`. Demonstrates how to use zero copy, kernels can read and write directly to pinned system memory.
|
||||
|
||||
### CUDA 11.0
|
||||
* Added `dmmaTensorCoreGemm`. Demonstrates double precision GEMM computation using the Double precision Warp Matrix Multiply and Accumulate (WMMA) API introduced with CUDA 11 in Ampere chip family tensor cores.
|
||||
* Added `bf16TensorCoreGemm`. Demonstrates __nv_bfloat16 (e8m7) GEMM computation using the __nv_bfloat16 WMMA API introduced with CUDA 11 in Ampere chip family tensor cores.
|
||||
* Added `tf32TensorCoreGemm`. Demonstrates tf32 (e8m10) GEMM computation using the tf32 WMMA API introduced with CUDA 11 in Ampere chip family tensor cores.
|
||||
* Added `globalToShmemAsyncCopy`. Demonstrates async copy of data from global to shared memory when on compute capability 8.0 or higher. Also demonstrates arrive-wait barrier for synchronization.
|
||||
* Added `simpleAWBarrier`. Demonstrates arrive wait barriers.
|
||||
* Added `simpleAttributes`. Demonstrates the stream attributes that affect L2 locality.
|
||||
* Added warp aggregated atomic multi bucket increments kernel using labeled_partition cooperative groups in `warpAggregatedAtomicsCG` which can be used on compute capability 7.0 and above GPU architectures.
|
||||
* Added `binaryPartitionCG`. Demonstrates binary partition cooperative groups and reduction within the thread block.
|
||||
* Added two new reduction kernels in `reduction` one which demonstrates reduce_add_sync intrinstic supported on compute capability 8.0 and another which uses cooperative_groups::reduce function which does thread_block_tile level reduction introduced from CUDA 11.0.
|
||||
* Added `cudaCompressibleMemory`. Demonstrates compressible memory allocation using cuMemMap API.
|
||||
* Added `simpleVulkanMMAP`. Demonstrates Vulkan CUDA Interop via cuMemMap APIs.
|
||||
* Added `concurrentKernels`. Demonstrates the use of CUDA streams for concurrent execution of several kernels on a GPU.
|
||||
* Dropped Mac OSX support from all samples.
|
||||
|
||||
### CUDA 10.2
|
||||
* Added `simpleD3D11`. Demonstrates CUDA-D3D11 External Resource Interoperability APIs for updating D3D11 buffers from CUDA and synchronization between D3D11 and CUDA with Keyed Mutexes.
|
||||
* Added `simpleDrvRuntime`. Demonstrates CUDA Driver and Runtime APIs working together to load fatbinary of a CUDA kernel.
|
||||
* Added `vectorAddMMAP`. Demonstrates how cuMemMap API allows the user to specify the physical properties of their memory while retaining the contiguous nature of their access.
|
||||
* Added `memMapIPCDrv`. Demonstrates Inter Process Communication using cuMemMap APIs.
|
||||
* Added `cudaNvSci`. Demonstrates CUDA-NvSciBuf/NvSciSync Interop.
|
||||
* Added `jacobiCudaGraphs`. Demonstrates Instantiated CUDA Graph Update with Jacobi Iterative Method using different approaches.
|
||||
* Added `cuSolverSp_LinearSolver`. Demonstrates cuSolverSP's LU, QR and Cholesky factorization.
|
||||
* Added `MersenneTwisterGP11213`. Demonstrates the Mersenne Twister random number generator GP11213 in cuRAND.
|
||||
|
||||
### CUDA 10.1 Update 2
|
||||
* Added `vulkanImageCUDA`. Demonstrates how to perform Vulkan image - CUDA Interop.
|
||||
* Added `nvJPEG_encoder`. Demonstrates encoding of jpeg images using NVJPEG Library.
|
||||
* Added Windows OS support to `nvJPEG` sample.
|
||||
* Added `boxFilterNPP`. Demonstrates how to use NPP FilterBox function to perform a box filter.
|
||||
* Added `cannyEdgeDetectorNPP`. Demonstrates the nppiFilterCannyBorder_8u_C1R Canny Edge Detection image filter function.
|
||||
|
||||
### CUDA 10.1 Update 1
|
||||
* Added `NV12toBGRandResize`. Demonstrates how to convert and resize NV12 frames to BGR planars frames using CUDA in batch.
|
||||
* Added `EGLStream_CUDA_Interop`. Demonstrates data exchange between CUDA and EGL Streams.
|
||||
* Added `cuSolverDn_LinearSolver`. Demonstrates cuSolverDN's LU, QR and Cholesky factorization.
|
||||
* Added support of Visual Studio 2019 to all samples supported on [Windows](#windows-1).
|
||||
|
||||
### CUDA 10.1
|
||||
* Added `immaTensorCoreGemm`. Demonstrates integer GEMM computation using the Warp Matrix Multiply and Accumulate (WMMA) API for integers employing the Tensor Cores.
|
||||
* Added `simpleIPC`. Demonstrates Inter Process Communication with one process per GPU for computation.
|
||||
* Added `nvJPEG`. Demonstrates single and batched decoding of jpeg images using NVJPEG Library.
|
||||
* Added `bandwidthTest`. It measures the memcopy bandwidth of the GPU and memcpy bandwidth across PCI-e.
|
||||
* Added `reduction`. Demonstrates several important optimization strategies for Data-Parallel Algorithms like reduction.
|
||||
* Update all the samples to support CUDA 10.1.
|
||||
|
||||
### CUDA 10.0
|
||||
* Added `simpleCudaGraphs`. Demonstrates CUDA Graphs creation, instantiation and launch using Graphs APIs and Stream Capture APIs.
|
||||
* Added `conjugateGradientCudaGraphs`. Demonstrates conjugate gradient solver on GPU using CUBLAS and CUSPARSE library calls captured and called using CUDA Graph APIs.
|
||||
* Added `simpleVulkan`. Demonstrates Vulkan - CUDA Interop.
|
||||
* Added `simpleD3D12`. Demonstrates DX12 - CUDA Interop.
|
||||
* Added `UnifiedMemoryPerf`. Demonstrates performance comparision of various memory types involved in system.
|
||||
* Added `p2pBandwidthLatencyTest`. Demonstrates Peer-To-Peer (P2P) data transfers between pairs of GPUs and computes latency and bandwidth.
|
||||
* Added `systemWideAtomics`. Demonstrates system wide atomic instructions.
|
||||
* Added `simpleCUBLASXT`. Demonstrates CUBLAS-XT library which performs GEMM operations over multiple GPUs.
|
||||
* Added Windows OS support to `conjugateGradientMultiDeviceCG` sample.
|
||||
* Removed support of Visual Studio 2010 from all samples.
|
||||
|
||||
### CUDA 9.2
|
||||
|
||||
This is the first release of CUDA Samples on GitHub:
|
||||
* Added `vectorAdd_nvrtc`. Demonstrates runtime compilation library using NVRTC of a simple vectorAdd kernel.
|
||||
* Added `warpAggregatedAtomicsCG`. Demonstrates warp aggregated atomics using Cooperative Groups.
|
||||
* Added `deviceQuery`. Enumerates the properties of the CUDA devices present in the system.
|
||||
* Added `matrixMul`. Demonstrates a matrix multiplication using shared memory through tiled approach.
|
||||
* Added `matrixMulDrv`. Demonstrates a matrix multiplication using shared memory through tiled approach, uses CUDA Driver API.
|
||||
* Added `cudaTensorCoreGemm`. Demonstrates a GEMM computation using the Warp Matrix Multiply and Accumulate (WMMA) API introduced in CUDA 9, as well as the new Tensor Cores introduced in the Volta chip family.
|
||||
* Added `simpleVoteIntrinsics` which uses *_sync equivalent of the vote intrinsics _any, _all added since CUDA 9.0.
|
||||
* Added `shfl_scan` which uses *_sync equivalent of the shfl intrinsics added since CUDA 9.0.
|
||||
* Added `conjugateGradientMultiBlockCG`. Demonstrates a conjugate gradient solver on GPU using Multi Block Cooperative Groups.
|
||||
* Added `conjugateGradientMultiDeviceCG`. Demonstrates a conjugate gradient solver on multiple GPUs using Multi Device Cooperative Groups, also uses unified memory prefetching and usage hints APIs.
|
||||
* Added `simpleCUBLAS`. Demonstrates how perform GEMM operations using CUBLAS library.
|
||||
* Added `simpleCUFFT`. Demonstrates how perform FFT operations using CUFFT library.
|
||||
### [Revision History](./CHANGELOG.md)
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Prerequisites
|
||||
|
||||
Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
||||
Download and install the [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
||||
For system requirements and installation instructions of cuda toolkit, please refer to the [Linux Installation Guide](http://docs.nvidia.com/cuda/cuda-installation-guide-linux/), and the [Windows Installation Guide](http://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html).
|
||||
|
||||
### Getting the CUDA Samples
|
||||
@@ -127,82 +28,456 @@ Without using git the easiest way to use these samples is to download the zip fi
|
||||
|
||||
## Building CUDA Samples
|
||||
|
||||
### Windows
|
||||
### Building CUDA Samples
|
||||
|
||||
The Windows samples are built using the Visual Studio IDE. Solution files (.sln) are provided for each supported version of Visual Studio, using the format:
|
||||
```
|
||||
*_vs<version>.sln - for Visual Studio <version>
|
||||
```
|
||||
Complete samples solution files exist at parent directory of the repo:
|
||||
|
||||
Each individual sample has its own set of solution files at:
|
||||
`<CUDA_SAMPLES_REPO>\Samples\<sample_dir>\`
|
||||
|
||||
To build/examine all the samples at once, the complete solution files should be used. To build/examine a single sample, the individual sample solution files should be used.
|
||||
The CUDA Samples are built using CMake. Follow the instructions below for building on Linux, Windows, and for cross-compilation to Tegra devices.
|
||||
|
||||
### Linux
|
||||
The Linux samples are built using makefiles. To use the makefiles, change the current directory to the sample directory you wish to build, and run make:
|
||||
```
|
||||
$ cd <sample_dir>
|
||||
$ make
|
||||
```
|
||||
The samples makefiles can take advantage of certain options:
|
||||
* **TARGET_ARCH=<arch>** - cross-compile targeting a specific architecture. Allowed architectures are x86_64, ppc64le, armv7l, aarch64.
|
||||
By default, TARGET_ARCH is set to HOST_ARCH. On a x86_64 machine, not setting TARGET_ARCH is the equivalent of setting TARGET_ARCH=x86_64.<br/>
|
||||
`$ make TARGET_ARCH=x86_64` <br/> `$ make TARGET_ARCH=ppc64le` <br/> `$ make TARGET_ARCH=armv7l` <br/> `$ make TARGET_ARCH=aarch64` <br/>
|
||||
See [here](http://docs.nvidia.com/cuda/cuda-samples/index.html#cross-samples) for more details on cross platform compilation of cuda samples.
|
||||
* **dbg=1** - build with debug symbols
|
||||
```
|
||||
$ make dbg=1
|
||||
```
|
||||
* **SMS="A B ..."** - override the SM architectures for which the sample will be built, where `"A B ..."` is a space-delimited list of SM architectures. For example, to generate SASS for SM 50 and SM 60, use `SMS="50 60"`.
|
||||
```
|
||||
$ make SMS="50 60"
|
||||
```
|
||||
|
||||
* **HOST_COMPILER=<host_compiler>** - override the default g++ host compiler. See the [Linux Installation Guide](http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#system-requirements) for a list of supported host compilers.
|
||||
```
|
||||
$ make HOST_COMPILER=g++
|
||||
```
|
||||
Ensure that CMake (version 3.20 or later) is installed. Install it using your package manager if necessary:
|
||||
|
||||
e.g.
|
||||
```sudo apt install cmake```
|
||||
|
||||
Navigate to the root of the cloned repository and create a build directory:
|
||||
```
|
||||
mkdir build && cd build
|
||||
```
|
||||
Configure the project with CMake:
|
||||
```
|
||||
cmake ..
|
||||
```
|
||||
Build the samples:
|
||||
```
|
||||
make -j$(nproc)
|
||||
```
|
||||
Run the samples from their respective directories in the build folder. You can also follow this process from and subdirectory of the samples repo, or from within any individual sample.
|
||||
|
||||
### Windows
|
||||
|
||||
Language services for CMake are available in Visual Studio 2019 version 16.5 or later, and you can directly import the CUDA samples repository from either the root level or from any
|
||||
subdirectory or individual sample.
|
||||
|
||||
To build from the command line, open the `x64 Native Tools Command Prompt for VS` provided with your Visual Studio installation.
|
||||
|
||||
Navigate to the root of the cloned repository and create a build directory:
|
||||
```
|
||||
mkdir build && cd build
|
||||
```
|
||||
Configure the project with CMake - for example:
|
||||
```
|
||||
cmake .. -G "Visual Studio 16 2019" -A x64
|
||||
```
|
||||
Open the generated solution file CUDA_Samples.sln in Visual Studio. Build the samples by selecting the desired configuration (e.g., Debug or Release) and pressing F7 (Build Solution).
|
||||
|
||||
Run the samples from the output directories specified in Visual Studio.
|
||||
|
||||
### Enabling On-GPU Debugging
|
||||
|
||||
NVIDIA GPUs support on-GPU debugging through cuda-gdb. Enabling this may significantly affect application performance as certain compiler optimizations are disabled
|
||||
in this configuration, hence it's not on by default. Enablement of on-device debugging is controlled via the `-G` switch to nvcc.
|
||||
|
||||
To enable cuda-gdb for samples builds, define the `ENABLE_CUDA_DEBUG` flag on the CMake command line. For example:
|
||||
|
||||
```
|
||||
cmake -DENABLE_CUDA_DEBUG=True ...
|
||||
```
|
||||
|
||||
### Platform-Specific Samples
|
||||
|
||||
Some CUDA samples are specific to certain platforms, and require passing flags into CMake to enable. In particular, we define the following platform-specific flags:
|
||||
|
||||
* `BUILD_TEGRA` - for Tegra-specific samples
|
||||
|
||||
To build these samples, set the variables either on the command line or through your CMake GUI. For example:
|
||||
|
||||
```
|
||||
cmake -DBUILD_TEGRA=True ..
|
||||
```
|
||||
|
||||
### Cross-Compilation for Tegra Platforms
|
||||
|
||||
Install the NVIDIA toolchain and cross-compilation environment for Tegra devices as described in the Tegra Development Guide.
|
||||
|
||||
Ensure that CMake (version 3.20 or later) is installed.
|
||||
|
||||
Navigate to the root of the cloned repository and create a build directory:
|
||||
```
|
||||
mkdir build && cd build
|
||||
```
|
||||
Configure the project with CMake, specifying the Tegra toolchain file. And you can use -DTARGET_FS to point to the target file system root path for necessary include and library files:
|
||||
```
|
||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/toolchain-aarch64-linux.cmake -DTARGET_FS=/path/to/target/system/file/system
|
||||
```
|
||||
Build the samples:
|
||||
```
|
||||
make -j$(nproc)
|
||||
```
|
||||
Transfer the built binaries to the Tegra device and execute them there.
|
||||
|
||||
|
||||
### Cross Building for Automotive Linux Platforms from the DriveOS Docker containers
|
||||
|
||||
To build CUDA samples to the target platform from the DriveOS Docker containers, use the following instructions.
|
||||
|
||||
Mount the target Root Filesystem (RFS) in the container so that the CUDA cmake process has the correct paths to CUDA and other system libraries required to build the samples.
|
||||
|
||||
Create a temporary directory, `<temp>` is any temporary directory of your choosing, for example, you can use `/drive/temp`:
|
||||
|
||||
```
|
||||
$ mkdir /drive/<temp>
|
||||
```
|
||||
|
||||
Mount the filesystem by running the following command:
|
||||
|
||||
```
|
||||
$ mount /drive/drive-linux/filesystem/targetfs-images/dev_nsr_desktop_ubuntu-24.04_thor_rfs.img /drive/temp
|
||||
```
|
||||
|
||||
Configure the project by running the following cmake command:
|
||||
|
||||
```
|
||||
$ mkdir build && cd build
|
||||
$ cmake .. -DBUILD_TEGRA=True \
|
||||
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
|
||||
-DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/toolchain-aarch64-linux.cmake \
|
||||
-DTARGET_FS=/drive/temp \
|
||||
-DCMAKE_LIBRARY_PATH=/drive/temp/usr/local/cuda-13.1/thor/lib64/ \
|
||||
-DCMAKE_INCLUDE_PATH=/drive/temp/usr/local/cuda-13.1/thor/include/
|
||||
```
|
||||
|
||||
Please note that the following libraries are not pre-installed in the DriveOS dev-nsr target filesystem:
|
||||
* libdrm-dev
|
||||
* Vulkan
|
||||
|
||||
This causes the cmake command to throw errors related to the missing files, and as a result, the related samples will not build in later steps. This issue will be addressed in a future DriveOS release.
|
||||
|
||||
To build the samples with ignore the error mentioned above, you can use `--ignore-errors`/`--keep-going` or comment out the comment out the corresponding `add_subdirectory` command in the CMakeLists.txt in the parent folder for the samples requiring Vulkan and libdrm_dev:
|
||||
|
||||
```
|
||||
$ make -j$(nproc) --ignore-errors # or --keep-going
|
||||
```
|
||||
|
||||
```
|
||||
# In cpp/5_Domain_Specific/CMakeList.txt
|
||||
# add_subdirectory(simpleGL)
|
||||
# add_subdirectory(simpleVulkan)
|
||||
# add_subdirectory(simpleVulkanMMAP)
|
||||
|
||||
# In cpp/8_Platform_Specific/Tegra/CMakeList.txt
|
||||
# add_subdirectory(simpleGLES_EGLOutput)
|
||||
```
|
||||
|
||||
### QNX
|
||||
|
||||
Cross-compilation for QNX with CMake is supported in the CUDA 13.0 samples release and newer. An example build for
|
||||
the Tegra Thor QNX platform might look like this:
|
||||
|
||||
```
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
|
||||
QNX_HOST=/path/to/qnx/host \
|
||||
QNX_TARGET=/path/to/qnx/target \
|
||||
cmake .. \
|
||||
-DBUILD_TEGRA=True \
|
||||
-DCMAKE_CUDA_COMPILER=/usr/local/cuda-13.3/bin/nvcc \
|
||||
-DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/toolchain-aarch64-qnx.cmake \
|
||||
-DCMAKE_LIBRARY_PATH=/usr/local/cuda-13.3/thor/targets/aarch64-qnx/lib/stubs/ \
|
||||
-DCMAKE_INCLUDE_PATH=/usr/local/cuda-13.3/thor/targets/aarch64-qnx/include/
|
||||
```
|
||||
|
||||
### Forward Compatibility
|
||||
|
||||
To build samples with new CUDA Toolkit(CUDA 13.0 or later) and UMD(Version 580 or later) and old KMD(Version 550 or earlier),you need to set the `CMAKE_PREFIX_PATH` for using new driver library, the command might like this:
|
||||
|
||||
```
|
||||
cmake -DCMAKE_PREFIX_PATH=/usr/local/cuda/lib64/stubs/ ..
|
||||
```
|
||||
|
||||
## CUDA Python samples
|
||||
|
||||
The repository includes **Python** examples under the [`python/`](./python) directory. **These samples are cuda.core–focused:** they use [CUDA Python](https://nvidia.github.io/cuda-python/), with [`cuda.core`](https://nvidia.github.io/cuda-python/cuda-core/latest/) for devices, programs, launches, and memory, alongside NumPy, CuPy, or framework interop where each sample notes.
|
||||
|
||||
**Layout (same themes as the C++ samples):**
|
||||
|
||||
| Directory | Contents |
|
||||
|-----------|----------|
|
||||
| `python/1_GettingStarted/` | Introductory scripts (e.g. `vectorAdd`, `deviceQuery`, `systemInfo`, image blur with unified memory, NumPy vs CuPy). |
|
||||
| `python/2_CoreConcepts/` | Algorithms and techniques (e.g. reductions, histograms, FFT, stream overlap, `memoryResources`, `cudaGraphs`, `jitLtoLinking`, `tmaTensorMap`). |
|
||||
| `python/3_FrameworkInterop/` | Integration with PyTorch and TensorFlow. |
|
||||
| `python/4_DistributedComputing/` | Multi-GPU, peer-to-peer, and IPC patterns (`ipcMemoryPool`). |
|
||||
| `python/Utilities/` | Shared helpers imported by some samples. |
|
||||
|
||||
**How to run:** The top-level CMake build does **not** compile these samples. For each sample, use a Python 3.10+ environment with a matching [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads) (the samples target CUDA 13.x and document exact package pins in `requirements.txt`):
|
||||
|
||||
```bash
|
||||
cd python/<category>/<sampleName>
|
||||
pip install -r requirements.txt
|
||||
python <sampleScript>.py
|
||||
```
|
||||
|
||||
Use each sample’s `README.md` for prerequisites, CLI options, and expected output.
|
||||
|
||||
## Install Samples
|
||||
|
||||
### Installation Path Structure
|
||||
|
||||
The installation system automatically organizes samples into a structured directory layout based on:
|
||||
- **Target Architecture**: ${CMAKE_SYSTEM_PROCESSOR}, e.g. `x64`, `aarch64`, `amd64`, etc.
|
||||
- **Target OS**: `linux`, `windows`, `darwin`, `qnx`
|
||||
- **Build Type**: `release`, `debug`, etc.
|
||||
|
||||
The default installation path is: `build/bin/${TARGET_ARCH}/${TARGET_OS}/${BUILD_TYPE}`
|
||||
|
||||
**Examples:**
|
||||
- Linux x86_64 Release: `build/bin/x64/linux/release`
|
||||
- Linux aarch64 Release: `build/bin/aarch64/linux/release`
|
||||
- Windows amd64 Release: `build/bin/amd64/windows/release`
|
||||
|
||||
### Customizing Installation Paths
|
||||
|
||||
You can customize the installation location using CMake variables during the configuration step:
|
||||
|
||||
- `CMAKE_INSTALL_PREFIX`: Changes the root installation directory (default: `build/bin`)
|
||||
```
|
||||
cmake -DCMAKE_INSTALL_PREFIX=/custom/path ..
|
||||
```
|
||||
This will install to: `/custom/path/${TARGET_ARCH}/${TARGET_OS}/${BUILD_TYPE}`
|
||||
|
||||
- `CUDA_SAMPLES_INSTALL_DIR`: Specifies the exact final installation directory (overrides the structured path)
|
||||
```
|
||||
cmake -DCUDA_SAMPLES_INSTALL_DIR=/exact/install/path ..
|
||||
```
|
||||
|
||||
### Install Samples on Linux
|
||||
|
||||
**Prerequisites:** You must first configure the project with CMake as described in the [Building CUDA Samples - Linux](#linux) or [Building]section.
|
||||
|
||||
After configuring and building, install the samples:
|
||||
|
||||
```
|
||||
cd build/
|
||||
make install
|
||||
```
|
||||
|
||||
### Install Samples on Windows
|
||||
|
||||
**Prerequisites:** You must first configure the project with CMake as described in the [Building CUDA Samples - Windows](#windows) section.
|
||||
|
||||
#### Using Command Line
|
||||
|
||||
After configuring with CMake, build and install from the `x64 Native Tools Command Prompt for VS`:
|
||||
|
||||
```cmd
|
||||
cd build
|
||||
cmake --build . --config Release
|
||||
cmake --install . --config Release
|
||||
```
|
||||
|
||||
**Note:** Replace `Release` with `Debug` if you want to install debug builds. For multi-configuration generators (like Visual Studio), the `--config` flag determines which build type to install.
|
||||
|
||||
#### Using Visual Studio IDE
|
||||
|
||||
Alternatively, open the generated solution file `CUDA_Samples.sln` in Visual Studio:
|
||||
1. Select the desired configuration (`Release` or `Debug`)
|
||||
2. Build the solution (F7 or Build > Build Solution)
|
||||
3. Right-click on the `INSTALL` target under `CMakePredefinedTargets` in Solution Explorer
|
||||
4. Select "Build"
|
||||
|
||||
## Running All Samples as Tests
|
||||
|
||||
It's important to note that the CUDA samples are _not_ intended as a validation suite for CUDA. They do not cover corner cases, they do not completely cover the
|
||||
runtime and driver APIs, are not intended for performance benchmarking, etc. That said, it can sometimes be useful to run all of the samples as a quick sanity check and
|
||||
we provide a script to do so, `run_tests.py`.
|
||||
|
||||
This Python3 script finds all executables in a subdirectory you choose, matching application names with command line arguments specified in `test_args.json`. It accepts
|
||||
the following command line arguments:
|
||||
|
||||
| Switch | Purpose | Example |
|
||||
| ---------- | -------------------------------------------------------------------------------------------------------------- | ----------------------- |
|
||||
| --dir | Specify the root directory to search for executables (recursively) | --dir ./build/cpp |
|
||||
| --config | JSON configuration file for executable arguments | --config test_args.json |
|
||||
| --output | Output directory for test results (stdout saved to .txt files - directory will be created if it doesn't exist) | --output ./test |
|
||||
| --args | Global arguments to pass to all executables (not currently used) | --args arg_1 arg_2 ... |
|
||||
| --parallel | Number of applications to execute in parallel. | --parallel 8 |
|
||||
|
||||
|
||||
Application configurations are loaded from `test_args.json` and matched against executable names (discarding the `.exe` extension on Windows).
|
||||
|
||||
The script returns 0 on success, or the first non-zero error code encountered during testing on failure. It will also print a condensed list of samples that failed, if any.
|
||||
|
||||
There are three primary modes of configuration:
|
||||
|
||||
**Skip**
|
||||
|
||||
An executable configured with "skip" will not be executed. These generally rely on having attached graphical displays and are not suited to this kind of automation.
|
||||
|
||||
Configuration example:
|
||||
```json
|
||||
"fluidsGL": {
|
||||
"skip": true
|
||||
}
|
||||
```
|
||||
|
||||
You will see:
|
||||
```
|
||||
Skipping fluidsGL (marked as skip in config)
|
||||
```
|
||||
|
||||
**Single Run**
|
||||
|
||||
For executables to run one time only with arguments, specify each argument as a list entry. Each entry in the JSON file will be appended to the command line, separated
|
||||
by a space.
|
||||
|
||||
All applications execute from their current directory, so all paths are relative to the application's location.
|
||||
|
||||
Note that if an application needs no arguments, this entry is optional. An executable found without a matching entry in the JSON will just run as `./application` from its
|
||||
current directory.
|
||||
|
||||
Configuration example:
|
||||
```json
|
||||
"ptxgen": {
|
||||
"args": [
|
||||
"test.ll",
|
||||
"-arch=compute_75"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
You will see:
|
||||
```
|
||||
Running ptxgen
|
||||
Command: ./ptxgen test.ll -arch=compute_75
|
||||
Test completed with return code 0
|
||||
```
|
||||
|
||||
**Multiple Runs**
|
||||
|
||||
For executables to run multiple times with different command line arguments, specify any number of sets of args within a "runs" list.
|
||||
|
||||
As with single runs, all applications execute from their current directory, so all paths are relative to the application's location.
|
||||
|
||||
Configuration example:
|
||||
```json
|
||||
"recursiveGaussian": {
|
||||
"runs": [
|
||||
{
|
||||
"args": [
|
||||
"-sigma=10",
|
||||
"-file=data/ref_10.ppm"
|
||||
]
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
"-sigma=14",
|
||||
"-file=data/ref_14.ppm"
|
||||
]
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
"-sigma=18",
|
||||
"-file=data/ref_18.ppm"
|
||||
]
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
"-sigma=22",
|
||||
"-file=data/ref_22.ppm"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
You will see:
|
||||
```
|
||||
Running recursiveGaussian (run 1/4)
|
||||
Command: ./recursiveGaussian -sigma=10 -file=data/ref_10.ppm
|
||||
Test completed with return code 0
|
||||
Running recursiveGaussian (run 2/4)
|
||||
Command: ./recursiveGaussian -sigma=14 -file=data/ref_14.ppm
|
||||
Test completed with return code 0
|
||||
Running recursiveGaussian (run 3/4)
|
||||
Command: ./recursiveGaussian -sigma=18 -file=data/ref_18.ppm
|
||||
Test completed with return code 0
|
||||
Running recursiveGaussian (run 4/4)
|
||||
Command: ./recursiveGaussian -sigma=22 -file=data/ref_22.ppm
|
||||
Test completed with return code 0
|
||||
```
|
||||
|
||||
### Example Usage
|
||||
|
||||
Here is an example set of commands to build and test all of the samples.
|
||||
|
||||
First, build:
|
||||
```bash
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make -j$(nproc)
|
||||
```
|
||||
|
||||
Now, return to the samples root directory and run the test script:
|
||||
```bash
|
||||
cd ..
|
||||
python3 run_tests.py --output ./test --dir ./build/cpp --config test_args.json
|
||||
```
|
||||
|
||||
If all applications run successfully, you will see something similar to this (the specific number of samples will depend on your build type
|
||||
and system configuration):
|
||||
|
||||
```
|
||||
Test Summary:
|
||||
Ran 199 test runs for 180 executables.
|
||||
All test runs passed!
|
||||
```
|
||||
|
||||
If some samples fail, you will see something like this:
|
||||
|
||||
```
|
||||
Test Summary:
|
||||
Ran 199 test runs for 180 executables.
|
||||
Failed runs (2):
|
||||
bicubicTexture (run 1/5): Failed (code 1)
|
||||
Mandelbrot (run 1/2): Failed (code 1)
|
||||
```
|
||||
|
||||
You can inspect the stdout logs in the output directory (generally `APM_<application_name>.txt` or `APM_<application_name>.run<n>.txt`) to help
|
||||
determine what may have gone wrong from the output logs. Please file issues against the samples repository if you believe a sample is failing
|
||||
incorrectly on your system.
|
||||
|
||||
## Samples list
|
||||
|
||||
### Samples by OS
|
||||
### [0. Introduction](./cpp/0_Introduction/README.md)
|
||||
Basic CUDA samples for beginners that illustrate key concepts with using CUDA and CUDA runtime APIs.
|
||||
|
||||
#### Linux
|
||||
**[vectorAdd_nvrtc](./Samples/vectorAdd_nvrtc)** | **[shfl_scan](./Samples/shfl_scan)** | **[binaryPartitionCG](./Samples/binaryPartitionCG)** | **[concurrentKernels](./Samples/concurrentKernels)** |
|
||||
---|---|---|---|
|
||||
**[streamOrderedAllocationIPC](./Samples/streamOrderedAllocationIPC)** | **[UnifiedMemoryPerf](./Samples/UnifiedMemoryPerf)** | **[bf16TensorCoreGemm](./Samples/bf16TensorCoreGemm)** | **[cuSolverSp_LinearSolver](./Samples/cuSolverSp_LinearSolver)** |
|
||||
**[nvJPEG](./Samples/nvJPEG)** | **[watershedSegmentationNPP](./Samples/watershedSegmentationNPP)** | **[vulkanImageCUDA](./Samples/vulkanImageCUDA)** | **[boxFilterNPP](./Samples/boxFilterNPP)** |
|
||||
**[matrixMul](./Samples/matrixMul)** | **[nvJPEG_encoder](./Samples/nvJPEG_encoder)** | **[simpleCudaGraphs](./Samples/simpleCudaGraphs)** | **[simpleCUFFT](./Samples/simpleCUFFT)** |
|
||||
**[cudaTensorCoreGemm](./Samples/cudaTensorCoreGemm)** | **[cudaOpenMP](./Samples/cudaOpenMP)** | **[NV12toBGRandResize](./Samples/NV12toBGRandResize)** | **[cudaNvSci](./Samples/cudaNvSci)** |
|
||||
**[immaTensorCoreGemm](./Samples/immaTensorCoreGemm)** | **[simpleVulkan](./Samples/simpleVulkan)** | **[simpleCUBLAS](./Samples/simpleCUBLAS)** | **[jacobiCudaGraphs](./Samples/jacobiCudaGraphs)** |
|
||||
**[streamOrderedAllocationP2P](./Samples/streamOrderedAllocationP2P)** | **[dmmaTensorCoreGemm](./Samples/dmmaTensorCoreGemm)** | **[EGLStream_CUDA_Interop](./Samples/EGLStream_CUDA_Interop)** | **[vectorAddMMAP](./Samples/vectorAddMMAP)** |
|
||||
**[MersenneTwisterGP11213](./Samples/MersenneTwisterGP11213)** | **[streamOrderedAllocation](./Samples/streamOrderedAllocation)** | **[cuSolverDn_LinearSolver](./Samples/cuSolverDn_LinearSolver)** | **[cudaCompressibleMemory](./Samples/cudaCompressibleMemory)** |
|
||||
**[simpleAWBarrier](./Samples/simpleAWBarrier)** | **[simpleGL](./Samples/simpleGL)** | **[p2pBandwidthLatencyTest](./Samples/p2pBandwidthLatencyTest)** | **[conjugateGradientCudaGraphs](./Samples/conjugateGradientCudaGraphs)** |
|
||||
**[globalToShmemAsyncCopy](./Samples/globalToShmemAsyncCopy)** | **[deviceQuery](./Samples/deviceQuery)** | **[systemWideAtomics](./Samples/systemWideAtomics)** | **[matrixMulDrv](./Samples/matrixMulDrv)** |
|
||||
**[conjugateGradientMultiBlockCG](./Samples/conjugateGradientMultiBlockCG)** | **[simpleZeroCopy](./Samples/simpleZeroCopy)** | **[simpleAttributes](./Samples/simpleAttributes)** | **[batchedLabelMarkersAndLabelCompressionNPP](./Samples/batchedLabelMarkersAndLabelCompressionNPP)** |
|
||||
**[conjugateGradientMultiDeviceCG](./Samples/conjugateGradientMultiDeviceCG)** | **[simpleIPC](./Samples/simpleIPC)** | **[simpleVulkanMMAP](./Samples/simpleVulkanMMAP)** | **[cudaNvSciNvMedia](./Samples/cudaNvSciNvMedia)** |
|
||||
**[simpleVoteIntrinsics](./Samples/simpleVoteIntrinsics)** | **[simpleCUBLAS_LU](./Samples/simpleCUBLAS_LU)** | **[bandwidthTest](./Samples/bandwidthTest)** | **[cdpQuadtree](./Samples/cdpQuadtree)** |
|
||||
**[simpleCUBLASXT](./Samples/simpleCUBLASXT)** | **[tf32TensorCoreGemm](./Samples/tf32TensorCoreGemm)** | **[simpleDrvRuntime](./Samples/simpleDrvRuntime)** | **[reduction](./Samples/reduction)** |
|
||||
**[memMapIPCDrv](./Samples/memMapIPCDrv)** | **[warpAggregatedAtomicsCG](./Samples/warpAggregatedAtomicsCG)** | **[cannyEdgeDetectorNPP](./Samples/cannyEdgeDetectorNPP)** |
|
||||
### [1. Utilities](./cpp/1_Utilities/README.md)
|
||||
Utility samples that demonstrate how to query device capabilities and measure GPU/CPU bandwidth.
|
||||
|
||||
#### Windows
|
||||
**[vectorAdd_nvrtc](./Samples/vectorAdd_nvrtc)** | **[shfl_scan](./Samples/shfl_scan)** | **[binaryPartitionCG](./Samples/binaryPartitionCG)** | **[concurrentKernels](./Samples/concurrentKernels)** |
|
||||
---|---|---|---|
|
||||
**[UnifiedMemoryPerf](./Samples/UnifiedMemoryPerf)** | **[bf16TensorCoreGemm](./Samples/bf16TensorCoreGemm)** | **[cuSolverSp_LinearSolver](./Samples/cuSolverSp_LinearSolver)** | **[nvJPEG](./Samples/nvJPEG)** |
|
||||
**[watershedSegmentationNPP](./Samples/watershedSegmentationNPP)** | **[vulkanImageCUDA](./Samples/vulkanImageCUDA)** | **[boxFilterNPP](./Samples/boxFilterNPP)** | **[matrixMul](./Samples/matrixMul)** |
|
||||
**[nvJPEG_encoder](./Samples/nvJPEG_encoder)** | **[simpleCudaGraphs](./Samples/simpleCudaGraphs)** | **[simpleCUFFT](./Samples/simpleCUFFT)** | **[cudaTensorCoreGemm](./Samples/cudaTensorCoreGemm)** |
|
||||
**[cudaOpenMP](./Samples/cudaOpenMP)** | **[NV12toBGRandResize](./Samples/NV12toBGRandResize)** | **[immaTensorCoreGemm](./Samples/immaTensorCoreGemm)** | **[simpleVulkan](./Samples/simpleVulkan)** |
|
||||
**[simpleCUBLAS](./Samples/simpleCUBLAS)** | **[jacobiCudaGraphs](./Samples/jacobiCudaGraphs)** | **[streamOrderedAllocationP2P](./Samples/streamOrderedAllocationP2P)** | **[dmmaTensorCoreGemm](./Samples/dmmaTensorCoreGemm)** |
|
||||
**[vectorAddMMAP](./Samples/vectorAddMMAP)** | **[MersenneTwisterGP11213](./Samples/MersenneTwisterGP11213)** | **[streamOrderedAllocation](./Samples/streamOrderedAllocation)** | **[cuSolverDn_LinearSolver](./Samples/cuSolverDn_LinearSolver)** |
|
||||
**[cudaCompressibleMemory](./Samples/cudaCompressibleMemory)** | **[simpleAWBarrier](./Samples/simpleAWBarrier)** | **[simpleGL](./Samples/simpleGL)** | **[p2pBandwidthLatencyTest](./Samples/p2pBandwidthLatencyTest)** |
|
||||
**[conjugateGradientCudaGraphs](./Samples/conjugateGradientCudaGraphs)** | **[simpleD3D11](./Samples/simpleD3D11)** | **[globalToShmemAsyncCopy](./Samples/globalToShmemAsyncCopy)** | **[deviceQuery](./Samples/deviceQuery)** |
|
||||
**[matrixMulDrv](./Samples/matrixMulDrv)** | **[conjugateGradientMultiBlockCG](./Samples/conjugateGradientMultiBlockCG)** | **[simpleZeroCopy](./Samples/simpleZeroCopy)** | **[simpleAttributes](./Samples/simpleAttributes)** |
|
||||
**[simpleD3D12](./Samples/simpleD3D12)** | **[batchedLabelMarkersAndLabelCompressionNPP](./Samples/batchedLabelMarkersAndLabelCompressionNPP)** | **[conjugateGradientMultiDeviceCG](./Samples/conjugateGradientMultiDeviceCG)** | **[simpleIPC](./Samples/simpleIPC)** |
|
||||
**[simpleVulkanMMAP](./Samples/simpleVulkanMMAP)** | **[simpleVoteIntrinsics](./Samples/simpleVoteIntrinsics)** | **[simpleCUBLAS_LU](./Samples/simpleCUBLAS_LU)** | **[bandwidthTest](./Samples/bandwidthTest)** |
|
||||
**[cdpQuadtree](./Samples/cdpQuadtree)** | **[simpleCUBLASXT](./Samples/simpleCUBLASXT)** | **[tf32TensorCoreGemm](./Samples/tf32TensorCoreGemm)** | **[simpleDrvRuntime](./Samples/simpleDrvRuntime)** |
|
||||
**[reduction](./Samples/reduction)** | **[memMapIPCDrv](./Samples/memMapIPCDrv)** | **[warpAggregatedAtomicsCG](./Samples/warpAggregatedAtomicsCG)** | **[cannyEdgeDetectorNPP](./Samples/cannyEdgeDetectorNPP)** |
|
||||
### [2. Concepts and Techniques](./cpp/2_Concepts_and_Techniques/README.md)
|
||||
Samples that demonstrate CUDA related concepts and common problem solving techniques.
|
||||
|
||||
### [3. CUDA Features](./cpp/3_CUDA_Features/README.md)
|
||||
Samples that demonstrate CUDA Features (Cooperative Groups, CUDA Dynamic Parallelism, CUDA Graphs etc).
|
||||
|
||||
### [4. CUDA Libraries](./cpp/4_CUDA_Libraries/README.md)
|
||||
Samples that demonstrate how to use CUDA platform libraries (NPP, NVJPEG, NVGRAPH cuBLAS, cuFFT, cuSPARSE, cuSOLVER and cuRAND).
|
||||
|
||||
### [5. Domain Specific](./cpp/5_Domain_Specific/README.md)
|
||||
Samples that are specific to domain (Graphics, Finance, Image Processing).
|
||||
|
||||
### [6. Performance](./cpp/6_Performance/README.md)
|
||||
Samples that demonstrate performance optimization.
|
||||
|
||||
### [7. libNVVM](./cpp/7_libNVVM/README.md)
|
||||
Samples that demonstrate the use of libNVVVM and NVVM IR.
|
||||
|
||||
### [8. Platform Specific](./cpp/8_Platform_Specific/Tegra/README.md)
|
||||
Samples that are specific to certain platforms (Tegra, cuDLA, NvMedia, NvSci, OpenGL ES).
|
||||
|
||||
### [9. CUDA Tile](./cpp/9_CUDA_Tile/README.md)
|
||||
Samples that demonstrate how to use CUDA Tile C++.
|
||||
|
||||
## Dependencies
|
||||
|
||||
@@ -220,7 +495,7 @@ These third-party dependencies are required by some CUDA samples. If available,
|
||||
|
||||
FreeImage is an open source imaging library. FreeImage can usually be installed on Linux using your distribution's package manager system. FreeImage can also be downloaded from the FreeImage website.
|
||||
|
||||
To set up FreeImage on a Windows system, extract the FreeImage DLL distribution into the folder `../../Common/FreeImage/Dist/x64` such that it contains the .h, .dll, and .lib files.
|
||||
To set up FreeImage on a Windows system, extract the FreeImage DLL distribution into the folder `./Common/FreeImage/Dist/x64` such that it contains the .h and .lib files. Copy the .dll file to the Release/ Debug/ execution folder or pass the FreeImage folder when cmake configuring with the `-DFreeImage_INCLUDE_DIR` and `-DFreeImage_LIBRARY` options.
|
||||
|
||||
#### Message Passing Interface
|
||||
|
||||
@@ -246,13 +521,27 @@ OpenGL is a graphics library used for 2D and 3D rendering. On systems which supp
|
||||
|
||||
OpenGL ES is an embedded systems graphics library used for 2D and 3D rendering. On systems which support OpenGL ES, NVIDIA's OpenGL ES implementation is provided with the CUDA Driver.
|
||||
|
||||
#### Freeglut
|
||||
|
||||
Freeglut is an open-source software library that serves as a replacement for the original OpenGL Utility Toolkit (GLUT). Its primary purpose is to make it easier for developers to create and manage windows containing OpenGL contexts, as well as handle input from devices like the mouse, keyboard, and joystick, across a wide range of platforms. To set up Freeglut on a Windowson on ARM system, you need to download the source from [Freeglut website](https://freeglut.sourceforge.net/), build freeglut on your system, and copy the freeglut.lib into the folder `./Common/lib/x64` and copy the freeglut.dll file into the `./bin/win64/${BUILD_TYPE}` execution folder.
|
||||
|
||||
#### Vulkan
|
||||
|
||||
Vulkan is a low-overhead, cross-platform 3D graphics and compute API. Vulkan targets high-performance realtime 3D graphics applications such as video games and interactive media across all platforms. On systems which support Vulkan, NVIDIA's Vulkan implementation is provided with the CUDA Driver. For building and running Vulkan applications one needs to install the [Vulkan SDK](https://www.lunarg.com/vulkan-sdk/).
|
||||
|
||||
#### GLEW
|
||||
|
||||
GLEW (OpenGL Extension Wrangler Library) is a cross-platform, open-source C/C++ library designed to simplify the process of using modern OpenGL features and extensions. Its main function is to dynamically load OpenGL function pointers at runtime, allowing developers to access both core OpenGL functions and additional features provided by hardware vendors, known as extensions. To set up GLEW on a Windows on ARM system, you need to download the source from [GLEW website](https://glew.sourceforge.net/), build GLEW on your system, and copy the glew32.lib into the folder `./Common/lib/x64` and the glew32.dll into the `./bin/win64/${BUILD_TYPE}` execution folder.
|
||||
|
||||
#### GLFW
|
||||
|
||||
GLFW is a lightweight, open-source library designed for managing OpenGL, OpenGL ES, and Vulkan contexts. It simplifies the process of creating and managing windows, handling user input (keyboard, mouse, and joystick), and working with multiple monitors in a cross-platform manner.
|
||||
|
||||
To set up GLFW on a Windows system, Download the pre-built binaries from [GLFW website](https://www.glfw.org/download.html) and extract the zip file into the folder, pass the GLFW include header folder as `-DGLFW_INCLUDE_DIR` and lib folder as `-DGLFW_LIB_DIR` for cmake configuring.
|
||||
|
||||
#### OpenMP
|
||||
|
||||
OpenMP is an API for multiprocessing programming. OpenMP can be installed using your Linux distribution's package manager system. It usually comes preinstalled with GCC. It can also be found at the [OpenMP website](http://openmp.org/).
|
||||
OpenMP is an API for multiprocessing programming. OpenMP can be installed using your Linux distribution's package manager system. It usually comes preinstalled with GCC. It can also be found at the [OpenMP website](http://openmp.org/). For compilers such as clang, make sure OpenMP is enabled when building LLVM by including `openmp` in `LLVM_ENABLE_PROJECTS`. If you use clang (from an installed prefix or directly from an LLVM build tree) with OpenMP enabled, set CMAKE_CXX_COMPILER and CMAKE_CUDA_HOST_COMPILER to that clang++ and let CMake detect OpenMP; extra OpenMP_* CMake variables are usually not needed. When using clang++ directly from an LLVM build tree, you may need to copy the generated `omp.h` into the `include/` directory under the path reported by `clang++ --print-resource-dir` before building the samples. When using an installed clang with OpenMP, if you see libomp.so: cannot open shared object file at runtime, add the directory that contains libomp.so to LD_LIBRARY_PATH (or configure it via ld.so.conf.d) so the dynamic linker can locate the OpenMP runtime.
|
||||
|
||||
#### Screen
|
||||
|
||||
@@ -342,6 +631,11 @@ NVJPEG library provides high-performance, GPU accelerated JPEG decoding function
|
||||
|
||||
NVRTC (CUDA RunTime Compilation) is a runtime compilation library for CUDA C++.
|
||||
|
||||
#### NVJITLINK
|
||||
|
||||
NVJITLINK is a CUDA runtime library that links multiple GPU device code objects at runtime and enables just‑in‑time link‑time optimization (JIT LTO).
|
||||
It can take device code from tools such as NVCC and NVRTC, link and optimize it on the fly, and produce the final GPU binary.For more details, see: https://docs.nvidia.com/cuda/nvjitlink/index.html
|
||||
|
||||
#### Stream Priorities
|
||||
|
||||
Stream Priorities allows the creation of streams with specified priorities. Stream Priorities is only available on GPUs with SM architecture of 3.5 or above.
|
||||
@@ -358,6 +652,10 @@ FP16 is a 16-bit floating-point format. One bit is used for the sign, five bits
|
||||
|
||||
NVCC support of [C++11 features](https://en.wikipedia.org/wiki/C++11).
|
||||
|
||||
#### CMake
|
||||
|
||||
The libNVVM samples are built using [CMake](https://cmake.org/) 3.10 or later.
|
||||
|
||||
## Contributors Guide
|
||||
|
||||
We welcome your input on issues and suggestions for samples. At this time we are not accepting contributions from the public, check back here as we evolve our contribution model.
|
||||
@@ -370,6 +668,9 @@ Answers to frequently asked questions about CUDA can be found at http://develope
|
||||
|
||||
## References
|
||||
|
||||
* [CUDA Programming Guide](http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html)
|
||||
* [Accelerated Computing Blog](https://devblogs.nvidia.com/category/accelerated-computing/)
|
||||
* [CUDA Programming Guide](https://docs.nvidia.com/cuda/cuda-programming-guide/index.html)
|
||||
* [Accelerated Computing Blog](https://developer.nvidia.com/blog/?tags=accelerated-computing)
|
||||
|
||||
## Attributions
|
||||
|
||||
* Teapot image is obtained from [Wikimedia](https://en.wikipedia.org/wiki/File:Original_Utah_Teapot.jpg) and is licensed under the Creative Commons [Attribution-Share Alike 2.0](https://creativecommons.org/licenses/by-sa/2.0/deed.en) Generic license. The image is modified for samples use cases.
|
||||
|
||||
@@ -1,408 +0,0 @@
|
||||
################################################################################
|
||||
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# Makefile project only supported on Mac OS X and Linux Platforms)
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# Location of the CUDA Toolkit
|
||||
CUDA_PATH ?= /usr/local/cuda
|
||||
|
||||
##############################
|
||||
# start deprecated interface #
|
||||
##############################
|
||||
ifeq ($(x86_64),1)
|
||||
$(info WARNING - x86_64 variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=x86_64 instead)
|
||||
TARGET_ARCH ?= x86_64
|
||||
endif
|
||||
ifeq ($(ARMv7),1)
|
||||
$(info WARNING - ARMv7 variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=armv7l instead)
|
||||
TARGET_ARCH ?= armv7l
|
||||
endif
|
||||
ifeq ($(aarch64),1)
|
||||
$(info WARNING - aarch64 variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=aarch64 instead)
|
||||
TARGET_ARCH ?= aarch64
|
||||
endif
|
||||
ifeq ($(ppc64le),1)
|
||||
$(info WARNING - ppc64le variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=ppc64le instead)
|
||||
TARGET_ARCH ?= ppc64le
|
||||
endif
|
||||
ifneq ($(GCC),)
|
||||
$(info WARNING - GCC variable has been deprecated)
|
||||
$(info WARNING - please use HOST_COMPILER=$(GCC) instead)
|
||||
HOST_COMPILER ?= $(GCC)
|
||||
endif
|
||||
ifneq ($(abi),)
|
||||
$(error ERROR - abi variable has been removed)
|
||||
endif
|
||||
############################
|
||||
# end deprecated interface #
|
||||
############################
|
||||
|
||||
# architecture
|
||||
HOST_ARCH := $(shell uname -m)
|
||||
TARGET_ARCH ?= $(HOST_ARCH)
|
||||
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le armv7l))
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le))
|
||||
TARGET_SIZE := 64
|
||||
else ifneq (,$(filter $(TARGET_ARCH),armv7l))
|
||||
TARGET_SIZE := 32
|
||||
endif
|
||||
else
|
||||
TARGET_SIZE := $(shell getconf LONG_BIT)
|
||||
endif
|
||||
else
|
||||
$(error ERROR - unsupported value $(TARGET_ARCH) for TARGET_ARCH!)
|
||||
endif
|
||||
|
||||
# sbsa and aarch64 systems look similar. Need to differentiate them at host level for now.
|
||||
ifeq ($(HOST_ARCH),aarch64)
|
||||
ifeq ($(CUDA_PATH)/targets/sbsa-linux,$(shell ls -1d $(CUDA_PATH)/targets/sbsa-linux 2>/dev/null))
|
||||
HOST_ARCH := sbsa
|
||||
TARGET_ARCH := sbsa
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq (,$(filter $(HOST_ARCH)-$(TARGET_ARCH),aarch64-armv7l x86_64-armv7l x86_64-aarch64 x86_64-sbsa x86_64-ppc64le))
|
||||
$(error ERROR - cross compiling from $(HOST_ARCH) to $(TARGET_ARCH) is not supported!)
|
||||
endif
|
||||
endif
|
||||
|
||||
# When on native aarch64 system with userspace of 32-bit, change TARGET_ARCH to armv7l
|
||||
ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_SIZE),aarch64-aarch64-32)
|
||||
TARGET_ARCH = armv7l
|
||||
endif
|
||||
|
||||
# operating system
|
||||
HOST_OS := $(shell uname -s 2>/dev/null | tr "[:upper:]" "[:lower:]")
|
||||
TARGET_OS ?= $(HOST_OS)
|
||||
ifeq (,$(filter $(TARGET_OS),linux darwin qnx android))
|
||||
$(error ERROR - unsupported value $(TARGET_OS) for TARGET_OS!)
|
||||
endif
|
||||
|
||||
# host compiler
|
||||
ifeq ($(TARGET_OS),darwin)
|
||||
ifeq ($(shell expr `xcodebuild -version | grep -i xcode | awk '{print $$2}' | cut -d'.' -f1` \>= 5),1)
|
||||
HOST_COMPILER ?= clang++
|
||||
endif
|
||||
else ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq ($(HOST_ARCH)-$(TARGET_ARCH),x86_64-armv7l)
|
||||
ifeq ($(TARGET_OS),linux)
|
||||
HOST_COMPILER ?= arm-linux-gnueabihf-g++
|
||||
else ifeq ($(TARGET_OS),qnx)
|
||||
ifeq ($(QNX_HOST),)
|
||||
$(error ERROR - QNX_HOST must be passed to the QNX host toolchain)
|
||||
endif
|
||||
ifeq ($(QNX_TARGET),)
|
||||
$(error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
|
||||
endif
|
||||
export QNX_HOST
|
||||
export QNX_TARGET
|
||||
HOST_COMPILER ?= $(QNX_HOST)/usr/bin/arm-unknown-nto-qnx6.6.0eabi-g++
|
||||
else ifeq ($(TARGET_OS),android)
|
||||
HOST_COMPILER ?= arm-linux-androideabi-g++
|
||||
endif
|
||||
else ifeq ($(TARGET_ARCH),aarch64)
|
||||
ifeq ($(TARGET_OS), linux)
|
||||
HOST_COMPILER ?= aarch64-linux-gnu-g++
|
||||
else ifeq ($(TARGET_OS),qnx)
|
||||
ifeq ($(QNX_HOST),)
|
||||
$(error ERROR - QNX_HOST must be passed to the QNX host toolchain)
|
||||
endif
|
||||
ifeq ($(QNX_TARGET),)
|
||||
$(error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
|
||||
endif
|
||||
export QNX_HOST
|
||||
export QNX_TARGET
|
||||
HOST_COMPILER ?= $(QNX_HOST)/usr/bin/q++
|
||||
else ifeq ($(TARGET_OS), android)
|
||||
HOST_COMPILER ?= aarch64-linux-android-clang++
|
||||
endif
|
||||
else ifeq ($(TARGET_ARCH),sbsa)
|
||||
HOST_COMPILER ?= aarch64-linux-gnu-g++
|
||||
else ifeq ($(TARGET_ARCH),ppc64le)
|
||||
HOST_COMPILER ?= powerpc64le-linux-gnu-g++
|
||||
endif
|
||||
endif
|
||||
HOST_COMPILER ?= g++
|
||||
NVCC := $(CUDA_PATH)/bin/nvcc -ccbin $(HOST_COMPILER)
|
||||
|
||||
# internal flags
|
||||
NVCCFLAGS := -m${TARGET_SIZE}
|
||||
CCFLAGS :=
|
||||
LDFLAGS :=
|
||||
|
||||
# build flags
|
||||
ifeq ($(TARGET_OS),darwin)
|
||||
LDFLAGS += -rpath $(CUDA_PATH)/lib
|
||||
CCFLAGS += -arch $(HOST_ARCH)
|
||||
else ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_OS),x86_64-armv7l-linux)
|
||||
LDFLAGS += --dynamic-linker=/lib/ld-linux-armhf.so.3
|
||||
CCFLAGS += -mfloat-abi=hard
|
||||
else ifeq ($(TARGET_OS),android)
|
||||
LDFLAGS += -pie
|
||||
CCFLAGS += -fpie -fpic -fexceptions
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
|
||||
ifneq ($(TARGET_FS),)
|
||||
GCCVERSIONLTEQ46 := $(shell expr `$(HOST_COMPILER) -dumpversion` \<= 4.6)
|
||||
ifeq ($(GCCVERSIONLTEQ46),1)
|
||||
CCFLAGS += --sysroot=$(TARGET_FS)
|
||||
endif
|
||||
LDFLAGS += --sysroot=$(TARGET_FS)
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/arm-linux-gnueabihf
|
||||
endif
|
||||
endif
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
|
||||
ifneq ($(TARGET_FS),)
|
||||
GCCVERSIONLTEQ46 := $(shell expr `$(HOST_COMPILER) -dumpversion` \<= 4.6)
|
||||
ifeq ($(GCCVERSIONLTEQ46),1)
|
||||
CCFLAGS += --sysroot=$(TARGET_FS)
|
||||
endif
|
||||
LDFLAGS += --sysroot=$(TARGET_FS)
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib -L$(TARGET_FS)/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib/aarch64-linux-gnu -L$(TARGET_FS)/lib/aarch64-linux-gnu
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib -L$(TARGET_FS)/usr/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/aarch64-linux-gnu -L$(TARGET_FS)/usr/lib/aarch64-linux-gnu
|
||||
LDFLAGS += --unresolved-symbols=ignore-in-shared-libs
|
||||
CCFLAGS += -isystem=$(TARGET_FS)/usr/include -I$(TARGET_FS)/usr/include -I$(TARGET_FS)/usr/include/libdrm
|
||||
CCFLAGS += -isystem=$(TARGET_FS)/usr/include/aarch64-linux-gnu -I$(TARGET_FS)/usr/include/aarch64-linux-gnu
|
||||
endif
|
||||
endif
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
|
||||
NVCCFLAGS += --qpp-config 5.4.0,gcc_ntoaarch64le
|
||||
CCFLAGS += -DWIN_INTERFACE_CUSTOM -I/usr/include/aarch64-qnx-gnu
|
||||
LDFLAGS += -lsocket
|
||||
LDFLAGS += -L/usr/lib/aarch64-qnx-gnu
|
||||
CCFLAGS += "-Wl\,-rpath-link\,/usr/lib/aarch64-qnx-gnu"
|
||||
ifdef TARGET_OVERRIDE
|
||||
LDFLAGS += -lslog2
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_FS),)
|
||||
LDFLAGS += -L$(TARGET_FS)/usr/lib
|
||||
CCFLAGS += "-Wl\,-rpath-link\,$(TARGET_FS)/usr/lib"
|
||||
LDFLAGS += -L$(TARGET_FS)/usr/libnvidia
|
||||
CCFLAGS += "-Wl\,-rpath-link\,$(TARGET_FS)/usr/libnvidia"
|
||||
CCFLAGS += -I$(TARGET_FS)/../include
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef TARGET_OVERRIDE # cuda toolkit targets override
|
||||
NVCCFLAGS += -target-dir $(TARGET_OVERRIDE)
|
||||
endif
|
||||
|
||||
# Install directory of different arch
|
||||
CUDA_INSTALL_TARGET_DIR :=
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-gnueabihf/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),sbsa-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/sbsa-linux/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-android)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-androideabi/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-android)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux-androideabi/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-qnx)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/ARMv7-linux-QNX/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-qnx/
|
||||
else ifeq ($(TARGET_ARCH),ppc64le)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/ppc64le-linux/
|
||||
endif
|
||||
|
||||
# Debug build flags
|
||||
ifeq ($(dbg),1)
|
||||
NVCCFLAGS += -g -G
|
||||
BUILD_TYPE := debug
|
||||
else
|
||||
BUILD_TYPE := release
|
||||
endif
|
||||
|
||||
ALL_CCFLAGS :=
|
||||
ALL_CCFLAGS += $(NVCCFLAGS)
|
||||
ALL_CCFLAGS += $(EXTRA_NVCCFLAGS)
|
||||
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(CCFLAGS))
|
||||
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(EXTRA_CCFLAGS))
|
||||
|
||||
UBUNTU = $(shell lsb_release -i -s 2>/dev/null | grep -i ubuntu)
|
||||
|
||||
SAMPLE_ENABLED := 1
|
||||
|
||||
# This sample is not supported on Mac OSX
|
||||
ifeq ($(TARGET_OS),darwin)
|
||||
$(info >>> WARNING - EGLStream_CUDA_Interop is not supported on Mac OSX - waiving sample <<<)
|
||||
SAMPLE_ENABLED := 0
|
||||
endif
|
||||
|
||||
# This sample is not supported on ARMv7
|
||||
ifeq ($(TARGET_ARCH),armv7l)
|
||||
$(info >>> WARNING - EGLStream_CUDA_Interop is not supported on ARMv7 - waiving sample <<<)
|
||||
SAMPLE_ENABLED := 0
|
||||
endif
|
||||
|
||||
# This sample is not supported on android
|
||||
ifeq ($(TARGET_OS),android)
|
||||
$(info >>> WARNING - EGLStream_CUDA_Interop is not supported on android - waiving sample <<<)
|
||||
SAMPLE_ENABLED := 0
|
||||
endif
|
||||
|
||||
ALL_LDFLAGS :=
|
||||
ALL_LDFLAGS += $(ALL_CCFLAGS)
|
||||
ALL_LDFLAGS += $(addprefix -Xlinker ,$(LDFLAGS))
|
||||
ALL_LDFLAGS += $(addprefix -Xlinker ,$(EXTRA_LDFLAGS))
|
||||
|
||||
# Common includes and paths for CUDA
|
||||
INCLUDES := -I../../Common
|
||||
LIBRARIES :=
|
||||
|
||||
################################################################################
|
||||
|
||||
# Makefile include to help find EGL Libraries
|
||||
include ./findegl.mk
|
||||
|
||||
# EGL specific libraries
|
||||
ifneq ($(TARGET_OS),darwin)
|
||||
LIBRARIES += -lEGL
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_OS),darwin)
|
||||
ALL_LDFLAGS += -Xcompiler -F/Library/Frameworks -Xlinker -framework -Xlinker CUDA
|
||||
else
|
||||
ifeq ($(TARGET_ARCH),x86_64)
|
||||
CUDA_SEARCH_PATH ?= $(CUDA_PATH)/lib64/stubs
|
||||
CUDA_SEARCH_PATH += $(CUDA_PATH)/targets/x86_64-linux/lib/stubs
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
|
||||
CUDA_SEARCH_PATH ?= $(CUDA_PATH)/targets/armv7-linux-gnueabihf/lib/stubs
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
|
||||
CUDA_SEARCH_PATH ?= $(CUDA_PATH)/targets/aarch64-linux/lib/stubs
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),sbsa-linux)
|
||||
CUDA_SEARCH_PATH ?= $(CUDA_PATH)/targets/sbsa-linux/lib/stubs
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-android)
|
||||
CUDA_SEARCH_PATH ?= $(CUDA_PATH)/targets/armv7-linux-androideabi/lib/stubs
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-android)
|
||||
CUDA_SEARCH_PATH ?= $(CUDA_PATH)/targets/aarch64-linux-androideabi/lib/stubs
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-qnx)
|
||||
CUDA_SEARCH_PATH ?= $(CUDA_PATH)/targets/ARMv7-linux-QNX/lib/stubs
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
|
||||
CUDA_SEARCH_PATH ?= $(CUDA_PATH)/targets/aarch64-qnx/lib/stubs
|
||||
ifdef TARGET_OVERRIDE
|
||||
CUDA_SEARCH_PATH := $(CUDA_PATH)/targets/$(TARGET_OVERRIDE)/lib/stubs
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_ARCH),ppc64le)
|
||||
CUDA_SEARCH_PATH ?= $(CUDA_PATH)/targets/ppc64le-linux/lib/stubs
|
||||
endif
|
||||
|
||||
ifeq ($(HOST_ARCH),ppc64le)
|
||||
CUDA_SEARCH_PATH += $(CUDA_PATH)/lib64/stubs
|
||||
endif
|
||||
|
||||
CUDALIB ?= $(shell find -L $(CUDA_SEARCH_PATH) -maxdepth 1 -name libcuda.so 2> /dev/null)
|
||||
ifeq ("$(CUDALIB)","")
|
||||
$(info >>> WARNING - libcuda.so not found, CUDA Driver is not installed. Please re-install the driver. <<<)
|
||||
SAMPLE_ENABLED := 0
|
||||
else
|
||||
CUDALIB := $(shell echo $(CUDALIB) | sed "s/ .*//" | sed "s/\/libcuda.so//" )
|
||||
LIBRARIES += -L$(CUDALIB) -lcuda
|
||||
endif
|
||||
endif
|
||||
|
||||
ALL_CCFLAGS += --threads 0
|
||||
|
||||
ifeq ($(SAMPLE_ENABLED),0)
|
||||
EXEC ?= @echo "[@]"
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
|
||||
# Target rules
|
||||
all: build
|
||||
|
||||
build: EGLStream_CUDA_Interop
|
||||
|
||||
check.deps:
|
||||
ifeq ($(SAMPLE_ENABLED),0)
|
||||
@echo "Sample will be waived due to the above missing dependencies"
|
||||
else
|
||||
@echo "Sample is ready - all dependencies have been met"
|
||||
endif
|
||||
|
||||
cuda_consumer.o:cuda_consumer.cpp
|
||||
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
|
||||
|
||||
cuda_producer.o:cuda_producer.cpp
|
||||
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
|
||||
|
||||
eglstrm_common.o:eglstrm_common.cpp
|
||||
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
|
||||
|
||||
main.o:main.cpp
|
||||
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
|
||||
|
||||
EGLStream_CUDA_Interop: cuda_consumer.o cuda_producer.o eglstrm_common.o main.o
|
||||
$(EXEC) $(NVCC) $(ALL_LDFLAGS) $(GENCODE_FLAGS) -o $@ $+ $(LIBRARIES)
|
||||
$(EXEC) mkdir -p ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
|
||||
$(EXEC) cp $@ ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
|
||||
|
||||
run: build
|
||||
$(EXEC) ./EGLStream_CUDA_Interop
|
||||
|
||||
clean:
|
||||
rm -f EGLStream_CUDA_Interop cuda_consumer.o cuda_producer.o eglstrm_common.o main.o
|
||||
rm -rf ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)/EGLStream_CUDA_Interop
|
||||
|
||||
clobber: clean
|
||||
@@ -1,77 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE entry SYSTEM "SamplesInfo.dtd">
|
||||
<entry>
|
||||
<name>EGLStream_CUDA_Interop</name>
|
||||
<cuda_api_list>
|
||||
<driver>cuDeviceGet</driver>
|
||||
<driver>cuDeviceGetAttribute</driver>
|
||||
<driver>cuDeviceComputeCapability</driver>
|
||||
<driver>cuDeviceGetCount</driver>
|
||||
<driver>cuDeviceGetName</driver>
|
||||
<driver>cuGraphicsResourceGetMappedEglFrame</driver>
|
||||
<driver>cuEGLStreamConsumerAcquireFrame</driver>
|
||||
<driver>cuEGLStreamConsumerReleaseFrame</driver>
|
||||
<driver>cuEGLStreamProducerPresentFrame</driver>
|
||||
<driver>cuCtxCreate</driver>
|
||||
<driver>cuMemAlloc</driver>
|
||||
<driver>cuMemFree</driver>
|
||||
<driver>cuMemcpy3D</driver>
|
||||
<driver>cuStreamCreate</driver>
|
||||
<driver>cuCtxPushCurrent</driver>
|
||||
<driver>cuCtxPopCurrent</driver>
|
||||
<driver>cuCtxDestroy</driver>
|
||||
</cuda_api_list>
|
||||
<description><![CDATA[Demonstrates data exchange between CUDA and EGL Streams.]]></description>
|
||||
<devicecompilation>whole</devicecompilation>
|
||||
<includepaths>
|
||||
<path>./</path>
|
||||
<path>../</path>
|
||||
<path>../../common/inc</path>
|
||||
</includepaths>
|
||||
<keyconcepts>
|
||||
<concept level="basic">EGLStreams Interop</concept>
|
||||
</keyconcepts>
|
||||
<keywords>
|
||||
<keyword>EGL Streams</keyword>
|
||||
</keywords>
|
||||
<libraries>
|
||||
<library os="linux">cuda</library>
|
||||
<library framework="true" os="macosx">CUDA</library>
|
||||
</libraries>
|
||||
<librarypaths>
|
||||
</librarypaths>
|
||||
<nsight_eclipse>true</nsight_eclipse>
|
||||
<primary_file>main.cpp</primary_file>
|
||||
<required_dependencies>
|
||||
<dependency>EGL</dependency>
|
||||
</required_dependencies>
|
||||
<scopes>
|
||||
<scope>1:CUDA Basic Topics</scope>
|
||||
<scope>2:Graphics Interop</scope>
|
||||
</scopes>
|
||||
<sm-arch>sm35</sm-arch>
|
||||
<sm-arch>sm37</sm-arch>
|
||||
<sm-arch>sm50</sm-arch>
|
||||
<sm-arch>sm52</sm-arch>
|
||||
<sm-arch>sm60</sm-arch>
|
||||
<sm-arch>sm61</sm-arch>
|
||||
<sm-arch>sm70</sm-arch>
|
||||
<sm-arch>sm72</sm-arch>
|
||||
<sm-arch>sm75</sm-arch>
|
||||
<sm-arch>sm80</sm-arch>
|
||||
<sm-arch>sm86</sm-arch>
|
||||
<supported_envs>
|
||||
<env>
|
||||
<arch>x86_64</arch>
|
||||
<platform>linux</platform>
|
||||
</env>
|
||||
<env>
|
||||
<arch>aarch64</arch>
|
||||
</env>
|
||||
</supported_envs>
|
||||
<supported_sm_architectures>
|
||||
<include>all</include>
|
||||
</supported_sm_architectures>
|
||||
<title>EGLStream CUDA Interop</title>
|
||||
<type>exe</type>
|
||||
</entry>
|
||||
@@ -1,64 +0,0 @@
|
||||
# EGLStream_CUDA_Interop - EGLStream CUDA Interop
|
||||
|
||||
## Description
|
||||
|
||||
Demonstrates data exchange between CUDA and EGL Streams.
|
||||
|
||||
## Key Concepts
|
||||
|
||||
EGLStreams Interop
|
||||
|
||||
## Supported SM Architectures
|
||||
|
||||
[SM 3.5 ](https://developer.nvidia.com/cuda-gpus) [SM 3.7 ](https://developer.nvidia.com/cuda-gpus) [SM 5.0 ](https://developer.nvidia.com/cuda-gpus) [SM 5.2 ](https://developer.nvidia.com/cuda-gpus) [SM 6.0 ](https://developer.nvidia.com/cuda-gpus) [SM 6.1 ](https://developer.nvidia.com/cuda-gpus) [SM 7.0 ](https://developer.nvidia.com/cuda-gpus) [SM 7.2 ](https://developer.nvidia.com/cuda-gpus) [SM 7.5 ](https://developer.nvidia.com/cuda-gpus) [SM 8.0 ](https://developer.nvidia.com/cuda-gpus) [SM 8.6 ](https://developer.nvidia.com/cuda-gpus)
|
||||
|
||||
## Supported OSes
|
||||
|
||||
Linux
|
||||
|
||||
## Supported CPU Architecture
|
||||
|
||||
x86_64, aarch64
|
||||
|
||||
## CUDA APIs involved
|
||||
|
||||
### [CUDA Driver API](http://docs.nvidia.com/cuda/cuda-driver-api/index.html)
|
||||
cuDeviceGet, cuDeviceGetAttribute, cuDeviceComputeCapability, cuDeviceGetCount, cuDeviceGetName, cuGraphicsResourceGetMappedEglFrame, cuEGLStreamConsumerAcquireFrame, cuEGLStreamConsumerReleaseFrame, cuEGLStreamProducerPresentFrame, cuCtxCreate, cuMemAlloc, cuMemFree, cuMemcpy3D, cuStreamCreate, cuCtxPushCurrent, cuCtxPopCurrent, cuCtxDestroy
|
||||
|
||||
## Dependencies needed to build/run
|
||||
[EGL](../../README.md#egl)
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
||||
Make sure the dependencies mentioned in [Dependencies]() section above are installed.
|
||||
|
||||
## Build and Run
|
||||
|
||||
### Linux
|
||||
The Linux samples are built using makefiles. To use the makefiles, change the current directory to the sample directory you wish to build, and run make:
|
||||
```
|
||||
$ cd <sample_dir>
|
||||
$ make
|
||||
```
|
||||
The samples makefiles can take advantage of certain options:
|
||||
* **TARGET_ARCH=<arch>** - cross-compile targeting a specific architecture. Allowed architectures are x86_64, aarch64.
|
||||
By default, TARGET_ARCH is set to HOST_ARCH. On a x86_64 machine, not setting TARGET_ARCH is the equivalent of setting TARGET_ARCH=x86_64.<br/>
|
||||
`$ make TARGET_ARCH=x86_64` <br/> `$ make TARGET_ARCH=aarch64` <br/>
|
||||
See [here](http://docs.nvidia.com/cuda/cuda-samples/index.html#cross-samples) for more details.
|
||||
* **dbg=1** - build with debug symbols
|
||||
```
|
||||
$ make dbg=1
|
||||
```
|
||||
* **SMS="A B ..."** - override the SM architectures for which the sample will be built, where `"A B ..."` is a space-delimited list of SM architectures. For example, to generate SASS for SM 50 and SM 60, use `SMS="50 60"`.
|
||||
```
|
||||
$ make SMS="50 60"
|
||||
```
|
||||
|
||||
* **HOST_COMPILER=<host_compiler>** - override the default g++ host compiler. See the [Linux Installation Guide](http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#system-requirements) for a list of supported host compilers.
|
||||
```
|
||||
$ make HOST_COMPILER=g++
|
||||
```
|
||||
|
||||
## References (for more details)
|
||||
|
||||
@@ -1,318 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
//
|
||||
// DESCRIPTION: Simple CUDA consumer rendering sample app
|
||||
//
|
||||
|
||||
#include "cuda_consumer.h"
|
||||
#include <helper_cuda_drvapi.h>
|
||||
#include "eglstrm_common.h"
|
||||
|
||||
#if defined(EXTENSION_LIST)
|
||||
EXTENSION_LIST(EXTLST_EXTERN)
|
||||
#endif
|
||||
|
||||
int checkbuf(FILE *fp1, FILE *fp2);
|
||||
|
||||
CUresult cudaConsumerTest(test_cuda_consumer_s *data, char *fileName) {
|
||||
CUresult cuStatus = CUDA_SUCCESS;
|
||||
CUarray cudaArr = NULL;
|
||||
CUeglFrame cudaEgl;
|
||||
CUgraphicsResource cudaResource;
|
||||
unsigned int i;
|
||||
int check_result;
|
||||
FILE *pInFile1 = NULL, *pInFile2 = NULL, *file_p = NULL;
|
||||
EGLint streamState = 0;
|
||||
|
||||
if (!data) {
|
||||
printf("%s: Bad parameter\n", __func__);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!eglQueryStreamKHR(g_display, eglStream, EGL_STREAM_STATE_KHR,
|
||||
&streamState)) {
|
||||
printf("Cuda consumer, eglQueryStreamKHR EGL_STREAM_STATE_KHR failed\n");
|
||||
}
|
||||
if (streamState == EGL_STREAM_STATE_DISCONNECTED_KHR) {
|
||||
printf("CUDA Consumer: - EGL_STREAM_STATE_DISCONNECTED_KHR received\n");
|
||||
}
|
||||
|
||||
if (streamState == EGL_STREAM_STATE_NEW_FRAME_AVAILABLE_KHR) {
|
||||
cuStatus = cuEGLStreamConsumerAcquireFrame(&(data->cudaConn), &cudaResource,
|
||||
NULL, 16000);
|
||||
|
||||
if (cuStatus == CUDA_SUCCESS) {
|
||||
CUdeviceptr pDevPtr = 0;
|
||||
int bufferSize;
|
||||
unsigned char *pCudaCopyMem = NULL;
|
||||
unsigned int copyWidthInBytes = 0, copyHeight = 0;
|
||||
|
||||
file_p = fopen(fileName, "wb+");
|
||||
if (!file_p) {
|
||||
printf("WriteFrame: file open failed %s\n", fileName);
|
||||
cuStatus = CUDA_ERROR_UNKNOWN;
|
||||
goto done;
|
||||
}
|
||||
cuStatus =
|
||||
cuGraphicsResourceGetMappedEglFrame(&cudaEgl, cudaResource, 0, 0);
|
||||
if (cuStatus != CUDA_SUCCESS) {
|
||||
printf("Cuda get resource failed with %d\n", cuStatus);
|
||||
goto done;
|
||||
}
|
||||
cuStatus = cuCtxSynchronize();
|
||||
if (cuStatus != CUDA_SUCCESS) {
|
||||
printf("cuCtxSynchronize failed \n");
|
||||
goto done;
|
||||
}
|
||||
if (!(cudaEgl.planeCount >= 1 && cudaEgl.planeCount <= 3)) {
|
||||
printf("Plane count is invalid\nExiting\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (i = 0; i < cudaEgl.planeCount; i++) {
|
||||
if (cudaEgl.frameType == CU_EGL_FRAME_TYPE_PITCH) {
|
||||
pDevPtr = (CUdeviceptr)cudaEgl.frame.pPitch[i];
|
||||
if (cudaEgl.planeCount == 1) {
|
||||
bufferSize = cudaEgl.pitch * cudaEgl.height;
|
||||
copyWidthInBytes = cudaEgl.pitch;
|
||||
copyHeight = data->height;
|
||||
} else if (i == 1 && cudaEgl.planeCount == 2) { // YUV 420
|
||||
// semi-planar
|
||||
bufferSize = cudaEgl.pitch * cudaEgl.height / 2;
|
||||
copyWidthInBytes = cudaEgl.pitch;
|
||||
copyHeight = data->height / 2;
|
||||
} else {
|
||||
bufferSize = data->width * data->height;
|
||||
copyWidthInBytes = data->width;
|
||||
copyHeight = data->height;
|
||||
if (i > 0) {
|
||||
bufferSize >>= 2;
|
||||
copyWidthInBytes >>= 1;
|
||||
copyHeight >>= 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cudaArr = cudaEgl.frame.pArray[i];
|
||||
if (cudaEgl.planeCount == 1) {
|
||||
bufferSize = data->width * data->height * 4;
|
||||
copyWidthInBytes = data->width * 4;
|
||||
copyHeight = data->height;
|
||||
} else if (i == 1 && cudaEgl.planeCount == 2) { // YUV 420
|
||||
// semi-planar
|
||||
bufferSize = data->width * data->height / 2;
|
||||
copyWidthInBytes = data->width;
|
||||
copyHeight = data->height / 2;
|
||||
} else {
|
||||
bufferSize = data->width * data->height;
|
||||
copyWidthInBytes = data->width;
|
||||
copyHeight = data->height;
|
||||
if (i > 0) {
|
||||
bufferSize >>= 2;
|
||||
copyWidthInBytes >>= 1;
|
||||
copyHeight >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i == 0) {
|
||||
pCudaCopyMem = (unsigned char *)malloc(bufferSize);
|
||||
if (pCudaCopyMem == NULL) {
|
||||
printf("pCudaCopyMem malloc failed\n");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
memset(pCudaCopyMem, 0, bufferSize);
|
||||
if (data->pitchLinearOutput) {
|
||||
cuStatus = cuMemcpyDtoH(pCudaCopyMem, pDevPtr, bufferSize);
|
||||
if (cuStatus != CUDA_SUCCESS) {
|
||||
printf(
|
||||
"cuda_consumer: pitch linear Memcpy failed, bufferSize =%d\n",
|
||||
bufferSize);
|
||||
goto done;
|
||||
}
|
||||
cuStatus = cuCtxSynchronize();
|
||||
if (cuStatus != CUDA_SUCCESS) {
|
||||
printf("cuda_consumer: cuCtxSynchronize failed after memcpy \n");
|
||||
goto done;
|
||||
}
|
||||
} else {
|
||||
CUDA_MEMCPY3D cpdesc;
|
||||
memset(&cpdesc, 0, sizeof(cpdesc));
|
||||
cpdesc.srcXInBytes = cpdesc.srcY = cpdesc.srcZ = cpdesc.srcLOD = 0;
|
||||
cpdesc.srcMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
cpdesc.srcArray = cudaArr;
|
||||
cpdesc.dstXInBytes = cpdesc.dstY = cpdesc.dstZ = cpdesc.dstLOD = 0;
|
||||
cpdesc.dstMemoryType = CU_MEMORYTYPE_HOST;
|
||||
cpdesc.dstHost = (void *)pCudaCopyMem;
|
||||
cpdesc.WidthInBytes = copyWidthInBytes; // data->width * 4;
|
||||
cpdesc.Height = copyHeight; // data->height;
|
||||
cpdesc.Depth = 1;
|
||||
|
||||
cuStatus = cuMemcpy3D(&cpdesc);
|
||||
if (cuStatus != CUDA_SUCCESS) {
|
||||
printf(
|
||||
"Cuda consumer: cuMemCpy3D failed, copyWidthInBytes=%d, "
|
||||
"copyHight=%d\n",
|
||||
copyWidthInBytes, copyHeight);
|
||||
}
|
||||
cuStatus = cuCtxSynchronize();
|
||||
if (cuStatus != CUDA_SUCCESS) {
|
||||
printf("cuCtxSynchronize failed after memcpy \n");
|
||||
}
|
||||
}
|
||||
if (cuStatus == CUDA_SUCCESS) {
|
||||
if (fwrite(pCudaCopyMem, bufferSize, 1, file_p) != 1) {
|
||||
printf("Cuda consumer: output file write failed\n");
|
||||
cuStatus = CUDA_ERROR_UNKNOWN;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
pInFile1 = fopen(data->fileName1, "rb");
|
||||
if (!pInFile1) {
|
||||
printf("Failed to open file :%s\n", data->fileName1);
|
||||
goto done;
|
||||
}
|
||||
pInFile2 = fopen(data->fileName2, "rb");
|
||||
if (!pInFile2) {
|
||||
printf("Failed to open file :%s\n", data->fileName2);
|
||||
goto done;
|
||||
}
|
||||
rewind(file_p);
|
||||
check_result = checkbuf(file_p, pInFile1);
|
||||
if (check_result == -1) {
|
||||
rewind(file_p);
|
||||
check_result = checkbuf(file_p, pInFile2);
|
||||
if (check_result == -1) {
|
||||
printf("Frame received does not match any valid image: FAILED\n");
|
||||
} else {
|
||||
printf("Frame check Passed\n");
|
||||
}
|
||||
} else {
|
||||
printf("Frame check Passed\n");
|
||||
}
|
||||
if (pCudaCopyMem) {
|
||||
free(pCudaCopyMem);
|
||||
pCudaCopyMem = NULL;
|
||||
}
|
||||
cuStatus =
|
||||
cuEGLStreamConsumerReleaseFrame(&data->cudaConn, cudaResource, NULL);
|
||||
if (cuStatus != CUDA_SUCCESS) {
|
||||
printf("cuEGLStreamConsumerReleaseFrame failed with cuStatus = %d\n",
|
||||
cuStatus);
|
||||
goto done;
|
||||
}
|
||||
} else {
|
||||
printf("cuda AcquireFrame FAILED with cuStatus=%d\n", cuStatus);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
if (file_p) {
|
||||
fclose(file_p);
|
||||
file_p = NULL;
|
||||
}
|
||||
if (pInFile1) {
|
||||
fclose(pInFile1);
|
||||
pInFile1 = NULL;
|
||||
}
|
||||
if (pInFile1) {
|
||||
fclose(pInFile2);
|
||||
pInFile2 = NULL;
|
||||
}
|
||||
return cuStatus;
|
||||
}
|
||||
|
||||
int checkbuf(FILE *fp1, FILE *fp2) {
|
||||
int match = 0;
|
||||
int ch1, ch2;
|
||||
if (fp1 == NULL) {
|
||||
printf("Invalid file pointer for first file\n");
|
||||
return -1;
|
||||
} else if (fp2 == NULL) {
|
||||
printf("Invalid file pointer for second file\n");
|
||||
return -1;
|
||||
} else {
|
||||
ch1 = getc(fp1);
|
||||
ch2 = getc(fp2);
|
||||
while ((ch1 != EOF) && (ch2 != EOF) && (ch1 == ch2)) {
|
||||
ch1 = getc(fp1);
|
||||
ch2 = getc(fp2);
|
||||
}
|
||||
if (ch1 == ch2) {
|
||||
match = 1;
|
||||
} else if (ch1 != ch2) {
|
||||
match = -1;
|
||||
}
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
CUresult cudaDeviceCreateConsumer(test_cuda_consumer_s *cudaConsumer,
|
||||
CUdevice device) {
|
||||
CUresult status = CUDA_SUCCESS;
|
||||
if (CUDA_SUCCESS != (status = cuInit(0))) {
|
||||
printf("Failed to initialize CUDA\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
int major = 0, minor = 0;
|
||||
char deviceName[256];
|
||||
checkCudaErrors(cuDeviceGetAttribute(
|
||||
&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, device));
|
||||
checkCudaErrors(cuDeviceGetAttribute(
|
||||
&minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, device));
|
||||
checkCudaErrors(cuDeviceGetName(deviceName, 256, device));
|
||||
printf(
|
||||
"CUDA Consumer on GPU Device %d: \"%s\" with compute capability "
|
||||
"%d.%d\n\n",
|
||||
device, deviceName, major, minor);
|
||||
|
||||
if (CUDA_SUCCESS !=
|
||||
(status = cuCtxCreate(&cudaConsumer->context, 0, device))) {
|
||||
printf("failed to create CUDA context\n");
|
||||
return status;
|
||||
}
|
||||
checkCudaErrors(cuCtxPopCurrent(&cudaConsumer->context));
|
||||
return status;
|
||||
}
|
||||
|
||||
void cuda_consumer_init(test_cuda_consumer_s *cudaConsumer, TestArgs *args) {
|
||||
cudaConsumer->pitchLinearOutput = args->pitchLinearOutput;
|
||||
cudaConsumer->width = args->inputWidth;
|
||||
cudaConsumer->height = args->inputHeight;
|
||||
cudaConsumer->fileName1 = args->infile1;
|
||||
cudaConsumer->fileName2 = args->infile2;
|
||||
|
||||
cudaConsumer->outFile1 = "cuda_out1.yuv";
|
||||
cudaConsumer->outFile2 = "cuda_out2.yuv";
|
||||
}
|
||||
|
||||
CUresult cuda_consumer_deinit(test_cuda_consumer_s *cudaConsumer) {
|
||||
return cuEGLStreamConsumerDisconnect(&cudaConsumer->cudaConn);
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
//
|
||||
// DESCRIPTION: CUDA consumer header file
|
||||
//
|
||||
|
||||
#ifndef _CUDA_CONSUMER_H_
|
||||
#define _CUDA_CONSUMER_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "cudaEGL.h"
|
||||
#include "eglstrm_common.h"
|
||||
|
||||
extern EGLStreamKHR eglStream;
|
||||
extern EGLDisplay g_display;
|
||||
|
||||
typedef struct _test_cuda_consumer_s {
|
||||
CUcontext context;
|
||||
CUeglStreamConnection cudaConn;
|
||||
bool pitchLinearOutput;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
char *fileName1;
|
||||
char *fileName2;
|
||||
char *outFile1;
|
||||
char *outFile2;
|
||||
unsigned int frameCount;
|
||||
} test_cuda_consumer_s;
|
||||
|
||||
void cuda_consumer_init(test_cuda_consumer_s *cudaConsumer, TestArgs *args);
|
||||
CUresult cuda_consumer_deinit(test_cuda_consumer_s *cudaConsumer);
|
||||
CUresult cudaConsumerTest(test_cuda_consumer_s *data, char *outFile);
|
||||
CUresult cudaDeviceCreateConsumer(test_cuda_consumer_s *cudaConsumer,
|
||||
CUdevice device);
|
||||
#endif
|
||||
@@ -1,406 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
//
|
||||
// DESCRIPTION: Simple cuda EGL stream producer app
|
||||
//
|
||||
|
||||
#include "cuda_producer.h"
|
||||
#include <helper_cuda_drvapi.h>
|
||||
#include "cudaEGL.h"
|
||||
#include "eglstrm_common.h"
|
||||
|
||||
#if defined(EXTENSION_LIST)
|
||||
EXTENSION_LIST(EXTLST_EXTERN)
|
||||
#endif
|
||||
|
||||
static CUresult cudaProducerReadYUVFrame(FILE *file, unsigned int frameNum,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
unsigned char *pBuff) {
|
||||
int bOrderUV = 0;
|
||||
unsigned char *pYBuff, *pUBuff, *pVBuff, *pChroma;
|
||||
unsigned int frameSize = (width * height * 3) / 2;
|
||||
CUresult ret = CUDA_SUCCESS;
|
||||
unsigned int i;
|
||||
|
||||
if (!pBuff || !file) return CUDA_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
pYBuff = pBuff;
|
||||
|
||||
// YVU order in the buffer
|
||||
pVBuff = pYBuff + width * height;
|
||||
pUBuff = pVBuff + width * height / 4;
|
||||
|
||||
if (fseek(file, frameNum * frameSize, SEEK_SET)) {
|
||||
printf("ReadYUVFrame: Error seeking file: %p\n", file);
|
||||
ret = CUDA_ERROR_NOT_PERMITTED;
|
||||
goto done;
|
||||
}
|
||||
// read Y U V separately
|
||||
for (i = 0; i < height; i++) {
|
||||
if (fread(pYBuff, width, 1, file) != 1) {
|
||||
printf("ReadYUVFrame: Error reading file: %p\n", file);
|
||||
ret = CUDA_ERROR_NOT_PERMITTED;
|
||||
goto done;
|
||||
}
|
||||
pYBuff += width;
|
||||
}
|
||||
|
||||
pChroma = bOrderUV ? pUBuff : pVBuff;
|
||||
for (i = 0; i < height / 2; i++) {
|
||||
if (fread(pChroma, width / 2, 1, file) != 1) {
|
||||
printf("ReadYUVFrame: Error reading file: %p\n", file);
|
||||
ret = CUDA_ERROR_NOT_PERMITTED;
|
||||
goto done;
|
||||
}
|
||||
pChroma += width / 2;
|
||||
}
|
||||
|
||||
pChroma = bOrderUV ? pVBuff : pUBuff;
|
||||
for (i = 0; i < height / 2; i++) {
|
||||
if (fread(pChroma, width / 2, 1, file) != 1) {
|
||||
printf("ReadYUVFrame: Error reading file: %p\n", file);
|
||||
ret = CUDA_ERROR_NOT_PERMITTED;
|
||||
goto done;
|
||||
}
|
||||
pChroma += width / 2;
|
||||
}
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static CUresult cudaProducerReadARGBFrame(FILE *file, unsigned int frameNum,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
unsigned char *pBuff) {
|
||||
unsigned int frameSize = width * height * 4;
|
||||
CUresult ret = CUDA_SUCCESS;
|
||||
|
||||
if (!pBuff || !file) return CUDA_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
if (fseek(file, frameNum * frameSize, SEEK_SET)) {
|
||||
printf("ReadYUVFrame: Error seeking file: %p\n", file);
|
||||
ret = CUDA_ERROR_NOT_PERMITTED;
|
||||
goto done;
|
||||
}
|
||||
|
||||
// read ARGB data
|
||||
if (fread(pBuff, frameSize, 1, file) != 1) {
|
||||
if (feof(file))
|
||||
printf("ReadARGBFrame: file read to the end\n");
|
||||
else
|
||||
printf("ReadARGBFrame: Error reading file: %p\n", file);
|
||||
ret = CUDA_ERROR_NOT_PERMITTED;
|
||||
goto done;
|
||||
}
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
CUresult cudaProducerTest(test_cuda_producer_s *cudaProducer, char *file) {
|
||||
int framenum = 0;
|
||||
CUarray cudaArr[3] = {0};
|
||||
CUdeviceptr cudaPtr[3] = {0, 0, 0};
|
||||
unsigned int bufferSize;
|
||||
CUresult cuStatus = CUDA_SUCCESS;
|
||||
unsigned int i, surfNum, uvOffset[3] = {0};
|
||||
unsigned int copyWidthInBytes[3] = {0, 0, 0}, copyHeight[3] = {0, 0, 0};
|
||||
CUeglColorFormat eglColorFormat;
|
||||
FILE *file_p;
|
||||
CUeglFrame cudaEgl;
|
||||
CUcontext oldContext;
|
||||
|
||||
file_p = fopen(file, "rb");
|
||||
if (!file_p) {
|
||||
printf("CudaProducer: Error opening file: %s\n", file);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (cudaProducer->pitchLinearOutput) {
|
||||
if (cudaProducer->isARGB) {
|
||||
cudaPtr[0] = cudaProducer->cudaPtrARGB[0];
|
||||
} else { // YUV case
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (i == 0) {
|
||||
bufferSize = cudaProducer->width * cudaProducer->height;
|
||||
} else {
|
||||
bufferSize = cudaProducer->width * cudaProducer->height / 4;
|
||||
}
|
||||
|
||||
cudaPtr[i] = cudaProducer->cudaPtrYUV[i];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (cudaProducer->isARGB) {
|
||||
cudaArr[0] = cudaProducer->cudaArrARGB[0];
|
||||
} else {
|
||||
for (i = 0; i < 3; i++) {
|
||||
cudaArr[i] = cudaProducer->cudaArrYUV[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
uvOffset[0] = 0;
|
||||
if (cudaProducer->isARGB) {
|
||||
if (CUDA_SUCCESS !=
|
||||
cudaProducerReadARGBFrame(file_p, framenum, cudaProducer->width,
|
||||
cudaProducer->height, cudaProducer->pBuff)) {
|
||||
printf("cuda producer, read ARGB frame failed\n");
|
||||
goto done;
|
||||
}
|
||||
copyWidthInBytes[0] = cudaProducer->width * 4;
|
||||
copyHeight[0] = cudaProducer->height;
|
||||
surfNum = 1;
|
||||
eglColorFormat = CU_EGL_COLOR_FORMAT_ARGB;
|
||||
} else {
|
||||
if (CUDA_SUCCESS !=
|
||||
cudaProducerReadYUVFrame(file_p, framenum, cudaProducer->width,
|
||||
cudaProducer->height, cudaProducer->pBuff)) {
|
||||
printf("cuda producer, reading YUV frame failed\n");
|
||||
goto done;
|
||||
}
|
||||
surfNum = 3;
|
||||
eglColorFormat = CU_EGL_COLOR_FORMAT_YUV420_PLANAR;
|
||||
copyWidthInBytes[0] = cudaProducer->width;
|
||||
copyHeight[0] = cudaProducer->height;
|
||||
copyWidthInBytes[1] = cudaProducer->width / 2;
|
||||
copyHeight[1] = cudaProducer->height / 2;
|
||||
copyWidthInBytes[2] = cudaProducer->width / 2;
|
||||
copyHeight[2] = cudaProducer->height / 2;
|
||||
uvOffset[1] = cudaProducer->width * cudaProducer->height;
|
||||
uvOffset[2] =
|
||||
uvOffset[1] + cudaProducer->width / 2 * cudaProducer->height / 2;
|
||||
}
|
||||
if (cudaProducer->pitchLinearOutput) {
|
||||
for (i = 0; i < surfNum; i++) {
|
||||
cuStatus =
|
||||
cuMemcpy(cudaPtr[i], (CUdeviceptr)(cudaProducer->pBuff + uvOffset[i]),
|
||||
copyWidthInBytes[i] * copyHeight[i]);
|
||||
|
||||
if (cuStatus != CUDA_SUCCESS) {
|
||||
printf("Cuda producer: cuMemCpy pitchlinear failed, cuStatus =%d\n",
|
||||
cuStatus);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// copy cudaProducer->pBuff to cudaArray
|
||||
CUDA_MEMCPY3D cpdesc;
|
||||
for (i = 0; i < surfNum; i++) {
|
||||
memset(&cpdesc, 0, sizeof(cpdesc));
|
||||
cpdesc.srcXInBytes = cpdesc.srcY = cpdesc.srcZ = cpdesc.srcLOD = 0;
|
||||
cpdesc.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
cpdesc.srcHost = (void *)(cudaProducer->pBuff + uvOffset[i]);
|
||||
cpdesc.dstXInBytes = cpdesc.dstY = cpdesc.dstZ = cpdesc.dstLOD = 0;
|
||||
cpdesc.dstMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
cpdesc.dstArray = cudaArr[i];
|
||||
cpdesc.WidthInBytes = copyWidthInBytes[i];
|
||||
cpdesc.Height = copyHeight[i];
|
||||
cpdesc.Depth = 1;
|
||||
cuStatus = cuMemcpy3D(&cpdesc);
|
||||
if (cuStatus != CUDA_SUCCESS) {
|
||||
printf("Cuda producer: cuMemCpy failed, cuStatus =%d\n", cuStatus);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < surfNum; i++) {
|
||||
if (cudaProducer->pitchLinearOutput)
|
||||
cudaEgl.frame.pPitch[i] = (void *)cudaPtr[i];
|
||||
else
|
||||
cudaEgl.frame.pArray[i] = cudaArr[i];
|
||||
}
|
||||
cudaEgl.width = copyWidthInBytes[0];
|
||||
cudaEgl.depth = 1;
|
||||
cudaEgl.height = copyHeight[0];
|
||||
cudaEgl.pitch = cudaProducer->pitchLinearOutput ? cudaEgl.width : 0;
|
||||
cudaEgl.frameType = cudaProducer->pitchLinearOutput ? CU_EGL_FRAME_TYPE_PITCH
|
||||
: CU_EGL_FRAME_TYPE_ARRAY;
|
||||
cudaEgl.planeCount = surfNum;
|
||||
cudaEgl.numChannels = (eglColorFormat == CU_EGL_COLOR_FORMAT_ARGB) ? 4 : 1;
|
||||
cudaEgl.eglColorFormat = eglColorFormat;
|
||||
cudaEgl.cuFormat = CU_AD_FORMAT_UNSIGNED_INT8;
|
||||
|
||||
static int numFramesPresented = 0;
|
||||
// If there is a frame presented before we check if consumer
|
||||
// is done with it using cuEGLStreamProducerReturnFrame.
|
||||
while (numFramesPresented) {
|
||||
CUeglFrame returnedCudaEgl;
|
||||
cuStatus = cuEGLStreamProducerReturnFrame(&cudaProducer->cudaConn,
|
||||
&returnedCudaEgl, NULL);
|
||||
if (cuStatus == CUDA_ERROR_LAUNCH_TIMEOUT) {
|
||||
continue;
|
||||
} else if (cuStatus != CUDA_SUCCESS) {
|
||||
printf("cuda Producer return frame FAILED with custatus= %d\n", cuStatus);
|
||||
return cuStatus;
|
||||
} else {
|
||||
numFramesPresented--;
|
||||
}
|
||||
}
|
||||
|
||||
cuStatus =
|
||||
cuEGLStreamProducerPresentFrame(&cudaProducer->cudaConn, cudaEgl, NULL);
|
||||
if (cuStatus != CUDA_SUCCESS) {
|
||||
printf("cuda Producer present frame FAILED with custatus= %d\n", cuStatus);
|
||||
goto done;
|
||||
}
|
||||
numFramesPresented++;
|
||||
|
||||
done:
|
||||
if (file_p) {
|
||||
fclose(file_p);
|
||||
file_p = NULL;
|
||||
}
|
||||
|
||||
return cuStatus;
|
||||
}
|
||||
|
||||
CUresult cudaDeviceCreateProducer(test_cuda_producer_s *cudaProducer,
|
||||
CUdevice device) {
|
||||
CUresult status = CUDA_SUCCESS;
|
||||
if (CUDA_SUCCESS != (status = cuInit(0))) {
|
||||
printf("Failed to initialize CUDA\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
int major = 0, minor = 0;
|
||||
char deviceName[256];
|
||||
checkCudaErrors(cuDeviceGetAttribute(
|
||||
&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, device));
|
||||
checkCudaErrors(cuDeviceGetAttribute(
|
||||
&minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, device));
|
||||
checkCudaErrors(cuDeviceGetName(deviceName, 256, device));
|
||||
printf(
|
||||
"CUDA Producer on GPU Device %d: \"%s\" with compute capability "
|
||||
"%d.%d\n\n",
|
||||
device, deviceName, major, minor);
|
||||
|
||||
if (major < 6) {
|
||||
printf(
|
||||
"EGLStreams_CUDA_Interop requires SM 6.0 or higher arch GPU. "
|
||||
"Exiting...\n");
|
||||
exit(2); // EXIT_WAIVED
|
||||
}
|
||||
|
||||
if (CUDA_SUCCESS !=
|
||||
(status = cuCtxCreate(&cudaProducer->context, 0, device))) {
|
||||
printf("failed to create CUDA context\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
status = cuMemAlloc(&cudaProducer->cudaPtrARGB[0], (WIDTH * HEIGHT * 4));
|
||||
if (status != CUDA_SUCCESS) {
|
||||
printf("Create CUDA pointer failed, cuStatus=%d\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = cuMemAlloc(&cudaProducer->cudaPtrYUV[0], (WIDTH * HEIGHT));
|
||||
if (status != CUDA_SUCCESS) {
|
||||
printf("Create CUDA pointer failed, cuStatus=%d\n", status);
|
||||
return status;
|
||||
}
|
||||
status = cuMemAlloc(&cudaProducer->cudaPtrYUV[1], (WIDTH * HEIGHT) / 4);
|
||||
if (status != CUDA_SUCCESS) {
|
||||
printf("Create CUDA pointer failed, cuStatus=%d\n", status);
|
||||
return status;
|
||||
}
|
||||
status = cuMemAlloc(&cudaProducer->cudaPtrYUV[2], (WIDTH * HEIGHT) / 4);
|
||||
if (status != CUDA_SUCCESS) {
|
||||
printf("Create CUDA pointer failed, cuStatus=%d\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
CUDA_ARRAY3D_DESCRIPTOR desc = {0};
|
||||
|
||||
desc.Format = CU_AD_FORMAT_UNSIGNED_INT8;
|
||||
desc.Depth = 1;
|
||||
desc.Flags = CUDA_ARRAY3D_SURFACE_LDST;
|
||||
desc.NumChannels = 4;
|
||||
desc.Width = WIDTH * 4;
|
||||
desc.Height = HEIGHT;
|
||||
status = cuArray3DCreate(&cudaProducer->cudaArrARGB[0], &desc);
|
||||
if (status != CUDA_SUCCESS) {
|
||||
printf("Create CUDA array failed, cuStatus=%d\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (i == 0) {
|
||||
desc.NumChannels = 1;
|
||||
desc.Width = WIDTH;
|
||||
desc.Height = HEIGHT;
|
||||
} else { // U/V surface as planar
|
||||
desc.NumChannels = 1;
|
||||
desc.Width = WIDTH / 2;
|
||||
desc.Height = HEIGHT / 2;
|
||||
}
|
||||
status = cuArray3DCreate(&cudaProducer->cudaArrYUV[i], &desc);
|
||||
if (status != CUDA_SUCCESS) {
|
||||
printf("Create CUDA array failed, cuStatus=%d\n", status);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
cudaProducer->pBuff = (unsigned char *)malloc((WIDTH * HEIGHT * 4));
|
||||
if (!cudaProducer->pBuff) {
|
||||
printf("CudaProducer: Failed to allocate image buffer\n");
|
||||
}
|
||||
|
||||
checkCudaErrors(cuCtxPopCurrent(&cudaProducer->context));
|
||||
return status;
|
||||
}
|
||||
|
||||
void cudaProducerInit(test_cuda_producer_s *cudaProducer, EGLDisplay eglDisplay,
|
||||
EGLStreamKHR eglStream, TestArgs *args) {
|
||||
cudaProducer->fileName1 = args->infile1;
|
||||
cudaProducer->fileName2 = args->infile2;
|
||||
|
||||
cudaProducer->frameCount = 2;
|
||||
cudaProducer->width = args->inputWidth;
|
||||
cudaProducer->height = args->inputHeight;
|
||||
cudaProducer->isARGB = args->isARGB;
|
||||
cudaProducer->pitchLinearOutput = args->pitchLinearOutput;
|
||||
|
||||
// Set cudaProducer default parameters
|
||||
cudaProducer->eglDisplay = eglDisplay;
|
||||
cudaProducer->eglStream = eglStream;
|
||||
}
|
||||
|
||||
CUresult cudaProducerDeinit(test_cuda_producer_s *cudaProducer) {
|
||||
if (cudaProducer->pBuff) free(cudaProducer->pBuff);
|
||||
|
||||
checkCudaErrors(cuMemFree(cudaProducer->cudaPtrARGB[0]));
|
||||
checkCudaErrors(cuMemFree(cudaProducer->cudaPtrYUV[0]));
|
||||
checkCudaErrors(cuMemFree(cudaProducer->cudaPtrYUV[1]));
|
||||
checkCudaErrors(cuMemFree(cudaProducer->cudaPtrYUV[2]));
|
||||
checkCudaErrors(cuArrayDestroy(cudaProducer->cudaArrARGB[0]));
|
||||
checkCudaErrors(cuArrayDestroy(cudaProducer->cudaArrYUV[0]));
|
||||
checkCudaErrors(cuArrayDestroy(cudaProducer->cudaArrYUV[1]));
|
||||
checkCudaErrors(cuArrayDestroy(cudaProducer->cudaArrYUV[2]));
|
||||
|
||||
return cuEGLStreamProducerDisconnect(&cudaProducer->cudaConn);
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
//
|
||||
// DESCRIPTION: Simple cuda producer header file
|
||||
//
|
||||
|
||||
#ifndef _CUDA_PRODUCER_H_
|
||||
#define _CUDA_PRODUCER_H_
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#include "cudaEGL.h"
|
||||
#include "eglstrm_common.h"
|
||||
|
||||
extern EGLStreamKHR eglStream;
|
||||
extern EGLDisplay g_display;
|
||||
|
||||
typedef struct _test_cuda_producer_s {
|
||||
// Stream params
|
||||
char *fileName1;
|
||||
char *fileName2;
|
||||
unsigned char *pBuff;
|
||||
int frameCount;
|
||||
bool isARGB;
|
||||
bool pitchLinearOutput;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
CUcontext context;
|
||||
CUeglStreamConnection cudaConn;
|
||||
CUdeviceptr cudaPtrARGB[1];
|
||||
CUdeviceptr cudaPtrYUV[3];
|
||||
CUarray cudaArrARGB[1];
|
||||
CUarray cudaArrYUV[3];
|
||||
EGLStreamKHR eglStream;
|
||||
EGLDisplay eglDisplay;
|
||||
} test_cuda_producer_s;
|
||||
|
||||
void cudaProducerInit(test_cuda_producer_s *cudaProducer, EGLDisplay eglDisplay,
|
||||
EGLStreamKHR eglStream, TestArgs *args);
|
||||
CUresult cudaProducerTest(test_cuda_producer_s *parserArg, char *file);
|
||||
CUresult cudaProducerDeinit(test_cuda_producer_s *cudaProducer);
|
||||
CUresult cudaDeviceCreateProducer(test_cuda_producer_s *cudaProducer,
|
||||
CUdevice device);
|
||||
#endif
|
||||
@@ -1,139 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
//
|
||||
// DESCRIPTION: Common egl stream functions
|
||||
//
|
||||
|
||||
#include "eglstrm_common.h"
|
||||
|
||||
EGLStreamKHR eglStream;
|
||||
EGLDisplay g_display;
|
||||
EGLAttrib cudaIndex;
|
||||
|
||||
#if defined(EXTENSION_LIST)
|
||||
EXTENSION_LIST(EXTLST_DECL)
|
||||
typedef void (*extlst_fnptr_t)(void);
|
||||
static struct {
|
||||
extlst_fnptr_t *fnptr;
|
||||
char const *name;
|
||||
} extensionList[] = {EXTENSION_LIST(EXTLST_ENTRY)};
|
||||
|
||||
int eglSetupExtensions(void) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < (sizeof(extensionList) / sizeof(*extensionList)); i++) {
|
||||
*extensionList[i].fnptr = eglGetProcAddress(extensionList[i].name);
|
||||
if (*extensionList[i].fnptr == NULL) {
|
||||
printf("Couldn't get address of %s()\n", extensionList[i].name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EGLStreamInit(int *cuda_device) {
|
||||
static const EGLint streamAttrMailboxMode[] = {EGL_SUPPORT_REUSE_NV,
|
||||
EGL_FALSE, EGL_NONE};
|
||||
EGLBoolean eglStatus;
|
||||
#define MAX_EGL_DEVICES 4
|
||||
EGLint numDevices = 0;
|
||||
EGLDeviceEXT devices[MAX_EGL_DEVICES];
|
||||
eglStatus = eglQueryDevicesEXT(MAX_EGL_DEVICES, devices, &numDevices);
|
||||
if (eglStatus != EGL_TRUE) {
|
||||
printf("Error querying EGL devices\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (numDevices == 0) {
|
||||
printf("No EGL devices found.. Waiving\n");
|
||||
eglStatus = EGL_FALSE;
|
||||
exit(EXIT_WAIVED);
|
||||
}
|
||||
|
||||
int egl_device_id = 0;
|
||||
for (egl_device_id = 0; egl_device_id < numDevices; egl_device_id++) {
|
||||
eglStatus = eglQueryDeviceAttribEXT(devices[egl_device_id],
|
||||
EGL_CUDA_DEVICE_NV, &cudaIndex);
|
||||
if (eglStatus == EGL_TRUE) {
|
||||
*cuda_device = cudaIndex; // We select first EGL-CUDA Capable device.
|
||||
printf("Found EGL-CUDA Capable device with CUDA Device id = %d\n",
|
||||
(int)cudaIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (egl_device_id >= numDevices) {
|
||||
printf("No CUDA Capable EGL Device found.. Waiving execution\n");
|
||||
exit(EXIT_WAIVED);
|
||||
}
|
||||
|
||||
g_display = eglGetPlatformDisplayEXT(EGL_PLATFORM_DEVICE_EXT,
|
||||
(void *)devices[egl_device_id], NULL);
|
||||
if (g_display == EGL_NO_DISPLAY) {
|
||||
printf("Could not get EGL display from device. \n");
|
||||
eglStatus = EGL_FALSE;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
eglStatus = eglInitialize(g_display, 0, 0);
|
||||
if (!eglStatus) {
|
||||
printf("EGL failed to initialize. \n");
|
||||
eglStatus = EGL_FALSE;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
eglStream = eglCreateStreamKHR(g_display, streamAttrMailboxMode);
|
||||
if (eglStream == EGL_NO_STREAM_KHR) {
|
||||
printf("Could not create EGL stream.\n");
|
||||
eglStatus = EGL_FALSE;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Created EGLStream %p\n", eglStream);
|
||||
|
||||
// Set stream attribute
|
||||
if (!eglStreamAttribKHR(g_display, eglStream, EGL_CONSUMER_LATENCY_USEC_KHR,
|
||||
16000)) {
|
||||
printf(
|
||||
"Consumer: eglStreamAttribKHR EGL_CONSUMER_LATENCY_USEC_KHR failed\n");
|
||||
return 0;
|
||||
}
|
||||
if (!eglStreamAttribKHR(g_display, eglStream,
|
||||
EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR, 16000)) {
|
||||
printf(
|
||||
"Consumer: eglStreamAttribKHR EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR "
|
||||
"failed\n");
|
||||
return 0;
|
||||
}
|
||||
printf("EGLStream initialized\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
void EGLStreamFini(void) { eglDestroyStreamKHR(g_display, eglStream); }
|
||||
#endif
|
||||
@@ -1,103 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
//
|
||||
// DESCRIPTION: Common EGL stream functions header file
|
||||
//
|
||||
|
||||
#ifndef _EGLSTRM_COMMON_H_
|
||||
#define _EGLSTRM_COMMON_H_
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "cuda.h"
|
||||
#include "cudaEGL.h"
|
||||
#include "helper_cuda_drvapi.h"
|
||||
|
||||
#define EXTENSION_LIST(T) \
|
||||
T(PFNEGLCREATESTREAMKHRPROC, eglCreateStreamKHR) \
|
||||
T(PFNEGLDESTROYSTREAMKHRPROC, eglDestroyStreamKHR) \
|
||||
T(PFNEGLQUERYSTREAMKHRPROC, eglQueryStreamKHR) \
|
||||
T(PFNEGLQUERYSTREAMU64KHRPROC, eglQueryStreamu64KHR) \
|
||||
T(PFNEGLQUERYSTREAMTIMEKHRPROC, eglQueryStreamTimeKHR) \
|
||||
T(PFNEGLSTREAMATTRIBKHRPROC, eglStreamAttribKHR) \
|
||||
T(PFNEGLSTREAMCONSUMERACQUIREKHRPROC, eglStreamConsumerAcquireKHR) \
|
||||
T(PFNEGLSTREAMCONSUMERRELEASEKHRPROC, eglStreamConsumerReleaseKHR) \
|
||||
T(PFNEGLSTREAMCONSUMERGLTEXTUREEXTERNALKHRPROC, \
|
||||
eglStreamConsumerGLTextureExternalKHR) \
|
||||
T(PFNEGLGETSTREAMFILEDESCRIPTORKHRPROC, eglGetStreamFileDescriptorKHR) \
|
||||
T(PFNEGLQUERYDEVICESEXTPROC, eglQueryDevicesEXT) \
|
||||
T(PFNEGLGETPLATFORMDISPLAYEXTPROC, eglGetPlatformDisplayEXT) \
|
||||
T(PFNEGLQUERYDEVICEATTRIBEXTPROC, eglQueryDeviceAttribEXT) \
|
||||
T(PFNEGLCREATESTREAMFROMFILEDESCRIPTORKHRPROC, \
|
||||
eglCreateStreamFromFileDescriptorKHR)
|
||||
|
||||
#define eglCreateStreamKHR my_eglCreateStreamKHR
|
||||
#define eglDestroyStreamKHR my_eglDestroyStreamKHR
|
||||
#define eglQueryStreamKHR my_eglQueryStreamKHR
|
||||
#define eglQueryStreamu64KHR my_eglQueryStreamu64KHR
|
||||
#define eglQueryStreamTimeKHR my_eglQueryStreamTimeKHR
|
||||
#define eglStreamAttribKHR my_eglStreamAttribKHR
|
||||
#define eglStreamConsumerAcquireKHR my_eglStreamConsumerAcquireKHR
|
||||
#define eglStreamConsumerReleaseKHR my_eglStreamConsumerReleaseKHR
|
||||
#define eglStreamConsumerGLTextureExternalKHR \
|
||||
my_eglStreamConsumerGLTextureExternalKHR
|
||||
#define eglGetStreamFileDescriptorKHR my_eglGetStreamFileDescriptorKHR
|
||||
#define eglCreateStreamFromFileDescriptorKHR \
|
||||
my_eglCreateStreamFromFileDescriptorKHR
|
||||
#define eglQueryDevicesEXT my_eglQueryDevicesEXT
|
||||
#define eglGetPlatformDisplayEXT my_eglGetPlatformDisplayEXT
|
||||
#define eglQueryDeviceAttribEXT my_eglQueryDeviceAttribEXT
|
||||
|
||||
#define EXTLST_DECL(tx, x) tx my_##x = NULL;
|
||||
#define EXTLST_EXTERN(tx, x) extern tx my_##x;
|
||||
#define EXTLST_ENTRY(tx, x) {(extlst_fnptr_t *)&my_##x, #x},
|
||||
|
||||
#define MAX_STRING_SIZE 256
|
||||
#define WIDTH 720
|
||||
#define HEIGHT 480
|
||||
|
||||
typedef struct _TestArgs {
|
||||
char *infile1;
|
||||
char *infile2;
|
||||
bool isARGB;
|
||||
unsigned int inputWidth;
|
||||
unsigned int inputHeight;
|
||||
bool pitchLinearOutput;
|
||||
} TestArgs;
|
||||
|
||||
int eglSetupExtensions(void);
|
||||
int EGLStreamInit(int *dev);
|
||||
void EGLStreamFini(void);
|
||||
#endif
|
||||
@@ -1,160 +0,0 @@
|
||||
################################################################################
|
||||
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# findegl.mk is used to find the necessary EGL Libraries for specific distributions
|
||||
# this is supported on Linux
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# Determine OS platform and unix distribution
|
||||
ifeq ("$(TARGET_OS)","linux")
|
||||
# first search lsb_release
|
||||
DISTRO = $(shell lsb_release -i -s 2>/dev/null | tr "[:upper:]" "[:lower:]")
|
||||
ifeq ("$(DISTRO)","")
|
||||
# second search and parse /etc/issue
|
||||
DISTRO = $(shell more /etc/issue | awk '{print $$1}' | sed '1!d' | sed -e "/^$$/d" 2>/dev/null | tr "[:upper:]" "[:lower:]")
|
||||
# ensure data from /etc/issue is valid
|
||||
ifeq (,$(filter $(DISTRO),ubuntu fedora red rhel centos suse))
|
||||
DISTRO =
|
||||
endif
|
||||
ifeq ("$(DISTRO)","")
|
||||
# third, we can search in /etc/os-release or /etc/{distro}-release
|
||||
DISTRO = $(shell awk '/ID/' /etc/*-release | sed 's/ID=//' | grep -v "VERSION" | grep -v "ID" | grep -v "DISTRIB")
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ("$(TARGET_OS)","linux")
|
||||
# $(info) >> findegl.mk -> LINUX path <<<)
|
||||
# Each set of Linux Distros have different paths for where to find their OpenGL libraries reside
|
||||
UBUNTU = $(shell echo $(DISTRO) | grep -i ubuntu >/dev/null 2>&1; echo $$?)
|
||||
FEDORA = $(shell echo $(DISTRO) | grep -i fedora >/dev/null 2>&1; echo $$?)
|
||||
RHEL = $(shell echo $(DISTRO) | grep -i 'red\|rhel' >/dev/null 2>&1; echo $$?)
|
||||
CENTOS = $(shell echo $(DISTRO) | grep -i centos >/dev/null 2>&1; echo $$?)
|
||||
SUSE = $(shell echo $(DISTRO) | grep -i 'suse\|sles' >/dev/null 2>&1; echo $$?)
|
||||
ifeq ("$(UBUNTU)","0")
|
||||
ifeq ($(HOST_ARCH)-$(TARGET_ARCH),x86_64-armv7l)
|
||||
GLPATH := /usr/arm-linux-gnueabihf/lib
|
||||
GLLINK := -L/usr/arm-linux-gnueabihf/lib
|
||||
ifneq ($(TARGET_FS),)
|
||||
GLPATH += $(TARGET_FS)/usr/lib/arm-linux-gnueabihf
|
||||
GLLINK += -L$(TARGET_FS)/usr/lib/arm-linux-gnueabihf
|
||||
endif
|
||||
else ifeq ($(HOST_ARCH)-$(TARGET_ARCH),x86_64-aarch64)
|
||||
GLPATH := /usr/aarch64-linux-gnu/lib
|
||||
GLLINK := -L/usr/aarch64-linux-gnu/lib
|
||||
ifneq ($(TARGET_FS),)
|
||||
GLPATH += $(TARGET_FS)/usr/lib
|
||||
GLPATH += $(TARGET_FS)/usr/lib/aarch64-linux-gnu
|
||||
GLLINK += -L$(TARGET_FS)/usr/lib/aarch64-linux-gnu
|
||||
endif
|
||||
else
|
||||
UBUNTU_PKG_NAME = $(shell which dpkg >/dev/null 2>&1 && dpkg -l 'nvidia-*' | grep '^ii' | awk '{print $$2}' | head -1)
|
||||
ifneq ("$(UBUNTU_PKG_NAME)","")
|
||||
GLPATH ?= /usr/lib/$(UBUNTU_PKG_NAME)
|
||||
GLLINK ?= -L/usr/lib/$(UBUNTU_PKG_NAME)
|
||||
endif
|
||||
|
||||
DFLT_PATH ?= /usr/lib
|
||||
endif
|
||||
endif
|
||||
ifeq ("$(SUSE)","0")
|
||||
GLPATH ?= /usr/X11R6/lib64
|
||||
GLLINK ?= -L/usr/X11R6/lib64
|
||||
DFLT_PATH ?= /usr/lib64
|
||||
endif
|
||||
ifeq ("$(FEDORA)","0")
|
||||
GLPATH ?= /usr/lib64/nvidia
|
||||
GLLINK ?= -L/usr/lib64/nvidia
|
||||
DFLT_PATH ?= /usr/lib64
|
||||
endif
|
||||
ifeq ("$(RHEL)","0")
|
||||
GLPATH ?= /usr/lib64/nvidia
|
||||
GLLINK ?= -L/usr/lib64/nvidia
|
||||
DFLT_PATH ?= /usr/lib64
|
||||
endif
|
||||
ifeq ("$(CENTOS)","0")
|
||||
GLPATH ?= /usr/lib64/nvidia
|
||||
GLLINK ?= -L/usr/lib64/nvidia
|
||||
DFLT_PATH ?= /usr/lib64
|
||||
endif
|
||||
|
||||
EGLLIB := $(shell find -L $(GLPATH) $(DFLT_PATH) -name libEGL.so -print 2>/dev/null)
|
||||
|
||||
ifeq ("$(EGLLIB)","")
|
||||
$(info >>> WARNING - libEGL.so not found, please install libEGL.so <<<)
|
||||
SAMPLE_ENABLED := 0
|
||||
endif
|
||||
|
||||
HEADER_SEARCH_PATH ?= $(TARGET_FS)/usr/include
|
||||
ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_OS),x86_64-armv7l-linux)
|
||||
HEADER_SEARCH_PATH += /usr/arm-linux-gnueabihf/include
|
||||
else ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_OS),x86_64-aarch64-linux)
|
||||
HEADER_SEARCH_PATH += /usr/aarch64-linux-gnu/include
|
||||
endif
|
||||
|
||||
EGLHEADER := $(shell find -L $(HEADER_SEARCH_PATH) -name egl.h -print 2>/dev/null)
|
||||
EGLEXTHEADER := $(shell find -L $(HEADER_SEARCH_PATH) -name eglext.h -print 2>/dev/null)
|
||||
|
||||
ifeq ("$(EGLHEADER)","")
|
||||
$(info >>> WARNING - egl.h not found, please install egl.h <<<)
|
||||
SAMPLE_ENABLED := 0
|
||||
endif
|
||||
ifeq ("$(EGLEXTHEADER)","")
|
||||
$(info >>> WARNING - eglext.h not found, please install eglext.h <<<)
|
||||
SAMPLE_ENABLED := 0
|
||||
endif
|
||||
else
|
||||
endif
|
||||
|
||||
ifeq ("$(TARGET_OS)","qnx")
|
||||
HOST_CCFLAGS := -V5.4.0,gcc_ntoaarch64le
|
||||
endif
|
||||
|
||||
# Attempt to compile a minimal EGL application and run to check if EGL_SUPPORT_REUSE_NV is supported in the EGL headers available.
|
||||
ifneq ($(SAMPLE_ENABLED), 0)
|
||||
$(shell printf "#include <EGL/egl.h>\n#include <EGL/eglext.h>\nint main() {\n#ifdef EGL_SUPPORT_REUSE_NV \n #error \"Compatible EGL header found\" \n return 0;\n#endif \n return 1;\n}" > test.c; )
|
||||
EGL_DEFINES := $(shell $(HOST_COMPILER) $(HOST_CCFLAGS) $(CCFLAGS) $(EXTRA_CCFLAGS) -lEGL test.c -c 2>&1 | grep -ic "Compatible EGL header found";)
|
||||
SHOULD_WAIVE := 0
|
||||
ifeq ($(EGL_DEFINES),0)
|
||||
SHOULD_WAIVE := 1
|
||||
endif
|
||||
ifeq ($(SHOULD_WAIVE),1)
|
||||
$(info -----------------------------------------------------------------------------------------------)
|
||||
$(info WARNING - NVIDIA EGL EXTENSIONS are not available in the present EGL headers)
|
||||
$(info -----------------------------------------------------------------------------------------------)
|
||||
$(info This CUDA Sample cannot be built if the EGL NVIDIA EXTENSIONS like EGL_SUPPORT_REUSE_NV are not supported in EGL headers.)
|
||||
$(info This will be a dry-run of the Makefile.)
|
||||
$(info Please install the latest khronos EGL headers and libs to build this sample)
|
||||
$(info -----------------------------------------------------------------------------------------------)
|
||||
SAMPLE_ENABLED := 0
|
||||
endif
|
||||
$(shell rm test.o test.c 2>/dev/null)
|
||||
endif
|
||||
|
||||
@@ -1,231 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
//
|
||||
// DESCRIPTION: Simple EGL stream sample app
|
||||
//
|
||||
//
|
||||
|
||||
//#define EGL_EGLEXT_PROTOTYPES
|
||||
|
||||
#include "cudaEGL.h"
|
||||
#include "cuda_consumer.h"
|
||||
#include "cuda_producer.h"
|
||||
#include "eglstrm_common.h"
|
||||
|
||||
/* ------ globals ---------*/
|
||||
|
||||
#if defined(EXTENSION_LIST)
|
||||
EXTENSION_LIST(EXTLST_EXTERN)
|
||||
#endif
|
||||
|
||||
#define NUM_TRAILS 4
|
||||
|
||||
bool signal_stop = 0;
|
||||
|
||||
static void sig_handler(int sig) {
|
||||
signal_stop = 1;
|
||||
printf("Signal: %d\n", sig);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
TestArgs args;
|
||||
CUresult curesult = CUDA_SUCCESS;
|
||||
unsigned int i, j;
|
||||
EGLint streamState = 0;
|
||||
|
||||
test_cuda_consumer_s cudaConsumer;
|
||||
test_cuda_producer_s cudaProducer;
|
||||
|
||||
memset(&cudaProducer, 0, sizeof(test_cuda_producer_s));
|
||||
memset(&cudaConsumer, 0, sizeof(test_cuda_consumer_s));
|
||||
|
||||
// Hook up Ctrl-C handler
|
||||
signal(SIGINT, sig_handler);
|
||||
if (!eglSetupExtensions()) {
|
||||
printf("SetupExtentions failed \n");
|
||||
curesult = CUDA_ERROR_UNKNOWN;
|
||||
goto done;
|
||||
}
|
||||
|
||||
checkCudaErrors(cuInit(0));
|
||||
|
||||
int count;
|
||||
|
||||
checkCudaErrors(cuDeviceGetCount(&count));
|
||||
printf("Found %d cuda devices\n", count);
|
||||
|
||||
CUdevice devId;
|
||||
|
||||
if (!EGLStreamInit(&devId)) {
|
||||
printf("EGLStream Init failed.\n");
|
||||
curesult = CUDA_ERROR_UNKNOWN;
|
||||
goto done;
|
||||
}
|
||||
curesult = cudaDeviceCreateProducer(&cudaProducer, devId);
|
||||
if (curesult != CUDA_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
curesult = cudaDeviceCreateConsumer(&cudaConsumer, devId);
|
||||
if (curesult != CUDA_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
checkCudaErrors(cuCtxPushCurrent(cudaConsumer.context));
|
||||
if (CUDA_SUCCESS != (curesult = cuEGLStreamConsumerConnect(
|
||||
&(cudaConsumer.cudaConn), eglStream))) {
|
||||
printf("FAILED Connect CUDA consumer with error %d\n", curesult);
|
||||
goto done;
|
||||
} else {
|
||||
printf("Connected CUDA consumer, CudaConsumer %p\n", cudaConsumer.cudaConn);
|
||||
}
|
||||
checkCudaErrors(cuCtxPopCurrent(&cudaConsumer.context));
|
||||
|
||||
checkCudaErrors(cuCtxPushCurrent(cudaProducer.context));
|
||||
if (CUDA_SUCCESS ==
|
||||
(curesult = cuEGLStreamProducerConnect(&(cudaProducer.cudaConn),
|
||||
eglStream, WIDTH, HEIGHT))) {
|
||||
printf("Connect CUDA producer Done, CudaProducer %p\n",
|
||||
cudaProducer.cudaConn);
|
||||
} else {
|
||||
printf("Connect CUDA producer FAILED with error %d\n", curesult);
|
||||
goto done;
|
||||
}
|
||||
checkCudaErrors(cuCtxPopCurrent(&cudaProducer.context));
|
||||
|
||||
// Initialize producer
|
||||
for (i = 0; i < NUM_TRAILS; i++) {
|
||||
if (streamState != EGL_STREAM_STATE_CONNECTING_KHR) {
|
||||
if (!eglQueryStreamKHR(g_display, eglStream, EGL_STREAM_STATE_KHR,
|
||||
&streamState)) {
|
||||
printf("main: eglQueryStreamKHR EGL_STREAM_STATE_KHR failed\n");
|
||||
curesult = CUDA_ERROR_UNKNOWN;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
args.inputWidth = WIDTH;
|
||||
args.inputHeight = HEIGHT;
|
||||
if (i % 2 != 0) {
|
||||
args.isARGB = 1;
|
||||
args.infile1 = sdkFindFilePath("cuda_f_1.yuv", argv[0]);
|
||||
args.infile2 = sdkFindFilePath("cuda_f_2.yuv", argv[0]);
|
||||
} else {
|
||||
args.isARGB = 0;
|
||||
args.infile1 = sdkFindFilePath("cuda_yuv_f_1.yuv", argv[0]);
|
||||
args.infile2 = sdkFindFilePath("cuda_yuv_f_2.yuv", argv[0]);
|
||||
}
|
||||
if ((i % 4) < 2) {
|
||||
args.pitchLinearOutput = 1;
|
||||
} else {
|
||||
args.pitchLinearOutput = 0;
|
||||
}
|
||||
|
||||
checkCudaErrors(cuCtxPushCurrent(cudaProducer.context));
|
||||
cudaProducerInit(&cudaProducer, g_display, eglStream, &args);
|
||||
checkCudaErrors(cuCtxPopCurrent(&cudaProducer.context));
|
||||
|
||||
checkCudaErrors(cuCtxPushCurrent(cudaConsumer.context));
|
||||
cuda_consumer_init(&cudaConsumer, &args);
|
||||
checkCudaErrors(cuCtxPopCurrent(&cudaConsumer.context));
|
||||
|
||||
printf("main - Cuda Producer and Consumer Initialized.\n");
|
||||
|
||||
for (j = 0; j < 2; j++) {
|
||||
printf("Running for %s frame and %s input\n",
|
||||
args.isARGB ? "ARGB" : "YUV",
|
||||
args.pitchLinearOutput ? "Pitchlinear" : "BlockLinear");
|
||||
if (j == 0) {
|
||||
checkCudaErrors(cuCtxPushCurrent(cudaProducer.context));
|
||||
curesult = cudaProducerTest(&cudaProducer, cudaProducer.fileName1);
|
||||
if (curesult != CUDA_SUCCESS) {
|
||||
printf("Cuda Producer Test failed for frame = %d\n", j + 1);
|
||||
goto done;
|
||||
}
|
||||
checkCudaErrors(cuCtxPopCurrent(&cudaProducer.context));
|
||||
checkCudaErrors(cuCtxPushCurrent(cudaConsumer.context));
|
||||
curesult = cudaConsumerTest(&cudaConsumer, cudaConsumer.outFile1);
|
||||
if (curesult != CUDA_SUCCESS) {
|
||||
printf("Cuda Consumer Test failed for frame = %d\n", j + 1);
|
||||
goto done;
|
||||
}
|
||||
checkCudaErrors(cuCtxPopCurrent(&cudaConsumer.context));
|
||||
} else {
|
||||
checkCudaErrors(cuCtxPushCurrent(cudaProducer.context));
|
||||
curesult = cudaProducerTest(&cudaProducer, cudaProducer.fileName2);
|
||||
if (curesult != CUDA_SUCCESS) {
|
||||
printf("Cuda Producer Test failed for frame = %d\n", j + 1);
|
||||
goto done;
|
||||
}
|
||||
|
||||
checkCudaErrors(cuCtxPopCurrent(&cudaProducer.context));
|
||||
checkCudaErrors(cuCtxPushCurrent(cudaConsumer.context));
|
||||
curesult = cudaConsumerTest(&cudaConsumer, cudaConsumer.outFile2);
|
||||
if (curesult != CUDA_SUCCESS) {
|
||||
printf("Cuda Consumer Test failed for frame = %d\n", j + 1);
|
||||
goto done;
|
||||
}
|
||||
checkCudaErrors(cuCtxPopCurrent(&cudaConsumer.context));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkCudaErrors(cuCtxPushCurrent(cudaProducer.context));
|
||||
if (CUDA_SUCCESS != (curesult = cudaProducerDeinit(&cudaProducer))) {
|
||||
printf("Producer Disconnect FAILED. \n");
|
||||
goto done;
|
||||
}
|
||||
checkCudaErrors(cuCtxPopCurrent(&cudaProducer.context));
|
||||
|
||||
if (!eglQueryStreamKHR(g_display, eglStream, EGL_STREAM_STATE_KHR,
|
||||
&streamState)) {
|
||||
printf("Cuda consumer, eglQueryStreamKHR EGL_STREAM_STATE_KHR failed\n");
|
||||
curesult = CUDA_ERROR_UNKNOWN;
|
||||
goto done;
|
||||
}
|
||||
if (streamState != EGL_STREAM_STATE_DISCONNECTED_KHR) {
|
||||
if (CUDA_SUCCESS != (curesult = cuda_consumer_deinit(&cudaConsumer))) {
|
||||
printf("Consumer Disconnect FAILED.\n");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
printf("Producer and Consumer Disconnected \n");
|
||||
|
||||
done:
|
||||
if (!eglQueryStreamKHR(g_display, eglStream, EGL_STREAM_STATE_KHR,
|
||||
&streamState)) {
|
||||
printf("Cuda consumer, eglQueryStreamKHR EGL_STREAM_STATE_KHR failed\n");
|
||||
curesult = CUDA_ERROR_UNKNOWN;
|
||||
}
|
||||
if (streamState != EGL_STREAM_STATE_DISCONNECTED_KHR) {
|
||||
EGLStreamFini();
|
||||
}
|
||||
|
||||
if (curesult == CUDA_SUCCESS) {
|
||||
printf("&&&& EGLStream interop test PASSED\n");
|
||||
} else {
|
||||
printf("&&&& EGLStream interop test FAILED\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,322 +0,0 @@
|
||||
################################################################################
|
||||
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# Makefile project only supported on Mac OS X and Linux Platforms)
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# Location of the CUDA Toolkit
|
||||
CUDA_PATH ?= /usr/local/cuda
|
||||
|
||||
##############################
|
||||
# start deprecated interface #
|
||||
##############################
|
||||
ifeq ($(x86_64),1)
|
||||
$(info WARNING - x86_64 variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=x86_64 instead)
|
||||
TARGET_ARCH ?= x86_64
|
||||
endif
|
||||
ifeq ($(ARMv7),1)
|
||||
$(info WARNING - ARMv7 variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=armv7l instead)
|
||||
TARGET_ARCH ?= armv7l
|
||||
endif
|
||||
ifeq ($(aarch64),1)
|
||||
$(info WARNING - aarch64 variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=aarch64 instead)
|
||||
TARGET_ARCH ?= aarch64
|
||||
endif
|
||||
ifeq ($(ppc64le),1)
|
||||
$(info WARNING - ppc64le variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=ppc64le instead)
|
||||
TARGET_ARCH ?= ppc64le
|
||||
endif
|
||||
ifneq ($(GCC),)
|
||||
$(info WARNING - GCC variable has been deprecated)
|
||||
$(info WARNING - please use HOST_COMPILER=$(GCC) instead)
|
||||
HOST_COMPILER ?= $(GCC)
|
||||
endif
|
||||
ifneq ($(abi),)
|
||||
$(error ERROR - abi variable has been removed)
|
||||
endif
|
||||
############################
|
||||
# end deprecated interface #
|
||||
############################
|
||||
|
||||
# architecture
|
||||
HOST_ARCH := $(shell uname -m)
|
||||
TARGET_ARCH ?= $(HOST_ARCH)
|
||||
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le armv7l))
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le))
|
||||
TARGET_SIZE := 64
|
||||
else ifneq (,$(filter $(TARGET_ARCH),armv7l))
|
||||
TARGET_SIZE := 32
|
||||
endif
|
||||
else
|
||||
TARGET_SIZE := $(shell getconf LONG_BIT)
|
||||
endif
|
||||
else
|
||||
$(error ERROR - unsupported value $(TARGET_ARCH) for TARGET_ARCH!)
|
||||
endif
|
||||
|
||||
# sbsa and aarch64 systems look similar. Need to differentiate them at host level for now.
|
||||
ifeq ($(HOST_ARCH),aarch64)
|
||||
ifeq ($(CUDA_PATH)/targets/sbsa-linux,$(shell ls -1d $(CUDA_PATH)/targets/sbsa-linux 2>/dev/null))
|
||||
HOST_ARCH := sbsa
|
||||
TARGET_ARCH := sbsa
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq (,$(filter $(HOST_ARCH)-$(TARGET_ARCH),aarch64-armv7l x86_64-armv7l x86_64-aarch64 x86_64-sbsa x86_64-ppc64le))
|
||||
$(error ERROR - cross compiling from $(HOST_ARCH) to $(TARGET_ARCH) is not supported!)
|
||||
endif
|
||||
endif
|
||||
|
||||
# When on native aarch64 system with userspace of 32-bit, change TARGET_ARCH to armv7l
|
||||
ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_SIZE),aarch64-aarch64-32)
|
||||
TARGET_ARCH = armv7l
|
||||
endif
|
||||
|
||||
# operating system
|
||||
HOST_OS := $(shell uname -s 2>/dev/null | tr "[:upper:]" "[:lower:]")
|
||||
TARGET_OS ?= $(HOST_OS)
|
||||
ifeq (,$(filter $(TARGET_OS),linux darwin qnx android))
|
||||
$(error ERROR - unsupported value $(TARGET_OS) for TARGET_OS!)
|
||||
endif
|
||||
|
||||
# host compiler
|
||||
ifeq ($(TARGET_OS),darwin)
|
||||
ifeq ($(shell expr `xcodebuild -version | grep -i xcode | awk '{print $$2}' | cut -d'.' -f1` \>= 5),1)
|
||||
HOST_COMPILER ?= clang++
|
||||
endif
|
||||
else ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq ($(HOST_ARCH)-$(TARGET_ARCH),x86_64-armv7l)
|
||||
ifeq ($(TARGET_OS),linux)
|
||||
HOST_COMPILER ?= arm-linux-gnueabihf-g++
|
||||
else ifeq ($(TARGET_OS),qnx)
|
||||
ifeq ($(QNX_HOST),)
|
||||
$(error ERROR - QNX_HOST must be passed to the QNX host toolchain)
|
||||
endif
|
||||
ifeq ($(QNX_TARGET),)
|
||||
$(error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
|
||||
endif
|
||||
export QNX_HOST
|
||||
export QNX_TARGET
|
||||
HOST_COMPILER ?= $(QNX_HOST)/usr/bin/arm-unknown-nto-qnx6.6.0eabi-g++
|
||||
else ifeq ($(TARGET_OS),android)
|
||||
HOST_COMPILER ?= arm-linux-androideabi-g++
|
||||
endif
|
||||
else ifeq ($(TARGET_ARCH),aarch64)
|
||||
ifeq ($(TARGET_OS), linux)
|
||||
HOST_COMPILER ?= aarch64-linux-gnu-g++
|
||||
else ifeq ($(TARGET_OS),qnx)
|
||||
ifeq ($(QNX_HOST),)
|
||||
$(error ERROR - QNX_HOST must be passed to the QNX host toolchain)
|
||||
endif
|
||||
ifeq ($(QNX_TARGET),)
|
||||
$(error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
|
||||
endif
|
||||
export QNX_HOST
|
||||
export QNX_TARGET
|
||||
HOST_COMPILER ?= $(QNX_HOST)/usr/bin/q++
|
||||
else ifeq ($(TARGET_OS), android)
|
||||
HOST_COMPILER ?= aarch64-linux-android-clang++
|
||||
endif
|
||||
else ifeq ($(TARGET_ARCH),sbsa)
|
||||
HOST_COMPILER ?= aarch64-linux-gnu-g++
|
||||
else ifeq ($(TARGET_ARCH),ppc64le)
|
||||
HOST_COMPILER ?= powerpc64le-linux-gnu-g++
|
||||
endif
|
||||
endif
|
||||
HOST_COMPILER ?= g++
|
||||
NVCC := $(CUDA_PATH)/bin/nvcc -ccbin $(HOST_COMPILER)
|
||||
|
||||
# internal flags
|
||||
NVCCFLAGS := -m${TARGET_SIZE}
|
||||
CCFLAGS :=
|
||||
LDFLAGS :=
|
||||
|
||||
# build flags
|
||||
ifeq ($(TARGET_OS),darwin)
|
||||
LDFLAGS += -rpath $(CUDA_PATH)/lib
|
||||
CCFLAGS += -arch $(HOST_ARCH)
|
||||
else ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_OS),x86_64-armv7l-linux)
|
||||
LDFLAGS += --dynamic-linker=/lib/ld-linux-armhf.so.3
|
||||
CCFLAGS += -mfloat-abi=hard
|
||||
else ifeq ($(TARGET_OS),android)
|
||||
LDFLAGS += -pie
|
||||
CCFLAGS += -fpie -fpic -fexceptions
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
|
||||
ifneq ($(TARGET_FS),)
|
||||
GCCVERSIONLTEQ46 := $(shell expr `$(HOST_COMPILER) -dumpversion` \<= 4.6)
|
||||
ifeq ($(GCCVERSIONLTEQ46),1)
|
||||
CCFLAGS += --sysroot=$(TARGET_FS)
|
||||
endif
|
||||
LDFLAGS += --sysroot=$(TARGET_FS)
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/arm-linux-gnueabihf
|
||||
endif
|
||||
endif
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
|
||||
ifneq ($(TARGET_FS),)
|
||||
GCCVERSIONLTEQ46 := $(shell expr `$(HOST_COMPILER) -dumpversion` \<= 4.6)
|
||||
ifeq ($(GCCVERSIONLTEQ46),1)
|
||||
CCFLAGS += --sysroot=$(TARGET_FS)
|
||||
endif
|
||||
LDFLAGS += --sysroot=$(TARGET_FS)
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib -L$(TARGET_FS)/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib/aarch64-linux-gnu -L$(TARGET_FS)/lib/aarch64-linux-gnu
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib -L$(TARGET_FS)/usr/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/aarch64-linux-gnu -L$(TARGET_FS)/usr/lib/aarch64-linux-gnu
|
||||
LDFLAGS += --unresolved-symbols=ignore-in-shared-libs
|
||||
CCFLAGS += -isystem=$(TARGET_FS)/usr/include -I$(TARGET_FS)/usr/include -I$(TARGET_FS)/usr/include/libdrm
|
||||
CCFLAGS += -isystem=$(TARGET_FS)/usr/include/aarch64-linux-gnu -I$(TARGET_FS)/usr/include/aarch64-linux-gnu
|
||||
endif
|
||||
endif
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
|
||||
NVCCFLAGS += --qpp-config 5.4.0,gcc_ntoaarch64le
|
||||
CCFLAGS += -DWIN_INTERFACE_CUSTOM -I/usr/include/aarch64-qnx-gnu
|
||||
LDFLAGS += -lsocket
|
||||
LDFLAGS += -L/usr/lib/aarch64-qnx-gnu
|
||||
CCFLAGS += "-Wl\,-rpath-link\,/usr/lib/aarch64-qnx-gnu"
|
||||
ifdef TARGET_OVERRIDE
|
||||
LDFLAGS += -lslog2
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_FS),)
|
||||
LDFLAGS += -L$(TARGET_FS)/usr/lib
|
||||
CCFLAGS += "-Wl\,-rpath-link\,$(TARGET_FS)/usr/lib"
|
||||
LDFLAGS += -L$(TARGET_FS)/usr/libnvidia
|
||||
CCFLAGS += "-Wl\,-rpath-link\,$(TARGET_FS)/usr/libnvidia"
|
||||
CCFLAGS += -I$(TARGET_FS)/../include
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef TARGET_OVERRIDE # cuda toolkit targets override
|
||||
NVCCFLAGS += -target-dir $(TARGET_OVERRIDE)
|
||||
endif
|
||||
|
||||
# Install directory of different arch
|
||||
CUDA_INSTALL_TARGET_DIR :=
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-gnueabihf/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),sbsa-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/sbsa-linux/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-android)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-androideabi/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-android)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux-androideabi/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-qnx)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/ARMv7-linux-QNX/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-qnx/
|
||||
else ifeq ($(TARGET_ARCH),ppc64le)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/ppc64le-linux/
|
||||
endif
|
||||
|
||||
# Debug build flags
|
||||
ifeq ($(dbg),1)
|
||||
NVCCFLAGS += -g -G
|
||||
BUILD_TYPE := debug
|
||||
else
|
||||
BUILD_TYPE := release
|
||||
endif
|
||||
|
||||
ALL_CCFLAGS :=
|
||||
ALL_CCFLAGS += $(NVCCFLAGS)
|
||||
ALL_CCFLAGS += $(EXTRA_NVCCFLAGS)
|
||||
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(CCFLAGS))
|
||||
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(EXTRA_CCFLAGS))
|
||||
|
||||
ALL_LDFLAGS :=
|
||||
ALL_LDFLAGS += $(ALL_CCFLAGS)
|
||||
ALL_LDFLAGS += $(addprefix -Xlinker ,$(LDFLAGS))
|
||||
ALL_LDFLAGS += $(addprefix -Xlinker ,$(EXTRA_LDFLAGS))
|
||||
|
||||
# Common includes and paths for CUDA
|
||||
INCLUDES := -I../../Common
|
||||
LIBRARIES :=
|
||||
|
||||
################################################################################
|
||||
|
||||
# Gencode arguments
|
||||
SMS ?=
|
||||
|
||||
ifeq ($(GENCODE_FLAGS),)
|
||||
# Generate SASS code for each SM architecture listed in $(SMS)
|
||||
$(foreach sm,$(SMS),$(eval GENCODE_FLAGS += -gencode arch=compute_$(sm),code=sm_$(sm)))
|
||||
|
||||
ifeq ($(SMS),)
|
||||
# Generate PTX code from SM 35
|
||||
GENCODE_FLAGS += -gencode arch=compute_35,code=compute_35
|
||||
endif
|
||||
|
||||
# Generate PTX code from the highest SM architecture in $(SMS) to guarantee forward-compatibility
|
||||
HIGHEST_SM := $(lastword $(sort $(SMS)))
|
||||
ifneq ($(HIGHEST_SM),)
|
||||
GENCODE_FLAGS += -gencode arch=compute_$(HIGHEST_SM),code=compute_$(HIGHEST_SM)
|
||||
endif
|
||||
endif
|
||||
|
||||
ALL_CCFLAGS += --threads 0
|
||||
|
||||
LIBRARIES += -lcurand_static -lculibos
|
||||
|
||||
################################################################################
|
||||
|
||||
# Target rules
|
||||
all: build
|
||||
|
||||
build: MersenneTwisterGP11213
|
||||
|
||||
MersenneTwister.o:MersenneTwister.cpp
|
||||
$(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
|
||||
|
||||
MersenneTwisterGP11213: MersenneTwister.o
|
||||
$(NVCC) $(ALL_LDFLAGS) $(GENCODE_FLAGS) -o $@ $+ $(LIBRARIES)
|
||||
mkdir -p ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
|
||||
cp $@ ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
|
||||
|
||||
run: build
|
||||
./MersenneTwisterGP11213
|
||||
|
||||
clean:
|
||||
rm -f MersenneTwisterGP11213 MersenneTwister.o
|
||||
rm -rf ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)/MersenneTwisterGP11213
|
||||
|
||||
clobber: clean
|
||||
@@ -1,180 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This sample demonstrates the use of CURAND to generate
|
||||
* random numbers on GPU and CPU.
|
||||
*/
|
||||
|
||||
// Utilities and system includes
|
||||
// includes, system
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <curand.h>
|
||||
|
||||
// Utilities and system includes
|
||||
#include <helper_functions.h>
|
||||
#include <helper_cuda.h>
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include <curand.h>
|
||||
|
||||
float compareResults(int rand_n, float *h_RandGPU, float *h_RandCPU);
|
||||
|
||||
const int DEFAULT_RAND_N = 2400000;
|
||||
const unsigned int DEFAULT_SEED = 777;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Main program
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
int main(int argc, char **argv) {
|
||||
// Start logs
|
||||
printf("%s Starting...\n\n", argv[0]);
|
||||
|
||||
// initialize the GPU, either identified by --device
|
||||
// or by picking the device with highest flop rate.
|
||||
int devID = findCudaDevice(argc, (const char **)argv);
|
||||
|
||||
// parsing the number of random numbers to generate
|
||||
int rand_n = DEFAULT_RAND_N;
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "count")) {
|
||||
rand_n = getCmdLineArgumentInt(argc, (const char **)argv, "count");
|
||||
}
|
||||
|
||||
printf("Allocating data for %i samples...\n", rand_n);
|
||||
|
||||
// parsing the seed
|
||||
int seed = DEFAULT_SEED;
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "seed")) {
|
||||
seed = getCmdLineArgumentInt(argc, (const char **)argv, "seed");
|
||||
}
|
||||
|
||||
printf("Seeding with %i ...\n", seed);
|
||||
|
||||
cudaStream_t stream;
|
||||
checkCudaErrors(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));
|
||||
|
||||
float *d_Rand;
|
||||
checkCudaErrors(cudaMalloc((void **)&d_Rand, rand_n * sizeof(float)));
|
||||
|
||||
curandGenerator_t prngGPU;
|
||||
checkCudaErrors(curandCreateGenerator(&prngGPU, CURAND_RNG_PSEUDO_MTGP32));
|
||||
checkCudaErrors(curandSetStream(prngGPU, stream));
|
||||
checkCudaErrors(curandSetPseudoRandomGeneratorSeed(prngGPU, seed));
|
||||
|
||||
curandGenerator_t prngCPU;
|
||||
checkCudaErrors(
|
||||
curandCreateGeneratorHost(&prngCPU, CURAND_RNG_PSEUDO_MTGP32));
|
||||
checkCudaErrors(curandSetPseudoRandomGeneratorSeed(prngCPU, seed));
|
||||
|
||||
//
|
||||
// Example 1: Compare random numbers generated on GPU and CPU
|
||||
float *h_RandGPU;
|
||||
checkCudaErrors(cudaMallocHost(&h_RandGPU, rand_n * sizeof(float)));
|
||||
|
||||
printf("Generating random numbers on GPU...\n\n");
|
||||
checkCudaErrors(curandGenerateUniform(prngGPU, (float *)d_Rand, rand_n));
|
||||
|
||||
printf("\nReading back the results...\n");
|
||||
checkCudaErrors(cudaMemcpyAsync(h_RandGPU, d_Rand, rand_n * sizeof(float),
|
||||
cudaMemcpyDeviceToHost, stream));
|
||||
|
||||
float *h_RandCPU = (float *)malloc(rand_n * sizeof(float));
|
||||
|
||||
printf("Generating random numbers on CPU...\n\n");
|
||||
checkCudaErrors(curandGenerateUniform(prngCPU, (float *)h_RandCPU, rand_n));
|
||||
|
||||
checkCudaErrors(cudaStreamSynchronize(stream));
|
||||
printf("Comparing CPU/GPU random numbers...\n\n");
|
||||
float L1norm = compareResults(rand_n, h_RandGPU, h_RandCPU);
|
||||
|
||||
//
|
||||
// Example 2: Timing of random number generation on GPU
|
||||
const int numIterations = 10;
|
||||
int i;
|
||||
StopWatchInterface *hTimer;
|
||||
|
||||
sdkCreateTimer(&hTimer);
|
||||
sdkResetTimer(&hTimer);
|
||||
sdkStartTimer(&hTimer);
|
||||
|
||||
for (i = 0; i < numIterations; i++) {
|
||||
checkCudaErrors(curandGenerateUniform(prngGPU, (float *)d_Rand, rand_n));
|
||||
}
|
||||
|
||||
checkCudaErrors(cudaStreamSynchronize(stream));
|
||||
sdkStopTimer(&hTimer);
|
||||
|
||||
double gpuTime = 1.0e-3 * sdkGetTimerValue(&hTimer) / (double)numIterations;
|
||||
|
||||
printf(
|
||||
"MersenneTwisterGP11213, Throughput = %.4f GNumbers/s, Time = %.5f s, "
|
||||
"Size = %u Numbers\n",
|
||||
1.0e-9 * rand_n / gpuTime, gpuTime, rand_n);
|
||||
|
||||
printf("Shutting down...\n");
|
||||
|
||||
checkCudaErrors(curandDestroyGenerator(prngGPU));
|
||||
checkCudaErrors(curandDestroyGenerator(prngCPU));
|
||||
checkCudaErrors(cudaStreamDestroy(stream));
|
||||
checkCudaErrors(cudaFree(d_Rand));
|
||||
sdkDeleteTimer(&hTimer);
|
||||
checkCudaErrors(cudaFreeHost(h_RandGPU));
|
||||
free(h_RandCPU);
|
||||
|
||||
exit(L1norm < 1e-6 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
|
||||
float compareResults(int rand_n, float *h_RandGPU, float *h_RandCPU) {
|
||||
int i;
|
||||
float rCPU, rGPU, delta;
|
||||
float max_delta = 0.;
|
||||
float sum_delta = 0.;
|
||||
float sum_ref = 0.;
|
||||
|
||||
for (i = 0; i < rand_n; i++) {
|
||||
rCPU = h_RandCPU[i];
|
||||
rGPU = h_RandGPU[i];
|
||||
delta = fabs(rCPU - rGPU);
|
||||
sum_delta += delta;
|
||||
sum_ref += fabs(rCPU);
|
||||
|
||||
if (delta >= max_delta) {
|
||||
max_delta = delta;
|
||||
}
|
||||
}
|
||||
|
||||
float L1norm = (float)(sum_delta / sum_ref);
|
||||
printf("Max absolute error: %E\n", max_delta);
|
||||
printf("L1 norm: %E\n\n", L1norm);
|
||||
|
||||
return L1norm;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2017
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MersenneTwisterGP11213", "MersenneTwisterGP11213_vs2017.vcxproj", "{997E0757-EA74-4A4E-A0FC-47D8C8831A15}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.Build.0 = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.ActiveCfg = Release|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,113 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<CUDAPropsPath Condition="'$(CUDAPropsPath)'==''">$(VCTargetsPath)\BuildCustomizations</CUDAPropsPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{997E0757-EA74-4A4E-A0FC-47D8C8831A15}</ProjectGuid>
|
||||
<RootNamespace>MersenneTwisterGP11213_vs2017</RootNamespace>
|
||||
<ProjectName>MersenneTwisterGP11213</ProjectName>
|
||||
<CudaToolkitCustomDir />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(WindowsTargetPlatformVersion)'==''">
|
||||
<LatestTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</LatestTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion Condition="'$(WindowsTargetPlatformVersion)' == ''">$(LatestTargetPlatformVersion)</WindowsTargetPlatformVersion>
|
||||
<TargetPlatformVersion>$(WindowsTargetPlatformVersion)</TargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup>
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IntDir>$(Platform)/$(Configuration)/</IntDir>
|
||||
<IncludePath>$(IncludePath)</IncludePath>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
||||
<OutDir>../../bin/win64/$(Configuration)/</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>./;$(CudaToolkitDir)/include;../../Common;$(CudaToolkitIncludeDir);</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>curand.lib;cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(CudaToolkitLibDir);</AdditionalLibraryDirectories>
|
||||
<OutputFile>$(OutDir)/MersenneTwisterGP11213.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_35,compute_35;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Include>./;../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
<AdditionalOptions>--threads 0</AdditionalOptions>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MTd</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MT</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="MersenneTwister.cpp" />
|
||||
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -1,20 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2019
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MersenneTwisterGP11213", "MersenneTwisterGP11213_vs2019.vcxproj", "{997E0757-EA74-4A4E-A0FC-47D8C8831A15}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.Build.0 = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.ActiveCfg = Release|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,109 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<CUDAPropsPath Condition="'$(CUDAPropsPath)'==''">$(VCTargetsPath)\BuildCustomizations</CUDAPropsPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{997E0757-EA74-4A4E-A0FC-47D8C8831A15}</ProjectGuid>
|
||||
<RootNamespace>MersenneTwisterGP11213_vs2019</RootNamespace>
|
||||
<ProjectName>MersenneTwisterGP11213</ProjectName>
|
||||
<CudaToolkitCustomDir />
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup>
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IntDir>$(Platform)/$(Configuration)/</IntDir>
|
||||
<IncludePath>$(IncludePath)</IncludePath>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
||||
<OutDir>../../bin/win64/$(Configuration)/</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>./;$(CudaToolkitDir)/include;../../Common;$(CudaToolkitIncludeDir);</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>curand.lib;cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(CudaToolkitLibDir);</AdditionalLibraryDirectories>
|
||||
<OutputFile>$(OutDir)/MersenneTwisterGP11213.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_35,compute_35;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Include>./;../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
<AdditionalOptions>--threads 0</AdditionalOptions>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MTd</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MT</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="MersenneTwister.cpp" />
|
||||
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -1,74 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE entry SYSTEM "SamplesInfo.dtd">
|
||||
<entry>
|
||||
<name>MersenneTwisterGP11213</name>
|
||||
<description><![CDATA[This sample demonstrates the Mersenne Twister random number generator GP11213 in cuRAND.]]></description>
|
||||
<devicecompilation>whole</devicecompilation>
|
||||
<fallback_min_ptx>true</fallback_min_ptx>
|
||||
<includepaths>
|
||||
<path>./</path>
|
||||
<path>../</path>
|
||||
<path>../../common/inc</path>
|
||||
</includepaths>
|
||||
<keyconcepts>
|
||||
<concept level="basic">CURAND Library</concept>
|
||||
</keyconcepts>
|
||||
<keywords>
|
||||
<keyword>CUDA</keyword>
|
||||
<keyword>CURAND</keyword>
|
||||
<keyword>Monte-Carlo</keyword>
|
||||
<keyword>random number generation</keyword>
|
||||
<keyword>GSFR</keyword>
|
||||
<keyword>Mersenne Twister</keyword>
|
||||
</keywords>
|
||||
<libraries>
|
||||
<library>curand_static</library>
|
||||
<library>culibos</library>
|
||||
</libraries>
|
||||
<librarypaths>
|
||||
</librarypaths>
|
||||
<nsight_eclipse>true</nsight_eclipse>
|
||||
<primary_file>MersenneTwister.cpp</primary_file>
|
||||
<required_dependencies>
|
||||
<dependency>CURAND</dependency>
|
||||
</required_dependencies>
|
||||
<scopes>
|
||||
<scope>1:CUDA Advanced Topics</scope>
|
||||
</scopes>
|
||||
<sm-arch>sm35</sm-arch>
|
||||
<sm-arch>sm37</sm-arch>
|
||||
<sm-arch>sm50</sm-arch>
|
||||
<sm-arch>sm52</sm-arch>
|
||||
<sm-arch>sm60</sm-arch>
|
||||
<sm-arch>sm61</sm-arch>
|
||||
<sm-arch>sm70</sm-arch>
|
||||
<sm-arch>sm72</sm-arch>
|
||||
<sm-arch>sm75</sm-arch>
|
||||
<sm-arch>sm80</sm-arch>
|
||||
<sm-arch>sm86</sm-arch>
|
||||
<supported_envs>
|
||||
<env>
|
||||
<arch>x86_64</arch>
|
||||
<platform>linux</platform>
|
||||
</env>
|
||||
<env>
|
||||
<platform>windows7</platform>
|
||||
</env>
|
||||
<env>
|
||||
<arch>x86_64</arch>
|
||||
<platform>macosx</platform>
|
||||
</env>
|
||||
<env>
|
||||
<arch>arm</arch>
|
||||
</env>
|
||||
<env>
|
||||
<arch>ppc64le</arch>
|
||||
<platform>linux</platform>
|
||||
</env>
|
||||
</supported_envs>
|
||||
<supported_sm_architectures>
|
||||
<include>all</include>
|
||||
</supported_sm_architectures>
|
||||
<title>MersenneTwisterGP11213</title>
|
||||
<type>exe</type>
|
||||
</entry>
|
||||
@@ -1,71 +0,0 @@
|
||||
# MersenneTwisterGP11213 - MersenneTwisterGP11213
|
||||
|
||||
## Description
|
||||
|
||||
This sample demonstrates the Mersenne Twister random number generator GP11213 in cuRAND.
|
||||
|
||||
## Key Concepts
|
||||
|
||||
CURAND Library
|
||||
|
||||
## Supported SM Architectures
|
||||
|
||||
[SM 3.5 ](https://developer.nvidia.com/cuda-gpus) [SM 3.7 ](https://developer.nvidia.com/cuda-gpus) [SM 5.0 ](https://developer.nvidia.com/cuda-gpus) [SM 5.2 ](https://developer.nvidia.com/cuda-gpus) [SM 6.0 ](https://developer.nvidia.com/cuda-gpus) [SM 6.1 ](https://developer.nvidia.com/cuda-gpus) [SM 7.0 ](https://developer.nvidia.com/cuda-gpus) [SM 7.2 ](https://developer.nvidia.com/cuda-gpus) [SM 7.5 ](https://developer.nvidia.com/cuda-gpus) [SM 8.0 ](https://developer.nvidia.com/cuda-gpus) [SM 8.6 ](https://developer.nvidia.com/cuda-gpus)
|
||||
|
||||
## Supported OSes
|
||||
|
||||
Linux, Windows
|
||||
|
||||
## Supported CPU Architecture
|
||||
|
||||
x86_64, ppc64le, armv7l
|
||||
|
||||
## CUDA APIs involved
|
||||
|
||||
## Dependencies needed to build/run
|
||||
[CURAND](../../README.md#curand)
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
||||
Make sure the dependencies mentioned in [Dependencies]() section above are installed.
|
||||
|
||||
## Build and Run
|
||||
|
||||
### Windows
|
||||
The Windows samples are built using the Visual Studio IDE. Solution files (.sln) are provided for each supported version of Visual Studio, using the format:
|
||||
```
|
||||
*_vs<version>.sln - for Visual Studio <version>
|
||||
```
|
||||
Each individual sample has its own set of solution files in its directory:
|
||||
|
||||
To build/examine all the samples at once, the complete solution files should be used. To build/examine a single sample, the individual sample solution files should be used.
|
||||
> **Note:** Some samples require that the Microsoft DirectX SDK (June 2010 or newer) be installed and that the VC++ directory paths are properly set up (**Tools > Options...**). Check DirectX Dependencies section for details."
|
||||
|
||||
### Linux
|
||||
The Linux samples are built using makefiles. To use the makefiles, change the current directory to the sample directory you wish to build, and run make:
|
||||
```
|
||||
$ cd <sample_dir>
|
||||
$ make
|
||||
```
|
||||
The samples makefiles can take advantage of certain options:
|
||||
* **TARGET_ARCH=<arch>** - cross-compile targeting a specific architecture. Allowed architectures are x86_64, ppc64le, armv7l.
|
||||
By default, TARGET_ARCH is set to HOST_ARCH. On a x86_64 machine, not setting TARGET_ARCH is the equivalent of setting TARGET_ARCH=x86_64.<br/>
|
||||
`$ make TARGET_ARCH=x86_64` <br/> `$ make TARGET_ARCH=ppc64le` <br/> `$ make TARGET_ARCH=armv7l` <br/>
|
||||
See [here](http://docs.nvidia.com/cuda/cuda-samples/index.html#cross-samples) for more details.
|
||||
* **dbg=1** - build with debug symbols
|
||||
```
|
||||
$ make dbg=1
|
||||
```
|
||||
* **SMS="A B ..."** - override the SM architectures for which the sample will be built, where `"A B ..."` is a space-delimited list of SM architectures. For example, to generate SASS for SM 50 and SM 60, use `SMS="50 60"`.
|
||||
```
|
||||
$ make SMS="50 60"
|
||||
```
|
||||
|
||||
* **HOST_COMPILER=<host_compiler>** - override the default g++ host compiler. See the [Linux Installation Guide](http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#system-requirements) for a list of supported host compilers.
|
||||
```
|
||||
$ make HOST_COMPILER=g++
|
||||
```
|
||||
|
||||
## References (for more details)
|
||||
|
||||
@@ -1,355 +0,0 @@
|
||||
################################################################################
|
||||
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# Makefile project only supported on Mac OS X and Linux Platforms)
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# Location of the CUDA Toolkit
|
||||
CUDA_PATH ?= /usr/local/cuda
|
||||
|
||||
##############################
|
||||
# start deprecated interface #
|
||||
##############################
|
||||
ifeq ($(x86_64),1)
|
||||
$(info WARNING - x86_64 variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=x86_64 instead)
|
||||
TARGET_ARCH ?= x86_64
|
||||
endif
|
||||
ifeq ($(ARMv7),1)
|
||||
$(info WARNING - ARMv7 variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=armv7l instead)
|
||||
TARGET_ARCH ?= armv7l
|
||||
endif
|
||||
ifeq ($(aarch64),1)
|
||||
$(info WARNING - aarch64 variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=aarch64 instead)
|
||||
TARGET_ARCH ?= aarch64
|
||||
endif
|
||||
ifeq ($(ppc64le),1)
|
||||
$(info WARNING - ppc64le variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=ppc64le instead)
|
||||
TARGET_ARCH ?= ppc64le
|
||||
endif
|
||||
ifneq ($(GCC),)
|
||||
$(info WARNING - GCC variable has been deprecated)
|
||||
$(info WARNING - please use HOST_COMPILER=$(GCC) instead)
|
||||
HOST_COMPILER ?= $(GCC)
|
||||
endif
|
||||
ifneq ($(abi),)
|
||||
$(error ERROR - abi variable has been removed)
|
||||
endif
|
||||
############################
|
||||
# end deprecated interface #
|
||||
############################
|
||||
|
||||
# architecture
|
||||
HOST_ARCH := $(shell uname -m)
|
||||
TARGET_ARCH ?= $(HOST_ARCH)
|
||||
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le armv7l))
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le))
|
||||
TARGET_SIZE := 64
|
||||
else ifneq (,$(filter $(TARGET_ARCH),armv7l))
|
||||
TARGET_SIZE := 32
|
||||
endif
|
||||
else
|
||||
TARGET_SIZE := $(shell getconf LONG_BIT)
|
||||
endif
|
||||
else
|
||||
$(error ERROR - unsupported value $(TARGET_ARCH) for TARGET_ARCH!)
|
||||
endif
|
||||
|
||||
# sbsa and aarch64 systems look similar. Need to differentiate them at host level for now.
|
||||
ifeq ($(HOST_ARCH),aarch64)
|
||||
ifeq ($(CUDA_PATH)/targets/sbsa-linux,$(shell ls -1d $(CUDA_PATH)/targets/sbsa-linux 2>/dev/null))
|
||||
HOST_ARCH := sbsa
|
||||
TARGET_ARCH := sbsa
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq (,$(filter $(HOST_ARCH)-$(TARGET_ARCH),aarch64-armv7l x86_64-armv7l x86_64-aarch64 x86_64-sbsa x86_64-ppc64le))
|
||||
$(error ERROR - cross compiling from $(HOST_ARCH) to $(TARGET_ARCH) is not supported!)
|
||||
endif
|
||||
endif
|
||||
|
||||
# When on native aarch64 system with userspace of 32-bit, change TARGET_ARCH to armv7l
|
||||
ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_SIZE),aarch64-aarch64-32)
|
||||
TARGET_ARCH = armv7l
|
||||
endif
|
||||
|
||||
# operating system
|
||||
HOST_OS := $(shell uname -s 2>/dev/null | tr "[:upper:]" "[:lower:]")
|
||||
TARGET_OS ?= $(HOST_OS)
|
||||
ifeq (,$(filter $(TARGET_OS),linux darwin qnx android))
|
||||
$(error ERROR - unsupported value $(TARGET_OS) for TARGET_OS!)
|
||||
endif
|
||||
|
||||
# host compiler
|
||||
ifeq ($(TARGET_OS),darwin)
|
||||
ifeq ($(shell expr `xcodebuild -version | grep -i xcode | awk '{print $$2}' | cut -d'.' -f1` \>= 5),1)
|
||||
HOST_COMPILER ?= clang++
|
||||
endif
|
||||
else ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq ($(HOST_ARCH)-$(TARGET_ARCH),x86_64-armv7l)
|
||||
ifeq ($(TARGET_OS),linux)
|
||||
HOST_COMPILER ?= arm-linux-gnueabihf-g++
|
||||
else ifeq ($(TARGET_OS),qnx)
|
||||
ifeq ($(QNX_HOST),)
|
||||
$(error ERROR - QNX_HOST must be passed to the QNX host toolchain)
|
||||
endif
|
||||
ifeq ($(QNX_TARGET),)
|
||||
$(error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
|
||||
endif
|
||||
export QNX_HOST
|
||||
export QNX_TARGET
|
||||
HOST_COMPILER ?= $(QNX_HOST)/usr/bin/arm-unknown-nto-qnx6.6.0eabi-g++
|
||||
else ifeq ($(TARGET_OS),android)
|
||||
HOST_COMPILER ?= arm-linux-androideabi-g++
|
||||
endif
|
||||
else ifeq ($(TARGET_ARCH),aarch64)
|
||||
ifeq ($(TARGET_OS), linux)
|
||||
HOST_COMPILER ?= aarch64-linux-gnu-g++
|
||||
else ifeq ($(TARGET_OS),qnx)
|
||||
ifeq ($(QNX_HOST),)
|
||||
$(error ERROR - QNX_HOST must be passed to the QNX host toolchain)
|
||||
endif
|
||||
ifeq ($(QNX_TARGET),)
|
||||
$(error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
|
||||
endif
|
||||
export QNX_HOST
|
||||
export QNX_TARGET
|
||||
HOST_COMPILER ?= $(QNX_HOST)/usr/bin/q++
|
||||
else ifeq ($(TARGET_OS), android)
|
||||
HOST_COMPILER ?= aarch64-linux-android-clang++
|
||||
endif
|
||||
else ifeq ($(TARGET_ARCH),sbsa)
|
||||
HOST_COMPILER ?= aarch64-linux-gnu-g++
|
||||
else ifeq ($(TARGET_ARCH),ppc64le)
|
||||
HOST_COMPILER ?= powerpc64le-linux-gnu-g++
|
||||
endif
|
||||
endif
|
||||
HOST_COMPILER ?= g++
|
||||
NVCC := $(CUDA_PATH)/bin/nvcc -ccbin $(HOST_COMPILER)
|
||||
|
||||
# internal flags
|
||||
NVCCFLAGS := -m${TARGET_SIZE}
|
||||
CCFLAGS :=
|
||||
LDFLAGS :=
|
||||
|
||||
# build flags
|
||||
ifeq ($(TARGET_OS),darwin)
|
||||
LDFLAGS += -rpath $(CUDA_PATH)/lib
|
||||
CCFLAGS += -arch $(HOST_ARCH)
|
||||
else ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_OS),x86_64-armv7l-linux)
|
||||
LDFLAGS += --dynamic-linker=/lib/ld-linux-armhf.so.3
|
||||
CCFLAGS += -mfloat-abi=hard
|
||||
else ifeq ($(TARGET_OS),android)
|
||||
LDFLAGS += -pie
|
||||
CCFLAGS += -fpie -fpic -fexceptions
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
|
||||
ifneq ($(TARGET_FS),)
|
||||
GCCVERSIONLTEQ46 := $(shell expr `$(HOST_COMPILER) -dumpversion` \<= 4.6)
|
||||
ifeq ($(GCCVERSIONLTEQ46),1)
|
||||
CCFLAGS += --sysroot=$(TARGET_FS)
|
||||
endif
|
||||
LDFLAGS += --sysroot=$(TARGET_FS)
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/arm-linux-gnueabihf
|
||||
endif
|
||||
endif
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
|
||||
ifneq ($(TARGET_FS),)
|
||||
GCCVERSIONLTEQ46 := $(shell expr `$(HOST_COMPILER) -dumpversion` \<= 4.6)
|
||||
ifeq ($(GCCVERSIONLTEQ46),1)
|
||||
CCFLAGS += --sysroot=$(TARGET_FS)
|
||||
endif
|
||||
LDFLAGS += --sysroot=$(TARGET_FS)
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib -L$(TARGET_FS)/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib/aarch64-linux-gnu -L$(TARGET_FS)/lib/aarch64-linux-gnu
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib -L$(TARGET_FS)/usr/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/aarch64-linux-gnu -L$(TARGET_FS)/usr/lib/aarch64-linux-gnu
|
||||
LDFLAGS += --unresolved-symbols=ignore-in-shared-libs
|
||||
CCFLAGS += -isystem=$(TARGET_FS)/usr/include -I$(TARGET_FS)/usr/include -I$(TARGET_FS)/usr/include/libdrm
|
||||
CCFLAGS += -isystem=$(TARGET_FS)/usr/include/aarch64-linux-gnu -I$(TARGET_FS)/usr/include/aarch64-linux-gnu
|
||||
endif
|
||||
endif
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
|
||||
NVCCFLAGS += --qpp-config 5.4.0,gcc_ntoaarch64le
|
||||
CCFLAGS += -DWIN_INTERFACE_CUSTOM -I/usr/include/aarch64-qnx-gnu
|
||||
LDFLAGS += -lsocket
|
||||
LDFLAGS += -L/usr/lib/aarch64-qnx-gnu
|
||||
CCFLAGS += "-Wl\,-rpath-link\,/usr/lib/aarch64-qnx-gnu"
|
||||
ifdef TARGET_OVERRIDE
|
||||
LDFLAGS += -lslog2
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_FS),)
|
||||
LDFLAGS += -L$(TARGET_FS)/usr/lib
|
||||
CCFLAGS += "-Wl\,-rpath-link\,$(TARGET_FS)/usr/lib"
|
||||
LDFLAGS += -L$(TARGET_FS)/usr/libnvidia
|
||||
CCFLAGS += "-Wl\,-rpath-link\,$(TARGET_FS)/usr/libnvidia"
|
||||
CCFLAGS += -I$(TARGET_FS)/../include
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef TARGET_OVERRIDE # cuda toolkit targets override
|
||||
NVCCFLAGS += -target-dir $(TARGET_OVERRIDE)
|
||||
endif
|
||||
|
||||
# Install directory of different arch
|
||||
CUDA_INSTALL_TARGET_DIR :=
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-gnueabihf/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),sbsa-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/sbsa-linux/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-android)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-androideabi/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-android)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux-androideabi/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-qnx)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/ARMv7-linux-QNX/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-qnx/
|
||||
else ifeq ($(TARGET_ARCH),ppc64le)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/ppc64le-linux/
|
||||
endif
|
||||
|
||||
# Debug build flags
|
||||
ifeq ($(dbg),1)
|
||||
NVCCFLAGS += -g -G
|
||||
BUILD_TYPE := debug
|
||||
else
|
||||
BUILD_TYPE := release
|
||||
endif
|
||||
|
||||
ALL_CCFLAGS :=
|
||||
ALL_CCFLAGS += $(NVCCFLAGS)
|
||||
ALL_CCFLAGS += $(EXTRA_NVCCFLAGS)
|
||||
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(CCFLAGS))
|
||||
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(EXTRA_CCFLAGS))
|
||||
|
||||
SAMPLE_ENABLED := 1
|
||||
|
||||
# This sample is not supported on ARMv7
|
||||
ifeq ($(TARGET_ARCH),armv7l)
|
||||
$(info >>> WARNING - NV12toBGRandResize is not supported on ARMv7 - waiving sample <<<)
|
||||
SAMPLE_ENABLED := 0
|
||||
endif
|
||||
|
||||
ALL_LDFLAGS :=
|
||||
ALL_LDFLAGS += $(ALL_CCFLAGS)
|
||||
ALL_LDFLAGS += $(addprefix -Xlinker ,$(LDFLAGS))
|
||||
ALL_LDFLAGS += $(addprefix -Xlinker ,$(EXTRA_LDFLAGS))
|
||||
|
||||
# Common includes and paths for CUDA
|
||||
INCLUDES := -I../../Common
|
||||
LIBRARIES :=
|
||||
|
||||
################################################################################
|
||||
|
||||
# Gencode arguments
|
||||
ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),armv7l aarch64))
|
||||
SMS ?= 35 37 50 52 60 61 70 72 75 80 86
|
||||
else
|
||||
SMS ?= 35 37 50 52 60 61 70 75 80 86
|
||||
endif
|
||||
|
||||
ifeq ($(SMS),)
|
||||
$(info >>> WARNING - no SM architectures have been specified - waiving sample <<<)
|
||||
SAMPLE_ENABLED := 0
|
||||
endif
|
||||
|
||||
ifeq ($(GENCODE_FLAGS),)
|
||||
# Generate SASS code for each SM architecture listed in $(SMS)
|
||||
$(foreach sm,$(SMS),$(eval GENCODE_FLAGS += -gencode arch=compute_$(sm),code=sm_$(sm)))
|
||||
|
||||
# Generate PTX code from the highest SM architecture in $(SMS) to guarantee forward-compatibility
|
||||
HIGHEST_SM := $(lastword $(sort $(SMS)))
|
||||
ifneq ($(HIGHEST_SM),)
|
||||
GENCODE_FLAGS += -gencode arch=compute_$(HIGHEST_SM),code=compute_$(HIGHEST_SM)
|
||||
endif
|
||||
endif
|
||||
|
||||
ALL_CCFLAGS += --threads 0
|
||||
|
||||
ifeq ($(SAMPLE_ENABLED),0)
|
||||
EXEC ?= @echo "[@]"
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
|
||||
# Target rules
|
||||
all: build
|
||||
|
||||
build: NV12toBGRandResize
|
||||
|
||||
check.deps:
|
||||
ifeq ($(SAMPLE_ENABLED),0)
|
||||
@echo "Sample will be waived due to the above missing dependencies"
|
||||
else
|
||||
@echo "Sample is ready - all dependencies have been met"
|
||||
endif
|
||||
|
||||
bgr_resize.o:bgr_resize.cu
|
||||
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
|
||||
|
||||
nv12_resize.o:nv12_resize.cu
|
||||
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
|
||||
|
||||
nv12_to_bgr_planar.o:nv12_to_bgr_planar.cu
|
||||
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
|
||||
|
||||
resize_convert_main.o:resize_convert_main.cpp
|
||||
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
|
||||
|
||||
utils.o:utils.cu
|
||||
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
|
||||
|
||||
NV12toBGRandResize: bgr_resize.o nv12_resize.o nv12_to_bgr_planar.o resize_convert_main.o utils.o
|
||||
$(EXEC) $(NVCC) $(ALL_LDFLAGS) $(GENCODE_FLAGS) -o $@ $+ $(LIBRARIES)
|
||||
$(EXEC) mkdir -p ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
|
||||
$(EXEC) cp $@ ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
|
||||
|
||||
run: build
|
||||
$(EXEC) ./NV12toBGRandResize
|
||||
|
||||
clean:
|
||||
rm -f NV12toBGRandResize bgr_resize.o nv12_resize.o nv12_to_bgr_planar.o resize_convert_main.o utils.o
|
||||
rm -rf ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)/NV12toBGRandResize
|
||||
|
||||
clobber: clean
|
||||
@@ -1,20 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2017
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NV12toBGRandResize", "NV12toBGRandResize_vs2017.vcxproj", "{997E0757-EA74-4A4E-A0FC-47D8C8831A15}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.Build.0 = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.ActiveCfg = Release|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,118 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<CUDAPropsPath Condition="'$(CUDAPropsPath)'==''">$(VCTargetsPath)\BuildCustomizations</CUDAPropsPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{997E0757-EA74-4A4E-A0FC-47D8C8831A15}</ProjectGuid>
|
||||
<RootNamespace>NV12toBGRandResize_vs2017</RootNamespace>
|
||||
<ProjectName>NV12toBGRandResize</ProjectName>
|
||||
<CudaToolkitCustomDir />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(WindowsTargetPlatformVersion)'==''">
|
||||
<LatestTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</LatestTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion Condition="'$(WindowsTargetPlatformVersion)' == ''">$(LatestTargetPlatformVersion)</WindowsTargetPlatformVersion>
|
||||
<TargetPlatformVersion>$(WindowsTargetPlatformVersion)</TargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup>
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IntDir>$(Platform)/$(Configuration)/</IntDir>
|
||||
<IncludePath>$(IncludePath)</IncludePath>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
||||
<OutDir>../../bin/win64/$(Configuration)/</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>./;$(CudaToolkitDir)/include;../../Common;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(CudaToolkitLibDir);</AdditionalLibraryDirectories>
|
||||
<OutputFile>$(OutDir)/NV12toBGRandResize.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_35,sm_35;compute_37,sm_37;compute_50,sm_50;compute_52,sm_52;compute_60,sm_60;compute_61,sm_61;compute_70,sm_70;compute_75,sm_75;compute_80,sm_80;compute_86,sm_86;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Include>./;../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
<AdditionalOptions>--threads 0</AdditionalOptions>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MTd</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MT</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<CudaCompile Include="bgr_resize.cu" />
|
||||
<CudaCompile Include="nv12_resize.cu" />
|
||||
<CudaCompile Include="nv12_to_bgr_planar.cu" />
|
||||
<ClCompile Include="resize_convert_main.cpp" />
|
||||
<CudaCompile Include="utils.cu" />
|
||||
<ClInclude Include="resize_convert.h" />
|
||||
<ClInclude Include="utils.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -1,20 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2019
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NV12toBGRandResize", "NV12toBGRandResize_vs2019.vcxproj", "{997E0757-EA74-4A4E-A0FC-47D8C8831A15}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.Build.0 = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.ActiveCfg = Release|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,114 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<CUDAPropsPath Condition="'$(CUDAPropsPath)'==''">$(VCTargetsPath)\BuildCustomizations</CUDAPropsPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{997E0757-EA74-4A4E-A0FC-47D8C8831A15}</ProjectGuid>
|
||||
<RootNamespace>NV12toBGRandResize_vs2019</RootNamespace>
|
||||
<ProjectName>NV12toBGRandResize</ProjectName>
|
||||
<CudaToolkitCustomDir />
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup>
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IntDir>$(Platform)/$(Configuration)/</IntDir>
|
||||
<IncludePath>$(IncludePath)</IncludePath>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
||||
<OutDir>../../bin/win64/$(Configuration)/</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>./;$(CudaToolkitDir)/include;../../Common;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(CudaToolkitLibDir);</AdditionalLibraryDirectories>
|
||||
<OutputFile>$(OutDir)/NV12toBGRandResize.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_35,sm_35;compute_37,sm_37;compute_50,sm_50;compute_52,sm_52;compute_60,sm_60;compute_61,sm_61;compute_70,sm_70;compute_75,sm_75;compute_80,sm_80;compute_86,sm_86;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Include>./;../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
<AdditionalOptions>--threads 0</AdditionalOptions>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MTd</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MT</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<CudaCompile Include="bgr_resize.cu" />
|
||||
<CudaCompile Include="nv12_resize.cu" />
|
||||
<CudaCompile Include="nv12_to_bgr_planar.cu" />
|
||||
<ClCompile Include="resize_convert_main.cpp" />
|
||||
<CudaCompile Include="utils.cu" />
|
||||
<ClInclude Include="resize_convert.h" />
|
||||
<ClInclude Include="utils.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -1,71 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE entry SYSTEM "SamplesInfo.dtd">
|
||||
<entry>
|
||||
<name>NV12toBGRandResize</name>
|
||||
<cuda_api_list>
|
||||
<toolkit>cudaMemcpy2D</toolkit>
|
||||
<toolkit>cudaMallocManaged</toolkit>
|
||||
</cuda_api_list>
|
||||
<description><![CDATA[This code shows two ways to convert and resize NV12 frames to BGR 3 planars frames using CUDA in batch. Way-1, Convert NV12 Input to BGR @ Input Resolution-1, then Resize to Resolution#2. Way-2, resize NV12 Input to Resolution#2 then convert it to BGR Output. NVIDIA HW Decoder, both dGPU and Tegra, normally outputs NV12 pitch format frames. For the inference using TensorRT, the input frame needs to be BGR planar format with possibly different size. So, conversion and resizing from NV12 to BGR planar is usually required for the inference following decoding. This CUDA code provides a reference implementation for conversion and resizing.]]></description>
|
||||
<devicecompilation>whole</devicecompilation>
|
||||
<includepaths>
|
||||
<path>./</path>
|
||||
<path>../</path>
|
||||
<path>../../common/inc</path>
|
||||
</includepaths>
|
||||
<keyconcepts>
|
||||
<concept level="basic">Graphics Interop</concept>
|
||||
<concept level="basic">Image Processing</concept>
|
||||
<concept level="basic">Video Processing</concept>
|
||||
</keyconcepts>
|
||||
<keywords>
|
||||
<keyword>GPGPU</keyword>
|
||||
</keywords>
|
||||
<libraries>
|
||||
</libraries>
|
||||
<librarypaths>
|
||||
</librarypaths>
|
||||
<nsight_eclipse>true</nsight_eclipse>
|
||||
<primary_file>resize_convert_main.cpp</primary_file>
|
||||
<scopes>
|
||||
<scope>1:CUDA Basic Topics</scope>
|
||||
<scope>2:Image Processing</scope>
|
||||
<scope>2:Computer Vision</scope>
|
||||
</scopes>
|
||||
<sm-arch>sm35</sm-arch>
|
||||
<sm-arch>sm37</sm-arch>
|
||||
<sm-arch>sm50</sm-arch>
|
||||
<sm-arch>sm52</sm-arch>
|
||||
<sm-arch>sm60</sm-arch>
|
||||
<sm-arch>sm61</sm-arch>
|
||||
<sm-arch>sm70</sm-arch>
|
||||
<sm-arch>sm72</sm-arch>
|
||||
<sm-arch>sm75</sm-arch>
|
||||
<sm-arch>sm80</sm-arch>
|
||||
<sm-arch>sm86</sm-arch>
|
||||
<supported_envs>
|
||||
<env>
|
||||
<arch>x86_64</arch>
|
||||
<platform>linux</platform>
|
||||
</env>
|
||||
<env>
|
||||
<platform>windows7</platform>
|
||||
</env>
|
||||
<env>
|
||||
<arch>x86_64</arch>
|
||||
<platform>macosx</platform>
|
||||
</env>
|
||||
<env>
|
||||
<arch>aarch64</arch>
|
||||
</env>
|
||||
<env>
|
||||
<arch>ppc64le</arch>
|
||||
<platform>linux</platform>
|
||||
</env>
|
||||
</supported_envs>
|
||||
<supported_sm_architectures>
|
||||
<include>all</include>
|
||||
</supported_sm_architectures>
|
||||
<title>NV12toBGRandResize</title>
|
||||
<type>exe</type>
|
||||
</entry>
|
||||
@@ -1,70 +0,0 @@
|
||||
# NV12toBGRandResize - NV12toBGRandResize
|
||||
|
||||
## Description
|
||||
|
||||
This code shows two ways to convert and resize NV12 frames to BGR 3 planars frames using CUDA in batch. Way-1, Convert NV12 Input to BGR @ Input Resolution-1, then Resize to Resolution#2. Way-2, resize NV12 Input to Resolution#2 then convert it to BGR Output. NVIDIA HW Decoder, both dGPU and Tegra, normally outputs NV12 pitch format frames. For the inference using TensorRT, the input frame needs to be BGR planar format with possibly different size. So, conversion and resizing from NV12 to BGR planar is usually required for the inference following decoding. This CUDA code provides a reference implementation for conversion and resizing.
|
||||
|
||||
## Key Concepts
|
||||
|
||||
Graphics Interop, Image Processing, Video Processing
|
||||
|
||||
## Supported SM Architectures
|
||||
|
||||
[SM 3.5 ](https://developer.nvidia.com/cuda-gpus) [SM 3.7 ](https://developer.nvidia.com/cuda-gpus) [SM 5.0 ](https://developer.nvidia.com/cuda-gpus) [SM 5.2 ](https://developer.nvidia.com/cuda-gpus) [SM 6.0 ](https://developer.nvidia.com/cuda-gpus) [SM 6.1 ](https://developer.nvidia.com/cuda-gpus) [SM 7.0 ](https://developer.nvidia.com/cuda-gpus) [SM 7.2 ](https://developer.nvidia.com/cuda-gpus) [SM 7.5 ](https://developer.nvidia.com/cuda-gpus) [SM 8.0 ](https://developer.nvidia.com/cuda-gpus) [SM 8.6 ](https://developer.nvidia.com/cuda-gpus)
|
||||
|
||||
## Supported OSes
|
||||
|
||||
Linux, Windows
|
||||
|
||||
## Supported CPU Architecture
|
||||
|
||||
x86_64, ppc64le, aarch64
|
||||
|
||||
## CUDA APIs involved
|
||||
|
||||
### [CUDA Runtime API](http://docs.nvidia.com/cuda/cuda-runtime-api/index.html)
|
||||
cudaMemcpy2D, cudaMallocManaged
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
||||
|
||||
## Build and Run
|
||||
|
||||
### Windows
|
||||
The Windows samples are built using the Visual Studio IDE. Solution files (.sln) are provided for each supported version of Visual Studio, using the format:
|
||||
```
|
||||
*_vs<version>.sln - for Visual Studio <version>
|
||||
```
|
||||
Each individual sample has its own set of solution files in its directory:
|
||||
|
||||
To build/examine all the samples at once, the complete solution files should be used. To build/examine a single sample, the individual sample solution files should be used.
|
||||
> **Note:** Some samples require that the Microsoft DirectX SDK (June 2010 or newer) be installed and that the VC++ directory paths are properly set up (**Tools > Options...**). Check DirectX Dependencies section for details."
|
||||
|
||||
### Linux
|
||||
The Linux samples are built using makefiles. To use the makefiles, change the current directory to the sample directory you wish to build, and run make:
|
||||
```
|
||||
$ cd <sample_dir>
|
||||
$ make
|
||||
```
|
||||
The samples makefiles can take advantage of certain options:
|
||||
* **TARGET_ARCH=<arch>** - cross-compile targeting a specific architecture. Allowed architectures are x86_64, ppc64le, aarch64.
|
||||
By default, TARGET_ARCH is set to HOST_ARCH. On a x86_64 machine, not setting TARGET_ARCH is the equivalent of setting TARGET_ARCH=x86_64.<br/>
|
||||
`$ make TARGET_ARCH=x86_64` <br/> `$ make TARGET_ARCH=ppc64le` <br/> `$ make TARGET_ARCH=aarch64` <br/>
|
||||
See [here](http://docs.nvidia.com/cuda/cuda-samples/index.html#cross-samples) for more details.
|
||||
* **dbg=1** - build with debug symbols
|
||||
```
|
||||
$ make dbg=1
|
||||
```
|
||||
* **SMS="A B ..."** - override the SM architectures for which the sample will be built, where `"A B ..."` is a space-delimited list of SM architectures. For example, to generate SASS for SM 50 and SM 60, use `SMS="50 60"`.
|
||||
```
|
||||
$ make SMS="50 60"
|
||||
```
|
||||
|
||||
* **HOST_COMPILER=<host_compiler>** - override the default g++ host compiler. See the [Linux Installation Guide](http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#system-requirements) for a list of supported host compilers.
|
||||
```
|
||||
$ make HOST_COMPILER=g++
|
||||
```
|
||||
|
||||
## References (for more details)
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
// Implements BGR 3 progressive planars frames batch resize
|
||||
|
||||
#include <cuda.h>
|
||||
#include <cuda_runtime.h>
|
||||
#include "resize_convert.h"
|
||||
|
||||
__global__ void resizeBGRplanarBatchKernel(cudaTextureObject_t texSrc,
|
||||
float *pDst, int nDstPitch, int nDstHeight, int nSrcHeight,
|
||||
int batch, float scaleX, float scaleY,
|
||||
int cropX, int cropY, int cropW, int cropH) {
|
||||
int x = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
int y = threadIdx.y + blockIdx.y * blockDim.y;
|
||||
|
||||
if (x >= (int)(cropW/scaleX) || y >= (int)(cropH/scaleY))
|
||||
return;
|
||||
|
||||
int frameSize = nDstPitch*nDstHeight;
|
||||
float *p = NULL;
|
||||
for (int i = blockIdx.z; i < batch; i += gridDim.z) {
|
||||
#pragma unroll
|
||||
for (int channel=0; channel < 3; channel++){
|
||||
p = pDst + i * 3 * frameSize + y * nDstPitch + x + channel * frameSize;
|
||||
*p = tex2D<float>(texSrc, x * scaleX + cropX,
|
||||
((3 * i + channel) * nSrcHeight + y * scaleY + cropY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void resizeBGRplanarBatchCore(
|
||||
float *dpSrc, int nSrcPitch, int nSrcWidth, int nSrcHeight,
|
||||
float *dpDst, int nDstPitch, int nDstWidth, int nDstHeight,
|
||||
int nBatchSize, cudaStream_t stream, bool whSameResizeRatio,
|
||||
int cropX, int cropY, int cropW, int cropH) {
|
||||
cudaTextureObject_t texSrc[2];
|
||||
int nTiles = 1, h, iTile;
|
||||
|
||||
h = nSrcHeight * 3 * nBatchSize;
|
||||
while ((h + nTiles - 1) / nTiles > 65536)
|
||||
nTiles++;
|
||||
|
||||
if (nTiles > 2)
|
||||
return;
|
||||
|
||||
int batchTile = nBatchSize / nTiles;
|
||||
int batchTileLast = nBatchSize - batchTile * (nTiles-1);
|
||||
|
||||
for (iTile = 0; iTile < nTiles; ++iTile) {
|
||||
int bs = (iTile == nTiles - 1) ? batchTileLast : batchTile;
|
||||
float *dpSrcNew = dpSrc +
|
||||
iTile * (batchTile * 3 * nSrcHeight * nSrcPitch);
|
||||
|
||||
cudaResourceDesc resDesc = {};
|
||||
resDesc.resType = cudaResourceTypePitch2D;
|
||||
resDesc.res.pitch2D.devPtr = dpSrcNew;
|
||||
resDesc.res.pitch2D.desc = cudaCreateChannelDesc<float>();
|
||||
resDesc.res.pitch2D.width = nSrcWidth;
|
||||
resDesc.res.pitch2D.height = bs * 3 * nSrcHeight;
|
||||
resDesc.res.pitch2D.pitchInBytes = nSrcPitch * sizeof(float);
|
||||
cudaTextureDesc texDesc = {};
|
||||
texDesc.filterMode = cudaFilterModeLinear;
|
||||
texDesc.readMode = cudaReadModeElementType;
|
||||
|
||||
checkCudaErrors(cudaCreateTextureObject(&texSrc[iTile], &resDesc, &texDesc, NULL));
|
||||
float *dpDstNew = dpDst +
|
||||
iTile * (batchTile * 3 * nDstHeight * nDstPitch);
|
||||
|
||||
if(cropW == 0 || cropH == 0) {
|
||||
cropX = 0;
|
||||
cropY = 0;
|
||||
cropW = nSrcWidth;
|
||||
cropH = nSrcHeight;
|
||||
}
|
||||
|
||||
float scaleX = (cropW*1.0f / nDstWidth);
|
||||
float scaleY = (cropH*1.0f / nDstHeight);
|
||||
|
||||
if(whSameResizeRatio == true)
|
||||
scaleX = scaleY = scaleX > scaleY ? scaleX : scaleY;
|
||||
dim3 block(32, 32, 1);
|
||||
|
||||
size_t blockDimZ = bs;
|
||||
// Restricting blocks in Z-dim till 32 to not launch too many blocks
|
||||
blockDimZ = (blockDimZ > 32) ? 32 : blockDimZ;
|
||||
dim3 grid((cropW*1.0f/scaleX + block.x - 1) / block.x,
|
||||
(cropH*1.0f/scaleY + block.y - 1) / block.y, blockDimZ);
|
||||
|
||||
resizeBGRplanarBatchKernel<<<grid, block, 0, stream>>>
|
||||
(texSrc[iTile], dpDstNew, nDstPitch, nDstHeight, nSrcHeight,
|
||||
bs, scaleX, scaleY, cropX, cropY, cropW, cropH);
|
||||
|
||||
}
|
||||
|
||||
for (iTile = 0; iTile < nTiles; ++iTile)
|
||||
checkCudaErrors(cudaDestroyTextureObject(texSrc[iTile]));
|
||||
}
|
||||
|
||||
void resizeBGRplanarBatch(
|
||||
float *dpSrc, int nSrcPitch, int nSrcWidth, int nSrcHeight,
|
||||
float *dpDst, int nDstPitch, int nDstWidth, int nDstHeight,
|
||||
int nBatchSize, cudaStream_t stream,
|
||||
int cropX, int cropY, int cropW, int cropH, bool whSameResizeRatio) {
|
||||
resizeBGRplanarBatchCore(dpSrc, nSrcPitch, nSrcWidth, nSrcHeight,
|
||||
dpDst, nDstPitch, nDstWidth, nDstHeight, nBatchSize, stream,
|
||||
whSameResizeRatio, cropX, cropY, cropW, cropH);
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// Implements interlace NV12 frames batch resize
|
||||
|
||||
#include <cuda.h>
|
||||
#include <cuda_runtime.h>
|
||||
#include "resize_convert.h"
|
||||
|
||||
__global__ static void resizeNV12BatchKernel(cudaTextureObject_t texSrcLuma,
|
||||
cudaTextureObject_t texSrcChroma,
|
||||
uint8_t *pDstNv12, int nSrcWidth,
|
||||
int nSrcHeight, int nDstPitch,
|
||||
int nDstWidth, int nDstHeight,
|
||||
int nBatchSize) {
|
||||
int x = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
int y = threadIdx.y + blockIdx.y * blockDim.y;
|
||||
|
||||
int px = x * 2, py = y * 2;
|
||||
|
||||
if ((px + 1) >= nDstWidth || (py + 1) >= nDstHeight) return;
|
||||
|
||||
float fxScale = 1.0f * nSrcWidth / nDstWidth;
|
||||
float fyScale = 1.0f * nSrcHeight / nDstHeight;
|
||||
|
||||
uint8_t *p = pDstNv12 + px + py * nDstPitch;
|
||||
int hh = nDstHeight * 3 / 2;
|
||||
int nByte = nDstPitch * hh;
|
||||
int px_fxScale = px * fxScale;
|
||||
int px_fxScale_1 = (px + 1) * fxScale;
|
||||
int py_fyScale = py * fyScale;
|
||||
int py_fyScale_1 = (py + 1) * fyScale;
|
||||
|
||||
for (int i = blockIdx.z; i < nBatchSize; i+=gridDim.z) {
|
||||
*(uchar2 *)p = make_uchar2(tex2D<uint8_t>(texSrcLuma, px_fxScale, py_fyScale),
|
||||
tex2D<uint8_t>(texSrcLuma, px_fxScale_1, py_fyScale));
|
||||
*(uchar2 *)(p + nDstPitch) =
|
||||
make_uchar2(tex2D<uint8_t>(texSrcLuma, px_fxScale, py_fyScale_1),
|
||||
tex2D<uint8_t>(texSrcLuma, px_fxScale_1, py_fyScale_1));
|
||||
*(uchar2 *)(p + (nDstHeight - y) * nDstPitch) = tex2D<uchar2>(
|
||||
texSrcChroma, x * fxScale, (hh * i + nDstHeight + y) * fyScale);
|
||||
p += nByte;
|
||||
py += hh;
|
||||
}
|
||||
}
|
||||
|
||||
void resizeNV12Batch(uint8_t *dpSrc, int nSrcPitch, int nSrcWidth,
|
||||
int nSrcHeight, uint8_t *dpDst, int nDstPitch,
|
||||
int nDstWidth, int nDstHeight, int nBatchSize,
|
||||
cudaStream_t stream) {
|
||||
int hhSrc = ceilf(nSrcHeight * 3.0f / 2.0f);
|
||||
cudaResourceDesc resDesc = {};
|
||||
resDesc.resType = cudaResourceTypePitch2D;
|
||||
resDesc.res.pitch2D.devPtr = dpSrc;
|
||||
resDesc.res.pitch2D.desc = cudaCreateChannelDesc<uint8_t>();
|
||||
resDesc.res.pitch2D.width = nSrcWidth;
|
||||
resDesc.res.pitch2D.height = hhSrc * nBatchSize;
|
||||
resDesc.res.pitch2D.pitchInBytes = nSrcPitch;
|
||||
|
||||
cudaTextureDesc texDesc = {};
|
||||
texDesc.filterMode = cudaFilterModePoint;
|
||||
texDesc.readMode = cudaReadModeElementType;
|
||||
|
||||
cudaTextureObject_t texLuma = 0;
|
||||
checkCudaErrors(cudaCreateTextureObject(&texLuma, &resDesc, &texDesc, NULL));
|
||||
|
||||
resDesc.res.pitch2D.desc = cudaCreateChannelDesc<uchar2>();
|
||||
resDesc.res.pitch2D.width /= 2;
|
||||
|
||||
cudaTextureObject_t texChroma = 0;
|
||||
checkCudaErrors(cudaCreateTextureObject(&texChroma, &resDesc, &texDesc, NULL));
|
||||
|
||||
dim3 block(32, 32, 1);
|
||||
|
||||
size_t blockDimZ = nBatchSize;
|
||||
|
||||
// Restricting blocks in Z-dim till 32 to not launch too many blocks
|
||||
blockDimZ = (blockDimZ > 32) ? 32 : blockDimZ;
|
||||
|
||||
dim3 grid((nDstWidth / 2 + block.x) / block.x,
|
||||
(nDstHeight / 2 + block.y) / block.y, blockDimZ);
|
||||
resizeNV12BatchKernel<<<grid, block, 0, stream>>>(
|
||||
texLuma, texChroma, dpDst, nSrcWidth, nSrcHeight, nDstPitch, nDstWidth,
|
||||
nDstHeight, nBatchSize);
|
||||
|
||||
checkCudaErrors(cudaDestroyTextureObject(texLuma));
|
||||
checkCudaErrors(cudaDestroyTextureObject(texChroma));
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
// Implements NV12 to BGR batch conversion
|
||||
|
||||
#include <cuda.h>
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
#include "resize_convert.h"
|
||||
|
||||
#define CONV_THREADS_X 64
|
||||
#define CONV_THREADS_Y 10
|
||||
|
||||
__forceinline__ __device__ static float clampF(float x, float lower,
|
||||
float upper) {
|
||||
return x < lower ? lower : (x > upper ? upper : x);
|
||||
}
|
||||
|
||||
__global__ static void nv12ToBGRplanarBatchKernel(const uint8_t *pNv12,
|
||||
int nNv12Pitch, float *pBgr,
|
||||
int nRgbPitch, int nWidth,
|
||||
int nHeight, int nBatchSize) {
|
||||
int x = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
int y = threadIdx.y + blockIdx.y * blockDim.y;
|
||||
|
||||
if ((x << 2) + 1 > nWidth || (y << 1) + 1 > nHeight) return;
|
||||
|
||||
const uint8_t *__restrict__ pSrc = pNv12;
|
||||
|
||||
for (int i = blockIdx.z; i < nBatchSize; i += gridDim.z) {
|
||||
pSrc = pNv12 + i * ((nHeight * nNv12Pitch * 3) >> 1) + (x << 2) +
|
||||
(y << 1) * nNv12Pitch;
|
||||
uchar4 luma2x01, luma2x23, uv2;
|
||||
*(uint32_t *)&luma2x01 = *(uint32_t *)pSrc;
|
||||
*(uint32_t *)&luma2x23 = *(uint32_t *)(pSrc + nNv12Pitch);
|
||||
*(uint32_t *)&uv2 = *(uint32_t *)(pSrc + (nHeight - y) * nNv12Pitch);
|
||||
|
||||
float *pDstBlock = (pBgr + i * ((nHeight * nRgbPitch * 3) >> 2) +
|
||||
((blockIdx.x * blockDim.x) << 2) +
|
||||
((blockIdx.y * blockDim.y) << 1) * (nRgbPitch >> 2));
|
||||
|
||||
float2 add1;
|
||||
float2 add2;
|
||||
float2 add3;
|
||||
float2 add00, add01, add02, add03;
|
||||
float2 d, e;
|
||||
|
||||
add00.x = 1.1644f * luma2x01.x;
|
||||
add01.x = 1.1644f * luma2x01.y;
|
||||
add00.y = 1.1644f * luma2x01.z;
|
||||
add01.y = 1.1644f * luma2x01.w;
|
||||
|
||||
add02.x = 1.1644f * luma2x23.x;
|
||||
add03.x = 1.1644f * luma2x23.y;
|
||||
add02.y = 1.1644f * luma2x23.z;
|
||||
add03.y = 1.1644f * luma2x23.w;
|
||||
|
||||
d.x = uv2.x - 128.0f;
|
||||
e.x = uv2.y - 128.0f;
|
||||
d.y = uv2.z - 128.0f;
|
||||
e.y = uv2.w - 128.0f;
|
||||
|
||||
add1.x = 2.0172f * d.x;
|
||||
add1.y = 2.0172f * d.y;
|
||||
|
||||
add2.x = (-0.3918f) * d.x + (-0.8130f) * e.x;
|
||||
add2.y = (-0.3918f) * d.y + (-0.8130f) * e.y;
|
||||
|
||||
add3.x = 1.5960f * e.x;
|
||||
add3.y = 1.5960f * e.y;
|
||||
|
||||
int rowStride = (threadIdx.y << 1) * (nRgbPitch >> 2);
|
||||
int nextRowStride = ((threadIdx.y << 1) + 1) * (nRgbPitch >> 2);
|
||||
// B
|
||||
*((float4 *)&pDstBlock[rowStride + (threadIdx.x << 2)]) =
|
||||
make_float4(clampF(add00.x + add1.x, 0.0f, 255.0f),
|
||||
clampF(add01.x + add1.x, 0.0f, 255.0f),
|
||||
clampF(add00.y + add1.y, 0.0f, 255.0f),
|
||||
clampF(add01.y + add1.y, 0.0f, 255.0f));
|
||||
*((float4 *)&pDstBlock[nextRowStride + (threadIdx.x << 2)]) =
|
||||
make_float4(clampF(add02.x + add1.x, 0.0f, 255.0f),
|
||||
clampF(add03.x + add1.x, 0.0f, 255.0f),
|
||||
clampF(add02.y + add1.y, 0.0f, 255.0f),
|
||||
clampF(add03.y + add1.y, 0.0f, 255.0f));
|
||||
|
||||
int planeStride = nHeight * nRgbPitch >> 2;
|
||||
// G
|
||||
*((float4 *)&pDstBlock[planeStride + rowStride + (threadIdx.x << 2)]) =
|
||||
make_float4(clampF(add00.x + add2.x, 0.0f, 255.0f),
|
||||
clampF(add01.x + add2.x, 0.0f, 255.0f),
|
||||
clampF(add00.y + add2.y, 0.0f, 255.0f),
|
||||
clampF(add01.y + add2.y, 0.0f, 255.0f));
|
||||
*((float4 *)&pDstBlock[planeStride + nextRowStride + (threadIdx.x << 2)]) =
|
||||
make_float4(clampF(add02.x + add2.x, 0.0f, 255.0f),
|
||||
clampF(add03.x + add2.x, 0.0f, 255.0f),
|
||||
clampF(add02.y + add2.y, 0.0f, 255.0f),
|
||||
clampF(add03.y + add2.y, 0.0f, 255.0f));
|
||||
|
||||
// R
|
||||
*((float4
|
||||
*)&pDstBlock[(planeStride << 1) + rowStride + (threadIdx.x << 2)]) =
|
||||
make_float4(clampF(add00.x + add3.x, 0.0f, 255.0f),
|
||||
clampF(add01.x + add3.x, 0.0f, 255.0f),
|
||||
clampF(add00.y + add3.y, 0.0f, 255.0f),
|
||||
clampF(add01.y + add3.y, 0.0f, 255.0f));
|
||||
*((float4 *)&pDstBlock[(planeStride << 1) + nextRowStride +
|
||||
(threadIdx.x << 2)]) =
|
||||
make_float4(clampF(add02.x + add3.x, 0.0f, 255.0f),
|
||||
clampF(add03.x + add3.x, 0.0f, 255.0f),
|
||||
clampF(add02.y + add3.y, 0.0f, 255.0f),
|
||||
clampF(add03.y + add3.y, 0.0f, 255.0f));
|
||||
}
|
||||
}
|
||||
|
||||
void nv12ToBGRplanarBatch(uint8_t *pNv12, int nNv12Pitch, float *pBgr,
|
||||
int nRgbPitch, int nWidth, int nHeight,
|
||||
int nBatchSize, cudaStream_t stream) {
|
||||
dim3 threads(CONV_THREADS_X, CONV_THREADS_Y);
|
||||
|
||||
size_t blockDimZ = nBatchSize;
|
||||
|
||||
// Restricting blocks in Z-dim till 32 to not launch too many blocks
|
||||
blockDimZ = (blockDimZ > 32) ? 32 : blockDimZ;
|
||||
|
||||
dim3 blocks((nWidth / 4 - 1) / threads.x + 1,
|
||||
(nHeight / 2 - 1) / threads.y + 1, blockDimZ);
|
||||
nv12ToBGRplanarBatchKernel<<<blocks, threads, 0, stream>>>(
|
||||
pNv12, nNv12Pitch, pBgr, nRgbPitch, nWidth, nHeight, nBatchSize);
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __H_RESIZE_CONVERT__
|
||||
#define __H_RESIZE_CONVERT__
|
||||
|
||||
#include <iostream>
|
||||
#include <helper_cuda.h>
|
||||
|
||||
// nv12 resize
|
||||
extern "C"
|
||||
void resizeNV12Batch(
|
||||
uint8_t *dpSrc, int nSrcPitch, int nSrcWidth, int nSrcHeight,
|
||||
uint8_t *dpDst, int nDstPitch, int nDstWidth, int nDstHeight,
|
||||
int nBatchSize, cudaStream_t stream = 0);
|
||||
|
||||
// bgr resize
|
||||
extern "C"
|
||||
void resizeBGRplanarBatch(
|
||||
float *dpSrc, int nSrcPitch, int nSrcWidth, int nSrcHeight,
|
||||
float *dpDst, int nDstPitch, int nDstWidth, int nDstHeight,
|
||||
int nBatchSize, cudaStream_t stream = 0,
|
||||
int cropX = 0, int cropY = 0, int cropW = 0, int cropH = 0,
|
||||
bool whSameResizeRatio = false);
|
||||
|
||||
//NV12 to bgr planar
|
||||
extern "C"
|
||||
void nv12ToBGRplanarBatch(uint8_t *pNv12, int nNv12Pitch,
|
||||
float *pRgb, int nRgbPitch, int nWidth, int nHeight,
|
||||
int nBatchSize, cudaStream_t stream=0);
|
||||
#endif
|
||||
@@ -1,448 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
NVIDIA HW Decoder, both dGPU and Tegra, normally outputs NV12 pitch format
|
||||
frames. For the inference using TensorRT, the input frame needs to be BGR planar
|
||||
format with possibly different size. So, conversion and resizing from NV12 to
|
||||
BGR planar is usually required for the inference following decoding.
|
||||
This CUDA code is to provide a reference implementation for conversion and
|
||||
resizing.
|
||||
|
||||
Limitaion
|
||||
=========
|
||||
NV12resize needs the height to be a even value.
|
||||
|
||||
Note
|
||||
====
|
||||
Resize function needs the pitch of image buffer to be 32 alignment.
|
||||
|
||||
Run
|
||||
====
|
||||
./NV12toBGRandResize
|
||||
OR
|
||||
./NV12toBGRandResize -input=data/test1920x1080.nv12 -width=1920 -height=1080 \
|
||||
-dst_width=640 -dst_height=480 -batch=40 -device=0
|
||||
|
||||
*/
|
||||
|
||||
#include <cuda.h>
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "resize_convert.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define TEST_LOOP 20
|
||||
|
||||
typedef struct _nv12_to_bgr24_context_t {
|
||||
int width;
|
||||
int height;
|
||||
int pitch;
|
||||
|
||||
int dst_width;
|
||||
int dst_height;
|
||||
int dst_pitch;
|
||||
|
||||
int batch;
|
||||
int device; // cuda device ID
|
||||
|
||||
char *input_nv12_file;
|
||||
|
||||
int ctx_pitch; // the value will be suitable for Texture memroy.
|
||||
int ctx_heights; // the value will be even.
|
||||
|
||||
} nv12_to_bgr24_context;
|
||||
|
||||
nv12_to_bgr24_context g_ctx;
|
||||
|
||||
static void printHelp(const char *app_name) {
|
||||
std::cout << "Usage:" << app_name << " [options]\n\n";
|
||||
std::cout << "OPTIONS:\n";
|
||||
std::cout << "\t-h,--help\n\n";
|
||||
std::cout << "\t-input=nv12file nv12 input file\n";
|
||||
std::cout
|
||||
<< "\t-width=width input nv12 image width, <1 -- 4096>\n";
|
||||
std::cout
|
||||
<< "\t-height=height input nv12 image height, <1 -- 4096>\n";
|
||||
std::cout
|
||||
<< "\t-pitch=pitch(optional) input nv12 image pitch, <0 -- 4096>\n";
|
||||
std::cout
|
||||
<< "\t-dst_width=width output BGR image width, <1 -- 4096>\n";
|
||||
std::cout
|
||||
<< "\t-dst_height=height output BGR image height, <1 -- 4096>\n";
|
||||
std::cout
|
||||
<< "\t-dst_pitch=pitch(optional) output BGR image pitch, <0 -- 4096>\n";
|
||||
std::cout
|
||||
<< "\t-batch=batch process frames count, <1 -- 4096>\n\n";
|
||||
std::cout
|
||||
<< "\t-device=device_num(optional) cuda device number, <0 -- 4096>\n\n";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int parseCmdLine(int argc, char *argv[]) {
|
||||
char **argp = (char **)argv;
|
||||
char *arg = (char *)argv[0];
|
||||
|
||||
memset(&g_ctx, 0, sizeof(g_ctx));
|
||||
|
||||
if ((arg && (!strcmp(arg, "-h") || !strcmp(arg, "--help")))) {
|
||||
printHelp(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
// Run using default arguments
|
||||
|
||||
g_ctx.input_nv12_file = sdkFindFilePath("test1920x1080.nv12", argv[0]);
|
||||
if (g_ctx.input_nv12_file == NULL) {
|
||||
printf("Cannot find input file test1920x1080.nv12\n Exiting\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
g_ctx.width = 1920;
|
||||
g_ctx.height = 1080;
|
||||
g_ctx.dst_width = 640;
|
||||
g_ctx.dst_height = 480;
|
||||
g_ctx.batch = 24;
|
||||
} else if (argc > 1) {
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "width")) {
|
||||
g_ctx.width = getCmdLineArgumentInt(argc, (const char **)argv, "width");
|
||||
}
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "height")) {
|
||||
g_ctx.height = getCmdLineArgumentInt(argc, (const char **)argv, "height");
|
||||
}
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "pitch")) {
|
||||
g_ctx.pitch = getCmdLineArgumentInt(argc, (const char **)argv, "pitch");
|
||||
}
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "input")) {
|
||||
getCmdLineArgumentString(argc, (const char **)argv, "input",
|
||||
(char **)&g_ctx.input_nv12_file);
|
||||
}
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "dst_width")) {
|
||||
g_ctx.dst_width =
|
||||
getCmdLineArgumentInt(argc, (const char **)argv, "dst_width");
|
||||
}
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "dst_height")) {
|
||||
g_ctx.dst_height =
|
||||
getCmdLineArgumentInt(argc, (const char **)argv, "dst_height");
|
||||
}
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "dst_pitch")) {
|
||||
g_ctx.dst_pitch =
|
||||
getCmdLineArgumentInt(argc, (const char **)argv, "dst_pitch");
|
||||
}
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "batch")) {
|
||||
g_ctx.batch = getCmdLineArgumentInt(argc, (const char **)argv, "batch");
|
||||
}
|
||||
}
|
||||
|
||||
g_ctx.device = findCudaDevice(argc, (const char **)argv);
|
||||
|
||||
if ((g_ctx.width == 0) || (g_ctx.height == 0) || (g_ctx.dst_width == 0) ||
|
||||
(g_ctx.dst_height == 0) || !g_ctx.input_nv12_file) {
|
||||
printHelp(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (g_ctx.pitch == 0) g_ctx.pitch = g_ctx.width;
|
||||
if (g_ctx.dst_pitch == 0) g_ctx.dst_pitch = g_ctx.dst_width;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
load nv12 yuvfile data into GPU device memory with batch of copy
|
||||
*/
|
||||
static int loadNV12Frame(unsigned char *d_inputNV12) {
|
||||
unsigned char *pNV12FrameData;
|
||||
unsigned char *d_nv12;
|
||||
int frameSize;
|
||||
std::ifstream nv12File(g_ctx.input_nv12_file, std::ifstream::in | std::ios::binary);
|
||||
|
||||
if (!nv12File.is_open()) {
|
||||
std::cerr << "Can't open files\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
frameSize = g_ctx.pitch * g_ctx.ctx_heights;
|
||||
|
||||
#if USE_UVM_MEM
|
||||
pNV12FrameData = d_inputNV12;
|
||||
#else
|
||||
pNV12FrameData = (unsigned char *)malloc(frameSize);
|
||||
if (pNV12FrameData == NULL) {
|
||||
std::cerr << "Failed to malloc pNV12FrameData\n";
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
nv12File.read((char *)pNV12FrameData, frameSize);
|
||||
|
||||
if (nv12File.gcount() < frameSize) {
|
||||
std::cerr << "can't get one frame!\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if USE_UVM_MEM
|
||||
// Prefetch to GPU for following GPU operation
|
||||
cudaStreamAttachMemAsync(NULL, pNV12FrameData, 0, cudaMemAttachGlobal);
|
||||
#endif
|
||||
|
||||
// expand one frame to multi frames for batch processing
|
||||
d_nv12 = d_inputNV12;
|
||||
for (int i = 0; i < g_ctx.batch; i++) {
|
||||
checkCudaErrors(cudaMemcpy2D((void *)d_nv12, g_ctx.ctx_pitch,
|
||||
pNV12FrameData, g_ctx.width, g_ctx.width,
|
||||
g_ctx.ctx_heights, cudaMemcpyHostToDevice));
|
||||
|
||||
d_nv12 += g_ctx.ctx_pitch * g_ctx.ctx_heights;
|
||||
}
|
||||
|
||||
#if (USE_UVM_MEM == 0)
|
||||
free(pNV12FrameData);
|
||||
#endif
|
||||
nv12File.close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
1. resize interlace nv12 to target size
|
||||
2. convert nv12 to bgr 3 progressive planars
|
||||
*/
|
||||
void nv12ResizeAndNV12ToBGR(unsigned char *d_inputNV12) {
|
||||
unsigned char *d_resizedNV12;
|
||||
float *d_outputBGR;
|
||||
int size;
|
||||
char filename[40];
|
||||
|
||||
/* allocate device memory for resized nv12 output */
|
||||
size = g_ctx.dst_width * ceil(g_ctx.dst_height * 3.0f / 2.0f) * g_ctx.batch *
|
||||
sizeof(unsigned char);
|
||||
checkCudaErrors(cudaMalloc((void **)&d_resizedNV12, size));
|
||||
|
||||
/* allocate device memory for bgr output */
|
||||
size = g_ctx.dst_pitch * g_ctx.dst_height * 3 * g_ctx.batch * sizeof(float);
|
||||
checkCudaErrors(cudaMalloc((void **)&d_outputBGR, size));
|
||||
|
||||
cudaStream_t stream;
|
||||
checkCudaErrors(cudaStreamCreate(&stream));
|
||||
/* create cuda event handles */
|
||||
cudaEvent_t start, stop;
|
||||
checkCudaErrors(cudaEventCreate(&start));
|
||||
checkCudaErrors(cudaEventCreate(&stop));
|
||||
float elapsedTime = 0.0f;
|
||||
|
||||
/* resize interlace nv12 */
|
||||
|
||||
cudaEventRecord(start, 0);
|
||||
for (int i = 0; i < TEST_LOOP; i++) {
|
||||
resizeNV12Batch(d_inputNV12, g_ctx.ctx_pitch, g_ctx.width, g_ctx.height,
|
||||
d_resizedNV12, g_ctx.dst_width, g_ctx.dst_width,
|
||||
g_ctx.dst_height, g_ctx.batch);
|
||||
}
|
||||
cudaEventRecord(stop, 0);
|
||||
cudaEventSynchronize(stop);
|
||||
|
||||
cudaEventElapsedTime(&elapsedTime, start, stop);
|
||||
printf(
|
||||
" CUDA resize nv12(%dx%d --> %dx%d), batch: %d,"
|
||||
" average time: %.3f ms ==> %.3f ms/frame\n",
|
||||
g_ctx.width, g_ctx.height, g_ctx.dst_width, g_ctx.dst_height, g_ctx.batch,
|
||||
(elapsedTime / (TEST_LOOP * 1.0f)),
|
||||
(elapsedTime / (TEST_LOOP * 1.0f)) / g_ctx.batch);
|
||||
|
||||
sprintf(filename, "resized_nv12_%dx%d", g_ctx.dst_width, g_ctx.dst_height);
|
||||
|
||||
/* convert nv12 to bgr 3 progressive planars */
|
||||
cudaEventRecord(start, 0);
|
||||
for (int i = 0; i < TEST_LOOP; i++) {
|
||||
nv12ToBGRplanarBatch(d_resizedNV12, g_ctx.dst_pitch, // intput
|
||||
d_outputBGR,
|
||||
g_ctx.dst_pitch * sizeof(float), // output
|
||||
g_ctx.dst_width, g_ctx.dst_height, // output
|
||||
g_ctx.batch, 0);
|
||||
}
|
||||
cudaEventRecord(stop, 0);
|
||||
cudaEventSynchronize(stop);
|
||||
|
||||
cudaEventElapsedTime(&elapsedTime, start, stop);
|
||||
|
||||
printf(
|
||||
" CUDA convert nv12(%dx%d) to bgr(%dx%d), batch: %d,"
|
||||
" average time: %.3f ms ==> %.3f ms/frame\n",
|
||||
g_ctx.dst_width, g_ctx.dst_height, g_ctx.dst_width, g_ctx.dst_height,
|
||||
g_ctx.batch, (elapsedTime / (TEST_LOOP * 1.0f)),
|
||||
(elapsedTime / (TEST_LOOP * 1.0f)) / g_ctx.batch);
|
||||
|
||||
sprintf(filename, "converted_bgr_%dx%d", g_ctx.dst_width, g_ctx.dst_height);
|
||||
dumpBGR(d_outputBGR, g_ctx.dst_pitch, g_ctx.dst_width, g_ctx.dst_height,
|
||||
g_ctx.batch, (char *)"t1", filename);
|
||||
|
||||
/* release resources */
|
||||
checkCudaErrors(cudaEventDestroy(start));
|
||||
checkCudaErrors(cudaEventDestroy(stop));
|
||||
checkCudaErrors(cudaStreamDestroy(stream));
|
||||
checkCudaErrors(cudaFree(d_resizedNV12));
|
||||
checkCudaErrors(cudaFree(d_outputBGR));
|
||||
}
|
||||
|
||||
/*
|
||||
1. convert nv12 to bgr 3 progressive planars
|
||||
2. resize bgr 3 planars to target size
|
||||
*/
|
||||
void nv12ToBGRandBGRresize(unsigned char *d_inputNV12) {
|
||||
float *d_bgr;
|
||||
float *d_resizedBGR;
|
||||
int size;
|
||||
char filename[40];
|
||||
|
||||
/* allocate device memory for bgr output */
|
||||
size = g_ctx.ctx_pitch * g_ctx.height * 3 * g_ctx.batch * sizeof(float);
|
||||
checkCudaErrors(cudaMalloc((void **)&d_bgr, size));
|
||||
|
||||
/* allocate device memory for resized bgr output */
|
||||
size = g_ctx.dst_width * g_ctx.dst_height * 3 * g_ctx.batch * sizeof(float);
|
||||
checkCudaErrors(cudaMalloc((void **)&d_resizedBGR, size));
|
||||
|
||||
cudaStream_t stream;
|
||||
checkCudaErrors(cudaStreamCreate(&stream));
|
||||
/* create cuda event handles */
|
||||
cudaEvent_t start, stop;
|
||||
checkCudaErrors(cudaEventCreate(&start));
|
||||
checkCudaErrors(cudaEventCreate(&stop));
|
||||
float elapsedTime = 0.0f;
|
||||
|
||||
/* convert interlace nv12 to bgr 3 progressive planars */
|
||||
cudaEventRecord(start, 0);
|
||||
cudaDeviceSynchronize();
|
||||
for (int i = 0; i < TEST_LOOP; i++) {
|
||||
nv12ToBGRplanarBatch(d_inputNV12, g_ctx.ctx_pitch, d_bgr,
|
||||
g_ctx.ctx_pitch * sizeof(float), g_ctx.width,
|
||||
g_ctx.height, g_ctx.batch, 0);
|
||||
}
|
||||
cudaEventRecord(stop, 0);
|
||||
cudaEventSynchronize(stop);
|
||||
|
||||
cudaEventElapsedTime(&elapsedTime, start, stop);
|
||||
printf(
|
||||
" CUDA convert nv12(%dx%d) to bgr(%dx%d), batch: %d,"
|
||||
" average time: %.3f ms ==> %.3f ms/frame\n",
|
||||
g_ctx.width, g_ctx.height, g_ctx.width, g_ctx.height, g_ctx.batch,
|
||||
(elapsedTime / (TEST_LOOP * 1.0f)),
|
||||
(elapsedTime / (TEST_LOOP * 1.0f)) / g_ctx.batch);
|
||||
|
||||
sprintf(filename, "converted_bgr_%dx%d", g_ctx.width, g_ctx.height);
|
||||
|
||||
/* resize bgr 3 progressive planars */
|
||||
cudaEventRecord(start, 0);
|
||||
for (int i = 0; i < TEST_LOOP; i++) {
|
||||
resizeBGRplanarBatch(d_bgr, g_ctx.ctx_pitch, g_ctx.width, g_ctx.height,
|
||||
d_resizedBGR, g_ctx.dst_width, g_ctx.dst_width,
|
||||
g_ctx.dst_height, g_ctx.batch);
|
||||
}
|
||||
cudaEventRecord(stop, 0);
|
||||
cudaEventSynchronize(stop);
|
||||
|
||||
cudaEventElapsedTime(&elapsedTime, start, stop);
|
||||
printf(
|
||||
" CUDA resize bgr(%dx%d --> %dx%d), batch: %d,"
|
||||
" average time: %.3f ms ==> %.3f ms/frame\n",
|
||||
g_ctx.width, g_ctx.height, g_ctx.dst_width, g_ctx.dst_height, g_ctx.batch,
|
||||
(elapsedTime / (TEST_LOOP * 1.0f)),
|
||||
(elapsedTime / (TEST_LOOP * 1.0f)) / g_ctx.batch);
|
||||
|
||||
memset(filename, 0, sizeof(filename));
|
||||
sprintf(filename, "resized_bgr_%dx%d", g_ctx.dst_width, g_ctx.dst_height);
|
||||
dumpBGR(d_resizedBGR, g_ctx.dst_pitch, g_ctx.dst_width, g_ctx.dst_height,
|
||||
g_ctx.batch, (char *)"t2", filename);
|
||||
|
||||
/* release resources */
|
||||
checkCudaErrors(cudaEventDestroy(start));
|
||||
checkCudaErrors(cudaEventDestroy(stop));
|
||||
checkCudaErrors(cudaStreamDestroy(stream));
|
||||
checkCudaErrors(cudaFree(d_bgr));
|
||||
checkCudaErrors(cudaFree(d_resizedBGR));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
unsigned char *d_inputNV12;
|
||||
|
||||
if (parseCmdLine(argc, argv) < 0) return EXIT_FAILURE;
|
||||
|
||||
g_ctx.ctx_pitch = g_ctx.width;
|
||||
int ctx_alignment = 32;
|
||||
g_ctx.ctx_pitch += (g_ctx.ctx_pitch % ctx_alignment != 0)
|
||||
? (ctx_alignment - g_ctx.ctx_pitch % ctx_alignment)
|
||||
: 0;
|
||||
|
||||
g_ctx.ctx_heights = ceil(g_ctx.height * 3.0f / 2.0f);
|
||||
|
||||
/* load nv12 yuv data into d_inputNV12 with batch of copies */
|
||||
#if USE_UVM_MEM
|
||||
checkCudaErrors(cudaMallocManaged(
|
||||
(void **)&d_inputNV12,
|
||||
(g_ctx.ctx_pitch * g_ctx.ctx_heights * g_ctx.batch), cudaMemAttachHost));
|
||||
printf("\nUSE_UVM_MEM\n");
|
||||
#else
|
||||
checkCudaErrors(
|
||||
cudaMalloc((void **)&d_inputNV12,
|
||||
(g_ctx.ctx_pitch * g_ctx.ctx_heights * g_ctx.batch)));
|
||||
#endif
|
||||
if (loadNV12Frame(d_inputNV12)) {
|
||||
std::cerr << "failed to load batch data!\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* firstly resize nv12, then convert nv12 to bgr */
|
||||
printf("\nTEST#1:\n");
|
||||
nv12ResizeAndNV12ToBGR(d_inputNV12);
|
||||
|
||||
/* first convert nv12 to bgr, then resize bgr */
|
||||
printf("\nTEST#2:\n");
|
||||
nv12ToBGRandBGRresize(d_inputNV12);
|
||||
|
||||
checkCudaErrors(cudaFree(d_inputNV12));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <cuda.h>
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
#include "resize_convert.h"
|
||||
#include "utils.h"
|
||||
|
||||
__global__ void floatToChar(float *src, unsigned char *dst, int height,
|
||||
int width, int batchSize) {
|
||||
int x = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
|
||||
if (x >= height * width) return;
|
||||
|
||||
int offset = height * width * 3;
|
||||
|
||||
for (int j = 0; j < batchSize; j++) {
|
||||
// b
|
||||
*(dst + j * offset + x * 3 + 0) =
|
||||
(unsigned char)*(src + j * offset + height * width * 0 + x);
|
||||
// g
|
||||
*(dst + j * offset + x * 3 + 1) =
|
||||
(unsigned char)*(src + j * offset + height * width * 1 + x);
|
||||
// r
|
||||
*(dst + j * offset + x * 3 + 2) =
|
||||
(unsigned char)*(src + j * offset + height * width * 2 + x);
|
||||
}
|
||||
}
|
||||
|
||||
void floatPlanarToChar(float *src, unsigned char *dst, int height, int width,
|
||||
int batchSize) {
|
||||
floatToChar<<<(height * width - 1) / 1024 + 1, 1024, 0, NULL>>>(
|
||||
src, dst, height, width, batchSize);
|
||||
}
|
||||
|
||||
void dumpRawBGR(float *d_srcBGR, int pitch, int width, int height,
|
||||
int batchSize, char *folder, char *tag) {
|
||||
float *bgr, *d_bgr;
|
||||
int frameSize;
|
||||
char directory[120];
|
||||
char mkdir_cmd[256];
|
||||
#if !defined(_WIN32)
|
||||
sprintf(directory, "output/%s", folder);
|
||||
sprintf(mkdir_cmd, "mkdir -p %s 2> /dev/null", directory);
|
||||
#else
|
||||
sprintf(directory, "output\\%s", folder);
|
||||
sprintf(mkdir_cmd, "mkdir %s 2> nul", directory);
|
||||
#endif
|
||||
|
||||
int ret = system(mkdir_cmd);
|
||||
|
||||
frameSize = width * height * 3 * sizeof(float);
|
||||
bgr = (float *)malloc(frameSize);
|
||||
if (bgr == NULL) {
|
||||
std::cerr << "Failed malloc for bgr\n";
|
||||
return;
|
||||
}
|
||||
|
||||
d_bgr = d_srcBGR;
|
||||
for (int i = 0; i < batchSize; i++) {
|
||||
char filename[120];
|
||||
std::ofstream *outputFile;
|
||||
|
||||
checkCudaErrors(cudaMemcpy((void *)bgr, (void *)d_bgr, frameSize,
|
||||
cudaMemcpyDeviceToHost));
|
||||
sprintf(filename, "%s/%s_%d.raw", directory, tag, (i + 1));
|
||||
|
||||
outputFile = new std::ofstream(filename);
|
||||
if (outputFile) {
|
||||
outputFile->write((char *)bgr, frameSize);
|
||||
delete outputFile;
|
||||
}
|
||||
|
||||
d_bgr += pitch * height * 3;
|
||||
}
|
||||
|
||||
free(bgr);
|
||||
}
|
||||
|
||||
void dumpBGR(float *d_srcBGR, int pitch, int width, int height, int batchSize,
|
||||
char *folder, char *tag) {
|
||||
dumpRawBGR(d_srcBGR, pitch, width, height, batchSize, folder, tag);
|
||||
}
|
||||
|
||||
void dumpYUV(unsigned char *d_nv12, int size, char *folder, char *tag) {
|
||||
unsigned char *nv12Data;
|
||||
std::ofstream *nv12File;
|
||||
char filename[120];
|
||||
char directory[60];
|
||||
char mkdir_cmd[256];
|
||||
#if !defined(_WIN32)
|
||||
sprintf(directory, "output/%s", folder);
|
||||
sprintf(mkdir_cmd, "mkdir -p %s 2> /dev/null", directory);
|
||||
#else
|
||||
sprintf(directory, "output\\%s", folder);
|
||||
sprintf(mkdir_cmd, "mkdir %s 2> nul", directory);
|
||||
#endif
|
||||
|
||||
int ret = system(mkdir_cmd);
|
||||
|
||||
sprintf(filename, "%s/%s.nv12", directory, tag);
|
||||
|
||||
nv12File = new std::ofstream(filename);
|
||||
if (nv12File == NULL) {
|
||||
std::cerr << "Failed to new " << filename;
|
||||
return;
|
||||
}
|
||||
|
||||
nv12Data = (unsigned char *)malloc(size * (sizeof(char)));
|
||||
if (nv12Data == NULL) {
|
||||
std::cerr << "Failed to allcoate memory\n";
|
||||
return;
|
||||
}
|
||||
|
||||
cudaMemcpy((void *)nv12Data, (void *)d_nv12, size, cudaMemcpyDeviceToHost);
|
||||
|
||||
nv12File->write((const char *)nv12Data, size);
|
||||
|
||||
free(nv12Data);
|
||||
delete nv12File;
|
||||
}
|
||||
@@ -1,349 +0,0 @@
|
||||
################################################################################
|
||||
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# Makefile project only supported on Mac OS X and Linux Platforms)
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# Location of the CUDA Toolkit
|
||||
CUDA_PATH ?= /usr/local/cuda
|
||||
|
||||
##############################
|
||||
# start deprecated interface #
|
||||
##############################
|
||||
ifeq ($(x86_64),1)
|
||||
$(info WARNING - x86_64 variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=x86_64 instead)
|
||||
TARGET_ARCH ?= x86_64
|
||||
endif
|
||||
ifeq ($(ARMv7),1)
|
||||
$(info WARNING - ARMv7 variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=armv7l instead)
|
||||
TARGET_ARCH ?= armv7l
|
||||
endif
|
||||
ifeq ($(aarch64),1)
|
||||
$(info WARNING - aarch64 variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=aarch64 instead)
|
||||
TARGET_ARCH ?= aarch64
|
||||
endif
|
||||
ifeq ($(ppc64le),1)
|
||||
$(info WARNING - ppc64le variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=ppc64le instead)
|
||||
TARGET_ARCH ?= ppc64le
|
||||
endif
|
||||
ifneq ($(GCC),)
|
||||
$(info WARNING - GCC variable has been deprecated)
|
||||
$(info WARNING - please use HOST_COMPILER=$(GCC) instead)
|
||||
HOST_COMPILER ?= $(GCC)
|
||||
endif
|
||||
ifneq ($(abi),)
|
||||
$(error ERROR - abi variable has been removed)
|
||||
endif
|
||||
############################
|
||||
# end deprecated interface #
|
||||
############################
|
||||
|
||||
# architecture
|
||||
HOST_ARCH := $(shell uname -m)
|
||||
TARGET_ARCH ?= $(HOST_ARCH)
|
||||
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le armv7l))
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le))
|
||||
TARGET_SIZE := 64
|
||||
else ifneq (,$(filter $(TARGET_ARCH),armv7l))
|
||||
TARGET_SIZE := 32
|
||||
endif
|
||||
else
|
||||
TARGET_SIZE := $(shell getconf LONG_BIT)
|
||||
endif
|
||||
else
|
||||
$(error ERROR - unsupported value $(TARGET_ARCH) for TARGET_ARCH!)
|
||||
endif
|
||||
|
||||
# sbsa and aarch64 systems look similar. Need to differentiate them at host level for now.
|
||||
ifeq ($(HOST_ARCH),aarch64)
|
||||
ifeq ($(CUDA_PATH)/targets/sbsa-linux,$(shell ls -1d $(CUDA_PATH)/targets/sbsa-linux 2>/dev/null))
|
||||
HOST_ARCH := sbsa
|
||||
TARGET_ARCH := sbsa
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq (,$(filter $(HOST_ARCH)-$(TARGET_ARCH),aarch64-armv7l x86_64-armv7l x86_64-aarch64 x86_64-sbsa x86_64-ppc64le))
|
||||
$(error ERROR - cross compiling from $(HOST_ARCH) to $(TARGET_ARCH) is not supported!)
|
||||
endif
|
||||
endif
|
||||
|
||||
# When on native aarch64 system with userspace of 32-bit, change TARGET_ARCH to armv7l
|
||||
ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_SIZE),aarch64-aarch64-32)
|
||||
TARGET_ARCH = armv7l
|
||||
endif
|
||||
|
||||
# operating system
|
||||
HOST_OS := $(shell uname -s 2>/dev/null | tr "[:upper:]" "[:lower:]")
|
||||
TARGET_OS ?= $(HOST_OS)
|
||||
ifeq (,$(filter $(TARGET_OS),linux darwin qnx android))
|
||||
$(error ERROR - unsupported value $(TARGET_OS) for TARGET_OS!)
|
||||
endif
|
||||
|
||||
# host compiler
|
||||
ifeq ($(TARGET_OS),darwin)
|
||||
ifeq ($(shell expr `xcodebuild -version | grep -i xcode | awk '{print $$2}' | cut -d'.' -f1` \>= 5),1)
|
||||
HOST_COMPILER ?= clang++
|
||||
endif
|
||||
else ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq ($(HOST_ARCH)-$(TARGET_ARCH),x86_64-armv7l)
|
||||
ifeq ($(TARGET_OS),linux)
|
||||
HOST_COMPILER ?= arm-linux-gnueabihf-g++
|
||||
else ifeq ($(TARGET_OS),qnx)
|
||||
ifeq ($(QNX_HOST),)
|
||||
$(error ERROR - QNX_HOST must be passed to the QNX host toolchain)
|
||||
endif
|
||||
ifeq ($(QNX_TARGET),)
|
||||
$(error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
|
||||
endif
|
||||
export QNX_HOST
|
||||
export QNX_TARGET
|
||||
HOST_COMPILER ?= $(QNX_HOST)/usr/bin/arm-unknown-nto-qnx6.6.0eabi-g++
|
||||
else ifeq ($(TARGET_OS),android)
|
||||
HOST_COMPILER ?= arm-linux-androideabi-g++
|
||||
endif
|
||||
else ifeq ($(TARGET_ARCH),aarch64)
|
||||
ifeq ($(TARGET_OS), linux)
|
||||
HOST_COMPILER ?= aarch64-linux-gnu-g++
|
||||
else ifeq ($(TARGET_OS),qnx)
|
||||
ifeq ($(QNX_HOST),)
|
||||
$(error ERROR - QNX_HOST must be passed to the QNX host toolchain)
|
||||
endif
|
||||
ifeq ($(QNX_TARGET),)
|
||||
$(error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
|
||||
endif
|
||||
export QNX_HOST
|
||||
export QNX_TARGET
|
||||
HOST_COMPILER ?= $(QNX_HOST)/usr/bin/q++
|
||||
else ifeq ($(TARGET_OS), android)
|
||||
HOST_COMPILER ?= aarch64-linux-android-clang++
|
||||
endif
|
||||
else ifeq ($(TARGET_ARCH),sbsa)
|
||||
HOST_COMPILER ?= aarch64-linux-gnu-g++
|
||||
else ifeq ($(TARGET_ARCH),ppc64le)
|
||||
HOST_COMPILER ?= powerpc64le-linux-gnu-g++
|
||||
endif
|
||||
endif
|
||||
HOST_COMPILER ?= g++
|
||||
NVCC := $(CUDA_PATH)/bin/nvcc -ccbin $(HOST_COMPILER)
|
||||
|
||||
# internal flags
|
||||
NVCCFLAGS := -m${TARGET_SIZE}
|
||||
CCFLAGS :=
|
||||
LDFLAGS :=
|
||||
|
||||
# build flags
|
||||
ifeq ($(TARGET_OS),darwin)
|
||||
LDFLAGS += -rpath $(CUDA_PATH)/lib
|
||||
CCFLAGS += -arch $(HOST_ARCH)
|
||||
else ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_OS),x86_64-armv7l-linux)
|
||||
LDFLAGS += --dynamic-linker=/lib/ld-linux-armhf.so.3
|
||||
CCFLAGS += -mfloat-abi=hard
|
||||
else ifeq ($(TARGET_OS),android)
|
||||
LDFLAGS += -pie
|
||||
CCFLAGS += -fpie -fpic -fexceptions
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
|
||||
ifneq ($(TARGET_FS),)
|
||||
GCCVERSIONLTEQ46 := $(shell expr `$(HOST_COMPILER) -dumpversion` \<= 4.6)
|
||||
ifeq ($(GCCVERSIONLTEQ46),1)
|
||||
CCFLAGS += --sysroot=$(TARGET_FS)
|
||||
endif
|
||||
LDFLAGS += --sysroot=$(TARGET_FS)
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/arm-linux-gnueabihf
|
||||
endif
|
||||
endif
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
|
||||
ifneq ($(TARGET_FS),)
|
||||
GCCVERSIONLTEQ46 := $(shell expr `$(HOST_COMPILER) -dumpversion` \<= 4.6)
|
||||
ifeq ($(GCCVERSIONLTEQ46),1)
|
||||
CCFLAGS += --sysroot=$(TARGET_FS)
|
||||
endif
|
||||
LDFLAGS += --sysroot=$(TARGET_FS)
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib -L$(TARGET_FS)/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib/aarch64-linux-gnu -L$(TARGET_FS)/lib/aarch64-linux-gnu
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib -L$(TARGET_FS)/usr/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/aarch64-linux-gnu -L$(TARGET_FS)/usr/lib/aarch64-linux-gnu
|
||||
LDFLAGS += --unresolved-symbols=ignore-in-shared-libs
|
||||
CCFLAGS += -isystem=$(TARGET_FS)/usr/include -I$(TARGET_FS)/usr/include -I$(TARGET_FS)/usr/include/libdrm
|
||||
CCFLAGS += -isystem=$(TARGET_FS)/usr/include/aarch64-linux-gnu -I$(TARGET_FS)/usr/include/aarch64-linux-gnu
|
||||
endif
|
||||
endif
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
|
||||
NVCCFLAGS += --qpp-config 5.4.0,gcc_ntoaarch64le
|
||||
CCFLAGS += -DWIN_INTERFACE_CUSTOM -I/usr/include/aarch64-qnx-gnu
|
||||
LDFLAGS += -lsocket
|
||||
LDFLAGS += -L/usr/lib/aarch64-qnx-gnu
|
||||
CCFLAGS += "-Wl\,-rpath-link\,/usr/lib/aarch64-qnx-gnu"
|
||||
ifdef TARGET_OVERRIDE
|
||||
LDFLAGS += -lslog2
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_FS),)
|
||||
LDFLAGS += -L$(TARGET_FS)/usr/lib
|
||||
CCFLAGS += "-Wl\,-rpath-link\,$(TARGET_FS)/usr/lib"
|
||||
LDFLAGS += -L$(TARGET_FS)/usr/libnvidia
|
||||
CCFLAGS += "-Wl\,-rpath-link\,$(TARGET_FS)/usr/libnvidia"
|
||||
CCFLAGS += -I$(TARGET_FS)/../include
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef TARGET_OVERRIDE # cuda toolkit targets override
|
||||
NVCCFLAGS += -target-dir $(TARGET_OVERRIDE)
|
||||
endif
|
||||
|
||||
# Install directory of different arch
|
||||
CUDA_INSTALL_TARGET_DIR :=
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-gnueabihf/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),sbsa-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/sbsa-linux/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-android)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-androideabi/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-android)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux-androideabi/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-qnx)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/ARMv7-linux-QNX/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-qnx/
|
||||
else ifeq ($(TARGET_ARCH),ppc64le)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/ppc64le-linux/
|
||||
endif
|
||||
|
||||
# Debug build flags
|
||||
ifeq ($(dbg),1)
|
||||
NVCCFLAGS += -g -G
|
||||
BUILD_TYPE := debug
|
||||
else
|
||||
BUILD_TYPE := release
|
||||
endif
|
||||
|
||||
ALL_CCFLAGS :=
|
||||
ALL_CCFLAGS += $(NVCCFLAGS)
|
||||
ALL_CCFLAGS += $(EXTRA_NVCCFLAGS)
|
||||
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(CCFLAGS))
|
||||
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(EXTRA_CCFLAGS))
|
||||
|
||||
SAMPLE_ENABLED := 1
|
||||
|
||||
# This sample is not supported on QNX
|
||||
ifeq ($(TARGET_OS),qnx)
|
||||
$(info >>> WARNING - UnifiedMemoryPerf is not supported on QNX - waiving sample <<<)
|
||||
SAMPLE_ENABLED := 0
|
||||
endif
|
||||
|
||||
ALL_LDFLAGS :=
|
||||
ALL_LDFLAGS += $(ALL_CCFLAGS)
|
||||
ALL_LDFLAGS += $(addprefix -Xlinker ,$(LDFLAGS))
|
||||
ALL_LDFLAGS += $(addprefix -Xlinker ,$(EXTRA_LDFLAGS))
|
||||
|
||||
# Common includes and paths for CUDA
|
||||
INCLUDES := -I../../Common
|
||||
LIBRARIES :=
|
||||
|
||||
################################################################################
|
||||
|
||||
# Gencode arguments
|
||||
ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),armv7l aarch64))
|
||||
SMS ?= 35 37 50 52 60 61 70 72 75 80 86
|
||||
else
|
||||
SMS ?= 35 37 50 52 60 61 70 75 80 86
|
||||
endif
|
||||
|
||||
ifeq ($(SMS),)
|
||||
$(info >>> WARNING - no SM architectures have been specified - waiving sample <<<)
|
||||
SAMPLE_ENABLED := 0
|
||||
endif
|
||||
|
||||
ifeq ($(GENCODE_FLAGS),)
|
||||
# Generate SASS code for each SM architecture listed in $(SMS)
|
||||
$(foreach sm,$(SMS),$(eval GENCODE_FLAGS += -gencode arch=compute_$(sm),code=sm_$(sm)))
|
||||
|
||||
# Generate PTX code from the highest SM architecture in $(SMS) to guarantee forward-compatibility
|
||||
HIGHEST_SM := $(lastword $(sort $(SMS)))
|
||||
ifneq ($(HIGHEST_SM),)
|
||||
GENCODE_FLAGS += -gencode arch=compute_$(HIGHEST_SM),code=compute_$(HIGHEST_SM)
|
||||
endif
|
||||
endif
|
||||
|
||||
ALL_CCFLAGS += --threads 0
|
||||
|
||||
ifeq ($(SAMPLE_ENABLED),0)
|
||||
EXEC ?= @echo "[@]"
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
|
||||
# Target rules
|
||||
all: build
|
||||
|
||||
build: UnifiedMemoryPerf
|
||||
|
||||
check.deps:
|
||||
ifeq ($(SAMPLE_ENABLED),0)
|
||||
@echo "Sample will be waived due to the above missing dependencies"
|
||||
else
|
||||
@echo "Sample is ready - all dependencies have been met"
|
||||
endif
|
||||
|
||||
commonKernels.o:commonKernels.cu
|
||||
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
|
||||
|
||||
helperFunctions.o:helperFunctions.cpp
|
||||
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
|
||||
|
||||
matrixMultiplyPerf.o:matrixMultiplyPerf.cu
|
||||
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
|
||||
|
||||
UnifiedMemoryPerf: commonKernels.o helperFunctions.o matrixMultiplyPerf.o
|
||||
$(EXEC) $(NVCC) $(ALL_LDFLAGS) $(GENCODE_FLAGS) -o $@ $+ $(LIBRARIES)
|
||||
$(EXEC) mkdir -p ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
|
||||
$(EXEC) cp $@ ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
|
||||
|
||||
run: build
|
||||
$(EXEC) ./UnifiedMemoryPerf
|
||||
|
||||
clean:
|
||||
rm -f UnifiedMemoryPerf commonKernels.o helperFunctions.o matrixMultiplyPerf.o
|
||||
rm -rf ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)/UnifiedMemoryPerf
|
||||
|
||||
clobber: clean
|
||||
@@ -1,75 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE entry SYSTEM "SamplesInfo.dtd">
|
||||
<entry>
|
||||
<name>UnifiedMemoryPerf</name>
|
||||
<cuda_api_list>
|
||||
<toolkit>cudaMallocManaged</toolkit>
|
||||
<toolkit>cudaStreamAttachMemAsync</toolkit>
|
||||
<toolkit>cudaMemcpyAsync</toolkit>
|
||||
<toolkit>cudaMallocHost</toolkit>
|
||||
<toolkit>cudaMalloc</toolkit>
|
||||
</cuda_api_list>
|
||||
<description><![CDATA[This sample demonstrates the performance comparision using matrix multiplication kernel of Unified Memory with/without hints and other types of memory like zero copy buffers, pageable, pagelocked memory performing synchronous and Asynchronous transfers on a single GPU.]]></description>
|
||||
<devicecompilation>whole</devicecompilation>
|
||||
<includepaths>
|
||||
<path>./</path>
|
||||
<path>../</path>
|
||||
<path>../../common/inc</path>
|
||||
</includepaths>
|
||||
<keyconcepts>
|
||||
<concept level="basic">CUDA Systems Integration</concept>
|
||||
<concept level="basic">Unified Memory</concept>
|
||||
<concept level="basic">CUDA Streams and Events</concept>
|
||||
<concept level="basic">Pinned System Paged Memory</concept>
|
||||
</keyconcepts>
|
||||
<keywords>
|
||||
<keyword>CUDA</keyword>
|
||||
<keyword>Unified Memory</keyword>
|
||||
<keyword>Pinned Memory</keyword>
|
||||
<keyword>Zero copy buffer</keyword>
|
||||
<keyword>UVM</keyword>
|
||||
<keyword>Streams</keyword>
|
||||
</keywords>
|
||||
<libraries>
|
||||
</libraries>
|
||||
<librarypaths>
|
||||
</librarypaths>
|
||||
<nsight_eclipse>true</nsight_eclipse>
|
||||
<primary_file>matrixMultiplyPerf.cu</primary_file>
|
||||
<required_dependencies>
|
||||
<dependency>UVM</dependency>
|
||||
</required_dependencies>
|
||||
<scopes>
|
||||
<scope>1:CUDA Basic Topics</scope>
|
||||
<scope>1:CUDA Systems Integration</scope>
|
||||
<scope>1:Unified Memory</scope>
|
||||
</scopes>
|
||||
<supported_envs>
|
||||
<env>
|
||||
<arch>x86_64</arch>
|
||||
<platform>linux</platform>
|
||||
</env>
|
||||
<env>
|
||||
<arch>x86_64</arch>
|
||||
<platform>macosx</platform>
|
||||
</env>
|
||||
<env>
|
||||
<platform>windows7</platform>
|
||||
</env>
|
||||
<env>
|
||||
<arch>arm</arch>
|
||||
</env>
|
||||
<env>
|
||||
<arch>aarch64</arch>
|
||||
</env>
|
||||
<env>
|
||||
<arch>ppc64le</arch>
|
||||
<platform>linux</platform>
|
||||
</env>
|
||||
</supported_envs>
|
||||
<supported_sm_architectures>
|
||||
<from>3.0</from>
|
||||
</supported_sm_architectures>
|
||||
<title>Unified and other CUDA Memories Performance</title>
|
||||
<type>exe</type>
|
||||
</entry>
|
||||
@@ -1,72 +0,0 @@
|
||||
# UnifiedMemoryPerf - Unified and other CUDA Memories Performance
|
||||
|
||||
## Description
|
||||
|
||||
This sample demonstrates the performance comparision using matrix multiplication kernel of Unified Memory with/without hints and other types of memory like zero copy buffers, pageable, pagelocked memory performing synchronous and Asynchronous transfers on a single GPU.
|
||||
|
||||
## Key Concepts
|
||||
|
||||
CUDA Systems Integration, Unified Memory, CUDA Streams and Events, Pinned System Paged Memory
|
||||
|
||||
## Supported SM Architectures
|
||||
|
||||
## Supported OSes
|
||||
|
||||
Linux, Windows
|
||||
|
||||
## Supported CPU Architecture
|
||||
|
||||
x86_64, ppc64le, armv7l, aarch64
|
||||
|
||||
## CUDA APIs involved
|
||||
|
||||
### [CUDA Runtime API](http://docs.nvidia.com/cuda/cuda-runtime-api/index.html)
|
||||
cudaMallocManaged, cudaStreamAttachMemAsync, cudaMemcpyAsync, cudaMallocHost, cudaMalloc
|
||||
|
||||
## Dependencies needed to build/run
|
||||
[UVM](../../README.md#uvm)
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Download and install the [CUDA Toolkit 11.4](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
||||
Make sure the dependencies mentioned in [Dependencies]() section above are installed.
|
||||
|
||||
## Build and Run
|
||||
|
||||
### Windows
|
||||
The Windows samples are built using the Visual Studio IDE. Solution files (.sln) are provided for each supported version of Visual Studio, using the format:
|
||||
```
|
||||
*_vs<version>.sln - for Visual Studio <version>
|
||||
```
|
||||
Each individual sample has its own set of solution files in its directory:
|
||||
|
||||
To build/examine all the samples at once, the complete solution files should be used. To build/examine a single sample, the individual sample solution files should be used.
|
||||
> **Note:** Some samples require that the Microsoft DirectX SDK (June 2010 or newer) be installed and that the VC++ directory paths are properly set up (**Tools > Options...**). Check DirectX Dependencies section for details."
|
||||
|
||||
### Linux
|
||||
The Linux samples are built using makefiles. To use the makefiles, change the current directory to the sample directory you wish to build, and run make:
|
||||
```
|
||||
$ cd <sample_dir>
|
||||
$ make
|
||||
```
|
||||
The samples makefiles can take advantage of certain options:
|
||||
* **TARGET_ARCH=<arch>** - cross-compile targeting a specific architecture. Allowed architectures are x86_64, ppc64le, armv7l, aarch64.
|
||||
By default, TARGET_ARCH is set to HOST_ARCH. On a x86_64 machine, not setting TARGET_ARCH is the equivalent of setting TARGET_ARCH=x86_64.<br/>
|
||||
`$ make TARGET_ARCH=x86_64` <br/> `$ make TARGET_ARCH=ppc64le` <br/> `$ make TARGET_ARCH=armv7l` <br/> `$ make TARGET_ARCH=aarch64` <br/>
|
||||
See [here](http://docs.nvidia.com/cuda/cuda-samples/index.html#cross-samples) for more details.
|
||||
* **dbg=1** - build with debug symbols
|
||||
```
|
||||
$ make dbg=1
|
||||
```
|
||||
* **SMS="A B ..."** - override the SM architectures for which the sample will be built, where `"A B ..."` is a space-delimited list of SM architectures. For example, to generate SASS for SM 50 and SM 60, use `SMS="50 60"`.
|
||||
```
|
||||
$ make SMS="50 60"
|
||||
```
|
||||
|
||||
* **HOST_COMPILER=<host_compiler>** - override the default g++ host compiler. See the [Linux Installation Guide](http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#system-requirements) for a list of supported host compilers.
|
||||
```
|
||||
$ make HOST_COMPILER=g++
|
||||
```
|
||||
|
||||
## References (for more details)
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2017
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnifiedMemoryPerf", "UnifiedMemoryPerf_vs2017.vcxproj", "{997E0757-EA74-4A4E-A0FC-47D8C8831A15}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.Build.0 = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.ActiveCfg = Release|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,116 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<CUDAPropsPath Condition="'$(CUDAPropsPath)'==''">$(VCTargetsPath)\BuildCustomizations</CUDAPropsPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{997E0757-EA74-4A4E-A0FC-47D8C8831A15}</ProjectGuid>
|
||||
<RootNamespace>UnifiedMemoryPerf_vs2017</RootNamespace>
|
||||
<ProjectName>UnifiedMemoryPerf</ProjectName>
|
||||
<CudaToolkitCustomDir />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(WindowsTargetPlatformVersion)'==''">
|
||||
<LatestTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</LatestTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion Condition="'$(WindowsTargetPlatformVersion)' == ''">$(LatestTargetPlatformVersion)</WindowsTargetPlatformVersion>
|
||||
<TargetPlatformVersion>$(WindowsTargetPlatformVersion)</TargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup>
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IntDir>$(Platform)/$(Configuration)/</IntDir>
|
||||
<IncludePath>$(IncludePath)</IncludePath>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
||||
<OutDir>../../bin/win64/$(Configuration)/</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>./;$(CudaToolkitDir)/include;../../Common;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(CudaToolkitLibDir);</AdditionalLibraryDirectories>
|
||||
<OutputFile>$(OutDir)/UnifiedMemoryPerf.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_35,sm_35;compute_37,sm_37;compute_50,sm_50;compute_52,sm_52;compute_60,sm_60;compute_61,sm_61;compute_70,sm_70;compute_75,sm_75;compute_80,sm_80;compute_86,sm_86;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Include>./;../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
<AdditionalOptions>--threads 0</AdditionalOptions>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MTd</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MT</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<CudaCompile Include="commonKernels.cu" />
|
||||
<ClCompile Include="helperFunctions.cpp" />
|
||||
<CudaCompile Include="matrixMultiplyPerf.cu" />
|
||||
<ClInclude Include="commonDefs.hpp" />
|
||||
<ClInclude Include="commonKernels.hpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -1,20 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2019
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnifiedMemoryPerf", "UnifiedMemoryPerf_vs2019.vcxproj", "{997E0757-EA74-4A4E-A0FC-47D8C8831A15}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.Build.0 = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.ActiveCfg = Release|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,112 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<CUDAPropsPath Condition="'$(CUDAPropsPath)'==''">$(VCTargetsPath)\BuildCustomizations</CUDAPropsPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{997E0757-EA74-4A4E-A0FC-47D8C8831A15}</ProjectGuid>
|
||||
<RootNamespace>UnifiedMemoryPerf_vs2019</RootNamespace>
|
||||
<ProjectName>UnifiedMemoryPerf</ProjectName>
|
||||
<CudaToolkitCustomDir />
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup>
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.4.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IntDir>$(Platform)/$(Configuration)/</IntDir>
|
||||
<IncludePath>$(IncludePath)</IncludePath>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
||||
<OutDir>../../bin/win64/$(Configuration)/</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>./;$(CudaToolkitDir)/include;../../Common;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(CudaToolkitLibDir);</AdditionalLibraryDirectories>
|
||||
<OutputFile>$(OutDir)/UnifiedMemoryPerf.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_35,sm_35;compute_37,sm_37;compute_50,sm_50;compute_52,sm_52;compute_60,sm_60;compute_61,sm_61;compute_70,sm_70;compute_75,sm_75;compute_80,sm_80;compute_86,sm_86;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Include>./;../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
<AdditionalOptions>--threads 0</AdditionalOptions>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MTd</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MT</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<CudaCompile Include="commonKernels.cu" />
|
||||
<ClCompile Include="helperFunctions.cpp" />
|
||||
<CudaCompile Include="matrixMultiplyPerf.cu" />
|
||||
<ClInclude Include="commonDefs.hpp" />
|
||||
<ClInclude Include="commonKernels.hpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.4.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -1,88 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _COMMON_DEFS_
|
||||
#define _COMMON_DEFS_
|
||||
#include <cuda.h>
|
||||
|
||||
#define ONE_KB 1024
|
||||
#define ONE_MB (ONE_KB * ONE_KB)
|
||||
|
||||
extern size_t maxSampleSizeInMb;
|
||||
extern int numKernelRuns;
|
||||
extern int verboseResults;
|
||||
|
||||
extern unsigned int findNumSizesToTest(unsigned int minSize,
|
||||
unsigned int maxSize,
|
||||
unsigned int multiplier);
|
||||
|
||||
// For Tracking the different memory allocation types
|
||||
typedef enum memAllocType_enum {
|
||||
MEMALLOC_TYPE_START,
|
||||
USE_MANAGED_MEMORY_WITH_HINTS = MEMALLOC_TYPE_START,
|
||||
USE_MANAGED_MEMORY_WITH_HINTS_ASYNC,
|
||||
USE_MANAGED_MEMORY,
|
||||
USE_ZERO_COPY,
|
||||
USE_HOST_PAGEABLE_AND_DEVICE_MEMORY,
|
||||
USE_HOST_PAGEABLE_AND_DEVICE_MEMORY_ASYNC,
|
||||
USE_HOST_PAGELOCKED_AND_DEVICE_MEMORY,
|
||||
USE_HOST_PAGELOCKED_AND_DEVICE_MEMORY_ASYNC,
|
||||
MEMALLOC_TYPE_END = USE_HOST_PAGELOCKED_AND_DEVICE_MEMORY_ASYNC,
|
||||
MEMALLOC_TYPE_INVALID,
|
||||
MEMALLOC_TYPE_COUNT = MEMALLOC_TYPE_INVALID
|
||||
} MemAllocType;
|
||||
|
||||
typedef enum bandwidthType_enum {
|
||||
READ_BANDWIDTH,
|
||||
WRITE_BANDWIDTH
|
||||
} BandwidthType;
|
||||
|
||||
extern const char *memAllocTypeStr[];
|
||||
extern const char *memAllocTypeShortStr[];
|
||||
|
||||
struct resultsData;
|
||||
struct testResults;
|
||||
|
||||
void createAndInitTestResults(struct testResults **results,
|
||||
const char *testName,
|
||||
unsigned int numMeasurements,
|
||||
unsigned int numSizesToTest);
|
||||
unsigned long *getPtrSizesToTest(struct testResults *results);
|
||||
|
||||
void freeTestResultsAndAllResultsData(struct testResults *results);
|
||||
|
||||
void createResultDataAndAddToTestResults(struct resultsData **ptrData,
|
||||
struct testResults *results,
|
||||
const char *resultsName,
|
||||
bool printOnlyInVerbose,
|
||||
bool reportAsBandwidth);
|
||||
double *getPtrRunTimesInMs(struct resultsData *data, int allocType,
|
||||
int sizeIndex);
|
||||
|
||||
void printResults(struct testResults *results,
|
||||
bool print_launch_transfer_results, bool print_std_deviation);
|
||||
#endif
|
||||
@@ -1,303 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "commonDefs.hpp"
|
||||
#define CU_INIT_UUID
|
||||
#include <cmath>
|
||||
|
||||
#define UNITS_Time "ms"
|
||||
#define UNITS_BW "MB/s"
|
||||
#define KB_str "KB"
|
||||
#define MB_str "MB"
|
||||
|
||||
struct resultsData {
|
||||
char resultsName[64];
|
||||
struct testResults *results;
|
||||
// this has MEMALLOC_TYPE_COUNT * results->numSizesToTest *
|
||||
// results->numMeasurements elements
|
||||
double **runTimesInMs[MEMALLOC_TYPE_COUNT];
|
||||
double *averageRunTimesInMs[MEMALLOC_TYPE_COUNT];
|
||||
double *stdDevRunTimesInMs[MEMALLOC_TYPE_COUNT];
|
||||
double *stdDevBandwidthInMBps[MEMALLOC_TYPE_COUNT];
|
||||
bool printOnlyInVerbose;
|
||||
bool reportAsBandwidth;
|
||||
struct resultsData *next;
|
||||
};
|
||||
|
||||
struct testResults {
|
||||
char testName[64];
|
||||
unsigned int numMeasurements;
|
||||
unsigned long *sizesToTest;
|
||||
unsigned int numSizesToTest;
|
||||
struct resultsData *resultsDataHead;
|
||||
struct resultsData *resultsDataTail;
|
||||
};
|
||||
|
||||
unsigned int findNumSizesToTest(unsigned int minSize, unsigned int maxSize,
|
||||
unsigned int multiplier) {
|
||||
unsigned int numSizesToTest = 0;
|
||||
while (minSize <= maxSize) {
|
||||
numSizesToTest++;
|
||||
minSize *= multiplier;
|
||||
}
|
||||
return numSizesToTest;
|
||||
}
|
||||
|
||||
int compareDoubles(const void *ptr1, const void *ptr2) {
|
||||
return (*(double *)ptr1 > *(double *)ptr2) ? 1 : -1;
|
||||
}
|
||||
|
||||
static inline double getTimeOrBandwidth(double runTimeInMs, unsigned long size,
|
||||
bool getBandwidth) {
|
||||
return (getBandwidth) ? (1000 * (size / runTimeInMs)) / ONE_MB : runTimeInMs;
|
||||
}
|
||||
|
||||
void createAndInitTestResults(struct testResults **ptrResults,
|
||||
const char *testName,
|
||||
unsigned int numMeasurements,
|
||||
unsigned int numSizesToTest) {
|
||||
unsigned int i;
|
||||
struct testResults *results;
|
||||
results = (struct testResults *)malloc(sizeof(struct testResults));
|
||||
memset(results, 0, sizeof(struct testResults));
|
||||
strcpy(results->testName, testName);
|
||||
results->numMeasurements = numMeasurements;
|
||||
results->numSizesToTest = numSizesToTest;
|
||||
results->sizesToTest =
|
||||
(unsigned long *)malloc(numSizesToTest * sizeof(unsigned long));
|
||||
results->resultsDataHead = NULL;
|
||||
results->resultsDataTail = NULL;
|
||||
|
||||
*ptrResults = results;
|
||||
}
|
||||
|
||||
unsigned long *getPtrSizesToTest(struct testResults *results) {
|
||||
return results->sizesToTest;
|
||||
}
|
||||
|
||||
void createResultDataAndAddToTestResults(struct resultsData **ptrData,
|
||||
struct testResults *results,
|
||||
const char *resultsName,
|
||||
bool printOnlyInVerbose,
|
||||
bool reportAsBandwidth) {
|
||||
unsigned int i, j;
|
||||
struct resultsData *data;
|
||||
data = (struct resultsData *)malloc(sizeof(struct resultsData));
|
||||
memset(data, 0, sizeof(struct resultsData));
|
||||
strcpy(data->resultsName, resultsName);
|
||||
data->results = results;
|
||||
for (i = 0; i < MEMALLOC_TYPE_COUNT; i++) {
|
||||
data->runTimesInMs[i] =
|
||||
(double **)malloc(results->numSizesToTest * sizeof(double *));
|
||||
for (j = 0; j < results->numSizesToTest; j++) {
|
||||
data->runTimesInMs[i][j] =
|
||||
(double *)malloc(results->numMeasurements * sizeof(double));
|
||||
}
|
||||
data->averageRunTimesInMs[i] =
|
||||
(double *)malloc(results->numSizesToTest * sizeof(double));
|
||||
data->stdDevRunTimesInMs[i] =
|
||||
(double *)malloc(results->numSizesToTest * sizeof(double));
|
||||
data->stdDevBandwidthInMBps[i] =
|
||||
(double *)malloc(results->numSizesToTest * sizeof(double));
|
||||
}
|
||||
data->printOnlyInVerbose = printOnlyInVerbose;
|
||||
data->reportAsBandwidth = reportAsBandwidth;
|
||||
data->next = NULL;
|
||||
*ptrData = data;
|
||||
if (results->resultsDataHead == NULL) {
|
||||
results->resultsDataHead = data;
|
||||
results->resultsDataTail = data;
|
||||
} else {
|
||||
results->resultsDataTail->next = data;
|
||||
results->resultsDataTail = data;
|
||||
}
|
||||
}
|
||||
|
||||
double *getPtrRunTimesInMs(struct resultsData *data, int allocType,
|
||||
int sizeIndex) {
|
||||
return data->runTimesInMs[allocType][sizeIndex];
|
||||
}
|
||||
|
||||
void freeTestResultsAndAllResultsData(struct testResults *results) {
|
||||
struct resultsData *data, *dataToFree;
|
||||
unsigned int i, j;
|
||||
for (data = results->resultsDataHead; data != NULL;) {
|
||||
for (i = 0; i < MEMALLOC_TYPE_COUNT; i++) {
|
||||
for (j = 0; j < results->numSizesToTest; j++) {
|
||||
free(data->runTimesInMs[i][j]);
|
||||
}
|
||||
free(data->runTimesInMs[i]);
|
||||
free(data->averageRunTimesInMs[i]);
|
||||
free(data->stdDevRunTimesInMs[i]);
|
||||
free(data->stdDevBandwidthInMBps[i]);
|
||||
}
|
||||
dataToFree = data;
|
||||
data = data->next;
|
||||
free(dataToFree);
|
||||
}
|
||||
free(results->sizesToTest);
|
||||
free(results);
|
||||
}
|
||||
|
||||
void calculateAverageAndStdDev(double *pAverage, double *pStdDev,
|
||||
double *allResults, unsigned int count) {
|
||||
unsigned int i;
|
||||
double average = 0.0;
|
||||
double stdDev = 0.0;
|
||||
for (i = 0; i < count; i++) {
|
||||
average += allResults[i];
|
||||
}
|
||||
average /= count;
|
||||
for (i = 0; i < count; i++) {
|
||||
stdDev += (allResults[i] - average) * (allResults[i] - average);
|
||||
}
|
||||
stdDev /= count;
|
||||
stdDev = sqrt(stdDev);
|
||||
*pAverage = average;
|
||||
*pStdDev = (average == 0.0) ? 0.0 : ((100.0 * stdDev) / average);
|
||||
}
|
||||
|
||||
void calculateStdDevBandwidth(double *pStdDev, double *allResults,
|
||||
unsigned int count, unsigned long size) {
|
||||
unsigned int i;
|
||||
double bandwidth;
|
||||
double average = 0.0;
|
||||
double stdDev = 0.0;
|
||||
for (i = 0; i < count; i++) {
|
||||
bandwidth = (1000 * (size / allResults[i])) / ONE_MB;
|
||||
average += bandwidth;
|
||||
}
|
||||
average /= count;
|
||||
for (i = 0; i < count; i++) {
|
||||
bandwidth = (1000 * (size / allResults[i])) / ONE_MB;
|
||||
stdDev += (bandwidth - average) * (bandwidth - average);
|
||||
}
|
||||
stdDev /= count;
|
||||
stdDev = sqrt(stdDev);
|
||||
*pStdDev = (average == 0.0) ? 0.0 : ((100.0 * stdDev) / average);
|
||||
}
|
||||
|
||||
void printTimesInTableFormat(struct testResults *results,
|
||||
struct resultsData *data, bool printAverage,
|
||||
bool printStdDev) {
|
||||
unsigned int i, j;
|
||||
bool printStdDevBandwidth = printStdDev && data->reportAsBandwidth;
|
||||
printf("Size_KB");
|
||||
for (i = 0; i < MEMALLOC_TYPE_COUNT; i++) {
|
||||
printf("\t%7s", memAllocTypeShortStr[i]);
|
||||
}
|
||||
printf("\n");
|
||||
for (j = 0; j < results->numSizesToTest; j++) {
|
||||
printf("%lu", results->sizesToTest[j] / ONE_KB);
|
||||
for (i = 0; i < MEMALLOC_TYPE_COUNT; i++) {
|
||||
printf(data->reportAsBandwidth ? "\t%7.2lf" : "\t%7.3lf",
|
||||
printStdDevBandwidth
|
||||
? data->stdDevBandwidthInMBps[i][j]
|
||||
: getTimeOrBandwidth(
|
||||
printAverage ? data->averageRunTimesInMs[i][j]
|
||||
: data->stdDevRunTimesInMs[i][j],
|
||||
results->sizesToTest[j], data->reportAsBandwidth));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void printAllResultsInVerboseMode(struct testResults *results,
|
||||
struct resultsData *data) {
|
||||
unsigned int i, j, k;
|
||||
for (i = 0; i < MEMALLOC_TYPE_COUNT; i++) {
|
||||
printf("Verbose mode, printing all results for %s\n", memAllocTypeStr[i]);
|
||||
printf("Instance");
|
||||
for (j = 0; j < results->numSizesToTest; j++) {
|
||||
printf("\t%lu", results->sizesToTest[j] / ONE_KB);
|
||||
}
|
||||
printf("\n");
|
||||
for (k = 0; k < results->numMeasurements; k++) {
|
||||
printf("%u", k);
|
||||
for (j = 0; j < results->numSizesToTest; j++) {
|
||||
printf(data->reportAsBandwidth ? "\t%7.2lf" : "\t%7.3lf",
|
||||
getTimeOrBandwidth(data->runTimesInMs[i][j][k],
|
||||
results->sizesToTest[j],
|
||||
data->reportAsBandwidth));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void printResults(struct testResults *results,
|
||||
bool print_launch_transfer_results,
|
||||
bool print_std_deviation) {
|
||||
char vulcanPrint[256];
|
||||
char resultNameNoSpaces[64];
|
||||
unsigned int i, j, k;
|
||||
struct resultsData *resultsIter;
|
||||
bool sizeGreaterThan1MB;
|
||||
for (resultsIter = results->resultsDataHead; resultsIter != NULL;
|
||||
resultsIter = resultsIter->next) {
|
||||
if (!verboseResults && resultsIter->printOnlyInVerbose) {
|
||||
continue;
|
||||
}
|
||||
if (!print_launch_transfer_results) {
|
||||
if (!(strcmp(resultsIter->resultsName, "Overall Time") == 0)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// regular print
|
||||
printf("\n%s For %s ", resultsIter->resultsName, results->testName);
|
||||
printf("\n");
|
||||
for (j = 0; j < results->numSizesToTest; j++) {
|
||||
for (i = 0; i < MEMALLOC_TYPE_COUNT; i++) {
|
||||
calculateAverageAndStdDev(&resultsIter->averageRunTimesInMs[i][j],
|
||||
&resultsIter->stdDevRunTimesInMs[i][j],
|
||||
resultsIter->runTimesInMs[i][j],
|
||||
results->numMeasurements);
|
||||
if (resultsIter->reportAsBandwidth) {
|
||||
calculateStdDevBandwidth(&resultsIter->stdDevBandwidthInMBps[i][j],
|
||||
resultsIter->runTimesInMs[i][j],
|
||||
results->numMeasurements,
|
||||
results->sizesToTest[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\nPrinting Average of %u measurements in (%s)\n",
|
||||
results->numMeasurements,
|
||||
resultsIter->reportAsBandwidth ? UNITS_BW : UNITS_Time);
|
||||
printTimesInTableFormat(results, resultsIter, true, false);
|
||||
if (print_std_deviation) {
|
||||
printf(
|
||||
"\nPrinting Standard Deviation as %% of average of %u measurements\n",
|
||||
results->numMeasurements);
|
||||
printTimesInTableFormat(results, resultsIter, false, true);
|
||||
}
|
||||
if (verboseResults) {
|
||||
printAllResultsInVerboseMode(results, resultsIter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,697 +0,0 @@
|
||||
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <helper_cuda.h>
|
||||
#include <helper_timer.h>
|
||||
#include "commonDefs.hpp"
|
||||
#include "commonKernels.hpp"
|
||||
|
||||
#define VERIFY_GPU_CORRECTNESS 0
|
||||
|
||||
size_t maxSampleSizeInMb = 64;
|
||||
int numKernelRuns = 20;
|
||||
int verboseResults = 0;
|
||||
|
||||
const char *memAllocTypeStr[MEMALLOC_TYPE_COUNT] = {
|
||||
"Managed_Memory_With_Hints",
|
||||
"Managed_Memory_With_Hints_FullyAsync",
|
||||
"Managed_Memory_NoHints",
|
||||
"Zero_Copy",
|
||||
"Memcpy_HostMalloc_DeviceCudaMalloc",
|
||||
"MemcpyAsync_HostMalloc_DeviceCudaMalloc",
|
||||
"Memcpy_HostCudaHostAlloc_DeviceCudaMalloc",
|
||||
"MemcpyAsync_HostCudaHostAlloc_DeviceCudaMalloc"};
|
||||
|
||||
const char *memAllocTypeShortStr[MEMALLOC_TYPE_COUNT] = {
|
||||
"UMhint", // Managed Memory With Hints
|
||||
"UMhntAs", // Managed Memory With_Hints Async
|
||||
"UMeasy", // Managed_Memory with No Hints
|
||||
"0Copy", // Zero Copy
|
||||
"MemCopy", // USE HOST PAGEABLE AND DEVICE_MEMORY
|
||||
"CpAsync", // USE HOST PAGEABLE AND DEVICE_MEMORY ASYNC
|
||||
"CpHpglk", // USE HOST PAGELOCKED AND DEVICE MEMORY
|
||||
"CpPglAs" // USE HOST PAGELOCKED AND DEVICE MEMORY ASYNC
|
||||
};
|
||||
|
||||
static float RandFloat(float low, float high) {
|
||||
float t = (float)rand() / (float)RAND_MAX;
|
||||
return (1.0f - t) * low + t * high;
|
||||
}
|
||||
|
||||
void fillMatrixWithRandomValues(float *matrix, unsigned int matrixDim) {
|
||||
unsigned int i, j;
|
||||
for (i = 0; i < matrixDim; ++i) {
|
||||
for (j = 0; j < matrixDim; ++j) {
|
||||
matrix[j + i * matrixDim] = RandFloat(0.0f, 10.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if VERIFY_GPU_CORRECTNESS
|
||||
void verifyMatrixMultiplyCorrectness(float *C, float *A, float *B,
|
||||
unsigned int matrixDim) {
|
||||
unsigned int i, j, k, numErrors = 0;
|
||||
for (i = 0; i < matrixDim; ++i) {
|
||||
for (j = 0; j < matrixDim; ++j) {
|
||||
float result = 0.0f;
|
||||
for (k = 0; k < matrixDim; ++k) {
|
||||
result += A[k + i * matrixDim] * B[j + k * matrixDim];
|
||||
}
|
||||
if (fabs(C[j + i * matrixDim] - result) > 0.001 * matrixDim) {
|
||||
printf("At [%u, %u]: Expected %f, Found %f\n", i, j, result,
|
||||
C[j + i * matrixDim]);
|
||||
++numErrors;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (numErrors != 0) {
|
||||
printf("%d value mismatches occured\n", numErrors);
|
||||
fflush(stdout);
|
||||
exit(EXIT_FAILURE); // exit since value mismatches occured
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void copyMatrix(float *dstMatrix, float *srcMatrix, unsigned int matrixDim) {
|
||||
size_t size = matrixDim * matrixDim * sizeof(float);
|
||||
memcpy(dstMatrix, srcMatrix, size);
|
||||
}
|
||||
|
||||
void verifyMatrixData(float *expectedData, float *observedData,
|
||||
unsigned int matrixDim) {
|
||||
unsigned int i, j, numErrors = 0;
|
||||
for (i = 0; i < matrixDim; ++i) {
|
||||
for (j = 0; j < matrixDim; ++j) {
|
||||
if (expectedData[j + i * matrixDim] != observedData[j + i * matrixDim]) {
|
||||
++numErrors;
|
||||
if (verboseResults) {
|
||||
printf("At [%u, %u]: Expected %f, Found %f\n", i, j,
|
||||
expectedData[j + i * matrixDim],
|
||||
observedData[j + i * matrixDim]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (numErrors != 0) {
|
||||
printf("%d value mismatches occured\n", numErrors);
|
||||
fflush(stdout);
|
||||
exit(EXIT_FAILURE); // exit since value mismatches occured
|
||||
}
|
||||
}
|
||||
|
||||
#define BLOCK_SIZE 32
|
||||
__global__ void matrixMultiplyKernel(float *C, float *A, float *B,
|
||||
unsigned int matrixDim) {
|
||||
// Block index
|
||||
int bx = blockIdx.x;
|
||||
int by = blockIdx.y;
|
||||
|
||||
// Thread index
|
||||
int tx = threadIdx.x;
|
||||
int ty = threadIdx.y;
|
||||
|
||||
unsigned int wA = matrixDim;
|
||||
unsigned int wB = matrixDim;
|
||||
|
||||
// Index of the first sub-matrix of A processed by the block
|
||||
int aBegin = matrixDim * BLOCK_SIZE * by;
|
||||
|
||||
// Index of the last sub-matrix of A processed by the block
|
||||
int aEnd = aBegin + wA - 1;
|
||||
|
||||
// Step size used to iterate through the sub-matrices of A
|
||||
int aStep = BLOCK_SIZE;
|
||||
|
||||
// Index of the first sub-matrix of B processed by the block
|
||||
int bBegin = BLOCK_SIZE * bx;
|
||||
|
||||
// Step size used to iterate through the sub-matrices of B
|
||||
int bStep = BLOCK_SIZE * wB;
|
||||
|
||||
// Csub is used to store the element of the block sub-matrix
|
||||
// that is computed by the thread
|
||||
float Csub = 0;
|
||||
|
||||
// Loop over all the sub-matrices of A and B
|
||||
// required to compute the block sub-matrix
|
||||
for (int a = aBegin, b = bBegin; a <= aEnd; a += aStep, b += bStep) {
|
||||
// Declaration of the shared memory array As used to
|
||||
// store the sub-matrix of A
|
||||
__shared__ float As[BLOCK_SIZE][BLOCK_SIZE];
|
||||
|
||||
// Declaration of the shared memory array Bs used to
|
||||
// store the sub-matrix of B
|
||||
__shared__ float Bs[BLOCK_SIZE][BLOCK_SIZE];
|
||||
|
||||
// Load the matrices from device memory
|
||||
// to shared memory; each thread loads
|
||||
// one element of each matrix
|
||||
As[ty][tx] = A[a + wA * ty + tx];
|
||||
Bs[ty][tx] = B[b + wB * ty + tx];
|
||||
|
||||
// Synchronize to make sure the matrices are loaded
|
||||
__syncthreads();
|
||||
|
||||
// Multiply the two matrices together;
|
||||
// each thread computes one element
|
||||
// of the block sub-matrix
|
||||
#pragma unroll
|
||||
|
||||
for (int k = 0; k < BLOCK_SIZE; ++k) {
|
||||
Csub += As[ty][k] * Bs[k][tx];
|
||||
}
|
||||
|
||||
// Synchronize to make sure that the preceding
|
||||
// computation is done before loading two new
|
||||
// sub-matrices of A and B in the next iteration
|
||||
__syncthreads();
|
||||
}
|
||||
|
||||
// Write the block sub-matrix to device memory;
|
||||
// each thread writes one element
|
||||
int c = wB * BLOCK_SIZE * by + BLOCK_SIZE * bx;
|
||||
C[c + wB * ty + tx] = Csub;
|
||||
}
|
||||
|
||||
void runMatrixMultiplyKernel(unsigned int matrixDim, int allocType,
|
||||
unsigned int numLoops, double *gpuLaunchCallsTimes,
|
||||
double *gpuTransferToCallsTimes,
|
||||
double *gpuTransferFromCallsTimes,
|
||||
double *gpuLaunchAndTransferCallsTimes,
|
||||
double *gpuLaunchTransferSyncTimes,
|
||||
double *cpuAccessTimes, double *overallTimes,
|
||||
int device_id) {
|
||||
float *dptrA = NULL, *hptrA = NULL;
|
||||
float *dptrB = NULL, *hptrB = NULL;
|
||||
float *dptrC = NULL, *hptrC = NULL;
|
||||
float *randValuesX = NULL, *randValuesY = NULL;
|
||||
float *randValuesVerifyXmulY = NULL, *randValuesVerifyYmulX = NULL;
|
||||
bool copyRequired = false, hintsRequired = false;
|
||||
bool someTransferOpRequired;
|
||||
bool isAsync = false;
|
||||
cudaStream_t streamToRunOn;
|
||||
unsigned int *latch;
|
||||
size_t size = matrixDim * matrixDim * sizeof(float);
|
||||
dim3 threads(32, 32);
|
||||
dim3 grid(matrixDim / threads.x, matrixDim / threads.y);
|
||||
StopWatchInterface *gpuLaunchCallsTimer = 0, *gpuTransferCallsTimer = 0;
|
||||
StopWatchInterface *gpuSyncTimer = 0, *cpuAccessTimer = 0;
|
||||
sdkCreateTimer(&gpuLaunchCallsTimer);
|
||||
sdkCreateTimer(&gpuTransferCallsTimer);
|
||||
sdkCreateTimer(&gpuSyncTimer);
|
||||
sdkCreateTimer(&cpuAccessTimer);
|
||||
unsigned int i;
|
||||
|
||||
cudaDeviceProp deviceProp;
|
||||
checkCudaErrors(cudaGetDeviceProperties(&deviceProp, device_id));
|
||||
checkCudaErrors(cudaStreamCreate(&streamToRunOn));
|
||||
|
||||
randValuesX = (float *)malloc(size);
|
||||
if (!randValuesX) {
|
||||
exit(EXIT_FAILURE); // exit since memory allocation error
|
||||
}
|
||||
randValuesY = (float *)malloc(size);
|
||||
if (!randValuesY) {
|
||||
exit(EXIT_FAILURE); // exit since memory allocation error
|
||||
}
|
||||
randValuesVerifyXmulY = (float *)malloc(size);
|
||||
if (!randValuesVerifyXmulY) {
|
||||
exit(EXIT_FAILURE); // exit since memory allocation error
|
||||
}
|
||||
randValuesVerifyYmulX = (float *)malloc(size);
|
||||
if (!randValuesVerifyYmulX) {
|
||||
exit(EXIT_FAILURE); // exit since memory allocation error
|
||||
}
|
||||
checkCudaErrors(cudaMalloc(&dptrA, size));
|
||||
checkCudaErrors(cudaMalloc(&dptrB, size));
|
||||
checkCudaErrors(cudaMalloc(&dptrC, size));
|
||||
|
||||
fillMatrixWithRandomValues(randValuesX, matrixDim);
|
||||
fillMatrixWithRandomValues(randValuesY, matrixDim);
|
||||
|
||||
checkCudaErrors(
|
||||
cudaMemcpyAsync(dptrA, randValuesX, size, cudaMemcpyHostToDevice));
|
||||
checkCudaErrors(
|
||||
cudaMemcpyAsync(dptrB, randValuesY, size, cudaMemcpyHostToDevice));
|
||||
matrixMultiplyKernel<<<grid, threads>>>(dptrC, dptrA, dptrB, matrixDim);
|
||||
checkCudaErrors(cudaMemcpyAsync(randValuesVerifyXmulY, dptrC, size,
|
||||
cudaMemcpyDeviceToHost));
|
||||
checkCudaErrors(cudaStreamSynchronize(NULL));
|
||||
matrixMultiplyKernel<<<grid, threads>>>(dptrC, dptrB, dptrA, matrixDim);
|
||||
checkCudaErrors(cudaMemcpyAsync(randValuesVerifyYmulX, dptrC, size,
|
||||
cudaMemcpyDeviceToHost));
|
||||
checkCudaErrors(cudaStreamSynchronize(NULL));
|
||||
#if VERIFY_GPU_CORRECTNESS
|
||||
verifyMatrixMultiplyCorrectness(randValuesVerifyXmulY, randValuesX,
|
||||
randValuesY, matrixDim);
|
||||
verifyMatrixMultiplyCorrectness(randValuesVerifyYmulX, randValuesY,
|
||||
randValuesX, matrixDim);
|
||||
#endif
|
||||
checkCudaErrors(cudaFree(dptrA));
|
||||
checkCudaErrors(cudaFree(dptrB));
|
||||
checkCudaErrors(cudaFree(dptrC));
|
||||
|
||||
checkCudaErrors(cudaMallocHost(&latch, sizeof(unsigned int)));
|
||||
|
||||
switch (allocType) {
|
||||
case USE_HOST_PAGEABLE_AND_DEVICE_MEMORY:
|
||||
case USE_HOST_PAGEABLE_AND_DEVICE_MEMORY_ASYNC:
|
||||
hptrA = (float *)malloc(size);
|
||||
if (!hptrA) {
|
||||
exit(EXIT_FAILURE); // exit since memory allocation error
|
||||
}
|
||||
hptrB = (float *)malloc(size);
|
||||
if (!hptrB) {
|
||||
exit(EXIT_FAILURE); // exit since memory allocation error
|
||||
}
|
||||
hptrC = (float *)malloc(size);
|
||||
if (!hptrC) {
|
||||
exit(EXIT_FAILURE); // exit since memory allocation error
|
||||
}
|
||||
checkCudaErrors(cudaMalloc(&dptrA, size));
|
||||
checkCudaErrors(cudaMalloc(&dptrB, size));
|
||||
checkCudaErrors(cudaMalloc(&dptrC, size));
|
||||
copyRequired = true;
|
||||
break;
|
||||
|
||||
case USE_HOST_PAGELOCKED_AND_DEVICE_MEMORY:
|
||||
case USE_HOST_PAGELOCKED_AND_DEVICE_MEMORY_ASYNC:
|
||||
checkCudaErrors(cudaMallocHost(&hptrA, size));
|
||||
checkCudaErrors(cudaMallocHost(&hptrB, size));
|
||||
checkCudaErrors(cudaMallocHost(&hptrC, size));
|
||||
checkCudaErrors(cudaMalloc(&dptrA, size));
|
||||
checkCudaErrors(cudaMalloc(&dptrB, size));
|
||||
checkCudaErrors(cudaMalloc(&dptrC, size));
|
||||
copyRequired = true;
|
||||
break;
|
||||
|
||||
case USE_ZERO_COPY:
|
||||
checkCudaErrors(cudaMallocHost(&hptrA, size));
|
||||
checkCudaErrors(cudaMallocHost(&hptrB, size));
|
||||
checkCudaErrors(cudaMallocHost(&hptrC, size));
|
||||
checkCudaErrors(cudaHostGetDevicePointer(&dptrA, hptrA, 0));
|
||||
checkCudaErrors(cudaHostGetDevicePointer(&dptrB, hptrB, 0));
|
||||
checkCudaErrors(cudaHostGetDevicePointer(&dptrC, hptrC, 0));
|
||||
break;
|
||||
|
||||
case USE_MANAGED_MEMORY:
|
||||
checkCudaErrors(cudaMallocManaged(&dptrA, size));
|
||||
checkCudaErrors(cudaMallocManaged(&dptrB, size));
|
||||
checkCudaErrors(cudaMallocManaged(&dptrC, size));
|
||||
hptrA = dptrA;
|
||||
hptrB = dptrB;
|
||||
hptrC = dptrC;
|
||||
break;
|
||||
|
||||
case USE_MANAGED_MEMORY_WITH_HINTS:
|
||||
case USE_MANAGED_MEMORY_WITH_HINTS_ASYNC:
|
||||
if (deviceProp.concurrentManagedAccess) {
|
||||
checkCudaErrors(cudaMallocManaged(&dptrA, size));
|
||||
checkCudaErrors(cudaMallocManaged(&dptrB, size));
|
||||
checkCudaErrors(cudaMallocManaged(&dptrC, size));
|
||||
checkCudaErrors(cudaMemPrefetchAsync(dptrA, size, cudaCpuDeviceId));
|
||||
checkCudaErrors(cudaMemPrefetchAsync(dptrB, size, cudaCpuDeviceId));
|
||||
checkCudaErrors(cudaMemPrefetchAsync(dptrC, size, cudaCpuDeviceId));
|
||||
} else {
|
||||
checkCudaErrors(cudaMallocManaged(&dptrA, size, cudaMemAttachHost));
|
||||
checkCudaErrors(cudaMallocManaged(&dptrB, size, cudaMemAttachHost));
|
||||
checkCudaErrors(cudaMallocManaged(&dptrC, size, cudaMemAttachHost));
|
||||
}
|
||||
hptrA = dptrA;
|
||||
hptrB = dptrB;
|
||||
hptrC = dptrC;
|
||||
hintsRequired = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
exit(EXIT_FAILURE); // exit with error
|
||||
}
|
||||
|
||||
if (allocType == USE_HOST_PAGEABLE_AND_DEVICE_MEMORY_ASYNC ||
|
||||
allocType == USE_HOST_PAGELOCKED_AND_DEVICE_MEMORY_ASYNC ||
|
||||
allocType == USE_MANAGED_MEMORY_WITH_HINTS_ASYNC) {
|
||||
isAsync = true;
|
||||
}
|
||||
|
||||
someTransferOpRequired = copyRequired || hintsRequired;
|
||||
|
||||
// fill buffers with 0 to avoid any first access page-fault overheads.
|
||||
memset(hptrA, 0, size);
|
||||
memset(hptrB, 0, size);
|
||||
memset(hptrC, 0, size);
|
||||
|
||||
for (i = 0; i < numLoops; i++) {
|
||||
cpuAccessTimes[i] = 0.0;
|
||||
gpuLaunchCallsTimes[i] = 0.0;
|
||||
gpuTransferToCallsTimes[i] = 0.0;
|
||||
gpuTransferFromCallsTimes[i] = 0.0;
|
||||
|
||||
sdkStartTimer(&cpuAccessTimer);
|
||||
{
|
||||
copyMatrix(hptrA, (i & 0x1 == 0) ? randValuesX : randValuesY, matrixDim);
|
||||
copyMatrix(hptrB, (i & 0x1 == 0) ? randValuesY : randValuesX, matrixDim);
|
||||
}
|
||||
sdkStopTimer(&cpuAccessTimer);
|
||||
cpuAccessTimes[i] += sdkGetAverageTimerValue(&cpuAccessTimer);
|
||||
sdkResetTimer(&cpuAccessTimer);
|
||||
|
||||
if (isAsync && hintsRequired) {
|
||||
*latch = 0;
|
||||
// Prevent any work on stream from starting until all work is pushed
|
||||
spinWhileLessThanOne<<<1, 1, 0, streamToRunOn>>>(latch);
|
||||
}
|
||||
|
||||
if (someTransferOpRequired) {
|
||||
sdkStartTimer(&gpuTransferCallsTimer);
|
||||
if (copyRequired) {
|
||||
if (isAsync) {
|
||||
checkCudaErrors(cudaMemcpyAsync(
|
||||
dptrA, hptrA, size, cudaMemcpyHostToDevice, streamToRunOn));
|
||||
checkCudaErrors(cudaMemcpyAsync(
|
||||
dptrB, hptrB, size, cudaMemcpyHostToDevice, streamToRunOn));
|
||||
} else {
|
||||
checkCudaErrors(
|
||||
cudaMemcpy(dptrA, hptrA, size, cudaMemcpyHostToDevice));
|
||||
checkCudaErrors(
|
||||
cudaMemcpy(dptrB, hptrB, size, cudaMemcpyHostToDevice));
|
||||
}
|
||||
}
|
||||
if (hintsRequired) {
|
||||
if (deviceProp.concurrentManagedAccess) {
|
||||
checkCudaErrors(
|
||||
cudaMemPrefetchAsync(dptrA, size, device_id, streamToRunOn));
|
||||
checkCudaErrors(
|
||||
cudaMemPrefetchAsync(dptrB, size, device_id, streamToRunOn));
|
||||
checkCudaErrors(
|
||||
cudaMemPrefetchAsync(dptrC, size, device_id, streamToRunOn));
|
||||
} else {
|
||||
checkCudaErrors(cudaStreamAttachMemAsync(streamToRunOn, dptrA, 0,
|
||||
cudaMemAttachGlobal));
|
||||
checkCudaErrors(cudaStreamAttachMemAsync(streamToRunOn, dptrB, 0,
|
||||
cudaMemAttachGlobal));
|
||||
checkCudaErrors(cudaStreamAttachMemAsync(streamToRunOn, dptrC, 0,
|
||||
cudaMemAttachGlobal));
|
||||
}
|
||||
if (!isAsync) {
|
||||
checkCudaErrors(cudaStreamSynchronize(streamToRunOn));
|
||||
}
|
||||
}
|
||||
|
||||
sdkStopTimer(&gpuTransferCallsTimer);
|
||||
gpuTransferToCallsTimes[i] +=
|
||||
sdkGetAverageTimerValue(&gpuTransferCallsTimer);
|
||||
sdkResetTimer(&gpuTransferCallsTimer);
|
||||
}
|
||||
|
||||
sdkStartTimer(&gpuLaunchCallsTimer);
|
||||
{
|
||||
matrixMultiplyKernel<<<grid, threads, 0, streamToRunOn>>>(
|
||||
dptrC, dptrA, dptrB, matrixDim);
|
||||
if (!isAsync) {
|
||||
checkCudaErrors(cudaStreamSynchronize(streamToRunOn));
|
||||
}
|
||||
}
|
||||
sdkStopTimer(&gpuLaunchCallsTimer);
|
||||
|
||||
gpuLaunchCallsTimes[i] += sdkGetAverageTimerValue(&gpuLaunchCallsTimer);
|
||||
sdkResetTimer(&gpuLaunchCallsTimer);
|
||||
|
||||
if (someTransferOpRequired) {
|
||||
sdkStartTimer(&gpuTransferCallsTimer);
|
||||
if (hintsRequired) {
|
||||
if (deviceProp.concurrentManagedAccess) {
|
||||
checkCudaErrors(cudaMemPrefetchAsync(dptrA, size, cudaCpuDeviceId));
|
||||
checkCudaErrors(cudaMemPrefetchAsync(dptrB, size, cudaCpuDeviceId));
|
||||
checkCudaErrors(cudaMemPrefetchAsync(dptrC, size, cudaCpuDeviceId));
|
||||
} else {
|
||||
checkCudaErrors(cudaStreamAttachMemAsync(streamToRunOn, dptrA, 0,
|
||||
cudaMemAttachHost));
|
||||
checkCudaErrors(cudaStreamAttachMemAsync(streamToRunOn, dptrB, 0,
|
||||
cudaMemAttachHost));
|
||||
checkCudaErrors(cudaStreamAttachMemAsync(streamToRunOn, dptrC, 0,
|
||||
cudaMemAttachHost));
|
||||
}
|
||||
if (!isAsync) {
|
||||
checkCudaErrors(cudaStreamSynchronize(streamToRunOn));
|
||||
}
|
||||
}
|
||||
if (copyRequired) {
|
||||
if (isAsync) {
|
||||
checkCudaErrors(cudaMemcpyAsync(
|
||||
hptrC, dptrC, size, cudaMemcpyDeviceToHost, streamToRunOn));
|
||||
} else {
|
||||
checkCudaErrors(
|
||||
cudaMemcpy(hptrC, dptrC, size, cudaMemcpyDeviceToHost));
|
||||
}
|
||||
}
|
||||
sdkStopTimer(&gpuTransferCallsTimer);
|
||||
gpuTransferFromCallsTimes[i] +=
|
||||
sdkGetAverageTimerValue(&gpuTransferCallsTimer);
|
||||
sdkResetTimer(&gpuTransferCallsTimer);
|
||||
}
|
||||
gpuLaunchAndTransferCallsTimes[i] = gpuLaunchCallsTimes[i] +
|
||||
gpuTransferToCallsTimes[i] +
|
||||
gpuTransferFromCallsTimes[i];
|
||||
gpuLaunchTransferSyncTimes[i] = gpuLaunchAndTransferCallsTimes[i];
|
||||
if (isAsync) {
|
||||
sdkStartTimer(&gpuSyncTimer);
|
||||
{
|
||||
if (hintsRequired) {
|
||||
*latch = 1;
|
||||
}
|
||||
checkCudaErrors(cudaStreamSynchronize(streamToRunOn));
|
||||
}
|
||||
sdkStopTimer(&gpuSyncTimer);
|
||||
gpuLaunchTransferSyncTimes[i] += sdkGetAverageTimerValue(&gpuSyncTimer);
|
||||
sdkResetTimer(&gpuSyncTimer);
|
||||
}
|
||||
|
||||
sdkStartTimer(&cpuAccessTimer);
|
||||
{
|
||||
verifyMatrixData(
|
||||
(i & 0x1 == 0) ? randValuesVerifyXmulY : randValuesVerifyYmulX, hptrC,
|
||||
matrixDim);
|
||||
}
|
||||
sdkStopTimer(&cpuAccessTimer);
|
||||
cpuAccessTimes[i] += sdkGetAverageTimerValue(&cpuAccessTimer);
|
||||
sdkResetTimer(&cpuAccessTimer);
|
||||
overallTimes[i] = cpuAccessTimes[i] + gpuLaunchTransferSyncTimes[i];
|
||||
}
|
||||
|
||||
switch (allocType) {
|
||||
case USE_HOST_PAGEABLE_AND_DEVICE_MEMORY:
|
||||
case USE_HOST_PAGEABLE_AND_DEVICE_MEMORY_ASYNC:
|
||||
free(hptrA);
|
||||
free(hptrB);
|
||||
free(hptrC);
|
||||
checkCudaErrors(cudaFree(dptrA));
|
||||
checkCudaErrors(cudaFree(dptrB));
|
||||
checkCudaErrors(cudaFree(dptrC));
|
||||
break;
|
||||
|
||||
case USE_HOST_PAGELOCKED_AND_DEVICE_MEMORY:
|
||||
case USE_HOST_PAGELOCKED_AND_DEVICE_MEMORY_ASYNC:
|
||||
checkCudaErrors(cudaFreeHost(hptrA));
|
||||
checkCudaErrors(cudaFreeHost(hptrB));
|
||||
checkCudaErrors(cudaFreeHost(hptrC));
|
||||
checkCudaErrors(cudaFree(dptrA));
|
||||
checkCudaErrors(cudaFree(dptrB));
|
||||
checkCudaErrors(cudaFree(dptrC));
|
||||
break;
|
||||
|
||||
case USE_ZERO_COPY:
|
||||
checkCudaErrors(cudaFreeHost(hptrA));
|
||||
checkCudaErrors(cudaFreeHost(hptrB));
|
||||
checkCudaErrors(cudaFreeHost(hptrC));
|
||||
break;
|
||||
|
||||
case USE_MANAGED_MEMORY:
|
||||
case USE_MANAGED_MEMORY_WITH_HINTS:
|
||||
case USE_MANAGED_MEMORY_WITH_HINTS_ASYNC:
|
||||
checkCudaErrors(cudaFree(dptrA));
|
||||
checkCudaErrors(cudaFree(dptrB));
|
||||
checkCudaErrors(cudaFree(dptrC));
|
||||
break;
|
||||
|
||||
default:
|
||||
exit(EXIT_FAILURE); // exit due to error
|
||||
}
|
||||
|
||||
checkCudaErrors(cudaStreamDestroy(streamToRunOn));
|
||||
checkCudaErrors(cudaFreeHost(latch));
|
||||
free(randValuesX);
|
||||
free(randValuesY);
|
||||
free(randValuesVerifyXmulY);
|
||||
free(randValuesVerifyYmulX);
|
||||
sdkDeleteTimer(&gpuLaunchCallsTimer);
|
||||
sdkDeleteTimer(&gpuTransferCallsTimer);
|
||||
sdkDeleteTimer(&gpuSyncTimer);
|
||||
sdkDeleteTimer(&cpuAccessTimer);
|
||||
}
|
||||
|
||||
void matrixMultiplyPerfRunner(bool reportAsBandwidth,
|
||||
bool print_launch_transfer_results,
|
||||
bool print_std_deviation, int device_id) {
|
||||
int i;
|
||||
unsigned int minMatrixDim = 32;
|
||||
unsigned int multiplierDim = 2;
|
||||
unsigned int matrixDim;
|
||||
unsigned int minSize = minMatrixDim * minMatrixDim * sizeof(float);
|
||||
unsigned int maxSize =
|
||||
(maxSampleSizeInMb * ONE_MB) /
|
||||
4; // 3 buffers are used, but dividing by 4 (power of 2)
|
||||
unsigned int multiplier = multiplierDim * multiplierDim;
|
||||
unsigned int numSizesToTest;
|
||||
|
||||
struct testResults *results;
|
||||
struct resultsData *gpuLaunchCallsTimes;
|
||||
struct resultsData *gpuTransferToCallsTimes;
|
||||
struct resultsData *gpuTransferFromCallsTimes;
|
||||
struct resultsData *gpuLaunchAndTransferCallsTimes;
|
||||
struct resultsData *gpuLaunchTransferSyncTimes;
|
||||
struct resultsData *cpuAccessTimes;
|
||||
struct resultsData *overallTimes;
|
||||
unsigned long *sizesToTest;
|
||||
unsigned int j;
|
||||
|
||||
numSizesToTest = findNumSizesToTest(minSize, maxSize, multiplier);
|
||||
|
||||
createAndInitTestResults(&results, "matrixMultiplyPerf", numKernelRuns,
|
||||
numSizesToTest);
|
||||
|
||||
sizesToTest = getPtrSizesToTest(results);
|
||||
|
||||
createResultDataAndAddToTestResults(&gpuLaunchCallsTimes, results,
|
||||
"GPU Kernel Launch Call Time", false,
|
||||
reportAsBandwidth);
|
||||
createResultDataAndAddToTestResults(&gpuTransferToCallsTimes, results,
|
||||
"CPU to GPU Transfer Calls Time", false,
|
||||
reportAsBandwidth);
|
||||
createResultDataAndAddToTestResults(&gpuTransferFromCallsTimes, results,
|
||||
"GPU to CPU Transfer Calls Time", false,
|
||||
reportAsBandwidth);
|
||||
createResultDataAndAddToTestResults(&gpuLaunchAndTransferCallsTimes, results,
|
||||
"GPU Launch and Transfer Calls Time",
|
||||
false, reportAsBandwidth);
|
||||
createResultDataAndAddToTestResults(&gpuLaunchTransferSyncTimes, results,
|
||||
"GPU Launch Transfer and Sync Time",
|
||||
false, reportAsBandwidth);
|
||||
createResultDataAndAddToTestResults(
|
||||
&cpuAccessTimes, results, "CPU Access Time", false, reportAsBandwidth);
|
||||
createResultDataAndAddToTestResults(&overallTimes, results, "Overall Time",
|
||||
false, reportAsBandwidth);
|
||||
|
||||
printf("Running ");
|
||||
for (matrixDim = minMatrixDim, j = 0;
|
||||
matrixDim * matrixDim <= maxSize / sizeof(float);
|
||||
matrixDim *= multiplierDim, ++j) {
|
||||
sizesToTest[j] = matrixDim * matrixDim * sizeof(float);
|
||||
for (i = MEMALLOC_TYPE_START; i <= MEMALLOC_TYPE_END; i++) {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
runMatrixMultiplyKernel(
|
||||
matrixDim, i, numKernelRuns,
|
||||
getPtrRunTimesInMs(gpuLaunchCallsTimes, i, j),
|
||||
getPtrRunTimesInMs(gpuTransferToCallsTimes, i, j),
|
||||
getPtrRunTimesInMs(gpuTransferFromCallsTimes, i, j),
|
||||
getPtrRunTimesInMs(gpuLaunchAndTransferCallsTimes, i, j),
|
||||
getPtrRunTimesInMs(gpuLaunchTransferSyncTimes, i, j),
|
||||
getPtrRunTimesInMs(cpuAccessTimes, i, j),
|
||||
getPtrRunTimesInMs(overallTimes, i, j), device_id);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
printResults(results, print_launch_transfer_results, print_std_deviation);
|
||||
freeTestResultsAndAllResultsData(results);
|
||||
}
|
||||
|
||||
static void usage() {
|
||||
printf(
|
||||
"./cudaMemoryTypesPerf [-device=<device_id>] [-reportAsBandwidth] "
|
||||
"[-print-launch-transfer-results] [-print-std-deviation] [-verbose]\n");
|
||||
printf("Options:\n");
|
||||
printf(
|
||||
"-reportAsBandwidth: By default time taken is printed, this "
|
||||
"option allows to instead print bandwidth.\n");
|
||||
printf(
|
||||
"-print-launch-transfer-results: By default overall results are printed, "
|
||||
"this option allows to print data transfers and kernel time as well.\n");
|
||||
printf(
|
||||
"-print-std-deviation: Prints std deviation of the results.\n");
|
||||
printf(
|
||||
"-kernel-iterations=<num>: Number of times the kernel tests should "
|
||||
"be run[default is 100 iterations].\n");
|
||||
printf(
|
||||
"-device=<device_id>: Allows to pass GPU Device ID on which "
|
||||
"the tests will be run.\n");
|
||||
printf("-verbose: Prints highly verbose output.\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
bool reportAsBandwidth = false;
|
||||
bool print_launch_transfer_results = false;
|
||||
bool print_std_deviation = false;
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "help") ||
|
||||
checkCmdLineFlag(argc, (const char **)argv, "h")) {
|
||||
usage();
|
||||
printf("&&&& %s WAIVED\n", argv[0]);
|
||||
exit(EXIT_WAIVED);
|
||||
}
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "reportAsBandwidth")) {
|
||||
reportAsBandwidth = true;
|
||||
}
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv,
|
||||
"print-launch-transfer-results")) {
|
||||
print_launch_transfer_results = true;
|
||||
}
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "print-std-deviation")) {
|
||||
print_std_deviation = true;
|
||||
}
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "kernel-iterations")) {
|
||||
numKernelRuns =
|
||||
getCmdLineArgumentInt(argc, (const char **)argv, "kernel-iterations");
|
||||
}
|
||||
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "verbose")) {
|
||||
verboseResults = 1;
|
||||
}
|
||||
|
||||
int device_id = findCudaDevice(argc, (const char **)argv);
|
||||
|
||||
matrixMultiplyPerfRunner(reportAsBandwidth, print_launch_transfer_results,
|
||||
print_std_deviation, device_id);
|
||||
|
||||
printf(
|
||||
"\nNOTE: The CUDA Samples are not meant for performance measurements. "
|
||||
"Results may vary when GPU Boost is enabled.\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
@@ -1,337 +0,0 @@
|
||||
################################################################################
|
||||
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# Makefile project only supported on Mac OS X and Linux Platforms)
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# Location of the CUDA Toolkit
|
||||
CUDA_PATH ?= /usr/local/cuda
|
||||
|
||||
##############################
|
||||
# start deprecated interface #
|
||||
##############################
|
||||
ifeq ($(x86_64),1)
|
||||
$(info WARNING - x86_64 variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=x86_64 instead)
|
||||
TARGET_ARCH ?= x86_64
|
||||
endif
|
||||
ifeq ($(ARMv7),1)
|
||||
$(info WARNING - ARMv7 variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=armv7l instead)
|
||||
TARGET_ARCH ?= armv7l
|
||||
endif
|
||||
ifeq ($(aarch64),1)
|
||||
$(info WARNING - aarch64 variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=aarch64 instead)
|
||||
TARGET_ARCH ?= aarch64
|
||||
endif
|
||||
ifeq ($(ppc64le),1)
|
||||
$(info WARNING - ppc64le variable has been deprecated)
|
||||
$(info WARNING - please use TARGET_ARCH=ppc64le instead)
|
||||
TARGET_ARCH ?= ppc64le
|
||||
endif
|
||||
ifneq ($(GCC),)
|
||||
$(info WARNING - GCC variable has been deprecated)
|
||||
$(info WARNING - please use HOST_COMPILER=$(GCC) instead)
|
||||
HOST_COMPILER ?= $(GCC)
|
||||
endif
|
||||
ifneq ($(abi),)
|
||||
$(error ERROR - abi variable has been removed)
|
||||
endif
|
||||
############################
|
||||
# end deprecated interface #
|
||||
############################
|
||||
|
||||
# architecture
|
||||
HOST_ARCH := $(shell uname -m)
|
||||
TARGET_ARCH ?= $(HOST_ARCH)
|
||||
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le armv7l))
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le))
|
||||
TARGET_SIZE := 64
|
||||
else ifneq (,$(filter $(TARGET_ARCH),armv7l))
|
||||
TARGET_SIZE := 32
|
||||
endif
|
||||
else
|
||||
TARGET_SIZE := $(shell getconf LONG_BIT)
|
||||
endif
|
||||
else
|
||||
$(error ERROR - unsupported value $(TARGET_ARCH) for TARGET_ARCH!)
|
||||
endif
|
||||
|
||||
# sbsa and aarch64 systems look similar. Need to differentiate them at host level for now.
|
||||
ifeq ($(HOST_ARCH),aarch64)
|
||||
ifeq ($(CUDA_PATH)/targets/sbsa-linux,$(shell ls -1d $(CUDA_PATH)/targets/sbsa-linux 2>/dev/null))
|
||||
HOST_ARCH := sbsa
|
||||
TARGET_ARCH := sbsa
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq (,$(filter $(HOST_ARCH)-$(TARGET_ARCH),aarch64-armv7l x86_64-armv7l x86_64-aarch64 x86_64-sbsa x86_64-ppc64le))
|
||||
$(error ERROR - cross compiling from $(HOST_ARCH) to $(TARGET_ARCH) is not supported!)
|
||||
endif
|
||||
endif
|
||||
|
||||
# When on native aarch64 system with userspace of 32-bit, change TARGET_ARCH to armv7l
|
||||
ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_SIZE),aarch64-aarch64-32)
|
||||
TARGET_ARCH = armv7l
|
||||
endif
|
||||
|
||||
# operating system
|
||||
HOST_OS := $(shell uname -s 2>/dev/null | tr "[:upper:]" "[:lower:]")
|
||||
TARGET_OS ?= $(HOST_OS)
|
||||
ifeq (,$(filter $(TARGET_OS),linux darwin qnx android))
|
||||
$(error ERROR - unsupported value $(TARGET_OS) for TARGET_OS!)
|
||||
endif
|
||||
|
||||
# host compiler
|
||||
ifeq ($(TARGET_OS),darwin)
|
||||
ifeq ($(shell expr `xcodebuild -version | grep -i xcode | awk '{print $$2}' | cut -d'.' -f1` \>= 5),1)
|
||||
HOST_COMPILER ?= clang++
|
||||
endif
|
||||
else ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq ($(HOST_ARCH)-$(TARGET_ARCH),x86_64-armv7l)
|
||||
ifeq ($(TARGET_OS),linux)
|
||||
HOST_COMPILER ?= arm-linux-gnueabihf-g++
|
||||
else ifeq ($(TARGET_OS),qnx)
|
||||
ifeq ($(QNX_HOST),)
|
||||
$(error ERROR - QNX_HOST must be passed to the QNX host toolchain)
|
||||
endif
|
||||
ifeq ($(QNX_TARGET),)
|
||||
$(error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
|
||||
endif
|
||||
export QNX_HOST
|
||||
export QNX_TARGET
|
||||
HOST_COMPILER ?= $(QNX_HOST)/usr/bin/arm-unknown-nto-qnx6.6.0eabi-g++
|
||||
else ifeq ($(TARGET_OS),android)
|
||||
HOST_COMPILER ?= arm-linux-androideabi-g++
|
||||
endif
|
||||
else ifeq ($(TARGET_ARCH),aarch64)
|
||||
ifeq ($(TARGET_OS), linux)
|
||||
HOST_COMPILER ?= aarch64-linux-gnu-g++
|
||||
else ifeq ($(TARGET_OS),qnx)
|
||||
ifeq ($(QNX_HOST),)
|
||||
$(error ERROR - QNX_HOST must be passed to the QNX host toolchain)
|
||||
endif
|
||||
ifeq ($(QNX_TARGET),)
|
||||
$(error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
|
||||
endif
|
||||
export QNX_HOST
|
||||
export QNX_TARGET
|
||||
HOST_COMPILER ?= $(QNX_HOST)/usr/bin/q++
|
||||
else ifeq ($(TARGET_OS), android)
|
||||
HOST_COMPILER ?= aarch64-linux-android-clang++
|
||||
endif
|
||||
else ifeq ($(TARGET_ARCH),sbsa)
|
||||
HOST_COMPILER ?= aarch64-linux-gnu-g++
|
||||
else ifeq ($(TARGET_ARCH),ppc64le)
|
||||
HOST_COMPILER ?= powerpc64le-linux-gnu-g++
|
||||
endif
|
||||
endif
|
||||
HOST_COMPILER ?= g++
|
||||
NVCC := $(CUDA_PATH)/bin/nvcc -ccbin $(HOST_COMPILER)
|
||||
|
||||
# internal flags
|
||||
NVCCFLAGS := -m${TARGET_SIZE}
|
||||
CCFLAGS :=
|
||||
LDFLAGS :=
|
||||
|
||||
# build flags
|
||||
ifeq ($(TARGET_OS),darwin)
|
||||
LDFLAGS += -rpath $(CUDA_PATH)/lib
|
||||
CCFLAGS += -arch $(HOST_ARCH)
|
||||
else ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_OS),x86_64-armv7l-linux)
|
||||
LDFLAGS += --dynamic-linker=/lib/ld-linux-armhf.so.3
|
||||
CCFLAGS += -mfloat-abi=hard
|
||||
else ifeq ($(TARGET_OS),android)
|
||||
LDFLAGS += -pie
|
||||
CCFLAGS += -fpie -fpic -fexceptions
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
|
||||
ifneq ($(TARGET_FS),)
|
||||
GCCVERSIONLTEQ46 := $(shell expr `$(HOST_COMPILER) -dumpversion` \<= 4.6)
|
||||
ifeq ($(GCCVERSIONLTEQ46),1)
|
||||
CCFLAGS += --sysroot=$(TARGET_FS)
|
||||
endif
|
||||
LDFLAGS += --sysroot=$(TARGET_FS)
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/arm-linux-gnueabihf
|
||||
endif
|
||||
endif
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
|
||||
ifneq ($(TARGET_FS),)
|
||||
GCCVERSIONLTEQ46 := $(shell expr `$(HOST_COMPILER) -dumpversion` \<= 4.6)
|
||||
ifeq ($(GCCVERSIONLTEQ46),1)
|
||||
CCFLAGS += --sysroot=$(TARGET_FS)
|
||||
endif
|
||||
LDFLAGS += --sysroot=$(TARGET_FS)
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib -L$(TARGET_FS)/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/lib/aarch64-linux-gnu -L$(TARGET_FS)/lib/aarch64-linux-gnu
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib -L$(TARGET_FS)/usr/lib
|
||||
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/aarch64-linux-gnu -L$(TARGET_FS)/usr/lib/aarch64-linux-gnu
|
||||
LDFLAGS += --unresolved-symbols=ignore-in-shared-libs
|
||||
CCFLAGS += -isystem=$(TARGET_FS)/usr/include -I$(TARGET_FS)/usr/include -I$(TARGET_FS)/usr/include/libdrm
|
||||
CCFLAGS += -isystem=$(TARGET_FS)/usr/include/aarch64-linux-gnu -I$(TARGET_FS)/usr/include/aarch64-linux-gnu
|
||||
endif
|
||||
endif
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
|
||||
NVCCFLAGS += --qpp-config 5.4.0,gcc_ntoaarch64le
|
||||
CCFLAGS += -DWIN_INTERFACE_CUSTOM -I/usr/include/aarch64-qnx-gnu
|
||||
LDFLAGS += -lsocket
|
||||
LDFLAGS += -L/usr/lib/aarch64-qnx-gnu
|
||||
CCFLAGS += "-Wl\,-rpath-link\,/usr/lib/aarch64-qnx-gnu"
|
||||
ifdef TARGET_OVERRIDE
|
||||
LDFLAGS += -lslog2
|
||||
endif
|
||||
|
||||
ifneq ($(TARGET_FS),)
|
||||
LDFLAGS += -L$(TARGET_FS)/usr/lib
|
||||
CCFLAGS += "-Wl\,-rpath-link\,$(TARGET_FS)/usr/lib"
|
||||
LDFLAGS += -L$(TARGET_FS)/usr/libnvidia
|
||||
CCFLAGS += "-Wl\,-rpath-link\,$(TARGET_FS)/usr/libnvidia"
|
||||
CCFLAGS += -I$(TARGET_FS)/../include
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef TARGET_OVERRIDE # cuda toolkit targets override
|
||||
NVCCFLAGS += -target-dir $(TARGET_OVERRIDE)
|
||||
endif
|
||||
|
||||
# Install directory of different arch
|
||||
CUDA_INSTALL_TARGET_DIR :=
|
||||
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-gnueabihf/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),sbsa-linux)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/sbsa-linux/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-android)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-androideabi/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-android)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux-androideabi/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-qnx)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/ARMv7-linux-QNX/
|
||||
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/aarch64-qnx/
|
||||
else ifeq ($(TARGET_ARCH),ppc64le)
|
||||
CUDA_INSTALL_TARGET_DIR = targets/ppc64le-linux/
|
||||
endif
|
||||
|
||||
# Debug build flags
|
||||
ifeq ($(dbg),1)
|
||||
NVCCFLAGS += -g -G
|
||||
BUILD_TYPE := debug
|
||||
else
|
||||
BUILD_TYPE := release
|
||||
endif
|
||||
|
||||
ALL_CCFLAGS :=
|
||||
ALL_CCFLAGS += $(NVCCFLAGS)
|
||||
ALL_CCFLAGS += $(EXTRA_NVCCFLAGS)
|
||||
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(CCFLAGS))
|
||||
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(EXTRA_CCFLAGS))
|
||||
|
||||
SAMPLE_ENABLED := 1
|
||||
|
||||
ALL_LDFLAGS :=
|
||||
ALL_LDFLAGS += $(ALL_CCFLAGS)
|
||||
ALL_LDFLAGS += $(addprefix -Xlinker ,$(LDFLAGS))
|
||||
ALL_LDFLAGS += $(addprefix -Xlinker ,$(EXTRA_LDFLAGS))
|
||||
|
||||
# Common includes and paths for CUDA
|
||||
INCLUDES := -I../../Common
|
||||
LIBRARIES :=
|
||||
|
||||
################################################################################
|
||||
|
||||
# Gencode arguments
|
||||
ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),armv7l aarch64))
|
||||
SMS ?= 35 37 50 52 60 61 70 72 75 80 86
|
||||
else
|
||||
SMS ?= 35 37 50 52 60 61 70 75 80 86
|
||||
endif
|
||||
|
||||
ifeq ($(SMS),)
|
||||
$(info >>> WARNING - no SM architectures have been specified - waiving sample <<<)
|
||||
SAMPLE_ENABLED := 0
|
||||
endif
|
||||
|
||||
ifeq ($(GENCODE_FLAGS),)
|
||||
# Generate SASS code for each SM architecture listed in $(SMS)
|
||||
$(foreach sm,$(SMS),$(eval GENCODE_FLAGS += -gencode arch=compute_$(sm),code=sm_$(sm)))
|
||||
|
||||
# Generate PTX code from the highest SM architecture in $(SMS) to guarantee forward-compatibility
|
||||
HIGHEST_SM := $(lastword $(sort $(SMS)))
|
||||
ifneq ($(HIGHEST_SM),)
|
||||
GENCODE_FLAGS += -gencode arch=compute_$(HIGHEST_SM),code=compute_$(HIGHEST_SM)
|
||||
endif
|
||||
endif
|
||||
|
||||
ALL_CCFLAGS += --threads 0
|
||||
|
||||
ifeq ($(SAMPLE_ENABLED),0)
|
||||
EXEC ?= @echo "[@]"
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
|
||||
# Target rules
|
||||
all: build
|
||||
|
||||
build: bandwidthTest
|
||||
|
||||
check.deps:
|
||||
ifeq ($(SAMPLE_ENABLED),0)
|
||||
@echo "Sample will be waived due to the above missing dependencies"
|
||||
else
|
||||
@echo "Sample is ready - all dependencies have been met"
|
||||
endif
|
||||
|
||||
bandwidthTest.o:bandwidthTest.cu
|
||||
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
|
||||
|
||||
bandwidthTest: bandwidthTest.o
|
||||
$(EXEC) $(NVCC) $(ALL_LDFLAGS) $(GENCODE_FLAGS) -o $@ $+ $(LIBRARIES)
|
||||
$(EXEC) mkdir -p ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
|
||||
$(EXEC) cp $@ ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
|
||||
|
||||
run: build
|
||||
$(EXEC) ./bandwidthTest
|
||||
|
||||
clean:
|
||||
rm -f bandwidthTest bandwidthTest.o
|
||||
rm -rf ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)/bandwidthTest
|
||||
|
||||
clobber: clean
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user