Skip to content

Commit 860275f

Browse files
anmyachevfywkevin
andauthored
[Proton] Check and error out on insufficient profiling memory (#7790) (#5305)
Add a checking and error msg to prevent libproton silent crash when dumping profiler buffer during profiler exit hook. Co-authored-by: Yuanwei Fang <[email protected]>
1 parent 32dbd88 commit 860275f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

third_party/proton/csrc/lib/Profiler/Instrumentation/InstrumentationProfiler.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ InstrumentationProfiler::getParserConfig(uint64_t functionId,
108108
config->totalUnits = functionMetadata.at(functionId).getNumWarps();
109109
config->numBlocks = bufferSize / config->scratchMemSize;
110110
config->uidVec = getUnitIdVector(modeOptions, config->totalUnits);
111+
112+
// Check if the uidVec is valid
113+
for (auto uid : config->uidVec)
114+
if (uid >= config->totalUnits) {
115+
throw std::runtime_error(
116+
"Invalid sampling warp id: " + std::to_string(uid) + ". We have " +
117+
std::to_string(config->totalUnits) +
118+
" warps in total. Please check the proton sampling options.");
119+
}
120+
111121
config->device = Device();
112122
config->device.type = runtime->getDeviceType();
113123

@@ -217,7 +227,7 @@ void InstrumentationProfiler::exitInstrumentedOp(uint64_t streamId,
217227

218228
runtime->synchronizeStream(reinterpret_cast<void *>(streamId));
219229
runtime->processHostBuffer(
220-
hostBuffer, DEFAULT_HOST_BUFFER_SIZE, buffer, size, priorityStream,
230+
hostBuffer, size, buffer, size, priorityStream,
221231
[&](uint8_t *bufferPtr, size_t size) {
222232
ByteSpan byteSpan(bufferPtr, size);
223233
CircularLayoutParser parser(byteSpan, *circularLayoutConfig);

0 commit comments

Comments
 (0)