| 14 | namespace test { |
| 15 | |
| 16 | TEST_F(CUDA, BN_FORWARD_BACKWARD) { |
| 17 | using namespace batch_normalization; |
| 18 | using cuda::cudnn_handle; |
| 19 | using cuda::batch_normalization::BNTensorDescHolder; |
| 20 | using cuda::batch_normalization::get_reserve_size; |
| 21 | std::vector<TestArg> args = batch_normalization::get_args(); |
| 22 | Checker<BNForward> checker(handle_cuda()); |
| 23 | Checker<BNBackward> checker_bwd(handle_cuda()); |
| 24 | for (auto&& arg : args) { |
| 25 | auto tensor_desc = BNTensorDescHolder( |
| 26 | {arg.src, arg.dtype}, arg.param.param_dim, arg.param.fwd_mode); |
| 27 | auto reserve = get_reserve_size(cudnn_handle(handle_cuda()), tensor_desc); |
| 28 | // Forward |
| 29 | for (int i = 0; i < 9; ++i) { |
| 30 | checker.set_dtype(i, dtype::Float32()); |
| 31 | } |
| 32 | checker.set_dtype(0, arg.dtype); |
| 33 | checker.set_dtype(7, dtype::Byte()); |
| 34 | checker.set_dtype(8, arg.dtype); |
| 35 | checker.set_bypass(7); |
| 36 | checker.set_epsilon(1e-3).set_param(arg.param); |
| 37 | for (bool need_statistic : {false, true}) |
| 38 | checker.exec({ |
| 39 | arg.src, |
| 40 | arg.param_shape, // bn_scale |
| 41 | arg.param_shape, // bn_bias |
| 42 | need_statistic ? arg.param_shape : TensorShape({0}), // mean |
| 43 | need_statistic ? arg.param_shape : TensorShape({0}), // variance |
| 44 | arg.param_shape, // batch_mean |
| 45 | arg.param_shape, // batch_inv_variance |
| 46 | {reserve}, // reserve |
| 47 | arg.src // dst |
| 48 | }); |
| 49 | |
| 50 | // Backward |
| 51 | for (int i = 0; i < 9; ++i) { |
| 52 | checker_bwd.set_dtype(i, dtype::Float32()); |
| 53 | } |
| 54 | checker_bwd |
| 55 | .set_dtype(0, arg.dtype) // x |
| 56 | .set_dtype(1, arg.dtype) // dy |
| 57 | .set_dtype(5, dtype::Byte()) // reserve |
| 58 | .set_dtype(8, arg.dtype) // dx |
| 59 | .set_bypass(5); |
| 60 | checker_bwd.set_epsilon(1e-3).set_param(arg.param).exec( |
| 61 | {arg.src, |
| 62 | arg.src, |
| 63 | arg.param_shape, |
| 64 | arg.param_shape, |
| 65 | arg.param_shape, |
| 66 | {reserve}, |
| 67 | arg.param_shape, |
| 68 | arg.param_shape, |
| 69 | arg.src}); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | } // namespace test |
nothing calls this directly
no test coverage detected