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

Error converting UPMEM MLIR to UPMEM C #27

Open
fengjingge815 opened this issue Dec 21, 2024 · 2 comments
Open

Error converting UPMEM MLIR to UPMEM C #27

fengjingge815 opened this issue Dec 21, 2024 · 2 comments

Comments

@fengjingge815
Copy link

Under Ubuntu 22.04, I encountered an error while installing the official command to compile and run CINM, and when converting UPMEM MLIR to UPMEM C, the specific information is as follows:

source:https://github.com/tud-ccc/Cinnamon
ubuntu:ubuntu22.04
compiler:gcc/g++11.4

cd Cinnamon //ok
just configure -no-torch-mlir //ok
./compile_benches.sh //err

Setting UPMEM_HOME to /home/test/src/llvm18-cinn/tmp/Cinnamon/upmem and updating PATH/LD_LIBRARY_PATH/PYTHONPATH
ninja -Ccinnamon/build cinm-opt
ninja: Entering directory `cinnamon/build'
ninja: no work to do.
Setting UPMEM_HOME to /home/fengjingge/src/llvm18-cinn/tmp/Cinnamon/upmem and updating PATH/LD_LIBRARY_PATH/PYTHONPATH
rm -rf generated2/va
../build/bin/cinm-opt va.mlir --cinm-tiling --affine-loop-unroll='unroll-full unroll-full-threshold=1' > generated2/va/irs/va.tiled.mlir
../build/bin/cinm-opt generated2/va/irs/va.tiled.mlir --convert-cinm-to-cnm --cnm-hoist-workgroups --canonicalize --cse > generated2/va/irs/va.cnm.mlir
../build/bin/cinm-opt generated2/va/irs/va.cnm.mlir --lower-affine --one-shot-bufferize='bufferize-function-boundaries function-boundary-type-conversion=identity-layout-map'
--convert-linalg-to-affine-loops --lower-affine --buffer-loop-hoisting --buffer-hoisting --canonicalize --cse > generated2/va/irs/va.cnm.bufferized.mlir
../build/bin/cinm-opt generated2/va/irs/va.cnm.bufferized.mlir --convert-cnm-to-upmem --cse --upmem-outline-kernel --upmem-dedup-kernels --cse > generated2/va/irs/va.upmem.mlir
../build/bin/cinm-opt generated2/va/irs/va.upmem.mlir --mlir-print-ir-after-failure --canonicalize
--convert-scf-to-cf --convert-cf-to-llvm --fold-memref-alias-ops --lower-affine --convert-arith-to-llvm
--convert-upmem-to-llvm
--expand-strided-metadata --memref-expand --finalize-memref-to-llvm --lower-affine --convert-arith-to-llvm
--convert-func-to-llvm=use-bare-ptr-memref-call-conv=true --cse --reconcile-unrealized-casts --llvm-legalize-for-export --canonicalize --cse \

generated2/va/irs/va.llvm.mlir
../build/bin/cinm-translate --mlir-to-llvmir generated2/va/irs/va.llvm.mlir > generated2/va/irs/va.host.ll
../../llvm/build/bin/opt -O3 -S generated2/va/irs/va.host.ll > generated2/va/irs/va.host.opt.ll
../../llvm/build/bin/llc -O3 generated2/va/irs/va.host.opt.ll -o generated2/va/irs/va.host.o -filetype=obj -relocation-model=pic
../build/bin/cinm-translate --mlir-to-upmem-cpp generated2/va/irs/va.upmem.mlir > generated2/va/irs/va.dpu.c
generated2/va/irs/va.upmem.mlir:4:3: error: Dialect `memref' not found for custom op 'memref.global'
memref.global "private" constant @__constant_2xi64_0 : memref<2xi64> = dense<[16384, 512]> {alignment = 64 : i64}
^
generated2/va/irs/va.upmem.mlir:4:3: note: Registered dialects: builtin, upmem ; for more info on dialect registration see https://mlir.llvm.org/getting_started/Faq/#registered-loaded-dependent-whats-up-with-dialects-management

va.upmem.mlir:
#map = affine_map<(d0, d1, d2) -> (d0 * 1024 + d1 * 16 + d2)>
2 #map1 = affine_map<(d0, d1, d2) -> (d0 * 512 + d1 * 8 + d2)>
3 module {
4 memref.global "private" constant @__constant_2xi64_0 : memref<2xi64> = dense<[16384, 512]> {alignment = 64 : i 64}
5 memref.global "private" constant @__constant_1xi64_1 : memref<1xi64> = dense<8388608> {alignment = 64 : i64}
6 memref.global "private" constant @__constant_16384x512xi32 : memref<16384x512xi32> = dense<0> {alignment = 64 : i64}
7 memref.global "private" constant @__constant_1xi64_0 : memref<1xi64> = dense<16777216> {alignment = 64 : i64}
8 memref.global "private" constant @__constant_2xi64 : memref<2xi64> = dense<[16384, 256]> {alignment = 64 : i64 }
9 memref.global "private" constant @__constant_1xi64 : memref<1xi64> = dense<4194304> {alignment = 64 : i64}
10 memref.global "private" constant @__constant_16384x256xi32 : memref<16384x256xi32> = dense<0> {alignment = 64 : i64}
......

@lvzc0
Copy link

lvzc0 commented Dec 25, 2024

I am getting the same issue.

@fengjingge815
Copy link
Author

fengjingge815 commented Jan 5, 2025

Modify cinnamon/lib/Target/UPMEMCpp/UPMEMTranslateToCpp.cpp
`void mlir::upmem_emitc::registerUPMEMCppTranslation() {
static llvm::cl::opt declareVarsAtTop(
"declare-vars-at-top",
llvm::cl::desc("Declare variables at top when emitting C/C++"),
llvm::cl::init(false));

TranslateFromMLIRRegistration reg(
"mlir-to-upmem-cpp", "translate from upmem's mlir to upmem's cpp",
[](Operation *op, raw_ostream &output) {
return upmem_emitc::UPMEMtranslateToCpp(
op, output,
/declareVariablesAtTop=/declareVarsAtTop);
},
[](DialectRegistry &registry) {
// clang-format off

    //Insert start
    registry.insert<mlir::memref::MemRefDialect>(); //Insert
    registry.insert<mlir::func::FuncDialect>(); //Insert
    registry.insert<mlir::scf::SCFDialect>();  //Insert
    //Insert end


    registry.insert<upmem::UPMEMDialect>();
    // clang-format on
  });

}`

Recompile to fix the above issues

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

No branches or pull requests

2 participants