buddy-compiler / buddy-mlir

An MLIR-based compiler framework bridges DSLs (domain-specific languages) to DSAs (domain-specific architectures).
https://buddy-compiler.github.io/
Apache License 2.0
514 stars 167 forks source link

[frontend] Conv2d correction #338

Closed WuXintong123 closed 4 months ago

WuXintong123 commented 4 months ago

Solve the problem that Conv2d can not adapt to Lenet

zhanghb97 commented 4 months ago

Convolution test failed:

$ ninja check-buddy
[0/2] Checking the buddy-mlir examples...

Testing Time: 0.59s

Total Discovered Tests: 91
  Passed: 91 (100.00%)
[1/2] Running the buddy regression tests...
FAIL: BUDDY :: Python/test_convolution_default.py (73 of 73)
******************** TEST 'BUDDY :: Python/test_convolution_default.py' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /home/zhanghongbin/miniconda3/envs/zhb-buddy/bin/python3 /home/zhanghongbin/buddy-mlir/tests/Python/test_convolution_default.py 2>&1 | /home/zhanghongbin/buddy-mlir/llvm/build/bin/FileCheck /home/zhanghongbin/buddy-mlir/tests/Python/test_convolution_default.py
+ /home/zhanghongbin/buddy-mlir/llvm/build/bin/FileCheck /home/zhanghongbin/buddy-mlir/tests/Python/test_convolution_default.py
+ /home/zhanghongbin/miniconda3/envs/zhb-buddy/bin/python3 /home/zhanghongbin/buddy-mlir/tests/Python/test_convolution_default.py
/home/zhanghongbin/buddy-mlir/tests/Python/test_convolution_default.py:38:10: error: CHECK: expected string not found in input
# CHECK: %{{.*}} = tosa.conv2d
         ^
<stdin>:10:21: note: scanning from here
 %4 = tosa.transpose %arg0, %3 : (tensor<3x1x5x5xf32>, tensor<4xi32>) -> tensor<5x5x3x1xf32>
                    ^
<stdin>:12:2: note: possible intended match here
 %6 = "tosa.const"() <{value = dense<[0, 3, 1, 2]> : tensor<4xi32>}> : () -> tensor<4xi32>
 ^

Input file: <stdin>
Check file: /home/zhanghongbin/buddy-mlir/tests/Python/test_convolution_default.py

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            .
            .
            .
            5:  func.func @forward(%arg0: tensor<3x1x5x5xf32>, %arg1: tensor<1x3x640x480xf32>) -> (tensor<1x3x214x161xf32>, tensor<3x1x5x5xf32>, tensor<1x3x640x480xf32>) { 
            6:  %0 = "tosa.const"() <{value = dense<0.000000e+00> : tensor<3xf32>}> : () -> tensor<3xf32> 
            7:  %1 = "tosa.const"() <{value = dense<[0, 2, 3, 1]> : tensor<4xi32>}> : () -> tensor<4xi32> 
            8:  %2 = tosa.transpose %arg1, %1 : (tensor<1x3x640x480xf32>, tensor<4xi32>) -> tensor<1x640x480x3xf32> 
            9:  %3 = "tosa.const"() <{value = dense<[2, 3, 0, 1]> : tensor<4xi32>}> : () -> tensor<4xi32> 
           10:  %4 = tosa.transpose %arg0, %3 : (tensor<3x1x5x5xf32>, tensor<4xi32>) -> tensor<5x5x3x1xf32> 
check:38'0                         X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
           11:  %5 = tosa.depthwise_conv2d %2, %4, %0 {dilation = array<i64: 1, 1>, pad = array<i64: 3, 3, 3, 3>, stride = array<i64: 3, 3>} : (tensor<1x640x480x3xf32>, tensor<5x5x3x1xf32>, tensor<3xf32>) -> tensor<1x214x161x3xf32> 
check:38'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           12:  %6 = "tosa.const"() <{value = dense<[0, 3, 1, 2]> : tensor<4xi32>}> : () -> tensor<4xi32> 
check:38'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:38'1      ?                                                                                          possible intended match
           13:  %7 = tosa.transpose %5, %6 : (tensor<1x214x161x3xf32>, tensor<4xi32>) -> tensor<1x3x214x161xf32> 
check:38'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           14:  return %7, %arg0, %arg1 : tensor<1x3x214x161xf32>, tensor<3x1x5x5xf32>, tensor<1x3x640x480xf32> 
check:38'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           15:  } 
check:38'0     ~~~
           16: } 
check:38'0     ~~
           17:  
check:38'0     ~
>>>>>>

--

********************
********************
Failed Tests (1):
  BUDDY :: Python/test_convolution_default.py

Testing Time: 5.84s

Total Discovered Tests: 73
  Passed: 72 (98.63%)
  Failed:  1 (1.37%)
FAILED: tests/CMakeFiles/check-tests /home/zhanghongbin/buddy-mlir/build-llama/tests/CMakeFiles/check-tests 
cd /home/zhanghongbin/buddy-mlir/build-llama/tests && /home/zhanghongbin/miniconda3/envs/zhb-buddy/bin/python3 /home/zhanghongbin/buddy-mlir/llvm/build/./bin/llvm-lit -sv /home/zhanghongbin/buddy-mlir/build-llama/tests
ninja: build stopped: subcommand failed.