Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit de88841

Browse files
authored
Merge pull request #186 from NVIDIA/bugfix/nvtarget_nvrtc_device_annotations
Fix NVRTC processing of <nv/target>
2 parents 8bde5f9 + 51debf7 commit de88841

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

.upstream-tests/test/cuda/test_platform.pass.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
//===----------------------------------------------------------------------===//
99

1010
#include <nv/target>
11-
#include <stdio.h>
11+
12+
#if !defined(__CUDACC_RTC__)
1213
#include <assert.h>
14+
#include <stdio.h>
15+
#endif
1316

14-
#if defined(__NVCC__)
17+
#if defined(__NVCC__) || defined(__CUDACC_RTC__)
1518
# define TEST_NVCC
1619
#elif defined(__NVCOMPILER)
1720
# define TEST_NVCXX

include/nv/target

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
# define _NV_COMPILER_NVCC
1818
#elif defined(__NVCOMPILER) && __cplusplus >= 201103L
1919
# define _NV_COMPILER_NVCXX
20+
#endif
21+
22+
#if defined(__CUDACC_RTC__)
23+
# define _NV_FUNCTION_ANNOTATION __device__
2024
#else
25+
# define _NV_FUNCTION_ANNOTATION
2126
#endif
2227

2328
#if defined(_NV_COMPILER_NVCXX)
@@ -61,6 +66,7 @@ namespace nv {
6166
// Store a set of targets as a set of bits
6267
struct _NV_BITSET_ATTRIBUTE target_description {
6368
base_int_t targets;
69+
_NV_FUNCTION_ANNOTATION
6470
constexpr target_description(base_int_t a) : targets(a) { }
6571
};
6672

@@ -72,9 +78,11 @@ namespace nv {
7278
sm_70 = 70, sm_72 = 72, sm_75 = 75,
7379
sm_80 = 80, sm_86 = 86,
7480
};
81+
_NV_FUNCTION_ANNOTATION
7582
constexpr base_int_t toint(sm_selector a) {
7683
return static_cast<base_int_t>(a);
7784
}
85+
_NV_FUNCTION_ANNOTATION
7886
constexpr base_int_t bitexact(sm_selector a) {
7987
return toint(a) == 35 ? sm_35_bit :
8088
toint(a) == 37 ? sm_37_bit :
@@ -90,6 +98,7 @@ namespace nv {
9098
toint(a) == 80 ? sm_80_bit :
9199
toint(a) == 86 ? sm_86_bit : 0;
92100
}
101+
_NV_FUNCTION_ANNOTATION
93102
constexpr base_int_t bitrounddown(sm_selector a) {
94103
return toint(a) >= 86 ? sm_86_bit :
95104
toint(a) >= 80 ? sm_80_bit :
@@ -108,26 +117,31 @@ namespace nv {
108117

109118
// Public API for NVIDIA GPUs
110119

120+
_NV_FUNCTION_ANNOTATION
111121
constexpr target_description is_exactly(sm_selector a) {
112122
return target_description(bitexact(a));
113123
}
114124

125+
_NV_FUNCTION_ANNOTATION
115126
constexpr target_description provides(sm_selector a) {
116127
return target_description(~(bitrounddown(a) - 1) & all_devices);
117128
}
118129

119130
// Boolean operations on target sets
120131

132+
_NV_FUNCTION_ANNOTATION
121133
constexpr target_description operator&&(target_description a,
122134
target_description b) {
123135
return target_description(a.targets & b.targets);
124136
}
125137

138+
_NV_FUNCTION_ANNOTATION
126139
constexpr target_description operator||(target_description a,
127140
target_description b) {
128141
return target_description(a.targets | b.targets);
129142
}
130143

144+
_NV_FUNCTION_ANNOTATION
131145
constexpr target_description operator!(target_description a) {
132146
return target_description(~a.targets & (all_devices | all_hosts));
133147
}

0 commit comments

Comments
 (0)