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

Method check_matrix_mul

dnn/test/common/matrix_mul.cpp:164–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162
163template <typename Opr>
164void matrix_mul::check_matrix_mul(
165 DType A_dtype, DType B_dtype, DType C_dtype, Handle* handle,
166 const ExecutionPolicyAlgoName& algo, param::MatrixMul::Format format,
167 size_t nbase, float eps, std::vector<TestArg>&& user_args,
168 bool force_deduce_dst, param::MatrixMul::ComputeMode compute_mode) {
169 megdnn_assert(A_dtype.enumv() == B_dtype.enumv());
170 Checker<Opr> checker(handle);
171 checker.set_force_deduce_dst(force_deduce_dst);
172 if (!algo.name.empty()) {
173 checker.set_before_exec_callback(AlgoChecker<Opr>(algo));
174 }
175 std::unique_ptr<RNG> rng;
176 checker.set_epsilon(eps);
177 if (A_dtype.enumv() == DTypeEnum::Int8 ||
178 A_dtype.enumv() == DTypeEnum::QuantizedS8) {
179 //! use larger rng to check the overflow
180 rng = std::make_unique<UniformIntRNG>(-127, 127);
181 } else if (
182 A_dtype.enumv() == DTypeEnum::Uint8 ||
183 A_dtype.enumv() == DTypeEnum::Quantized8Asymm) {
184 rng = std::make_unique<NormalRNG>(128.f);
185 } else if (A_dtype.enumv() == DTypeEnum::Int16) {
186 rng = std::make_unique<UniformIntRNG>(-32767, 32767);
187 } else if (A_dtype.enumv() == DTypeEnum::Float16) {
188 rng = std::make_unique<NormalRNG>(2.f);
189 //! if fp16 not set eps, default 1e-3, we just set it to 1e-2
190 if (eps < 1e-2) {
191 checker.set_epsilon(1e-2);
192 }
193 }
194
195 if (rng) {
196 checker.set_rng(0, rng.get()).set_rng(1, rng.get());
197 }
198
199 //! return expect if stride == -1, stride otherwise
200 auto stride_val = [](size_t stride, size_t expect) -> size_t {
201 if (stride == TestArg::UNSET_STRIDE_VAL) {
202 return expect;
203 } else {
204 return stride;
205 }
206 };
207
208 constexpr static bool batched = std::is_same<Opr, megdnn::BatchedMatrixMul>::value;
209 using Param = MatrixMul::Param;
210 std::vector<TestArg> args;
211 if (user_args.empty()) {
212 if (format == param::MatrixMul::Format::DEFAULT) {
213 if (batched) {
214 args = matrix_mul::get_batched_matmul_args();
215 } else {
216 args = matrix_mul::get_matmul_args();
217 }
218
219 } else {
220 megdnn_assert(!batched, "BatchedMatrixMul does not support MK4/MK8");
221 args = matrix_mul::get_matmul_mk_packed_args(nbase);

Callers

nothing calls this directly

Calls 8

swapFunction · 0.85
set_dtypeMethod · 0.80
enumvMethod · 0.45
emptyMethod · 0.45
getMethod · 0.45
typeMethod · 0.45
execlMethod · 0.45
execsMethod · 0.45

Tested by

no test coverage detected