├── .github └── workflows │ ├── build-ci.sh │ └── build_and_test.yml ├── .gitignore ├── LICENSE ├── README.md ├── cinnamon ├── .gitignore ├── CMakeLists.txt ├── README.md ├── cmake │ └── MLIRUtils.cmake ├── dialectTemplate │ ├── justfile │ └── templateFiles │ │ ├── include │ │ ├── ${projectPrefix} │ │ │ ├── Conversion │ │ │ │ ├── ${dialectNameUpper}Passes.h │ │ │ │ ├── ${dialectNameUpper}Passes.td │ │ │ │ └── CMakeLists.txt │ │ │ └── Dialect │ │ │ │ ├── ${dialectNameUpper} │ │ │ │ ├── CMakeLists.txt │ │ │ │ └── IR │ │ │ │ │ ├── ${dialectNameUpper}Attributes.h │ │ │ │ │ ├── ${dialectNameUpper}Attributes.td │ │ │ │ │ ├── ${dialectNameUpper}Base.h │ │ │ │ │ ├── ${dialectNameUpper}Base.td │ │ │ │ │ ├── ${dialectNameUpper}Dialect.h │ │ │ │ │ ├── ${dialectNameUpper}Ops.h │ │ │ │ │ ├── ${dialectNameUpper}Ops.td │ │ │ │ │ ├── ${dialectNameUpper}Types.h │ │ │ │ │ ├── ${dialectNameUpper}Types.td │ │ │ │ │ └── CMakeLists.txt │ │ │ │ └── CMakeLists.txt │ │ └── CMakeLists.txt │ │ └── lib │ │ ├── CMakeLists.txt │ │ ├── Conversion │ │ ├── CMakeLists.txt │ │ └── PassDetails.h │ │ └── Dialect │ │ ├── ${dialectNameUpper} │ │ ├── CMakeLists.txt │ │ └── IR │ │ │ ├── ${dialectNameUpper}Base.cpp │ │ │ ├── ${dialectNameUpper}Ops.cpp │ │ │ ├── ${dialectNameUpper}Types.cpp │ │ │ └── CMakeLists.txt │ │ └── CMakeLists.txt ├── include │ ├── CMakeLists.txt │ └── cinm-mlir │ │ ├── CMakeLists.txt │ │ ├── Conversion │ │ ├── CMakeLists.txt │ │ ├── CimPasses.h │ │ ├── CimPasses.td │ │ ├── CimToMemristor │ │ │ └── CimToMemristor.h │ │ ├── CinmFrontendPasses.h │ │ ├── CinmFrontendPasses.td │ │ ├── CinmPasses.h │ │ ├── CinmPasses.td │ │ ├── CinmToCim │ │ │ └── CinmToCim.h │ │ ├── CinmToCnm │ │ │ └── CinmToCnm.h │ │ ├── CnmPasses.h │ │ ├── CnmPasses.td │ │ ├── CnmToGPU │ │ │ └── CnmToGPU.h │ │ ├── CnmToUPMEM │ │ │ └── CnmToUPMEM.h │ │ ├── CommonPatterns.h │ │ ├── MemristorPasses.h │ │ ├── MemristorPasses.td │ │ ├── MemristorToFunc │ │ │ └── MemristorToFunc.h │ │ ├── TorchToCinm │ │ │ └── TorchToCinm.h │ │ ├── UPMEMPasses.h │ │ ├── UPMEMPasses.td │ │ └── UPMEMToLLVM │ │ │ └── UPMEMToLLVM.h │ │ ├── Dialect │ │ ├── CMakeLists.txt │ │ ├── Cim │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── CimAttributes.h │ │ │ │ ├── CimAttributes.td │ │ │ │ ├── CimBase.h │ │ │ │ ├── CimBase.td │ │ │ │ ├── CimDialect.h │ │ │ │ ├── CimOps.h │ │ │ │ ├── CimOps.td │ │ │ │ ├── CimTypes.h │ │ │ │ └── CimTypes.td │ │ │ └── Transforms │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── Passes.h │ │ │ │ └── Passes.td │ │ ├── Cinm │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── CinmAttributes.h │ │ │ │ ├── CinmAttributes.td │ │ │ │ ├── CinmBase.h │ │ │ │ ├── CinmBase.td │ │ │ │ ├── CinmDialect.h │ │ │ │ ├── CinmOps.h │ │ │ │ ├── CinmOps.td │ │ │ │ ├── CinmTypes.h │ │ │ │ └── CinmTypes.td │ │ │ ├── Interfaces │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── TilingInterface.h │ │ │ │ └── TilingInterface.td │ │ │ └── Transforms │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── Passes.h │ │ │ │ └── Passes.td │ │ ├── Cnm │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── CnmAttributes.h │ │ │ │ ├── CnmAttributes.td │ │ │ │ ├── CnmBase.h │ │ │ │ ├── CnmBase.td │ │ │ │ ├── CnmDialect.h │ │ │ │ ├── CnmOps.h │ │ │ │ ├── CnmOps.td │ │ │ │ ├── CnmTypes.h │ │ │ │ └── CnmTypes.td │ │ │ └── Transforms │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── Passes.h │ │ │ │ └── Passes.td │ │ ├── Memristor │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── MemristorAttributes.h │ │ │ │ ├── MemristorAttributes.td │ │ │ │ ├── MemristorBase.h │ │ │ │ ├── MemristorBase.td │ │ │ │ ├── MemristorDialect.h │ │ │ │ ├── MemristorOps.h │ │ │ │ ├── MemristorOps.td │ │ │ │ ├── MemristorTypes.h │ │ │ │ └── MemristorTypes.td │ │ │ └── Transforms │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── Passes.h │ │ │ │ └── Passes.td │ │ └── UPMEM │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ ├── AsyncOpInterface.h │ │ │ ├── AsyncOpInterface.td │ │ │ ├── CMakeLists.txt │ │ │ ├── UPMEMAttributes.h │ │ │ ├── UPMEMAttributes.td │ │ │ ├── UPMEMBase.h │ │ │ ├── UPMEMBase.td │ │ │ ├── UPMEMDialect.h │ │ │ ├── UPMEMOps.h │ │ │ ├── UPMEMOps.td │ │ │ ├── UPMEMTypes.h │ │ │ └── UPMEMTypes.td │ │ │ └── Transforms │ │ │ ├── CMakeLists.txt │ │ │ ├── Passes.h │ │ │ └── Passes.td │ │ ├── Target │ │ └── UPMEMCpp │ │ │ └── UPMEMCppEmitter.h │ │ └── Utils │ │ ├── CinmUtils.h │ │ └── Scheduling │ │ ├── Schedulers │ │ ├── Alap.h │ │ └── Asap.h │ │ └── Scheduling.h ├── lib │ ├── CMakeLists.txt │ ├── Conversion │ │ ├── CMakeLists.txt │ │ ├── CimToMemristor │ │ │ ├── CMakeLists.txt │ │ │ └── CimToMemristor.cpp │ │ ├── CinmToCim │ │ │ ├── CMakeLists.txt │ │ │ └── CinmToCim.cpp │ │ ├── CinmToCnm │ │ │ ├── CMakeLists.txt │ │ │ └── CinmToCnm.cpp │ │ ├── CnmToGPU │ │ │ ├── CMakeLists.txt │ │ │ └── CnmToGPU.cpp │ │ ├── CnmToUPMEM │ │ │ ├── CMakeLists.txt │ │ │ └── CnmToUPMEM.cpp │ │ ├── CommonPatterns.cpp │ │ ├── MemristorToFunc │ │ │ ├── CMakeLists.txt │ │ │ └── MemristorToFunc.cpp │ │ ├── PassDetails.h │ │ ├── TorchToCinm │ │ │ ├── CMakeLists.txt │ │ │ └── TorchToCinm.cpp │ │ └── UPMEMToLLVM │ │ │ ├── CMakeLists.txt │ │ │ ├── ToLLVMInterfaceImpl.cpp │ │ │ └── UPMEMToLLVM.cpp │ ├── Dialect │ │ ├── CMakeLists.txt │ │ ├── Cim │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── CimBase.cpp │ │ │ │ ├── CimOps.cpp │ │ │ │ └── CimTypes.cpp │ │ │ └── Transforms │ │ │ │ ├── CMakeLists.txt │ │ │ │ └── SchedulingPasses.cpp │ │ ├── Cinm │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── CinmBase.cpp │ │ │ │ ├── CinmOps.cpp │ │ │ │ ├── CinmTilingImplementations.cpp │ │ │ │ └── CinmTypes.cpp │ │ │ ├── Interfaces │ │ │ │ ├── CMakeLists.txt │ │ │ │ └── TilingInterface.cpp │ │ │ └── Transforms │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── SoftmaxToCinmPass.cpp │ │ │ │ └── TilingPass.cpp │ │ ├── Cnm │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── CnmBase.cpp │ │ │ │ ├── CnmOps.cpp │ │ │ │ └── CnmTypes.cpp │ │ │ └── Transforms │ │ │ │ ├── Bufferize.cpp │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── HoistWorkgroups.cpp │ │ │ │ └── SPIRVAttachAttributes.cpp │ │ ├── Memristor │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── MemristorBase.cpp │ │ │ │ ├── MemristorOps.cpp │ │ │ │ └── MemristorTypes.cpp │ │ │ └── Transforms │ │ │ │ ├── CMakeLists.txt │ │ │ │ └── dummy.cpp │ │ └── UPMEM │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ ├── CMakeLists.txt │ │ │ ├── InferIntRangeInterfaceImpls.cpp │ │ │ ├── UPMEMBase.cpp │ │ │ ├── UPMEMOps.cpp │ │ │ └── UPMEMTypes.cpp │ │ │ └── Transforms │ │ │ ├── CMakeLists.txt │ │ │ ├── DedupKernels.cpp │ │ │ └── OutlineFunction.cpp │ ├── Target │ │ ├── CMakeLists.txt │ │ └── UPMEMCpp │ │ │ ├── CMakeLists.txt │ │ │ ├── UPMEMTranslateRegistration.cpp │ │ │ └── UPMEMTranslateToCpp.cpp │ └── Utils │ │ ├── CMakeLists.txt │ │ └── CinmUtils.cpp ├── python │ ├── .gitignore │ ├── pyproject.toml │ └── src │ │ └── cinnamon │ │ └── torch_backend │ │ ├── __init__.py │ │ ├── _utility │ │ ├── ciface_type_wrappers.py │ │ ├── common_pipelines.py │ │ ├── compiler_invoker.py │ │ ├── resource_paths.py │ │ └── signature_extractor.py │ │ ├── cinm.py │ │ ├── compiled_model.py │ │ ├── exceptions.py │ │ ├── linalg_on_tensor.py │ │ └── model_invoker.py ├── runtime │ ├── Memristor │ │ ├── CMakeLists.txt │ │ ├── executor.cpp │ │ ├── executor_interface.hpp │ │ ├── gemm_cpu.hpp │ │ ├── gemm_simulator.hpp │ │ ├── runtime_c_interface.cpp │ │ └── simulator_interface.hpp │ └── Upmem │ │ ├── CMakeLists.txt │ │ ├── memref_rt.cpp │ │ ├── upmem_rt.c │ │ └── upmem_rt.h ├── samples │ ├── cinm_conv2d.mlir │ ├── cnm_conv.mlir │ ├── gemm.mlir │ ├── gemm_cnm.mlir │ ├── gemm_gpu.mlir │ ├── gemv.mlir │ ├── linalg_conv2d.mlir │ ├── llama2.cpp │ ├── min.mlir │ ├── transformer.mlir │ ├── upmem │ │ ├── module.mlir │ │ ├── va.mlir │ │ └── va_big.mlir │ ├── vector_add_big_cnm.mlir │ └── vector_add_small_cnm.mlir ├── test │ ├── CMakeLists.txt │ ├── Conversion │ │ ├── CimToMemristor │ │ │ ├── cim-to-memristor-multi-tile.mlir │ │ │ └── cim-to-memristor.mlir │ │ ├── CinmToCim │ │ │ └── cinm-to-cim.mlir │ │ ├── CinmToCnm │ │ │ └── cinm-to-cnm.mlir │ │ ├── MemristorToFunc │ │ │ └── memristor-to-func.mlir │ │ └── TorchToCinm │ │ │ └── torch-to-cinm.mlir │ ├── Dialect │ │ ├── Cim │ │ │ └── cim-ops.mlir │ │ ├── Cinm │ │ │ ├── cinm-ops.mlir │ │ │ └── cinm-tiling.mlir │ │ ├── Cnm │ │ │ └── cnm-ops.mlir │ │ ├── Memristor │ │ │ └── memristor-ops.mlir │ │ └── UPMEM │ │ │ └── upmem-ops.mlir │ ├── Python │ │ ├── cinm_backend.py │ │ └── linalg_backend.py │ ├── Transform │ │ └── Cim │ │ │ ├── schedule-alap-oversaturated.mlir │ │ │ ├── schedule-alap-undersaturated.mlir │ │ │ ├── schedule-asap-oversaturated.mlir │ │ │ └── schedule-asap-undersaturated.mlir │ ├── lit.cfg.py │ └── lit.site.cfg.py.in ├── testbench │ ├── .gitignore │ ├── 1mm.mlir │ ├── 2mm.mlir │ ├── 3mm.mlir │ ├── Makefile │ ├── apps │ │ ├── 1mm.cpp │ │ ├── 2mm.cpp │ │ ├── 3mm.cpp │ │ ├── conv.cpp │ │ ├── mlp.cpp │ │ ├── mv.cpp │ │ └── va.cpp │ ├── conv.mlir │ ├── gemm.mlir │ ├── generated │ │ ├── 1mm │ │ │ ├── Makefile │ │ │ ├── dpu │ │ │ │ └── task.c │ │ │ ├── host │ │ │ │ └── app.c │ │ │ └── support │ │ │ │ ├── common.h │ │ │ │ └── timer.h │ │ ├── 2mm │ │ │ ├── Makefile │ │ │ ├── dpu │ │ │ │ └── task.c │ │ │ ├── host │ │ │ │ └── app.c │ │ │ └── support │ │ │ │ ├── common.h │ │ │ │ └── timer.h │ │ ├── 3mm │ │ │ ├── Makefile │ │ │ ├── dpu │ │ │ │ └── task.c │ │ │ ├── host │ │ │ │ └── app.c │ │ │ └── support │ │ │ │ ├── common.h │ │ │ │ └── timer.h │ │ ├── conv │ │ │ ├── Makefile │ │ │ ├── dpu │ │ │ │ └── task.c │ │ │ ├── host │ │ │ │ └── app.c │ │ │ └── support │ │ │ │ ├── common.h │ │ │ │ └── timer.h │ │ ├── hst │ │ │ ├── Makefile │ │ │ ├── dpu │ │ │ │ └── task.c │ │ │ ├── host │ │ │ │ └── app.c │ │ │ ├── input │ │ │ │ └── image_VanHateren.iml │ │ │ └── support │ │ │ │ ├── common.h │ │ │ │ └── timer.h │ │ ├── mlp.tiled-cinm.mlir │ │ ├── mv │ │ │ ├── Makefile │ │ │ ├── dpu │ │ │ │ └── task.c │ │ │ ├── host │ │ │ │ └── app.c │ │ │ └── support │ │ │ │ ├── common.h │ │ │ │ └── timer.h │ │ ├── plot-fig-11.py │ │ ├── red │ │ │ ├── Makefile │ │ │ ├── dpu │ │ │ │ └── task.c │ │ │ ├── host │ │ │ │ └── app.c │ │ │ └── support │ │ │ │ ├── common.h │ │ │ │ └── timer.h │ │ ├── run_benchmarks.py │ │ ├── sel │ │ │ ├── Makefile │ │ │ ├── dpu │ │ │ │ └── task.c │ │ │ ├── host │ │ │ │ └── app.c │ │ │ └── support │ │ │ │ ├── common.h │ │ │ │ └── timer.h │ │ ├── va.cnm.mlir │ │ ├── va.upmem.mlir │ │ └── va │ │ │ ├── Makefile │ │ │ ├── dpu │ │ │ └── task.c │ │ │ ├── host │ │ │ └── app.c │ │ │ └── support │ │ │ ├── common.h │ │ │ └── timer.h │ ├── get_results.py │ ├── lib │ │ ├── bench │ │ │ └── testbench.hpp │ │ ├── compile_dpu.sh │ │ ├── dpu │ │ │ ├── dpu_lib.h │ │ │ └── expf.c │ │ └── host │ │ │ ├── binary_path.h │ │ │ ├── host_lib.c │ │ │ └── host_lib.h │ ├── mlp.mlir │ ├── mm2.mlir │ ├── mv.mlir │ ├── prim │ │ ├── GEMV │ │ │ ├── Makefile │ │ │ ├── dpu │ │ │ │ └── task.c │ │ │ ├── host │ │ │ │ └── app.c │ │ │ └── support │ │ │ │ ├── common.h │ │ │ │ ├── params.h │ │ │ │ └── timer.h │ │ ├── HST-L │ │ │ ├── Makefile │ │ │ ├── dpu │ │ │ │ └── task.c │ │ │ ├── host │ │ │ │ └── app.c │ │ │ ├── input │ │ │ │ └── image_VanHateren.iml │ │ │ └── support │ │ │ │ ├── common.h │ │ │ │ ├── params.h │ │ │ │ └── timer.h │ │ ├── RED │ │ │ ├── Makefile │ │ │ ├── dpu │ │ │ │ └── task.c │ │ │ ├── host │ │ │ │ └── app.c │ │ │ └── support │ │ │ │ ├── common.h │ │ │ │ ├── cyclecount.h │ │ │ │ ├── params.h │ │ │ │ └── timer.h │ │ ├── SEL │ │ │ ├── Makefile │ │ │ ├── dpu │ │ │ │ └── task.c │ │ │ ├── host │ │ │ │ └── app.c │ │ │ └── support │ │ │ │ ├── common.h │ │ │ │ ├── params.h │ │ │ │ └── timer.h │ │ ├── VA │ │ │ ├── Makefile │ │ │ ├── dpu │ │ │ │ └── task.c │ │ │ ├── host │ │ │ │ └── app.c │ │ │ └── support │ │ │ │ ├── common.h │ │ │ │ ├── params.h │ │ │ │ └── timer.h │ │ └── run_benchmarks.py │ └── va.mlir └── tools │ ├── CMakeLists.txt │ ├── cinm-lsp-server │ ├── CMakeLists.txt │ └── cinm-lsp-server.cpp │ ├── cinm-opt │ ├── CMakeLists.txt │ └── cinm-opt.cpp │ ├── cinm-translate │ ├── CMakeLists.txt │ └── cinm-translate.cpp │ └── cinm-vulkan-runner │ ├── CMakeLists.txt │ └── cinm-vulkan-runner.cpp ├── compile_benches.sh ├── exp-fig-11.sh ├── exp-fig-12.sh ├── justfile ├── plot ├── exp-fig-11.txt ├── exp-fig-12.txt ├── plot-fig-11.py ├── plot-fig-12.py └── plot.sh └── scripts ├── download_plot.sh ├── exp-fig-11.txt ├── exp-fig-12.txt ├── plot-fig-11.py ├── plot-fig-12.py └── run_bench.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .cache 2 | /.vscode/ 3 | /.idea/ 4 | .directory 5 | /.venv/ 6 | /llvm 7 | /torch-mlir/ 8 | /upmem/ 9 | /.env 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Chair for Compiler Construction TU Dresden 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /cinnamon/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/cmake 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=cmake 3 | 4 | ### CMake ### 5 | CMakeLists.txt.user 6 | CMakeCache.txt 7 | CMakeFiles 8 | CMakeScripts 9 | Testing 10 | Makefile 11 | cmake_install.cmake 12 | install_manifest.txt 13 | compile_commands.json 14 | CTestTestfile.cmake 15 | _deps 16 | 17 | ### CMake Patch ### 18 | # External projects 19 | *-prefix/ 20 | 21 | # End of https://www.toptal.com/developers/gitignore/api/cmake 22 | build-* 23 | build 24 | llvm 25 | .cache 26 | sandbox 27 | 28 | python/cinnamon/_resources 29 | .env 30 | **/__pycache__ 31 | -------------------------------------------------------------------------------- /cinnamon/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Setup instructions 3 | 4 | - Create a file named `.env` in the clone directory 5 | - In this file, write `LLVM_BUILD_DIR="> .env 22 | ``` -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/justfile: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | set export 5 | 6 | applyTemplate DIALECT_NAME DIALECT_NS PROJECT_PREFIX OUT_DIR: 7 | #!/bin/bash 8 | 9 | TMPDIR=$(mktemp -d) 10 | cp -r ./templateFiles/* "$TMPDIR" 11 | pushd "$TMPDIR" 12 | 13 | declare -A vardict 14 | vardict["dialectNameUpper"]=$DIALECT_NAME 15 | vardict["dialectNameAllCaps"]=${DIALECT_NS^^} 16 | vardict["dialectNs"]=$DIALECT_NS 17 | vardict["projectPrefix"]=$PROJECT_PREFIX 18 | 19 | # rename files and directories 20 | for varname in "${!vardict[@]}"; do 21 | find . -depth -exec bash -c 'REPLACED="${1//\$\{$2\}/$3}"; if [[ $REPLACED != $1 ]]; then mkdir -p $(dirname $REPLACED); mv $1 $REPLACED; fi' - '{}' "$varname" "${vardict[$varname]}" \; 22 | done 23 | # remove empty dirs 24 | find . -depth -empty -delete 25 | 26 | # replace within files 27 | for varname in "${!vardict[@]}"; do 28 | find . -type f -exec bash -c 'sed -i "s/\${$2}/$3/g" $1' - '{}' "$varname" "${vardict[$varname]}" \; 29 | done 30 | 31 | find . -type f -exec bash -c 'if [[ -e "$2/$1" ]]; then cat "$1" >> "$2/$1"; else mkdir -p $(dirname "$2/$1"); cp "$1" "$2/$1"; fi' - '{}' "$OUT_DIR" \; 32 | 33 | popd 34 | 35 | echo "Done. Check changes for correctness!" 36 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/${projectPrefix}/Conversion/${dialectNameUpper}Passes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the conversion pass within ${dialectNameUpper} dialect. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | namespace mlir { 8 | 9 | //===- Generated passes ---------------------------------------------------===// 10 | 11 | #define GEN_PASS_REGISTRATION 12 | #include "${projectPrefix}/Conversion/${dialectNameUpper}Passes.h.inc" 13 | 14 | //===----------------------------------------------------------------------===// 15 | 16 | } // namespace mlir -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/${projectPrefix}/Conversion/${dialectNameUpper}Passes.td: -------------------------------------------------------------------------------- 1 | //===- Passes.td - ${dialectNameUpper} dialect passes ---------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the ${dialectNameUpper} dialect conversion passes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef ${dialectNameAllCaps}_CONVERSION_PASSES 8 | #define ${dialectNameAllCaps}_CONVERSION_PASSES 9 | 10 | include "PassUtil.td" 11 | 12 | def Convert${dialectNameUpper}ToLLVM : ConvertToLlvm<"${dialectNameUpper}", "${dialectNs}">; 13 | 14 | 15 | #endif // ${dialectNameAllCaps}_CONVERSION_PASSES -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/${projectPrefix}/Conversion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS ${dialectNameUpper}Passes.td) 2 | mlir_tablegen(${dialectNameUpper}Passes.h.inc -gen-pass-decls -name ${dialectNameUpper}Conversion) 3 | add_public_tablegen_target(${dialectNameUpper}ConversionPassIncGen) 4 | 5 | add_mlir_doc(${dialectNameUpper}Passes ${dialectNameUpper}ConversionPasses ./ -gen-pass-doc) 6 | 7 | 8 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/${projectPrefix}/Dialect/${dialectNameUpper}/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # ${dialectNameUpper}IncGen 3 | # 4 | # MLIR ${dialectNameUpper} dialect generated includes. 5 | ################################################################################ 6 | 7 | add_custom_target(${dialectNameUpper}IncGen) 8 | 9 | # Attributes, Dialect, Operations and Types. 10 | add_subdirectory(IR) 11 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Attributes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the ${dialectNameUpper} dialect attributes. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Base.h" 8 | #include "mlir/IR/Attributes.h" 9 | 10 | //===- Generated includes -------------------------------------------------===// 11 | 12 | #define GET_ATTRDEF_CLASSES 13 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Attributes.h.inc" 14 | 15 | //===----------------------------------------------------------------------===// 16 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Attributes.td: -------------------------------------------------------------------------------- 1 | //===- Attributes.td - ${dialectNameUpper} dialect attributes --------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the ${dialectNameUpper} dialect attributes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef ${dialectNameAllCaps}_ATTRIBUTES 8 | #define ${dialectNameAllCaps}_ATTRIBUTES 9 | 10 | include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Base.td" 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Base.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the ${dialectNameUpper} dialect base. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "mlir/IR/BuiltinAttributes.h" 8 | #include "mlir/IR/BuiltinTypes.h" 9 | #include "mlir/IR/Dialect.h" 10 | 11 | //===- Generated includes -------------------------------------------------===// 12 | 13 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Base.h.inc" 14 | 15 | //===----------------------------------------------------------------------===// 16 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Base.td: -------------------------------------------------------------------------------- 1 | //===- Base.td - ${dialectNameUpper} dialect base ------------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the ${dialectNameUpper} dialect base. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef ${dialectNameAllCaps}_BASE 8 | #define ${dialectNameAllCaps}_BASE 9 | 10 | include "mlir/IR/BuiltinAttributes.td" 11 | include "mlir/IR/BuiltinTypes.td" 12 | include "mlir/IR/OpBase.td" 13 | 14 | def ${dialectNameUpper}_Dialect : Dialect { 15 | let name = "${dialectNs}"; 16 | let cppNamespace = "::mlir::${dialectNs}"; 17 | 18 | let summary = "TODO"; 19 | let description = [{ 20 | TODO 21 | }]; 22 | 23 | let useDefaultTypePrinterParser = 1; 24 | let useFoldAPI = kEmitFoldAdaptorFolder; 25 | 26 | 27 | code extraClassDeclaration = [{ 28 | private: 29 | void registerOps(); 30 | void registerTypes(); 31 | }]; 32 | } 33 | 34 | // Template for attributes. 35 | // class ${dialectNameUpper}_Attr traits = []> 36 | // : AttrDef<${dialectNameUpper}_Dialect, name, traits>; 37 | // Template for ops. 38 | class ${dialectNameUpper}_Op traits = []> 39 | : Op<${dialectNameUpper}_Dialect, mnemonic, traits>; 40 | // Template for types. 41 | class ${dialectNameUpper}_Type traits = []> 42 | : TypeDef<${dialectNameUpper}_Dialect, name, traits>; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Dialect.h: -------------------------------------------------------------------------------- 1 | /// Convenience include for the ${dialectNameUpper} dialect. 2 | /// 3 | 4 | #pragma once 5 | 6 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Ops.h" 7 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Ops.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the ${dialectNameUpper} dialect ops. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Types.h" 8 | 9 | #include "mlir/IR/Builders.h" 10 | #include "mlir/IR/BuiltinTypes.h" 11 | #include "mlir/IR/Dialect.h" 12 | #include "mlir/IR/OpImplementation.h" 13 | #include "mlir/Interfaces/ControlFlowInterfaces.h" 14 | #include "mlir/Interfaces/InferTypeOpInterface.h" 15 | #include "mlir/Interfaces/SideEffectInterfaces.h" 16 | 17 | 18 | 19 | //===- Generated includes -------------------------------------------------===// 20 | 21 | #define GET_OP_CLASSES 22 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Ops.h.inc" 23 | 24 | //===----------------------------------------------------------------------===// 25 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Ops.td: -------------------------------------------------------------------------------- 1 | //===- Ops.td - ${dialectNameUpper} dialect ops ----------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the ${dialectNameUpper} dialect ops. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef ${dialectNameAllCaps}_OPS 8 | #define ${dialectNameAllCaps}_OPS 9 | 10 | 11 | include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Base.td" 12 | include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Types.td" 13 | 14 | include "mlir/IR/EnumAttr.td" 15 | include "mlir/IR/OpAsmInterface.td" 16 | include "mlir/IR/SymbolInterfaces.td" 17 | include "mlir/Interfaces/CallInterfaces.td" 18 | include "mlir/Interfaces/ControlFlowInterfaces.td" 19 | include "mlir/IR/FunctionInterfaces.td" 20 | include "mlir/Interfaces/InferTypeOpInterface.td" 21 | include "mlir/Interfaces/SideEffectInterfaces.td" 22 | 23 | 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Types.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the ${dialectNameUpper} dialect types. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Attributes.h" 8 | 9 | 10 | //===- Generated includes -------------------------------------------------===// 11 | 12 | #define GET_TYPEDEF_CLASSES 13 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Types.h.inc" 14 | 15 | //===----------------------------------------------------------------------===// 16 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Types.td: -------------------------------------------------------------------------------- 1 | //===- Types.td - ${dialectNameUpper} dialect types ------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the ${dialectNameUpper} dialect types. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef ${dialectNameAllCaps}_TYPES 8 | #define ${dialectNameAllCaps}_TYPES 9 | 10 | include "mlir/IR/BuiltinTypeInterfaces.td" 11 | 12 | 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/${projectPrefix}/Dialect/${dialectNameUpper}/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mlir_gen_ir(${dialectNameUpper}) 2 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/${projectPrefix}/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # include(MLIRUtils) 2 | 3 | add_subdirectory(${dialectNameUpper}) 4 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # add_subdirectory(${projectPrefix}) 2 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Conversion) 2 | add_subdirectory(Dialect) 3 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/lib/Conversion/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tud-ccc/Cinnamon/715eb4d97359966792a80d6540bfb856ba6b9357/cinnamon/dialectTemplate/templateFiles/lib/Conversion/CMakeLists.txt -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/lib/Conversion/PassDetails.h: -------------------------------------------------------------------------------- 1 | /// Declaration of conversion passes for the ${dialectNameUpper} dialect. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "mlir/Pass/Pass.h" 8 | #include "mlir/IR/BuiltinOps.h" 9 | 10 | namespace mlir { 11 | 12 | // Forward declaration from Dialect.h 13 | template 14 | void registerDialect(DialectRegistry ®istry); 15 | 16 | namespace ${dialectNs} { 17 | class ${dialectNameUpper}Dialect; 18 | } // namespace ${dialectNs} 19 | 20 | //===- Generated passes ---------------------------------------------------===// 21 | 22 | #define GEN_PASS_CLASSES 23 | #include "${projectPrefix}/Conversion/${dialectNameUpper}Passes.h.inc" 24 | 25 | //===----------------------------------------------------------------------===// 26 | 27 | } // namespace mlir -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/lib/Dialect/${dialectNameUpper}/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/lib/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Base.cpp: -------------------------------------------------------------------------------- 1 | /// Implements the ${dialectNameUpper} dialect base. 2 | /// 3 | /// @file 4 | 5 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Base.h" 6 | 7 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Dialect.h" 8 | 9 | #define DEBUG_TYPE "${dialectNs}-base" 10 | 11 | using namespace mlir; 12 | using namespace mlir::${dialectNs}; 13 | 14 | //===- Generated implementation -------------------------------------------===// 15 | 16 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Base.cpp.inc" 17 | 18 | //===----------------------------------------------------------------------===// 19 | 20 | //===----------------------------------------------------------------------===// 21 | // ${dialectNameUpper}Dialect 22 | //===----------------------------------------------------------------------===// 23 | 24 | void ${dialectNameUpper}Dialect::initialize() 25 | { 26 | registerOps(); 27 | registerTypes(); 28 | } 29 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/lib/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Ops.cpp: -------------------------------------------------------------------------------- 1 | /// Implements the ${dialectNameUpper} dialect ops. 2 | /// 3 | /// @file 4 | 5 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Ops.h" 6 | 7 | #include "mlir/IR/Builders.h" 8 | #include "mlir/IR/OpImplementation.h" 9 | 10 | #include "llvm/ADT/APFloat.h" 11 | 12 | #define DEBUG_TYPE "${dialectNs}-ops" 13 | 14 | using namespace mlir; 15 | using namespace mlir::${dialectNs}; 16 | 17 | //===- Generated implementation -------------------------------------------===// 18 | 19 | #define GET_OP_CLASSES 20 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Ops.cpp.inc" 21 | 22 | //===----------------------------------------------------------------------===// 23 | // ${dialectNameUpper}Dialect 24 | //===----------------------------------------------------------------------===// 25 | 26 | void ${dialectNameUpper}Dialect::registerOps() 27 | { 28 | addOperations< 29 | #define GET_OP_LIST 30 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Ops.cpp.inc" 31 | >(); 32 | } 33 | 34 | // parsers/printers 35 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/lib/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Types.cpp: -------------------------------------------------------------------------------- 1 | /// Implements the ${dialectNameUpper} dialect types. 2 | /// 3 | /// @file 4 | 5 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Types.h" 6 | 7 | #include "mlir/IR/Builders.h" 8 | #include "mlir/IR/DialectImplementation.h" 9 | #include "mlir/IR/OpImplementation.h" 10 | 11 | #include "llvm/ADT/TypeSwitch.h" 12 | 13 | #define DEBUG_TYPE "${dialectNs}-types" 14 | 15 | using namespace mlir; 16 | using namespace mlir::${dialectNs}; 17 | 18 | //===- Generated implementation -------------------------------------------===// 19 | 20 | #define GET_TYPEDEF_CLASSES 21 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Types.cpp.inc" 22 | 23 | //===----------------------------------------------------------------------===// 24 | 25 | //===----------------------------------------------------------------------===// 26 | // ${dialectNameUpper}Dialect 27 | //===----------------------------------------------------------------------===// 28 | 29 | void ${dialectNameUpper}Dialect::registerTypes() 30 | { 31 | addTypes< 32 | #define GET_TYPEDEF_LIST 33 | #include "${projectPrefix}/Dialect/${dialectNameUpper}/IR/${dialectNameUpper}Types.cpp.inc" 34 | >(); 35 | } 36 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/lib/Dialect/${dialectNameUpper}/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(${dialectNameUpper}IR 2 | ${dialectNameUpper}Base.cpp 3 | ${dialectNameUpper}Ops.cpp 4 | ${dialectNameUpper}Types.cpp 5 | 6 | DEPENDS 7 | ${dialectNameUpper}IncGen 8 | ${dialectNameUpper}ConversionPassIncGen 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRIR 12 | MLIRParser 13 | MLIRSideEffectInterfaces 14 | ) 15 | -------------------------------------------------------------------------------- /cinnamon/dialectTemplate/templateFiles/lib/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(${dialectNameUpper}) 2 | -------------------------------------------------------------------------------- /cinnamon/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(cinm-mlir) 2 | # add_subdirectory(cinm-mlir) 3 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Dialect) 2 | add_subdirectory(Conversion) -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(TBLGEN_EXTRA $<$:-DCINM_GPU_SUPPORT>) 3 | 4 | set(LLVM_TARGET_DEFINITIONS CinmFrontendPasses.td) 5 | mlir_tablegen(CinmFrontendPasses.h.inc -gen-pass-decls -name CinmFrontendConversion ${TBLGEN_EXTRA}) 6 | add_public_tablegen_target(CinmFrontendConversionPassIncGen) 7 | 8 | add_mlir_doc(CinmFrontendPasses CinmFrontendConversionPasses ./ -gen-pass-doc) 9 | 10 | set(LLVM_TARGET_DEFINITIONS CinmPasses.td) 11 | mlir_tablegen(CinmPasses.h.inc -gen-pass-decls -name CinmConversion ${TBLGEN_EXTRA}) 12 | add_public_tablegen_target(CinmConversionPassIncGen) 13 | 14 | add_mlir_doc(CinmPasses CinmConversionPasses ./ -gen-pass-doc) 15 | 16 | set(LLVM_TARGET_DEFINITIONS CimPasses.td) 17 | mlir_tablegen(CimPasses.h.inc -gen-pass-decls -name CimConversion ${TBLGEN_EXTRA}) 18 | add_public_tablegen_target(CimConversionPassIncGen) 19 | 20 | add_mlir_doc(CimPasses CimConversionPasses ./ -gen-pass-doc) 21 | 22 | set(LLVM_TARGET_DEFINITIONS CnmPasses.td) 23 | mlir_tablegen(CnmPasses.h.inc -gen-pass-decls -name CnmConversion ${TBLGEN_EXTRA}) 24 | add_public_tablegen_target(CnmConversionPassIncGen) 25 | 26 | add_mlir_doc(CnmPasses CnmConversionPasses ./ -gen-pass-doc) 27 | 28 | set(LLVM_TARGET_DEFINITIONS MemristorPasses.td) 29 | mlir_tablegen(MemristorPasses.h.inc -gen-pass-decls -name MemristorConversion ${TBLGEN_EXTRA}) 30 | add_public_tablegen_target(MemristorConversionPassIncGen) 31 | 32 | add_mlir_doc(MemristorPasses MemristorConversionPasses ./ -gen-pass-doc) 33 | 34 | set(LLVM_TARGET_DEFINITIONS UPMEMPasses.td) 35 | mlir_tablegen(UPMEMPasses.h.inc -gen-pass-decls -name UPMEMConversion ${TBLGEN_EXTRA}) 36 | add_public_tablegen_target(UPMEMConversionPassIncGen) 37 | 38 | add_mlir_doc(UPMEMPasses UPMEMConversionPasses ./ -gen-pass-doc) 39 | 40 | 41 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/CimPasses.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the conversion pass within Cim dialect. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Conversion/CimToMemristor/CimToMemristor.h" 8 | 9 | namespace mlir { 10 | 11 | //===- Generated passes ---------------------------------------------------===// 12 | 13 | #define GEN_PASS_REGISTRATION 14 | #include "cinm-mlir/Conversion/CimPasses.h.inc" 15 | 16 | //===----------------------------------------------------------------------===// 17 | 18 | } // namespace mlir 19 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/CimPasses.td: -------------------------------------------------------------------------------- 1 | //===- Passes.td - Cim dialect passes ---------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Cim dialect conversion passes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef CIM_CONVERSION_PASSES 8 | #define CIM_CONVERSION_PASSES 9 | 10 | include "mlir/Pass/PassBase.td" 11 | 12 | def ConvertCimToMemristorPass : Pass<"convert-cim-to-memristor", operation="func::FuncOp"> { 13 | let summary = "Convert cim dialect to memristor dialect"; 14 | let constructor = "mlir::cim::createConvertCimToMemristorPass()"; 15 | let dependentDialects = ["cim::CimDialect", "memristor::MemristorDialect", 16 | "bufferization::BufferizationDialect", "memref::MemRefDialect", "tensor::TensorDialect"]; 17 | } 18 | 19 | #endif // CIM_CONVERSION_PASSES 20 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/CimToMemristor/CimToMemristor.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | 6 | namespace mlir::cim { 7 | std::unique_ptr createConvertCimToMemristorPass(); 8 | } // namespace mlir::cim -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/CinmFrontendPasses.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the conversion pass within Cinm dialect. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | namespace mlir { 10 | 11 | //===- Generated passes ---------------------------------------------------===// 12 | 13 | #define GEN_PASS_REGISTRATION 14 | #include "cinm-mlir/Conversion/CinmFrontendPasses.h.inc" 15 | 16 | //===----------------------------------------------------------------------===// 17 | 18 | } // namespace mlir -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/CinmFrontendPasses.td: -------------------------------------------------------------------------------- 1 | //===- Passes.td - CinmFrontend passes ---------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Cinm frontend conversion passes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef CINM_FRONTEND_CONVERSION_PASSES 8 | #define CINM_FRONTEND_CONVERSION_PASSES 9 | 10 | 11 | include "mlir/Pass/PassBase.td" 12 | 13 | def ConvertTorchToCinm : Pass<"convert-torch-to-cinm", operation="func::FuncOp"> { 14 | let summary = "Convert torch dialect to cinm dialect"; 15 | let constructor = "mlir::cinm_frontend::createConvertTorchToCinmPass()"; 16 | let dependentDialects = ["torch::Torch::TorchDialect", "torch::TorchConversion::TorchConversionDialect", 17 | "cinm::CinmDialect", "func::FuncDialect", "tensor::TensorDialect"]; 18 | } 19 | 20 | #endif // CINM_FRONTEND_CONVERSION_PASSES -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/CinmPasses.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the conversion pass within Cinm dialect. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | namespace mlir { 11 | 12 | //===- Generated passes ---------------------------------------------------===// 13 | 14 | #define GEN_PASS_REGISTRATION 15 | #include "cinm-mlir/Conversion/CinmPasses.h.inc" 16 | 17 | //===----------------------------------------------------------------------===// 18 | 19 | } // namespace mlir -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/CinmPasses.td: -------------------------------------------------------------------------------- 1 | //===- Passes.td - Cinm dialect passes ---------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Cinm dialect conversion passes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef CINM_CONVERSION_PASSES 8 | #define CINM_CONVERSION_PASSES 9 | 10 | 11 | include "mlir/Pass/PassBase.td" 12 | 13 | def ConvertTiledCinmToCnm : Pass<"convert-cinm-to-cnm", operation="func::FuncOp"> { 14 | let summary = "Convert CINM dialect to CNM dialect (may require --cinm-tiling before)"; 15 | let constructor = "mlir::cinm::createConvertTiledCinmToCnmPass()"; 16 | let dependentDialects = ["cnm::CnmDialect", "func::FuncDialect", 17 | "arith::ArithDialect", "tensor::TensorDialect"]; 18 | } 19 | 20 | def ConvertTiledCinmToCim : Pass<"convert-cinm-to-cim", operation="func::FuncOp"> { 21 | let summary = "Convert CINM dialect to CIM dialect (may require --cinm-tiling before)"; 22 | let constructor = "mlir::cinm::createConvertTiledCinmToCimPass()"; 23 | let dependentDialects = ["cim::CimDialect", "func::FuncDialect", "tensor::TensorDialect"]; 24 | } 25 | 26 | #endif // CINM_CONVERSION_PASSES -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/CinmToCim/CinmToCim.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | 6 | namespace mlir::cinm { 7 | 8 | /// Full pipeline 9 | void registerCinmToCimPipeline(); 10 | 11 | /// Just the pass after --cinm-tiling 12 | std::unique_ptr createConvertTiledCinmToCimPass(); 13 | } // namespace mlir::cinm -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/CinmToCnm/CinmToCnm.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | namespace mlir::cinm { 6 | 7 | /// Full pipeline 8 | void registerCinmToCnmPipeline(); 9 | 10 | /// Just the pass after --cinm-tiling 11 | std::unique_ptr createConvertTiledCinmToCnmPass(); 12 | } // namespace mlir::cnm -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/CnmPasses.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the conversion pass within Cnm dialect. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Conversion/CnmToGPU/CnmToGPU.h" 8 | #include "cinm-mlir/Conversion/CnmToUPMEM/CnmToUPMEM.h" 9 | 10 | namespace mlir { 11 | 12 | //===- Generated passes ---------------------------------------------------===// 13 | 14 | #define GEN_PASS_REGISTRATION 15 | #include "cinm-mlir/Conversion/CnmPasses.h.inc" 16 | 17 | //===----------------------------------------------------------------------===// 18 | 19 | } // namespace mlir 20 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/CnmPasses.td: -------------------------------------------------------------------------------- 1 | //===- Passes.td - Cnm dialect passes ---------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Cnm dialect conversion passes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef CNM_CONVERSION_PASSES 8 | #define CNM_CONVERSION_PASSES 9 | 10 | include "mlir/Pass/PassBase.td" 11 | 12 | #ifdef CINM_GPU_SUPPORT 13 | def ConvertCnmToGPUPass : Pass<"convert-cnm-to-gpu"> { 14 | let summary = ""; 15 | let constructor = "mlir::cnm::createConvertCnmToGPUPass()"; 16 | let dependentDialects = [ 17 | "mlir::LLVM::LLVMDialect", 18 | "mlir::affine::AffineDialect", 19 | "mlir::arith::ArithDialect", 20 | "mlir::bufferization::BufferizationDialect", 21 | "mlir::gpu::GPUDialect", 22 | "mlir::memref::MemRefDialect", 23 | "mlir::tensor::TensorDialect" 24 | ]; 25 | } 26 | #endif 27 | 28 | def ConvertCnmToUPMEMPass : Pass<"convert-cnm-to-upmem"> { 29 | let summary = ""; 30 | let constructor = "mlir::cnm::createConvertCnmToUPMEMPass()"; 31 | let dependentDialects = [ 32 | "mlir::affine::AffineDialect", 33 | "mlir::arith::ArithDialect", 34 | "mlir::memref::MemRefDialect", 35 | "mlir::tensor::TensorDialect", 36 | "mlir::upmem::UPMEMDialect" 37 | ]; 38 | } 39 | 40 | #endif // CNM_CONVERSION_PASSES 41 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/CnmToGPU/CnmToGPU.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #ifdef CINM_GPU_SUPPORT 7 | namespace mlir::cnm { 8 | void populateCnmToGPUFinalTypeConversions(LLVMTypeConverter &typeConverter); 9 | void populateCnmToGPUConversionPatterns(LLVMTypeConverter &typeConverter, RewritePatternSet &patterns); 10 | std::unique_ptr createConvertCnmToGPUPass(); 11 | } // namespace mlir::cnm 12 | 13 | #endif -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/CnmToUPMEM/CnmToUPMEM.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMDialect.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace mlir::cnm { 9 | void populateCnmToUPMEMFinalTypeConversions(TypeConverter &typeConverter); 10 | void populateCnmToUPMEMConversionPatterns(TypeConverter &typeConverter, 11 | RewritePatternSet &patterns); 12 | std::unique_ptr createConvertCnmToUPMEMPass(); 13 | } // namespace mlir::cnm 14 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/MemristorPasses.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the conversion pass within Memristor dialect. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Conversion/MemristorToFunc/MemristorToFunc.h" 8 | 9 | namespace mlir { 10 | 11 | //===- Generated passes ---------------------------------------------------===// 12 | 13 | #define GEN_PASS_REGISTRATION 14 | #include "cinm-mlir/Conversion/MemristorPasses.h.inc" 15 | 16 | //===----------------------------------------------------------------------===// 17 | 18 | } // namespace mlir 19 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/MemristorPasses.td: -------------------------------------------------------------------------------- 1 | //===- Passes.td - Memristor dialect passes ---------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Memristor dialect conversion passes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef MEMRISTOR_CONVERSION_PASSES 8 | #define MEMRISTOR_CONVERSION_PASSES 9 | 10 | include "mlir/Pass/PassBase.td" 11 | 12 | def ConvertMemristorToFunc : Pass<"convert-memristor-to-func", operation="func::FuncOp"> { 13 | let summary = "Convert memristor dialect to func dialect"; 14 | let constructor = "mlir::memristor::createConvertMemristorToFuncPass()"; 15 | let dependentDialects = ["memristor::MemristorDialect", "func::FuncDialect", 16 | "memref::MemRefDialect", "tensor::TensorDialect"]; 17 | } 18 | 19 | #endif // MEMRISTOR_CONVERSION_PASSES 20 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/MemristorToFunc/MemristorToFunc.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "cinm-mlir/Dialect/Memristor/IR/MemristorDialect.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace mlir::memristor { 10 | void populateMemristorToFuncConversionPatterns(RewritePatternSet &patterns, 11 | MLIRContext *context); 12 | std::unique_ptr createConvertMemristorToFuncPass(); 13 | } // namespace mlir::memristor -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/TorchToCinm/TorchToCinm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinm-mlir/Dialect/Cinm/IR/CinmDialect.h" 3 | 4 | #include 5 | #include 6 | 7 | namespace mlir::cinm_frontend { 8 | std::unique_ptr createConvertTorchToCinmPass(); 9 | } // namespace mlir::cinm_frontend -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/UPMEMPasses.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the conversion pass within UPMEM dialect. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Conversion/UPMEMToLLVM/UPMEMToLLVM.h" 8 | #include "mlir/IR/BuiltinOps.h" 9 | #include "mlir/Pass/Pass.h" 10 | #include "mlir/Dialect/Func/IR/FuncOps.h" 11 | 12 | 13 | namespace mlir { 14 | 15 | //===- Generated passes ---------------------------------------------------===// 16 | 17 | #define GEN_PASS_REGISTRATION 18 | #include "cinm-mlir/Conversion/UPMEMPasses.h.inc" 19 | 20 | //===----------------------------------------------------------------------===// 21 | 22 | } -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/UPMEMPasses.td: -------------------------------------------------------------------------------- 1 | //===- Passes.td - UPMEM dialect passes ---------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the UPMEM dialect conversion passes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef UPMEM_CONVERSION_PASSES 8 | #define UPMEM_CONVERSION_PASSES 9 | 10 | include "mlir/Pass/PassBase.td" 11 | 12 | def ConvertUPMEMToLLVMPass : Pass<"convert-upmem-to-llvm", "ModuleOp"> { 13 | let summary = ""; 14 | let constructor = "mlir::upmem::createConvertUPMEMToLLVMPass()"; 15 | let dependentDialects = [ 16 | "mlir::LLVM::LLVMDialect", 17 | "mlir::affine::AffineDialect", 18 | "mlir::arith::ArithDialect", 19 | "mlir::memref::MemRefDialect", 20 | "mlir::tensor::TensorDialect", 21 | "mlir::upmem::UPMEMDialect" 22 | ]; 23 | } 24 | 25 | 26 | #endif // UPMEM_CONVERSION_PASSES//===- Passes.td - UPMEM dialect passes ---------------------*- tablegen -*-===// -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Conversion/UPMEMToLLVM/UPMEMToLLVM.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMDialect.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace mlir::upmem { 9 | 10 | void populateUPMEMToLLVMFinalTypeConversions(LLVMTypeConverter &typeConverter); 11 | 12 | void populateUPMEMToLLVMConversionPatterns(LLVMTypeConverter &typeConverter, 13 | RewritePatternSet &patterns); 14 | 15 | std::unique_ptr createConvertUPMEMToLLVMPass(); 16 | 17 | void registerConvertUpmemToLLvmInterface(DialectRegistry ®istry); 18 | } // namespace mlir::upmem 19 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(MLIRUtils) 2 | 3 | add_subdirectory(Cinm) 4 | add_subdirectory(Cim) 5 | add_subdirectory(Cnm) 6 | 7 | add_subdirectory(Memristor) 8 | add_subdirectory(UPMEM) 9 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cim/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # CimIncGen 3 | # 4 | # MLIR Cim dialect generated includes. 5 | ################################################################################ 6 | 7 | add_custom_target(CimIncGen) 8 | 9 | # Attributes, Dialect, Operations and Types. 10 | add_subdirectory(IR) 11 | add_subdirectory(Transforms) 12 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cim/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mlir_gen_ir(Cim) 2 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cim/IR/CimAttributes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Cim dialect attributes. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Dialect/Cim/IR/CimBase.h" 8 | #include "mlir/IR/Attributes.h" 9 | 10 | //===- Generated includes -------------------------------------------------===// 11 | 12 | #define GET_ATTRDEF_CLASSES 13 | #include "cinm-mlir/Dialect/Cim/IR/CimAttributes.h.inc" 14 | 15 | //===----------------------------------------------------------------------===// 16 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cim/IR/CimAttributes.td: -------------------------------------------------------------------------------- 1 | //===- Attributes.td - Cim dialect attributes --------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Cim dialect attributes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef CIM_ATTRIBUTES 8 | #define CIM_ATTRIBUTES 9 | 10 | include "cinm-mlir/Dialect/Cim/IR/CimBase.td" 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cim/IR/CimBase.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Cim dialect base. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "mlir/IR/BuiltinAttributes.h" 8 | #include "mlir/IR/BuiltinTypes.h" 9 | #include "mlir/IR/Dialect.h" 10 | 11 | //===- Generated includes -------------------------------------------------===// 12 | 13 | #include "cinm-mlir/Dialect/Cim/IR/CimBase.h.inc" 14 | 15 | //===----------------------------------------------------------------------===// 16 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cim/IR/CimBase.td: -------------------------------------------------------------------------------- 1 | //===- Base.td - Cim dialect base ------------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Cim dialect base. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef CIM_BASE 8 | #define CIM_BASE 9 | 10 | include "mlir/IR/BuiltinAttributes.td" 11 | include "mlir/IR/BuiltinTypes.td" 12 | include "mlir/IR/OpBase.td" 13 | 14 | def Cim_Dialect : Dialect { 15 | let name = "cim"; 16 | let cppNamespace = "::mlir::cim"; 17 | 18 | let summary = "TODO"; 19 | let description = [{ 20 | TODO 21 | }]; 22 | 23 | let useDefaultTypePrinterParser = 1; 24 | 25 | code extraClassDeclaration = [{ 26 | private: 27 | void registerOps(); 28 | void registerTypes(); 29 | }]; 30 | } 31 | 32 | // Template for attributes. 33 | class Cim_Attr traits = []> 34 | : AttrDef; 35 | 36 | // Template for ops. 37 | class Cim_Op traits = []> 38 | : Op; 39 | 40 | // Template for types. 41 | class Cim_Type traits = []> 42 | : TypeDef; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cim/IR/CimDialect.h: -------------------------------------------------------------------------------- 1 | /// Convenience include for the Cim dialect. 2 | /// 3 | 4 | #pragma once 5 | 6 | #include "cinm-mlir/Dialect/Cim/IR/CimOps.h" 7 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cim/IR/CimOps.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Cim dialect ops. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Dialect/Cim/IR/CimTypes.h" 8 | #include "mlir/Bytecode/BytecodeOpInterface.h" 9 | #include "mlir/IR/OpDefinition.h" 10 | #include "mlir/IR/OpImplementation.h" 11 | #include "mlir/IR/Region.h" 12 | #include "mlir/Interfaces/InferTypeOpInterface.h" 13 | 14 | //===- Generated includes -------------------------------------------------===// 15 | 16 | #define GET_OP_CLASSES 17 | #include "cinm-mlir/Dialect/Cim/IR/CimOps.h.inc" 18 | 19 | //===----------------------------------------------------------------------===// 20 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cim/IR/CimTypes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Cim dialect types. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Dialect/Cim/IR/CimAttributes.h" 8 | #include "mlir/Dialect/Utils/IndexingUtils.h" 9 | 10 | //===- Generated includes -------------------------------------------------===// 11 | 12 | #define GET_TYPEDEF_CLASSES 13 | #include "cinm-mlir/Dialect/Cim/IR/CimTypes.h.inc" 14 | 15 | //===----------------------------------------------------------------------===// 16 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cim/IR/CimTypes.td: -------------------------------------------------------------------------------- 1 | //===- Types.td - Cim dialect types ------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Cim dialect types. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef CIM_TYPES 8 | #define CIM_TYPES 9 | 10 | include "mlir/IR/BuiltinTypeInterfaces.td" 11 | include "CimBase.td" 12 | 13 | def DeviceIdType : Cim_Type<"DeviceId"> { 14 | let mnemonic = "deviceId"; 15 | let summary = "Represents an acquired cim device."; 16 | } 17 | 18 | def CrossbarIdType : Cim_Type<"CrossbarId"> { 19 | let mnemonic = "crossbarId"; 20 | let summary = "Represents an acquired cim crossbar."; 21 | } 22 | 23 | def FutureType : Cim_Type<"Future", [ShapedTypeInterface]> { 24 | let mnemonic = "future"; 25 | let summary = "Result of a cim operation"; 26 | 27 | let parameters = (ins ArrayRefParameter<"int64_t">:$shape, "Type":$elementType); 28 | 29 | let hasCustomAssemblyFormat = 1; 30 | 31 | let builders = [TypeBuilderWithInferredContext< 32 | (ins "ArrayRef":$shape, "Type": $elementType), 33 | [{ return $_get(elementType.getContext(), shape, elementType); }] 34 | >]; 35 | 36 | let extraClassDeclaration = [{ 37 | bool hasRank() const { return true; } 38 | 39 | ShapedType cloneWith(::std::optional<::llvm::ArrayRef> newShape, ::mlir::Type elementType) { 40 | auto shape = newShape.value_or(getShape()); 41 | return FutureType::get(getContext(), shape, elementType); 42 | } 43 | 44 | int64_t getItemCount() { 45 | auto shape = getShape(); 46 | return shape.empty() ? 1 : mlir::computeProduct(shape); 47 | } 48 | 49 | int64_t getSizeInBytes() { 50 | return getItemCount() * getElementTypeBitWidth() / 8; 51 | } 52 | }]; 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cim/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name CimTransforms) 3 | add_public_tablegen_target(CimTransformPassesIncGen) 4 | 5 | add_mlir_doc(Passes CimTransformPasses ./ -gen-pass-doc) 6 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cim/Transforms/Passes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the transform pass within Cim dialect. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | #include "cinm-mlir/Dialect/Cim/IR/CimOps.h" 11 | 12 | namespace mlir { 13 | namespace cim { 14 | 15 | //===- Generated passes ---------------------------------------------------===// 16 | 17 | #define GEN_PASS_DECL 18 | #define GEN_PASS_REGISTRATION 19 | #include "cinm-mlir/Dialect/Cim/Transforms/Passes.h.inc" 20 | //===----------------------------------------------------------------------===// 21 | } // namespace cim 22 | } // namespace mlir 23 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cim/Transforms/Passes.td: -------------------------------------------------------------------------------- 1 | //===- Passes.td - Cim dialect passes ---------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Cim dialect transform passes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef CIM_TRANSFORM_PASSES 8 | #define CIM_TRANSFORM_PASSES 9 | 10 | include "mlir/Pass/PassBase.td" 11 | 12 | def CimScheduleAsapPass : Pass<"cim-schedule-asap", "func::FuncOp"> { 13 | let summary = "Insert barriers to enforce as soon as possible scheduling."; 14 | let description = [{}]; 15 | let dependentDialects = []; 16 | } 17 | 18 | def CimScheduleAlapPass : Pass<"cim-schedule-alap", "func::FuncOp"> { 19 | let summary = "Insert barriers to enforce as late as possible scheduling."; 20 | let description = [{}]; 21 | let dependentDialects = []; 22 | } 23 | 24 | #endif // CIM_TRANSFORM_PASSES 25 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cinm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # CinmIncGen 3 | # 4 | # MLIR Cinm dialect generated includes. 5 | ################################################################################ 6 | 7 | add_custom_target(CinmIncGen) 8 | 9 | # Attributes, Dialect, Operations and Types. 10 | add_subdirectory(Interfaces) 11 | add_subdirectory(IR) 12 | add_subdirectory(Transforms) 13 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cinm/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mlir_gen_ir(Cinm) 2 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cinm/IR/CinmAttributes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Cinm dialect attributes. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Dialect/Cinm/IR/CinmBase.h" 8 | #include "mlir/IR/Attributes.h" 9 | #include 10 | 11 | //===- Generated includes -------------------------------------------------===// 12 | 13 | #include "cinm-mlir/Dialect/Cinm/IR/CinmEnums.h.inc" 14 | #define GET_ATTRDEF_CLASSES 15 | #include "cinm-mlir/Dialect/Cinm/IR/CinmAttributes.h.inc" 16 | 17 | //===----------------------------------------------------------------------===// 18 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cinm/IR/CinmAttributes.td: -------------------------------------------------------------------------------- 1 | //===- Attributes.td - Cinm dialect attributes --------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Cinm dialect attributes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef CINM_ATTRIBUTES 8 | #define CINM_ATTRIBUTES 9 | 10 | include "cinm-mlir/Dialect/Cinm/IR/CinmBase.td" 11 | 12 | include "mlir/IR/EnumAttr.td" 13 | include "mlir/IR/CommonAttrConstraints.td" 14 | 15 | def Cinm_ScanMethodAttr : I64EnumAttr< 16 | "ScanMethod", "", 17 | [ 18 | I64EnumAttrCase<"ADD", 0, "add">, 19 | I64EnumAttrCase<"MUL", 1, "mul"> 20 | ]> { 21 | let cppNamespace = "::mlir::cinm"; 22 | } 23 | 24 | def Cinm_ReduceMethodAttr : I64EnumAttr< 25 | "ReduceMethod", "", 26 | [ 27 | I64EnumAttrCase<"ADD", 0, "add">, 28 | I64EnumAttrCase<"MUL", 1, "mul">, 29 | I64EnumAttrCase<"MAX", 2, "max">, 30 | I64EnumAttrCase<"MIN", 3, "min">, 31 | ]> { 32 | let cppNamespace = "::mlir::cinm"; 33 | } 34 | 35 | 36 | def Cinm_SimilarityMetricAttr : I64EnumAttr< 37 | "SimilarityMetric", "", 38 | [ 39 | // dot product similarity 40 | I64EnumAttrCase<"DOT", 0, "dot">, 41 | // cosine similarity 42 | I64EnumAttrCase<"COS", 1, "cos"> 43 | ]> { 44 | let cppNamespace = "::mlir::cinm"; 45 | } 46 | 47 | //def Cinm_SimilarityMetricAttr : EnumAttr; 48 | //def Cinm_ReduceMethodAttr : EnumAttr; 49 | //def Cinm_ScanMethodAttr : EnumAttr; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cinm/IR/CinmBase.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Cinm dialect base. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "mlir/IR/BuiltinAttributes.h" 8 | #include "mlir/IR/BuiltinTypes.h" 9 | #include "mlir/IR/Dialect.h" 10 | 11 | //===- Generated includes -------------------------------------------------===// 12 | 13 | #include "cinm-mlir/Dialect/Cinm/IR/CinmBase.h.inc" 14 | 15 | //===----------------------------------------------------------------------===// 16 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cinm/IR/CinmBase.td: -------------------------------------------------------------------------------- 1 | //===- Base.td - Cinm dialect base ------------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Cinm dialect base. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef CINM_BASE 8 | #define CINM_BASE 9 | 10 | include "mlir/IR/BuiltinAttributes.td" 11 | include "mlir/IR/BuiltinTypes.td" 12 | include "mlir/IR/OpBase.td" 13 | 14 | def Cinm_Dialect : Dialect { 15 | let name = "cinm"; 16 | let cppNamespace = "::mlir::cinm"; 17 | 18 | let summary = "TODO"; 19 | let description = [{ 20 | TODO 21 | }]; 22 | 23 | let usePropertiesForAttributes = 0; 24 | let useDefaultAttributePrinterParser = 1; 25 | // let useDefaultTypePrinterParser = 1; 26 | let hasOperationAttrVerify = 1; 27 | 28 | 29 | code extraClassDeclaration = [{ 30 | constexpr static StringRef NOTILE_NAME = "cinm.notile"; 31 | private: 32 | void registerOps(); 33 | void registerTypes(); 34 | }]; 35 | } 36 | 37 | // Template for attributes. 38 | class Cinm_Attr traits = []> 39 | : AttrDef; 40 | // Template for ops. 41 | class Cinm_Base_Op traits = []> 42 | : Op; 43 | 44 | class Cinm_Op traits = []> 45 | : Cinm_Base_Op 48 | ])>; 49 | // Template for types. 50 | class Cinm_Type traits = []> 51 | : TypeDef; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cinm/IR/CinmDialect.h: -------------------------------------------------------------------------------- 1 | /// Convenience include for the Cinm dialect. 2 | /// 3 | 4 | #pragma once 5 | 6 | #include "cinm-mlir/Dialect/Cinm/IR/CinmOps.h" 7 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cinm/IR/CinmOps.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Cinm dialect ops. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Dialect/Cinm/IR/CinmTypes.h" 8 | #include "cinm-mlir/Dialect/Cinm/Interfaces/TilingInterface.h" 9 | #include "cinm-mlir/Dialect/Cnm/IR/CnmTypes.h" 10 | 11 | #include "mlir/Bytecode/BytecodeOpInterface.h" 12 | #include "mlir/IR/Builders.h" 13 | #include "mlir/IR/BuiltinTypes.h" 14 | #include "mlir/IR/Dialect.h" 15 | #include "mlir/IR/OpImplementation.h" 16 | #include "mlir/Interfaces/ControlFlowInterfaces.h" 17 | #include "mlir/Interfaces/InferTypeOpInterface.h" 18 | #include "mlir/Interfaces/SideEffectInterfaces.h" 19 | 20 | 21 | //===- Generated includes -------------------------------------------------===// 22 | 23 | #define GET_OP_CLASSES 24 | #include "cinm-mlir/Dialect/Cinm/IR/CinmOps.h.inc" 25 | 26 | //===----------------------------------------------------------------------===// 27 | 28 | namespace mlir::cinm { 29 | 30 | cinm::ComputeOp getEnclosingComputeBlock(Operation *op); 31 | 32 | } // namespace mlir::cinm -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cinm/IR/CinmTypes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Cinm dialect types. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Dialect/Cinm/IR/CinmAttributes.h" 8 | 9 | 10 | //===- Generated includes -------------------------------------------------===// 11 | 12 | #define GET_TYPEDEF_CLASSES 13 | #include "cinm-mlir/Dialect/Cinm/IR/CinmTypes.h.inc" 14 | 15 | //===----------------------------------------------------------------------===// 16 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cinm/IR/CinmTypes.td: -------------------------------------------------------------------------------- 1 | //===- Types.td - Cinm dialect types ------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Cinm dialect types. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef CINM_TYPES 8 | #define CINM_TYPES 9 | 10 | include "mlir/IR/BuiltinTypeInterfaces.td" 11 | 12 | 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cinm/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mlir_gen_iface(Cinm TilingInterface op) 2 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cinm/Interfaces/TilingInterface.td: -------------------------------------------------------------------------------- 1 | //===- TilingInterface.td -----------------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the cinm TilingInterface. 4 | // 5 | //===-----------------------------------------------------------------===// 6 | 7 | #ifndef CINM_TILING_INTERFACE 8 | #define CINM_TILING_INTERFACE 9 | 10 | include "mlir/IR/OpBase.td" 11 | 12 | def CinmTilingInterface : OpInterface<"CinmTilingInterface"> { 13 | let cppNamespace = "::mlir::cinm"; 14 | 15 | let description = [{ 16 | }]; 17 | 18 | let methods = [ 19 | InterfaceMethod< 20 | /*desc=*/ [{ 21 | }], 22 | /*retTy=*/ "FailureOr>", 23 | /*methodName=*/ "convertToTiledOps", 24 | /*args=*/ (ins "OpBuilder&":$builder, "TilingParameters":$params), 25 | /*methodBody=*/ "", 26 | /*defaultImplementation=*/ "">]; 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cinm/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name CinmTransforms) 3 | add_public_tablegen_target(CinmTransformPassesIncGen) 4 | 5 | add_mlir_doc(Passes CinmTransformPasses ./ -gen-pass-doc) 6 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cinm/Transforms/Passes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the transform pass within Cinm dialect. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "mlir/Pass/Pass.h" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace mlir::cinm { 15 | 16 | //===- Generated passes ---------------------------------------------------===// 17 | 18 | #define GEN_PASS_DECL 19 | #define GEN_PASS_REGISTRATION 20 | #include "cinm-mlir/Dialect/Cinm/Transforms/Passes.h.inc" 21 | 22 | //===----------------------------------------------------------------------===// 23 | 24 | } // namespace mlir::cinm 25 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cinm/Transforms/Passes.td: -------------------------------------------------------------------------------- 1 | //===- Passes.td - Cinm dialect passes ---------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Cinm dialect transform passes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef CINM_TRANSFORM_PASSES 8 | #define CINM_TRANSFORM_PASSES 9 | 10 | include "mlir/Pass/PassBase.td" 11 | 12 | def CinmTilingPass: Pass<"cinm-tiling"> { 13 | let summary = "Applys tiling to all operations implementing the cinm tiling interface"; 14 | let description = [{}]; 15 | 16 | let dependentDialects = [ 17 | "mlir::LLVM::LLVMDialect", 18 | "mlir::affine::AffineDialect", 19 | "mlir::bufferization::BufferizationDialect", 20 | "mlir::linalg::LinalgDialect", 21 | "mlir::tensor::TensorDialect" 22 | ]; 23 | } 24 | 25 | def SoftmaxToCinmPass: Pass<"softmax-to-cinm"> { 26 | let summary = "converts the linalg::softmax op to cinm"; 27 | let description = [{}]; 28 | 29 | let dependentDialects = [ 30 | "mlir::LLVM::LLVMDialect", 31 | "mlir::linalg::LinalgDialect", 32 | ]; 33 | } 34 | 35 | #endif // CINM_TRANSFORM_PASSES 36 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cnm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # CnmIncGen 3 | # 4 | # MLIR Cnm dialect generated includes. 5 | ################################################################################ 6 | 7 | add_custom_target(CnmIncGen) 8 | 9 | # Attributes, Dialect, Operations and Types. 10 | add_subdirectory(IR) 11 | add_subdirectory(Transforms) 12 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cnm/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mlir_gen_ir(Cnm) 2 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cnm/IR/CnmAttributes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Cnm dialect attributes. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Dialect/Cnm/IR/CnmBase.h" 8 | #include "mlir/IR/Attributes.h" 9 | 10 | //===- Generated includes -------------------------------------------------===// 11 | 12 | #define GET_ATTRDEF_CLASSES 13 | #include "cinm-mlir/Dialect/Cnm/IR/CnmAttributes.h.inc" 14 | 15 | //===----------------------------------------------------------------------===// 16 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cnm/IR/CnmAttributes.td: -------------------------------------------------------------------------------- 1 | //===- Attributes.td - Cnm dialect attributes --------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Cnm dialect attributes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef CNM_ATTRIBUTES 8 | #define CNM_ATTRIBUTES 9 | 10 | include "cinm-mlir/Dialect/Cnm/IR/CnmBase.td" 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cnm/IR/CnmBase.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Cnm dialect base. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "mlir/IR/BuiltinAttributes.h" 8 | #include "mlir/IR/BuiltinTypes.h" 9 | #include "mlir/IR/Dialect.h" 10 | 11 | //===- Generated includes -------------------------------------------------===// 12 | 13 | #include "cinm-mlir/Dialect/Cnm/IR/CnmBase.h.inc" 14 | 15 | //===----------------------------------------------------------------------===// 16 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cnm/IR/CnmBase.td: -------------------------------------------------------------------------------- 1 | //===- Base.td - Cnm dialect base ------------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Cnm dialect base. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef CNM_BASE 8 | #define CNM_BASE 9 | 10 | include "mlir/IR/BuiltinAttributes.td" 11 | include "mlir/IR/BuiltinTypes.td" 12 | include "mlir/IR/OpBase.td" 13 | 14 | def Cnm_Dialect : Dialect { 15 | let name = "cnm"; 16 | let cppNamespace = "::mlir::cnm"; 17 | 18 | let summary = "TODO"; 19 | let description = [{ 20 | TODO 21 | }]; 22 | 23 | let useDefaultTypePrinterParser = 1; 24 | 25 | code extraClassDeclaration = [{ 26 | private: 27 | void registerOps(); 28 | void registerTypes(); 29 | }]; 30 | } 31 | 32 | // Template for attributes. 33 | class Cnm_Attr traits = []> 34 | : AttrDef; 35 | 36 | // Template for ops. 37 | class Cnm_Op traits = []> 38 | : Op; 39 | 40 | // Template for types. 41 | class Cnm_Type traits = []> 42 | : TypeDef; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cnm/IR/CnmDialect.h: -------------------------------------------------------------------------------- 1 | /// Convenience include for the Cnm dialect. 2 | /// 3 | 4 | #pragma once 5 | 6 | #include "cinm-mlir/Dialect/Cnm/IR/CnmOps.h" 7 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cnm/IR/CnmOps.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Cnm dialect ops. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Dialect/Cnm/IR/CnmTypes.h" 8 | 9 | #include "mlir/IR/Builders.h" 10 | #include "mlir/IR/BuiltinTypes.h" 11 | #include "mlir/IR/Dialect.h" 12 | #include "mlir/IR/OpImplementation.h" 13 | #include "mlir/Interfaces/ControlFlowInterfaces.h" 14 | #include "mlir/Interfaces/InferTypeOpInterface.h" 15 | #include "mlir/Interfaces/SideEffectInterfaces.h" 16 | #include "mlir/Bytecode/BytecodeOpInterface.h" 17 | #include "mlir/IR/AffineMap.h" 18 | #include "mlir/Dialect/Utils/IndexingUtils.h" 19 | #include "mlir/Dialect/Bufferization/IR/Bufferization.h" 20 | 21 | 22 | //===- Generated includes -------------------------------------------------===// 23 | 24 | #define GET_OP_CLASSES 25 | #include "cinm-mlir/Dialect/Cnm/IR/CnmOps.h.inc" 26 | 27 | //===----------------------------------------------------------------------===// 28 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cnm/IR/CnmTypes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Cnm dialect types. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Dialect/Cnm/IR/CnmAttributes.h" 8 | #include "mlir/Dialect/Utils/IndexingUtils.h" 9 | #include 10 | #include 11 | 12 | //===- Generated includes -------------------------------------------------===// 13 | 14 | #define GET_TYPEDEF_CLASSES 15 | #include "cinm-mlir/Dialect/Cnm/IR/CnmTypes.h.inc" 16 | 17 | //===----------------------------------------------------------------------===// 18 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cnm/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name CnmTransforms) 3 | add_public_tablegen_target(CnmTransformPassesIncGen) 4 | 5 | add_mlir_doc(Passes CnmTransformPasses ./ -gen-pass-doc) 6 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Cnm/Transforms/Passes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the transform pass within Cnm dialect. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "mlir/Pass/Pass.h" 8 | 9 | namespace mlir { 10 | namespace cnm { 11 | 12 | void registerCnmBufferizationExternalModels(DialectRegistry ®istry); 13 | 14 | //===- Generated passes ---------------------------------------------------===// 15 | 16 | #define GEN_PASS_DECL 17 | #define GEN_PASS_REGISTRATION 18 | #include "cinm-mlir/Dialect/Cnm/Transforms/Passes.h.inc" 19 | //===----------------------------------------------------------------------===// 20 | 21 | } // namespace cnm 22 | } // namespace mlir 23 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Memristor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # MemristorIncGen 3 | # 4 | # MLIR Memristor dialect generated includes. 5 | ################################################################################ 6 | 7 | add_custom_target(MemristorIncGen) 8 | 9 | # Attributes, Dialect, Operations and Types. 10 | add_subdirectory(IR) 11 | add_subdirectory(Transforms) 12 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Memristor/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mlir_gen_ir(Memristor) 2 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Memristor/IR/MemristorAttributes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Memristor dialect attributes. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Dialect/Memristor/IR/MemristorBase.h" 8 | #include "mlir/IR/Attributes.h" 9 | 10 | //===- Generated includes -------------------------------------------------===// 11 | 12 | #define GET_ATTRDEF_CLASSES 13 | #include "cinm-mlir/Dialect/Memristor/IR/MemristorAttributes.h.inc" 14 | 15 | //===----------------------------------------------------------------------===// 16 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Memristor/IR/MemristorAttributes.td: -------------------------------------------------------------------------------- 1 | //===- Attributes.td - Memristor dialect attributes --------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Memristor dialect attributes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef MEMRISTOR_ATTRIBUTES 8 | #define MEMRISTOR_ATTRIBUTES 9 | 10 | include "cinm-mlir/Dialect/Memristor/IR/MemristorBase.td" 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Memristor/IR/MemristorBase.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Memristor dialect base. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "mlir/IR/BuiltinAttributes.h" 8 | #include "mlir/IR/BuiltinTypes.h" 9 | #include "mlir/IR/Dialect.h" 10 | 11 | //===- Generated includes -------------------------------------------------===// 12 | 13 | #include "cinm-mlir/Dialect/Memristor/IR/MemristorBase.h.inc" 14 | 15 | //===----------------------------------------------------------------------===// 16 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Memristor/IR/MemristorBase.td: -------------------------------------------------------------------------------- 1 | //===- Base.td - Memristor dialect base ------------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Memristor dialect base. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef MEMRISTOR_BASE 8 | #define MEMRISTOR_BASE 9 | 10 | include "mlir/IR/BuiltinAttributes.td" 11 | include "mlir/IR/BuiltinTypes.td" 12 | include "mlir/IR/OpBase.td" 13 | 14 | def Memristor_Dialect : Dialect { 15 | let name = "memristor"; 16 | let cppNamespace = "::mlir::memristor"; 17 | 18 | let summary = "TODO"; 19 | let description = [{ 20 | TODO 21 | }]; 22 | 23 | code extraClassDeclaration = [{ 24 | private: 25 | void registerOps(); 26 | }]; 27 | } 28 | 29 | // Template for attributes. 30 | class Memristor_Attr traits = []> 31 | : AttrDef; 32 | 33 | // Template for ops. 34 | class Memristor_Op traits = []> 35 | : Op { 36 | code libraryCallName = [{ 37 | std::string getLibraryCallName() { 38 | return generateLibraryCallName(getOperation()); 39 | } 40 | }]; 41 | 42 | let extraClassDeclaration = libraryCallName; 43 | } 44 | 45 | // Template for types. 46 | class Memristor_Type traits = []> 47 | : TypeDef; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Memristor/IR/MemristorDialect.h: -------------------------------------------------------------------------------- 1 | /// Convenience include for the Memristor dialect. 2 | /// 3 | 4 | #pragma once 5 | 6 | #include "cinm-mlir/Dialect/Memristor/IR/MemristorOps.h" 7 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Memristor/IR/MemristorOps.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Memristor dialect ops. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Dialect/Memristor/IR/MemristorTypes.h" 8 | #include "mlir/IR/OpDefinition.h" 9 | #include "mlir/IR/OpImplementation.h" 10 | #include "mlir/IR/Region.h" 11 | #include "mlir/Interfaces/InferTypeOpInterface.h" 12 | 13 | namespace mlir::memristor { 14 | std::string generateLibraryCallName(Operation *op); 15 | void appendOperandPrecision(llvm::raw_string_ostream &ss, Type t); 16 | } // namespace mlir::memristor 17 | 18 | //===- Generated includes -------------------------------------------------===// 19 | 20 | #define GET_OP_CLASSES 21 | #include "cinm-mlir/Dialect/Memristor/IR/MemristorOps.h.inc" 22 | 23 | //===----------------------------------------------------------------------===// 24 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Memristor/IR/MemristorTypes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the Memristor dialect types. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Dialect/Memristor/IR/MemristorAttributes.h" 8 | #include "mlir/Dialect/Utils/IndexingUtils.h" 9 | 10 | //===- Generated includes -------------------------------------------------===// 11 | 12 | #define GET_TYPEDEF_CLASSES 13 | #include "cinm-mlir/Dialect/Memristor/IR/MemristorTypes.h.inc" 14 | 15 | //===----------------------------------------------------------------------===// 16 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Memristor/IR/MemristorTypes.td: -------------------------------------------------------------------------------- 1 | //===- Types.td - Memristor dialect types ------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Memristor dialect types. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef MEMRISTOR_TYPES 8 | #define MEMRISTOR_TYPES 9 | 10 | include "mlir/IR/BuiltinTypeInterfaces.td" 11 | include "MemristorBase.td" 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Memristor/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name MemristorTransforms) 3 | add_public_tablegen_target(MemristorTransformPassesIncGen) 4 | 5 | add_mlir_doc(Passes MemristorTransformPasses ./ -gen-pass-doc) 6 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Memristor/Transforms/Passes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the transform pass within Memristor dialect. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "mlir/Pass/Pass.h" 8 | #include 9 | 10 | namespace mlir { 11 | namespace memristor { 12 | 13 | //===- Generated passes ---------------------------------------------------===// 14 | 15 | #define GEN_PASS_DECL 16 | #define GEN_PASS_REGISTRATION 17 | #include "cinm-mlir/Dialect/Memristor/Transforms/Passes.h.inc" 18 | //===----------------------------------------------------------------------===// 19 | 20 | void populateMemristorScheduleAsapPatterns(RewritePatternSet &patterns, 21 | MLIRContext *ctx); 22 | bool memristorScheduleAsapCheckDynamicallyLegal(Operation *op); 23 | void populateMemristorScheduleAlapPatterns(RewritePatternSet &patterns, 24 | MLIRContext *ctx); 25 | bool memristorScheduleAlapCheckDynamicallyLegal(Operation *op); 26 | 27 | void populateMemristorEraseRedundantBarriersPatterns( 28 | RewritePatternSet &patterns, MLIRContext *ctx); 29 | 30 | bool isMemristorOp(Operation *op); 31 | bool isMemristorFuture(Value v); 32 | bool isLegalOp(Operation *op); 33 | bool isLegalBarrier(Operation *op); 34 | 35 | struct MemristorEraseRedundantBarriersPattern; 36 | 37 | } // namespace memristor 38 | } // namespace mlir 39 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/Memristor/Transforms/Passes.td: -------------------------------------------------------------------------------- 1 | //===- Passes.td - Memristor dialect passes ---------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the Memristor dialect transform passes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef MEMRISTOR_TRANSFORM_PASSES 8 | #define MEMRISTOR_TRANSFORM_PASSES 9 | 10 | include "mlir/Pass/PassBase.td" 11 | 12 | #endif // MEMRISTOR_TRANSFORM_PASSES 13 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/UPMEM/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # UPMEMIncGen 3 | # 4 | # MLIR UPMEM dialect generated includes. 5 | ################################################################################ 6 | 7 | add_custom_target(UPMEMIncGen) 8 | 9 | # Attributes, Dialect, Operations and Types. 10 | add_subdirectory(IR) 11 | add_subdirectory(Transforms) 12 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/UPMEM/IR/AsyncOpInterface.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "mlir/IR/OpDefinition.h" 5 | 6 | //===- Generated includes -------------------------------------------------===// 7 | namespace mlir { 8 | namespace upmem { 9 | // Adds a `upmem.async.token` to the front of the argument list. 10 | void addAsyncDependency(Operation *op, Value token); 11 | } // namespace upmem 12 | } // namespace mlir 13 | 14 | #include "cinm-mlir/Dialect/UPMEM/IR/AsyncOpInterface.h.inc" 15 | 16 | //===----------------------------------------------------------------------===// 17 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/UPMEM/IR/AsyncOpInterface.td: -------------------------------------------------------------------------------- 1 | include "UPMEMBase.td" 2 | 3 | def UPMEM_AsyncOpInterface : OpInterface<"AsyncOpInterface"> { 4 | let description = [{ 5 | Interface for UPMEM operations that execute asynchronously on the device. 6 | 7 | UPMEM operations implementing this interface take a list of dependencies 8 | as `upmem.async.token` arguments and optionally return a `upmem.async.token`. 9 | 10 | The op doesn't start executing until all depent ops producing the async 11 | dependency tokens have finished executing. 12 | 13 | If the op returns a token, the op merely schedules the execution on the 14 | device and returns immediately, without waiting for the execution to 15 | complete. On the hand, if the op does not return a token, the op will wait 16 | for the execution to complete. 17 | }]; 18 | let cppNamespace = "::mlir::upmem"; 19 | 20 | let methods = [ 21 | InterfaceMethod<[{ 22 | Query the operands that represent async dependency tokens. 23 | }], 24 | "OperandRange", "getAsyncDependencies", (ins), [{}], [{ 25 | ConcreteOp op = cast(this->getOperation()); 26 | return op.getAsyncDependencies(); 27 | }] 28 | >, 29 | InterfaceMethod<[{ 30 | Adds a new token to the list of async dependencies if it is not already there. 31 | }], 32 | "void", "addAsyncDependency", (ins "Value":$token), 33 | [{}], [{ 34 | if (!::llvm::is_contained(this->getAsyncDependencies(), token)) 35 | ::mlir::upmem::addAsyncDependency(this->getOperation(), token); 36 | }] 37 | >, 38 | InterfaceMethod<[{ 39 | Query the result that represents the async token to depend on. 40 | }], 41 | "Value", "getAsyncToken" 42 | > 43 | ]; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/UPMEM/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mlir_gen_ir(UPMEM) 2 | mlir_gen_iface(UPMEM AsyncOpInterface op) -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/UPMEM/IR/UPMEMAttributes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the UPMEM dialect attributes. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMBase.h" 8 | #include "mlir/IR/Attributes.h" 9 | 10 | //===- Generated includes -------------------------------------------------===// 11 | 12 | #define GET_ATTRDEF_CLASSES 13 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMEnums.h.inc" 14 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMAttributes.h.inc" 15 | 16 | //===----------------------------------------------------------------------===// 17 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/UPMEM/IR/UPMEMAttributes.td: -------------------------------------------------------------------------------- 1 | //===- Attributes.td - UPMEM dialect attributes --------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the UPMEM dialect attributes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef UPMEM_ATTRIBUTES 8 | #define UPMEM_ATTRIBUTES 9 | 10 | include "cinm-mlir/Dialect/UPMEM/IR/UPMEMBase.td" 11 | 12 | // def UPMEM_AddressSpaceGlobal : I32EnumAttrCase<"Global", 1, "global">; 13 | // def UPMEM_AddressSpaceWorkgroup : I32EnumAttrCase<"Workgroup", 2, "workgroup">; 14 | // def UPMEM_AddressSpacePrivate : I32EnumAttrCase<"Private", 3, "private">; 15 | // def UPMEM_AddressSpaceEnum : UPMEM_I32Enum< 16 | // "AddressSpace", "UPMEM address space", [ 17 | // UPMEM_AddressSpaceGlobal, 18 | // UPMEM_AddressSpaceWorkgroup, 19 | // UPMEM_AddressSpacePrivate 20 | // ]>; 21 | 22 | // def UPMEM_AddressSpaceAttr : 23 | // UPMEM_I32EnumAttr<"address_space", UPMEM_AddressSpaceEnum>; 24 | 25 | 26 | def UPMEM_MemcpyOpMRAMToWRAM: I32EnumAttrCase<"MRAMToWRAM", 0, "mram_to_wram">; 27 | def UPMEM_MemcpyOpWRAMToMRAM: I32EnumAttrCase<"WRAMToMRAM", 1, "wram_to_mram">; 28 | 29 | def MemcpyDir : I32EnumAttr<"MemcpyDirOp", 30 | "copy operation between wram and mram", [ 31 | UPMEM_MemcpyOpMRAMToWRAM, 32 | UPMEM_MemcpyOpWRAMToMRAM 33 | ]> { 34 | let genSpecializedAttr = 0; 35 | let cppNamespace = "::mlir::upmem"; 36 | } 37 | 38 | def MemcpyDirAttr : EnumAttr; 40 | 41 | 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/UPMEM/IR/UPMEMBase.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the UPMEM dialect base. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "mlir/IR/BuiltinAttributes.h" 8 | #include "mlir/IR/BuiltinTypes.h" 9 | #include "mlir/IR/Dialect.h" 10 | 11 | //===- Generated includes -------------------------------------------------===// 12 | 13 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMBase.h.inc" 14 | 15 | //===----------------------------------------------------------------------===// 16 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/UPMEM/IR/UPMEMDialect.h: -------------------------------------------------------------------------------- 1 | /// Convenience include for the UPMEM dialect. 2 | /// 3 | 4 | #pragma once 5 | 6 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMOps.h" 7 | 8 | 9 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/UPMEM/IR/UPMEMOps.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the UPMEM dialect ops. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Dialect/UPMEM/IR/AsyncOpInterface.h" 8 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMBase.h" 9 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMTypes.h" 10 | 11 | #include "mlir/Bytecode/BytecodeOpInterface.h" 12 | #include "mlir/Dialect/DLTI/Traits.h" 13 | #include "mlir/IR/Builders.h" 14 | #include "mlir/IR/BuiltinTypes.h" 15 | #include "mlir/IR/Dialect.h" 16 | #include "mlir/IR/OpDefinition.h" 17 | #include "mlir/IR/OpImplementation.h" 18 | #include "mlir/IR/RegionKindInterface.h" 19 | #include "mlir/IR/SymbolTable.h" 20 | #include "mlir/Interfaces/ControlFlowInterfaces.h" 21 | #include "mlir/Interfaces/FunctionInterfaces.h" 22 | #include "mlir/Interfaces/InferIntRangeInterface.h" 23 | #include "mlir/Interfaces/InferTypeOpInterface.h" 24 | #include "mlir/Interfaces/SideEffectInterfaces.h" 25 | #include "llvm/ADT/STLExtras.h" 26 | 27 | namespace mlir { 28 | namespace upmem { 29 | 30 | struct KernelDim { 31 | Value x; 32 | }; 33 | 34 | // Adds a `upmem.async.token` to the front of the argument list. 35 | void addAsyncDependency(Operation *op, Value token); 36 | 37 | } // namespace upmem 38 | } // namespace mlir 39 | 40 | //===- Generated includes -------------------------------------------------===// 41 | 42 | #define GET_OP_CLASSES 43 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMOps.h.inc" 44 | 45 | // namespace mlir::upmem 46 | //===----------------------------------------------------------------------===// -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/UPMEM/IR/UPMEMTypes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the UPMEM dialect types. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMAttributes.h" 8 | #include "mlir/Bytecode/BytecodeOpInterface.h" 9 | #include "mlir/Dialect/DLTI/Traits.h" 10 | #include "mlir/IR/Builders.h" 11 | #include "mlir/IR/BuiltinTypes.h" 12 | #include "mlir/IR/Dialect.h" 13 | #include "mlir/IR/OpDefinition.h" 14 | #include "mlir/IR/OpImplementation.h" 15 | #include "mlir/IR/SymbolTable.h" 16 | #include "mlir/Interfaces/FunctionInterfaces.h" 17 | #include "mlir/Interfaces/InferIntRangeInterface.h" 18 | #include "mlir/Interfaces/InferTypeOpInterface.h" 19 | #include "mlir/Interfaces/SideEffectInterfaces.h" 20 | #include "llvm/ADT/STLExtras.h" 21 | #include 22 | 23 | 24 | namespace mlir { 25 | namespace upmem { 26 | 27 | 28 | } // namespace upmem 29 | } // namespace mlir 30 | 31 | 32 | //===- Generated includes -------------------------------------------------===// 33 | 34 | #define GET_TYPEDEF_CLASSES 35 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMTypes.h.inc" 36 | 37 | //===----------------------------------------------------------------------===// 38 | 39 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/UPMEM/IR/UPMEMTypes.td: -------------------------------------------------------------------------------- 1 | //===- Types.td - UPMEM dialect types ------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the UPMEM dialect types. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef UPMEM_TYPES 8 | #define UPMEM_TYPES 9 | 10 | include "mlir/IR/BuiltinTypeInterfaces.td" 11 | include "mlir/IR/AttrTypeBase.td" 12 | include "mlir/IR/EnumAttr.td" 13 | include "mlir/IR/OpBase.td" 14 | include "UPMEMBase.td" 15 | 16 | 17 | def UPMEM_AsyncToken : UPMEM_Type<"AsyncToken"> { 18 | let mnemonic = "async.token"; 19 | let summary = ""; 20 | } 21 | 22 | def DeviceHierarchy : UPMEM_Type<"DeviceHierarchy"> { 23 | let mnemonic = "hierarchy"; 24 | let summary = ""; 25 | 26 | let parameters = (ins ArrayRefParameter<"int64_t">:$shape); 27 | 28 | let hasCustomAssemblyFormat = 1; 29 | let genVerifyDecl = 1; 30 | let extraClassDeclaration = [{ 31 | int64_t getNumElements() { 32 | auto wgShape = getShape(); 33 | return std::reduce(wgShape.begin(), wgShape.end(), 1, std::multiplies<>()); 34 | } 35 | int64_t getNumDims() { return getShape().size();} 36 | 37 | int64_t getNumRanks() { 38 | return getShape()[0]; 39 | } 40 | int64_t getNumDpusPerRank() { 41 | return getShape()[1]; 42 | } 43 | int64_t getNumTaskletsPerDpu() { 44 | return getShape()[2]; 45 | } 46 | }]; 47 | } 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/UPMEM/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name UPMEMTransforms) 3 | add_public_tablegen_target(UPMEMTransformPassesIncGen) 4 | 5 | add_mlir_doc(Passes UPMEMTransformPasses ./ -gen-pass-doc) 6 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/UPMEM/Transforms/Passes.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the transform pass within UPMEM dialect. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "mlir/Pass/Pass.h" 8 | #include "mlir/Dialect/Func/IR/FuncOps.h" 9 | #include "mlir/IR/BuiltinOps.h" 10 | 11 | namespace mlir { 12 | 13 | //===- Generated passes ---------------------------------------------------===// 14 | 15 | #define GEN_PASS_DECL 16 | #define GEN_PASS_REGISTRATION 17 | #include "cinm-mlir/Dialect/UPMEM/Transforms/Passes.h.inc" 18 | 19 | //===----------------------------------------------------------------------===// 20 | 21 | } // namespace mlir 22 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Dialect/UPMEM/Transforms/Passes.td: -------------------------------------------------------------------------------- 1 | //===- Passes.td - UPMEM dialect passes ---------------------*- tablegen -*-===// 2 | // 3 | // This is the definitions file for the UPMEM dialect transform passes. 4 | // 5 | //===----------------------------------------------------------------------===// 6 | 7 | #ifndef UPMEM_TRANSFORM_PASSES 8 | #define UPMEM_TRANSFORM_PASSES 9 | 10 | include "mlir/Pass/PassBase.td" 11 | 12 | 13 | def UPMEMOutlineKernelPass: Pass<"upmem-outline-kernel", "ModuleOp"> { 14 | let summary = "Outlines a launch operation to a kernel and replaces it with a function call"; 15 | let dependentDialects = [ 16 | "::mlir::upmem::UPMEMDialect" 17 | ]; 18 | let description = [{ 19 | }]; 20 | } 21 | 22 | def UPMEMDedupKernelsPass: Pass<"upmem-dedup-kernels", "upmem::UPMEMModuleOp"> { 23 | let summary = "Deduplicate the DPU kernels within an upmem module"; 24 | let description = [{ 25 | }]; 26 | let dependentDialects = [ 27 | "::mlir::upmem::UPMEMDialect" 28 | ]; 29 | } 30 | 31 | #endif // UPMEM_TRANSFORM_PASSES 32 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Target/UPMEMCpp/UPMEMCppEmitter.h: -------------------------------------------------------------------------------- 1 | /// Declaration of the UPMEM CPP emitter. 2 | /// 3 | /// @file 4 | 5 | #pragma once 6 | 7 | #include "mlir/IR/BuiltinTypes.h" 8 | #include "mlir/IR/Value.h" 9 | #include "llvm/ADT/ScopedHashTable.h" 10 | #include "llvm/Support/raw_ostream.h" 11 | #include 12 | 13 | namespace mlir { 14 | namespace upmem_emitc { 15 | 16 | /// Translates the given operation to C++ code. The operation or operations in 17 | /// the region of 'op' need almost all be in EmitC dialect. The parameter 18 | /// 'declareVariablesAtTop' enforces that all variables for op results and block 19 | /// arguments are declared at the beginning of the function. 20 | LogicalResult UPMEMtranslateToCpp(Operation *op, raw_ostream &os, 21 | bool declareVariablesAtTop = false); 22 | 23 | void registerUPMEMCppTranslation(); 24 | } // namespace emitc 25 | } // namespace mlir 26 | -------------------------------------------------------------------------------- /cinnamon/include/cinm-mlir/Utils/CinmUtils.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | namespace mlir { 6 | 7 | SmallString<20> getUniqueFunctionName(SymbolTable &moduleOp, StringRef prefix); 8 | 9 | /// Check that the memref is contiguous in the dimensions corresponding to the 10 | /// bufShape, which is a suffix of the shape of the input tensor/memref. 11 | bool scatteredMemrefIsContiguous(TypedValue value, 12 | llvm::ArrayRef bufShape); 13 | 14 | /// Simplify an affine map given static upper bounds on the inputs. 15 | /// This is used to simplify even more the affine maps on the CNM and UPMEM 16 | /// levels, given knowledge of the workgroup shape. That makes the generated code 17 | /// simpler, and gives more opportunities for broadcasting. 18 | AffineMap simplifyAffineMapWithBounds(AffineMap map, 19 | llvm::ArrayRef dimSizes); 20 | } // namespace mlir 21 | -------------------------------------------------------------------------------- /cinnamon/lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Conversion) 2 | add_subdirectory(Dialect) 3 | add_subdirectory(Target) 4 | add_subdirectory(Utils) -------------------------------------------------------------------------------- /cinnamon/lib/Conversion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_library(CinmCommonPatterns 2 | CommonPatterns.cpp 3 | 4 | LINK_COMPONENTS 5 | Core 6 | 7 | LINK_LIBS PUBLIC 8 | MLIRDialectUtils 9 | ) 10 | 11 | if (TORCH_MLIR_DIR) 12 | add_subdirectory(TorchToCinm) 13 | endif() 14 | if (CINM_BUILD_GPU_SUPPORT) 15 | add_subdirectory(CnmToGPU) 16 | endif() 17 | add_subdirectory(CnmToUPMEM) 18 | add_subdirectory(UPMEMToLLVM) 19 | add_subdirectory(CinmToCnm) 20 | add_subdirectory(CinmToCim) 21 | add_subdirectory(CimToMemristor) 22 | add_subdirectory(MemristorToFunc) 23 | -------------------------------------------------------------------------------- /cinnamon/lib/Conversion/CimToMemristor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_conversion_library(MLIRCimToMemristor 2 | CimToMemristor.cpp 3 | 4 | ADDITIONAL_HEADER_DIRS 5 | ${MLIR_MAIN_INCLUDE_DIR}/cim/Conversion/CimToMemristor 6 | 7 | DEPENDS 8 | CimConversionPassIncGen 9 | MemristorIncGen 10 | 11 | LINK_COMPONENTS 12 | Core 13 | 14 | LINK_LIBS PUBLIC 15 | CimIR 16 | MLIRDialectUtils 17 | MLIRBufferizationDialect 18 | MLIRMemRefDialect 19 | MLIRTensorDialect 20 | MLIRTransformUtils 21 | MLIRReconcileUnrealizedCasts 22 | ) 23 | -------------------------------------------------------------------------------- /cinnamon/lib/Conversion/CinmToCim/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_conversion_library(MLIRCinmToCim 2 | CinmToCim.cpp 3 | 4 | ADDITIONAL_HEADER_DIRS 5 | ${MLIR_MAIN_INCLUDE_DIR}/cim/Conversion/CinmToCim 6 | 7 | DEPENDS 8 | CinmConversionPassIncGen 9 | CimIncGen 10 | 11 | LINK_COMPONENTS 12 | Core 13 | 14 | LINK_LIBS PUBLIC 15 | CimIR 16 | CinmUtils 17 | MLIRDialectUtils 18 | MLIRFuncDialect 19 | MLIRLinalgDialect 20 | MLIRTensorDialect 21 | MLIRTransformUtils 22 | MLIRReconcileUnrealizedCasts 23 | ) 24 | -------------------------------------------------------------------------------- /cinnamon/lib/Conversion/CinmToCnm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_conversion_library(MLIRCinmToCnm 2 | CinmToCnm.cpp 3 | 4 | ADDITIONAL_HEADER_DIRS 5 | ${MLIR_MAIN_INCLUDE_DIR}/cnm/Conversion/CinmToCnm 6 | 7 | DEPENDS 8 | CinmConversionPassIncGen 9 | 10 | LINK_COMPONENTS 11 | Core 12 | 13 | LINK_LIBS PUBLIC 14 | CnmIR 15 | CinmUtils 16 | MLIRDialectUtils 17 | MLIRFuncDialect 18 | MLIRLinalgDialect 19 | MLIRTensorDialect 20 | MLIRTransformUtils 21 | MLIRReconcileUnrealizedCasts 22 | ) 23 | -------------------------------------------------------------------------------- /cinnamon/lib/Conversion/CnmToGPU/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_conversion_library(MLIRCnmToGPU 2 | CnmToGPU.cpp 3 | 4 | ADDITIONAL_HEADER_DIRS 5 | ${MLIR_MAIN_INCLUDE_DIR}/cnm/Conversion/CnmToGPU 6 | 7 | DEPENDS 8 | CnmConversionPassIncGen 9 | 10 | LINK_COMPONENTS 11 | Core 12 | 13 | LINK_LIBS PUBLIC 14 | CinmCommonPatterns 15 | CnmIR 16 | MLIRDialectUtils 17 | MLIRFuncDialect 18 | MLIRTransformUtils 19 | MLIRReconcileUnrealizedCasts 20 | ) 21 | -------------------------------------------------------------------------------- /cinnamon/lib/Conversion/CnmToUPMEM/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_conversion_library(MLIRCnmToUPMEM 2 | CnmToUPMEM.cpp 3 | 4 | ADDITIONAL_HEADER_DIRS 5 | ${MLIR_MAIN_INCLUDE_DIR}/cnm/Conversion/CnmToUPMEM 6 | 7 | DEPENDS 8 | CnmConversionPassIncGen 9 | UPMEMIncGen 10 | 11 | LINK_COMPONENTS 12 | Core 13 | 14 | LINK_LIBS PUBLIC 15 | CinmCommonPatterns 16 | CnmIR 17 | MLIRDialectUtils 18 | MLIRFuncDialect 19 | MLIRTransformUtils 20 | MLIRReconcileUnrealizedCasts 21 | ) 22 | -------------------------------------------------------------------------------- /cinnamon/lib/Conversion/MemristorToFunc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_conversion_library(MLIRMemristorToFunc 2 | MemristorToFunc.cpp 3 | 4 | ADDITIONAL_HEADER_DIRS 5 | ${MLIR_MAIN_INCLUDE_DIR}/memristor/Conversion/MemristorToFunc 6 | 7 | DEPENDS 8 | MemristorConversionPassIncGen 9 | 10 | LINK_COMPONENTS 11 | Core 12 | 13 | LINK_LIBS PUBLIC 14 | MemristorIR 15 | MLIRDialectUtils 16 | MLIRFuncDialect 17 | MLIRTransformUtils 18 | MLIRReconcileUnrealizedCasts 19 | ) 20 | -------------------------------------------------------------------------------- /cinnamon/lib/Conversion/TorchToCinm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_conversion_library(MLIRTorchToCinm 2 | TorchToCinm.cpp 3 | 4 | ADDITIONAL_HEADER_DIRS 5 | ${MLIR_MAIN_INCLUDE_DIR}/cinm_frontend/Conversion/TorchToCinm 6 | 7 | DEPENDS 8 | CinmFrontendConversionPassIncGen 9 | 10 | LINK_COMPONENTS 11 | Core 12 | 13 | LINK_LIBS PUBLIC 14 | CinmIR 15 | CinmUtils 16 | MLIRDialectUtils 17 | MLIRFuncDialect 18 | MLIRLinalgDialect 19 | MLIRTensorDialect 20 | MLIRTransformUtils 21 | MLIRReconcileUnrealizedCasts 22 | ) 23 | -------------------------------------------------------------------------------- /cinnamon/lib/Conversion/UPMEMToLLVM/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_conversion_library(MLIRUPMEMToLLVM 2 | UPMEMToLLVM.cpp 3 | ToLLVMInterfaceImpl.cpp 4 | 5 | ADDITIONAL_HEADER_DIRS 6 | ${MLIR_MAIN_INCLUDE_DIR}/upmem/Conversion/UPMEMToLLVM 7 | 8 | DEPENDS 9 | UPMEMConversionPassIncGen 10 | 11 | LINK_COMPONENTS 12 | Core 13 | 14 | LINK_LIBS PUBLIC 15 | CinmCommonPatterns 16 | UPMEMIR 17 | CinmUtils 18 | MLIRDialectUtils 19 | MLIRReconcileUnrealizedCasts 20 | MLIRLLVMDialect 21 | MLIRLLVMCommonConversion 22 | ) 23 | -------------------------------------------------------------------------------- /cinnamon/lib/Conversion/UPMEMToLLVM/ToLLVMInterfaceImpl.cpp: -------------------------------------------------------------------------------- 1 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMBase.h" 2 | #include 3 | #include 4 | #include 5 | 6 | namespace mlir::upmem { 7 | 8 | struct UpmemToLlvmDialectInterface : public ConvertToLLVMPatternInterface { 9 | using ConvertToLLVMPatternInterface::ConvertToLLVMPatternInterface; 10 | 11 | /// Hook for derived dialect interface to load the dialects they 12 | /// target. The LLVMDialect is implicitly already loaded, but this 13 | /// method allows to load other intermediate dialects used in the 14 | /// conversion, or target dialects like NVVM for example. 15 | void loadDependentDialects(MLIRContext *) const override {} 16 | 17 | /// Hook for derived dialect interface to provide conversion patterns 18 | /// and mark dialect legal for the conversion target. 19 | void populateConvertToLLVMConversionPatterns( 20 | ConversionTarget &target, LLVMTypeConverter &typeConverter, 21 | RewritePatternSet &patterns) const override { 22 | target.addIllegalDialect(); 23 | populateUPMEMToLLVMConversionPatterns(typeConverter, patterns); 24 | populateUPMEMToLLVMFinalTypeConversions(typeConverter); 25 | populateFinalizeMemRefToLLVMConversionPatterns(typeConverter, patterns); 26 | } 27 | }; 28 | 29 | void registerConvertUpmemToLLvmInterface(DialectRegistry ®istry) { 30 | registry.addExtension(+[](MLIRContext *, upmem::UPMEMDialect *dialect) { 31 | dialect->addInterfaces(); 32 | }); 33 | } 34 | 35 | } // namespace mlir::upmem -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Cinm) 2 | add_subdirectory(Cim) 3 | add_subdirectory(Cnm) 4 | add_subdirectory(Memristor) 5 | add_subdirectory(UPMEM) 6 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Cim/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Cim/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(CimIR 2 | CimBase.cpp 3 | CimOps.cpp 4 | CimTypes.cpp 5 | 6 | DEPENDS 7 | CimIncGen 8 | # CimConversionPassIncGen 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRIR 12 | MLIRParser 13 | MLIRSideEffectInterfaces 14 | CinmUtils 15 | ) 16 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Cim/IR/CimBase.cpp: -------------------------------------------------------------------------------- 1 | /// Implements the Cim dialect base. 2 | /// 3 | /// @file 4 | 5 | #include "cinm-mlir/Dialect/Cim/IR/CimBase.h" 6 | 7 | #include "cinm-mlir/Dialect/Cim/IR/CimDialect.h" 8 | 9 | #define DEBUG_TYPE "cim-base" 10 | 11 | using namespace mlir; 12 | using namespace mlir::cim; 13 | 14 | //===- Generated implementation -------------------------------------------===// 15 | 16 | #include "cinm-mlir/Dialect/Cim/IR/CimBase.cpp.inc" 17 | 18 | //===----------------------------------------------------------------------===// 19 | 20 | //===----------------------------------------------------------------------===// 21 | // CimDialect 22 | //===----------------------------------------------------------------------===// 23 | 24 | void CimDialect::initialize() { 25 | registerOps(); 26 | registerTypes(); 27 | } 28 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Cim/IR/CimTypes.cpp: -------------------------------------------------------------------------------- 1 | /// Implements the Cim dialect types. 2 | /// 3 | /// @file 4 | 5 | #include "cinm-mlir/Dialect/Cim/IR/CimTypes.h" 6 | 7 | #include "mlir/IR/Builders.h" 8 | #include "mlir/IR/DialectImplementation.h" 9 | #include "mlir/IR/OpImplementation.h" 10 | 11 | #include "llvm/ADT/TypeSwitch.h" 12 | 13 | #define DEBUG_TYPE "cim-types" 14 | 15 | using namespace mlir; 16 | using namespace mlir::cim; 17 | 18 | //===- Generated implementation -------------------------------------------===// 19 | 20 | #define GET_TYPEDEF_CLASSES 21 | #include "cinm-mlir/Dialect/Cim/IR/CimTypes.cpp.inc" 22 | 23 | //===----------------------------------------------------------------------===// 24 | 25 | //===----------------------------------------------------------------------===// 26 | // CimDialect 27 | //===----------------------------------------------------------------------===// 28 | 29 | void CimDialect::registerTypes() { 30 | addTypes< 31 | #define GET_TYPEDEF_LIST 32 | #include "cinm-mlir/Dialect/Cim/IR/CimTypes.cpp.inc" 33 | >(); 34 | } 35 | 36 | Type mlir::cim::FutureType::parse(mlir::AsmParser &parser) { 37 | SmallVector shape; 38 | Type elementType; 39 | 40 | if (parser.parseLess() || // 41 | parser.parseDimensionList(shape, false, true) || // 42 | parser.parseType(elementType) || // 43 | parser.parseGreater()) { 44 | return Type(); 45 | } 46 | 47 | return cim::FutureType::get(parser.getContext(), shape, elementType); 48 | } 49 | 50 | void mlir::cim::FutureType::print(mlir::AsmPrinter &printer) const { 51 | printer << "<"; 52 | printer.printDimensionList(getShape()); 53 | printer << (getShape().empty() ? "" : "x") << getElementType() << ">"; 54 | } -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Cim/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(CimTransforms 2 | SchedulingPasses.cpp 3 | 4 | DEPENDS 5 | CimIncGen 6 | CimTransformPassesIncGen 7 | 8 | LINK_LIBS PUBLIC 9 | MLIRIR 10 | MLIRMemRefDialect 11 | MLIRLLVMDialect 12 | MLIRAffineDialect 13 | MLIRLinalgDialect 14 | MLIRSPIRVTarget 15 | MLIRTransformUtils 16 | ) 17 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Cinm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Interfaces) 2 | add_subdirectory(IR) 3 | add_subdirectory(Transforms) 4 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Cinm/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(CinmIR 2 | CinmBase.cpp 3 | CinmOps.cpp 4 | CinmTypes.cpp 5 | CinmTilingImplementations.cpp 6 | 7 | DEPENDS 8 | CinmIncGen 9 | CinmConversionPassIncGen 10 | 11 | LINK_LIBS PUBLIC 12 | MLIRIR 13 | MLIRParser 14 | MLIRSideEffectInterfaces 15 | CinmInterfaces 16 | ) 17 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Cinm/IR/CinmBase.cpp: -------------------------------------------------------------------------------- 1 | /// Implements the Cinm dialect base. 2 | /// 3 | /// @file 4 | 5 | #include "cinm-mlir/Dialect/Cinm/IR/CinmBase.h" 6 | 7 | #include "cinm-mlir/Dialect/Cinm/IR/CinmDialect.h" 8 | #include 9 | #include 10 | #include 11 | 12 | #define DEBUG_TYPE "cinm-base" 13 | 14 | using namespace mlir; 15 | using namespace mlir::cinm; 16 | 17 | //===- Generated implementation -------------------------------------------===// 18 | 19 | #include "cinm-mlir/Dialect/Cinm/IR/CinmBase.cpp.inc" 20 | #define GET_ATTRDEF_CLASSES 21 | #include "cinm-mlir/Dialect/Cinm/IR/CinmAttributes.cpp.inc" 22 | 23 | //===----------------------------------------------------------------------===// 24 | 25 | //===----------------------------------------------------------------------===// 26 | // CinmDialect 27 | //===----------------------------------------------------------------------===// 28 | 29 | void CinmDialect::initialize() { 30 | registerOps(); 31 | registerTypes(); 32 | addAttributes< 33 | #define GET_ATTRDEF_LIST 34 | #include "cinm-mlir/Dialect/Cinm/IR/CinmAttributes.cpp.inc" 35 | >(); 36 | } 37 | 38 | ::mlir::LogicalResult 39 | CinmDialect::verifyOperationAttribute(::mlir::Operation *op, 40 | ::mlir::NamedAttribute attribute) { 41 | 42 | if (attribute.getName() == CinmDialect::NOTILE_NAME) { 43 | if (op->getDialect() == this) { 44 | return success(); 45 | } 46 | return op->emitOpError() 47 | << CinmDialect::NOTILE_NAME 48 | << " attribute can only be used on cinm dialect operations"; 49 | } 50 | return op->emitOpError("unknown attribute ") << attribute.getName(); 51 | } 52 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Cinm/IR/CinmTypes.cpp: -------------------------------------------------------------------------------- 1 | /// Implements the Cinm dialect types. 2 | /// 3 | /// @file 4 | 5 | #include "cinm-mlir/Dialect/Cinm/IR/CinmTypes.h" 6 | 7 | #include "mlir/IR/Builders.h" 8 | #include "mlir/IR/DialectImplementation.h" 9 | #include "mlir/IR/OpImplementation.h" 10 | 11 | #include "llvm/ADT/TypeSwitch.h" 12 | 13 | #define DEBUG_TYPE "cinm-types" 14 | 15 | using namespace mlir; 16 | using namespace mlir::cinm; 17 | 18 | //===- Generated implementation -------------------------------------------===// 19 | 20 | #define GET_TYPEDEF_CLASSES 21 | #include "cinm-mlir/Dialect/Cinm/IR/CinmTypes.cpp.inc" 22 | 23 | //===----------------------------------------------------------------------===// 24 | 25 | //===----------------------------------------------------------------------===// 26 | // CinmDialect 27 | //===----------------------------------------------------------------------===// 28 | 29 | void CinmDialect::registerTypes() 30 | { 31 | addTypes< 32 | #define GET_TYPEDEF_LIST 33 | #include "cinm-mlir/Dialect/Cinm/IR/CinmTypes.cpp.inc" 34 | >(); 35 | } 36 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Cinm/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_library(CinmInterfaces 2 | TilingInterface.cpp 3 | 4 | ENABLE_AGGREGATION 5 | DEPENDS 6 | CinmIncGen 7 | 8 | LINK_LIBS PUBLIC 9 | CinmCommonPatterns 10 | ) 11 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Cinm/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(CinmTransforms 2 | SoftmaxToCinmPass.cpp 3 | TilingPass.cpp 4 | 5 | DEPENDS 6 | CinmIncGen 7 | CinmTransformPassesIncGen 8 | 9 | LINK_LIBS PUBLIC 10 | MLIRIR 11 | MLIRLLVMDialect 12 | MLIRAffineDialect 13 | MLIRLinalgDialect 14 | MLIRTransformUtils 15 | ) 16 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Cnm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Cnm/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(CnmIR 2 | CnmBase.cpp 3 | CnmOps.cpp 4 | CnmTypes.cpp 5 | 6 | DEPENDS 7 | CnmIncGen 8 | CnmConversionPassIncGen 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRIR 12 | MLIRParser 13 | MLIRSideEffectInterfaces 14 | CinmUtils 15 | ) 16 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Cnm/IR/CnmBase.cpp: -------------------------------------------------------------------------------- 1 | /// Implements the Cnm dialect base. 2 | /// 3 | /// @file 4 | 5 | #include "cinm-mlir/Dialect/Cnm/IR/CnmBase.h" 6 | 7 | #include "cinm-mlir/Dialect/Cnm/IR/CnmDialect.h" 8 | 9 | #define DEBUG_TYPE "cnm-base" 10 | 11 | using namespace mlir; 12 | using namespace mlir::cnm; 13 | 14 | //===- Generated implementation -------------------------------------------===// 15 | 16 | #include "cinm-mlir/Dialect/Cnm/IR/CnmBase.cpp.inc" 17 | 18 | //===----------------------------------------------------------------------===// 19 | 20 | //===----------------------------------------------------------------------===// 21 | // CnmDialect 22 | //===----------------------------------------------------------------------===// 23 | 24 | void CnmDialect::initialize() 25 | { 26 | registerOps(); 27 | registerTypes(); 28 | } 29 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Cnm/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(CnmTransforms 2 | SPIRVAttachAttributes.cpp 3 | Bufferize.cpp 4 | HoistWorkgroups.cpp 5 | 6 | DEPENDS 7 | CnmIncGen 8 | CnmTransformPassesIncGen 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRIR 12 | MLIRGPUDialect 13 | MLIRBufferizationDialect 14 | MLIRMemRefDialect 15 | MLIRLLVMDialect 16 | MLIRAffineDialect 17 | MLIRLinalgDialect 18 | MLIRSPIRVTarget 19 | MLIRTransformUtils 20 | ) 21 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Memristor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Memristor/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MemristorIR 2 | MemristorBase.cpp 3 | MemristorOps.cpp 4 | MemristorTypes.cpp 5 | 6 | DEPENDS 7 | MemristorIncGen 8 | # MemristorConversionPassIncGen 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRIR 12 | MLIRParser 13 | MLIRSideEffectInterfaces 14 | ) 15 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Memristor/IR/MemristorBase.cpp: -------------------------------------------------------------------------------- 1 | /// Implements the Memristor dialect base. 2 | /// 3 | /// @file 4 | 5 | #include "cinm-mlir/Dialect/Memristor/IR/MemristorBase.h" 6 | 7 | #include "cinm-mlir/Dialect/Memristor/IR/MemristorDialect.h" 8 | 9 | #define DEBUG_TYPE "memristor-base" 10 | 11 | using namespace mlir; 12 | using namespace mlir::memristor; 13 | 14 | //===- Generated implementation -------------------------------------------===// 15 | 16 | #include "cinm-mlir/Dialect/Memristor/IR/MemristorBase.cpp.inc" 17 | 18 | //===----------------------------------------------------------------------===// 19 | 20 | //===----------------------------------------------------------------------===// 21 | // MemristorDialect 22 | //===----------------------------------------------------------------------===// 23 | 24 | void MemristorDialect::initialize() { registerOps(); } 25 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Memristor/IR/MemristorTypes.cpp: -------------------------------------------------------------------------------- 1 | /// Implements the Memristor dialect types. 2 | /// 3 | /// @file 4 | 5 | #include "cinm-mlir/Dialect/Memristor/IR/MemristorTypes.h" 6 | 7 | #include "mlir/IR/Builders.h" 8 | #include "mlir/IR/DialectImplementation.h" 9 | #include "mlir/IR/OpImplementation.h" 10 | 11 | #define DEBUG_TYPE "memristor-types" 12 | 13 | using namespace mlir; 14 | using namespace mlir::memristor; 15 | 16 | //===- Generated implementation -------------------------------------------===// 17 | 18 | #define GET_TYPEDEF_CLASSES 19 | #include "cinm-mlir/Dialect/Memristor/IR/MemristorTypes.cpp.inc" 20 | 21 | //===----------------------------------------------------------------------===// 22 | 23 | //===----------------------------------------------------------------------===// 24 | // MemristorDialect 25 | //===----------------------------------------------------------------------===// 26 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Memristor/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MemristorTransforms 2 | dummy.cpp 3 | 4 | DEPENDS 5 | MemristorIncGen 6 | MemristorTransformPassesIncGen 7 | 8 | LINK_LIBS PUBLIC 9 | MLIRIR 10 | MLIRMemRefDialect 11 | MLIRLLVMDialect 12 | MLIRAffineDialect 13 | MLIRLinalgDialect 14 | MLIRSPIRVTarget 15 | MLIRTransformUtils 16 | ) 17 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/Memristor/Transforms/dummy.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tud-ccc/Cinnamon/715eb4d97359966792a80d6540bfb856ba6b9357/cinnamon/lib/Dialect/Memristor/Transforms/dummy.cpp -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/UPMEM/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/UPMEM/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(UPMEMIR 2 | UPMEMBase.cpp 3 | UPMEMOps.cpp 4 | UPMEMTypes.cpp 5 | InferIntRangeInterfaceImpls.cpp 6 | 7 | DEPENDS 8 | UPMEMIncGen 9 | UPMEMConversionPassIncGen 10 | 11 | LINK_LIBS PUBLIC 12 | MLIRIR 13 | MLIRParser 14 | MLIRSideEffectInterfaces 15 | 16 | MLIRArithDialect 17 | MLIRDLTIDialect 18 | MLIRFunctionInterfaces 19 | MLIRInferIntRangeInterface 20 | MLIRMemRefDialect 21 | MLIRSupport 22 | ) 23 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/UPMEM/IR/UPMEMBase.cpp: -------------------------------------------------------------------------------- 1 | /// Implements the UPMEM dialect base. 2 | /// 3 | /// @file 4 | 5 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMBase.h" 6 | 7 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMDialect.h" 8 | #include "mlir/IR/DialectImplementation.h" 9 | #include "mlir/IR/BuiltinAttributes.h" 10 | #include "mlir/IR/Attributes.h" 11 | #include "llvm/ADT/TypeSwitch.h" 12 | 13 | 14 | #define DEBUG_TYPE "upmem-base" 15 | 16 | using namespace mlir; 17 | using namespace mlir::upmem; 18 | 19 | //===- Generated implementation -------------------------------------------===// 20 | 21 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMBase.cpp.inc" 22 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMEnums.cpp.inc" 23 | 24 | #define GET_ATTRDEF_CLASSES 25 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMAttributes.cpp.inc" 26 | 27 | //===----------------------------------------------------------------------===// 28 | 29 | //===----------------------------------------------------------------------===// 30 | // UPMEMDialect 31 | //===----------------------------------------------------------------------===// 32 | 33 | void UPMEMDialect::initialize() 34 | { 35 | registerOps(); 36 | registerTypes(); 37 | addAttributes(); 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /cinnamon/lib/Dialect/UPMEM/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(UPMEMTransforms 2 | OutlineFunction.cpp 3 | DedupKernels.cpp 4 | 5 | DEPENDS 6 | UPMEMIncGen 7 | UPMEMTransformPassesIncGen 8 | 9 | LINK_LIBS PUBLIC 10 | MLIRIR 11 | MLIRTransformUtils 12 | ) 13 | -------------------------------------------------------------------------------- /cinnamon/lib/Target/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(UPMEMCpp) -------------------------------------------------------------------------------- /cinnamon/lib/Target/UPMEMCpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_translation_library(MLIRUPMEMTargetCpp 2 | UPMEMTranslateRegistration.cpp 3 | UPMEMTranslateToCpp.cpp 4 | 5 | # ADDITIONAL_HEADER_DIRS 6 | # ${EMITC_MAIN_INCLUDE_DIR}/emitc/Target/Cpp 7 | 8 | LINK_LIBS PUBLIC 9 | MLIRArithDialect 10 | MLIRControlFlowDialect 11 | MLIRFuncDialect 12 | UPMEMIR 13 | MLIRIR 14 | MLIRMathDialect 15 | MLIRSCFDialect 16 | MLIRSupport 17 | MLIRTranslateLib 18 | ) 19 | -------------------------------------------------------------------------------- /cinnamon/lib/Utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_mlir_dialect_library(CinmUtils 3 | CinmUtils.cpp 4 | 5 | LINK_LIBS PUBLIC 6 | MLIRIR 7 | ) -------------------------------------------------------------------------------- /cinnamon/python/.gitignore: -------------------------------------------------------------------------------- 1 | **/__pycache__ 2 | **/*.egg-info 3 | dist 4 | src/cinnamon/_resources 5 | LICENSE -------------------------------------------------------------------------------- /cinnamon/python/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools", "wheel"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "cinnamon" 7 | version = "0.1.0" 8 | license = {file = "LICENSE"} 9 | description = "Python bindings for the Cinnamon compiler" 10 | authors = [{name = "Felix Reißmann"}] 11 | requires-python = ">=3.6" 12 | dependencies = [ 13 | "torch", 14 | "torch-mlir" 15 | ] 16 | classifiers = [ 17 | "Programming Language :: Python :: 3", 18 | "Operating System :: POSIX :: Linux", 19 | "Operating System :: POSIX :: Linux x86_64", 20 | "License :: OSI Approved :: MIT License", 21 | ] 22 | 23 | [project.urls] 24 | homepage = "https://github.com/tud-ccc/Cinnamon" 25 | repository = "https://github.com/tud-ccc/Cinnamon" 26 | issues = "https://github.com/tud-ccc/Cinnamon/issues" 27 | 28 | [tool.setuptools] 29 | platforms = ["none"] 30 | 31 | [tool.setuptools.package-data] 32 | myModule = ["_resources/*"] 33 | 34 | [tool.distutils.bdist_wheel] 35 | plat-name = "manylinux1_x86_64" -------------------------------------------------------------------------------- /cinnamon/python/src/cinnamon/torch_backend/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tud-ccc/Cinnamon/715eb4d97359966792a80d6540bfb856ba6b9357/cinnamon/python/src/cinnamon/torch_backend/__init__.py -------------------------------------------------------------------------------- /cinnamon/python/src/cinnamon/torch_backend/_utility/resource_paths.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | class ResourcePaths: 5 | def _resource_dir(): 6 | file_location = os.path.dirname(os.path.abspath(__file__)) 7 | return os.path.join(file_location, "..", "..", "_resources") 8 | 9 | def torch_mlir_opt(): 10 | resource_dir = ResourcePaths._resource_dir() 11 | return os.path.join(resource_dir, "torch-mlir-opt") 12 | 13 | def cinm_opt(): 14 | resource_dir = ResourcePaths._resource_dir() 15 | return os.path.join(resource_dir, "cinm-opt") 16 | 17 | def mlir_translate(): 18 | resource_dir = ResourcePaths._resource_dir() 19 | return os.path.join(resource_dir, "mlir-translate") 20 | 21 | def clang(): 22 | resource_dir = ResourcePaths._resource_dir() 23 | return os.path.join(resource_dir, "clang") 24 | 25 | def memristor_runtime(): 26 | resource_dir = ResourcePaths._resource_dir() 27 | return os.path.join(resource_dir, "libMemristorDialectRuntime.so") 28 | -------------------------------------------------------------------------------- /cinnamon/python/src/cinnamon/torch_backend/_utility/signature_extractor.py: -------------------------------------------------------------------------------- 1 | import dataclasses 2 | 3 | 4 | @dataclasses.dataclass 5 | class FunctionSignature: 6 | name: str 7 | argument_types: list[str] 8 | return_type: str 9 | 10 | 11 | class SignatureExtractor: 12 | def extract(mlir: bytes) -> dict: 13 | signatures = {} 14 | 15 | # FIXME: This is a very naive way to extract function signatures 16 | for line in mlir.decode("utf-8").split("\n"): 17 | line = line.strip() 18 | if not line.startswith("func.func"): 19 | continue 20 | 21 | name = line.split("@")[1].split("(")[0].strip() 22 | 23 | arg_types = [] 24 | args_string = line.split("(")[1].split(")")[0].strip() 25 | for arg in args_string.split("%"): 26 | if len(arg) == 0: 27 | continue 28 | arg_type = arg.split(" ")[1].strip(", ") 29 | arg_types.append(arg_type) 30 | 31 | return_type = line.split("->")[1].split("{")[0].strip() 32 | 33 | signatures[name] = FunctionSignature(name, arg_types, return_type) 34 | return signatures 35 | -------------------------------------------------------------------------------- /cinnamon/python/src/cinnamon/torch_backend/cinm.py: -------------------------------------------------------------------------------- 1 | from ._utility.compiler_invoker import CompilerInvoker 2 | from .model_invoker import ModelInvoker 3 | from .compiled_model import CompiledModel 4 | from ._utility.common_pipelines import CommonPipelines 5 | from ._utility.resource_paths import ResourcePaths 6 | from ._utility.signature_extractor import SignatureExtractor 7 | 8 | 9 | class CinmBackend: 10 | CINM_PIPELINE = [ 11 | # Convert supported torch ops to cinm dialect 12 | "func.func(convert-torch-to-cinm)", 13 | "func.func(convert-cinm-to-cim)", 14 | "func.func(cim-schedule-asap)", 15 | "func.func(convert-cim-to-memristor)", 16 | "func.func(convert-memristor-to-func)", 17 | "convert-func-to-llvm", 18 | ] 19 | LINALG_PIPELINE = ( 20 | CommonPipelines.LOWER_TORCH_TO_LINALG_UNCHECKED_PIPELINE 21 | + CommonPipelines.LOWER_LINALG_TO_LLVM_PIPELINE 22 | ) 23 | 24 | def compile( 25 | self, model, input_tensor, *, dump_dir: str = None, step_by_step: bool = False 26 | ) -> CompiledModel: 27 | invoker = CompilerInvoker(dump_dir, step_by_step) 28 | 29 | mlir = invoker.compile_torch_module(model, input_tensor) 30 | mlir = invoker.cinm_opt(CinmBackend.CINM_PIPELINE, mlir) 31 | llvm_mlir = invoker.cinm_opt(CinmBackend.LINALG_PIPELINE, mlir) 32 | ll_ir = invoker.mlir_translate(llvm_mlir) 33 | shared_object = invoker.clang(ll_ir) 34 | 35 | signatures = SignatureExtractor.extract(mlir) 36 | 37 | return CompiledModel(signatures, shared_object) 38 | 39 | def load(self, model: CompiledModel) -> ModelInvoker: 40 | runtimes = [ResourcePaths.memristor_runtime()] 41 | return ModelInvoker(model, runtimes) 42 | -------------------------------------------------------------------------------- /cinnamon/python/src/cinnamon/torch_backend/compiled_model.py: -------------------------------------------------------------------------------- 1 | from ._utility.signature_extractor import FunctionSignature 2 | from zipfile import ZipFile as zipfile 3 | import pickle 4 | 5 | 6 | class CompiledModel: 7 | def __init__(self, signatures: dict[str, FunctionSignature], shared_object: bytes): 8 | self._shared_object = shared_object 9 | self._function_signatures = signatures 10 | 11 | def save_to_file(self, filename: str) -> None: 12 | with zipfile(filename, "w") as f: 13 | f.writestr("shared_object.so", self._shared_object) 14 | f.writestr("signatures.json", pickle.dumps(self._function_signatures)) 15 | 16 | @staticmethod 17 | def load_from_file(filename: str) -> "CompiledModel": 18 | with zipfile(filename, "r") as f: 19 | shared_object = f.read("shared_object.so") 20 | signatures = pickle.loads(f.read("signatures.json")) 21 | 22 | return CompiledModel(signatures, shared_object) 23 | 24 | def data(self) -> bytes: 25 | return self._shared_object 26 | 27 | def signatures(self) -> dict[str, FunctionSignature]: 28 | return self._function_signatures 29 | -------------------------------------------------------------------------------- /cinnamon/python/src/cinnamon/torch_backend/exceptions.py: -------------------------------------------------------------------------------- 1 | class BackendException(Exception): 2 | pass 3 | -------------------------------------------------------------------------------- /cinnamon/python/src/cinnamon/torch_backend/linalg_on_tensor.py: -------------------------------------------------------------------------------- 1 | from ._utility.compiler_invoker import CompilerInvoker 2 | from .model_invoker import ModelInvoker 3 | from .compiled_model import CompiledModel 4 | from ._utility.common_pipelines import CommonPipelines 5 | from ._utility.signature_extractor import SignatureExtractor 6 | 7 | 8 | class LinalgOnTensorBackend: 9 | 10 | PIPELINE = ( 11 | CommonPipelines.LOWER_TORCH_TO_LINALG_CHECKED_PIPELINE 12 | + CommonPipelines.LOWER_LINALG_TO_LLVM_PIPELINE 13 | ) 14 | 15 | def compile( 16 | self, model, input_tensor, *, dump_dir: str = None, step_by_step: bool = False 17 | ) -> CompiledModel: 18 | invoker = CompilerInvoker(dump_dir, step_by_step) 19 | 20 | mlir = invoker.compile_torch_module(model, input_tensor) 21 | llvm_mlir = invoker.cinm_opt(LinalgOnTensorBackend.PIPELINE, mlir) 22 | ll_ir = invoker.mlir_translate(llvm_mlir) 23 | shared_object = invoker.clang(ll_ir) 24 | 25 | signatures = SignatureExtractor.extract(mlir) 26 | 27 | return CompiledModel(signatures, shared_object) 28 | 29 | def load(self, model: CompiledModel) -> ModelInvoker: 30 | return ModelInvoker(model) 31 | -------------------------------------------------------------------------------- /cinnamon/runtime/Memristor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library( 2 | MemristorDialectRuntime 3 | SHARED 4 | runtime_c_interface.cpp 5 | executor.cpp 6 | ) -------------------------------------------------------------------------------- /cinnamon/runtime/Memristor/gemm_cpu.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "executor_interface.hpp" 5 | 6 | namespace memristor_runtime { 7 | 8 | template bool gemm_cpu_available() { return true; } 9 | 10 | template void gemm_cpu(int32_t crossbar_id) { 11 | auto &crossbar = crossbars[crossbar_id]; 12 | auto lhs_rows = crossbar.lhs.sizes[0]; 13 | auto lhs_cols = crossbar.lhs.sizes[1]; 14 | auto rhs_cols = crossbar.rhs.sizes[1]; 15 | auto *lhs = (T *)crossbar.lhs.data; 16 | auto *rhs = (T *)crossbar.rhs.data; 17 | auto *result = (T *)crossbar.result.data; 18 | 19 | for (int64_t lhs_count = 0; lhs_count < lhs_rows; ++lhs_count) { 20 | for (int64_t rhs_count = 0; rhs_count < rhs_cols; ++rhs_count) { 21 | int64_t result_index = lhs_count * rhs_cols + rhs_count; 22 | result[result_index] = 0; 23 | for (int64_t shared = 0; shared < lhs_cols; ++shared) { 24 | int64_t lhs_index = lhs_count * lhs_cols + shared; 25 | int64_t rhs_index = shared * rhs_cols + rhs_count; 26 | result[result_index] += lhs[lhs_index] * rhs[rhs_index]; 27 | } 28 | } 29 | } 30 | } 31 | 32 | } // namespace memristor_runtime -------------------------------------------------------------------------------- /cinnamon/runtime/Memristor/simulator_interface.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace memristor_runtime { 10 | 11 | // NOTE: This struct is also used for ipc to systemc-rram-wrapper 12 | // If you change it, make sure to update the corresponding struct in the wrapper 13 | struct matrix_descriptor { 14 | uint8_t bits; 15 | uint16_t rows; 16 | uint16_t cols; 17 | 18 | size_t byte_count() const { return rows * cols * storage_bitwidth() / 8; } 19 | 20 | uint8_t storage_bitwidth() const { 21 | uint8_t storage_bits = bits - 1; 22 | storage_bits |= storage_bits >> 1; 23 | storage_bits |= storage_bits >> 2; 24 | storage_bits |= storage_bits >> 4; 25 | storage_bits |= storage_bits >> 8; 26 | storage_bits++; 27 | return storage_bits; 28 | } 29 | }; 30 | } // namespace memristor_runtime -------------------------------------------------------------------------------- /cinnamon/runtime/Upmem/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | add_library( 4 | UpmemDialectRuntime 5 | STATIC 6 | upmem_rt.c 7 | memref_rt.cpp 8 | ) 9 | target_link_libraries(UpmemDialectRuntime PRIVATE Upmem::dpu) 10 | #target_link_libraries(UpmemDialectRuntime PUBLIC mlir_c_runner_utils mlir_runner_utils) -------------------------------------------------------------------------------- /cinnamon/runtime/Upmem/upmem_rt.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | /// Scatter a tensor on the given DPU set. 9 | /// For each DPU `x`, copies `copy_bytes` bytes from `A` 10 | /// into DPU memory (at offset `offset_in_dpu`), 11 | /// starting from `A + base_offset(x)`. 12 | /// 13 | /// @param dpu_set Pointer to DPU structure 14 | /// @param host_buffer Input tensor to scatter 15 | /// @param element_size Total size of a tensor element in bytes 16 | /// @param num_elements Total number of elements in tensor 17 | /// @param num_elements_per_tasklet Total number of elements for one tasklet 18 | /// @param copy_bytes Total number of bytes to copy into each DPU 19 | /// @param offset_in_dpu_bytes Offset in the DPU memory at which to start 20 | /// copying 21 | /// @param base_offset Function mapping the index of a DPU to an offset 22 | /// in the input tensor. 23 | size_t upmemrt_dpu_scatter(struct dpu_set_t *dpu_set, void *host_buffer, 24 | size_t element_size, size_t num_elements, 25 | size_t num_elements_per_tasklet, size_t copy_bytes, 26 | size_t offset_in_dpu_bytes, 27 | size_t (*base_offset)(size_t)); 28 | 29 | void upmemrt_dpu_gather(struct dpu_set_t *dpu_set, void *host_buffer, 30 | size_t element_size, size_t num_elements, 31 | size_t num_elements_per_tasklet, size_t copy_bytes, 32 | size_t offset_in_dpu_bytes, 33 | size_t (*base_offset)(size_t)); 34 | 35 | struct dpu_set_t *upmemrt_dpu_alloc(int32_t num_ranks, int32_t num_dpus, 36 | const char *dpu_binary_path); 37 | 38 | void upmemrt_dpu_launch(struct dpu_set_t *void_dpu_set); 39 | -------------------------------------------------------------------------------- /cinnamon/samples/cinm_conv2d.mlir: -------------------------------------------------------------------------------- 1 | #im2col_traits = { 2 | indexing_maps = [ 3 | affine_map<(N,H,W,KH,KW,C)->(N,H+KH,W+KW,C)>, 4 | affine_map<(N,H,W,KH,KW,C)->(N,H,W,KH,KW,C)>], 5 | iterator_types = [ 6 | "parallel", "parallel", "parallel", "parallel", "parallel", "parallel"]} 7 | 8 | func.func @conv(%img : tensor<1x128x128x3xi16>, %flt : tensor<3x3x3x8xi16>, %bias: tensor<1x126x126x8xi16>) { 9 | // %init = linalg.init_tensor [1, 126, 126, 3, 3, 3] : tensor<1x126x126x3x3x3xi16> 10 | %init = bufferization.alloc_tensor() : tensor<1x126x126x3x3x3xi16> 11 | 12 | %cbuf = linalg.generic #im2col_traits 13 | ins(%img: tensor<1x128x128x3xi16>) 14 | outs(%init: tensor<1x126x126x3x3x3xi16>) { 15 | ^bb0(%arg0: i16, %arg1: i16): 16 | linalg.yield %arg0 : i16 17 | } -> tensor<1x126x126x3x3x3xi16> 18 | %im2col = tensor.collapse_shape %cbuf [[0,1,2],[3,4,5]] 19 | : tensor<1x126x126x3x3x3xi16> into tensor<15876x27xi16> 20 | 21 | %rbuf = cinm.compute -> tensor<15876x8xi16> { 22 | %flt = arith.constant dense<"..."> : tensor<27x8xi16> 23 | %conv = cinm.op.gemm %im2col, %flt : (tensor<15876x27xi16>, tensor<27x8xi16>) -> tensor<15876x8xi16> 24 | cinm.yield %conv : tensor<15876x8xi16> 25 | } 26 | 27 | %conv = tensor.expand_shape %rbuf [[0,1,2],[3,4,5]] 28 | : tensor<15876x8xi16> into tensor<1x126x126x8xi16> 29 | return 30 | } 31 | -------------------------------------------------------------------------------- /cinnamon/samples/gemm.mlir: -------------------------------------------------------------------------------- 1 | func.func @main() { 2 | %a = tensor.empty() : tensor<1024x1024xi32> 3 | %b = tensor.empty() : tensor<1024x1024xi32> 4 | %res = cinm.compute attributes{ workgroupShape = array }-> tensor<1024x1024xi32> { 5 | %d = cinm.op.gemm %a, %b : (tensor<1024x1024xi32>, tensor<1024x1024xi32>) -> tensor<1024x1024xi32> 6 | cinm.yield %d : tensor<1024x1024xi32> 7 | } 8 | return 9 | } 10 | -------------------------------------------------------------------------------- /cinnamon/samples/gemv.mlir: -------------------------------------------------------------------------------- 1 | func.func @main() { 2 | %a = tensor.empty() : tensor<1024x1024xi32> 3 | %b = tensor.empty() : tensor<1024xi32> 4 | %res = cinm.compute attributes{ workgroupShape = array }-> tensor<1024xi32> { 5 | %d = cinm.op.gemv %a, %b : (tensor<1024x1024xi32>, tensor<1024xi32>) -> tensor<1024xi32> 6 | cinm.yield %d: tensor<1024xi32> 7 | } 8 | return 9 | } 10 | -------------------------------------------------------------------------------- /cinnamon/samples/linalg_conv2d.mlir: -------------------------------------------------------------------------------- 1 | 2 | func.func @conv(%img : tensor<1x128x128x3xi16>, %flt : tensor<3x3x3x8xi16>, %bias: tensor<1x126x126x8xi16>) { 3 | %conv = linalg.conv_2d_nhwc_hwcf 4 | ins(%img, %flt: tensor<1x128x128x3xi16>, tensor<3x3x3x8xi16>) 5 | outs(%bias: tensor<1x126x126x8xi16>) 6 | -> tensor<1x126x126x8xi16> 7 | return 8 | } 9 | -------------------------------------------------------------------------------- /cinnamon/samples/min.mlir: -------------------------------------------------------------------------------- 1 | func.func @main() { 2 | %a = tensor.empty() : tensor<1024xi32> 3 | 4 | %x,%y = cinm.compute -> i32, i32 { 5 | %b = cinm.op.min %a : tensor<1024xi32> 6 | %c = cinm.op.max %a : tensor<1024xi32> 7 | cinm.yield %b, %c : i32, i32 8 | } 9 | return 10 | } 11 | -------------------------------------------------------------------------------- /cinnamon/samples/vector_add_big_cnm.mlir: -------------------------------------------------------------------------------- 1 | #scatter_map = affine_map<(i) -> ( 2 | (i floordiv 262144) mod 2, 3 | (i floordiv 8192) mod 32, 4 | (i floordiv 512) mod 16, 5 | (i floordiv 64) mod 8, 6 | i mod 64 7 | )> 8 | 9 | #gather_map = affine_map<(wg0, wg1, wg2, wg3, b0) -> ( 10 | wg0 * 262144 + 11 | wg1 * 8192 + 12 | wg2 * 512 + 13 | wg3 * 64 + 14 | b0 15 | )> 16 | 17 | func.func @add(%a: tensor<524288xi32>, %b: tensor<524288xi32>) -> tensor<524288xi32> { 18 | %wg = cnm.workgroup : !cnm.workgroup<2x32x16x8> 19 | %a_buf = cnm.alloc () for %wg : !cnm.buffer<64xi32 on 2x32x16x8, level 0> 20 | %b_buf = cnm.alloc () for %wg : !cnm.buffer<64xi32 on 2x32x16x8, level 0> 21 | %c_buf = cnm.alloc () for %wg : !cnm.buffer<64xi32 on 2x32x16x8, level 0> 22 | %a_token = cnm.scatter %a into %a_buf[#scatter_map] of %wg : tensor<524288xi32> into !cnm.buffer<64xi32 on 2x32x16x8, level 0> 23 | %b_token = cnm.scatter %b into %b_buf[#scatter_map] of %wg : tensor<524288xi32> into !cnm.buffer<64xi32 on 2x32x16x8, level 0> 24 | %10 = cnm.launch %wg in (%a_buf, %b_buf : !cnm.buffer<64xi32 on 2x32x16x8, level 0>, !cnm.buffer<64xi32 on 2x32x16x8, level 0>) out (%c_buf : !cnm.buffer<64xi32 on 2x32x16x8, level 0>) on !cnm.workgroup<2x32x16x8> { 25 | ^bb0(%a_slice: memref<64xi32>, %b_slice: memref<64xi32>, %c_slice: memref<64xi32>): 26 | affine.for %i = 0 to 64 step 1 { 27 | %a_elem = affine.load %a_slice[%i] : memref<64xi32> 28 | %b_elem = affine.load %b_slice[%i] : memref<64xi32> 29 | %c_elem = arith.addi %a_elem, %b_elem : i32 30 | affine.store %c_elem, %c_slice[%i] : memref<64xi32> 31 | } 32 | } 33 | %c, %c_token = cnm.gather %c_buf[#gather_map] of %wg : !cnm.buffer<64xi32 on 2x32x16x8, level 0> into tensor<524288xi32> 34 | return %c : tensor<524288xi32> 35 | } 36 | -------------------------------------------------------------------------------- /cinnamon/samples/vector_add_small_cnm.mlir: -------------------------------------------------------------------------------- 1 | #scatter_map = affine_map<(i) -> ( 2 | (i floordiv 32768) mod 2, 3 | (i floordiv 1024) mod 32, 4 | (i floordiv 64) mod 16, 5 | i mod 64 6 | )> 7 | 8 | #gather_map = affine_map<(wg0, wg1, wg2, b0) -> ( 9 | wg0 * 32768 + 10 | wg1 * 1024 + 11 | wg2 * 64 + 12 | b0 13 | )> 14 | 15 | func.func @add(%a: tensor<65536xi32>, %b: tensor<65536xi32>) -> tensor<65536xi32> { 16 | %wg = cnm.workgroup : !cnm.workgroup<2x32x16> 17 | %a_buf = cnm.alloc () for %wg : !cnm.buffer<64xi32 on 2x32x16, level 0> 18 | %b_buf = cnm.alloc () for %wg : !cnm.buffer<64xi32 on 2x32x16, level 0> 19 | %c_buf = cnm.alloc () for %wg : !cnm.buffer<64xi32 on 2x32x16, level 0> 20 | %a_token = cnm.scatter %a into %a_buf[#scatter_map] of %wg : tensor<65536xi32> into !cnm.buffer<64xi32 on 2x32x16, level 0> 21 | %b_token = cnm.scatter %b into %b_buf[#scatter_map] of %wg : tensor<65536xi32> into !cnm.buffer<64xi32 on 2x32x16, level 0> 22 | %10 = cnm.launch %wg in (%a_buf, %b_buf : !cnm.buffer<64xi32 on 2x32x16, level 0>, !cnm.buffer<64xi32 on 2x32x16, level 0>) out (%c_buf : !cnm.buffer<64xi32 on 2x32x16, level 0>) on !cnm.workgroup<2x32x16> { 23 | ^bb0(%a_slice: memref<64xi32>, %b_slice: memref<64xi32>, %c_slice: memref<64xi32>): 24 | affine.for %i = 0 to 64 step 1 { 25 | %a_elem = affine.load %a_slice[%i] : memref<64xi32> 26 | %b_elem = affine.load %b_slice[%i] : memref<64xi32> 27 | %c_elem = arith.addi %a_elem, %b_elem : i32 28 | affine.store %c_elem, %c_slice[%i] : memref<64xi32> 29 | } 30 | } 31 | %c, %c_token = cnm.gather %c_buf[#gather_map] of %wg : !cnm.buffer<64xi32 on 2x32x16, level 0> into tensor<65536xi32> 32 | return %c : tensor<65536xi32> 33 | } 34 | -------------------------------------------------------------------------------- /cinnamon/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # check-cinm-mlir 3 | # 4 | # The cinm-mlir regression test project. 5 | ################################################################################ 6 | 7 | project(check-cinm-mlir) 8 | 9 | # Configure the testing site configuration. 10 | configure_lit_site_cfg( 11 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in 12 | ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py 13 | MAIN_CONFIG 14 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py 15 | ) 16 | set(TEST_DEPENDS 17 | FileCheck count not 18 | cinm-opt 19 | ) 20 | 21 | # Create the test suite. 22 | add_lit_testsuite(${PROJECT_NAME} 23 | "Running the cinm-mlir regression tests" 24 | ${CMAKE_CURRENT_BINARY_DIR} 25 | DEPENDS 26 | ${TEST_DEPENDS} 27 | ) 28 | add_lit_testsuites(cinmMLIR 29 | ${CMAKE_CURRENT_SOURCE_DIR} 30 | DEPENDS 31 | ${TEST_DEPENDS} 32 | ) 33 | -------------------------------------------------------------------------------- /cinnamon/test/Conversion/CinmToCim/cinm-to-cim.mlir: -------------------------------------------------------------------------------- 1 | // RUN: cinm-opt --convert-cinm-to-cim %s | cinm-opt | FileCheck %s 2 | 3 | // CHECK-LABEL: simple 4 | func.func @simple(%t0: tensor<6x6xi32>, %t1: tensor<6x6xi32>, %t2 : tensor<6xi32>) { 5 | 6 | // CHECK %0 = cim.acquire_device -> !cim.deviceId 7 | // CHECK %1 = cim.acquire_crossbar %0 : !cim.deviceId -> !cim.crossbarId 8 | %result = cinm.compute -> tensor<6xi32> { 9 | // CHECK %2 = cim.op.gemm %arg0, %arg1 : tensor<6x6xi32>, tensor<6x6xi32> -> !cim.future<6x6xi32> 10 | %r0 = cinm.op.gemm %t0, %t1 : (tensor<6x6xi32>, tensor<6x6xi32>) -> tensor<6x6xi32> 11 | // CHECK %3 = cim.op.gemv %2, %arg2 : !cim.future<6x6xi32>, tensor<6xi32> -> !cim.future<6xi32> 12 | %r1 = cinm.op.gemv %r0, %t2 : (tensor<6x6xi32>, tensor<6xi32>) -> tensor<6xi32> 13 | // CHECK %4 = cim.barrier %3 : !cim.future<6xi32> -> tensor<6xi32> 14 | cinm.yield %r1: tensor<6xi32> 15 | } 16 | // CHECK cim.release_crossbar %1 : !cim.crossbarId 17 | // CHECK cim.release_device %0 : !cim.deviceId 18 | 19 | return 20 | } 21 | 22 | -------------------------------------------------------------------------------- /cinnamon/test/Dialect/Cim/cim-ops.mlir: -------------------------------------------------------------------------------- 1 | // RUN: cinm-opt %s | cinm-opt | FileCheck %s 2 | // RUN: cinm-opt %s --mlir-print-op-generic | cinm-opt | FileCheck %s 3 | 4 | 5 | // CHECK-LABEL: simple 6 | func.func @simple(%t0: tensor<6x3xi32>, %t1: tensor<3x6xi32>, %t2 : tensor<6xi32> ) { 7 | %device = cim.acquire_device -> !cim.deviceId 8 | %crossbar = cim.acquire_crossbar %device : !cim.deviceId -> !cim.crossbarId 9 | 10 | %r0 = cim.op.gemm %crossbar, %t0, %t1 : !cim.crossbarId, tensor<6x3xi32>, tensor<3x6xi32> -> !cim.future<6x6xi32> 11 | %r1 = cim.op.gemv %crossbar, %r0, %t2 : !cim.crossbarId, !cim.future<6x6xi32>, tensor<6xi32> -> !cim.future<6xi32> 12 | 13 | %result = cim.barrier %r1 : !cim.future<6xi32> -> tensor<6xi32> 14 | 15 | cim.release_crossbar %crossbar : !cim.crossbarId 16 | cim.release_device %device : !cim.deviceId 17 | 18 | return 19 | } 20 | -------------------------------------------------------------------------------- /cinnamon/test/Dialect/Memristor/memristor-ops.mlir: -------------------------------------------------------------------------------- 1 | // RUN: cinm-opt %s | cinm-opt | FileCheck %s 2 | // RUN: cinm-opt %s --mlir-print-op-generic | cinm-opt | FileCheck %s 3 | 4 | 5 | // CHECK-LABEL: simple 6 | func.func @simple(%t0: memref<6x6xi32>, %t1 : memref<6x6xi32>, %t2 : memref<6xi32>) { 7 | %tile = arith.constant 0 : i64 8 | 9 | %rm0 = memref.alloc() : memref<6x6xi32> 10 | %rm1 = memref.alloc() : memref<6xi32> 11 | 12 | memristor.write_to_crossbar %tile, %t1 : i64, memref<6x6xi32> 13 | memristor.gemm %tile, %t0, %rm0 : i64, memref<6x6xi32>, memref<6x6xi32> 14 | 15 | memristor.write_to_crossbar %tile, %rm0 : i64, memref<6x6xi32> 16 | memristor.gevm %tile, %t2, %rm1 : i64, memref<6xi32>, memref<6xi32> 17 | 18 | memristor.barrier %tile : i64 19 | 20 | return 21 | } 22 | 23 | -------------------------------------------------------------------------------- /cinnamon/test/Python/cinm_backend.py: -------------------------------------------------------------------------------- 1 | # RUN: python %s | FileCheck %s 2 | 3 | import torch 4 | from cinnamon.torch_backend.cinm import CinmBackend 5 | 6 | 7 | def predictable_tensor(shape, dtype): 8 | count = torch.tensor(shape).prod() 9 | values = range(1, 1 + count) 10 | return torch.tensor(values, dtype=dtype).reshape(shape) 11 | 12 | 13 | def predictable_param(param): 14 | return torch.nn.Parameter(predictable_tensor(param.shape, param.dtype)) 15 | 16 | 17 | class Model(torch.nn.Module): 18 | def __init__(self): 19 | super(Model, self).__init__() 20 | 21 | self.fc1 = torch.nn.Linear(5, 5) 22 | self.fc1.weight = predictable_param(self.fc1.weight) 23 | self.fc1.bias = predictable_param(self.fc1.bias) 24 | 25 | self.fc2 = torch.nn.Linear(5, 10) 26 | self.fc2.weight = predictable_param(self.fc2.weight) 27 | self.fc2.bias = predictable_param(self.fc2.bias) 28 | 29 | self.fc3 = torch.nn.Linear(10, 2) 30 | self.fc3.weight = predictable_param(self.fc3.weight) 31 | self.fc3.bias = predictable_param(self.fc3.bias) 32 | 33 | def forward(self, x): 34 | x = self.fc1(x) 35 | x = self.fc2(x) 36 | x = self.fc3(x) 37 | return x 38 | 39 | 40 | model = Model() 41 | 42 | sample_input = predictable_tensor((1, 5), torch.float32) 43 | 44 | backend = CinmBackend() 45 | compiled_model = backend.compile(model, sample_input) 46 | 47 | model_invoker = backend.load(compiled_model) 48 | 49 | # CHECK: model via torch [1929786. 4658337.] 50 | print("model via torch", model(sample_input).detach().numpy()[0]) 51 | # CHECK: model via cinm [1929786. 4658337.] 52 | print("model via cinm", model_invoker.main(sample_input).numpy()[0]) 53 | -------------------------------------------------------------------------------- /cinnamon/test/Python/linalg_backend.py: -------------------------------------------------------------------------------- 1 | # RUN: python %s | FileCheck %s 2 | 3 | import torch 4 | from cinnamon.torch_backend.linalg_on_tensor import LinalgOnTensorBackend 5 | 6 | 7 | def predictable_tensor(shape, dtype): 8 | count = torch.tensor(shape).prod() 9 | values = range(1, 1 + count) 10 | return torch.tensor(values, dtype=dtype).reshape(shape) 11 | 12 | 13 | def predictable_param(param): 14 | return torch.nn.Parameter(predictable_tensor(param.shape, param.dtype)) 15 | 16 | 17 | class Model(torch.nn.Module): 18 | def __init__(self): 19 | super(Model, self).__init__() 20 | 21 | self.fc1 = torch.nn.Linear(5, 5) 22 | self.fc1.weight = predictable_param(self.fc1.weight) 23 | self.fc1.bias = predictable_param(self.fc1.bias) 24 | 25 | self.fc2 = torch.nn.Linear(5, 10) 26 | self.fc2.weight = predictable_param(self.fc2.weight) 27 | self.fc2.bias = predictable_param(self.fc2.bias) 28 | 29 | self.fc3 = torch.nn.Linear(10, 2) 30 | self.fc3.weight = predictable_param(self.fc3.weight) 31 | self.fc3.bias = predictable_param(self.fc3.bias) 32 | 33 | def forward(self, x): 34 | x = self.fc1(x) 35 | x = self.fc2(x) 36 | x = self.fc3(x) 37 | return x 38 | 39 | 40 | model = Model() 41 | 42 | sample_input = predictable_tensor((1, 5), torch.float32) 43 | 44 | backend = LinalgOnTensorBackend() 45 | compiled_model = backend.compile(model, sample_input) 46 | 47 | model_invoker = backend.load(compiled_model) 48 | 49 | # CHECK: model via torch [1929786. 4658337.] 50 | print("model via torch", model(sample_input).detach().numpy()[0]) 51 | # CHECK: model via cinm [1929786. 4658337.] 52 | print("model via cinm", model_invoker.main(sample_input).numpy()[0]) 53 | -------------------------------------------------------------------------------- /cinnamon/test/lit.site.cfg.py.in: -------------------------------------------------------------------------------- 1 | @LIT_SITE_CFG_IN_HEADER@ 2 | 3 | import sys 4 | 5 | config.llvm_src_root = "@LLVM_SOURCE_DIR@" 6 | config.llvm_obj_root = "@LLVM_BINARY_DIR@" 7 | config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" 8 | config.llvm_lib_dir = "@LLVM_LIBS_DIR@" 9 | config.llvm_shlib_dir = "@SHLIBDIR@" 10 | config.llvm_shlib_ext = "@SHLIBEXT@" 11 | config.llvm_exe_ext = "@EXEEXT@" 12 | config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" 13 | config.python_executable = sys.executable 14 | 15 | config.base2_src_root = "@CMAKE_SOURCE_DIR@" 16 | config.base2_obj_root = "@CMAKE_BINARY_DIR@" 17 | 18 | import lit.llvm 19 | lit.llvm.initialize(lit_config, config) 20 | 21 | # Let the main config do the real work. 22 | lit_config.load_config(config, "@CMAKE_SOURCE_DIR@/test/lit.cfg.py") 23 | -------------------------------------------------------------------------------- /cinnamon/testbench/.gitignore: -------------------------------------------------------------------------------- 1 | *.*.mlir 2 | *.upmem.c 3 | *.*.ll 4 | *.o 5 | *.s 6 | generated2 -------------------------------------------------------------------------------- /cinnamon/testbench/apps/1mm.cpp: -------------------------------------------------------------------------------- 1 | #include "../lib/bench/testbench.hpp" 2 | #include 3 | 4 | extern "C" { 5 | void *mm_dimm4_nopt(int32_t *, int32_t *); 6 | void *mm_dimm4_opt(int32_t *, int32_t *); 7 | void *mm_dimm8_nopt(int32_t *, int32_t *); 8 | void *mm_dimm8_opt(int32_t *, int32_t *); 9 | void *mm_dimm16_nopt(int32_t *, int32_t *); 10 | void *mm_dimm16_opt(int32_t *, int32_t *); 11 | } 12 | 13 | #define BENCH_MM(ty, M, K, N, fun_name) \ 14 | do { \ 15 | ty *A = init_matrix(); \ 16 | ty *B = init_matrix(); \ 17 | DO_BENCH(REPS, WARMUP, fun_name(A, B)); \ 18 | free(A); \ 19 | free(B); \ 20 | } while (false) 21 | 22 | int main(void) { 23 | srand(0); 24 | 25 | BENCH_MM(int32_t, 8, 1024, 256, mm_dimm4_nopt); 26 | BENCH_MM(int32_t, 16, 1024, 128, mm_dimm4_opt); 27 | 28 | BENCH_MM(int32_t, 8, 1024, 128, mm_dimm8_nopt); 29 | // BENCH_MM(int32_t, 16, 1024, 64, mm_dimm8_opt); 30 | 31 | // BENCH_MM(int32_t, 8, 1024, 64, mm_dimm16_nopt); 32 | // BENCH_MM(int32_t, 16, 1024, 32, mm_dimm16_opt); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /cinnamon/testbench/apps/2mm.cpp: -------------------------------------------------------------------------------- 1 | #include "../lib/bench/testbench.hpp" 2 | #include 3 | 4 | extern "C" { 5 | void *mm_dimm4_nopt(int32_t *, int32_t *); 6 | void *mm_dimm4_opt(int32_t *, int32_t *); 7 | void *mm_dimm8_nopt(int32_t *, int32_t *); 8 | void *mm_dimm8_opt(int32_t *, int32_t *); 9 | void *mm_dimm16_nopt(int32_t *, int32_t *); 10 | void *mm_dimm16_opt(int32_t *, int32_t *); 11 | } 12 | 13 | #define BENCH_MM(ty, M, K, N, fun_name) \ 14 | do { \ 15 | ty *A = init_matrix(); \ 16 | ty *B = init_matrix(); \ 17 | DO_BENCH(REPS, WARMUP, fun_name(A, B)); \ 18 | free(A); \ 19 | free(B); \ 20 | } while (false) 21 | 22 | int main(void) { 23 | srand(0); 24 | 25 | BENCH_MM(int32_t, 8, 1024, 256, mm_dimm4_nopt); 26 | BENCH_MM(int32_t, 16, 1024, 128, mm_dimm4_opt); 27 | 28 | BENCH_MM(int32_t, 8, 1024, 128, mm_dimm8_nopt); 29 | // BENCH_MM(int32_t, 16, 1024, 64, mm_dimm8_opt); 30 | 31 | // BENCH_MM(int32_t, 8, 1024, 64, mm_dimm16_nopt); 32 | // BENCH_MM(int32_t, 16, 1024, 32, mm_dimm16_opt); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /cinnamon/testbench/apps/3mm.cpp: -------------------------------------------------------------------------------- 1 | #include "../lib/bench/testbench.hpp" 2 | #include 3 | 4 | extern "C" { 5 | void *mm_dimm4_nopt(int32_t *, int32_t *); 6 | void *mm_dimm4_opt(int32_t *, int32_t *); 7 | void *mm_dimm8_nopt(int32_t *, int32_t *); 8 | void *mm_dimm8_opt(int32_t *, int32_t *); 9 | void *mm_dimm16_nopt(int32_t *, int32_t *); 10 | void *mm_dimm16_opt(int32_t *, int32_t *); 11 | } 12 | 13 | #define BENCH_MM(ty, M, K, N, fun_name) \ 14 | do { \ 15 | ty *A = init_matrix(); \ 16 | ty *B = init_matrix(); \ 17 | DO_BENCH(REPS, WARMUP, fun_name(A, B)); \ 18 | free(A); \ 19 | free(B); \ 20 | } while (false) 21 | 22 | int main(void) { 23 | srand(0); 24 | 25 | BENCH_MM(int32_t, 8, 1024, 256, mm_dimm4_nopt); 26 | BENCH_MM(int32_t, 16, 1024, 128, mm_dimm4_opt); 27 | 28 | BENCH_MM(int32_t, 8, 1024, 128, mm_dimm8_nopt); 29 | // BENCH_MM(int32_t, 16, 1024, 64, mm_dimm8_opt); 30 | 31 | // BENCH_MM(int32_t, 8, 1024, 64, mm_dimm16_nopt); 32 | // BENCH_MM(int32_t, 16, 1024, 32, mm_dimm16_opt); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /cinnamon/testbench/apps/conv.cpp: -------------------------------------------------------------------------------- 1 | #include "../lib/bench/testbench.hpp" 2 | #include 3 | 4 | // linked with LLVM module 5 | extern "C" { 6 | int32_t *mm_dimm4_nopt(int32_t *, int32_t *); 7 | int32_t *mm_dimm4_opt(int32_t *, int32_t *); 8 | int32_t *mm_dimm8_nopt(int32_t *, int32_t *); 9 | int32_t *mm_dimm8_opt(int32_t *, int32_t *); 10 | int32_t *mm_dimm16_nopt(int32_t *, int32_t *); 11 | int32_t *mm_dimm16_opt(int32_t *, int32_t *); 12 | } 13 | 14 | #define BENCH_MM(ty, M, K, N, fun_name) \ 15 | do { \ 16 | ty *A = init_matrix(); \ 17 | ty *B = init_matrix(); \ 18 | DO_BENCH(REPS, WARMUP, fun_name(A, B)); \ 19 | free(A); \ 20 | free(B); \ 21 | } while (false) 22 | 23 | int main(void) { 24 | srand(0); 25 | 26 | BENCH_MM(int32_t, 25088, 16, 256, mm_dimm4_nopt); 27 | BENCH_MM(int32_t, 6272, 64, 256, mm_dimm4_opt); 28 | 29 | BENCH_MM(int32_t, 25088, 8, 256, mm_dimm8_nopt); 30 | BENCH_MM(int32_t, 3136, 64, 256, mm_dimm8_opt); 31 | 32 | BENCH_MM(int32_t, 25088, 4, 256, mm_dimm16_nopt); 33 | BENCH_MM(int32_t, 1568, 64, 256, mm_dimm16_opt); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /cinnamon/testbench/apps/mlp.cpp: -------------------------------------------------------------------------------- 1 | #include "../lib/bench/testbench.hpp" 2 | #include 3 | 4 | // linked with LLVM module 5 | extern "C" { 6 | int32_t *mm_dimm1_nopt(int32_t *, int32_t *); 7 | int32_t *mm_dimm1_opt(int32_t *, int32_t *); 8 | int32_t *mm_dimm2_nopt(int32_t *, int32_t *); 9 | int32_t *mm_dimm2_opt(int32_t *, int32_t *); 10 | int32_t *mm_dimm4_nopt(int32_t *, int32_t *); 11 | int32_t *mm_dimm4_opt(int32_t *, int32_t *); 12 | } 13 | 14 | #define BENCH_MM(ty, M, K, N, fun_name) \ 15 | do { \ 16 | ty *A = init_matrix(); \ 17 | ty *B = init_matrix(); \ 18 | DO_BENCH(REPS, WARMUP, fun_name(A, B)); \ 19 | free(A); \ 20 | free(B); \ 21 | } while (false) 22 | 23 | int main(void) { 24 | srand(0); 25 | 26 | BENCH_MM(int32_t, 1, 1024, 512, mm_dimm1_nopt); 27 | BENCH_MM(int32_t, 16, 64, 512, mm_dimm1_opt); 28 | 29 | BENCH_MM(int32_t, 1, 1024, 256, mm_dimm2_nopt); 30 | BENCH_MM(int32_t, 16, 64, 256, mm_dimm2_opt); 31 | 32 | //BENCH_MM(int32_t, 1, 1024, 128, mm_dimm4_nopt); 33 | BENCH_MM(int32_t, 16, 64, 128, mm_dimm4_opt); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /cinnamon/testbench/apps/mv.cpp: -------------------------------------------------------------------------------- 1 | #include "../lib/bench/testbench.hpp" 2 | #include 3 | 4 | extern "C" { 5 | // int32_t *mv_dimm4_nopt(int32_t *, int32_t *); 6 | int32_t *mv_dimm4_opt(int32_t *, int32_t *); 7 | int32_t *mv_dimm8_nopt(int32_t *, int32_t *); 8 | // int32_t* mv_dimm8_opt(int32_t *, int32_t *); 9 | // int32_t* mv_dimm16_nopt(int32_t *, int32_t *); 10 | int32_t *mv_dimm16_opt(int32_t *, int32_t *); 11 | } 12 | 13 | #define BENCH_MV(ty, M, N, fun_name) \ 14 | do { \ 15 | ty *A = init_matrix(); \ 16 | ty *B = init_matrix(); \ 17 | DO_BENCH(REPS, WARMUP, fun_name(A, B)); \ 18 | free(A); \ 19 | free(B); \ 20 | } while (false) 21 | 22 | int main(void) { 23 | srand(0); 24 | 25 | // BENCH_MV(int32_t, 128, 65536, mv_dimm4_nopt); 26 | BENCH_MV(int32_t, 4096, 2048, mv_dimm4_opt); 27 | 28 | BENCH_MV(int32_t, 16384, 512, mv_dimm8_nopt); 29 | // BENCH_MV(int32_t, 4096, 2048, mv_dimm8_opt); 30 | 31 | // BENCH_MV(int32_t, 128, 65536, mv_dimm16_nopt); 32 | BENCH_MV(int32_t, 16384, 128, mv_dimm16_opt); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /cinnamon/testbench/apps/va.cpp: -------------------------------------------------------------------------------- 1 | #include "../lib/bench/testbench.hpp" 2 | #include 3 | 4 | extern "C" { 5 | void va_8(int32_t *, int32_t *); 6 | void va_16(int32_t *, int32_t *); 7 | } 8 | 9 | #define BENCH_VA(ty, M, N, fun_name) \ 10 | do { \ 11 | ty *A = init_matrix(); \ 12 | ty *B = init_matrix(); \ 13 | DO_BENCH(REPS, WARMUP, fun_name(A, B)); \ 14 | free(A); \ 15 | free(B); \ 16 | } while (false) 17 | 18 | int main(void) { 19 | srand(0); 20 | 21 | BENCH_VA(int32_t, 8, 2097152, va_8); 22 | BENCH_VA(int32_t, 16, 1048576, va_16); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /cinnamon/testbench/gemm.mlir: -------------------------------------------------------------------------------- 1 | func.func @main() { 2 | %a = tensor.empty() : tensor<64x64xi32> 3 | %b = tensor.empty() : tensor<64x64xi32> 4 | %res = cinm.compute attributes{ workgroupShape = array }-> tensor<64x64xi32> { 5 | %d = cinm.op.gemm %a, %b : (tensor<64x64xi32>, tensor<64x64xi32>) -> tensor<64x64xi32> 6 | cinm.yield %d : tensor<64x64xi32> 7 | } 8 | return 9 | } 10 | -------------------------------------------------------------------------------- /cinnamon/testbench/generated/1mm/Makefile: -------------------------------------------------------------------------------- 1 | DPU_DIR := dpu 2 | HOST_DIR := host 3 | BUILDDIR ?= bin 4 | NR_TASKLETS ?= 16 5 | BL ?= 10 6 | NR_DPUS ?= 64 7 | 8 | define conf_filename 9 | ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3).conf 10 | endef 11 | CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL}) 12 | 13 | HOST_TARGET := ${BUILDDIR}/host 14 | DPU_TARGET := ${BUILDDIR}/dpu 15 | 16 | COMMON_INCLUDES := support 17 | HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) 18 | DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) 19 | 20 | .PHONY: all clean test 21 | 22 | __dirs := $(shell mkdir -p ${BUILDDIR}) 23 | 24 | COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES} 25 | HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} 26 | DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} 27 | 28 | all: ${HOST_TARGET} ${DPU_TARGET} 29 | 30 | ${CONF}: 31 | $(RM) $(call conf_filename,*,*) 32 | touch ${CONF} 33 | 34 | ${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} 35 | $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} 36 | 37 | ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} 38 | dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} 39 | 40 | clean: 41 | $(RM) -r $(BUILDDIR) 42 | 43 | test: all 44 | ./${HOST_TARGET} -m 4096 -n 4096 45 | -------------------------------------------------------------------------------- /cinnamon/testbench/generated/1mm/support/common.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef COMMON_H_ 3 | #define COMMON_H_ 4 | #include 5 | 6 | #define T uint32_t 7 | 8 | 9 | #define ITERATION 1 10 | 11 | typedef struct { 12 | uint32_t cycles; 13 | } dpu_result_t; 14 | 15 | typedef struct { 16 | dpu_result_t tasklet_result[NR_TASKLETS]; 17 | } dpu_results_t; 18 | 19 | typedef struct { 20 | uint32_t m_size; 21 | uint32_t n_size; 22 | uint32_t q_size; 23 | } dpu_arguments_t; 24 | 25 | // Specific information for each DPU 26 | struct dpu_info_t { 27 | uint32_t m_size; 28 | uint32_t n_size; 29 | uint32_t q_size; 30 | }; 31 | struct dpu_info_t *dpu_info; 32 | 33 | #endif // COMMON_H_ -------------------------------------------------------------------------------- /cinnamon/testbench/generated/2mm/Makefile: -------------------------------------------------------------------------------- 1 | DPU_DIR := dpu 2 | HOST_DIR := host 3 | BUILDDIR ?= bin 4 | NR_TASKLETS ?= 16 5 | BL ?= 10 6 | NR_DPUS ?= 64 7 | 8 | define conf_filename 9 | ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3).conf 10 | endef 11 | CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL}) 12 | 13 | HOST_TARGET := ${BUILDDIR}/host 14 | DPU_TARGET := ${BUILDDIR}/dpu 15 | 16 | COMMON_INCLUDES := support 17 | HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) 18 | DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) 19 | 20 | .PHONY: all clean test 21 | 22 | __dirs := $(shell mkdir -p ${BUILDDIR}) 23 | 24 | COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES} 25 | HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} 26 | DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} 27 | 28 | all: ${HOST_TARGET} ${DPU_TARGET} 29 | 30 | ${CONF}: 31 | $(RM) $(call conf_filename,*,*) 32 | touch ${CONF} 33 | 34 | ${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} 35 | $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} 36 | 37 | ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} 38 | dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} 39 | 40 | clean: 41 | $(RM) -r $(BUILDDIR) 42 | 43 | test: all 44 | ./${HOST_TARGET} -m 4096 -n 4096 45 | -------------------------------------------------------------------------------- /cinnamon/testbench/generated/2mm/support/common.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef COMMON_H_ 3 | #define COMMON_H_ 4 | #include 5 | 6 | #define T uint32_t 7 | 8 | 9 | #define ITERATION 1 10 | 11 | typedef struct { 12 | uint32_t cycles; 13 | } dpu_result_t; 14 | 15 | typedef struct { 16 | dpu_result_t tasklet_result[NR_TASKLETS]; 17 | } dpu_results_t; 18 | 19 | typedef struct { 20 | uint32_t m_size; 21 | uint32_t n_size; 22 | uint32_t q_size; 23 | } dpu_arguments_t; 24 | 25 | // Specific information for each DPU 26 | struct dpu_info_t { 27 | uint32_t m_size; 28 | uint32_t n_size; 29 | uint32_t q_size; 30 | }; 31 | struct dpu_info_t *dpu_info; 32 | 33 | #endif // COMMON_H_ -------------------------------------------------------------------------------- /cinnamon/testbench/generated/3mm/Makefile: -------------------------------------------------------------------------------- 1 | DPU_DIR := dpu 2 | HOST_DIR := host 3 | BUILDDIR ?= bin 4 | NR_TASKLETS ?= 16 5 | BL ?= 10 6 | NR_DPUS ?= 64 7 | 8 | define conf_filename 9 | ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3).conf 10 | endef 11 | CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL}) 12 | 13 | HOST_TARGET := ${BUILDDIR}/host 14 | DPU_TARGET := ${BUILDDIR}/dpu 15 | 16 | COMMON_INCLUDES := support 17 | HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) 18 | DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) 19 | 20 | .PHONY: all clean test 21 | 22 | __dirs := $(shell mkdir -p ${BUILDDIR}) 23 | 24 | COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES} 25 | HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} 26 | DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} 27 | 28 | all: ${HOST_TARGET} ${DPU_TARGET} 29 | 30 | ${CONF}: 31 | $(RM) $(call conf_filename,*,*) 32 | touch ${CONF} 33 | 34 | ${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} 35 | $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} 36 | 37 | ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} 38 | dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} 39 | 40 | clean: 41 | $(RM) -r $(BUILDDIR) 42 | 43 | test: all 44 | ./${HOST_TARGET} -m 4096 -n 4096 45 | -------------------------------------------------------------------------------- /cinnamon/testbench/generated/3mm/support/common.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef COMMON_H_ 3 | #define COMMON_H_ 4 | #include 5 | 6 | #define T uint32_t 7 | 8 | 9 | #define ITERATION 1 10 | 11 | typedef struct { 12 | uint32_t cycles; 13 | } dpu_result_t; 14 | 15 | typedef struct { 16 | dpu_result_t tasklet_result[NR_TASKLETS]; 17 | } dpu_results_t; 18 | 19 | typedef struct { 20 | uint32_t m_size; 21 | uint32_t n_size; 22 | uint32_t q_size; 23 | } dpu_arguments_t; 24 | 25 | // Specific information for each DPU 26 | struct dpu_info_t { 27 | uint32_t m_size; 28 | uint32_t n_size; 29 | uint32_t q_size; 30 | }; 31 | struct dpu_info_t *dpu_info; 32 | 33 | #endif // COMMON_H_ -------------------------------------------------------------------------------- /cinnamon/testbench/generated/conv/Makefile: -------------------------------------------------------------------------------- 1 | DPU_DIR := dpu 2 | HOST_DIR := host 3 | BUILDDIR ?= bin 4 | NR_TASKLETS ?= 16 5 | BL ?= 10 6 | NR_DPUS ?= 64 7 | 8 | define conf_filename 9 | ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3).conf 10 | endef 11 | CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL}) 12 | 13 | HOST_TARGET := ${BUILDDIR}/host 14 | DPU_TARGET := ${BUILDDIR}/dpu 15 | 16 | COMMON_INCLUDES := support 17 | HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) 18 | DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) 19 | 20 | .PHONY: all clean test 21 | 22 | __dirs := $(shell mkdir -p ${BUILDDIR}) 23 | 24 | COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES} 25 | HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} 26 | DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} 27 | 28 | all: ${HOST_TARGET} ${DPU_TARGET} 29 | 30 | ${CONF}: 31 | $(RM) $(call conf_filename,*,*) 32 | touch ${CONF} 33 | 34 | ${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} 35 | $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} 36 | 37 | ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} 38 | dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} 39 | 40 | clean: 41 | $(RM) -r $(BUILDDIR) 42 | 43 | test: all 44 | ./${HOST_TARGET} -m 4096 -n 4096 45 | -------------------------------------------------------------------------------- /cinnamon/testbench/generated/conv/support/common.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef COMMON_H_ 3 | #define COMMON_H_ 4 | #include 5 | 6 | #define T uint32_t 7 | 8 | 9 | #define ITERATION 1 10 | 11 | typedef struct { 12 | uint32_t cycles; 13 | } dpu_result_t; 14 | 15 | typedef struct { 16 | dpu_result_t tasklet_result[NR_TASKLETS]; 17 | } dpu_results_t; 18 | 19 | typedef struct { 20 | uint32_t m_size; 21 | uint32_t n_size; 22 | uint32_t q_size; 23 | } dpu_arguments_t; 24 | 25 | // Specific information for each DPU 26 | struct dpu_info_t { 27 | uint32_t m_size; 28 | uint32_t n_size; 29 | uint32_t q_size; 30 | }; 31 | struct dpu_info_t *dpu_info; 32 | 33 | #endif // COMMON_H_ -------------------------------------------------------------------------------- /cinnamon/testbench/generated/hst/Makefile: -------------------------------------------------------------------------------- 1 | DPU_DIR := dpu 2 | HOST_DIR := host 3 | BUILDDIR ?= bin 4 | NR_TASKLETS ?= 16 5 | BL ?= 10 6 | NR_DPUS ?= 64 7 | 8 | define conf_filename 9 | ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3).conf 10 | endef 11 | CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL}) 12 | 13 | HOST_TARGET := ${BUILDDIR}/host 14 | DPU_TARGET := ${BUILDDIR}/dpu 15 | 16 | COMMON_INCLUDES := support 17 | HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) 18 | DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) 19 | 20 | .PHONY: all clean test 21 | 22 | __dirs := $(shell mkdir -p ${BUILDDIR}) 23 | 24 | COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES} 25 | HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} 26 | DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} 27 | 28 | all: ${HOST_TARGET} ${DPU_TARGET} 29 | 30 | ${CONF}: 31 | $(RM) $(call conf_filename,*,*) 32 | touch ${CONF} 33 | 34 | ${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} 35 | $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} 36 | 37 | ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} 38 | dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} 39 | 40 | clean: 41 | $(RM) -r $(BUILDDIR) 42 | 43 | test: all 44 | ./${HOST_TARGET} -m 4096 -n 4096 45 | -------------------------------------------------------------------------------- /cinnamon/testbench/generated/hst/input/image_VanHateren.iml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tud-ccc/Cinnamon/715eb4d97359966792a80d6540bfb856ba6b9357/cinnamon/testbench/generated/hst/input/image_VanHateren.iml -------------------------------------------------------------------------------- /cinnamon/testbench/generated/hst/support/common.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMMON_H_ 2 | #define _COMMON_H_ 3 | 4 | #ifdef BL 5 | #define BLOCK_SIZE_LOG2 BL 6 | #define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2) 7 | #else 8 | #define BLOCK_SIZE_LOG2 8 9 | #define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2) 10 | #define BL BLOCK_SIZE_LOG2 11 | #endif 12 | 13 | // Data type 14 | #define T uint32_t 15 | #define DIV 2 // Shift right to divide by sizeof(T) 16 | 17 | // Pixel depth 18 | #define DEPTH 12 19 | #define ByteSwap16(n) (((((unsigned int)n) << 8) & 0xFF00) | ((((unsigned int)n) >> 8) & 0x00FF)) 20 | 21 | // Structures used by both the host and the dpu to communicate information 22 | typedef struct { 23 | uint32_t size; 24 | uint32_t transfer_size; 25 | uint32_t buffer_size; 26 | uint32_t bins; 27 | } dpu_arguments_t; 28 | 29 | 30 | #define ANSI_COLOR_RED "\x1b[31m" 31 | #define ANSI_COLOR_GREEN "\x1b[32m" 32 | #define ANSI_COLOR_RESET "\x1b[0m" 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /cinnamon/testbench/generated/mv/Makefile: -------------------------------------------------------------------------------- 1 | DPU_DIR := dpu 2 | HOST_DIR := host 3 | BUILDDIR ?= bin 4 | NR_TASKLETS ?= 16 5 | BL ?= 10 6 | NR_DPUS ?= 1 7 | 8 | define conf_filename 9 | ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3).conf 10 | endef 11 | CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL}) 12 | 13 | HOST_TARGET := ${BUILDDIR}/host 14 | DPU_TARGET := ${BUILDDIR}/dpu 15 | 16 | COMMON_INCLUDES := support 17 | HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) 18 | DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) 19 | 20 | .PHONY: all clean test 21 | 22 | __dirs := $(shell mkdir -p ${BUILDDIR}) 23 | 24 | COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES} 25 | HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} 26 | DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} 27 | 28 | all: ${HOST_TARGET} ${DPU_TARGET} 29 | 30 | ${CONF}: 31 | $(RM) $(call conf_filename,*,*) 32 | touch ${CONF} 33 | 34 | ${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} 35 | $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} 36 | 37 | ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} 38 | dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} 39 | 40 | clean: 41 | $(RM) -r $(BUILDDIR) 42 | 43 | test: all 44 | ./${HOST_TARGET} -m 1024 -n 1024 45 | -------------------------------------------------------------------------------- /cinnamon/testbench/generated/mv/support/common.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef COMMON_H_ 3 | #define COMMON_H_ 4 | #include 5 | 6 | #define XSTR(x) STR(x) 7 | #define STR(x) #x 8 | 9 | #define T uint32_t 10 | 11 | 12 | #define ITERATION 1 13 | 14 | typedef struct { 15 | uint32_t cycles; 16 | } dpu_result_t; 17 | 18 | typedef struct { 19 | dpu_result_t tasklet_result[NR_TASKLETS]; 20 | } dpu_results_t; 21 | 22 | typedef struct { 23 | uint32_t m_size; 24 | uint32_t n_size; 25 | } dpu_arguments_t; 26 | 27 | // Specific information for each DPU 28 | struct dpu_info_t { 29 | uint32_t m_size; 30 | uint32_t n_size; 31 | }; 32 | struct dpu_info_t *dpu_info; 33 | 34 | #endif // COMMON_H_ -------------------------------------------------------------------------------- /cinnamon/testbench/generated/red/Makefile: -------------------------------------------------------------------------------- 1 | DPU_DIR := dpu 2 | HOST_DIR := host 3 | BUILDDIR ?= bin 4 | NR_TASKLETS ?= 16 5 | BL ?= 10 6 | NR_DPUS ?= 1 7 | VERSION ?= SINGLE 8 | SYNC ?= HAND 9 | TYPE ?= INT64 10 | ENERGY ?= 0 11 | PERF ?= 0 12 | 13 | define conf_filename 14 | ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3)_VERSION_$(4)_SYNC_$(5)_TYPE_$(6).conf 15 | endef 16 | CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL},${VERSION},${SYNC},${TYPE}) 17 | 18 | HOST_TARGET := ${BUILDDIR}/host 19 | DPU_TARGET := ${BUILDDIR}/dpu 20 | 21 | COMMON_INCLUDES := support 22 | HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) 23 | DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) 24 | 25 | .PHONY: all clean test 26 | 27 | __dirs := $(shell mkdir -p ${BUILDDIR}) 28 | 29 | COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES} 30 | HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} -D${VERSION} -D${SYNC} -D${TYPE} -DENERGY=${ENERGY} -DPERF=${PERF} 31 | DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${VERSION} -D${SYNC} -D${TYPE} -DPERF=${PERF} 32 | 33 | all: ${HOST_TARGET} ${DPU_TARGET} 34 | 35 | ${CONF}: 36 | $(RM) $(call conf_filename,*,*) 37 | touch ${CONF} 38 | 39 | ${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} 40 | $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} 41 | 42 | ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} 43 | dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} 44 | 45 | clean: 46 | $(RM) -r $(BUILDDIR) 47 | 48 | test: all 49 | ./${HOST_TARGET} -w 0 -e 1 -i 6553600 -x 1 50 | -------------------------------------------------------------------------------- /cinnamon/testbench/generated/red/support/common.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMMON_H_ 2 | #define _COMMON_H_ 3 | 4 | typedef struct { 5 | uint32_t size; 6 | uint32_t buffer_size; 7 | } dpu_arguments_t; 8 | 9 | typedef struct { 10 | uint64_t cycles; 11 | int output; 12 | } dpu_results_t; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /cinnamon/testbench/generated/run_benchmarks.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | import csv 4 | 5 | 6 | def run(bench): 7 | os.chdir(bench) 8 | 9 | subprocess.run(["make", "clean"], stdout=subprocess.PIPE) 10 | subprocess.run(["make"]) 11 | output = subprocess.run(["./bin/host"], stdout=subprocess.PIPE).stdout.decode('utf-8') 12 | os.chdir("../") 13 | results = {} 14 | last_dimm_count = None 15 | last_exec_type = None 16 | for line in output.split("\n"): 17 | if line.startswith("Non-opt") or line.startswith("Opt"): 18 | dimm_count = int(line.split(" ")[1]) 19 | exec_type = line.split(" ")[0] 20 | if dimm_count not in results : 21 | results[dimm_count] = {} 22 | if exec_type not in results[dimm_count]: 23 | results[dimm_count][exec_type] = 0 24 | last_dimm_count = dimm_count 25 | last_exec_type = exec_type 26 | 27 | elif len(line) > 1: 28 | results[last_dimm_count][last_exec_type] += float(line) 29 | return results 30 | 31 | 32 | 33 | 34 | 35 | def run_cinm(): 36 | numbers = {} 37 | benchmarks = ["1mm", "2mm", "3mm", "hst", "va", "red", "sel", "mv", "conv"] 38 | # benchmarks = ["red", "sel", "mv", "hst", "va"] 39 | for bench in benchmarks: 40 | print(bench) 41 | numbers[bench] = run(bench) 42 | return numbers -------------------------------------------------------------------------------- /cinnamon/testbench/generated/sel/Makefile: -------------------------------------------------------------------------------- 1 | DPU_DIR := dpu 2 | HOST_DIR := host 3 | BUILDDIR ?= bin 4 | NR_TASKLETS ?= 16 5 | BL ?= 10 6 | NR_DPUS ?= 1 7 | ENERGY ?= 0 8 | 9 | define conf_filename 10 | ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3).conf 11 | endef 12 | CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL}) 13 | 14 | HOST_TARGET := ${BUILDDIR}/host 15 | DPU_TARGET := ${BUILDDIR}/dpu 16 | 17 | COMMON_INCLUDES := support 18 | HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) 19 | DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) 20 | 21 | .PHONY: all clean test 22 | 23 | __dirs := $(shell mkdir -p ${BUILDDIR}) 24 | 25 | COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES} 26 | HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} -DENERGY=${ENERGY} 27 | DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} 28 | 29 | all: ${HOST_TARGET} ${DPU_TARGET} 30 | 31 | ${CONF}: 32 | $(RM) $(call conf_filename,*,*) 33 | touch ${CONF} 34 | 35 | ${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} 36 | $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} 37 | 38 | ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} 39 | dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} 40 | 41 | clean: 42 | $(RM) -r $(BUILDDIR) 43 | 44 | test: all 45 | ./${HOST_TARGET} 46 | -------------------------------------------------------------------------------- /cinnamon/testbench/generated/sel/support/common.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMMON_H_ 2 | #define _COMMON_H_ 3 | 4 | typedef struct { 5 | uint32_t size; 6 | uint32_t buffer_size; 7 | 8 | } dpu_arguments_t; 9 | 10 | typedef struct { 11 | uint32_t t_count; 12 | } dpu_results_t; 13 | 14 | bool pred(const int x){ 15 | return (x % 2) == 0; 16 | } 17 | 18 | #ifdef BL 19 | #define BLOCK_SIZE_LOG2 BL 20 | #define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2) 21 | #else 22 | #define BLOCK_SIZE_LOG2 8 23 | #define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2) 24 | #define BL BLOCK_SIZE_LOG2 25 | #endif 26 | 27 | #define BLOCK_DIM 128 28 | // Data type 29 | #define T uint64_t 30 | #define REGS (BLOCK_SIZE >> 3) // 64 bits 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /cinnamon/testbench/generated/va/Makefile: -------------------------------------------------------------------------------- 1 | DPU_DIR := dpu 2 | HOST_DIR := host 3 | BUILDDIR ?= bin 4 | NR_TASKLETS ?= 16 5 | BL ?= 10 6 | NR_DPUS ?= 1 7 | TYPE ?= INT32 8 | ENERGY ?= 0 9 | 10 | define conf_filename 11 | ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3)_TYPE_$(4).conf 12 | endef 13 | CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL},${TYPE}) 14 | 15 | HOST_TARGET := ${BUILDDIR}/host 16 | DPU_TARGET := ${BUILDDIR}/dpu 17 | 18 | COMMON_INCLUDES := support 19 | HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) 20 | DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) 21 | 22 | .PHONY: all clean test 23 | 24 | __dirs := $(shell mkdir -p ${BUILDDIR}) 25 | 26 | COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES} 27 | HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} -D${TYPE} -DENERGY=${ENERGY} 28 | DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${TYPE} 29 | 30 | all: ${HOST_TARGET} ${DPU_TARGET} 31 | 32 | ${CONF}: 33 | $(RM) $(call conf_filename,*,*) 34 | touch ${CONF} 35 | 36 | ${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} 37 | $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} 38 | 39 | ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} 40 | dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} 41 | 42 | clean: 43 | $(RM) -r $(BUILDDIR) 44 | 45 | test: all 46 | ./${HOST_TARGET} 47 | -------------------------------------------------------------------------------- /cinnamon/testbench/generated/va/support/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H_ 2 | #define COMMON_H_ 3 | #include 4 | 5 | #define T uint32_t 6 | 7 | 8 | #define ITERATION 1 9 | 10 | typedef struct { 11 | uint32_t cycles; 12 | } dpu_result_t; 13 | 14 | typedef struct { 15 | dpu_result_t tasklet_result[NR_TASKLETS]; 16 | } dpu_results_t; 17 | 18 | typedef struct { 19 | uint32_t m_size; 20 | uint32_t buffer_size; 21 | } dpu_arguments_t; 22 | 23 | // Specific information for each DPU 24 | struct dpu_info_t { 25 | uint32_t m_size; 26 | uint32_t n_size; 27 | uint32_t q_size; 28 | uint32_t buffer_size; 29 | }; 30 | struct dpu_info_t *dpu_info; 31 | 32 | #endif // COMMON_H_ -------------------------------------------------------------------------------- /cinnamon/testbench/get_results.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | import generated.run_benchmarks 4 | import prim.run_benchmarks 5 | 6 | results = {} 7 | os.chdir("generated") 8 | results["cinm"] = generated.run_benchmarks.run_cinm() 9 | os.chdir("../prim") 10 | results["prim"] = prim.run_benchmarks.run_prim() 11 | os.chdir("..") 12 | 13 | f = open("exp-fig-12.txt", "w") 14 | 15 | dimm_counts = [4, 8, 16] 16 | print(results) 17 | 18 | fig12 = {"va":"VA", "sel":"SEL", "mv":"GEMV", "hst":"HST-L", "red":"RED"} 19 | # benchmarks = {"mv":"GEMV"} 20 | 21 | for bench in fig12: 22 | f.write(bench + " ") 23 | for dimm_count in dimm_counts: 24 | f.write(str(results["prim"][fig12[bench]][dimm_count])) 25 | f.write(" ") 26 | f.write(str(results["cinm"][bench][dimm_count]["Opt"])) 27 | f.write(" ") 28 | f.write("\n") 29 | 30 | f.close() 31 | 32 | f = open("exp-fig-11.txt", "w") 33 | fig11 = ["1mm", "2mm", "3mm", "conv", "mv"] 34 | 35 | for bench in fig11: 36 | f.write(bench + " ") 37 | for dimm_count in dimm_counts: 38 | f.write(str(results["cinm"][bench][dimm_count]["Non-opt"])) 39 | f.write(" ") 40 | f.write(str(results["cinm"][bench][dimm_count]["Opt"])) 41 | f.write(" ") 42 | f.write("\n") 43 | 44 | f.close() -------------------------------------------------------------------------------- /cinnamon/testbench/lib/bench/testbench.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define REPS 3 8 | #define WARMUP 1 9 | 10 | // todo call srand(0) before 11 | template T *init_matrix() { 12 | size_t size = 1; 13 | size_t shape[] = {Shape...}; 14 | for (auto dim : shape) { 15 | size *= dim; 16 | } 17 | 18 | T *mat = (T *)malloc(size * sizeof(T)); 19 | assert(mat && "Size of allocation too large, malloc returned 0"); 20 | for (size_t i = 0; i < size; i++) { 21 | while ((mat[i] = (T)(rand() % 100)) == 0) 22 | ; 23 | } 24 | return mat; 25 | } 26 | 27 | inline void timeAndExecute(int reps, int warmup, const char *name, 28 | std::function run) { 29 | using std::chrono::duration; 30 | using std::chrono::duration_cast; 31 | using std::chrono::high_resolution_clock; 32 | using std::chrono::milliseconds; 33 | 34 | for (int i = 0; i < warmup; i++) { 35 | run(); 36 | } 37 | auto start = high_resolution_clock::now(); 38 | for (int i = 0; i < reps; i++) { 39 | run(); 40 | } 41 | auto stop = high_resolution_clock::now(); 42 | 43 | duration ms_int = 44 | duration_cast(stop - start); 45 | printf("Average time (ms) over %d reps (%s): %f\n", reps, name, 46 | ms_int.count() / reps); 47 | } 48 | 49 | #define DO_BENCH(reps, warmup, code) \ 50 | do { \ 51 | timeAndExecute((reps), (warmup), "" #code, [&]() { code; }); \ 52 | } while (false); -------------------------------------------------------------------------------- /cinnamon/testbench/lib/compile_dpu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PROG=${1:?"Error: missing file argument"} 4 | OUTPATH=${2:?"Error: missing out directory argument"} 5 | 6 | dpuCompiler="${UPMEM_HOME:?"UPMEM_HOME is undefined"}"/bin/dpu-upmem-dpurte-clang 7 | 8 | curdir="$(dirname "$0")" 9 | 10 | mkdir -p "$OUTPATH" 11 | header="$(head -n 1 "$PROG")" 12 | pat="// UPMEM-TRANSLATE: (.*)" 13 | if [[ "$header" =~ $pat ]]; then 14 | rest="${BASH_REMATCH[1]}" 15 | # todo split, capture 16 | for word in $(echo $rest | tr ';' ' '); do 17 | pat="(\w+)\:([0-9]+):(\w+).*" 18 | if [[ "$word" =~ $pat ]]; then 19 | var="${BASH_REMATCH[1]}" 20 | threads="${BASH_REMATCH[2]}" 21 | bin_name="${BASH_REMATCH[3]}" 22 | bin_path=$(realpath "$OUTPATH/$bin_name") 23 | 24 | command="'$dpuCompiler' -DNR_TASKLETS=$threads -D$var '$PROG' -o '$bin_path' '-I$curdir/dpu' -Wall -Wextra -Werror -Wno-unused-variable" 25 | echo $command 26 | eval "$command" 27 | fi 28 | done 29 | fi 30 | -------------------------------------------------------------------------------- /cinnamon/testbench/lib/host/binary_path.h: -------------------------------------------------------------------------------- 1 | #ifndef DPU_BINARY 2 | #define DPU_BINARY "./bin/dpu" 3 | #endif -------------------------------------------------------------------------------- /cinnamon/testbench/lib/host/host_lib.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | /// Scatter a tensor on the given DPU set. 10 | /// For each DPU `x`, copies `copy_bytes` bytes from `A` 11 | /// into DPU memory (at offset `offset_in_dpu`), 12 | /// starting from `A + base_offset(x)`. 13 | /// 14 | /// @param dpu_set Pointer to DPU structure 15 | /// @param A Input tensor to scatter 16 | /// @param input_size Total size of tensor in bytes 17 | /// @param copy_bytes Total number of bytes to copy into each DPU 18 | /// @param offset_in_dpu Offset in the DPU memory at which to start copying 19 | /// @param base_offset Function mapping the index of a DPU to an offset in 20 | /// the input tensor. 21 | size_t upmemrt_dpu_scatter(struct dpu_set_t *dpu_set, void *hostBuffer, 22 | size_t input_size, size_t copy_bytes, 23 | size_t offset_in_dpu, size_t (*base_offset)(size_t)); 24 | 25 | void upmemrt_dpu_gather(struct dpu_set_t *dpu_set, void *hostBuffer, 26 | size_t input_size, size_t copy_bytes, 27 | size_t offset_in_dpu, size_t (*base_offset)(size_t)); 28 | 29 | struct dpu_set_t *upmemrt_dpu_alloc(int32_t num_ranks, int32_t num_dpus); 30 | 31 | void upmemrt_dpu_launch(struct dpu_set_t *void_dpu_set); -------------------------------------------------------------------------------- /cinnamon/testbench/mm2.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | 3 | func.func @mm_dimm4_nopt(%A: tensor<1x1024xi32>, %B: tensor<1024x128xi32>) -> tensor<1x128xi32> { 4 | 5 | %r0 = cinm.compute attributes { workgroupShape=array } -> tensor<1x128xi32> { 6 | %r = cinm.op.gemm %A, %B: (tensor<1x1024xi32>, tensor<1024x128xi32>) -> tensor<1x128xi32> 7 | cinm.yield %r : tensor<1x128xi32> 8 | } 9 | func.return %r0 : tensor<1x128xi32> 10 | } 11 | 12 | func.func @mm_dimm4_opt(%A: tensor<16x64xi32>, %B: tensor<64x128xi32>) -> tensor<16x128xi32> { 13 | 14 | %r0 = cinm.compute attributes { workgroupShape=array } -> tensor<16x128xi32> { 15 | %r = cinm.op.gemm %A, %B: (tensor<16x64xi32>, tensor<64x128xi32>) -> tensor<16x128xi32> 16 | cinm.yield %r : tensor<16x128xi32> 17 | } 18 | func.return %r0 : tensor<16x128xi32> 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /cinnamon/testbench/prim/GEMV/Makefile: -------------------------------------------------------------------------------- 1 | DPU_DIR := dpu 2 | HOST_DIR := host 3 | BUILDDIR ?= bin 4 | NR_TASKLETS ?= 16 5 | BL ?= 10 6 | NR_DPUS ?= 1 7 | 8 | define conf_filename 9 | ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3).conf 10 | endef 11 | CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL}) 12 | 13 | HOST_TARGET := ${BUILDDIR}/host 14 | DPU_TARGET := ${BUILDDIR}/gemv_dpu 15 | 16 | COMMON_INCLUDES := support 17 | HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) 18 | DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) 19 | 20 | .PHONY: all clean test 21 | 22 | __dirs := $(shell mkdir -p ${BUILDDIR}) 23 | 24 | COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES} 25 | HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} 26 | DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} 27 | 28 | all: ${HOST_TARGET} ${DPU_TARGET} 29 | 30 | ${CONF}: 31 | $(RM) $(call conf_filename,*,*) 32 | touch ${CONF} 33 | 34 | ${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} 35 | $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} 36 | 37 | ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} 38 | dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} 39 | 40 | clean: 41 | $(RM) -r $(BUILDDIR) 42 | 43 | test: all 44 | ./${HOST_TARGET} -m 1024 -n 1024 45 | -------------------------------------------------------------------------------- /cinnamon/testbench/prim/GEMV/support/common.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMMON_H_ 2 | #define _COMMON_H_ 3 | 4 | // Structures used by both the host and the dpu to communicate information 5 | typedef struct { 6 | uint32_t n_size; 7 | uint32_t n_size_pad; 8 | uint32_t nr_rows; 9 | uint32_t max_rows; 10 | } dpu_arguments_t; 11 | 12 | // Specific information for each DPU 13 | struct dpu_info_t { 14 | uint32_t rows_per_dpu; 15 | uint32_t rows_per_dpu_pad; 16 | uint32_t prev_rows_dpu; 17 | }; 18 | struct dpu_info_t *dpu_info; 19 | 20 | // Transfer size between MRAM and WRAM 21 | #ifdef BL 22 | #define BLOCK_SIZE_LOG2 BL 23 | #define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2) 24 | #else 25 | #define BLOCK_SIZE_LOG2 8 26 | #define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2) 27 | #define BL BLOCK_SIZE_LOG2 28 | #endif 29 | 30 | // Data type 31 | #define T uint32_t 32 | 33 | #ifndef ENERGY 34 | #define ENERGY 0 35 | #endif 36 | #define PRINT 0 37 | 38 | #define ANSI_COLOR_RED "\x1b[31m" 39 | #define ANSI_COLOR_GREEN "\x1b[32m" 40 | #define ANSI_COLOR_RESET "\x1b[0m" 41 | #endif 42 | -------------------------------------------------------------------------------- /cinnamon/testbench/prim/HST-L/Makefile: -------------------------------------------------------------------------------- 1 | DPU_DIR := dpu 2 | HOST_DIR := host 3 | BUILDDIR ?= bin 4 | NR_TASKLETS ?= 16 5 | BL ?= 8 6 | NR_DPUS ?= 1 7 | NR_HISTO ?= 1 8 | ENERGY ?= 0 9 | 10 | define conf_filename 11 | ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3)_NR_DPUS_$(4).conf 12 | endef 13 | CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL},${NR_DPUS}) 14 | 15 | HOST_TARGET := ${BUILDDIR}/host 16 | DPU_TARGET := ${BUILDDIR}/dpu_code 17 | 18 | COMMON_INCLUDES := support 19 | HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) 20 | DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) 21 | 22 | .PHONY: all clean test 23 | 24 | __dirs := $(shell mkdir -p ${BUILDDIR}) 25 | 26 | COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES} 27 | HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} -DENERGY=${ENERGY} 28 | DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -DNR_HISTO=${NR_HISTO} 29 | 30 | all: ${HOST_TARGET} ${DPU_TARGET} 31 | 32 | ${CONF}: 33 | $(RM) $(call conf_filename,*,*) 34 | touch ${CONF} 35 | 36 | ${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} 37 | $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} 38 | 39 | ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} 40 | dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} 41 | 42 | clean: 43 | $(RM) -r $(BUILDDIR) 44 | 45 | test: all 46 | ./${HOST_TARGET} 47 | -------------------------------------------------------------------------------- /cinnamon/testbench/prim/HST-L/input/image_VanHateren.iml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tud-ccc/Cinnamon/715eb4d97359966792a80d6540bfb856ba6b9357/cinnamon/testbench/prim/HST-L/input/image_VanHateren.iml -------------------------------------------------------------------------------- /cinnamon/testbench/prim/HST-L/support/common.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMMON_H_ 2 | #define _COMMON_H_ 3 | 4 | // Transfer size between MRAM and WRAM 5 | #ifdef BL 6 | #define BLOCK_SIZE_LOG2 BL 7 | #define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2) 8 | #else 9 | #define BLOCK_SIZE_LOG2 8 10 | #define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2) 11 | #define BL BLOCK_SIZE_LOG2 12 | #endif 13 | 14 | // Data type 15 | #define T uint32_t 16 | #define DIV 2 // Shift right to divide by sizeof(T) 17 | #define REGS (BLOCK_SIZE >> 2) // 32 bits 18 | 19 | // Pixel depth 20 | #define DEPTH 12 21 | #define ByteSwap16(n) (((((unsigned int)n) << 8) & 0xFF00) | ((((unsigned int)n) >> 8) & 0x00FF)) 22 | 23 | // Structures used by both the host and the dpu to communicate information 24 | typedef struct { 25 | uint32_t size; 26 | uint32_t transfer_size; 27 | uint32_t bins; 28 | enum kernels { 29 | kernel1 = 0, 30 | nr_kernels = 1, 31 | } kernel; 32 | } dpu_arguments_t; 33 | 34 | #ifndef ENERGY 35 | #define ENERGY 0 36 | #endif 37 | #define PRINT 0 38 | 39 | #define ANSI_COLOR_RED "\x1b[31m" 40 | #define ANSI_COLOR_GREEN "\x1b[32m" 41 | #define ANSI_COLOR_RESET "\x1b[0m" 42 | 43 | #define divceil(n, m) (((n)-1) / (m) + 1) 44 | #define roundup(n, m) ((n / m) * m + m) 45 | #endif 46 | -------------------------------------------------------------------------------- /cinnamon/testbench/prim/RED/Makefile: -------------------------------------------------------------------------------- 1 | DPU_DIR := dpu 2 | HOST_DIR := host 3 | BUILDDIR ?= bin 4 | NR_TASKLETS ?= 16 5 | BL ?= 10 6 | NR_DPUS ?= 1 7 | VERSION ?= SINGLE 8 | SYNC ?= HAND 9 | TYPE ?= INT64 10 | ENERGY ?= 0 11 | PERF ?= 0 12 | 13 | define conf_filename 14 | ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3)_VERSION_$(4)_SYNC_$(5)_TYPE_$(6).conf 15 | endef 16 | CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL},${VERSION},${SYNC},${TYPE}) 17 | 18 | HOST_TARGET := ${BUILDDIR}/host 19 | DPU_TARGET := ${BUILDDIR}/dpu_code 20 | 21 | COMMON_INCLUDES := support 22 | HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) 23 | DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) 24 | 25 | .PHONY: all clean test 26 | 27 | __dirs := $(shell mkdir -p ${BUILDDIR}) 28 | 29 | COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES} 30 | HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} -D${VERSION} -D${SYNC} -D${TYPE} -DENERGY=${ENERGY} -DPERF=${PERF} 31 | DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${VERSION} -D${SYNC} -D${TYPE} -DPERF=${PERF} 32 | 33 | all: ${HOST_TARGET} ${DPU_TARGET} 34 | 35 | ${CONF}: 36 | $(RM) $(call conf_filename,*,*) 37 | touch ${CONF} 38 | 39 | ${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} 40 | $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} 41 | 42 | ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} 43 | dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} 44 | 45 | clean: 46 | $(RM) -r $(BUILDDIR) 47 | 48 | test: all 49 | ./${HOST_TARGET} -w 0 -e 1 -i 6553600 -x 1 50 | -------------------------------------------------------------------------------- /cinnamon/testbench/prim/RED/support/cyclecount.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Timer 4 | typedef struct perfcounter_cycles{ 5 | perfcounter_t start; 6 | perfcounter_t end; 7 | perfcounter_t end2; 8 | 9 | }perfcounter_cycles; 10 | 11 | void timer_start(perfcounter_cycles *cycles){ 12 | cycles->start = perfcounter_get(); // START TIMER 13 | } 14 | 15 | uint64_t timer_stop(perfcounter_cycles *cycles){ 16 | cycles->end = perfcounter_get(); // STOP TIMER 17 | cycles->end2 = perfcounter_get(); // STOP TIMER 18 | return(((uint64_t)((uint32_t)(((cycles->end >> 4) - (cycles->start >> 4)) - ((cycles->end2 >> 4) - (cycles->end >> 4))))) << 4); 19 | } 20 | -------------------------------------------------------------------------------- /cinnamon/testbench/prim/RED/support/params.h: -------------------------------------------------------------------------------- 1 | #ifndef _PARAMS_H_ 2 | #define _PARAMS_H_ 3 | 4 | #include "common.h" 5 | 6 | typedef struct Params { 7 | unsigned int input_size; 8 | int n_warmup; 9 | int n_reps; 10 | int exp; 11 | }Params; 12 | 13 | static void usage() { 14 | fprintf(stderr, 15 | "\nUsage: ./program [options]" 16 | "\n" 17 | "\nGeneral options:" 18 | "\n -h help" 19 | "\n -w # of untimed warmup iterations (default=1)" 20 | "\n -e # of timed repetition iterations (default=3)" 21 | "\n -x Weak (0) or strong (1) scaling (default=0)" 22 | "\n" 23 | "\nBenchmark-specific options:" 24 | "\n -i input size (default=6553600 elements)" 25 | "\n"); 26 | } 27 | 28 | struct Params input_params(int argc, char **argv) { 29 | struct Params p; 30 | p.input_size = 6553600; 31 | p.n_warmup = 1; 32 | p.n_reps = 3; 33 | p.exp = 0; 34 | 35 | int opt; 36 | while((opt = getopt(argc, argv, "hi:w:e:x:")) >= 0) { 37 | switch(opt) { 38 | case 'h': 39 | usage(); 40 | exit(0); 41 | break; 42 | case 'i': p.input_size = atoi(optarg); break; 43 | case 'w': p.n_warmup = atoi(optarg); break; 44 | case 'e': p.n_reps = atoi(optarg); break; 45 | case 'x': p.exp = atoi(optarg); break; 46 | default: 47 | fprintf(stderr, "\nUnrecognized option!\n"); 48 | usage(); 49 | exit(0); 50 | } 51 | } 52 | assert(NR_DPUS > 0 && "Invalid # of dpus!"); 53 | 54 | return p; 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /cinnamon/testbench/prim/SEL/Makefile: -------------------------------------------------------------------------------- 1 | DPU_DIR := dpu 2 | HOST_DIR := host 3 | BUILDDIR ?= bin 4 | NR_TASKLETS ?= 16 5 | BL ?= 10 6 | NR_DPUS ?= 1 7 | ENERGY ?= 0 8 | 9 | define conf_filename 10 | ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3).conf 11 | endef 12 | CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL}) 13 | 14 | HOST_TARGET := ${BUILDDIR}/host 15 | DPU_TARGET := ${BUILDDIR}/dpu_code 16 | 17 | COMMON_INCLUDES := support 18 | HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) 19 | DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) 20 | 21 | .PHONY: all clean test 22 | 23 | __dirs := $(shell mkdir -p ${BUILDDIR}) 24 | 25 | COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES} 26 | HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} -DENERGY=${ENERGY} 27 | DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} 28 | 29 | all: ${HOST_TARGET} ${DPU_TARGET} 30 | 31 | ${CONF}: 32 | $(RM) $(call conf_filename,*,*) 33 | touch ${CONF} 34 | 35 | ${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} 36 | $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} 37 | 38 | ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} 39 | dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} 40 | 41 | clean: 42 | $(RM) -r $(BUILDDIR) 43 | 44 | test: all 45 | ./${HOST_TARGET} 46 | -------------------------------------------------------------------------------- /cinnamon/testbench/prim/SEL/support/common.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMMON_H_ 2 | #define _COMMON_H_ 3 | 4 | // Structures used by both the host and the dpu to communicate information 5 | typedef struct { 6 | uint32_t size; 7 | enum kernels { 8 | kernel1 = 0, 9 | nr_kernels = 1, 10 | } kernel; 11 | } dpu_arguments_t; 12 | 13 | typedef struct { 14 | uint32_t t_count; 15 | } dpu_results_t; 16 | 17 | // Transfer size between MRAM and WRAM 18 | #ifdef BL 19 | #define BLOCK_SIZE_LOG2 BL 20 | #define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2) 21 | #else 22 | #define BLOCK_SIZE_LOG2 8 23 | #define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2) 24 | #define BL BLOCK_SIZE_LOG2 25 | #endif 26 | 27 | // Data type 28 | #define T uint64_t 29 | #define REGS (BLOCK_SIZE >> 3) // 64 bits 30 | 31 | // Sample predicate 32 | bool pred(const T x){ 33 | return (x % 2) == 0; 34 | } 35 | 36 | #ifndef ENERGY 37 | #define ENERGY 0 38 | #endif 39 | #define PRINT 0 40 | 41 | #define ANSI_COLOR_RED "\x1b[31m" 42 | #define ANSI_COLOR_GREEN "\x1b[32m" 43 | #define ANSI_COLOR_RESET "\x1b[0m" 44 | 45 | #define divceil(n, m) (((n)-1) / (m) + 1) 46 | #define roundup(n, m) ((n / m) * m + m) 47 | #endif 48 | -------------------------------------------------------------------------------- /cinnamon/testbench/prim/SEL/support/params.h: -------------------------------------------------------------------------------- 1 | #ifndef _PARAMS_H_ 2 | #define _PARAMS_H_ 3 | 4 | #include "common.h" 5 | 6 | typedef struct Params { 7 | unsigned int input_size; 8 | int n_warmup; 9 | int n_reps; 10 | int exp; 11 | }Params; 12 | 13 | static void usage() { 14 | fprintf(stderr, 15 | "\nUsage: ./program [options]" 16 | "\n" 17 | "\nGeneral options:" 18 | "\n -h help" 19 | "\n -w # of untimed warmup iterations (default=1)" 20 | "\n -e # of timed repetition iterations (default=3)" 21 | "\n -x Weak (0) or strong (1) scaling (default=0)" 22 | "\n" 23 | "\nBenchmark-specific options:" 24 | "\n -i input size (default=3932160 elements)" 25 | "\n"); 26 | } 27 | 28 | struct Params input_params(int argc, char **argv) { 29 | struct Params p; 30 | p.input_size = 3932160; 31 | p.n_warmup = 1; 32 | p.n_reps = 3; 33 | p.exp = 0; 34 | 35 | int opt; 36 | while((opt = getopt(argc, argv, "hi:w:e:x:")) >= 0) { 37 | switch(opt) { 38 | case 'h': 39 | usage(); 40 | exit(0); 41 | break; 42 | case 'i': p.input_size = atoi(optarg); break; 43 | case 'w': p.n_warmup = atoi(optarg); break; 44 | case 'e': p.n_reps = atoi(optarg); break; 45 | case 'x': p.exp = atoi(optarg); break; 46 | default: 47 | fprintf(stderr, "\nUnrecognized option!\n"); 48 | usage(); 49 | exit(0); 50 | } 51 | } 52 | assert(NR_DPUS > 0 && "Invalid # of dpus!"); 53 | 54 | return p; 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /cinnamon/testbench/prim/VA/Makefile: -------------------------------------------------------------------------------- 1 | DPU_DIR := dpu 2 | HOST_DIR := host 3 | BUILDDIR ?= bin 4 | NR_TASKLETS ?= 16 5 | BL ?= 10 6 | NR_DPUS ?= 1 7 | TYPE ?= INT32 8 | ENERGY ?= 0 9 | 10 | define conf_filename 11 | ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3)_TYPE_$(4).conf 12 | endef 13 | CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL},${TYPE}) 14 | 15 | HOST_TARGET := ${BUILDDIR}/host 16 | DPU_TARGET := ${BUILDDIR}/dpu_code 17 | 18 | COMMON_INCLUDES := support 19 | HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) 20 | DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) 21 | 22 | .PHONY: all clean test 23 | 24 | __dirs := $(shell mkdir -p ${BUILDDIR}) 25 | 26 | COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES} 27 | HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} -D${TYPE} -DENERGY=${ENERGY} 28 | DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${TYPE} 29 | 30 | all: ${HOST_TARGET} ${DPU_TARGET} 31 | 32 | ${CONF}: 33 | $(RM) $(call conf_filename,*,*) 34 | touch ${CONF} 35 | 36 | ${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} 37 | $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} 38 | 39 | ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} 40 | dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} 41 | 42 | clean: 43 | $(RM) -r $(BUILDDIR) 44 | 45 | test: all 46 | ./${HOST_TARGET} 47 | -------------------------------------------------------------------------------- /cinnamon/testbench/prim/VA/support/common.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMMON_H_ 2 | #define _COMMON_H_ 3 | 4 | // Structures used by both the host and the dpu to communicate information 5 | typedef struct { 6 | uint32_t size; 7 | uint32_t transfer_size; 8 | enum kernels { 9 | kernel1 = 0, 10 | nr_kernels = 1, 11 | } kernel; 12 | } dpu_arguments_t; 13 | 14 | // Transfer size between MRAM and WRAM 15 | #ifdef BL 16 | #define BLOCK_SIZE_LOG2 BL 17 | #define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2) 18 | #else 19 | #define BLOCK_SIZE_LOG2 9 20 | #define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2) 21 | #define BL BLOCK_SIZE_LOG2 22 | #endif 23 | 24 | // Data type 25 | #define T uint32_t 26 | #define DIV 2 // Shift right to divide by sizeof(T) 27 | 28 | #ifndef ENERGY 29 | #define ENERGY 0 30 | #endif 31 | #define PRINT 0 32 | 33 | #define ANSI_COLOR_RED "\x1b[31m" 34 | #define ANSI_COLOR_GREEN "\x1b[32m" 35 | #define ANSI_COLOR_RESET "\x1b[0m" 36 | 37 | #define divceil(n, m) (((n)-1) / (m) + 1) 38 | #define roundup(n, m) ((n / m) * m + m) 39 | #endif 40 | -------------------------------------------------------------------------------- /cinnamon/testbench/prim/VA/support/params.h: -------------------------------------------------------------------------------- 1 | #ifndef _PARAMS_H_ 2 | #define _PARAMS_H_ 3 | 4 | #include "common.h" 5 | 6 | typedef struct Params { 7 | unsigned int input_size; 8 | int n_warmup; 9 | int n_reps; 10 | int exp; 11 | }Params; 12 | 13 | static void usage() { 14 | fprintf(stderr, 15 | "\nUsage: ./program [options]" 16 | "\n" 17 | "\nGeneral options:" 18 | "\n -h help" 19 | "\n -w # of untimed warmup iterations (default=1)" 20 | "\n -e # of timed repetition iterations (default=3)" 21 | "\n -x Weak (0) or strong (1) scaling (default=0)" 22 | "\n" 23 | "\nBenchmark-specific options:" 24 | "\n -i input size (default=2621440 elements)" 25 | "\n"); 26 | } 27 | 28 | struct Params input_params(int argc, char **argv) { 29 | struct Params p; 30 | p.input_size = 2621440; 31 | p.n_warmup = 1; 32 | p.n_reps = 3; 33 | p.exp = 0; 34 | 35 | int opt; 36 | while((opt = getopt(argc, argv, "hi:w:e:x:")) >= 0) { 37 | switch(opt) { 38 | case 'h': 39 | usage(); 40 | exit(0); 41 | break; 42 | case 'i': p.input_size = atoi(optarg); break; 43 | case 'w': p.n_warmup = atoi(optarg); break; 44 | case 'e': p.n_reps = atoi(optarg); break; 45 | case 'x': p.exp = atoi(optarg); break; 46 | default: 47 | fprintf(stderr, "\nUnrecognized option!\n"); 48 | usage(); 49 | exit(0); 50 | } 51 | } 52 | assert(NR_DPUS > 0 && "Invalid # of dpus!"); 53 | 54 | return p; 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /cinnamon/testbench/prim/run_benchmarks.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | import csv 4 | 5 | 6 | def run(bench): 7 | os.chdir(bench) 8 | 9 | subprocess.run(["make", "clean"], stdout=subprocess.PIPE) 10 | subprocess.run(["make"]) 11 | output = subprocess.run(["./bin/host"], stdout=subprocess.PIPE).stdout.decode('utf-8') 12 | os.chdir("../") 13 | results = {} 14 | last_dimm_count = None 15 | last_exec_type = None 16 | for line in output.split("\n"): 17 | if line.startswith("PRIM"): 18 | dimm_count = int(line.split(" ")[1]) 19 | if dimm_count not in results : 20 | results[dimm_count] = 0 21 | last_dimm_count = dimm_count 22 | 23 | elif len(line) > 1: 24 | results[last_dimm_count] += float(line) 25 | return results 26 | 27 | 28 | def run_prim(): 29 | 30 | numbers = {} 31 | benchmarks = ["RED", "HST-L", "VA", "SEL", "GEMV"] 32 | for bench in benchmarks: 33 | # print(bench) 34 | numbers[bench] = run(bench) 35 | return numbers 36 | 37 | # for bench in benchmarks: 38 | # f.write(bench + " ") 39 | # for dimm_count in dimm_counts: 40 | # f.write(str(numbers[bench][dimm_count]["Non-opt"])) 41 | # f.write(" ") 42 | # f.write(str(numbers[bench][dimm_count]["Opt"])) 43 | # f.write(" ") 44 | # f.write("\n") 45 | 46 | # f.close() 47 | 48 | -------------------------------------------------------------------------------- /cinnamon/testbench/va.mlir: -------------------------------------------------------------------------------- 1 | // cinm-opt $FILE --convert-cinm-to-cnm 2 | 3 | module { 4 | 5 | func.func @va_8(%A: tensor<8x2097152xi32>, %B: tensor<8x2097152xi32>) { 6 | 7 | 8 | %res = cinm.compute attributes { workgroupShape=array } -> tensor<8x2097152xi32> { 9 | %r = cinm.op.add %A, %B: tensor<8x2097152xi32> 10 | cinm.yield %r: tensor<8x2097152xi32> 11 | } 12 | 13 | func.return 14 | } 15 | func.func @va_16(%A: tensor<16x1048576xi32>, %B: tensor<16x1048576xi32>) { 16 | 17 | %res = cinm.compute attributes { workgroupShape=array } -> tensor<16x1048576xi32> { 18 | %r = cinm.op.add %A, %B: tensor<16x1048576xi32> 19 | cinm.yield %r: tensor<16x1048576xi32> 20 | } 21 | 22 | func.return 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /cinnamon/tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(cinm-opt) 2 | add_subdirectory(cinm-translate) 3 | add_subdirectory(cinm-lsp-server) 4 | if (CINM_BUILD_GPU_SUPPORT) 5 | add_subdirectory(cinm-vulkan-runner) 6 | endif() -------------------------------------------------------------------------------- /cinnamon/tools/cinm-lsp-server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # cinm-lsp-server 3 | # 4 | # The cinm-lsp-server MLIR language server. 5 | ################################################################################ 6 | 7 | project(cinm-lsp-server) 8 | 9 | add_executable(${PROJECT_NAME} 10 | cinm-lsp-server.cpp 11 | ) 12 | 13 | # Link all standard MLIR dialect and conversion libs. 14 | get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) 15 | get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) 16 | get_property(dependency_libs GLOBAL PROPERTY CINM_DEPENDENCY_LIBS) 17 | target_link_libraries(${PROJECT_NAME} 18 | PRIVATE 19 | MLIRLspServerLib 20 | ${dialect_libs} 21 | ${conversion_libs} 22 | ${dependency_libs} 23 | ) 24 | -------------------------------------------------------------------------------- /cinnamon/tools/cinm-lsp-server/cinm-lsp-server.cpp: -------------------------------------------------------------------------------- 1 | /// Main entry point for the cinm-mlir MLIR language server. 2 | 3 | #include "cinm-mlir/Dialect/Cinm/IR/CinmDialect.h" 4 | #include "cinm-mlir/Dialect/Cim/IR/CimDialect.h" 5 | #include "cinm-mlir/Dialect/Cnm/IR/CnmDialect.h" 6 | #include "cinm-mlir/Dialect/Memristor/IR/MemristorDialect.h" 7 | #include "cinm-mlir/Dialect/UPMEM/IR/UPMEMDialect.h" 8 | 9 | #ifdef CINM_TORCH_MLIR_ENABLED 10 | #include "torch-mlir/Dialect/Torch/IR/TorchDialect.h" 11 | #include "torch-mlir/Dialect/TorchConversion/IR/TorchConversionDialect.h" 12 | #endif 13 | 14 | #include "mlir/IR/Dialect.h" 15 | #include "mlir/IR/MLIRContext.h" 16 | #include "mlir/InitAllDialects.h" 17 | #include "mlir/Tools/mlir-lsp-server/MlirLspServerMain.h" 18 | 19 | using namespace mlir; 20 | 21 | static int asMainReturnCode(LogicalResult r) { 22 | return r.succeeded() ? EXIT_SUCCESS : EXIT_FAILURE; 23 | } 24 | 25 | int main(int argc, char *argv[]) { 26 | DialectRegistry registry; 27 | registerAllDialects(registry); 28 | 29 | registry.insert(); 30 | registry.insert(); 31 | registry.insert(); 32 | registry.insert(); 33 | registry.insert(); 34 | 35 | #ifdef CINM_TORCH_MLIR_ENABLED 36 | registry.insert(); 37 | registry.insert(); 38 | #endif 39 | 40 | return asMainReturnCode(MlirLspServerMain(argc, argv, registry)); 41 | } 42 | -------------------------------------------------------------------------------- /cinnamon/tools/cinm-opt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # cinm-opt 3 | # 4 | # The cinm-mlir optimizer driver. 5 | ################################################################################ 6 | 7 | project(cinm-opt) 8 | 9 | add_executable(${PROJECT_NAME} 10 | cinm-opt.cpp 11 | ) 12 | 13 | # Link all standard MLIR dialect and conversion libs. 14 | get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) 15 | get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) 16 | get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS) 17 | get_property(dependency_libs GLOBAL PROPERTY CINM_DEPENDENCY_LIBS) 18 | target_link_libraries(${PROJECT_NAME} 19 | PRIVATE 20 | -Wl,--start-group 21 | MLIROptLib 22 | ${dialect_libs} 23 | ${conversion_libs} 24 | ${extension_libs} 25 | ${dependency_libs} 26 | LLVMSupport 27 | -Wl,--end-group 28 | ) 29 | -------------------------------------------------------------------------------- /cinnamon/tools/cinm-translate/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # cinm-translate 3 | # 4 | # The cinnamon translation driver. 5 | ################################################################################ 6 | 7 | project(cinm-translate) 8 | 9 | add_executable(${PROJECT_NAME} 10 | cinm-translate.cpp 11 | ) 12 | 13 | # Link all standard MLIR dialect and translation libs. 14 | get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) 15 | get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) 16 | target_link_libraries(${PROJECT_NAME} 17 | PRIVATE 18 | MLIRIR 19 | MLIRParser 20 | MLIRPass 21 | MLIRTranslateLib 22 | MLIRSupport 23 | ${dialect_libs} 24 | ${translation_libs} 25 | ) 26 | -------------------------------------------------------------------------------- /cinnamon/tools/cinm-translate/cinm-translate.cpp: -------------------------------------------------------------------------------- 1 | /// Main entry point for the cinm-mlir optimizer driver. 2 | /// 3 | /// @file 4 | /// @author Karl F. A. Friebel (karl.friebel@tu-dresden.de) 5 | /// @author Clément Fournier (clement.fournier@tu-dresden.de) 6 | /// @author Hamid Farzaneh (hamid.farzaneh@tu-dresden.de) 7 | #include "cinm-mlir/Target/UPMEMCpp/UPMEMCppEmitter.h" 8 | 9 | #include "mlir/InitAllTranslations.h" 10 | #include "mlir/Support/LogicalResult.h" 11 | #include "mlir/Tools/mlir-translate/MlirTranslateMain.h" 12 | 13 | using namespace mlir; 14 | 15 | 16 | int main(int argc, char **argv) { 17 | registerAllTranslations(); 18 | upmem_emitc::registerUPMEMCppTranslation(); 19 | return failed(mlirTranslateMain(argc, argv, "MLIR Translation Testing Tool")); 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /cinnamon/tools/cinm-vulkan-runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(cinm-vulkan-runner) 2 | 3 | find_package(Vulkan) 4 | 5 | get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) 6 | get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) 7 | set(LIBS 8 | ${dialect_libs} 9 | ${conversion_libs} 10 | MLIRAnalysis 11 | MLIRBuiltinToLLVMIRTranslation 12 | MLIRExecutionEngine 13 | MLIRIR 14 | MLIRJitRunner 15 | MLIRLLVMToLLVMIRTranslation 16 | MLIRParser 17 | MLIRSupport 18 | MLIRTargetLLVMIRExport 19 | MLIRTransforms 20 | MLIRTranslateLib 21 | ${Vulkan_LIBRARY} 22 | ) 23 | 24 | add_executable(cinm-vulkan-runner cinm-vulkan-runner.cpp) 25 | llvm_update_compile_flags(cinm-vulkan-runner) 26 | target_link_libraries(cinm-vulkan-runner PRIVATE ${LIBS} ${dialect_libs} ${conversion_libs}) 27 | -------------------------------------------------------------------------------- /compile_benches.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # source /opt/upmem/upmem-2023.2.0-Linux-x86_64/upmem_env.sh 3 | 4 | just genBench va 5 | just genBench mlp 6 | just genBench 1mm 7 | just genBench 2mm 8 | just genBench 3mm 9 | just genBench mv 10 | -------------------------------------------------------------------------------- /exp-fig-11.sh: -------------------------------------------------------------------------------- 1 | python3 ./testbench/scripts/plot-fig-11.py -------------------------------------------------------------------------------- /exp-fig-12.sh: -------------------------------------------------------------------------------- 1 | python3 ./testbench/scripts/plot-fig-12.py -------------------------------------------------------------------------------- /plot/exp-fig-11.txt: -------------------------------------------------------------------------------- 1 | 1mm 180.471 124.442333 90.381667 62.204333 45.349667 31.302 2 | 2mm 360.908 248.871 180.699 124.38466700000001 90.682 62.588667 3 | 3mm 541.395 373.32399999999996 271.09333300000003 186.58433300000002 136.06400000000002 93.860334 4 | conv 6430.966333 6107.245 3455.250333 3061.608333 1960.521667 1529.905 5 | mv 477.512 464.4598 232.491 237.4102 116.4792 118.9158 6 | -------------------------------------------------------------------------------- /plot/exp-fig-12.txt: -------------------------------------------------------------------------------- 1 | va 98.229 99.107333 49.111667 49.657333 24.712333 25.396667 2 | sel 147.55433299999999 98.8 73.801 49.510667 37.080666 24.935 3 | mv 460.075 464.4598 230.295333 237.4102 115.293667 118.9158 4 | hst 2326.5823339999997 623.852667 1163.186 312.115 581.846333 156.151333 5 | red 394.185667 241.571 197.040333 120.908333 98.634 60.646667 6 | -------------------------------------------------------------------------------- /plot/plot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | python3 plot-fig-11.py 3 | python3 plot-fig-12.py 4 | -------------------------------------------------------------------------------- /scripts/download_plot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Get the directory where the script is located 4 | CINNAMON_LOC="Cinnamon" # MODIFY if you are using a differet location 5 | MACHINE_DIR="/home/reviewer/$CINNAMON_LOC/plot/" 6 | 7 | TARGET_DIR="." # modify to your liking 8 | SSH_HOST="reviewer@ios.inf.uni-osnabrueck.de" 9 | SSH_PORT="2293" 10 | 11 | SOURCE_DIR="reviewer@ios.inf.uni-osnabrueck.de:$MACHINE_DIR" 12 | 13 | # # Use scp to copy files 14 | scp -P $SSH_PORT -r "$SOURCE_DIR" "$TARGET_DIR" 15 | -------------------------------------------------------------------------------- /scripts/exp-fig-11.txt: -------------------------------------------------------------------------------- 1 | mm 180.440667 124.439333 90.353667 62.203667 45.414 31.416 2 | 2mm 360.921667 249.130667 180.678 124.411 90.872 62.783 3 | 3mm 541.355333 373.55 271.087667 186.666666 136.262333 94.128667 4 | conv 553.194 495.518 351.369 276.523 175.766 138.52 5 | contrl 4437.7306 3960.0326 2301.5394 1979.2632 1142.278 989.568 6 | contrs1 3.0334 0.5602 1.714 0.5308 1.4128 0.4448 7 | contrs2 1400.737 987.362 700.6632 493.917 350.418 247.1986 8 | mlp 2412.1268 2326.492668 1170.32134 1080.23334 995.31267 989.312367 9 | mv 493.4876 465.1396 247.013 232.3794 123.6274 116.3802 -------------------------------------------------------------------------------- /scripts/exp-fig-12.txt: -------------------------------------------------------------------------------- 1 | va 212.075 122.214 98.878666 61.107 49.439333 30.712667 25.407667 2 | sel 21184 147.374666 110.458 73.687333 55.229 36.979 27.831 3 | bfs 216.657996 2423.907027 251.318997 4832.744941 251.318997 7801.188346 251.318997 4 | mv 363.041 460.022 465.1396 230.011 232.3794 115.119667 116.3802 5 | hst-l 5804.067333 2329.814666 623.583334 1164.907333 311.872 582.392 155.929667 6 | mlp 1041.637 2521.492668 2326.492668 1260.746334 1080.23334 1048.331667 989.312367 7 | red 1063.429 394.956666 482.640666 197.478333 120.621333 98.860333 60.578 8 | ts 5242.957 1566.103469 1566.103469 757.646333 811.6041875 420.052 447.515031 9 | -------------------------------------------------------------------------------- /scripts/run_bench.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Get the directory where the script is located 4 | # SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" 5 | 6 | # SOURCE_DIR="${SCRIPT_DIR}/../cinnamon/testbench/generated/" 7 | 8 | # TARGET_DIR="reviewer@ios.inf.uni-osnabrueck.de:/home/reviewer/generated" 9 | # SSH_HOST="reviewer@ios.inf.uni-osnabrueck.de" 10 | # SSH_PORT="2293" 11 | 12 | # # Use scp to copy files 13 | # scp -P $SSH_PORT -r "$SOURCE_DIR" "$TARGET_DIR" 14 | 15 | # # Check if scp was successful 16 | # if [ $? -eq 0 ]; then 17 | # echo "Files copied successfully. Establishing SSH connection..." 18 | # # SSH into the remote server 19 | # ssh -p $SSH_PORT $SSH_HOST 20 | # else 21 | # echo "Copy failed. SSH connection not established." 22 | # fi 23 | 24 | cd /home/reviewer/Cinnamon/cinnamon/testbench/ || { echo "Failed to change directory to /home/reviewer/generated"; exit 1; } 25 | source /opt/upmem/upmem-2023.2.0-Linux-x86_64/upmem_env.sh 26 | python3 get_results.py 27 | 28 | cd ../../ 29 | 30 | cat ./cinnamon/testbench/exp-fig-11.txt 31 | cat ./cinnamon/testbench/exp-fig-12.txt 32 | cp ./cinnamon/testbench/exp-fig-11.txt ./plot/exp-fig-11.txt 33 | cp ./cinnamon/testbench/exp-fig-12.txt ./plot/exp-fig-12.txt 34 | --------------------------------------------------------------------------------