Add ucm-toolkit for posix aio test&nic monitor and copy bandwidth test#1012
Add ucm-toolkit for posix aio test&nic monitor and copy bandwidth test#1012harrisonyhq wants to merge 9 commits into
Conversation
| std::vector<const CopyBuffer*> srcBuffers(ctx.nDevice); | ||
| std::vector<const CopyBuffer*> dstBuffers(ctx.nDevice); | ||
| for (size_t device = 0; device < ctx.nDevice; device++) { | ||
| srcBuffers[device] = new HostCopyBuffer{device, ctx.size, ctx.num}; |
There was a problem hiding this comment.
🔴 Critical: Memory allocation with new followed by instance.DoCopyBatch(...) without exception handling. If DoCopyBatch throws an exception, the HostCopyBuffer and DeviceCopyBuffer objects will not be deleted, causing memory leaks. Consider wrapping this in a try-catch block or using smart pointers (e.g., std::unique_ptr).
ygwpz
left a comment
There was a problem hiding this comment.
Follow-up review: Two concerns addressed, but critical memory safety issue remains.
| * Copyright (c) 2026 Mag1c.H | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal |
There was a problem hiding this comment.
Thank you for addressing the first two concerns. However, I notice that the critical memory safety issue (Comment #3) remains unaddressed.
The concern was about exception safety in toolkit/src/dev-sandbox/module/copy/ascend/copy_case_ascend.cc around lines 73-82:
for (size_t device = 0; device < ctx.nDevice; device++) {
srcBuffers[device] = new HostCopyBuffer{device, ctx.size, ctx.num};
dstBuffers[device] = new DeviceCopyBuffer{device, ctx.size, ctx.num};
}
H2DCECopyInstance instance{ctx.iter, false};
CopyResult result;
result.Push(instance.DoCopyBatch(srcBuffers, dstBuffers)); // ← If this throws
for (size_t device = 0; device < ctx.nDevice; device++) {
delete srcBuffers[device]; // ← These cleanup lines will never execute
delete dstBuffers[device];
}If DoCopyBatch() throws an exception, the memory allocated with new will leak because the cleanup loop won't execute.
Suggested fix: Wrap the cleanup in a try-catch block or use smart pointers (e.g., std::unique_ptr):
std::vector<std::unique_ptr<HostCopyBuffer>> srcBuffers(ctx.nDevice);
std::vector<std::unique_ptr<DeviceCopyBuffer>> dstBuffers(ctx.nDevice);
for (size_t device = 0; device < ctx.nDevice; device++) {
srcBuffers[device] = std::make_unique<HostCopyBuffer>(device, ctx.size, ctx.num);
dstBuffers[device] = std::make_unique<DeviceCopyBuffer>(device, ctx.size, ctx.num);
}
H2DCECopyInstance instance{ctx.iter, false};
CopyResult result;
result.Push(instance.DoCopyBatch(srcBuffers, dstBuffers));
// Smart pointers handle cleanup automaticallyOr use a try-catch:
try {
result.Push(instance.DoCopyBatch(srcBuffers, dstBuffers));
} catch (...) {
for (size_t device = 0; device < ctx.nDevice; device++) {
delete srcBuffers[device];
delete dstBuffers[device];
}
throw;
}Please address this issue before the PR can be approved.
- Replace raw pointer new/delete with std::unique_ptr for RAII - Extract raw pointers for DoCopyBatch interface compatibility - Ensure automatic memory cleanup even on exception Fixes review comment about potential memory leak if DoCopyBatch throws.
| result.Push(instance.DoCopy(&srcBuffer, &dstBuffer)); | ||
| } | ||
| result.Show("[[ " + Key() + " ]] " + Brief()); | ||
| } |
There was a problem hiding this comment.
💡 Suggestion: Using unique_ptr for memory management is good. Verify that the smart pointer ownership transfer is correct, especially in multi-threaded contexts.
| result.Show("[[ " + Key() + " ]] " + Brief()); | ||
| } | ||
|
|
||
| DEFINE_COPY_CASE(AllHost2AllDeviceCECase, "all_host_to_all_device_ce", |
There was a problem hiding this comment.
💡 Suggestion: Using unique_ptr for memory management is good. Verify that the smart pointer ownership transfer is correct, especially in multi-threaded contexts.
| result.Show("[[ " + Key() + " ]] " + Brief()); | ||
| } | ||
|
|
||
| DEFINE_COPY_CASE(AllHost2AllDeviceCECase, "all_host_to_all_device_ce", |
There was a problem hiding this comment.
💡 Suggestion: Using unique_ptr for memory management is good. Verify that the smart pointer ownership transfer is correct, especially in multi-threaded contexts.
Purpose
Add
ucm-toolkitas a unified CLI entry for POSIX AIO testing, NIC monitoring, and copy bandwidth testing.Modifications
ucm-toolkitpackage and CLI entry point.posix-aio,nic-monitor, anddev-sandboxtooling.Test