Skip to content
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

Merged
merged 1 commit into from
Nov 10, 2020

Conversation

wenming2014
Copy link
Collaborator

@wenming2014 wenming2014 commented Nov 9, 2020

add op C++ benchmark test framework(matmul, elementwise_add op benchmark test)(#271

  1. 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);
    }

  2. 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);
    }

  3. 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

@paddle-bot-old
Copy link

paddle-bot-old bot commented Nov 9, 2020

Thanks for your contribution! Please wait for the result of CI firstly.

Copy link
Collaborator

@haozech haozech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@haozech haozech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wenming2014 wenming2014 merged commit 0344a30 into PaddlePaddle:develop Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants