Skip to content

Commit 742260c

Browse files
aaronenyeshifacebook-github-bot
authored andcommitted
Update HAS_CUPTI_RANGE_PROFILER to CUDA 11+ for CUPTI Range Profiler APIs and remove init-statement in selection statement (#555)
Summary: Pull Request resolved: #555 The CuptiRangeProfilerAPI is using APIs from CUPTI in CUDA 11 such as CUpti_Profiler_GetCounterAvailability_Params and cuptiProfilerGetCounterAvailability. These are not available in CUDA 10.2 which caused PyTorch CI to crash. Also, move the init statement outside of the if statement, which is a C++17 feature, but PyTorch uses C++14. Test Plan: CI Tests and PyTorch build in C++14. Reviewed By: malfet Differential Revision: D34690168 Pulled By: aaronenyeshi fbshipit-source-id: 619570452130aabe29d83e12459c366b99a7f830
1 parent 505a9e8 commit 742260c

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

libkineto/src/CuptiRangeProfilerApi.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
#include "CuptiCallbackApiMock.h"
2323
#include "CuptiRangeProfilerApi.h"
2424

25-
#if HAS_CUPTI_PROFILER
25+
#if HAS_CUPTI_RANGE_PROFILER
2626
#include <cupti.h>
2727
#include <nvperf_host.h>
2828
#include "cupti_call.h"
29-
#endif // HAS_CUPTI_PROFILER
29+
#endif // HAS_CUPTI_RANGE_PROFILER
3030

3131
namespace KINETO_NAMESPACE {
3232

33-
#if HAS_CUPTI_PROFILER
33+
#if HAS_CUPTI_RANGE_PROFILER
3434
constexpr char kRootUserRangeName[] = "__profile__";
3535
constexpr int kCallbacksCountToFlush = 500;
3636

@@ -171,7 +171,8 @@ void __trackCudaKernelLaunch(
171171
<< " context ptr = " << ctx;
172172

173173
uint32_t device_id = 0;
174-
if (auto it = ctx_to_dev.find(ctx); it == ctx_to_dev.end()) {
174+
auto it = ctx_to_dev.find(ctx);
175+
if (it == ctx_to_dev.end()) {
175176
// Warning here could be too noisy
176177
VLOG(0) << " Could not find corresponding device to ctx = " << ctx;
177178
return;
@@ -730,20 +731,20 @@ std::vector<uint8_t>& CuptiRBProfilerSession::counterAvailabilityImage() {
730731
static std::vector<uint8_t> _vec;
731732
return _vec;
732733
}
733-
#endif // HAS_CUPTI_PROFILER
734+
#endif // HAS_CUPTI_RANGE_PROFILER
734735

735736
namespace testing {
736737

737738
void trackCudaCtx(CUcontext ctx, uint32_t device_id, CUpti_CallbackId cbid) {
738-
#if HAS_CUPTI_PROFILER
739+
#if HAS_CUPTI_RANGE_PROFILER
739740
__trackCudaCtx(ctx, device_id, cbid);
740-
#endif // HAS_CUPTI_PROFILER
741+
#endif // HAS_CUPTI_RANGE_PROFILER
741742
}
742743

743744
void trackCudaKernelLaunch(CUcontext ctx, const char* kernelName) {
744-
#if HAS_CUPTI_PROFILER
745+
#if HAS_CUPTI_RANGE_PROFILER
745746
__trackCudaKernelLaunch(ctx, kernelName);
746-
#endif // HAS_CUPTI_PROFILER
747+
#endif // HAS_CUPTI_RANGE_PROFILER
747748
}
748749

749750
} // namespace testing

libkineto/src/CuptiRangeProfilerApi.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
#ifdef HAS_CUPTI
66
#include <cuda.h>
77
#include <cuda_runtime_api.h>
8-
#if defined(CUDART_VERSION) && CUDART_VERSION >= 10000 && CUDART_VERSION < 11040 && CUDA_VERSION >= 10010
9-
#define HAS_CUPTI_PROFILER 1
10-
#endif // CUDART_VERSION > 10.00 and < 11.04 && CUDA_VERSION >= 10.10
8+
// Using CUDA 11 and above due to usage of API: cuptiProfilerGetCounterAvailability.
9+
#if defined(CUDART_VERSION) && CUDART_VERSION >= 10000 && CUDART_VERSION < 11040 && CUDA_VERSION >= 11000
10+
#define HAS_CUPTI_RANGE_PROFILER 1
11+
#endif // CUDART_VERSION > 10.00 and < 11.04 && CUDA_VERSION >= 11.00
1112
#endif // HAS_CUPTI
1213

13-
#if HAS_CUPTI_PROFILER
14+
#if HAS_CUPTI_RANGE_PROFILER
1415
#include <cupti.h>
1516
#include <cupti_profiler_target.h>
1617
#include <cupti_target.h>
@@ -26,7 +27,7 @@ using CUpti_ProfilerReplayMode = enum
2627
CUPTI_KernelReplay,
2728
CUPTI_UserReplay,
2829
};
29-
#endif // HAS_CUPTI_PROFILER
30+
#endif // HAS_CUPTI_RANGE_PROFILER
3031

3132
#include <chrono>
3233
#include <mutex>
@@ -197,7 +198,7 @@ class CuptiRBProfilerSession {
197198

198199
static std::vector<uint8_t>& counterAvailabilityImage();
199200

200-
#if HAS_CUPTI_PROFILER
201+
#if HAS_CUPTI_RANGE_PROFILER
201202
CUpti_Profiler_BeginPass_Params beginPassParams_;
202203
CUpti_Profiler_EndPass_Params endPassParams_;
203204
#endif

libkineto/test/CuptiProfilerApiTest.cu

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void VectorAddSubtract() {
149149
cleanUp(h_A, h_B, h_C, h_D, d_A, d_B, d_C, d_D);
150150
}
151151

152-
#if HAS_CUPTI_PROFILER
152+
#if HAS_CUPTI_RANGE_PROFILER
153153
bool runTestWithAutoRange(
154154
int deviceNum,
155155
const std::vector<std::string>& metricNames,
@@ -272,7 +272,7 @@ bool runTestWithUserRange(
272272
}
273273
return true;
274274
}
275-
#endif // HAS_CUPTI_PROFILER
275+
#endif // HAS_CUPTI_RANGE_PROFILER
276276

277277
int main(int argc, char* argv[]) {
278278

@@ -314,7 +314,7 @@ int main(int argc, char* argv[]) {
314314
LOG(ERROR) << "CUPTI Profiler is not supported with compute capability < 7.0";
315315
return -2;
316316
}
317-
317+
318318
CuptiRBProfilerSession::staticInit();
319319

320320
// metrics to profile
@@ -329,7 +329,7 @@ int main(int argc, char* argv[]) {
329329

330330
VectorAddSubtract();
331331

332-
#if HAS_CUPTI_PROFILER
332+
#if HAS_CUPTI_RANGE_PROFILER
333333
CuptiRBProfilerSession::staticInit();
334334

335335
if (!runTestWithUserRange(deviceNum, metricNames, cuContext, false)) {
@@ -345,7 +345,7 @@ int main(int argc, char* argv[]) {
345345
CuptiRBProfilerSession::deInitCupti();
346346
#else
347347
LOG(WARNING) << "CuptiRBProfilerSession is not supported.";
348-
#endif // HAS_CUPTI_PROFILER
348+
#endif // HAS_CUPTI_RANGE_PROFILER
349349
DRIVER_API_CALL(cuCtxDestroy(cuContext));
350350

351351

0 commit comments

Comments
 (0)