|
| 1 | +import pytest |
| 2 | +import torch |
| 3 | + |
| 4 | +import flag_gems |
| 5 | +from benchmark.attri_util import FLOAT_DTYPES |
| 6 | +from benchmark.performance_utils import GenericBenchmark |
| 7 | + |
| 8 | + |
| 9 | +class Conv2DBenchmark(GenericBenchmark): |
| 10 | + def set_more_shapes(self): |
| 11 | + return [ |
| 12 | + (32, 64, 128, 128, 32, 3, 3, 1, 2, 1), |
| 13 | + (32, 64, 210, 210, 16, 5, 5, 2, 1, 1), |
| 14 | + (16, 32, 12, 12, 24, 3, 3, 2, 1, 1), |
| 15 | + (16, 32, 24, 24, 24, 3, 3, 2, 2, 2), |
| 16 | + (16, 32, 24, 24, 24, 3, 3, 1, 2, 2), |
| 17 | + (16, 32, 12, 12, 24, 3, 3, 2, "valid", 1), |
| 18 | + (32, 64, 128, 128, 32, 3, 3, 1, "valid", 1), |
| 19 | + (16, 32, 24, 24, 24, 3, 3, 1, "same", 2), |
| 20 | + (32, 64, 210, 210, 16, 5, 5, 1, "same", 1), |
| 21 | + ] |
| 22 | + |
| 23 | + |
| 24 | +def _input_fn(shape, dtype, device): |
| 25 | + ( |
| 26 | + batch, |
| 27 | + input_c, |
| 28 | + input_h, |
| 29 | + input_w, |
| 30 | + out_c, |
| 31 | + kernel_h, |
| 32 | + kernel_w, |
| 33 | + stride, |
| 34 | + padding, |
| 35 | + groups, |
| 36 | + ) = shape |
| 37 | + input_shape = (batch, input_c, input_h, input_w) |
| 38 | + weight_shape = (out_c, input_c // groups, kernel_h, kernel_w) |
| 39 | + input = torch.randn(size=input_shape, device=device, dtype=dtype) |
| 40 | + weight = torch.randn(size=weight_shape, device=device, dtype=dtype) |
| 41 | + |
| 42 | + yield { |
| 43 | + "input": input, |
| 44 | + "weight": weight, |
| 45 | + "bias": None, |
| 46 | + "groups": groups, |
| 47 | + "stride": stride, |
| 48 | + "padding": padding, |
| 49 | + }, |
| 50 | + |
| 51 | + |
| 52 | +@pytest.mark.conv2d |
| 53 | +def test_conv2d(monkeypatch): |
| 54 | + if flag_gems.vendor_name == "hygon": |
| 55 | + monkeypatch.setenv("TRITON_HIP_USE_NEW_STREAM_PIPELINE", "0") |
| 56 | + |
| 57 | + torch.backends.cudnn.allow_tf32 = False |
| 58 | + bench = Conv2DBenchmark( |
| 59 | + input_fn=_input_fn, |
| 60 | + op_name="conv2d", |
| 61 | + torch_op=torch.nn.functional.conv2d, |
| 62 | + dtypes=FLOAT_DTYPES, |
| 63 | + ) |
| 64 | + bench.set_gems(flag_gems.conv2d) |
| 65 | + |
| 66 | + bench.run() |
0 commit comments