已合并
StatelessRandom delete CheckFromToRange #3062
zhaozi3创建于 6月1日
StatelessRandom delete CheckFromToRange #3062
已合并
zhaozi3创建于 6月1日
14 个文件变更+33-122
@@ -303,7 +303,7 @@ int main() {
303 float mean = 2.;303 float mean = 2.;
304 float std = 1.;304 float std = 1.;
305 int64_t seed = 1;305 int64_t seed = 1;
306- int64_t offset = 2;306+ int64_t offset = 0;
307 void* selfDeviceAddr = nullptr;307 void* selfDeviceAddr = nullptr;
308 aclTensor* selfRef = nullptr;308 aclTensor* selfRef = nullptr;
309 std::vector<float> selfHostData = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};309 std::vector<float> selfHostData = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
@@ -318,7 +318,7 @@ int main() {
318 aclTensor* seed = nullptr;318 aclTensor* seed = nullptr;
319 void* offsetDeviceAddr = nullptr;319 void* offsetDeviceAddr = nullptr;
320 aclTensor* offset = nullptr;320 aclTensor* offset = nullptr;
321- int64_t offset2 = 102;321+ int64_t offset2 = 100;
322 void* selfDeviceAddr = nullptr;322 void* selfDeviceAddr = nullptr;
323 aclTensor* selfRef = nullptr;323 aclTensor* selfRef = nullptr;
324 std::vector<float> selfHostData = {0.0, 0.0, 0.0, 0.0};324 std::vector<float> selfHostData = {0.0, 0.0, 0.0, 0.0};
@@ -78,7 +78,7 @@ int main() {
78 float mean = 2.;78 float mean = 2.;
79 float std = 1.;79 float std = 1.;
80 int64_t seed = 1;80 int64_t seed = 1;
81- int64_t offset = 2;81+ int64_t offset = 0;
82 void* selfDeviceAddr = nullptr;82 void* selfDeviceAddr = nullptr;
83 aclTensor* selfRef = nullptr;83 aclTensor* selfRef = nullptr;
84 std::vector<float> selfHostData = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};84 std::vector<float> selfHostData = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
@@ -83,7 +83,7 @@ int main() {
83 aclTensor* seed = nullptr;83 aclTensor* seed = nullptr;
84 void* offsetDeviceAddr = nullptr;84 void* offsetDeviceAddr = nullptr;
85 aclTensor* offset = nullptr;85 aclTensor* offset = nullptr;
86- int64_t offset2 = 102;86+ int64_t offset2 = 100;
87 void* selfDeviceAddr = nullptr;87 void* selfDeviceAddr = nullptr;
88 aclTensor* selfRef = nullptr;88 aclTensor* selfRef = nullptr;
89 std::vector<float> selfHostData = {0.0, 0.0, 0.0, 0.0};89 std::vector<float> selfHostData = {0.0, 0.0, 0.0, 0.0};
@@ -225,10 +225,9 @@ aclnnStatus aclnnInplaceRandom(
225 225 
226- 确定性计算:226- 确定性计算:
227 - aclnnInplaceRandom默认确定性实现。227 - aclnnInplaceRandom默认确定性实现。
228-- 参数范围228+- <term>Ascend 950PR/Ascend 950DT</term>
229- - offset4的倍数。229+ - offset必须为4的倍数。
230- - from < to。230+ - from必须小于to,且from/to指定范围不可超出self数据类型的范围
231- - from/to指定范围不可超出self数据类型的范围。
232 231 
233## 调用示例232## 调用示例
234 233 
@@ -233,10 +233,9 @@ aclnnStatus aclnnInplaceRandomTensor(
233 233 
234- 确定性计算:234- 确定性计算:
235 - aclnnInplaceRandomTensor默认确定性实现。235 - aclnnInplaceRandomTensor默认确定性实现。
236-- 参数范围236+- <term>Ascend 950PR/Ascend 950DT</term>
237- - offset4的倍数。237+ - offset必须为4的倍数。
238- - from < to。238+ - from必须小于to,且from/to指定范围不可超出self数据类型的范围
239- - from/to指定范围不可超出self数据类型的范围。
240 239 
241## 调用示例240## 调用示例
242 241 
@@ -320,7 +319,7 @@ int main() {
320 aclTensor* seed = nullptr;319 aclTensor* seed = nullptr;
321 void* offsetDeviceAddr = nullptr;320 void* offsetDeviceAddr = nullptr;
322 aclTensor* offset = nullptr;321 aclTensor* offset = nullptr;
323- int64_t offset2 = 102;322+ int64_t offset2 = 100;
324 std::vector<float> selfHostData = {1, 2, 3, 4, 5, 6, 7, 8};323 std::vector<float> selfHostData = {1, 2, 3, 4, 5, 6, 7, 8};
325 std::vector<int64_t> seedHostData = {0};324 std::vector<int64_t> seedHostData = {0};
326 std::vector<int64_t> offsetHostData = {392};325 std::vector<int64_t> offsetHostData = {392};
@@ -196,8 +196,8 @@ aclnnStatus aclnnInplaceRandomWithoutFromTo(
196 196 
197- 确定性计算:197- 确定性计算:
198 - aclnnInplaceRandomWithoutFromTo默认确定性实现。198 - aclnnInplaceRandomWithoutFromTo默认确定性实现。
199-- 参数范围199+- <term>Ascend 950PR/Ascend 950DT</term>
200- - offset4的倍数。200+ - offset必须为4的倍数。
201 201 
202## 调用示例202## 调用示例
203 203 
@@ -206,8 +206,8 @@ aclnnStatus aclnnInplaceRandomWithoutFromToTensor(
206 206 
207- 确定性计算:207- 确定性计算:
208 - aclnnInplaceRandomWithoutFromToTensor默认确定性实现。208 - aclnnInplaceRandomWithoutFromToTensor默认确定性实现。
209-- 参数范围209+- <term>Ascend 950PR/Ascend 950DT</term>
210- - offset4的倍数。210+ - offset必须为4的倍数。
211 211 
212## 调用示例212## 调用示例
213 213 
@@ -291,7 +291,7 @@ int main() {
291 aclTensor* seed = nullptr;291 aclTensor* seed = nullptr;
292 void* offsetDeviceAddr = nullptr;292 void* offsetDeviceAddr = nullptr;
293 aclTensor* offset = nullptr;293 aclTensor* offset = nullptr;
294- int64_t offset2 = 102;294+ int64_t offset2 = 100;
295 std::vector<float> selfHostData = {1, 2, 3, 4, 5, 6, 7, 8};295 std::vector<float> selfHostData = {1, 2, 3, 4, 5, 6, 7, 8};
296 std::vector<int64_t> seedHostData = {0};296 std::vector<int64_t> seedHostData = {0};
297 std::vector<int64_t> offsetHostData = {392};297 std::vector<int64_t> offsetHostData = {392};
@@ -324,7 +324,7 @@ int main() {
324 aclTensor* seed = nullptr;324 aclTensor* seed = nullptr;
325 void* offsetDeviceAddr = nullptr;325 void* offsetDeviceAddr = nullptr;
326 aclTensor* offset = nullptr;326 aclTensor* offset = nullptr;
327- int64_t offset2 = 102;327+ int64_t offset2 = 100;
328 std::vector<float> selfRefHostData = {0, 0, 0, 0};328 std::vector<float> selfRefHostData = {0, 0, 0, 0};
329 std::vector<int64_t> seedHostData = {0};329 std::vector<int64_t> seedHostData = {0};
330 std::vector<int64_t> offsetHostData = {392};330 std::vector<int64_t> offsetHostData = {392};
@@ -85,7 +85,7 @@ int main() {
85 aclTensor* seed = nullptr;85 aclTensor* seed = nullptr;
86 void* offsetDeviceAddr = nullptr;86 void* offsetDeviceAddr = nullptr;
87 aclTensor* offset = nullptr;87 aclTensor* offset = nullptr;
88- int64_t offset2 = 102;88+ int64_t offset2 = 100;
89 std::vector<float> selfHostData = {1, 2, 3, 4, 5, 6, 7, 8};89 std::vector<float> selfHostData = {1, 2, 3, 4, 5, 6, 7, 8};
90 std::vector<int64_t> seedHostData = {0};90 std::vector<int64_t> seedHostData = {0};
91 std::vector<int64_t> offsetHostData = {392};91 std::vector<int64_t> offsetHostData = {392};
@@ -87,7 +87,7 @@ int main() {
87 aclTensor* seed = nullptr;87 aclTensor* seed = nullptr;
88 void* offsetDeviceAddr = nullptr;88 void* offsetDeviceAddr = nullptr;
89 aclTensor* offset = nullptr;89 aclTensor* offset = nullptr;
90- int64_t offset2 = 102;90+ int64_t offset2 = 100;
91 std::vector<float> selfRefHostData = {0, 0, 0, 0};91 std::vector<float> selfRefHostData = {0, 0, 0, 0};
92 std::vector<int64_t> seedHostData = {0};92 std::vector<int64_t> seedHostData = {0};
93 std::vector<int64_t> offsetHostData = {392};93 std::vector<int64_t> offsetHostData = {392};
@@ -138,6 +138,8 @@ static const std::initializer_list<op::DataType> INT_DTYPE_LIST = {op::DataType:
138 op::DataType::DT_INT16, op::DataType::DT_INT8,138 op::DataType::DT_INT16, op::DataType::DT_INT8,
139 op::DataType::DT_UINT8, op::DataType::DT_BOOL};139 op::DataType::DT_UINT8, op::DataType::DT_BOOL};
140 140 
141+static const std::initializer_list<op::DataType> FLOAT_DTYPE_LIST = {op::DataType::DT_FLOAT,
142+ op::DataType::DT_FLOAT16, op::DataType::DT_BF16};
141static bool CheckNotNull(const aclTensor* selfRef)143static bool CheckNotNull(const aclTensor* selfRef)
142{144{
143 OP_CHECK_NULL(selfRef, return false);145 OP_CHECK_NULL(selfRef, return false);
@@ -157,66 +159,8 @@ static bool CheckShape(const aclTensor* selfRef)
157 return true;159 return true;
158}160}
159 161 
160-static bool CheckFromToRange(int64_t from, int64_t to, op::DataType dtype)162+static bool CheckFromToRange(int64_t from, int64_t to)
161{163{
162- int64_t dtypeMin = 0;
163- int64_t dtypeMax = 0;
164- 
165- switch (dtype) {
166- case op::DataType::DT_INT8:
167- dtypeMin = static_cast<int64_t>(std::numeric_limits<int8_t>::min());
168- dtypeMax = static_cast<int64_t>(std::numeric_limits<int8_t>::max());
169- break;
170- case op::DataType::DT_UINT8:
171- dtypeMin = static_cast<int64_t>(std::numeric_limits<uint8_t>::min());
172- dtypeMax = static_cast<int64_t>(std::numeric_limits<uint8_t>::max());
173- break;
174- case op::DataType::DT_INT16:
175- dtypeMin = static_cast<int64_t>(std::numeric_limits<int16_t>::min());
176- dtypeMax = static_cast<int64_t>(std::numeric_limits<int16_t>::max());
177- break;
178- case op::DataType::DT_INT32:
179- dtypeMin = static_cast<int64_t>(std::numeric_limits<int32_t>::min());
180- dtypeMax = static_cast<int64_t>(std::numeric_limits<int32_t>::max());
181- break;
182- case op::DataType::DT_INT64:
183- dtypeMin = static_cast<int64_t>(std::numeric_limits<int64_t>::min());
184- dtypeMax = static_cast<int64_t>(std::numeric_limits<int64_t>::max());
185- break;
186- case op::DataType::DT_FLOAT:
187- dtypeMin = -(1L << std::numeric_limits<float>::digits);
188- dtypeMax = (1L << std::numeric_limits<float>::digits);
189- break;
190- case op::DataType::DT_FLOAT16:
191- dtypeMin = -(1L << FLOAT16_DIGITS);
192- dtypeMax = (1L << FLOAT16_DIGITS);
193- break;
194- case op::DataType::DT_BF16:
195- dtypeMin = -(1L << BF16_DIGITS);
196- dtypeMax = (1L << BF16_DIGITS);
197- break;
198- case op::DataType::DT_BOOL:
199- dtypeMin = 0;
200- dtypeMax = 1;
201- break;
202- default:
203- dtypeMin = static_cast<int64_t>(std::numeric_limits<int64_t>::min());
204- dtypeMax = static_cast<int64_t>(std::numeric_limits<int64_t>::max());
205- break;
206- }
207- 
208- if (from < dtypeMin || from > dtypeMax) {
209- OP_LOGE(ACLNN_ERR_PARAM_INVALID, "from value %ld is out of valid range [%ld, %ld] for dtype %d", from,
210- dtypeMin, dtypeMax, static_cast<int>(dtype));
211- return false;
212- }
213- 
214- if (to <= dtypeMin || to - 1 > dtypeMax) {
215- OP_LOGE(ACLNN_ERR_PARAM_INVALID, "to value %ld is out of valid range (%ld, %lu] for dtype %d", to,
216- dtypeMin, static_cast<uint64_t>(dtypeMax) + 1, static_cast<int>(dtype));
217- return false;
218- }
219- 
220 if (from >= to) {164 if (from >= to) {
221 OP_LOGE(ACLNN_ERR_PARAM_INVALID, "from %ld must be less than to %ld.", from, to);165 OP_LOGE(ACLNN_ERR_PARAM_INVALID, "from %ld must be less than to %ld.", from, to);
222 return false;166 return false;
@@ -242,6 +186,11 @@ static inline bool CheckSocVersionIsSupportDSA(void)
242 186 
243static const aclTensor* CastProcess(const aclTensor* selfRef, const aclTensor* computeOut, aclOpExecutor* executor)187static const aclTensor* CastProcess(const aclTensor* selfRef, const aclTensor* computeOut, aclOpExecutor* executor)
244{188{
189+ auto curArch = GetCurrentPlatformInfo().GetCurNpuArch();
190+ if (IsRegBase(curArch) && CheckType(selfRef->GetDataType(), FLOAT_DTYPE_LIST)) {
191+ return computeOut;
192+ }
193+ 
245 if (!CheckType(selfRef->GetDataType(), INT_DTYPE_LIST)) {194 if (!CheckType(selfRef->GetDataType(), INT_DTYPE_LIST)) {
246 auto castResultInt64 = l0op::Cast(computeOut, op::DataType::DT_INT64, executor);195 auto castResultInt64 = l0op::Cast(computeOut, op::DataType::DT_INT64, executor);
247 CHECK_RET(castResultInt64 != nullptr, nullptr);196 CHECK_RET(castResultInt64 != nullptr, nullptr);
@@ -363,7 +312,8 @@ aclnnStatus aclnnInplaceRandomGetWorkspaceSize(
363 L2_DFX_PHASE_1(aclnnInplaceRandom, DFX_IN(selfRef, from, to, seed, offset), DFX_OUT(selfRef));312 L2_DFX_PHASE_1(aclnnInplaceRandom, DFX_IN(selfRef, from, to, seed, offset), DFX_OUT(selfRef));
364 auto ret = CheckParams(selfRef);313 auto ret = CheckParams(selfRef);
365 CHECK_RET(ret == ACLNN_SUCCESS, ret);314 CHECK_RET(ret == ACLNN_SUCCESS, ret);
366- CHECK_RET(CheckFromToRange(from, to, selfRef->GetDataType()), ACLNN_ERR_PARAM_INVALID);315+ CHECK_RET(CheckFromToRange(from, to), ACLNN_ERR_PARAM_INVALID);
316+
367 auto uniqueExecutor = CREATE_EXECUTOR();317 auto uniqueExecutor = CREATE_EXECUTOR();
368 CHECK_RET(uniqueExecutor.get() != nullptr, ACLNN_ERR_INNER_CREATE_EXECUTOR);318 CHECK_RET(uniqueExecutor.get() != nullptr, ACLNN_ERR_INNER_CREATE_EXECUTOR);
369 319 
@@ -429,7 +379,7 @@ aclnnStatus aclnnInplaceRandomTensorGetWorkspaceSize(
429 379 
430 auto ret = CheckParams(selfRef);380 auto ret = CheckParams(selfRef);
431 CHECK_RET(ret == ACLNN_SUCCESS, ret);381 CHECK_RET(ret == ACLNN_SUCCESS, ret);
432- CHECK_RET(CheckFromToRange(from, to, selfRef->GetDataType()), ACLNN_ERR_PARAM_INVALID);382+ CHECK_RET(CheckFromToRange(from, to), ACLNN_ERR_PARAM_INVALID);
433 auto uniqueExecutor = CREATE_EXECUTOR();383 auto uniqueExecutor = CREATE_EXECUTOR();
434 CHECK_RET(uniqueExecutor.get() != nullptr, ACLNN_ERR_INNER_CREATE_EXECUTOR);384 CHECK_RET(uniqueExecutor.get() != nullptr, ACLNN_ERR_INNER_CREATE_EXECUTOR);
435 385 
@@ -91,7 +91,9 @@
91 91 
92## 约束说明92## 约束说明
93 93 
94-94+ - offset是4的倍数。
95+ - 输出张量维度支持0~8维
96+ - from必须小于to, from/to指定范围不可超出self数据类型的范围。
95 97 
96## 调用说明98## 调用说明
97 99 
@@ -85,35 +85,6 @@ static void GetMinAndMaxByDtype(ge::DataType dtype, int64_t& dtypeMin, int64_t&
85 }85 }
86}86}
87 87 
88-static ge::graphStatus CheckFromToRange(gert::TilingContext* context, int64_t from, int64_t to, ge::DataType dtype)
89-{
90- int64_t dtypeMin = 0;
91- int64_t dtypeMax = 0;
92- 
93- GetMinAndMaxByDtype(dtype, dtypeMin, dtypeMax);
94- 
95- if (from < dtypeMin || from > dtypeMax) {
96- OP_LOGE(
97- context->GetNodeName(), "from value %ld is out of valid range [%ld, %ld] for dtype %d", from, dtypeMin,
98- dtypeMax, static_cast<int>(dtype));
99- return ge::GRAPH_FAILED;
100- }
101- 
102- if (to <= dtypeMin || to - 1 > dtypeMax) {
103- OP_LOGE(
104- context->GetNodeName(), "to value %ld is out of valid range (%ld, %lu] for dtype %d", to, dtypeMin,
105- static_cast<uint64_t>(dtypeMax) + 1, static_cast<int>(dtype));
106- return ge::GRAPH_FAILED;
107- }
108- 
109- if (to <= from) {
110- OP_LOGE(context->GetNodeName(), "from(%ld) must be less than to(%ld).", from, to);
111- return ge::GRAPH_FAILED;
112- }
113- 
114- return ge::GRAPH_SUCCESS;
115-}
116- 
117OpTilingConfig StatelessRandomTiling::BuildOpConfig()88OpTilingConfig StatelessRandomTiling::BuildOpConfig()
118{89{
119 OpTilingConfig config;90 OpTilingConfig config;
@@ -195,27 +166,23 @@ ge::graphStatus StatelessRandomTiling::UniqueProcess()
195 int64_t dtypeMin = 0;166 int64_t dtypeMin = 0;
196 int64_t dtypeMax = 0;167 int64_t dtypeMax = 0;
197 int64_t from = 0;168 int64_t from = 0;
198- int64_t to = 0;
199 uint64_t range = 0;169 uint64_t range = 0;
200 auto fromTensor = context_->GetOptionalInputTensor(INPUT_IDX_FROM);170 auto fromTensor = context_->GetOptionalInputTensor(INPUT_IDX_FROM);
201 auto toTensor = context_->GetOptionalInputTensor(INPUT_IDX_TO);171 auto toTensor = context_->GetOptionalInputTensor(INPUT_IDX_TO);
202 if ((fromTensor == nullptr) && (toTensor == nullptr)) {172 if ((fromTensor == nullptr) && (toTensor == nullptr)) {
203 GetMinAndMaxByDtype(outputDtype, dtypeMin, dtypeMax);173 GetMinAndMaxByDtype(outputDtype, dtypeMin, dtypeMax);
204 from = 0;174 from = 0;
205- to = dtypeMax;
206 range = static_cast<uint64_t>(dtypeMax) + 1;175 range = static_cast<uint64_t>(dtypeMax) + 1;
207 } else if (fromTensor == nullptr) {176 } else if (fromTensor == nullptr) {
208 auto toData = toTensor->GetData<int64_t>();177 auto toData = toTensor->GetData<int64_t>();
209 OP_CHECK_NULL_WITH_CONTEXT(context_, toData);178 OP_CHECK_NULL_WITH_CONTEXT(context_, toData);
210 from = 0;179 from = 0;
211- to = toData[0];
212 range = toData[0];180 range = toData[0];
213 } else if (toTensor == nullptr) {181 } else if (toTensor == nullptr) {
214 GetMinAndMaxByDtype(outputDtype, dtypeMin, dtypeMax);182 GetMinAndMaxByDtype(outputDtype, dtypeMin, dtypeMax);
215 auto fromData = fromTensor->GetData<int64_t>();183 auto fromData = fromTensor->GetData<int64_t>();
216 OP_CHECK_NULL_WITH_CONTEXT(context_, fromData);184 OP_CHECK_NULL_WITH_CONTEXT(context_, fromData);
217 from = fromData[0];185 from = fromData[0];
218- to = dtypeMax;
219 range = static_cast<uint64_t>(dtypeMax) + 1 - fromData[0];186 range = static_cast<uint64_t>(dtypeMax) + 1 - fromData[0];
220 } else {187 } else {
221 auto fromData = fromTensor->GetData<int64_t>();188 auto fromData = fromTensor->GetData<int64_t>();
@@ -223,15 +190,9 @@ ge::graphStatus StatelessRandomTiling::UniqueProcess()
223 auto toData = toTensor->GetData<int64_t>();190 auto toData = toTensor->GetData<int64_t>();
224 OP_CHECK_NULL_WITH_CONTEXT(context_, toData);191 OP_CHECK_NULL_WITH_CONTEXT(context_, toData);
225 from = fromData[0];192 from = fromData[0];
226- to = toData[0];
227 range = toData[0] - fromData[0];193 range = toData[0] - fromData[0];
228 }194 }
229 195 
230- auto ret = CheckFromToRange(context_, from, to, outputDtype);
231- if (ret != ge::GRAPH_SUCCESS) {
232- OP_LOGE(context_->GetNodeName(), "from %ld or to %ld is bounds for dtype(%d)", from, to, outputDtype);
233- return ge::GRAPH_FAILED;
234- }
235 simtTilingData_.from = from;196 simtTilingData_.from = from;
236 simtTilingData_.range = range;197 simtTilingData_.range = range;
237 simtTilingData_.extraInt64Param1 = config_.unrollFactor;198 simtTilingData_.extraInt64Param1 = config_.unrollFactor;