已合并
处理AdaptiveMaxPool3d算子examples中test_aclnn_adaptive_max_pool3d失败问题 #9020
liuhongpeng创建于 8月21日
处理AdaptiveMaxPool3d算子examples中test_aclnn_adaptive_max_pool3d失败问题 #9020
已合并
共 1 个文件变更+12-8
| @@ -91,18 +91,18 @@ int main() | |||
| 91 | aclTensor* indices = nullptr; | 91 | aclTensor* indices = nullptr; |
| 92 | std::vector<float> selfHostData = {0, 1, 2, 3, 4.1, 5, 6, 7, 8, 9, 10, 11, | 92 | std::vector<float> selfHostData = {0, 1, 2, 3, 4.1, 5, 6, 7, 8, 9, 10, 11, |
| 93 | 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}; | 93 | 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}; |
| 94 | - std::vector<float> outHostData = {0, 0, 0, 0.0}; | 94 | + std::vector<float> outHostData(8, 0); |
| 95 | - std::vector<int32_t> indicesHostData = {0, 0, 0, 0}; | 95 | + std::vector<int32_t> indicesHostData(8, 0); |
| 96 | 96 | ||
| 97 | - //创建self aclTensor | 97 | + // 创建self aclTensor |
| 98 | ret = CreateAclTensor(selfHostData, selfShape, &selfDeviceAddr, aclDataType::ACL_FLOAT, &self); | 98 | ret = CreateAclTensor(selfHostData, selfShape, &selfDeviceAddr, aclDataType::ACL_FLOAT, &self); |
| 99 | CHECK_RET(ret == ACL_SUCCESS, return ret); | 99 | CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 100 | 100 | ||
| 101 | - //创建out aclTensor | 101 | + // 创建out aclTensor |
| 102 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); | 102 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); |
| 103 | CHECK_RET(ret == ACL_SUCCESS, return ret); | 103 | CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 104 | 104 | ||
| 105 | - //创建indices aclTensor | 105 | + // 创建indices aclTensor |
| 106 | ret = CreateAclTensor(indicesHostData, outShape, &indDeviceAddr, aclDataType::ACL_INT32, &indices); | 106 | ret = CreateAclTensor(indicesHostData, outShape, &indDeviceAddr, aclDataType::ACL_INT32, &indices); |
| 107 | CHECK_RET(ret == ACL_SUCCESS, return ret); | 107 | CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 108 | 108 | ||
| @@ -134,18 +134,22 @@ int main() | |||
| 134 | // 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改 | 134 | // 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改 |
| 135 | auto size = GetShapeSize(outShape); | 135 | auto size = GetShapeSize(outShape); |
| 136 | std::vector<float> outData(size, 0); | 136 | std::vector<float> outData(size, 0); |
| 137 | - std::vector<int64_t> indicesData(size, 0); | 137 | + std::vector<int32_t> indicesData(size, 0); |
| 138 | ret = aclrtMemcpy(outData.data(), outData.size() * sizeof(outData[0]), outDeviceAddr, size * sizeof(float), | 138 | ret = aclrtMemcpy(outData.data(), outData.size() * sizeof(outData[0]), outDeviceAddr, size * sizeof(float), |
| 139 | ACL_MEMCPY_DEVICE_TO_HOST); | 139 | ACL_MEMCPY_DEVICE_TO_HOST); |
| 140 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | 140 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); |
| 141 | ret = aclrtMemcpy(indicesData.data(), indicesData.size() * sizeof(indicesData[0]), indDeviceAddr, | 141 | ret = aclrtMemcpy(indicesData.data(), indicesData.size() * sizeof(indicesData[0]), indDeviceAddr, |
| 142 | - size * sizeof(int64_t), ACL_MEMCPY_DEVICE_TO_HOST); | 142 | + size * sizeof(int32_t), ACL_MEMCPY_DEVICE_TO_HOST); |
| 143 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | 143 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); |
| 144 | 144 | ||
| 145 | for (int64_t i = 0; i < size; i++) { | 145 | for (int64_t i = 0; i < size; i++) { |
| 146 | LOG_PRINT("out[%ld] is: %f\n", i, outData[i]); | 146 | LOG_PRINT("out[%ld] is: %f\n", i, outData[i]); |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | + for (int64_t i = 0; i < size; i++) { | ||
| 150 | + LOG_PRINT("indices[%ld] is: %d\n", i, indicesData[i]); | ||
| 151 | + } | ||
| 152 | + | ||
| 149 | // 6. 释放aclTensor,需要根据具体API的接口定义修改 | 153 | // 6. 释放aclTensor,需要根据具体API的接口定义修改 |
| 150 | aclDestroyTensor(self); | 154 | aclDestroyTensor(self); |
| 151 | aclDestroyTensor(out); | 155 | aclDestroyTensor(out); |
| @@ -164,4 +168,4 @@ int main() | |||
| 164 | aclFinalize(); | 168 | aclFinalize(); |
| 165 | 169 | ||
| 166 | return 0; | 170 | return 0; |
| 167 | -} | 171 | +} |