Skip to content

Commit

Permalink
Specify cuContext in range profiler structs (#643)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #643

## Context:
I was experiencing some crashes with the range proiler. The backtrace showed ::disable() failing and I found that the `.ctx` member of the configuration struct was not set.

## Changes:
This diff specifies cuContext for all structs that have it as a required member.

This diff also specifies the `.targetNestingLevel` member for the `setConfigParams` struct as it was unset.

Reviewed By: benghaem

Differential Revision: D38435331

fbshipit-source-id: 3a2a297f7ed5665ed3d58df7f48ae8a64e5ac956
  • Loading branch information
aaronenyeshi authored and facebook-github-bot committed Dec 5, 2023
1 parent 127df34 commit e8a3713
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion libkineto/src/CuptiRangeProfilerApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ CuptiRBProfilerSession::CuptiRBProfilerSession(
<< counterDataScratchBuffer.size() << " B";

beginPassParams_ = {CUpti_Profiler_BeginPass_Params_STRUCT_SIZE, nullptr};
beginPassParams_.ctx = cuContext_;
endPassParams_ = {CUpti_Profiler_EndPass_Params_STRUCT_SIZE, nullptr};
endPassParams_.ctx = cuContext_;

initSuccess_ = true;
profiler_map[deviceId_] = this;
Expand Down Expand Up @@ -448,9 +450,10 @@ void CuptiRBProfilerSession::startInternal(
setConfigParams.ctx = cuContext_;
setConfigParams.pConfig = configImage.data();
setConfigParams.configSize = configImage.size();
setConfigParams.passIndex = 0;
setConfigParams.minNestingLevel = 1;
setConfigParams.numNestingLevels = numNestingLevels_;
setConfigParams.passIndex = 0;
setConfigParams.targetNestingLevel = setConfigParams.minNestingLevel;
status = CUPTI_CALL(cuptiProfilerSetConfig(&setConfigParams));

if (status != CUPTI_SUCCESS) {
Expand All @@ -475,10 +478,12 @@ void CuptiRBProfilerSession::stop() {

CUpti_Profiler_UnsetConfig_Params unsetConfigParams = {
CUpti_Profiler_UnsetConfig_Params_STRUCT_SIZE, nullptr};
unsetConfigParams.ctx = cuContext_;
CUPTI_CALL(cuptiProfilerUnsetConfig(&unsetConfigParams));

CUpti_Profiler_EndSession_Params endSessionParams = {
CUpti_Profiler_EndSession_Params_STRUCT_SIZE, nullptr};
endSessionParams.ctx = cuContext_;
CUPTI_CALL(cuptiProfilerEndSession(&endSessionParams));

disableKernelCallbacks();
Expand Down Expand Up @@ -508,6 +513,7 @@ void CuptiRBProfilerSession::flushCounterData() {
LOG(INFO) << "Flushing counter data on device = " << deviceId_;
CUpti_Profiler_FlushCounterData_Params flushCounterDataParams = {
CUpti_Profiler_FlushCounterData_Params_STRUCT_SIZE, nullptr};
flushCounterDataParams.ctx = cuContext_;
CUPTI_CALL(cuptiProfilerFlushCounterData(&flushCounterDataParams));
}

Expand All @@ -519,6 +525,7 @@ void CuptiRBProfilerSession::enable() {
}
CUpti_Profiler_EnableProfiling_Params enableProfilingParams = {
CUpti_Profiler_EnableProfiling_Params_STRUCT_SIZE, nullptr};
enableProfilingParams.ctx = cuContext_;
CUPTI_CALL(cuptiProfilerEnableProfiling(&enableProfilingParams));
}

Expand All @@ -529,6 +536,7 @@ void CuptiRBProfilerSession::disable() {
}
CUpti_Profiler_DisableProfiling_Params disableProfilingParams = {
CUpti_Profiler_DisableProfiling_Params_STRUCT_SIZE, nullptr};
disableProfilingParams.ctx = cuContext_;
CUPTI_CALL(cuptiProfilerDisableProfiling(&disableProfilingParams));
}

Expand All @@ -537,6 +545,7 @@ void CuptiRBProfilerSession::pushRange(const std::string& rangeName) {
LOG(INFO) << " CUPTI pushrange ( " << rangeName << " )";
CUpti_Profiler_PushRange_Params pushRangeParams = {
CUpti_Profiler_PushRange_Params_STRUCT_SIZE, nullptr};
pushRangeParams.ctx = cuContext_;
pushRangeParams.pRangeName = rangeName.c_str();
CUPTI_CALL(cuptiProfilerPushRange(&pushRangeParams));
}
Expand All @@ -545,6 +554,7 @@ void CuptiRBProfilerSession::popRange() {
LOG(INFO) << " CUPTI pop range";
CUpti_Profiler_PopRange_Params popRangeParams = {
CUpti_Profiler_PopRange_Params_STRUCT_SIZE, nullptr};
popRangeParams.ctx = cuContext_;
CUPTI_CALL(cuptiProfilerPopRange(&popRangeParams));
}

Expand Down

0 comments on commit e8a3713

Please sign in to comment.