| 44 | } |
| 45 | |
| 46 | CondTakeImpl::Output CondTakeImpl::exec( |
| 47 | _megdnn_tensor_in data, _megdnn_tensor_in mask, _megdnn_workspace workspace, |
| 48 | DynOutMallocPolicyCall malloc_policy) { |
| 49 | #if !MGE_BUILD_WITHOUT_NAIVE_EXEC |
| 50 | auto size = check_exec_get_size(data.layout, mask.layout, workspace.size); |
| 51 | auto idx_tmp = workspace.ptr<dt_int32>(); |
| 52 | |
| 53 | switch (mask.layout.dtype.enumv()) { |
| 54 | #define cb(_dt) \ |
| 55 | case DTypeTrait<_dt>::enumv: { \ |
| 56 | using ctype = DTypeTrait<_dt>::ctype; \ |
| 57 | dispatch_genidx<ctype>(size, idx_tmp, mask); \ |
| 58 | break; \ |
| 59 | } |
| 60 | MEGDNN_FOREACH_COMPUTING_DTYPE(cb) |
| 61 | cb(::megdnn::dtype::Bool) |
| 62 | #undef cb |
| 63 | default : megdnn_throw("bad mask dtype"); |
| 64 | } |
| 65 | |
| 66 | static_cast<HandleImpl*>(handle())->megcore_dispatcher()->sync(); |
| 67 | size_t out_size = idx_tmp[size]; |
| 68 | auto out_data = malloc_policy.alloc_output(0, data.layout.dtype, {out_size}); |
| 69 | auto out_idx = malloc_policy.alloc_output(1, dtype::Int32(), {out_size}); |
| 70 | |
| 71 | switch (data.layout.dtype.enumv()) { |
| 72 | #define cb(_dt) \ |
| 73 | case DTypeTrait<_dt>::enumv: { \ |
| 74 | using ctype = DTypeTrait<_dt>::ctype; \ |
| 75 | MEGDNN_DISPATCH_CPU_KERN_OPR(copy_data<ctype>( \ |
| 76 | out_size, out_idx.ptr<dt_int32>(), out_data.ptr<ctype>(), idx_tmp, \ |
| 77 | data.ptr<ctype>())); \ |
| 78 | break; \ |
| 79 | } |
| 80 | MEGDNN_FOREACH_COMPUTING_DTYPE(cb) |
| 81 | cb(::megdnn::dtype::Bool) |
| 82 | #undef cb |
| 83 | default : megdnn_throw("bad data dtype"); |
| 84 | } |
| 85 | |
| 86 | return {{out_data, out_idx}}; |
| 87 | #else |
| 88 | __builtin_trap(); |
| 89 | return {}; |
| 90 | #endif |
| 91 | } |
| 92 | |
| 93 | template <typename ctype> |
| 94 | void CondTakeImpl::dispatch_genidx(size_t size, dt_int32* dest, const TensorND& mask) { |
nothing calls this directly
no test coverage detected