| 238 | |
| 239 | template <typename T> |
| 240 | void 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 | |
| 270 | template <typename T> |
| 271 | void run_shuffle(Handle* handle, bool bwd_flag) { |
nothing calls this directly
no test coverage detected