MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / run_permutation

Function run_permutation

dnn/test/naive/rng.cpp:270–303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268
269template <typename dtype>
270void 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
305template <typename T>
306void run_shuffle(Handle* handle, bool bwd_flag) {

Callers

nothing calls this directly

Calls 12

maxFunction · 0.85
sortFunction · 0.85
minFunction · 0.50
absFunction · 0.50
paramMethod · 0.45
execMethod · 0.45
tensorndMethod · 0.45
ptrMethod · 0.45
total_nr_elemsMethod · 0.45
layoutMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected