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

Function run_permutation

dnn/test/cuda/rng.cpp:240–268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238
239template <typename T>
240void run_permutation(Handle* handle) {
241 using ctype = typename DTypeTrait<T>::ctype;
242 size_t sample_num = std::min(200000, static_cast<int>(DTypeTrait<T>::max()) - 10);
243
244 auto opr = handle->create_operator<PermutationRNG>();
245 opr->param().dtype = DTypeTrait<T>::enumv;
246 TensorLayout ly{TensorShape{sample_num}, T()};
247 Tensor<dt_byte> workspace(
248 handle, {TensorShape{opr->get_workspace_in_bytes(ly)}, dtype::Byte()});
249 SyncedTensor<ctype> t(handle, ly);
250
251 opr->exec(t.tensornd_dev(), {workspace.ptr(), workspace.layout().total_nr_elems()});
252
253 auto ptr = t.ptr_mutable_host();
254 auto size = t.layout().total_nr_elems();
255
256 std::vector<ctype> res(size);
257 int not_same = 0;
258 for (size_t i = 0; i < size; ++i) {
259 if ((ptr[i] - ctype(i)) >= ctype(1))
260 not_same++;
261 res[i] = ptr[i];
262 }
263 ASSERT_GT(not_same, 5000);
264 std::sort(res.begin(), res.end());
265 for (size_t i = 0; i < size; ++i) {
266 ASSERT_LE(std::abs(res[i] - ctype(i)), 1e-8);
267 }
268}
269
270template <typename T>
271void run_shuffle(Handle* handle, bool bwd_flag) {

Callers

nothing calls this directly

Calls 13

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

Tested by

no test coverage detected