Merged
fix(codecheck): resolve codecheck findings in profiler and block ops #6742
fix(codecheck): resolve codecheck findings in profiler and block ops #6742
Merged
h9718wAdd on Sep 28
Total: 3 files changed+12-4
@@ -389,7 +389,6 @@ TypePtr DeduceSubViewType([[maybe_unused]] const std::vector<ExprPtr>& args,
389 PRO_IR_CHECK(ExternalError::INVALID_ARGUMENT, args.size() == 0x3)389 PRO_IR_CHECK(ExternalError::INVALID_ARGUMENT, args.size() == 0x3)
390 << "block.subview requires exactly 3 arguments (container, offset, valid_shape), but got " << args.size();390 << "block.subview requires exactly 3 arguments (container, offset, valid_shape), but got " << args.size();
391 auto container_type = args[0]->GetType();391 auto container_type = args[0]->GetType();
392- 
393 if (auto tile_type = As<TileType>(container_type)) {392 if (auto tile_type = As<TileType>(container_type)) {
394 return tile_type;393 return tile_type;
395 }394 }
@@ -13,6 +13,8 @@
13#include <acl/acl_prof.h>13#include <acl/acl_prof.h>
14#include <acl/acl_rt.h>14#include <acl/acl_rt.h>
15#include <profiling/aprof_pub.h>15#include <profiling/aprof_pub.h>
16+#include "securec.h"
17+#include <cstdint>
16#include <cstdlib>18#include <cstdlib>
17#include <cstring>19#include <cstring>
18#include <sys/syscall.h>20#include <sys/syscall.h>
@@ -81,16 +83,17 @@ inline void CacheCaptureTensorInfo(const aclprofTensorInfo& info)
81 return;83 return;
82 }84 }
83 const size_t size = sizeof(ProfCacheTaskInfo) + info.tensorNum * sizeof(MsrofTensorData);85 const size_t size = sizeof(ProfCacheTaskInfo) + info.tensorNum * sizeof(MsrofTensorData);
84- auto* buffer = static_cast<unsigned char*>(std::malloc(size));86+ auto* buffer = static_cast<uint8_t*>(std::malloc(size));
85 if (buffer == nullptr) {87 if (buffer == nullptr) {
86 return;88 return;
87 }89 }
88 const ProfCacheTaskInfo task{info.kernelType, info.blockNums, info.opNameId, info.opTypeId, 0, 0, 0,90 const ProfCacheTaskInfo task{info.kernelType, info.blockNums, info.opNameId, info.opTypeId, 0, 0, 0,
89 info.tensorNum};91 info.tensorNum};
90- std::memcpy(buffer, &task, sizeof(task));92+ (void)memcpy_s(buffer, size, &task, sizeof(task));
91 for (uint32_t index = 0; index < info.tensorNum; ++index) {93 for (uint32_t index = 0; index < info.tensorNum; ++index) {
92 const auto tensor = MakeProfTensorData(info.tensors[index]);94 const auto tensor = MakeProfTensorData(info.tensors[index]);
93- std::memcpy(buffer + sizeof(task) + index * sizeof(tensor), &tensor, sizeof(tensor));95+ const size_t offset = sizeof(task) + index * sizeof(tensor);
96+ (void)memcpy_s(buffer + offset, size - offset, &tensor, sizeof(tensor));
94 }97 }
95 (void)aclrtCacheLastTaskOpInfo(buffer, size);98 (void)aclrtCacheLastTaskOpInfo(buffer, size);
96 std::free(buffer);99 std::free(buffer);
@@ -41,6 +41,12 @@ extern "C" aclError aclrtCacheLastTaskOpInfo(const void* const data, const size_
41 return reportError;41 return reportError;
42}42}
43extern "C" uint64_t MsprofSysCycleTime() { return 100 + ++cycles; }43extern "C" uint64_t MsprofSysCycleTime() { return 100 + ++cycles; }
44+extern "C" errno_t memcpy_s(void* dest, size_t destMax, const void* src, size_t count)
45+{
46+ assert(count <= destMax);
47+ std::memcpy(dest, src, count);
48+ return EOK;
49+}
44extern "C" int32_t MsprofReportCompactInfo(uint32_t aging, void* data, uint32_t size)50extern "C" int32_t MsprofReportCompactInfo(uint32_t aging, void* data, uint32_t size)
45{51{
46 assert(aging && size == sizeof(basic));52 assert(aging && size == sizeof(basic));