| 268 | |
| 269 | template <typename dtype> |
| 270 | void run_permutation(Handle* handle) { |
| 271 | using ctype = typename DTypeTrait<dtype>::ctype; |
| 272 | size_t sample_num = |
| 273 | std::min(200000, static_cast<int>(DTypeTrait<dtype>::max()) - 10); |
| 274 | #ifdef __ANDROID__ |
| 275 | //! Android NDK25c has a bug, sample_num will make malloc OOM |
| 276 | //! so we reduce the sample_num when dtype is float32 |
| 277 | if (std::is_same_v<megdnn::dtype::Float32, dtype>) { |
| 278 | sample_num = 200000; |
| 279 | } |
| 280 | #endif |
| 281 | |
| 282 | auto opr = handle->create_operator<PermutationRNG>(); |
| 283 | opr->param().dtype = DTypeTrait<dtype>::enumv; |
| 284 | TensorLayout ly{TensorShape{sample_num}, dtype()}; |
| 285 | Tensor<ctype> t(handle, ly); |
| 286 | opr->exec(t.tensornd(), {}); |
| 287 | |
| 288 | auto ptr = t.ptr(); |
| 289 | auto size = t.layout().total_nr_elems(); |
| 290 | |
| 291 | std::vector<ctype> res(size); |
| 292 | int not_same = 0; |
| 293 | for (size_t i = 0; i < size; ++i) { |
| 294 | if ((ptr[i] - ctype(i)) >= 1) |
| 295 | not_same++; |
| 296 | res[i] = ptr[i]; |
| 297 | } |
| 298 | ASSERT_GT(not_same, 5000); |
| 299 | std::sort(res.begin(), res.end()); |
| 300 | for (size_t i = 0; i < size; ++i) { |
| 301 | ASSERT_LE(std::abs(res[i] - ctype(i)), 1e-8); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | template <typename T> |
| 306 | void run_shuffle(Handle* handle, bool bwd_flag) { |
nothing calls this directly
no test coverage detected