Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

测试cinn单算子时间问题 #69304

Open
wangzy0327 opened this issue Nov 12, 2024 · 2 comments
Open

测试cinn单算子时间问题 #69304

wangzy0327 opened this issue Nov 12, 2024 · 2 comments

Comments

@wangzy0327
Copy link

bug描述 Describe the Bug

Paddle版本 release/v2.6.0
GPU Nvidia V100
编译paddle后,单元测试Paddle的算子测试用例,发现测试CINN算子时间很长,好像是包含了其他时间,没有只测CINN算子执行时间。请问该用例如何只测试CINN算子执行时间?
单算子测试用例代码链接:https://github.com/PaddlePaddle/Paddle/blob/release/2.6/test/cinn/ops/test_abs_op.py
基于上述的代码链接,添加测试时间部分代码

import time

def build_paddle_program(self, target):
        x = paddle.to_tensor(self.x_np, stop_gradient=True)
        # 记录开始时间
        start_time = time.time()
        out = paddle.abs(x)
        end_time = time.time()
        # 计算执行时间
        execution_time = end_time - start_time
        print(f"Paddle Execution time: {execution_time:.6f} seconds")
        
        self.paddle_outputs = [out]

    def build_cinn_program(self, target):
        builder = NetBuilder("identity")
        x = builder.create_input(
            self.nptype2cinntype(self.case["x_dtype"]),
            self.case["x_shape"],
            "x",
        )
        out = builder.abs(x)

        prog = builder.build()

        # 记录开始时间
        start_time = time.time()

        res = self.get_cinn_output(prog, target, [x], [self.x_np], [out])
        
        end_time = time.time()
        # 计算执行时间
        execution_time = end_time - start_time

        print(f"CINN Execution time: {execution_time:.6f} seconds")
        
        self.cinn_outputs = [res[0]]

测试结果

Current Paddle device : gpu:0

Running TestAbsOpShape.TestAbsOpShape0: {'x_shape': [1], 'x_dtype': 'float32'}
Paddle Execution time: 0.164408 seconds
CINN Execution time: 1.507690 seconds
Current Paddle device : gpu:0

Running TestAbsOpShape.TestAbsOpShape1: {'x_shape': [1024], 'x_dtype': 'float32'}
Paddle Execution time: 0.000076 seconds
CINN Execution time: 0.756306 seconds
Current Paddle device : gpu:0

Running TestAbsOpShape.TestAbsOpShape2: {'x_shape': [1, 2048], 'x_dtype': 'float32'}
Paddle Execution time: 0.000171 seconds
CINN Execution time: 0.722324 seconds
Current Paddle device : gpu:0

Running TestAbsOpShape.TestAbsOpShape3: {'x_shape': [1, 1, 1], 'x_dtype': 'float32'}
Paddle Execution time: 0.000140 seconds
CINN Execution time: 0.760242 seconds
Current Paddle device : gpu:0

Running TestAbsOpShape.TestAbsOpShape4: {'x_shape': [32, 64], 'x_dtype': 'float32'}
Paddle Execution time: 0.000108 seconds
CINN Execution time: 0.765401 seconds
Current Paddle device : gpu:0

Running TestAbsOpShape.TestAbsOpShape5: {'x_shape': [16, 8, 4, 2], 'x_dtype': 'float32'}
Paddle Execution time: 0.000079 seconds
CINN Execution time: 0.788273 seconds
Current Paddle device : gpu:0

Running TestAbsOpShape.TestAbsOpShape6: {'x_shape': [16, 8, 4, 2, 1], 'x_dtype': 'float32'}
Paddle Execution time: 0.000115 seconds
CINN Execution time: 0.731257 seconds
Current Paddle device : gpu:0

Running TestAbsOpDtype.TestAbsOpDtype0: {'x_shape': [32, 64], 'x_dtype': 'int32'}
Paddle Execution time: 0.000089 seconds
CINN Execution time: 0.721283 seconds
Current Paddle device : gpu:0

Running TestAbsOpDtype.TestAbsOpDtype1: {'x_shape': [32, 64], 'x_dtype': 'int64'}
Paddle Execution time: 0.000092 seconds
CINN Execution time: 0.764283 seconds
Current Paddle device : gpu:0

Running TestAbsOpDtype.TestAbsOpDtype2: {'x_shape': [32, 64], 'x_dtype': 'float16', 'max_relative_error': 0.001}
Paddle Execution time: 0.000149 seconds
CINN Execution time: 0.727614 seconds
Current Paddle device : gpu:0

Running TestAbsOpDtype.TestAbsOpDtype3: {'x_shape': [32, 64], 'x_dtype': 'float32'}
Paddle Execution time: 0.000118 seconds
CINN Execution time: 0.769592 seconds
Current Paddle device : gpu:0

Running TestAbsOpDtype.TestAbsOpDtype4: {'x_shape': [32, 64], 'x_dtype': 'float64'}
Paddle Execution time: 0.000132 seconds
CINN Execution time: 0.726039 seconds

Finished running test_abs_op.py.

测试Paddle调库的时间与CINN时间差异很大,请问CINN的测试时间,在该单元测试用例里如何进行? 谢谢

其他补充信息 Additional Supplementary Information

No response

@wangzy0327
Copy link
Author

@wanghuancoder 可以帮忙看一下么?

@warrentdrew
Copy link
Contributor

您好,可以测试下build_and_get_output这个方法里的execute的时间

program->Execute();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants