| 19 | } |
| 20 | |
| 21 | void GroupNormForwardImpl::exec( |
| 22 | _megdnn_tensor_in data, _megdnn_tensor_in weight, _megdnn_tensor_in bias, |
| 23 | _megdnn_tensor_out dst, _megdnn_tensor_out mean, _megdnn_tensor_out rstd, |
| 24 | _megdnn_workspace workspace) { |
| 25 | check_exec( |
| 26 | data.layout, weight.layout, bias.layout, dst.layout, mean.layout, |
| 27 | rstd.layout, workspace.size); |
| 28 | |
| 29 | auto p = param(); |
| 30 | float eps = p.eps; |
| 31 | int group = p.group; |
| 32 | bool affine = p.affine; |
| 33 | auto layout = data.layout; |
| 34 | size_t N, C, H, W, imsize; |
| 35 | N = layout.shape[0]; |
| 36 | C = layout.shape[1]; |
| 37 | H = layout.shape[2]; |
| 38 | W = layout.shape[3]; |
| 39 | imsize = H * W; |
| 40 | |
| 41 | auto stream = cuda_stream(handle()); |
| 42 | using namespace ::megdnn::cuda::group_norm; |
| 43 | auto wbundle = |
| 44 | get_workspace_bundle(N, group, rstd.layout.dtype.size(), workspace.raw_ptr); |
| 45 | |
| 46 | #define cb(DType) \ |
| 47 | if (data.layout.dtype == DType()) { \ |
| 48 | using T = typename DTypeTrait<DType>::ctype; \ |
| 49 | using T_ACC = float; \ |
| 50 | T_ACC* temp_rstd = wbundle.get_workspace(0).ptr<T_ACC>(); \ |
| 51 | forward<T, T_ACC>( \ |
| 52 | data.ptr<T>(), affine ? weight.ptr<T>() : nullptr, \ |
| 53 | affine ? bias.ptr<T>() : nullptr, dst.ptr<T>(), mean.ptr<T_ACC>(), \ |
| 54 | rstd.ptr<T_ACC>(), temp_rstd, static_cast<T_ACC>(eps), \ |
| 55 | static_cast<int>(group), static_cast<int>(N), static_cast<int>(C), \ |
| 56 | static_cast<int>(W), static_cast<int>(imsize), stream); \ |
| 57 | return; \ |
| 58 | } |
| 59 | MEGDNN_FOREACH_COMPUTING_DTYPE_FLOAT(cb) |
| 60 | #undef cb |
| 61 | megdnn_throw("bad dtype"); |
| 62 | } |
| 63 | |
| 64 | size_t GroupNormBackwardImpl::get_workspace_in_bytes( |
| 65 | const TensorLayout&, const TensorLayout& data, const TensorLayout&, |
nothing calls this directly
no test coverage detected