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

Class BenchmarkerBase

dnn/test/common/benchmarker.h:18–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16
17template <typename Opr, typename T, typename Proxy = OprProxy<Opr>>
18class BenchmarkerBase {
19public:
20 using Param = typename Opr::Param;
21 using TensorValueArray = TensorNDArray;
22 using BeforeExecCallback = std::function<void(Opr*, const TensorValueArray&)>;
23 using TensorsConstriant = std::function<void(TensorValueArray& tensors)>;
24
25 BenchmarkerBase(Handle* handle, T timer)
26 : m_timer(timer),
27 m_handle_naive(create_cpu_handle(2, false)),
28 m_handle(handle),
29 m_default_rng(new NormalRNG()),
30 m_param(Param()),
31 m_proxy{new Proxy()} {}
32
33 const Handle* handle() const { return m_handle; }
34
35 /*!
36 * \brief benchmark opr on current param/dtype/rng config
37 * \returns elapsed time in ms
38 *
39 * Benchmarker would construct TensorLayout vectors from shapes and
40 * dtypes and call exec(TensorLayoutArray &).
41 */
42 float exec(const TensorShapeArray& shapes) { return exec(make_layouts(shapes)); }
43 float exec(TensorLayoutArray layouts);
44
45 float exect(const TensorValueArray& testcase_in);
46
47 //! disabiguate overloaded exec
48 float execs(const TensorShapeArray& shapes) { return exec(shapes); }
49 float execl(const TensorLayoutArray& layouts) { return exec(layouts); }
50 BenchmarkerBase& set_param(Param param) {
51 m_param = param;
52 return *this;
53 }
54 BenchmarkerBase& set_dtype(size_t idx, DType dtype) {
55 m_dtype[idx] = dtype;
56 return *this;
57 }
58 BenchmarkerBase& set_rng(size_t idx, RNG* rng) {
59 m_rng[idx] = rng;
60 return *this;
61 }
62 BenchmarkerBase& set_fmt(size_t idx, TensorFormat fmt) {
63 m_fmt[idx] = fmt;
64 return *this;
65 }
66 BenchmarkerBase& set_tensors_constraint(
67 const TensorsConstriant& tensor_constraint) {
68 m_tensor_constraint = tensor_constraint;
69 return *this;
70 }
71 TensorLayoutArray make_layouts(const TensorShapeArray& shapes) {
72 TensorLayoutArray layouts(shapes.size());
73 for (size_t i = 0; i < shapes.size(); ++i) {
74 DType dt =
75 (m_dtype.find(i) != m_dtype.end() ? m_dtype[i] : dtype::Float32());

Callers

nothing calls this directly

Calls 1

resetMethod · 0.45

Tested by

no test coverage detected