已合并
fix: 初始化random_num_task样例counter(#827) #4295
fix: 初始化random_num_task样例counter(#827) #4295
已合并
jiaxingru创建于 25 天前
1 个文件变更+6-4
@@ -73,9 +73,11 @@ int main()
73 // 准备 Host 数据73 // 准备 Host 数据
74 auto hostOutput = std::unique_ptr<void, decltype(&free)>(malloc(size), free);74 auto hostOutput = std::unique_ptr<void, decltype(&free)>(malloc(size), free);
75 75 
76- // 申请存放随机数状态 counter 的device内存 (要求 16Byte)76+ // 申请并初始化存放随机数状态 counter 的 Device 内存(要求 16 Byte)
77- void* counterAddr = NULL;77+ constexpr size_t kCounterSize = 16U;
78- CHECK_ERROR(aclrtMalloc((void**)&counterAddr, 16, ACL_MEM_MALLOC_HUGE_FIRST));78+ void* counterAddr = nullptr;
79+ CHECK_ERROR(aclrtMalloc(&counterAddr, kCounterSize, ACL_MEM_MALLOC_HUGE_FIRST));
80+ CHECK_ERROR(aclrtMemset(counterAddr, kCounterSize, 0, kCounterSize));
79 81 
80 printf("Gen normal distribution random num, data type: float \n");82 printf("Gen normal distribution random num, data type: float \n");
81 float mean = 3.0;83 float mean = 3.0;
@@ -421,4 +423,4 @@ aclError DropoutBitmask(
421 taskInfo.randomNum.size = sizeof(uint64_t);423 taskInfo.randomNum.size = sizeof(uint64_t);
422 taskInfo.randomNum.isAddr = 0;424 taskInfo.randomNum.isAddr = 0;
423 return aclrtRandomNumAsync(&taskInfo, stream, NULL);425 return aclrtRandomNumAsync(&taskInfo, stream, NULL);
424-}426+}