已合并
【fix】: 修复acl对外获取地址属性时的错误type以及修正内部对于loc_type在部分驱动返回值的映射逻辑 #3833
【fix】: 修复acl对外获取地址属性时的错误type以及修正内部对于loc_type在部分驱动返回值的映射逻辑 #3833
已合并
YzQnWyx创建于 7月25日
12 个文件变更+61-22
@@ -3833,10 +3833,14 @@ typedef enum aclrtMemLocationType {
3833 ACL_MEM_LOCATION_TYPE_HOST = 0, // 通过acl接口(例如aclrtMallocHost)申请的Host内存3833 ACL_MEM_LOCATION_TYPE_HOST = 0, // 通过acl接口(例如aclrtMallocHost)申请的Host内存
3834 ACL_MEM_LOCATION_TYPE_DEVICE, // 通过acl接口(例如aclrtMalloc)申请的Device内存3834 ACL_MEM_LOCATION_TYPE_DEVICE, // 通过acl接口(例如aclrtMalloc)申请的Device内存
3835 ACL_MEM_LOCATION_TYPE_UNREGISTERED, // 未通过acl接口申请的内存3835 ACL_MEM_LOCATION_TYPE_UNREGISTERED, // 未通过acl接口申请的内存
3836+ ACL_MEM_LOCATION_TYPE_MANAGED, // UVM类型内存(Unified Virtual Memory, 统一虚拟内存)
3836 ACL_MEM_LOCATION_TYPE_HOST_NUMA =4, // 通过aclrtMallocPhysical接口按照NUMA ID申请Host内存3837 ACL_MEM_LOCATION_TYPE_HOST_NUMA =4, // 通过aclrtMallocPhysical接口按照NUMA ID申请Host内存
3837} aclrtMemLocationType;3838} aclrtMemLocationType;
3838```3839```
3839 3840 
3841+<!-- npu="910b" id103 -->
3842+ACL_MEM_LOCATION_TYPE_MANAGED选项当前仅Atlas A2 训练系列产品/Atlas A2 推理系列产品支持
3843+<!-- end id103 -->
3840 3844 
3841<br>3845<br>
3842<br>3846<br>
@@ -313,6 +313,7 @@ typedef enum aclrtMemLocationType {
313 ACL_MEM_LOCATION_TYPE_HOST = 0, /**< reserved enum, current version not support */313 ACL_MEM_LOCATION_TYPE_HOST = 0, /**< reserved enum, current version not support */
314 ACL_MEM_LOCATION_TYPE_DEVICE,314 ACL_MEM_LOCATION_TYPE_DEVICE,
315 ACL_MEM_LOCATION_TYPE_UNREGISTERED,315 ACL_MEM_LOCATION_TYPE_UNREGISTERED,
316+ ACL_MEM_LOCATION_TYPE_MANAGED,
316 ACL_MEM_LOCATION_TYPE_HOST_NUMA = 4, /*alloc host memeory via NUMA ID */317 ACL_MEM_LOCATION_TYPE_HOST_NUMA = 4, /*alloc host memeory via NUMA ID */
317} aclrtMemLocationType;318} aclrtMemLocationType;
318 319 
@@ -43,8 +43,7 @@ typedef enum {
43 RT_MEMORY_LOC_UNREGISTERED,43 RT_MEMORY_LOC_UNREGISTERED,
44 RT_MEMORY_LOC_MANAGED,44 RT_MEMORY_LOC_MANAGED,
45 RT_MEMORY_LOC_HOST_NUMA,45 RT_MEMORY_LOC_HOST_NUMA,
46- RT_MEMORY_LOC_MAX,46+ RT_MEMORY_LOC_MAX
47- RT_MEMORY_LOC_UVM_MANAGED,
48} rtMemLocationType;47} rtMemLocationType;
49 48 
50typedef struct {49typedef struct {
@@ -1015,12 +1015,21 @@ aclError aclrtMallocPhysicalImpl(aclrtDrvMemHandle *handle,
1015 ACL_CHECK_RESERVED_PARAM_REPORT_RET(flags, 0, ACL_ERROR_INVALID_PARAM);1015 ACL_CHECK_RESERVED_PARAM_REPORT_RET(flags, 0, ACL_ERROR_INVALID_PARAM);
1016 ACL_REQUIRES_PARAM_EQUAL_REPORT(prop->handleType, ACL_MEM_HANDLE_TYPE_NONE);1016 ACL_REQUIRES_PARAM_EQUAL_REPORT(prop->handleType, ACL_MEM_HANDLE_TYPE_NONE);
1017 ACL_REQUIRES_PARAM_EQUAL_REPORT(prop->allocationType, ACL_MEM_ALLOCATION_TYPE_PINNED);1017 ACL_REQUIRES_PARAM_EQUAL_REPORT(prop->allocationType, ACL_MEM_ALLOCATION_TYPE_PINNED);
1018- ACL_CHECK_INVALID_PARAM_WITH_REASON_DESC_RET(1018+ if (prop->location.type == ACL_MEM_LOCATION_TYPE_UNREGISTERED ||
1019- prop->location.type == ACL_MEM_LOCATION_TYPE_UNREGISTERED,1019+ prop->location.type == ACL_MEM_LOCATION_TYPE_MANAGED) {
1020- acl::GetMemLocationTypeDesc(prop->location.type),1020+ ACL_LOG_ERROR(
1021- "prop->location.type",1021+ "[Check][PARAM]prop->location.type is invalid, location type does not support %s. value=%s",
1022- "location type does not support ACL_MEM_LOCATION_TYPE_UNREGISTERED",1022+ acl::GetMemLocationTypeDesc(prop->location.type), acl::GetMemLocationTypeDesc(prop->location.type));
1023- ACL_ERROR_INVALID_PARAM);1023+ std::string errMsg = acl::AclErrorLogManager::FormatStr(
1024+ "location type does not support %s", acl::GetMemLocationTypeDesc(prop->location.type));
1025+ std::string funcName = acl::AclErrorLogManager::GetFuncNameWithoutImplSuffix(__func__);
1026+ acl::AclErrorLogManager::ReportInputError(
1027+ acl::INVALID_PARAM_REASON_MSG, std::vector<const char*>({"func", "value", "param", "reason"}),
1028+ std::vector<const char*>(
1029+ {funcName.c_str(), acl::GetMemLocationTypeDesc(prop->location.type), "prop->location.type",
1030+ errMsg.c_str()}));
1031+ return ACL_ERROR_INVALID_PARAM;
1032+ }
1024 1033 
1025 rtDrvMemProp_t rtProp = {};1034 rtDrvMemProp_t rtProp = {};
1026 rtProp.side = prop->location.type;1035 rtProp.side = prop->location.type;
@@ -246,10 +246,11 @@ inline const char* GetCallbackBlockTypeDesc(aclrtCallbackBlockType type) {
246 246 
247inline const char* GetMemLocationTypeDesc(aclrtMemLocationType type) {247inline const char* GetMemLocationTypeDesc(aclrtMemLocationType type) {
248 static const std::unordered_map<aclrtMemLocationType, const char*> memLocationTypeDescMap = {248 static const std::unordered_map<aclrtMemLocationType, const char*> memLocationTypeDescMap = {
249- {ACL_MEM_LOCATION_TYPE_HOST, "MEM_LOCATION_TYPE_HOST(0)"},249+ {ACL_MEM_LOCATION_TYPE_HOST, "ACL_MEM_LOCATION_TYPE_HOST(0)"},
250- {ACL_MEM_LOCATION_TYPE_DEVICE, "MEM_LOCATION_TYPE_DEVICE(1)"},250+ {ACL_MEM_LOCATION_TYPE_DEVICE, "ACL_MEM_LOCATION_TYPE_DEVICE(1)"},
251- {ACL_MEM_LOCATION_TYPE_UNREGISTERED, "MEM_LOCATION_TYPE_UNREGISTERED(2)"},251+ {ACL_MEM_LOCATION_TYPE_UNREGISTERED, "ACL_MEM_LOCATION_TYPE_UNREGISTERED(2)"},
252- {ACL_MEM_LOCATION_TYPE_HOST_NUMA, "MEM_LOCATION_TYPE_HOST_NUMA(4)"},252+ {ACL_MEM_LOCATION_TYPE_MANAGED, "ACL_MEM_LOCATION_TYPE_MANAGED(3)"},
253+ {ACL_MEM_LOCATION_TYPE_HOST_NUMA, "ACL_MEM_LOCATION_TYPE_HOST_NUMA(4)"},
253 };254 };
254 255 
255 auto it = memLocationTypeDescMap.find(type);256 auto it = memLocationTypeDescMap.find(type);
@@ -74,7 +74,7 @@ bool UvmCallback::IsUvmMem(const void * const ptr, const uint64_t cnt)
74 return false;74 return false;
75 }75 }
76 76 
77- if ((locationStart == RT_MEMORY_LOC_UVM_MANAGED) && (locationEnd == RT_MEMORY_LOC_UVM_MANAGED)) {77+ if ((locationStart == RT_MEMORY_LOC_MANAGED) && (locationEnd == RT_MEMORY_LOC_MANAGED)) {
78 return true;78 return true;
79 }79 }
80 80 
@@ -2114,15 +2114,17 @@ rtError_t NpuDriver::PtrGetAttributes(const void * const ptr, rtPtrAttributes_t
2114 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_SOMA)) != 0U) {2114 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_SOMA)) != 0U) {
2115 attributes->location.type = RT_MEMORY_LOC_DEVICE;2115 attributes->location.type = RT_MEMORY_LOC_DEVICE;
2116 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_SVM_DEVICE)) != 0U) {2116 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_SVM_DEVICE)) != 0U) {
2117- attributes->location.type = RT_MEMORY_LOC_MANAGED;2117+ attributes->location.type = RT_MEMORY_LOC_DEVICE;
2118 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_SVM_HOST)) != 0U) {2118 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_SVM_HOST)) != 0U) {
2119- attributes->location.type = RT_MEMORY_LOC_MANAGED;2119+ attributes->location.type = RT_MEMORY_LOC_HOST;
2120 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_SVM)) != 0U) {2120 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_SVM)) != 0U) {
2121- attributes->location.type = RT_MEMORY_LOC_MANAGED;2121+ attributes->location.type = RT_MEMORY_LOC_DEVICE;
2122 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_USER_REGISTER)) != 0U) {2122 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_USER_REGISTER)) != 0U) {
2123 attributes->location.type = RT_MEMORY_LOC_HOST;2123 attributes->location.type = RT_MEMORY_LOC_HOST;
2124 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_USER_MALLOC)) != 0U) {2124 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_USER_MALLOC)) != 0U) {
2125 attributes->location.type = (IsRegisteredMemory(ptr)) ? RT_MEMORY_LOC_HOST : RT_MEMORY_LOC_UNREGISTERED;2125 attributes->location.type = (IsRegisteredMemory(ptr)) ? RT_MEMORY_LOC_HOST : RT_MEMORY_LOC_UNREGISTERED;
2126+ } else if ((dvAttributes.memType & DV_MEM_UVM) != 0U) {
2127+ attributes->location.type = RT_MEMORY_LOC_MANAGED;
2126 } else {2128 } else {
2127 RT_LOG(RT_LOG_ERROR, "does not support this type, drvMemGetAttribute get memType=%u", dvAttributes.memType);2129 RT_LOG(RT_LOG_ERROR, "does not support this type, drvMemGetAttribute get memType=%u", dvAttributes.memType);
2128 return RT_ERROR_INVALID_VALUE;2130 return RT_ERROR_INVALID_VALUE;
@@ -2162,14 +2164,14 @@ rtError_t NpuDriver::PtrGetRealLocation(const void * const ptr, rtMemLocationTyp
2162 location = RT_MEMORY_LOC_DEVICE;2164 location = RT_MEMORY_LOC_DEVICE;
2163 realLocation = RT_MEMORY_LOC_DEVICE;2165 realLocation = RT_MEMORY_LOC_DEVICE;
2164 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_SVM_DEVICE)) != 0U) {2166 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_SVM_DEVICE)) != 0U) {
2165- location = RT_MEMORY_LOC_MANAGED;2167+ location = RT_MEMORY_LOC_DEVICE;
2166 realLocation = RT_MEMORY_LOC_DEVICE;2168 realLocation = RT_MEMORY_LOC_DEVICE;
2167 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_SVM_HOST)) != 0U) {2169 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_SVM_HOST)) != 0U) {
2168- location = RT_MEMORY_LOC_MANAGED;2170+ location = RT_MEMORY_LOC_HOST;
2169 realLocation = RT_MEMORY_LOC_HOST;2171 realLocation = RT_MEMORY_LOC_HOST;
2170 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_SVM)) != 0U) {2172 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_SVM)) != 0U) {
2171- location = RT_MEMORY_LOC_MANAGED;2173+ location = RT_MEMORY_LOC_DEVICE;
2172- realLocation = RT_MEMORY_LOC_HOST; // to be check2174+ realLocation = RT_MEMORY_LOC_DEVICE; // to be check
2173 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_USER_REGISTER)) != 0U) {2175 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_USER_REGISTER)) != 0U) {
2174 location = RT_MEMORY_LOC_HOST;2176 location = RT_MEMORY_LOC_HOST;
2175 realLocation = RT_MEMORY_LOC_HOST;2177 realLocation = RT_MEMORY_LOC_HOST;
@@ -2177,8 +2179,8 @@ rtError_t NpuDriver::PtrGetRealLocation(const void * const ptr, rtMemLocationTyp
2177 location = (IsRegisteredMemory(ptr)) ? RT_MEMORY_LOC_HOST : RT_MEMORY_LOC_UNREGISTERED;2179 location = (IsRegisteredMemory(ptr)) ? RT_MEMORY_LOC_HOST : RT_MEMORY_LOC_UNREGISTERED;
2178 realLocation = RT_MEMORY_LOC_HOST;2180 realLocation = RT_MEMORY_LOC_HOST;
2179 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_UVM)) != 0U) {2181 } else if ((dvAttributes.memType & static_cast<uint32_t>(DV_MEM_UVM)) != 0U) {
2180- location = RT_MEMORY_LOC_UVM_MANAGED;2182+ location = RT_MEMORY_LOC_MANAGED;
2181- realLocation = RT_MEMORY_LOC_HOST;2183+ realLocation = RT_MEMORY_LOC_MANAGED;
2182 } else {2184 } else {
2183 RT_LOG(RT_LOG_ERROR, "does not support this type, drvMemGetAttribute get memType=%u", dvAttributes.memType);2185 RT_LOG(RT_LOG_ERROR, "does not support this type, drvMemGetAttribute get memType=%u", dvAttributes.memType);
2184 return RT_ERROR_INVALID_VALUE;2186 return RT_ERROR_INVALID_VALUE;
@@ -2912,6 +2912,11 @@ TEST_F(UTEST_ACL_Runtime, physical_memory_malloc_free)
2912 EXPECT_EQ(ret, ACL_SUCCESS);2912 EXPECT_EQ(ret, ACL_SUCCESS);
2913 EXPECT_NE(handle, nullptr);2913 EXPECT_NE(handle, nullptr);
2914 2914 
2915+ prop.location.type = ACL_MEM_LOCATION_TYPE_MANAGED;
2916+ ret = aclrtMallocPhysical(&handle, size, &prop, 0);
2917+ EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM);
2918+ prop.location.type = ACL_MEM_LOCATION_TYPE_DEVICE;
2919+ 
2915 prop.memAttr = ACL_DDR_MEM;2920 prop.memAttr = ACL_DDR_MEM;
2916 ret = aclrtMallocPhysical(&handle, size, &prop, 0);2921 ret = aclrtMallocPhysical(&handle, size, &prop, 0);
2917 EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM);2922 EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM);
@@ -58,6 +58,12 @@ DVresult drvMemGetAttribute_9(DVdeviceptr vptr, struct DVattribute *attr)
58 attr->memType = DV_MEM_USER_REGISTER;58 attr->memType = DV_MEM_USER_REGISTER;
59 return DRV_ERROR_NONE;59 return DRV_ERROR_NONE;
60}60}
61+ 
62+DVresult drvMemGetAttribute_10(DVdeviceptr vptr, struct DVattribute* attr)
63+{
64+ attr->memType = DV_MEM_UVM;
65+ return DRV_ERROR_NONE;
66+}
61extern rtError_t rtStreamAddToModel(rtStream_t stm, rtModel_t captureMdl);67extern rtError_t rtStreamAddToModel(rtStream_t stm, rtModel_t captureMdl);
62 68 
63drvError_t drvGetPlatformInfo_1(uint32_t *info)69drvError_t drvGetPlatformInfo_1(uint32_t *info)
@@ -7599,6 +7599,11 @@ TEST_F(ApiTest, rts_memory_reallocation)
7599 error = drv.PtrGetRealLocation(hostPtr, location, realLocation);7599 error = drv.PtrGetRealLocation(hostPtr, location, realLocation);
7600 EXPECT_NE(error, RT_ERROR_NONE);7600 EXPECT_NE(error, RT_ERROR_NONE);
7601 GlobalMockObject::verify();7601 GlobalMockObject::verify();
7602+ 
7603+ MOCKER(drvMemGetAttribute).stubs().will(invoke(drvMemGetAttribute_10));
7604+ error = drv.PtrGetRealLocation(hostPtr, location, realLocation);
7605+ EXPECT_EQ(error, RT_ERROR_NONE);
7606+ GlobalMockObject::verify();
7602}7607}
7603 7608 
7604TEST_F(ApiTest, get_taskid_streamid)7609TEST_F(ApiTest, get_taskid_streamid)
@@ -82,6 +82,7 @@ DVresult drvMemGetAttribute_6(DVdeviceptr vptr, struct DVattribute *attr);
82DVresult drvMemGetAttribute_7(DVdeviceptr vptr, struct DVattribute *attr);82DVresult drvMemGetAttribute_7(DVdeviceptr vptr, struct DVattribute *attr);
83DVresult drvMemGetAttribute_8(DVdeviceptr vptr, struct DVattribute *attr);83DVresult drvMemGetAttribute_8(DVdeviceptr vptr, struct DVattribute *attr);
84DVresult drvMemGetAttribute_9(DVdeviceptr vptr, struct DVattribute *attr);84DVresult drvMemGetAttribute_9(DVdeviceptr vptr, struct DVattribute *attr);
85+DVresult drvMemGetAttribute_10(DVdeviceptr vptr, struct DVattribute *attr);
85extern rtError_t rtStreamAddToModel(rtStream_t stm, rtModel_t captureMdl);86extern rtError_t rtStreamAddToModel(rtStream_t stm, rtModel_t captureMdl);
86drvError_t drvGetPlatformInfo_1(uint32_t *info);87drvError_t drvGetPlatformInfo_1(uint32_t *info);
87drvError_t drvGetPlatformInfo_2(uint32_t *info);88drvError_t drvGetPlatformInfo_2(uint32_t *info);
@@ -59,6 +59,12 @@ DVresult drvMemGetAttribute_9(DVdeviceptr vptr, struct DVattribute *attr)
59 attr->memType = DV_MEM_USER_REGISTER;59 attr->memType = DV_MEM_USER_REGISTER;
60 return DRV_ERROR_NONE;60 return DRV_ERROR_NONE;
61}61}
62+ 
63+DVresult drvMemGetAttribute_10(DVdeviceptr vptr, struct DVattribute* attr)
64+{
65+ attr->memType = DV_MEM_UVM;
66+ return DRV_ERROR_NONE;
67+}
62extern rtError_t rtStreamAddToModel(rtStream_t stm, rtModel_t captureMdl);68extern rtError_t rtStreamAddToModel(rtStream_t stm, rtModel_t captureMdl);
63 69 
64drvError_t drvGetPlatformInfo_1(uint32_t *info)70drvError_t drvGetPlatformInfo_1(uint32_t *info)