UCLA-VAST / AutoSA

AutoSA: Polyhedral-Based Systolic Array Compiler
MIT License
188 stars 31 forks source link

Only specific coding style can pass compilation #12

Open chhzh123 opened 2 years ago

chhzh123 commented 2 years ago

Hi,

I just installed AutoSA and tried to make some code generation for systolic arrays. It seems AutoSA has a very strict coding style. I wonder why in the following GEMM example. Only the second can work, but the first way cannot.

#include <algorithm>
#include <ap_axi_sdata.h>
#include <ap_fixed.h>
#include <ap_int.h>
#include <hls_math.h>
#include <hls_stream.h>
#include <math.h>
#include <stdint.h>
using namespace std;
void Stage_C(
  int32_t A0[32][32],
  int32_t B1[32][32],
  int32_t C2[32][32]
) { // L13
#pragma scop
  l_i3: for (int i3 = 0; i3 < 32; i3 += 1) {    // L14
    l_j4: for (int j4 = 0; j4 < 32; j4 += 1) {  // L15
      l_k6: for (int k6 = 0; k6 < 32; k6 += 1) {    // L20
        // 1st
        int32_t v7 = A0[i3][k6];    // L21
        int32_t v8 = B1[k6][j4];    // L22
        C2[i3][j4] += v7 * v8;  // L26
        // 2nd
        // C2[i3][j4] += A0[i3][k6] * B1[k6][j4];   // L26
      }
    }
  }
#pragma endscop
}

If I use the first way, the compiler gives the following error.

$./autosa test.cpp -I"$(dirname "$(which vivado_hls)")"/../include --config=./autosa_config/autosa_config.json --target=autosa_hls_c --output-dir=./autosa.tmp/output --sa-sizes="{kernel[]->space_time[3];}"
lt-autosa: /work/shared/common/usr/local/include/clang/AST/Decl.h:276: llvm::StringRef clang::NamedDecl::getName() const: Assertion `Name.isIdentifier() && "Name is not a simple identifier"' failed.
[AutoSA] Error: Exit abnormally!

Is this a limitation of AutoSA or are there something wrong with my code? Thanks!

whbldhwj commented 2 years ago

Hi,

Right now AutoSA did has a rigid requirement for the coding style. I don't think local variable definition is allowed. That should be the reason that caused the error you encountered.

chhzh123 commented 2 years ago

Okay. Thanks for your reply! Do you have plans to fix this limitation?

whbldhwj commented 2 years ago

It will take some time, probably will not be fixed in a short time. You probably could consider doing some quick fix on your generated code (e.g., replace v7 and v8 with array references) to get around this limitation?

chhzh123 commented 2 years ago

Yeah, since we are working on MLIR which has a strict SSA format, plugging v7 and v8 into the multiplication is impossible at the IR level. Actually, this piece of code has already been simplified manually, the original generated code also introduces an intermediate summation variable for C2, which I think is even harder to analyze.