This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
add op C++ benchmark test framework(matmul, elementwise_add op benchmark test) #284
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
add op C++ benchmark test framework(matmul, elementwise_add op benchmark test)(#271)
OpBenchmarkTester is the basic class to test the benchmark of op. It can test the op benchmark with default strategy or specific compute and schedule. You should feed it registered op_name, input_shapes and out_types.
e.g.:
default:
TEST(test_matmul, default) {
int M = 1024;
int N = 1024;
int K = 1024;
std::vector<std::vector> input_shapes{{M, K}, {K, N}};
std::string op_name = "matmul";
hlir::framework::NodeAttr attrs;
OpBenchmarkTester matmul_tester(op_name, input_shapes);
std::vector type{Float(32)};
matmul_tester.TestOp("matmul_default", attrs, type);
}
if you want to define specfic stragegy, you can inherit the OpBenchmarkTester class and overide the "CreateSpecificStrategy" funtion which depicts the out tensors' compute and stages. Then invoke TestOp function with the fourth arg set to be 'false' which indicates not to use the default stragegy.
e.g.
class MatmulTester : public OpBenchmarkTester {
public:
MatmulTester(const std::string &op_name,
const std::vector<std::vector> &input_shapes,
const common::Target &target = common::DefaultHostTarget(),
int repeat = 10,
float diff = 1e-5)
: OpBenchmarkTester(op_name, input_shapes, target, repeat, diff) {}
std::vectorir::Tensor CreateSpecificStrategy(const std::vectorir::Tensor &inputs,
poly::StageMap *stages) override;
};
TEST(test_matmul, tile) {
int M = 1024;
int N = 1024;
int K = 1024;
std::vector<std::vector> input_shapes{{M, K}, {K, N}};
std::string op_name = "matmul";
hlir::framework::NodeAttr attrs;
MatmulTileTester matmul_tester(op_name, input_shapes);
std::vector type{Float(32)};
matmul_tester.TestOp("matmul_tile", attrs, type, false);
}
the benchmark result will be showed in the log temporily as follows:
I1109 07:31:30.700934 154627 test_utils.cc:27] Testing elementwise_add_default
I1109 07:31:30.701002 154627 test_utils.cc:34] repeat times: 10, kernel run time: 0.0043922 ms