├── .github └── workflows │ └── github-actions-build-test.yml ├── .gitignore ├── CITATION.cff ├── CMakeLists.txt ├── LICENSE ├── README.md ├── evaluation ├── FormatConversion │ ├── UniSparse │ │ ├── executables │ │ │ ├── coo_c2sr │ │ │ ├── coo_c2sr.o │ │ │ ├── coo_cisr │ │ │ ├── coo_cisr.o │ │ │ ├── coo_dia │ │ │ ├── coo_dia.o │ │ │ ├── coo_ell │ │ │ ├── coo_ell.o │ │ │ ├── csb_dia_v │ │ │ ├── csb_dia_v.o │ │ │ ├── csr_csc │ │ │ ├── csr_csc.o │ │ │ ├── dcsc_bcsr │ │ │ └── dcsc_bcsr.o │ │ ├── unisparse_coo_c2sr.mlir │ │ ├── unisparse_coo_cisr.mlir │ │ ├── unisparse_coo_dia.mlir │ │ ├── unisparse_coo_ell.mlir │ │ ├── unisparse_csb_dia_v.mlir │ │ ├── unisparse_csr_csc.mlir │ │ └── unisparse_dcsc_bcsr.mlir │ ├── executables │ │ ├── coo_c2sr │ │ ├── coo_c2sr.o │ │ ├── coo_cisr │ │ ├── coo_cisr.o │ │ ├── coo_dia │ │ ├── coo_dia.o │ │ ├── coo_ell │ │ ├── coo_ell.o │ │ ├── csb_dia_v │ │ ├── csb_dia_v.o │ │ ├── csr_csc │ │ ├── csr_csc.o │ │ ├── dcsc_bcsr │ │ ├── dcsc_bcsr.o │ │ ├── sparse_tensor_csr_csc │ │ ├── sparse_tensor_csr_csc.o │ │ └── taco_format_conversion │ ├── output.log │ ├── run.sh │ ├── sparse_tensor_dialect │ │ ├── sparse_tensor_csr_csc │ │ └── sparse_tensor_csr_to_csc.mlir │ └── taco │ │ └── taco_format_conversion.cpp ├── KernelGeneration │ ├── UniSparse │ │ ├── unisparse_csc_csc_csc_spgemm_F64.mlir │ │ ├── unisparse_csr_csr_csr_spgemm_F64.mlir │ │ ├── unisparse_csr_spmm_F64.mlir │ │ └── unisparse_dcsc_spmm_F64.mlir │ ├── executables │ │ ├── sparse_tensor_csc_csc_csc_spgemm_F64 │ │ ├── sparse_tensor_csc_csc_csc_spgemm_F64.o │ │ ├── sparse_tensor_csr_csr_csr_spgemm_F64 │ │ ├── sparse_tensor_csr_csr_csr_spgemm_F64.o │ │ ├── sparse_tensor_csr_spmm_F64 │ │ ├── sparse_tensor_csr_spmm_F64.o │ │ ├── sparse_tensor_dcsc_spmm_F64 │ │ ├── sparse_tensor_dcsc_spmm_F64.o │ │ ├── taco_csr_csr_csr_spgemm │ │ ├── taco_csr_spmm │ │ ├── taco_dcsc_spmm │ │ ├── unisparse_csc_csc_csc_spgemm_F64 │ │ ├── unisparse_csc_csc_csc_spgemm_F64.o │ │ ├── unisparse_csr_csr_csr_spgemm_F64 │ │ ├── unisparse_csr_csr_csr_spgemm_F64.o │ │ ├── unisparse_csr_spmm_F64 │ │ ├── unisparse_csr_spmm_F64.o │ │ ├── unisparse_dcsc_spmm_F64 │ │ └── unisparse_dcsc_spmm_F64.o │ ├── output.log │ ├── run.sh │ ├── sparse_tensor_dialect │ │ ├── sparse_tensor_csc_csc_csc_spgemm_F64.mlir │ │ ├── sparse_tensor_csr_csr_csr_spgemm_F64.mlir │ │ ├── sparse_tensor_csr_spmm_F64.mlir │ │ └── sparse_tensor_dcsc_spmm_F64.mlir │ └── taco │ │ ├── taco_csr_csr_csr_spgemm.cpp │ │ ├── taco_csr_spmm.cpp │ │ └── taco_dcsc_spmm.cpp └── Reusability │ ├── executables │ ├── coo_bcsc.mlir │ ├── coo_bcsc.o │ ├── csr_dia_v │ ├── csr_dia_v.o │ ├── unisparse_csc_spmm_F64 │ ├── unisparse_csc_spmm_F64.o │ ├── unisparse_csr_csc_csc_spgemm_F64 │ └── unisparse_csr_csc_csc_spgemm_F64.o │ ├── output.log │ ├── run.sh │ ├── unisparse_csc_spmm_F64.mlir │ ├── unisparse_csr_csc_csc_spgemm_F64.mlir │ └── unisparse_csr_dia_v.mlir ├── include ├── CMakeLists.txt ├── IR │ ├── CMakeLists.txt │ ├── UniSparseAffineMap.h │ ├── UniSparseAttr.h │ ├── UniSparseAttr.td │ ├── UniSparseDialect.h │ ├── UniSparseDialect.td │ ├── UniSparseOps.h │ ├── UniSparseOps.td │ ├── UniSparseParser.h │ └── UniSparseTypes.h └── Transforms │ ├── CMakeLists.txt │ ├── Passes.h │ └── Passes.td ├── install.sh ├── lib ├── CMakeLists.txt ├── IR │ ├── CMakeLists.txt │ ├── UniSparseDialect.cpp │ ├── UniSparseOps.cpp │ ├── UniSparseParser.cpp │ └── UniSparseTypes.cpp ├── Runtime │ ├── CMakeLists.txt │ └── UniSparseUtils.cpp └── Transforms │ ├── CMakeLists.txt │ ├── DeadCodeEliminationPass.cpp │ ├── LowerFormatConversionPass.cpp │ ├── LowerStructConvert.cpp │ ├── LowerStructPass.cpp │ └── UniSparseCodegen.cpp ├── scripts ├── bin-path.sh ├── build.sh ├── cmake-config.sh ├── convert_colmajor_to_rowmajor_mtx.py └── unisparse-icon.png ├── test ├── CMakeLists.txt ├── Data │ ├── tensor46.mtx │ ├── test.mtx │ └── wide.mtx ├── UniSparse │ ├── FormatPreprocess │ │ ├── conversion │ │ │ ├── coo_to_csbdcsr.mlir │ │ │ ├── lower_csr_to_dia1.mlir │ │ │ ├── run_conversion.sh │ │ │ ├── temp_coo_csr_csc.mlir │ │ │ ├── temp_coo_dcsr_dcsc.mlir │ │ │ ├── temp_coo_to_bcoo.mlir │ │ │ ├── temp_coo_to_bcsc.mlir │ │ │ ├── temp_coo_to_bcsr.mlir │ │ │ ├── temp_coo_to_bdcsr.mlir │ │ │ ├── temp_coo_to_bdia.mlir │ │ │ ├── temp_coo_to_bdia_100.mlir │ │ │ ├── temp_coo_to_bdia_1000.mlir │ │ │ ├── temp_coo_to_bdia_500.mlir │ │ │ ├── temp_coo_to_bell.mlir │ │ │ ├── temp_coo_to_bell_16.mlir │ │ │ ├── temp_coo_to_bell_32.mlir │ │ │ ├── temp_coo_to_bell_64.mlir │ │ │ ├── temp_coo_to_cisr.mlir │ │ │ ├── temp_coo_to_cisr_plus.mlir │ │ │ ├── temp_coo_to_csb.mlir │ │ │ ├── temp_coo_to_csbcsr.mlir │ │ │ ├── temp_coo_to_csbdcsr.mlir │ │ │ ├── temp_coo_to_dia1.mlir │ │ │ ├── temp_coo_to_dia2.mlir │ │ │ ├── temp_coo_to_dia3.mlir │ │ │ ├── temp_coo_to_dia4.mlir │ │ │ ├── temp_coo_to_dia4_only.mlir │ │ │ ├── temp_coo_to_ell.mlir │ │ │ ├── temp_coo_to_serpens.mlir │ │ │ ├── temp_csr_to_csbdcsr.mlir │ │ │ ├── temp_csr_to_dia1.mlir │ │ │ ├── temp_dcsr_to_ell.mlir │ │ │ ├── temp_dia1_to_csb.mlir │ │ │ ├── unisparse_coo_csr_csc.mlir │ │ │ ├── unisparse_coo_dcsr_csr.mlir │ │ │ ├── unisparse_coo_dcsr_dcsc.mlir │ │ │ ├── unisparse_coo_dia_bcsr.mlir │ │ │ ├── unisparse_coo_to_bcoo.mlir │ │ │ ├── unisparse_coo_to_bcsc.mlir │ │ │ ├── unisparse_coo_to_bcsr.mlir │ │ │ ├── unisparse_coo_to_bdcsr.mlir │ │ │ ├── unisparse_coo_to_bdia.mlir │ │ │ ├── unisparse_coo_to_bdia_100.mlir │ │ │ ├── unisparse_coo_to_bdia_1000.mlir │ │ │ ├── unisparse_coo_to_bdia_500.mlir │ │ │ ├── unisparse_coo_to_c2sr.mlir │ │ │ ├── unisparse_coo_to_csb.mlir │ │ │ ├── unisparse_coo_to_csbcsr.mlir │ │ │ ├── unisparse_coo_to_csbdcsr.mlir │ │ │ ├── unisparse_coo_to_dia1.mlir │ │ │ ├── unisparse_coo_to_dia2.mlir │ │ │ ├── unisparse_coo_to_dia3.mlir │ │ │ ├── unisparse_coo_to_dia4.mlir │ │ │ ├── unisparse_csr_to_csbdcsr.mlir │ │ │ ├── unisparse_csr_to_dia1.mlir │ │ │ ├── unisparse_dcsc_to_bcsr.mlir │ │ │ ├── unisparse_dia1_to_csb.mlir │ │ │ └── unisparse_dia1_to_dia4.mlir │ │ ├── convert-correctness.mlir │ │ ├── convert-perf-all.mlir │ │ ├── convert-perf-small.mlir │ │ └── decompose.mlir │ ├── IR │ │ ├── linalg.mlir │ │ ├── to-ops.mlir │ │ ├── unisparse-attr.mlir │ │ └── unisparse-struct.mlir │ └── KernelGen │ │ └── CPU │ │ ├── run_spgemm.sh │ │ ├── run_spmm_spmv.sh │ │ ├── unisparse_coo_spmm_F32.mlir │ │ ├── unisparse_coo_spmm_F64.mlir │ │ ├── unisparse_coo_spmv_F32.mlir │ │ ├── unisparse_coo_spmv_F64.mlir │ │ ├── unisparse_csc_csc_csc_spgemm.mlir │ │ ├── unisparse_csc_spmm_F32.mlir │ │ ├── unisparse_csc_spmm_F64.mlir │ │ ├── unisparse_csc_spmv_F32.mlir │ │ ├── unisparse_csc_spmv_F64.mlir │ │ ├── unisparse_csr_csc_csc_spgemm.mlir │ │ ├── unisparse_csr_csc_csr_spgemm.mlir │ │ ├── unisparse_csr_csr_csr_spgemm.mlir │ │ ├── unisparse_csr_spmm_F32.mlir │ │ ├── unisparse_csr_spmm_F64.mlir │ │ ├── unisparse_csr_spmv_F32.mlir │ │ ├── unisparse_csr_spmv_F64.mlir │ │ ├── unisparse_dcsc_spmm_F32.mlir │ │ ├── unisparse_dcsc_spmm_F64.mlir │ │ ├── unisparse_dcsc_spmv_F32.mlir │ │ ├── unisparse_dcsc_spmv_F64.mlir │ │ ├── unisparse_dcsr_spmm_F32.mlir │ │ ├── unisparse_dcsr_spmm_F64.mlir │ │ ├── unisparse_dcsr_spmv_F32.mlir │ │ └── unisparse_dcsr_spmv_F64.mlir ├── lit.cfg.py └── lit.site.cfg.py.in ├── unisparse-opt ├── CMakeLists.txt └── unisparse-opt.cpp └── unisparse-translate ├── CMakeLists.txt └── unisparse-translate.cpp /.github/workflows/github-actions-build-test.yml: -------------------------------------------------------------------------------- 1 | name: GitHub Actions Build Test 2 | on: [push, pull_request] 3 | jobs: 4 | Build-UniSparse-Dialect: 5 | name: Build and Test 6 | runs-on: ${{ matrix.config.os }} 7 | 8 | strategy: 9 | matrix: 10 | config: 11 | - { name: "Ubuntu-clang", os: ubuntu-latest, cc: "clang", cxx: "clang++" } 12 | 13 | container: 14 | image: sibylau/mlir-llvm:omp 15 | 16 | steps: 17 | - name: Check out repository code 18 | uses: actions/checkout@v3 19 | 20 | - name: Build UniSparse 21 | run: | 22 | mkdir -p build && cd build 23 | export CPATH=/install/eigen-3.4.0:/install/llvm-project/mlir/lib:$CPATH 24 | export CPATH=/install/llvm-project/mlir/include/mlir:$CPATH 25 | export PATH=/install/llvm-project/build/bin:$PATH 26 | export CPATH=/install/llvm-project/openmp/build/runtime/src:$CPATH 27 | export LD_LIBRARY_PATH=/install/llvm-project/openmp/build/runtime/src:$LD_LIBRARY_PATH 28 | cmake .. \ 29 | -DMLIR_DIR="/install/llvm-project/build/lib/cmake/mlir" \ 30 | -DLLVM_DIR="/install/llvm-project/build/lib/cmake/llvm" \ 31 | -DLLVM_BUILD_LIBRARY_DIR="/install/llvm-project/build" \ 32 | -DLLVM_EXTERNAL_LIT="/install/llvm-project/build/bin/llvm-lit" \ 33 | -DEXTERNAL_INCLUDE_DIRS="/install/eigen-3.4.0" \ 34 | -DMLIR_LIB_DIR="/install/llvm-project/mlir/lib" \ 35 | -DLLVM_ENABLE_ASSERTIONS=ON \ 36 | -DCMAKE_BUILD_TYPE=RELEASE \ 37 | -DLLVM_USE_LINKER=lld \ 38 | -DCMAKE_C_COMPILER=clang \ 39 | -DCMAKE_CXX_COMPILER=clang++ 40 | cmake --build . -j $(nproc) 41 | 42 | # - name: Check UniSparse 43 | # run: | 44 | # cmake --build . --target check-unisparse -j $(nproc) 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | /build* 3 | # /scripts* 4 | # scripts/* 5 | evaluation/CPU/build* 6 | storage-src/1 7 | /eigen -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.0.0 2 | message: "If you use this software, please cite it as below." 3 | authors: 4 | - family-names: "Liu" 5 | given-names: "Jie" 6 | orcid: "https://orcid.org/0000-0003-1534-3500" 7 | - family-names: "Zhao" 8 | given-names: "Zhongyuan" 9 | orcid: "https://orcid.org/0000-0002-6637-553X" 10 | - family-names: "Ding" 11 | given-names: "Zijian" 12 | orcid: "https://orcid.org/0009-0000-4555-2077" 13 | - family-names: "Brock" 14 | given-names: "Benjamin" 15 | orcid: "https://orcid.org/0000-0003-1488-1622" 16 | - family-names: "Rong" 17 | given-names: "Hongbo" 18 | orcid: "https://orcid.org/0000-0002-3275-7791" 19 | - family-names: "Zhang" 20 | given-names: "Zhiru" 21 | orcid: "https://orcid.org/0000-0002-0778-0308" 22 | title: "UniSparse: An Intermediate Language for General Sparse Format Customization" 23 | version: 1.0.0 24 | doi: 10.5281/zenodo.10464499 25 | date-released: 2024-01-05 26 | url: "https://github.com/cornell-zhang/UniSparse" -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13.4) 2 | project(unisparse-dialect LANGUAGES CXX C) 3 | 4 | set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) 5 | 6 | set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to") 7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLGAS} -O3") 8 | 9 | find_package(MLIR REQUIRED CONFIG) 10 | 11 | message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") 12 | message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") 13 | message(STATUS "Using LLVM_BUILD_LIBRARY_DIR = ${LLVM_BUILD_LIBRARY_DIR}") 14 | message(STATUS "LLVM include DIR = ${LLVM_INCLUDE_DIRS}") 15 | message(STATUS "MLIR include DIR = ${MLIR_INCLUDE_DIRS}") 16 | 17 | 18 | set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin) 19 | set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib) 20 | set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR}) 21 | 22 | message(STATUS "MLIR lib DIR = ${MLIR_LIB_DIR}") 23 | 24 | list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") 25 | list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") 26 | include(TableGen) 27 | include(AddLLVM) 28 | include(AddMLIR) 29 | include(HandleLLVMOptions) 30 | 31 | include_directories(${LLVM_INCLUDE_DIRS}) 32 | include_directories(${MLIR_INCLUDE_DIRS}) 33 | include_directories(${MLIR_LIB_DIR}) 34 | include_directories(${PROJECT_SOURCE_DIR}/include) 35 | include_directories(${PROJECT_BINARY_DIR}/include) 36 | include_directories(${EXTERNAL_INCLUDE_DIRS}) 37 | link_directories(${LLVM_BUILD_LIBRARY_DIR}) 38 | add_definitions(${LLVM_DEFINITIONS}) 39 | 40 | add_subdirectory(include) 41 | add_subdirectory(lib) 42 | add_subdirectory(test) 43 | add_subdirectory(unisparse-opt) 44 | add_subdirectory(unisparse-translate) -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/executables/coo_c2sr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/UniSparse/executables/coo_c2sr -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/executables/coo_c2sr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/UniSparse/executables/coo_c2sr.o -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/executables/coo_cisr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/UniSparse/executables/coo_cisr -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/executables/coo_cisr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/UniSparse/executables/coo_cisr.o -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/executables/coo_dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/UniSparse/executables/coo_dia -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/executables/coo_dia.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/UniSparse/executables/coo_dia.o -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/executables/coo_ell: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/UniSparse/executables/coo_ell -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/executables/coo_ell.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/UniSparse/executables/coo_ell.o -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/executables/csb_dia_v: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/UniSparse/executables/csb_dia_v -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/executables/csb_dia_v.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/UniSparse/executables/csb_dia_v.o -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/executables/csr_csc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/UniSparse/executables/csr_csc -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/executables/csr_csc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/UniSparse/executables/csr_csc.o -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/executables/dcsc_bcsr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/UniSparse/executables/dcsc_bcsr -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/executables/dcsc_bcsr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/UniSparse/executables/dcsc_bcsr.o -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/unisparse_coo_c2sr.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delUniSparseTensorF32(!llvm.ptr) 3 | func.func private @sptTileMergeF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 4 | func.func private @sptSeparateF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptTrimF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptGrowF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptFuseF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptMoveF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptTileSplitF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptCopyF32(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 11 | func.func private @sptFromFileF32(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @rtclock() -> f64 13 | func.func private @getTensorFilename(index) -> !llvm.ptr 14 | func.func @main() { 15 | %c0 = arith.constant 0 : index 16 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 17 | %1 = call @sptFromFileF32(%0) : (!llvm.ptr) -> !llvm.ptr 18 | %2 = call @sptCopyF32(%1) : (!llvm.ptr) -> !llvm.ptr 19 | %3 = call @rtclock() : () -> f64 20 | %c0_i32 = arith.constant 0 : i32 21 | %c1_i32 = arith.constant 1 : i32 22 | %c2_i32 = arith.constant 2 : i32 23 | %c3_i32 = arith.constant 3 : i32 24 | %c4_i32 = arith.constant 4 : i32 25 | %c5_i32 = arith.constant 5 : i32 26 | %c1024_i32 = arith.constant 1024 : i32 27 | %4 = call @sptTileSplitF32(%2, %c0_i32, %c1024_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 28 | %5 = call @sptMoveF32(%4, %c1_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 29 | %6 = call @sptFuseF32(%5, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 30 | %7 = call @sptFuseF32(%6, %c1_i32) : (!llvm.ptr, i32) -> !llvm.ptr 31 | %8 = call @sptGrowF32(%7, %c1_i32) : (!llvm.ptr, i32) -> !llvm.ptr 32 | %9 = call @rtclock() : () -> f64 33 | %10 = arith.subf %9, %3 : f64 34 | vector.print %10 : f64 35 | %c0_i32_0 = arith.constant 0 : i32 36 | %c1_i32_1 = arith.constant 1 : i32 37 | %c2_i32_2 = arith.constant 2 : i32 38 | %c3_i32_3 = arith.constant 3 : i32 39 | %c4_i32_4 = arith.constant 4 : i32 40 | %c5_i32_5 = arith.constant 5 : i32 41 | %11 = call @sptTrimF32(%8, %c0_i32_0) : (!llvm.ptr, i32) -> !llvm.ptr 42 | %12 = call @sptSeparateF32(%11, %c0_i32_0) : (!llvm.ptr, i32) -> !llvm.ptr 43 | %13 = call @sptSeparateF32(%12, %c1_i32_1) : (!llvm.ptr, i32) -> !llvm.ptr 44 | %14 = call @sptMoveF32(%13, %c1_i32_1, %c0_i32_0) : (!llvm.ptr, i32, i32) -> !llvm.ptr 45 | %c1024_i32_6 = arith.constant 1024 : i32 46 | %15 = call @sptTileMergeF32(%14, %c0_i32_0, %c1024_i32_6) : (!llvm.ptr, i32, i32) -> !llvm.ptr 47 | call @delUniSparseTensorF32(%1) : (!llvm.ptr) -> () 48 | call @delUniSparseTensorF32(%15) : (!llvm.ptr) -> () 49 | return 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/unisparse_coo_cisr.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delUniSparseTensorF32(!llvm.ptr) 3 | func.func private @sptCheckF32(!llvm.ptr, !llvm.ptr) attributes {llvm.emit_c_interface} 4 | func.func private @sptMoveF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptFuseF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptSumF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptScheduleF32(!llvm.ptr, i32, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptPadF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptReorderF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptCopyF32(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 11 | func.func private @sptFromFileF32(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @rtclock() -> f64 13 | func.func private @getTensorFilename(index) -> !llvm.ptr 14 | func.func @main() { 15 | %cst = arith.constant 0.000000e+00 : f32 16 | %c0 = arith.constant 0 : index 17 | %c1 = arith.constant 1 : index 18 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 19 | %1 = call @sptFromFileF32(%0) : (!llvm.ptr) -> !llvm.ptr 20 | %2 = call @sptCopyF32(%1) : (!llvm.ptr) -> !llvm.ptr 21 | %3 = call @rtclock() : () -> f64 22 | %c0_i32 = arith.constant 0 : i32 23 | %c1_i32 = arith.constant 1 : i32 24 | %c2_i32 = arith.constant 2 : i32 25 | %c3_i32 = arith.constant 3 : i32 26 | %c4_i32 = arith.constant 4 : i32 27 | %c5_i32 = arith.constant 1024 : i32 28 | %4 = call @sptSumF32(%2, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 29 | %5 = call @sptScheduleF32(%4, %c0_i32, %c0_i32, %c5_i32) : (!llvm.ptr, i32, i32, i32) -> !llvm.ptr 30 | %6 = call @sptMoveF32(%5, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 31 | %7 = call @sptFuseF32(%6, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 32 | %8 = call @sptFuseF32(%7, %c1_i32) : (!llvm.ptr, i32) -> !llvm.ptr 33 | %14 = call @rtclock() : () -> f64 34 | %15 = arith.subf %14, %3 : f64 35 | vector.print %15 : f64 36 | call @delUniSparseTensorF32(%1) : (!llvm.ptr) -> () 37 | call @delUniSparseTensorF32(%7) : (!llvm.ptr) -> () 38 | return 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/unisparse_coo_dia.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delUniSparseTensorF32(!llvm.ptr) 3 | func.func private @sptCheckF32(!llvm.ptr, !llvm.ptr) attributes {llvm.emit_c_interface} 4 | func.func private @sptNegF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptAddF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptSeparateF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptDevectorizeF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptVectorizeF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptFuseF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptMoveF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 11 | func.func private @sptFusedDIA2DF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @sptSubF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 13 | func.func private @sptSwapF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 14 | func.func private @sptCopyF32(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 15 | func.func private @sptFromFileF32(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 16 | func.func private @rtclock() -> f64 17 | func.func private @getTensorFilename(index) -> !llvm.ptr 18 | func.func @main() { 19 | %cst = arith.constant 0.000000e+00 : f32 20 | %c0 = arith.constant 0 : index 21 | %c1 = arith.constant 1 : index 22 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 23 | %1 = call @sptFromFileF32(%0) : (!llvm.ptr) -> !llvm.ptr 24 | %2 = call @sptCopyF32(%1) : (!llvm.ptr) -> !llvm.ptr 25 | %3 = call @rtclock() : () -> f64 26 | %c0_i32 = arith.constant 0 : i32 27 | %c1_i32 = arith.constant 1 : i32 28 | %c2_i32 = arith.constant 2 : i32 29 | %c3_i32 = arith.constant 3 : i32 30 | %c4_i32 = arith.constant 4 : i32 31 | %c5_i32 = arith.constant -1 : i32 32 | %4 = call @sptFusedDIA2DF32(%2, %c5_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 33 | %9 = call @rtclock() : () -> f64 34 | %10 = arith.subf %9, %3 : f64 35 | vector.print %10 : f64 36 | call @delUniSparseTensorF32(%1) : (!llvm.ptr) -> () 37 | call @delUniSparseTensorF32(%4) : (!llvm.ptr) -> () 38 | return 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /evaluation/FormatConversion/UniSparse/unisparse_coo_ell.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delUniSparseTensorF32(!llvm.ptr) 3 | func.func private @sptCheckF32(!llvm.ptr, !llvm.ptr) attributes {llvm.emit_c_interface} 4 | func.func private @sptMoveF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptSwapF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptSeparateF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptTrimF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptGrowF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptFuseF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptSumF32(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 11 | func.func private @sptCustPadF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @sptEnumerateF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 13 | func.func private @sptFusedEnumeratePadF32(!llvm.ptr, i32, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 14 | func.func private @sptPadF32(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 15 | func.func private @sptCopyF32(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 16 | func.func private @sptFromFileF32(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 17 | func.func private @rtclock() -> f64 18 | func.func private @getTensorFilename(index) -> !llvm.ptr 19 | func.func @main() { 20 | %cst = arith.constant 0.000000e+00 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 24 | %1 = call @sptFromFileF32(%0) : (!llvm.ptr) -> !llvm.ptr 25 | %2 = call @sptCopyF32(%1) : (!llvm.ptr) -> !llvm.ptr 26 | %c0_i32 = arith.constant 0 : i32 27 | %c1_i32 = arith.constant 1 : i32 28 | %c2_i32 = arith.constant 2 : i32 29 | %c3_i32 = arith.constant 3 : i32 30 | %c4_i32 = arith.constant 4 : i32 31 | %c5_i32 = arith.constant 5 : i32 32 | %3 = call @rtclock() : () -> f64 33 | %6 = call @sptSumF32(%2, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 34 | %9 = call @sptFusedEnumeratePadF32(%6, %c1_i32, %c1_i32, %c1_i32) : (!llvm.ptr, i32, i32, i32) -> !llvm.ptr 35 | %12 = call @rtclock() : () -> f64 36 | %13 = arith.subf %12, %3 : f64 37 | vector.print %13 : f64 38 | call @delUniSparseTensorF32(%1) : (!llvm.ptr) -> () 39 | call @delUniSparseTensorF32(%9) : (!llvm.ptr) -> () 40 | return 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/coo_c2sr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/coo_c2sr -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/coo_c2sr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/coo_c2sr.o -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/coo_cisr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/coo_cisr -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/coo_cisr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/coo_cisr.o -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/coo_dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/coo_dia -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/coo_dia.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/coo_dia.o -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/coo_ell: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/coo_ell -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/coo_ell.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/coo_ell.o -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/csb_dia_v: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/csb_dia_v -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/csb_dia_v.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/csb_dia_v.o -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/csr_csc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/csr_csc -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/csr_csc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/csr_csc.o -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/dcsc_bcsr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/dcsc_bcsr -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/dcsc_bcsr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/dcsc_bcsr.o -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/sparse_tensor_csr_csc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/sparse_tensor_csr_csc -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/sparse_tensor_csr_csc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/sparse_tensor_csr_csc.o -------------------------------------------------------------------------------- /evaluation/FormatConversion/executables/taco_format_conversion: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/executables/taco_format_conversion -------------------------------------------------------------------------------- /evaluation/FormatConversion/output.log: -------------------------------------------------------------------------------- 1 | wiki-Vote_row_major.mtx 2 | CSR_CSC UniSparse 3 | Size of the matrix: 8297 8297 103689 4 | 0.00233984 5 | CSR_CSC SparseTensor 6 | 0.00692987 7 | CSR_CSC TACO 8 | 0.003658(s) 9 | COO_DIA UniSparse 10 | Size of the matrix: 8297 8297 103689 11 | 0.0677412 12 | COO_DIA TACO 13 | 0.150222(s) 14 | COO_ELL UniSparse 15 | Size of the matrix: 8297 8297 103689 16 | 0.017961 17 | COO_ELL TACO 18 | 0.022383(s) 19 | DCSC_BCSR UniSparse 20 | Size of the matrix: 8297 8297 103689 21 | 0.0220902 22 | CSB_DIA_V UniSparse 23 | Size of the matrix: 8297 8297 103689 24 | 0.216771 25 | COO_C2SR UniSparse 26 | Size of the matrix: 8297 8297 103689 27 | 0.00874305 28 | COO_CISR UniSparse 29 | Size of the matrix: 8297 8297 103689 30 | 0.00664592 31 | email-Eu-core_row_major.mtx 32 | CSR_CSC UniSparse 33 | Size of the matrix: 1005 1005 25571 34 | 0.000365973 35 | CSR_CSC SparseTensor 36 | 0.00125694 37 | CSR_CSC TACO 38 | 0.000478(s) 39 | COO_DIA UniSparse 40 | Size of the matrix: 1005 1005 25571 41 | 0.00357389 42 | COO_DIA TACO 43 | 0.003676(s) 44 | COO_ELL UniSparse 45 | Size of the matrix: 1005 1005 25571 46 | 0.00309896 47 | COO_ELL TACO 48 | 0.003041(s) 49 | DCSC_BCSR UniSparse 50 | Size of the matrix: 1005 1005 25571 51 | 0.00510502 52 | CSB_DIA_V UniSparse 53 | Size of the matrix: 1005 1005 25571 54 | 0.00582194 55 | COO_C2SR UniSparse 56 | Size of the matrix: 1005 1005 25571 57 | 0.00153899 58 | COO_CISR UniSparse 59 | Size of the matrix: 1005 1005 25571 60 | 0.00179195 61 | crystm02_row_major.mtx 62 | CSR_CSC UniSparse 63 | Size of the matrix: 13965 13965 168435 64 | 0.00195408 65 | CSR_CSC SparseTensor 66 | 0.0149548 67 | CSR_CSC TACO 68 | 0.003449(s) 69 | COO_DIA UniSparse 70 | Size of the matrix: 13965 13965 168435 71 | 0.00334096 72 | COO_DIA TACO 73 | 0.004621(s) 74 | COO_ELL UniSparse 75 | Size of the matrix: 13965 13965 168435 76 | 0.00642109 77 | COO_ELL TACO 78 | 0.004248(s) 79 | DCSC_BCSR UniSparse 80 | Size of the matrix: 13965 13965 168435 81 | 0.0245421 82 | CSB_DIA_V UniSparse 83 | Size of the matrix: 13965 13965 168435 84 | 0.0990119 85 | COO_C2SR UniSparse 86 | Size of the matrix: 13965 13965 168435 87 | 0.00964808 88 | COO_CISR UniSparse 89 | Size of the matrix: 13965 13965 168435 90 | 0.01104 91 | nemeth21_row_major.mtx 92 | CSR_CSC UniSparse 93 | Size of the matrix: 9506 9506 591626 94 | 0.00622821 95 | CSR_CSC SparseTensor 96 | 0.0690989 97 | CSR_CSC TACO 98 | 0.022672(s) 99 | COO_DIA UniSparse 100 | Size of the matrix: 9506 9506 591626 101 | 0.010097 102 | COO_DIA TACO 103 | 0.023704(s) 104 | COO_ELL UniSparse 105 | Size of the matrix: 9506 9506 591626 106 | 0.0211241 107 | COO_ELL TACO 108 | 0.03477(s) 109 | DCSC_BCSR UniSparse 110 | Size of the matrix: 9506 9506 591626 111 | 0.079057 112 | CSB_DIA_V UniSparse 113 | Size of the matrix: 9506 9506 591626 114 | 0.103504 115 | COO_C2SR UniSparse 116 | Size of the matrix: 9506 9506 591626 117 | 0.032166 118 | COO_CISR UniSparse 119 | Size of the matrix: 9506 9506 591626 120 | 0.0347331 -------------------------------------------------------------------------------- /evaluation/FormatConversion/sparse_tensor_dialect/sparse_tensor_csr_csc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/FormatConversion/sparse_tensor_dialect/sparse_tensor_csr_csc -------------------------------------------------------------------------------- /evaluation/FormatConversion/sparse_tensor_dialect/sparse_tensor_csr_to_csc.mlir: -------------------------------------------------------------------------------- 1 | // mlir-opt ./sparse_tensor_csr_to_csc.mlir -sparse-compiler | mlir-translate -mlir-to-llvmir | opt -O3 -S | llc -O3 -relocation-model=pic -filetype=obj -o csr_to_csc.o 2 | 3 | // clang++ spmm.o -L$SPLHOME/build/lib -lmlir_sparlay_runner_utils \ 4 | // -L$LLVM_ROOT/build/lib -lmlir_runner_utils -lmlir_c_runner_utils -o spmm 5 | 6 | // ./spmm 7 | 8 | // RUN: sparlay-opt %s -lower-format-conversion -lower-struct -dce | FileCheck %s 9 | 10 | !Filename = !llvm.ptr 11 | 12 | #CSR = #sparse_tensor.encoding<{ 13 | dimLevelType = [ "dense", "compressed" ], 14 | dimOrdering = affine_map<(i,j) -> (i,j)> 15 | }> 16 | 17 | #CSC = #sparse_tensor.encoding<{ 18 | dimLevelType = [ "dense", "compressed" ], 19 | dimOrdering = affine_map<(i,j) -> (j,i)> 20 | }> 21 | 22 | #trait1 = { 23 | indexing_maps = [ 24 | affine_map<(i,j,k) -> (i, k)>, // A 25 | affine_map<(i,j,k) -> (k, j)>, // B 26 | affine_map<(i,j,k) -> (i, j)> // X (out) 27 | ], 28 | iterator_types = ["parallel", "parallel", "reduction"], 29 | doc = "X(i,j) =+ A(i,k) * B(k, j)" 30 | } 31 | 32 | module { 33 | func.func private @rtclock() -> f64 34 | func.func private @getTensorFilename(index) -> (!Filename) 35 | 36 | //CHECK-LABEL: func.func @main 37 | func.func @main() { 38 | %i0 = arith.constant 0.0 : f32 39 | %c0 = arith.constant 0 : index 40 | %c1 = arith.constant 1 : index 41 | 42 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 43 | %a0 = sparse_tensor.new %fileName : !Filename to tensor 44 | %t_start1 = call @rtclock() : () -> f64 45 | %a1 = sparse_tensor.convert %a0 : tensor to tensor 46 | %t_end1 = call @rtclock() : () -> f64 47 | %t_1 = arith.subf %t_end1, %t_start1: f64 48 | vector.print %t_1 : f64 49 | 50 | //Release the resources 51 | bufferization.dealloc_tensor %a1 : tensor 52 | // bufferization.dealloc_tensor %init_256_4 : tensor 53 | // bufferization.dealloc_tensor %o1_4_4 : tensor 54 | return 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/sparse_tensor_csc_csc_csc_spgemm_F64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/sparse_tensor_csc_csc_csc_spgemm_F64 -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/sparse_tensor_csc_csc_csc_spgemm_F64.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/sparse_tensor_csc_csc_csc_spgemm_F64.o -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/sparse_tensor_csr_csr_csr_spgemm_F64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/sparse_tensor_csr_csr_csr_spgemm_F64 -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/sparse_tensor_csr_csr_csr_spgemm_F64.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/sparse_tensor_csr_csr_csr_spgemm_F64.o -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/sparse_tensor_csr_spmm_F64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/sparse_tensor_csr_spmm_F64 -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/sparse_tensor_csr_spmm_F64.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/sparse_tensor_csr_spmm_F64.o -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/sparse_tensor_dcsc_spmm_F64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/sparse_tensor_dcsc_spmm_F64 -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/sparse_tensor_dcsc_spmm_F64.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/sparse_tensor_dcsc_spmm_F64.o -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/taco_csr_csr_csr_spgemm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/taco_csr_csr_csr_spgemm -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/taco_csr_spmm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/taco_csr_spmm -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/taco_dcsc_spmm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/taco_dcsc_spmm -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/unisparse_csc_csc_csc_spgemm_F64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/unisparse_csc_csc_csc_spgemm_F64 -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/unisparse_csc_csc_csc_spgemm_F64.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/unisparse_csc_csc_csc_spgemm_F64.o -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/unisparse_csr_csr_csr_spgemm_F64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/unisparse_csr_csr_csr_spgemm_F64 -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/unisparse_csr_csr_csr_spgemm_F64.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/unisparse_csr_csr_csr_spgemm_F64.o -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/unisparse_csr_spmm_F64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/unisparse_csr_spmm_F64 -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/unisparse_csr_spmm_F64.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/unisparse_csr_spmm_F64.o -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/unisparse_dcsc_spmm_F64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/unisparse_dcsc_spmm_F64 -------------------------------------------------------------------------------- /evaluation/KernelGeneration/executables/unisparse_dcsc_spmm_F64.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/KernelGeneration/executables/unisparse_dcsc_spmm_F64.o -------------------------------------------------------------------------------- /evaluation/KernelGeneration/output.log: -------------------------------------------------------------------------------- 1 | p2p-Gnutella31_row_major 2 | CSR_SpMM UniSparse 3 | 0.190639 4 | CSR_SpMM SparseTensor 5 | 0.182643 6 | CSR_SpMM TACO 7 | 2.35181 (s) 8 | DCSC_SpMM UniSparse 9 | 0.207442 10 | DCSC_SpMM SparseTensor 11 | 0.203161 12 | DCSC_SpMM TACO 13 | 2.37913 (s) 14 | CSR_CSR_CSR_SpGEMM UniSparse 15 | 0.047277 16 | CSR_CSR_CSR_SpGEMM SparseTensor 17 | 0.0516961 18 | CSR_CSR_CSR_SpGEMM TACO 19 | 0.094224 (s) 20 | CSC_CSC_CSC_SpGEMM UniSparse 21 | 0.050751 22 | CSC_CSC_CSC_SpGEMM SparseTensor 23 | 0.0504441 24 | wiki-Vote_row_major 25 | CSR_SpMM UniSparse 26 | 0.084409 27 | CSR_SpMM SparseTensor 28 | 0.085114 29 | CSR_SpMM TACO 30 | 1.13663 (s) 31 | DCSC_SpMM UniSparse 32 | 0.0930312 33 | DCSC_SpMM SparseTensor 34 | 0.0928359 35 | DCSC_SpMM TACO 36 | 1.11957 (s) 37 | CSR_CSR_CSR_SpGEMM UniSparse 38 | 0.155286 39 | CSR_CSR_CSR_SpGEMM SparseTensor 40 | 0.156852 41 | CSR_CSR_CSR_SpGEMM TACO 42 | 0.397439 (s) 43 | CSC_CSC_CSC_SpGEMM UniSparse 44 | 0.171326 45 | CSC_CSC_CSC_SpGEMM SparseTensor 46 | 0.168915 47 | email-Eu-core_row_major 48 | CSR_SpMM UniSparse 49 | 0.020139 50 | CSR_SpMM SparseTensor 51 | 0.0200889 52 | CSR_SpMM TACO 53 | 0.278436 (s) 54 | DCSC_SpMM UniSparse 55 | 0.021096 56 | DCSC_SpMM SparseTensor 57 | 0.021245 58 | DCSC_SpMM TACO 59 | 0.267589 (s) 60 | CSR_CSR_CSR_SpGEMM UniSparse 61 | 0.0371339 62 | CSR_CSR_CSR_SpGEMM SparseTensor 63 | 0.054724 64 | CSR_CSR_CSR_SpGEMM TACO 65 | 0.095778 (s) 66 | CSC_CSC_CSC_SpGEMM UniSparse 67 | 0.0381031 68 | CSC_CSC_CSC_SpGEMM SparseTensor 69 | 0.039902 -------------------------------------------------------------------------------- /evaluation/KernelGeneration/sparse_tensor_dialect/sparse_tensor_csc_csc_csc_spgemm_F64.mlir: -------------------------------------------------------------------------------- 1 | // mlir-opt ./sparse_tensor_csr_csr_spgemm.mlir -sparse-compiler | mlir-translate -mlir-to-llvmir | opt -O3 -S | llc -O3 -relocation-model=pic -filetype=obj -o spmv.o 2 | // clang++ spmm.o -L$SPLHOME/build/lib -lmlir_sparlay_runner_utils \ 3 | // -L$LLVMHOME/build/lib -lmlir_runner_utils -lmlir_c_runner_utils -o spmv 4 | 5 | // ./spgemm 6 | 7 | !Filename = !llvm.ptr 8 | 9 | #CSC = #sparse_tensor.encoding<{ 10 | dimLevelType = [ "dense", "compressed" ], 11 | dimOrdering = affine_map<(i,j) -> (j,i)> 12 | }> 13 | 14 | #trait1 = { 15 | indexing_maps = [ 16 | affine_map<(i,j,k) -> (i, k)>, // A 17 | affine_map<(i,j,k) -> (k, j)>, // B 18 | affine_map<(i,j,k) -> (i, j)> // X (out) 19 | ], 20 | iterator_types = ["parallel", "parallel", "reduction"], 21 | doc = "X(i,j) =+ A(i,k) * B(k, j)" 22 | } 23 | 24 | module { 25 | func.func private @rtclock() -> f64 26 | func.func private @getTensorFilename(index) -> (!Filename) 27 | 28 | func.func @kernel_spgemm(%arg0: tensor, %arg1: tensor, %dim0: index, %dim1: index) -> tensor { 29 | %0 = bufferization.alloc_tensor(%dim0, %dim1) : tensor 30 | %1 = linalg.generic #trait1 31 | ins(%arg0, %arg1 : tensor, tensor) 32 | outs(%0: tensor) { 33 | ^bb0(%a: f64, %b: f64, %x: f64): 34 | %2 = arith.mulf %a, %b : f64 35 | %3 = arith.addf %x, %2 : f64 36 | linalg.yield %3 : f64 37 | } -> tensor 38 | return %1 : tensor 39 | } 40 | 41 | //CHECK-LABEL: func.func @main 42 | func.func @main() { 43 | %i0 = arith.constant 0.0 : f64 44 | %c0 = arith.constant 0 : index 45 | %c1 = arith.constant 1 : index 46 | 47 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 48 | 49 | %a0 = sparse_tensor.new %fileName : !Filename to tensor 50 | %a1 = sparse_tensor.new %fileName : !Filename to tensor 51 | %dim0 = tensor.dim %a0, %c0 : tensor 52 | %dim1 = tensor.dim %a1, %c1 : tensor 53 | 54 | // Initialize output sparse matrix. 55 | 56 | %t_start4 = call @rtclock() : () -> f64 57 | %0 = call @kernel_spgemm(%a0, %a1, %dim0, %dim1) : (tensor, tensor, index, index) -> tensor 58 | %t_end4 = call @rtclock() : () -> f64 59 | %t_4 = arith.subf %t_end4, %t_start4: f64 60 | vector.print %t_4 : f64 61 | 62 | %out_val = sparse_tensor.values %0 : tensor to memref 63 | %v0 = vector.transfer_read %out_val[%c0], %i0: memref, vector<8xf64> 64 | %nnz = memref.dim %out_val, %c0 : memref 65 | // vector.print %v0 : vector<8xf64> 66 | // vector.print %nnz : index 67 | 68 | //Release the resources 69 | bufferization.dealloc_tensor %a0 : tensor 70 | bufferization.dealloc_tensor %a1 : tensor 71 | return 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /evaluation/KernelGeneration/sparse_tensor_dialect/sparse_tensor_csr_csr_csr_spgemm_F64.mlir: -------------------------------------------------------------------------------- 1 | // mlir-opt ./sparse_tensor_csr_csr_csr_spgemm_F64.mlir -sparse-compiler | mlir-translate -mlir-to-llvmir | opt -O3 -S | llc -O3 -relocation-model=pic -filetype=obj -o csr_csr_csr_spgemm_F64.o 2 | // clang++ csr_csr_csr_spgemm_F64.o -L$SPLHOME/build/lib -lmlir_unisparse_runner_utils \ 3 | // -L$LLVM_ROOT/build/lib -lmlir_runner_utils -lmlir_c_runner_utils -o csr_csr_csr_spgemm_F64 4 | 5 | // ./csr_csr_csr_spgemm_F64 6 | 7 | !Filename = !llvm.ptr 8 | 9 | #CSR = #sparse_tensor.encoding<{ 10 | dimLevelType = [ "dense", "compressed" ], 11 | dimOrdering = affine_map<(i,j) -> (i,j)> 12 | }> 13 | 14 | #trait1 = { 15 | indexing_maps = [ 16 | affine_map<(i,j,k) -> (i, k)>, // A 17 | affine_map<(i,j,k) -> (k, j)>, // B 18 | affine_map<(i,j,k) -> (i, j)> // X (out) 19 | ], 20 | iterator_types = ["parallel", "parallel", "reduction"], 21 | doc = "X(i,j) =+ A(i,k) * B(k, j)" 22 | } 23 | 24 | module { 25 | func.func private @rtclock() -> f64 26 | func.func private @getTensorFilename(index) -> (!Filename) 27 | 28 | func.func @kernel_csr_spgemm(%arg0: tensor, %arg1: tensor, %dim0: index, %dim1: index) -> tensor { 29 | %0 = bufferization.alloc_tensor(%dim0, %dim1) : tensor 30 | %1 = linalg.generic #trait1 31 | ins(%arg0, %arg1 : tensor, tensor) 32 | outs(%0: tensor) { 33 | ^bb0(%a: f64, %b: f64, %x: f64): 34 | %2 = arith.mulf %a, %b : f64 35 | %3 = arith.addf %x, %2 : f64 36 | linalg.yield %3 : f64 37 | } -> tensor 38 | return %1 : tensor 39 | } 40 | 41 | //CHECK-LABEL: func.func @main 42 | func.func @main() { 43 | %i0 = arith.constant 0.0 : f64 44 | %c0 = arith.constant 0 : index 45 | %c1 = arith.constant 1 : index 46 | 47 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 48 | 49 | %a0 = sparse_tensor.new %fileName : !Filename to tensor 50 | %a1 = sparse_tensor.new %fileName : !Filename to tensor 51 | %dim0 = tensor.dim %a0, %c0 : tensor 52 | %dim1 = tensor.dim %a1, %c1 : tensor 53 | 54 | // Initialize output sparse matrix. 55 | 56 | %t_start4 = call @rtclock() : () -> f64 57 | %0 = call @kernel_csr_spgemm(%a0, %a1, %dim0, %dim1) : (tensor, tensor, index, index) -> tensor 58 | %t_end4 = call @rtclock() : () -> f64 59 | %t_4 = arith.subf %t_end4, %t_start4: f64 60 | vector.print %t_4 : f64 61 | 62 | %out_val = sparse_tensor.values %0 : tensor to memref 63 | %v0 = vector.transfer_read %out_val[%c0], %i0: memref, vector<8xf64> 64 | %nnz = memref.dim %out_val, %c0 : memref 65 | // vector.print %v0 : vector<8xf64> 66 | // vector.print %nnz : index 67 | 68 | //Release the resources 69 | bufferization.dealloc_tensor %a0 : tensor 70 | bufferization.dealloc_tensor %a1 : tensor 71 | return 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /evaluation/KernelGeneration/sparse_tensor_dialect/sparse_tensor_csr_spmm_F64.mlir: -------------------------------------------------------------------------------- 1 | // mlir-opt ./sparse_tensor_csr_spmm.mlir -sparse-compiler | mlir-translate -mlir-to-llvmir | opt -O3 -S | llc -O3 -relocation-model=pic -filetype=obj -o spmm.o 2 | 3 | // clang++ spmm.o -L$SPLHOME/build/lib -lmlir_sparlay_runner_utils \ 4 | // -L$LLVMHOME/build/lib -lmlir_runner_utils -lmlir_c_runner_utils -o spmm 5 | 6 | // ./spmm 7 | 8 | !Filename = !llvm.ptr 9 | 10 | #CSR = #sparse_tensor.encoding<{ 11 | dimLevelType = [ "dense", "compressed" ], 12 | dimOrdering = affine_map<(i,j) -> (i,j)> 13 | }> 14 | 15 | #trait1 = { 16 | indexing_maps = [ 17 | affine_map<(i,j,k) -> (i, k)>, // A 18 | affine_map<(i,j,k) -> (k, j)>, // B 19 | affine_map<(i,j,k) -> (i, j)> // X (out) 20 | ], 21 | iterator_types = ["parallel", "parallel", "reduction"], 22 | doc = "X(i,j) =+ A(i,k) * B(k, j)" 23 | } 24 | 25 | module { 26 | func.func private @rtclock() -> f64 27 | func.func private @getTensorFilename(index) -> (!Filename) 28 | 29 | func.func @kernel_csr_spmm(%arg0: tensor, %arg1: tensor, %argx: tensor) -> tensor { 30 | %0 = linalg.generic #trait1 31 | ins(%arg0, %arg1 : tensor, tensor) 32 | outs(%argx: tensor) { 33 | ^bb0(%a: f64, %b: f64, %x: f64): 34 | %2 = arith.mulf %a, %b : f64 35 | %3 = arith.addf %x, %2 : f64 36 | linalg.yield %3 : f64 37 | } -> tensor 38 | return %0 : tensor 39 | } 40 | 41 | //CHECK-LABEL: func.func @main 42 | func.func @main() { 43 | %i0 = arith.constant 0.0 : f64 44 | %c0 = arith.constant 0 : index 45 | %c1 = arith.constant 1 : index 46 | %c4 = arith.constant 1000 : index 47 | 48 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 49 | 50 | %t_start0 = call @rtclock() : () -> f64 51 | %a0 = sparse_tensor.new %fileName : !Filename to tensor 52 | %c256 = tensor.dim %a0, %c1 : tensor 53 | %t_end0 = call @rtclock() : () -> f64 54 | %t_0 = arith.subf %t_end0, %t_start0: f64 55 | // vector.print %t_0 : f64 56 | 57 | // Initialize dense matrix. 58 | %init_256_4 = bufferization.alloc_tensor(%c256, %c4) : tensor 59 | %b = scf.for %i = %c0 to %c256 step %c1 iter_args(%t = %init_256_4) -> tensor { 60 | %b2 = scf.for %j = %c0 to %c4 step %c1 iter_args(%t2 = %t) -> tensor { 61 | %k0 = arith.muli %i, %c4 : index 62 | %k1 = arith.addi %j, %k0 : index 63 | %k2 = arith.index_cast %k1 : index to i32 64 | %k = arith.sitofp %k2 : i32 to f64 65 | %t3 = tensor.insert %k into %t2[%i, %j] : tensor 66 | scf.yield %t3 : tensor 67 | } 68 | scf.yield %b2 : tensor 69 | } 70 | 71 | %o0_4_4 = bufferization.alloc_tensor(%c256, %c4) : tensor 72 | %o0 = scf.for %i = %c0 to %c256 step %c1 iter_args(%t = %o0_4_4) -> tensor { 73 | %x2 = scf.for %j = %c0 to %c4 step %c1 iter_args(%t2 = %t) -> tensor { 74 | %t3 = tensor.insert %i0 into %t2[%i, %j] : tensor 75 | scf.yield %t3 : tensor 76 | } 77 | scf.yield %x2 : tensor 78 | } 79 | 80 | %t_start4 = call @rtclock() : () -> f64 81 | %0 = call @kernel_csr_spmm(%a0, %b, %o0) : (tensor, tensor, tensor) -> tensor 82 | %t_end4 = call @rtclock() : () -> f64 83 | %t_4 = arith.subf %t_end4, %t_start4: f64 84 | vector.print %t_4 : f64 85 | %v0 = vector.transfer_read %0[%c0, %c0], %i0: tensor, vector<4x4xf64> 86 | // vector.print %v0 : vector<4x4xf64> 87 | 88 | //Release the resources 89 | bufferization.dealloc_tensor %a0 : tensor 90 | // bufferization.dealloc_tensor %init_256_4 : tensor 91 | // bufferization.dealloc_tensor %o0_4_4 : tensor 92 | return 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /evaluation/KernelGeneration/sparse_tensor_dialect/sparse_tensor_dcsc_spmm_F64.mlir: -------------------------------------------------------------------------------- 1 | // mlir-opt ./sparse_tensor_dcsc_spmm.mlir -sparse-compiler | mlir-translate -mlir-to-llvmir | opt -O3 -S | llc -O3 -relocation-model=pic -filetype=obj -o spmm.o 2 | 3 | // clang++ spmm.o -L$SPLHOME/build/lib -lmlir_sparlay_runner_utils \ 4 | // -L$LLVMHOME/build/lib -lmlir_runner_utils -lmlir_c_runner_utils -o spmm 5 | 6 | // ./spmm 7 | 8 | !Filename = !llvm.ptr 9 | 10 | #DCSC = #sparse_tensor.encoding<{ 11 | dimLevelType = [ "compressed", "compressed" ], 12 | dimOrdering = affine_map<(i,j) -> (j,i)> 13 | }> 14 | 15 | #trait1 = { 16 | indexing_maps = [ 17 | affine_map<(i,j,k) -> (i, k)>, // A 18 | affine_map<(i,j,k) -> (k, j)>, // B 19 | affine_map<(i,j,k) -> (i, j)> // X (out) 20 | ], 21 | iterator_types = ["parallel", "parallel", "reduction"], 22 | doc = "X(i,j) =+ A(i,k) * B(k, j)" 23 | } 24 | 25 | module { 26 | func.func private @rtclock() -> f64 27 | func.func private @getTensorFilename(index) -> (!Filename) 28 | 29 | func.func @kernel_dcsc_spmm(%arg0: tensor, %arg1: tensor, %argx: tensor) -> tensor { 30 | %0 = linalg.generic #trait1 31 | ins(%arg0, %arg1 : tensor, tensor) 32 | outs(%argx: tensor) { 33 | ^bb0(%a: f64, %b: f64, %x: f64): 34 | %2 = arith.mulf %a, %b : f64 35 | %3 = arith.addf %x, %2 : f64 36 | linalg.yield %3 : f64 37 | } -> tensor 38 | return %0 : tensor 39 | } 40 | 41 | //CHECK-LABEL: func.func @main 42 | func.func @main() { 43 | %i0 = arith.constant 0.0 : f64 44 | %c0 = arith.constant 0 : index 45 | %c1 = arith.constant 1 : index 46 | %c4 = arith.constant 1000 : index 47 | 48 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 49 | %t_start3 = call @rtclock() : () -> f64 50 | %a3 = sparse_tensor.new %fileName : !Filename to tensor 51 | %c256 = tensor.dim %a3, %c1 : tensor 52 | %t_end3 = call @rtclock() : () -> f64 53 | %t_3 = arith.subf %t_end3, %t_start3: f64 54 | // vector.print %t_3 : f64 55 | 56 | // Initialize dense matrix. 57 | %init_256_4 = bufferization.alloc_tensor(%c256, %c4) : tensor 58 | %b = scf.for %i = %c0 to %c256 step %c1 iter_args(%t = %init_256_4) -> tensor { 59 | %b2 = scf.for %j = %c0 to %c4 step %c1 iter_args(%t2 = %t) -> tensor { 60 | %k0 = arith.muli %i, %c4 : index 61 | %k1 = arith.addi %j, %k0 : index 62 | %k2 = arith.index_cast %k1 : index to i32 63 | %k = arith.sitofp %k2 : i32 to f64 64 | %t3 = tensor.insert %k into %t2[%i, %j] : tensor 65 | scf.yield %t3 : tensor 66 | } 67 | scf.yield %b2 : tensor 68 | } 69 | 70 | %o3_4_4 = bufferization.alloc_tensor(%c256, %c4) : tensor 71 | %o3 = scf.for %i = %c0 to %c256 step %c1 iter_args(%t = %o3_4_4) -> tensor { 72 | %x2 = scf.for %j = %c0 to %c4 step %c1 iter_args(%t2 = %t) -> tensor { 73 | %t3 = tensor.insert %i0 into %t2[%i, %j] : tensor 74 | scf.yield %t3 : tensor 75 | } 76 | scf.yield %x2 : tensor 77 | } 78 | 79 | %t_start7 = call @rtclock() : () -> f64 80 | %3 = call @kernel_dcsc_spmm(%a3, %b, %o3) : (tensor, tensor, tensor) -> tensor 81 | %t_end7 = call @rtclock() : () -> f64 82 | %t_7 = arith.subf %t_end7, %t_start7: f64 83 | vector.print %t_7 : f64 84 | %v3 = vector.transfer_read %3[%c0, %c0], %i0: tensor, vector<4x4xf64> 85 | // vector.print %v3 : vector<4x4xf64> 86 | 87 | //Release the resources 88 | bufferization.dealloc_tensor %a3 : tensor 89 | // bufferization.dealloc_tensor %init_256_4 : tensor 90 | // bufferization.dealloc_tensor %o3_4_4 : tensor 91 | return 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /evaluation/KernelGeneration/taco/taco_csr_csr_csr_spgemm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "taco.h" 4 | using namespace taco; 5 | int main(int argc, char* argv[]) { 6 | 7 | Format csr({Dense, Sparse}); 8 | 9 | char *file_name0 = argv[1]; 10 | char *file_name1 = argv[2]; 11 | Tensor A = read(file_name0, csr); 12 | Tensor B = read(file_name1, csr); 13 | 14 | Tensor x({A.getDimension(0), B.getDimension(1)}, csr); 15 | 16 | x.pack(); 17 | 18 | IndexVar i, j, k; 19 | x(i, j) = A(i, k) * B(k, j); 20 | 21 | x.compile(); 22 | 23 | auto t3 = std::chrono::high_resolution_clock::now(); 24 | x.assemble(); 25 | x.compute(); 26 | 27 | auto t4 = std::chrono::high_resolution_clock::now(); 28 | double compute_time = double(std::chrono::duration_cast(t4 - t3).count()) / 1000000; 29 | // std::cout << "Compute CSR SpGEMM time : " << compute_time << " seconds" << std::endl; 30 | std::cout << compute_time << " (s)" << std::endl; 31 | 32 | // write("y.tns", y); 33 | } 34 | -------------------------------------------------------------------------------- /evaluation/KernelGeneration/taco/taco_csr_spmm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "taco.h" 4 | using namespace taco; 5 | int main(int argc, char* argv[]) { 6 | std::default_random_engine gen(0); 7 | std::uniform_real_distribution unif(0.0, 1.0); 8 | Format csr({Dense, Sparse}); 9 | Format dm({Dense, Dense}); 10 | 11 | char *file_name = argv[1]; 12 | auto t1 = std::chrono::high_resolution_clock::now(); 13 | Tensor A = read(file_name, csr); 14 | auto t2 = std::chrono::high_resolution_clock::now(); 15 | double convert_time = double(std::chrono::duration_cast(t2 - t1).count()) / 1000000; 16 | // std::cout << "Convert to CSR time : " << convert_time << " seconds" << std::endl; 17 | 18 | Tensor x({A.getDimension(1), 1000}, dm); 19 | for (int i = 0; i < x.getDimension(0); ++i) { 20 | for(int j = 0; j < x.getDimension(1); ++j) { 21 | x.insert({i, j}, unif(gen)); 22 | } 23 | } 24 | x.pack(); 25 | 26 | Tensor y({A.getDimension(0), 1000}, dm); 27 | 28 | IndexVar i, j, k; 29 | y(i, j) = A(i, k) * x(k, j); 30 | 31 | y.compile(); 32 | y.assemble(); 33 | 34 | auto t3 = std::chrono::high_resolution_clock::now(); 35 | y.compute(); 36 | auto t4 = std::chrono::high_resolution_clock::now(); 37 | double compute_time = double(std::chrono::duration_cast(t4 - t3).count()) / 1000000; 38 | // std::cout << "Compute CSR SpMM time : " << compute_time << " seconds" << std::endl; 39 | std::cout << compute_time << " (s)" << std::endl; 40 | 41 | // write("y.tns", y); 42 | } 43 | -------------------------------------------------------------------------------- /evaluation/KernelGeneration/taco/taco_dcsc_spmm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "taco.h" 4 | using namespace taco; 5 | int main(int argc, char* argv[]) { 6 | std::default_random_engine gen(0); 7 | std::uniform_real_distribution unif(0.0, 1.0); 8 | Format dcsc({Sparse, Sparse},{1, 0}); 9 | Format dm({Dense, Dense}); 10 | 11 | char *file_name = argv[1]; 12 | auto t1 = std::chrono::high_resolution_clock::now(); 13 | Tensor A = read(file_name, dcsc); 14 | auto t2 = std::chrono::high_resolution_clock::now(); 15 | double convert_time = double(std::chrono::duration_cast(t2 - t1).count()) / 1000000; 16 | // std::cout << "Convert to DCSC time : " << convert_time << " seconds" << std::endl; 17 | 18 | Tensor x({A.getDimension(1), 1000}, dm); 19 | for (int i = 0; i < x.getDimension(0); ++i) { 20 | for(int j = 0; j < x.getDimension(1); ++j) { 21 | x.insert({i, j}, unif(gen)); 22 | } 23 | } 24 | x.pack(); 25 | 26 | Tensor y({A.getDimension(0), 1000}, dm); 27 | 28 | IndexVar i, j, k; 29 | y(i, j) = A(i, k) * x(k, j); 30 | 31 | y.compile(); 32 | y.assemble(); 33 | 34 | auto t3 = std::chrono::high_resolution_clock::now(); 35 | y.compute(); 36 | auto t4 = std::chrono::high_resolution_clock::now(); 37 | double compute_time = double(std::chrono::duration_cast(t4 - t3).count()) / 1000000; 38 | // std::cout << "Compute DCSC SpMM time : " << compute_time << " seconds" << std::endl; 39 | std::cout << compute_time << " (s)" << std::endl; 40 | 41 | // write("y1.tns", y); 42 | } 43 | -------------------------------------------------------------------------------- /evaluation/Reusability/executables/coo_bcsc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/Reusability/executables/coo_bcsc.o -------------------------------------------------------------------------------- /evaluation/Reusability/executables/csr_dia_v: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/Reusability/executables/csr_dia_v -------------------------------------------------------------------------------- /evaluation/Reusability/executables/csr_dia_v.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/Reusability/executables/csr_dia_v.o -------------------------------------------------------------------------------- /evaluation/Reusability/executables/unisparse_csc_spmm_F64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/Reusability/executables/unisparse_csc_spmm_F64 -------------------------------------------------------------------------------- /evaluation/Reusability/executables/unisparse_csc_spmm_F64.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/Reusability/executables/unisparse_csc_spmm_F64.o -------------------------------------------------------------------------------- /evaluation/Reusability/executables/unisparse_csr_csc_csc_spgemm_F64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/Reusability/executables/unisparse_csr_csc_csc_spgemm_F64 -------------------------------------------------------------------------------- /evaluation/Reusability/executables/unisparse_csr_csc_csc_spgemm_F64.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/evaluation/Reusability/executables/unisparse_csr_csc_csc_spgemm_F64.o -------------------------------------------------------------------------------- /evaluation/Reusability/output.log: -------------------------------------------------------------------------------- 1 | wiki-Vote_row_major.mtx 2 | CSR_DIA_V UniSparse 3 | 0.066685 4 | CSC_SpMM UniSparse 5 | 0.115291 6 | CSR_CSC_CSC_SpGEMM UniSparse 7 | 8.22384 8 | email-Eu-core_row_major.mtx 9 | CSR_DIA_V UniSparse 10 | 0.00568819 11 | CSC_SpMM UniSparse 12 | 0.0207629 13 | CSR_CSC_CSC_SpGEMM UniSparse 14 | 0.376283 15 | crystm02_row_major.mtx 16 | CSR_DIA_V UniSparse 17 | 0.007406 18 | CSC_SpMM UniSparse 19 | 0.146814 20 | CSR_CSC_CSC_SpGEMM UniSparse 21 | 26.8299 22 | nemeth21_row_major.mtx 23 | CSR_DIA_V UniSparse 24 | 0.0298648 25 | CSC_SpMM UniSparse 26 | 0.468524 27 | CSR_CSC_CSC_SpGEMM UniSparse 28 | 44.6911 -------------------------------------------------------------------------------- /evaluation/Reusability/run.sh: -------------------------------------------------------------------------------- 1 | # DATASET_PATH0=/install/datasets/row_major 2 | # DATASET_PATH1=/install/datasets/replicate 3 | # DATASETS=( 4 | # "wiki-Vote_row_major.mtx" 5 | # "email-Eu-core_row_major.mtx" 6 | # "crystm02_row_major.mtx" 7 | # "nemeth21_row_major.mtx" 8 | # ) 9 | 10 | mlir-opt unisparse_csr_dia_v.mlir -one-shot-bufferize="bufferize-function-boundaries=1 allow-return-allocs unknown-type-conversion=identity-layout-map function-boundary-type-conversion=identity-layout-map" -finalizing-bufferize -convert-linalg-to-loops -convert-vector-to-scf -convert-scf-to-cf -lower-affine -convert-vector-to-llvm -convert-memref-to-llvm -convert-complex-to-standard -convert-math-to-llvm -convert-math-to-libm -convert-complex-to-libm -convert-complex-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | mlir-translate -mlir-to-llvmir | opt -O3 -S | llc -O3 -relocation-model=pic -filetype=obj -o csr_dia_v.o 11 | clang++ csr_dia_v.o -L$SPLHOME/build/lib -lmlir_unisparse_runner_utils -L$LLVM_ROOT/build/lib -lmlir_runner_utils -lmlir_c_runner_utils -o csr_dia_v 12 | unisparse-opt ./unisparse_csc_spmm_F64.mlir -unisparse-codegen -lower-format-conversion -lower-struct -dce | mlir-opt -one-shot-bufferize="bufferize-function-boundaries=1 allow-return-allocs unknown-type-conversion=identity-layout-map function-boundary-type-conversion=identity-layout-map" -finalizing-bufferize -convert-linalg-to-loops -convert-vector-to-scf -convert-scf-to-cf -lower-affine -convert-vector-to-llvm -convert-memref-to-llvm -convert-complex-to-standard -convert-math-to-llvm -convert-math-to-libm -convert-complex-to-libm -convert-complex-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | mlir-translate -mlir-to-llvmir | opt -O3 -S | llc -O3 -relocation-model=pic -filetype=obj -o unisparse_csc_spmm_F64.o 13 | clang++ unisparse_csc_spmm_F64.o -L$SPLHOME/build/lib -lmlir_unisparse_runner_utils -L$LLVM_ROOT/build/lib -lmlir_runner_utils -lmlir_c_runner_utils -o unisparse_csc_spmm_F64 14 | unisparse-opt ./unisparse_csr_csc_csc_spgemm_F64.mlir -unisparse-codegen -lower-format-conversion -lower-struct -dce | mlir-opt -one-shot-bufferize="bufferize-function-boundaries=1 allow-return-allocs unknown-type-conversion=identity-layout-map function-boundary-type-conversion=identity-layout-map" -finalizing-bufferize -convert-linalg-to-loops -convert-vector-to-scf -convert-scf-to-cf -lower-affine -convert-vector-to-llvm -convert-memref-to-llvm -convert-complex-to-standard -convert-math-to-llvm -convert-math-to-libm -convert-complex-to-libm -convert-complex-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | mlir-translate -mlir-to-llvmir | opt -O3 -S | llc -O3 -relocation-model=pic -filetype=obj -o unisparse_csr_csc_csc_spgemm_F64.o 15 | clang++ unisparse_csr_csc_csc_spgemm_F64.o -L$SPLHOME/build/lib -lmlir_unisparse_runner_utils -L$LLVM_ROOT/build/lib -lmlir_runner_utils -lmlir_c_runner_utils -o unisparse_csr_csc_csc_spgemm_F64 16 | 17 | # for dataset in "${DATASETS[@]}" 18 | # do 19 | # echo $dataset 20 | # export TENSOR0=$DATASET_PATH/$dataset 21 | 22 | # echo CSR_DIA_V UniSparse 23 | # ./csr_dia_v 24 | 25 | # echo CSC_SpMM UniSparse 26 | # ./unisparse_csc_spmm_F64 27 | 28 | # echo CSR_CSC_CSC_SpGEMM UniSparse 29 | # ./unisparse_csr_csc_csc_spgemm_F64 30 | 31 | 32 | # done 33 | 34 | -------------------------------------------------------------------------------- /include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /include/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect(UniSparseOps unisparse) 2 | add_mlir_doc(UniSparseDialect UniSparseDialect IR/ -gen-dialect-doc) 3 | add_mlir_doc(UniSparseOps UniSparseOps IR/ -gen-op-doc) 4 | 5 | 6 | set(LLVM_TARGET_DEFINITIONS UniSparseAttr.td) 7 | mlir_tablegen(UniSparseAttr.h.inc -gen-attrdef-decls) 8 | mlir_tablegen(UniSparseAttr.cpp.inc -gen-attrdef-defs) 9 | add_public_tablegen_target(MLIRUniSparseAttrIncGen) -------------------------------------------------------------------------------- /include/IR/UniSparseAttr.h: -------------------------------------------------------------------------------- 1 | #ifndef UNISPARSE_UNISPARSEATTR_H 2 | #define UNISPARSE_UNISPARSEATTR_H 3 | 4 | #include "mlir/IR/BuiltinTypes.h" 5 | #include "mlir/IR/Dialect.h" 6 | #include "mlir/IR/TensorEncoding.h" 7 | #include "IR/UniSparseAffineMap.h" 8 | 9 | #define GET_ATTRDEF_CLASSES 10 | #include "IR/UniSparseAttr.h.inc" 11 | 12 | 13 | 14 | #endif -------------------------------------------------------------------------------- /include/IR/UniSparseAttr.td: -------------------------------------------------------------------------------- 1 | //===-- SparseTensorAttrDefs.td - attributes definitions ---*- tablegen -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef UNISPARSE_ATTR 10 | #define UNISPARSE_ATTR 11 | 12 | include "UniSparseDialect.td" 13 | include "mlir/IR/AttrTypeBase.td" 14 | include "mlir/IR/TensorEncoding.td" 15 | 16 | // All of the Tensor attributes will extend this class. 17 | class UniSparse_Attr traits = []> 18 | : AttrDef; 19 | 20 | def UniSparseCompressAttr : UniSparse_Attr<"UniSparseCompress", []> { 21 | let mnemonic = "compress"; 22 | let hasCustomAssemblyFormat = 1; 23 | let parameters = (ins "CompressMap":$value); 24 | } 25 | 26 | def UniSparseCrdAttr : UniSparse_Attr<"UniSparseCrd", []> { 27 | let mnemonic = "crd"; 28 | let hasCustomAssemblyFormat = 1; 29 | let parameters = (ins "CrdMap": $value); 30 | } 31 | 32 | def UniSparseSumAttr : UniSparse_Attr<"UniSparseSum", []> { 33 | let mnemonic = "sum"; 34 | let hasCustomAssemblyFormat = 1; 35 | let parameters = (ins "SumPrim": $value); 36 | } 37 | 38 | def UniSparseEnumerateAttr : UniSparse_Attr<"UniSparseEnumerate", []> { 39 | let mnemonic = "enumerate"; 40 | let hasCustomAssemblyFormat = 1; 41 | let parameters = (ins "EnumeratePrim": $value); 42 | } 43 | 44 | def UniSparseScheduleAttr : UniSparse_Attr<"UniSparseSchedule", []> { 45 | let mnemonic = "schedule"; 46 | let hasCustomAssemblyFormat = 1; 47 | let parameters = (ins "SchedulePrim": $value); 48 | } 49 | 50 | def UniSparseReorderAttr : UniSparse_Attr<"UniSparseReorder", []> { 51 | let mnemonic = "reorder"; 52 | let hasCustomAssemblyFormat = 1; 53 | let parameters = (ins "ReorderPrim": $value); 54 | } 55 | 56 | def UniSparseIndirectAttr : UniSparse_Attr<"UniSparseIndirect", []> { 57 | let mnemonic = "indirect"; 58 | let hasCustomAssemblyFormat = 1; 59 | let parameters = ( 60 | ins 61 | "SumPrim": $sumVal, 62 | "EnumeratePrim": $enumVal, 63 | "SchedulePrim": $schedVal, 64 | "ReorderPrim": $reorderVal 65 | ); 66 | } 67 | 68 | def UniSparseLayoutAttr : UniSparse_Attr<"UniSparseLayout", []> { 69 | let mnemonic = "layout"; 70 | let hasCustomAssemblyFormat = 1; 71 | let parameters = (ins "LayoutPrim":$value); 72 | } 73 | 74 | // Sparse tensor encoding attribute. 75 | def UniSparseEncodingAttr : UniSparse_Attr<"UniSparseEncoding", 76 | [DeclareAttrInterfaceMethods]> { 77 | let mnemonic = "encoding"; 78 | let hasCustomAssemblyFormat = 1; 79 | 80 | let description = [{ 81 | Tree-base encoding for Sparse Tensor Layout 82 | 83 | Example: 84 | 85 | ```mlir 86 | #1 = #unisparse.encoding<{ 87 | compressMap = #unisparse.compress, 88 | crdMap = #unisparse.crd<(i,j,k)[s0,s1] -> ((i+j minus s0)*4 mod 7, (k + (minus i)) floordiv s1)> 89 | bitwidth = 8 90 | }> 91 | 92 | !unisparse.tensor 93 | ``` 94 | }]; 95 | 96 | // Data in sparse tensor encoding. 97 | let parameters = ( 98 | ins 99 | "CrdMap":$crdMap, 100 | "CompressMap":$compressMap, 101 | "unsigned":$bitWidth, 102 | "IndirectFunc": $indirectFunc, 103 | "LayoutPrim": $layout 104 | ); 105 | 106 | let genVerifyDecl = 1; 107 | } 108 | 109 | #endif // UNISPARSE_ATTRS -------------------------------------------------------------------------------- /include/IR/UniSparseDialect.h: -------------------------------------------------------------------------------- 1 | //===- UniSparseDialect.h - UniSparse dialect -----------------*- C++ -*-===// 2 | // 3 | // This file is licensed under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef UNISPARSE_UNISPARSEDIALECT_H 10 | #define UNISPARSE_UNISPARSEDIALECT_H 11 | 12 | #include "mlir/IR/Dialect.h" 13 | 14 | #include "mlir/IR/BuiltinOps.h" 15 | #include "mlir/IR/BuiltinTypes.h" 16 | #include "mlir/Interfaces/CastInterfaces.h" 17 | #include "mlir/Interfaces/SideEffectInterfaces.h" 18 | 19 | 20 | #include "IR/UniSparseOpsDialect.h.inc" 21 | 22 | #include "IR/UniSparseAttr.h" 23 | 24 | namespace mlir { 25 | namespace unisparse { 26 | UniSparseEncodingAttr getUniSparseEncoding(Type type); 27 | } 28 | } 29 | 30 | 31 | #endif // UNISPARSE_UNISPARSEDIALECT_H 32 | -------------------------------------------------------------------------------- /include/IR/UniSparseDialect.td: -------------------------------------------------------------------------------- 1 | //===- UniSparseDialect.td - UniSparse dialect -----------*- tablegen -*-===// 2 | // 3 | // This file is licensed under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef UNISPARSE_DIALECT 10 | #define UNISPARSE_DIALECT 11 | 12 | include "mlir/IR/OpBase.td" 13 | 14 | include "mlir/Interfaces/CallInterfaces.td" 15 | include "mlir/Interfaces/CastInterfaces.td" 16 | include "mlir/Interfaces/SideEffectInterfaces.td" 17 | 18 | //===----------------------------------------------------------------------===// 19 | // UniSparse dialect definition. 20 | //===----------------------------------------------------------------------===// 21 | 22 | def UniSparse_Dialect : Dialect { 23 | let name = "unisparse"; 24 | let summary = "A unisparse out-of-tree MLIR dialect."; 25 | let description = [{ 26 | This dialect is an example of an out-of-tree MLIR dialect designed to 27 | illustrate the basic setup required to develop MLIR-based tools without 28 | working inside of the LLVM source tree. 29 | }]; 30 | let cppNamespace = "::mlir::unisparse"; 31 | let extraClassDeclaration = [{ 32 | void registerTypes(); 33 | }]; 34 | let useDefaultAttributePrinterParser = 1; 35 | let useDefaultTypePrinterParser = 1; 36 | } 37 | 38 | //===----------------------------------------------------------------------===// 39 | // Base unisparse type definition. 40 | //===----------------------------------------------------------------------===// 41 | 42 | def UniSparse_StructType : 43 | DialectType()">, 44 | "UniSparse struct type">; 45 | 46 | def UniSparse_Type : AnyTypeOf<[AnyType, AnyTensor, AnyMemRef, UniSparse_StructType]>; 47 | 48 | #endif // UNISPARSE_DIALECT 49 | -------------------------------------------------------------------------------- /include/IR/UniSparseOps.h: -------------------------------------------------------------------------------- 1 | //===- UniSparseOps.h - UniSparse dialect ops -----------------*- C++ -*-===// 2 | // 3 | // This file is licensed under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef UNISPARSE_UNISPARSEOPS_H 10 | #define UNISPARSE_UNISPARSEOPS_H 11 | 12 | #include "mlir/IR/BuiltinTypes.h" 13 | #include "mlir/IR/Dialect.h" 14 | #include "mlir/IR/OpDefinition.h" 15 | #include "mlir/Interfaces/InferTypeOpInterface.h" 16 | #include "mlir/Interfaces/SideEffectInterfaces.h" 17 | #include "mlir/IR/OpImplementation.h" 18 | 19 | #define GET_OP_CLASSES 20 | #include "IR/UniSparseOps.h.inc" 21 | 22 | #endif // UNISPARSE_UNISPARSEOPS_H 23 | -------------------------------------------------------------------------------- /include/IR/UniSparseParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "mlir/IR/AffineMap.h" 4 | #include "mlir/IR/DialectImplementation.h" 5 | #include "mlir/IR/OpImplementation.h" 6 | 7 | #include "AsmParser/Parser.h" 8 | #include "AsmParser/Token.h" 9 | #include 10 | 11 | using namespace mlir; 12 | 13 | namespace mlir { 14 | 15 | namespace unisparse { 16 | 17 | namespace parser { 18 | 19 | #define suc(A) succeeded(A) 20 | 21 | enum AffineLowPrecOp { 22 | /// Null value. 23 | LNoOp, 24 | Add, 25 | Sub 26 | }; 27 | 28 | enum AffineHighPrecOp { 29 | /// Null value. 30 | HNoOp, 31 | Mul, 32 | FloorDiv, 33 | CeilDiv, 34 | Mod 35 | }; 36 | 37 | AffineExpr parseAffineExpr(AsmParser& parser); 38 | 39 | AffineMap parseAffineMapWithKeyword(AsmParser& parser, const ArrayRef& opTokens, 40 | std::vector< std::vector >& vis, 41 | std::vector< std::vector >& indirectExpr 42 | ); 43 | 44 | 45 | } 46 | 47 | } //end of namespace unisparse 48 | } //end of namespace mlir -------------------------------------------------------------------------------- /include/IR/UniSparseTypes.h: -------------------------------------------------------------------------------- 1 | //===- UniSparseTypes.h - UniSparse Type Classes --------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef UNISPARSE_UNISPARSETYPES_H 10 | #define UNISPARSE_UNISPARSETYPES_H 11 | 12 | #include "mlir/IR/Types.h" 13 | 14 | //===----------------------------------------------------------------------===// 15 | // UniSparse Types 16 | //===----------------------------------------------------------------------===// 17 | namespace mlir { 18 | namespace unisparse { 19 | 20 | namespace detail { 21 | struct StructTypeStorage; 22 | } // end namespace detail 23 | 24 | //===----------------------------------------------------------------------===// 25 | // UniSparse Types 26 | //===----------------------------------------------------------------------===// 27 | 28 | /// This class defines the Toy struct type. It represents a collection of 29 | /// element types. All derived types in MLIR must inherit from the CRTP class 30 | /// 'Type::TypeBase'. It takes as template parameters the concrete type 31 | /// (StructType), the base class to use (Type), and the storage class 32 | /// (StructTypeStorage). 33 | class StructType : public mlir::Type::TypeBase { 35 | public: 36 | /// Inherit some necessary constructors from 'TypeBase'. 37 | using Base::Base; 38 | 39 | /// Create an instance of a `StructType` with the given element types. There 40 | /// *must* be atleast one element type. 41 | static StructType get(llvm::ArrayRef dimSizes, 42 | llvm::ArrayRef elementTypes, 43 | llvm::StringRef identifier, 44 | llvm::ArrayRef order); 45 | llvm::ArrayRef getDimSizes(); 46 | 47 | /// Returns the element types of this struct type. 48 | llvm::ArrayRef getElementTypes(); 49 | 50 | llvm::StringRef getIdentifier(); 51 | 52 | llvm::ArrayRef getOrder(); 53 | 54 | /// Returns the number of element type held by this struct. 55 | size_t getNumElementTypes() { return getElementTypes().size(); } 56 | }; 57 | } // end namespace unisparse 58 | } // end namespace mlir 59 | 60 | #define GET_TYPEDEF_CLASSES 61 | #include "IR/UniSparseOpsTypes.h.inc" 62 | 63 | #endif // UNISPARSE_UNISPARSETYPES_H 64 | -------------------------------------------------------------------------------- /include/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name Transforms) 3 | add_public_tablegen_target(MLIRUniSparseTransformsIncGen) 4 | 5 | add_mlir_doc(Passes TransformsPasses Transforms/ -gen-pass-doc) 6 | -------------------------------------------------------------------------------- /include/Transforms/Passes.h: -------------------------------------------------------------------------------- 1 | //===- Passes.h - Pass Entrypoints ------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // 9 | // This header file defines a set of transforms specific for the UniSparse 10 | // dialect. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef UNISPARSE_TRANSFORMS_PASSES_H 15 | #define UNISPARSE_TRANSFORMS_PASSES_H 16 | 17 | #include "mlir/Pass/Pass.h" 18 | 19 | namespace mlir { 20 | 21 | class AffineDialect; 22 | 23 | namespace arith { 24 | class ArithmeticDialect; 25 | } 26 | 27 | namespace bufferization { 28 | class BufferizationDialect; 29 | } 30 | 31 | namespace func { 32 | class FuncDialect; 33 | } 34 | 35 | namespace memref { 36 | class MemRefDialect; 37 | } 38 | 39 | namespace scf { 40 | class SCFDialect; 41 | } 42 | 43 | namespace vector { 44 | class VectorDialect; 45 | } 46 | 47 | namespace linalg { 48 | class LinalgDialect; 49 | } 50 | 51 | namespace LLVM { 52 | class LLVMDialect; 53 | } 54 | 55 | namespace unisparse { 56 | 57 | void populateUniSparseCodegenPatterns(RewritePatternSet &patterns); 58 | 59 | std::unique_ptr createDeadCodeEliminationPass(); 60 | std::unique_ptr createLowerStructConvertPass(); 61 | std::unique_ptr createLowerFormatConversionPass(); 62 | std::unique_ptr createLowerStructPass(); 63 | std::unique_ptr createUniSparseCodegenPass(); 64 | std::unique_ptr createTmpGenBuffer(); 65 | 66 | 67 | 68 | //===----------------------------------------------------------------------===// 69 | // Registration 70 | //===----------------------------------------------------------------------===// 71 | 72 | /// Generate the code for registering passes. 73 | #define GEN_PASS_REGISTRATION 74 | #include "Transforms/Passes.h.inc" 75 | 76 | } // namespace unisparse 77 | } // namespace mlir 78 | 79 | #endif // UNISPARSE_TRANSFORMS_PASSES_H 80 | -------------------------------------------------------------------------------- /include/Transforms/Passes.td: -------------------------------------------------------------------------------- 1 | //===-- Passes.td - UniSparse pass definition file -----------*- tablegen -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // 9 | // This file contains definitions for passes within the UniSparse/ directory. 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #ifndef MLIR_DIALECT_UNISPARSE_PASSES 14 | #define MLIR_DIALECT_UNISPARSE_PASSES 15 | 16 | include "mlir/Pass/PassBase.td" 17 | 18 | def LowerFormatConversion : Pass<"lower-format-conversion", "func::FuncOp"> { 19 | let summary = "Lower operations for format conversion"; 20 | let constructor = "mlir::unisparse::createLowerFormatConversionPass()"; 21 | let dependentDialects = [ 22 | "arith::ArithmeticDialect", 23 | "func::FuncDialect", 24 | "memref::MemRefDialect", 25 | "scf::SCFDialect", 26 | "vector::VectorDialect", 27 | "linalg::LinalgDialect", 28 | "LLVM::LLVMDialect" 29 | ]; 30 | } 31 | 32 | def LowerStruct : Pass<"lower-struct", "func::FuncOp"> { 33 | let summary = "Lower struct conversion"; 34 | let constructor = "mlir::unisparse::createLowerStructPass()"; 35 | } 36 | 37 | def LowerStructConvert: Pass<"lower-struct-convert", "func::FuncOp"> { 38 | let summary = "Lower Struct Convert conversion"; 39 | let constructor = "mlir::unisparse::createLowerStructConvertPass()"; 40 | let dependentDialects = [ 41 | "arith::ArithmeticDialect", 42 | "func::FuncDialect", 43 | "UniSparseDialect" 44 | ]; 45 | } 46 | 47 | def DeadCodeElimination : Pass<"dce", "func::FuncOp"> { 48 | let summary = "dead code elimination"; 49 | let constructor = "mlir::unisparse::createDeadCodeEliminationPass()"; 50 | } 51 | 52 | def UniSparseCodegen : Pass<"unisparse-codegen"> { 53 | let summary = "Automatically generate sparse tensor code from unisparse sparse tensor types"; 54 | let constructor = "mlir::unisparse::createUniSparseCodegenPass()"; 55 | let dependentDialects = [ 56 | "AffineDialect", 57 | "bufferization::BufferizationDialect", 58 | "memref::MemRefDialect", 59 | "scf::SCFDialect", 60 | "unisparse::UniSparseDialect", 61 | "vector::VectorDialect" 62 | ]; 63 | } 64 | 65 | #endif // MLIR_DIALECT_UNISPARSE_PASSES 66 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | ## Copyright UniSparse authors. All Rights Reserved. 2 | 3 | ## Install Eigen library 4 | wget https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz -P $EIGEN_PATH 5 | cd $EIGEN_PATH && tar -xzf eigen-3.4.0.tar.gz 6 | 7 | ## Install LLVM/MLIR 8 | git clone --depth 1 --branch llvmorg-15.0.0 https://github.com/llvm/llvm-project.git $LLVM_PATH/llvm-project 9 | mkdir -p $LLVM_PATH/llvm_project/build && cd $LLVM_PATH/llvm_project/build 10 | cmake ../llvm -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" \ 11 | -DLLVM_BUILD_EXAMPLES=ON -DLLVM_TARGETS_TO_BUILD="host;NVPTX" \ 12 | -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON \ 13 | -DLLVM_INSTALL_UTILS=ON -DLLVM_BUILD_UTILS=ON \ 14 | -DLLVM_USE_LINKER=lld -DMLIR_INCLUDE_INTEGRATION_TESTS=ON \ 15 | -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ 16 | cmake --build . -j $(nproc) 17 | 18 | ## OpenMp 19 | cd $LLVM_PATH/llvm_project/openmp && \ 20 | mkdir build && cd build && \ 21 | cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ .. 22 | make -j $(nproc) 23 | export CPATH=$LLVM_PATH/llvm_project/openmp/build/runtime/src:$CPATH 24 | export LD_LIBRARY_PATH=$LLVM_PATH/llvm_project/openmp/build/runtime/src:$LD_LIBRARY_PATH 25 | 26 | ## Install UniSparse 27 | mkdir -p $UniSparse_PATH/UniSparse/build && cd $UniSparse_PATH/UniSparse/build 28 | cmake .. \ 29 | -DMLIR_DIR=$LLVM_PATH/llvm_project/build/lib/cmake/mlir \ 30 | -DLLVM_EXTERNAL_LIT=$LLVM_PATH/llvm_project/build/bin/llvm-lit \ 31 | -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ 32 | cmake --build . -j $(nproc) 33 | export LD_LIBRARY_PATH=$UniSparse_PATH/UniSparse/build/lib:$LD_LIBRARY_PATH 34 | export PATH=$UniSparse_PATH/UniSparse/build/bin:$PATH 35 | 36 | 37 | -------------------------------------------------------------------------------- /lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | add_subdirectory(Runtime) 4 | -------------------------------------------------------------------------------- /lib/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MLIRUniSparse 2 | UniSparseDialect.cpp 3 | UniSparseOps.cpp 4 | UniSparseTypes.cpp 5 | UniSparseParser.cpp 6 | 7 | ADDITIONAL_HEADER_DIRS 8 | ${PROJECT_SOURCE_DIR}/include/IR 9 | 10 | DEPENDS 11 | MLIRUniSparseOpsIncGen 12 | MLIRUniSparseAttrIncGen 13 | 14 | LINK_LIBS PUBLIC 15 | MLIRIR 16 | MLIRDialect 17 | MLIRParser 18 | MLIRInferTypeOpInterface 19 | MLIRSupport 20 | ) 21 | -------------------------------------------------------------------------------- /lib/IR/UniSparseOps.cpp: -------------------------------------------------------------------------------- 1 | //===- UniSparseOps.cpp - UniSparse dialect ops ---------------*- C++ -*-===// 2 | // 3 | // This file is licensed under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #include "IR/UniSparseOps.h" 10 | #include "IR/UniSparseDialect.h" 11 | #include "IR/UniSparseTypes.h" 12 | 13 | #include "mlir/IR/DialectImplementation.h" 14 | #include "mlir/IR/FunctionImplementation.h" 15 | #include "mlir/IR/OpImplementation.h" 16 | #include "mlir/IR/Dialect.h" 17 | #include "mlir/IR/Builders.h" 18 | #include "mlir/IR/OpDefinition.h" 19 | #include "mlir/IR/BuiltinTypes.h" 20 | #include "mlir/IR/AffineMap.h" 21 | #include "mlir/Transforms/InliningUtils.h" 22 | 23 | using namespace mlir; 24 | using namespace mlir::unisparse; 25 | 26 | //===----------------------------------------------------------------------===// 27 | // UniSparse Operations 28 | //===----------------------------------------------------------------------===// 29 | 30 | //===----------------------------------------------------------------------===// 31 | // StructAccessOp 32 | 33 | void StructAccessOp::build(mlir::OpBuilder &b, mlir::OperationState &state, 34 | mlir::Value input, size_t index) { 35 | // Extract the result type from the input type. 36 | StructType structTy = input.getType().cast(); 37 | assert(index < structTy.getNumElementTypes()); 38 | mlir::Type resultType = structTy.getElementTypes()[index]; 39 | 40 | // Call into the auto-generated build method. 41 | build(b, state, resultType, input, b.getI64IntegerAttr(index)); 42 | } 43 | 44 | mlir::LogicalResult StructAccessOp::verify() { 45 | StructType structTy = this->input().getType().cast(); 46 | size_t index = this->index(); 47 | if (index >= structTy.getNumElementTypes()) 48 | return emitOpError() 49 | << "index should be within the range of the input struct type"; 50 | mlir::Type resultType = getResult().getType(); 51 | if (resultType != structTy.getElementTypes()[index]) 52 | return emitOpError() << "must have the same result type as the struct " 53 | "element referred to by the index"; 54 | return mlir::success(); 55 | } 56 | 57 | /// Fold simple struct access operations that access into a constant. 58 | OpFoldResult StructAccessOp::fold(ArrayRef operands) { 59 | auto structAttr = operands.front().dyn_cast_or_null(); 60 | if (!structAttr) 61 | return nullptr; 62 | 63 | size_t elementIndex = index(); 64 | return structAttr[elementIndex]; 65 | } 66 | 67 | #define GET_OP_CLASSES 68 | #include "IR/UniSparseOps.cpp.inc" 69 | -------------------------------------------------------------------------------- /lib/Runtime/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_OPTIONAL_SOURCES 2 | UniSparseUtils.cpp 3 | ) 4 | 5 | get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) 6 | 7 | find_package(OpenMP REQUIRED) 8 | # find_package(CUDA REQUIRED) 9 | 10 | include(CheckLanguage) 11 | # check_language(CUDA) 12 | # if (CMAKE_CUDA_COMPILER) 13 | # enable_language(CUDA) 14 | # else() 15 | # message(SEND_ERROR 16 | # "Building the mlir cuda runner requires a working CUDA install") 17 | # endif() 18 | 19 | # We need the libcuda.so library. 20 | # find_library(CUDA_LIBRARIES cuda REQUIRED) 21 | # find_library(CUDA_cusparse_LIBRARY cuda REQUIRED) 22 | 23 | add_mlir_library(mlir_unisparse_runner_utils 24 | SHARED 25 | UniSparseUtils.cpp 26 | 27 | EXCLUDE_FROM_LIBMLIR 28 | ) 29 | 30 | set_property(TARGET mlir_unisparse_runner_utils PROPERTY CXX_STANDARD 14) 31 | target_compile_definitions(mlir_unisparse_runner_utils PRIVATE mlir_unisparse_runner_utils_EXPORTS) 32 | # target_include_directories(mlir_unisparse_runner_utils PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) 33 | # target_link_libraries(mlir_unisparse_runner_utils PRIVATE OpenMP::OpenMP_CXX PRIVATE ${CUDA_LIBRARIES} PRIVATE ${CUDA_cusparse_LIBRARY}) 34 | -------------------------------------------------------------------------------- /lib/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MLIRUniSparseTransforms 2 | 3 | LowerFormatConversionPass.cpp 4 | LowerStructPass.cpp 5 | DeadCodeEliminationPass.cpp 6 | UniSparseCodegen.cpp 7 | LowerStructConvert.cpp 8 | 9 | ADDITIONAL_HEADER_DIRS 10 | ${PROJECT_SOURCE_DIR}/include/Transforms 11 | ${PROJECT_SOURCE_DIR}/include/IR 12 | 13 | DEPENDS 14 | MLIRUniSparseOpsIncGen 15 | MLIRUniSparseAttrIncGen 16 | MLIRUniSparseTransformsIncGen 17 | 18 | LINK_LIBS PUBLIC 19 | MLIRIR 20 | MLIRPass 21 | MLIRSideEffectInterfaces 22 | MLIRTransformUtils 23 | MLIRVectorToLLVM 24 | MLIRUniSparse 25 | ) 26 | -------------------------------------------------------------------------------- /lib/Transforms/DeadCodeEliminationPass.cpp: -------------------------------------------------------------------------------- 1 | //===- DeadCodeEliminationPass.cpp --- Lower Format Conversion pass ------------*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // 9 | // This file implements a pass to tile loop nests. 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | #include "mlir/IR/AffineMap.h" 14 | #include "mlir/IR/Builders.h" 15 | #include "mlir/Pass/Pass.h" 16 | #include "mlir/IR/BuiltinTypes.h" 17 | #include "mlir/Dialect/Func/IR/FuncOps.h" 18 | #include "mlir/Transforms/DialectConversion.h" 19 | #include "mlir/Transforms/GreedyPatternRewriteDriver.h" 20 | #include "mlir/Interfaces/InferTypeOpInterface.h" 21 | #include "llvm/Support/CommandLine.h" 22 | #include "llvm/Support/Debug.h" 23 | #include "llvm/Support/raw_ostream.h" 24 | 25 | #include "Transforms/Passes.h" 26 | #include "IR/UniSparseDialect.h" 27 | #include "IR/UniSparseOps.h" 28 | #include "IR/UniSparseDialect.h" 29 | #include "IR/UniSparseTypes.h" 30 | 31 | #include 32 | #include 33 | 34 | using namespace mlir; 35 | using namespace unisparse; 36 | 37 | #define DEBUG_TYPE "dce" 38 | 39 | namespace { 40 | 41 | #define GEN_PASS_CLASSES 42 | #include "Transforms/Passes.h.inc" 43 | 44 | //===----------------------------------------------------------------------===// 45 | // DeadCodeEliminationPass 46 | //===----------------------------------------------------------------------===// 47 | class DeadCodeElimination : public OpRewritePattern { 48 | public: 49 | using OpRewritePattern::OpRewritePattern; 50 | 51 | LogicalResult 52 | matchAndRewrite(unisparse::StructConstructOp op, PatternRewriter &rewriter) const override { 53 | rewriter.eraseOp(op); 54 | return success(); 55 | } 56 | }; 57 | 58 | struct DeadCodeEliminationPass : 59 | public DeadCodeEliminationBase { 60 | 61 | void runOnOperation() override { 62 | 63 | func::FuncOp function = getOperation(); 64 | MLIRContext *ctx = function.getContext(); 65 | RewritePatternSet patterns(ctx); 66 | patterns.add(&getContext()); 67 | ConversionTarget target(getContext()); 68 | target.addIllegalOp(); 69 | if (failed( 70 | applyPartialConversion(getOperation(), target, std::move(patterns)))) 71 | signalPassFailure(); 72 | }; 73 | 74 | }; 75 | } 76 | 77 | std::unique_ptr mlir::unisparse::createDeadCodeEliminationPass() { 78 | return std::make_unique(); 79 | } 80 | -------------------------------------------------------------------------------- /lib/Transforms/LowerStructConvert.cpp: -------------------------------------------------------------------------------- 1 | #include "mlir/IR/AffineMap.h" 2 | #include "mlir/IR/Builders.h" 3 | #include "mlir/IR/BuiltinTypes.h" 4 | #include "mlir/Pass/Pass.h" 5 | #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" 6 | #include "mlir/Dialect/Func/IR/FuncOps.h" 7 | #include "mlir/Dialect/LLVMIR/LLVMDialect.h" 8 | #include "mlir/Transforms/DialectConversion.h" 9 | #include "mlir/Interfaces/InferTypeOpInterface.h" 10 | #include "llvm/Support/CommandLine.h" 11 | #include "llvm/Support/Debug.h" 12 | #include "llvm/Support/raw_ostream.h" 13 | 14 | #include "IR/UniSparseDialect.h" 15 | #include "IR/UniSparseOps.h" 16 | #include "IR/UniSparseTypes.h" 17 | #include "Transforms/Passes.h" 18 | 19 | #include 20 | #include 21 | 22 | using namespace mlir; 23 | using namespace unisparse; 24 | 25 | namespace { 26 | #define GEN_PASS_CLASSES 27 | #include "Transforms/Passes.h.inc" 28 | 29 | class StructConvertOpLowering : public OpConversionPattern { 30 | public: 31 | using OpConversionPattern::OpConversionPattern; 32 | 33 | LogicalResult matchAndRewrite(unisparse::StructConvertOp op, OpAdaptor adaptor, 34 | ConversionPatternRewriter &rewriter) const final { 35 | Location loc = op->getLoc(); 36 | //access all element 37 | Value input = op->getOperand(0); 38 | Value output = op->getResult(0); 39 | auto inputType = input.getType().dyn_cast(); 40 | auto outputType = output.getType().dyn_cast(); 41 | llvm::ArrayRef inputElmTypes = inputType.getElementTypes(); 42 | llvm::ArrayRef outputElmTypes = outputType.getElementTypes(); 43 | uint64_t inputSize = inputElmTypes.size(); 44 | uint64_t outputSize = outputElmTypes.size(); 45 | assert(inputSize == outputSize); 46 | std::vector inputValues; 47 | for (uint64_t i = 0; i < inputSize; ++i) { 48 | inputValues.push_back(rewriter.create(loc,inputElmTypes[i],input,i)); 49 | } 50 | std::vector outputValues; 51 | //convert 52 | for (size_t i = 0; i < inputValues.size(); ++i) { 53 | outputValues.push_back(rewriter.create(loc, outputElmTypes[i], inputValues[i])); 54 | } 55 | //construct a new struct 56 | Value outStruct = rewriter.create(loc, outputType, llvm::makeArrayRef(outputValues)); 57 | rewriter.replaceOp(op, outStruct); 58 | return success(); 59 | } 60 | 61 | }; 62 | 63 | struct LowerStructConvertPass : 64 | public LowerStructConvertBase { 65 | void runOnOperation() final { 66 | ConversionTarget target(getContext()); 67 | target.addLegalDialect< 68 | arith::ArithmeticDialect, LLVM::LLVMDialect, 69 | func::FuncDialect, unisparse::UniSparseDialect 70 | >(); 71 | target.addIllegalOp(); 72 | RewritePatternSet patterns(&getContext()); 73 | patterns.add(&getContext()); 74 | func::FuncOp curOp = getOperation(); 75 | if ( 76 | failed(applyPartialConversion(curOp, target, std::move(patterns))) 77 | ) { 78 | signalPassFailure(); 79 | } 80 | } 81 | }; 82 | 83 | } //end of anonymus namespace 84 | 85 | std::unique_ptr mlir::unisparse::createLowerStructConvertPass() { 86 | return std::make_unique(); 87 | } 88 | -------------------------------------------------------------------------------- /scripts/bin-path.sh: -------------------------------------------------------------------------------- 1 | export LD_LIBRARY_PATH=$PWD/build/lib:$LD_LIBRARY_PATH 2 | export PATH=$PWD/build/bin:$PATH 3 | export SPLHOME=$PWD -------------------------------------------------------------------------------- /scripts/build.sh: -------------------------------------------------------------------------------- 1 | export LLVM_ROOT=/install/llvm-project 2 | export PATH=$LLVM_ROOT/build/bin:$PATH 3 | export LD_LIBRARY_PATH=$LLVM_ROOT/build/lib:$LD_LIBRARY_PATH 4 | export CPATH=$HOME/eigen-3.4.0:$HOME/llvm-project/mlir/lib:$HOME/llvm-project/mlir/include/mlir:$CPATH 5 | export CPATH=$LLVM_ROOT/openmp/build/runtime/src:$CPATH 6 | export LD_LIBRARY_PATH=$LLVM_ROOT/openmp/build/runtime/src:$LD_LIBRARY_PATH 7 | export LD_LIBRARY_PATH=/install/taco/build/lib:$LD_LIBRARY_PATH 8 | 9 | mkdir -p build && cd build 10 | cmake .. \ 11 | -DMLIR_DIR=$LLVM_ROOT/build/lib/cmake/mlir \ 12 | -DLLVM_EXTERNAL_LIT=$LLVM_ROOT/build/bin/llvm-lit \ 13 | -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ && \ 14 | cmake --build . 15 | 16 | export SPLHOME=/install/UniSparse 17 | export LD_LIBRARY_PATH=/install/UniSparse/build/lib:$LD_LIBRARY_PATH 18 | export PATH=/install/UniSparse/build/bin:$PATH 19 | 20 | cd .. 21 | 22 | -------------------------------------------------------------------------------- /scripts/cmake-config.sh: -------------------------------------------------------------------------------- 1 | cmake -G Ninja -B build \ 2 | -DMLIR_DIR=$LLVM_ROOT/build/lib/cmake/mlir \ 3 | -DLLVM_EXTERNAL_LIT=$LLVM_ROOT/build/bin/llvm-lit \ 4 | -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ 5 | -DCNPY_LIB=/work/shared/common/datasets/UniSparse_dataset/cnpy/build \ 6 | -DCNPY_INCLUDE_LIB=/work/shared/common/datasets/UniSparse_dataset/cnpy -------------------------------------------------------------------------------- /scripts/unisparse-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/scripts/unisparse-icon.png -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | configure_lit_site_cfg( 2 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in 3 | ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py 4 | MAIN_CONFIG 5 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py 6 | ) 7 | 8 | set(UNISPARSE_TEST_DEPENDS 9 | FileCheck count not 10 | unisparse-opt 11 | unisparse-translate 12 | ) 13 | 14 | add_lit_testsuite(check-unisparse "Running the unisparse regression tests" 15 | ${CMAKE_CURRENT_BINARY_DIR} 16 | DEPENDS ${UNISPARSE_TEST_DEPENDS} 17 | ) 18 | set_target_properties(check-unisparse PROPERTIES FOLDER "Tests") 19 | 20 | add_lit_testsuites(UNISPARSE ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${UNISPARSE_TEST_DEPENDS}) 21 | -------------------------------------------------------------------------------- /test/Data/tensor46.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix coordinate real general 2 | % 3 | % This is a test sparse matrix in Matrix Market Exchange Format. 4 | % see https://math.nist.gov/MatrixMarket 5 | % 6 | 4 6 5 7 | 1 2 1 8 | 1 4 2 9 | 2 1 3 10 | 3 4 10 11 | 4 2 -1 12 | -------------------------------------------------------------------------------- /test/Data/test.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix coordinate integer general 2 | % 3 | % This is a test sparse matrix in Matrix Market Exchange Format. 4 | % see https://math.nist.gov/MatrixMarket 5 | % 6 | 4 6 7 7 | 1 1 1.0 8 | 1 2 2.0 9 | 2 1 3.0 10 | 2 2 4.0 11 | 4 1 5.0 12 | 4 4 6.0 13 | 4 5 7.0 14 | -------------------------------------------------------------------------------- /test/Data/wide.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix coordinate integer general 2 | % 3 | % This is a test sparse matrix in Matrix Market Exchange Format. 4 | % see https://math.nist.gov/MatrixMarket 5 | % 6 | 4 256 17 7 | 1 1 -1 8 | 1 127 2 9 | 1 128 -3 10 | 1 255 4 11 | 2 2 -5 12 | 2 254 6 13 | 3 3 -7 14 | 4 1 8 15 | 4 2 -9 16 | 4 4 10 17 | 4 99 -11 18 | 4 127 12 19 | 4 128 -13 20 | 4 129 14 21 | 4 250 -15 22 | 4 254 16 23 | 4 256 -17 24 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/coo_to_csbdcsr.mlir: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornell-zhang/UniSparse/acfd229ffacaa7779f60b3bc2b65659672cbe862/test/UniSparse/FormatPreprocess/conversion/coo_to_csbdcsr.mlir -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/temp_coo_to_bcoo.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delSparlayTensor(!llvm.ptr) 3 | func.func private @sptCheck(!llvm.ptr, !llvm.ptr) attributes {llvm.emit_c_interface} 4 | func.func private @sptTileMerge(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptDevectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptVectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptMove(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptTileSplit(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptCopy(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptPrint(!llvm.ptr) attributes {llvm.emit_c_interface} 11 | func.func private @sptFromFile(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @rtclock() -> f64 13 | func.func private @getTensorFilename(index) -> !llvm.ptr 14 | func.func @main() { 15 | %cst = arith.constant 0.000000e+00 : f32 16 | %c0 = arith.constant 0 : index 17 | %c1 = arith.constant 1 : index 18 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 19 | %1 = call @sptFromFile(%0) : (!llvm.ptr) -> !llvm.ptr 20 | call @sptPrint(%1) : (!llvm.ptr) -> () 21 | %2 = call @sptCopy(%1) : (!llvm.ptr) -> !llvm.ptr 22 | %3 = call @rtclock() : () -> f64 23 | %c0_i32 = arith.constant 0 : i32 24 | %c1_i32 = arith.constant 1 : i32 25 | %c2_i32 = arith.constant 2 : i32 26 | %c3_i32 = arith.constant 3 : i32 27 | %c4_i32 = arith.constant 4 : i32 28 | %c5_i32 = arith.constant 5 : i32 29 | %c3_i32_0 = arith.constant 3 : i32 30 | %4 = call @sptTileSplit(%2, %c1_i32, %c3_i32_0) : (!llvm.ptr, i32, i32) -> !llvm.ptr 31 | %c2_i32_1 = arith.constant 2 : i32 32 | %5 = call @sptTileSplit(%4, %c0_i32, %c2_i32_1) : (!llvm.ptr, i32, i32) -> !llvm.ptr 33 | %6 = call @sptMove(%5, %c2_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 34 | %7 = call @sptMove(%6, %c1_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 35 | %8 = call @sptVectorize(%7, %c2_i32) : (!llvm.ptr, i32) -> !llvm.ptr 36 | call @sptPrint(%8) : (!llvm.ptr) -> () 37 | %9 = call @rtclock() : () -> f64 38 | %10 = arith.subf %9, %3 : f64 39 | vector.print %10 : f64 40 | %c0_i32_2 = arith.constant 0 : i32 41 | %c1_i32_3 = arith.constant 1 : i32 42 | %c2_i32_4 = arith.constant 2 : i32 43 | %c3_i32_5 = arith.constant 3 : i32 44 | %c4_i32_6 = arith.constant 4 : i32 45 | %c5_i32_7 = arith.constant 5 : i32 46 | %11 = call @sptDevectorize(%8, %c2_i32_4) : (!llvm.ptr, i32) -> !llvm.ptr 47 | %12 = call @sptMove(%11, %c2_i32_4, %c1_i32_3) : (!llvm.ptr, i32, i32) -> !llvm.ptr 48 | %13 = call @sptMove(%12, %c3_i32_5, %c3_i32_5) : (!llvm.ptr, i32, i32) -> !llvm.ptr 49 | %c3_i32_8 = arith.constant 3 : i32 50 | %14 = call @sptTileMerge(%13, %c2_i32_4, %c3_i32_8) : (!llvm.ptr, i32, i32) -> !llvm.ptr 51 | %c2_i32_9 = arith.constant 2 : i32 52 | %15 = call @sptTileMerge(%14, %c0_i32_2, %c2_i32_9) : (!llvm.ptr, i32, i32) -> !llvm.ptr 53 | call @sptPrint(%15) : (!llvm.ptr) -> () 54 | call @sptCheck(%15, %1) : (!llvm.ptr, !llvm.ptr) -> () 55 | call @delSparlayTensor(%1) : (!llvm.ptr) -> () 56 | call @delSparlayTensor(%15) : (!llvm.ptr) -> () 57 | return 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/temp_coo_to_bell_16.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delSparlayTensor(!llvm.ptr) 3 | func.func private @sptCheck(!llvm.ptr, !llvm.ptr) attributes {llvm.emit_c_interface} 4 | func.func private @sptTileMerge(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptSeparate(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptTrim(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptDevectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptVectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptGrow(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptFuse(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 11 | func.func private @sptMove(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @sptEnumerate(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 13 | func.func private @sptPad(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 14 | func.func private @sptTileSplit(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 15 | func.func private @sptCopy(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 16 | func.func private @sptPrint(!llvm.ptr) attributes {llvm.emit_c_interface} 17 | func.func private @sptFromFile(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 18 | func.func private @rtclock() -> f64 19 | func.func private @getTensorFilename(index) -> !llvm.ptr 20 | func.func @main() { 21 | %cst = arith.constant 0.000000e+00 : f32 22 | %c0 = arith.constant 0 : index 23 | %c1 = arith.constant 1 : index 24 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 25 | %1 = call @sptFromFile(%0) : (!llvm.ptr) -> !llvm.ptr 26 | // call @sptPrint(%1) : (!llvm.ptr) -> () 27 | %2 = call @sptCopy(%1) : (!llvm.ptr) -> !llvm.ptr 28 | %3 = call @rtclock() : () -> f64 29 | %c0_i32 = arith.constant 0 : i32 30 | %c1_i32 = arith.constant 1 : i32 31 | %c2_i32 = arith.constant 2 : i32 32 | %c3_i32 = arith.constant 3 : i32 33 | %c16_i32 = arith.constant 16 : i32 34 | %c5_i32 = arith.constant 5 : i32 35 | %4 = call @sptTileSplit(%2, %c1_i32, %c16_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 36 | %5 = call @sptTileSplit(%4, %c0_i32, %c16_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 37 | // %6 = call @sptMove(%5, %c2_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 38 | // %7 = call @sptMove(%6, %c1_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 39 | %7 = call @sptMove(%5, %c2_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 40 | %8 = call @sptFuse(%7, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 41 | %9 = call @sptFuse(%8, %c1_i32) : (!llvm.ptr, i32) -> !llvm.ptr 42 | %10 = call @sptGrow(%9, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 43 | %11 = call @sptVectorize(%10, %c2_i32) : (!llvm.ptr, i32) -> !llvm.ptr 44 | %12 = call @sptEnumerate(%11, %c1_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 45 | %13 = call @sptPad(%12, %c2_i32, %c2_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 46 | %14 = call @sptMove(%13, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 47 | // call @sptPrint(%14) : (!llvm.ptr) -> () 48 | %15 = call @rtclock() : () -> f64 49 | %t_0 = arith.subf %15, %3: f64 50 | vector.print %t_0 : f64 51 | call @delSparlayTensor(%1) : (!llvm.ptr) -> () 52 | call @delSparlayTensor(%14) : (!llvm.ptr) -> () 53 | return 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/temp_coo_to_bell_32.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delSparlayTensor(!llvm.ptr) 3 | func.func private @sptCheck(!llvm.ptr, !llvm.ptr) attributes {llvm.emit_c_interface} 4 | func.func private @sptTileMerge(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptSeparate(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptTrim(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptDevectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptVectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptGrow(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptFuse(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 11 | func.func private @sptMove(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @sptEnumerate(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 13 | func.func private @sptPad(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 14 | func.func private @sptTileSplit(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 15 | func.func private @sptCopy(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 16 | func.func private @sptPrint(!llvm.ptr) attributes {llvm.emit_c_interface} 17 | func.func private @sptFromFile(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 18 | func.func private @rtclock() -> f64 19 | func.func private @getTensorFilename(index) -> !llvm.ptr 20 | func.func @main() { 21 | %cst = arith.constant 0.000000e+00 : f32 22 | %c0 = arith.constant 0 : index 23 | %c1 = arith.constant 1 : index 24 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 25 | %1 = call @sptFromFile(%0) : (!llvm.ptr) -> !llvm.ptr 26 | // call @sptPrint(%1) : (!llvm.ptr) -> () 27 | %2 = call @sptCopy(%1) : (!llvm.ptr) -> !llvm.ptr 28 | %3 = call @rtclock() : () -> f64 29 | %c0_i32 = arith.constant 0 : i32 30 | %c1_i32 = arith.constant 1 : i32 31 | %c2_i32 = arith.constant 2 : i32 32 | %c3_i32 = arith.constant 3 : i32 33 | %c32_i32 = arith.constant 32 : i32 34 | %c5_i32 = arith.constant 5 : i32 35 | %4 = call @sptTileSplit(%2, %c1_i32, %c32_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 36 | %5 = call @sptTileSplit(%4, %c0_i32, %c32_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 37 | // %6 = call @sptMove(%5, %c2_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 38 | // %7 = call @sptMove(%6, %c1_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 39 | %7 = call @sptMove(%5, %c2_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 40 | %8 = call @sptFuse(%7, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 41 | %9 = call @sptFuse(%8, %c1_i32) : (!llvm.ptr, i32) -> !llvm.ptr 42 | %10 = call @sptGrow(%9, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 43 | %11 = call @sptVectorize(%10, %c2_i32) : (!llvm.ptr, i32) -> !llvm.ptr 44 | %12 = call @sptEnumerate(%11, %c1_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 45 | %13 = call @sptPad(%12, %c2_i32, %c2_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 46 | %14 = call @sptMove(%13, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 47 | // call @sptPrint(%14) : (!llvm.ptr) -> () 48 | %15 = call @rtclock() : () -> f64 49 | %t_0 = arith.subf %15, %3: f64 50 | vector.print %t_0 : f64 51 | call @delSparlayTensor(%1) : (!llvm.ptr) -> () 52 | call @delSparlayTensor(%14) : (!llvm.ptr) -> () 53 | return 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/temp_coo_to_bell_64.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delSparlayTensor(!llvm.ptr) 3 | func.func private @sptCheck(!llvm.ptr, !llvm.ptr) attributes {llvm.emit_c_interface} 4 | func.func private @sptTileMerge(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptSeparate(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptTrim(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptDevectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptVectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptGrow(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptFuse(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 11 | func.func private @sptMove(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @sptEnumerate(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 13 | func.func private @sptPad(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 14 | func.func private @sptTileSplit(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 15 | func.func private @sptCopy(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 16 | func.func private @sptPrint(!llvm.ptr) attributes {llvm.emit_c_interface} 17 | func.func private @sptFromFile(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 18 | func.func private @rtclock() -> f64 19 | func.func private @getTensorFilename(index) -> !llvm.ptr 20 | func.func @main() { 21 | %cst = arith.constant 0.000000e+00 : f32 22 | %c0 = arith.constant 0 : index 23 | %c1 = arith.constant 1 : index 24 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 25 | %1 = call @sptFromFile(%0) : (!llvm.ptr) -> !llvm.ptr 26 | // call @sptPrint(%1) : (!llvm.ptr) -> () 27 | %2 = call @sptCopy(%1) : (!llvm.ptr) -> !llvm.ptr 28 | %3 = call @rtclock() : () -> f64 29 | %c0_i32 = arith.constant 0 : i32 30 | %c1_i32 = arith.constant 1 : i32 31 | %c2_i32 = arith.constant 2 : i32 32 | %c3_i32 = arith.constant 3 : i32 33 | %c64_i32 = arith.constant 64 : i32 34 | %c5_i32 = arith.constant 5 : i32 35 | %4 = call @sptTileSplit(%2, %c1_i32, %c64_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 36 | %5 = call @sptTileSplit(%4, %c0_i32, %c64_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 37 | // %6 = call @sptMove(%5, %c2_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 38 | // %7 = call @sptMove(%6, %c1_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 39 | %7 = call @sptMove(%5, %c2_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 40 | %8 = call @sptFuse(%7, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 41 | %9 = call @sptFuse(%8, %c1_i32) : (!llvm.ptr, i32) -> !llvm.ptr 42 | %10 = call @sptGrow(%9, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 43 | %11 = call @sptVectorize(%10, %c2_i32) : (!llvm.ptr, i32) -> !llvm.ptr 44 | %12 = call @sptEnumerate(%11, %c1_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 45 | %13 = call @sptPad(%12, %c2_i32, %c2_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 46 | %14 = call @sptMove(%13, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 47 | // call @sptPrint(%14) : (!llvm.ptr) -> () 48 | %15 = call @rtclock() : () -> f64 49 | %t_0 = arith.subf %15, %3: f64 50 | vector.print %t_0 : f64 51 | call @delSparlayTensor(%1) : (!llvm.ptr) -> () 52 | call @delSparlayTensor(%14) : (!llvm.ptr) -> () 53 | return 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/temp_coo_to_cisr.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delSparlayTensor(!llvm.ptr) 3 | func.func private @sptCheck(!llvm.ptr, !llvm.ptr) attributes {llvm.emit_c_interface} 4 | func.func private @sptMove(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptSwap(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptTileSplit(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptSeparate(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptTrim(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptGrow(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptFuse(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 11 | func.func private @sptSum(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @sptEnumerate(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 13 | func.func private @sptSchedule(!llvm.ptr, i32, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 14 | func.func private @sptPad(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 15 | func.func private @sptReorder(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 16 | func.func private @sptCustTrim(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 17 | func.func private @sptCopy(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 18 | func.func private @sptFromFile(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 19 | func.func private @rtclock() -> f64 20 | func.func private @getTensorFilename(index) -> !llvm.ptr 21 | func.func @main() { 22 | %cst = arith.constant 0.000000e+00 : f32 23 | %c0 = arith.constant 0 : index 24 | %c1 = arith.constant 1 : index 25 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 26 | %1 = call @sptFromFile(%0) : (!llvm.ptr) -> !llvm.ptr 27 | %2 = call @sptCopy(%1) : (!llvm.ptr) -> !llvm.ptr 28 | %3 = call @rtclock() : () -> f64 29 | %c0_i32 = arith.constant 0 : i32 30 | %c1_i32 = arith.constant 1 : i32 31 | %c2_i32 = arith.constant 2 : i32 32 | %c3_i32 = arith.constant 3 : i32 33 | %c4_i32 = arith.constant 4 : i32 34 | %c5_i32 = arith.constant 1024 : i32 35 | %4 = call @sptSum(%2, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 36 | %5 = call @sptSchedule(%4, %c0_i32, %c0_i32, %c5_i32) : (!llvm.ptr, i32, i32, i32) -> !llvm.ptr 37 | %6 = call @sptMove(%5, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 38 | %7 = call @sptFuse(%6, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 39 | %8 = call @sptFuse(%7, %c1_i32) : (!llvm.ptr, i32) -> !llvm.ptr 40 | %14 = call @rtclock() : () -> f64 41 | %15 = arith.subf %14, %3 : f64 42 | vector.print %15 : f64 43 | call @delSparlayTensor(%1) : (!llvm.ptr) -> () 44 | call @delSparlayTensor(%7) : (!llvm.ptr) -> () 45 | return 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/temp_coo_to_cisr_plus.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delSparlayTensor(!llvm.ptr) 3 | func.func private @sptCheck(!llvm.ptr, !llvm.ptr) attributes {llvm.emit_c_interface} 4 | func.func private @sptMove(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptSwap(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptTileSplit(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptSeparate(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptTrim(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptGrow(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptFuse(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 11 | func.func private @sptSum(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @sptEnumerate(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 13 | func.func private @sptSchedule(!llvm.ptr, i32, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 14 | func.func private @sptPad(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 15 | func.func private @sptReorder(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 16 | func.func private @sptCustTrim(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 17 | func.func private @sptCopy(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 18 | func.func private @sptFromFile(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 19 | func.func private @rtclock() -> f64 20 | func.func private @getTensorFilename(index) -> !llvm.ptr 21 | func.func @main() { 22 | %cst = arith.constant 0.000000e+00 : f32 23 | %c0 = arith.constant 0 : index 24 | %c1 = arith.constant 1 : index 25 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 26 | %1 = call @sptFromFile(%0) : (!llvm.ptr) -> !llvm.ptr 27 | %2 = call @sptCopy(%1) : (!llvm.ptr) -> !llvm.ptr 28 | %3 = call @rtclock() : () -> f64 29 | %c0_i32 = arith.constant 0 : i32 30 | %c1_i32 = arith.constant 1 : i32 31 | %c2_i32 = arith.constant 2 : i32 32 | %c3_i32 = arith.constant 3 : i32 33 | %c4_i32 = arith.constant 4 : i32 34 | %c5_i32 = arith.constant 1024 : i32 35 | %4 = call @sptSum(%2, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 36 | %5 = call @sptReorder(%4, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 37 | %6 = call @sptMove(%5, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 38 | %7 = call @sptSum(%6, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 39 | %8 = call @sptSchedule(%7, %c0_i32, %c0_i32, %c5_i32) : (!llvm.ptr, i32, i32, i32) -> !llvm.ptr 40 | %9 = call @sptMove(%8, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 41 | %10 = call @sptFuse(%9, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 42 | %11 = call @sptFuse(%10, %c1_i32) : (!llvm.ptr, i32) -> !llvm.ptr 43 | %14 = call @rtclock() : () -> f64 44 | %15 = arith.subf %14, %3 : f64 45 | vector.print %15 : f64 46 | call @delSparlayTensor(%1) : (!llvm.ptr) -> () 47 | call @delSparlayTensor(%11) : (!llvm.ptr) -> () 48 | return 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/temp_coo_to_dia1.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delSparlayTensor(!llvm.ptr) 3 | func.func private @sptCheck(!llvm.ptr, !llvm.ptr) attributes {llvm.emit_c_interface} 4 | func.func private @sptSeparate(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptDevectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptVectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptFuse(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptMove(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptNeg(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptSub(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 11 | func.func private @sptCopy(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @sptPrint(!llvm.ptr) attributes {llvm.emit_c_interface} 13 | func.func private @sptFromFile(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 14 | func.func private @rtclock() -> f64 15 | func.func private @getTensorFilename(index) -> !llvm.ptr 16 | func.func @main() { 17 | %cst = arith.constant 0.000000e+00 : f32 18 | %c0 = arith.constant 0 : index 19 | %c1 = arith.constant 1 : index 20 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 21 | %1 = call @sptFromFile(%0) : (!llvm.ptr) -> !llvm.ptr 22 | call @sptPrint(%1) : (!llvm.ptr) -> () 23 | %2 = call @sptCopy(%1) : (!llvm.ptr) -> !llvm.ptr 24 | %3 = call @rtclock() : () -> f64 25 | %c0_i32 = arith.constant 0 : i32 26 | %c1_i32 = arith.constant 1 : i32 27 | %c2_i32 = arith.constant 2 : i32 28 | %c3_i32 = arith.constant 3 : i32 29 | %c4_i32 = arith.constant 4 : i32 30 | %c5_i32 = arith.constant 5 : i32 31 | %4 = call @sptSub(%2, %c0_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 32 | %5 = call @sptNeg(%4, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 33 | %6 = call @sptMove(%5, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 34 | %7 = call @sptFuse(%6, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 35 | %8 = call @sptVectorize(%7, %c1_i32) : (!llvm.ptr, i32) -> !llvm.ptr 36 | call @sptPrint(%8) : (!llvm.ptr) -> () 37 | %9 = call @rtclock() : () -> f64 38 | %10 = arith.subf %9, %3 : f64 39 | vector.print %10 : f64 40 | %c0_i32_0 = arith.constant 0 : i32 41 | %c1_i32_1 = arith.constant 1 : i32 42 | %c2_i32_2 = arith.constant 2 : i32 43 | %c3_i32_3 = arith.constant 3 : i32 44 | %c4_i32_4 = arith.constant 4 : i32 45 | %c5_i32_5 = arith.constant 5 : i32 46 | %11 = call @sptDevectorize(%8, %c1_i32_1) : (!llvm.ptr, i32) -> !llvm.ptr 47 | %12 = call @sptSeparate(%11, %c0_i32_0) : (!llvm.ptr, i32) -> !llvm.ptr 48 | %13 = call @sptSub(%12, %c0_i32_0, %c1_i32_1) : (!llvm.ptr, i32, i32) -> !llvm.ptr 49 | %14 = call @sptNeg(%13, %c0_i32_0) : (!llvm.ptr, i32) -> !llvm.ptr 50 | %15 = call @sptMove(%14, %c0_i32_0, %c0_i32_0) : (!llvm.ptr, i32, i32) -> !llvm.ptr 51 | %16 = call @sptMove(%15, %c1_i32_1, %c1_i32_1) : (!llvm.ptr, i32, i32) -> !llvm.ptr 52 | call @sptPrint(%16) : (!llvm.ptr) -> () 53 | call @sptCheck(%16, %1) : (!llvm.ptr, !llvm.ptr) -> () 54 | call @delSparlayTensor(%1) : (!llvm.ptr) -> () 55 | call @delSparlayTensor(%16) : (!llvm.ptr) -> () 56 | return 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/temp_coo_to_dia3.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delSparlayTensor(!llvm.ptr) 3 | func.func private @sptCheck(!llvm.ptr, !llvm.ptr) attributes {llvm.emit_c_interface} 4 | func.func private @sptAdd(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptSeparate(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptDevectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptVectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptFuse(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptMove(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptSub(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 11 | func.func private @sptCopy(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @sptPrint(!llvm.ptr) attributes {llvm.emit_c_interface} 13 | func.func private @sptFromFile(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 14 | func.func private @rtclock() -> f64 15 | func.func private @getTensorFilename(index) -> !llvm.ptr 16 | func.func @main() { 17 | %cst = arith.constant 0.000000e+00 : f32 18 | %c0 = arith.constant 0 : index 19 | %c1 = arith.constant 1 : index 20 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 21 | %1 = call @sptFromFile(%0) : (!llvm.ptr) -> !llvm.ptr 22 | call @sptPrint(%1) : (!llvm.ptr) -> () 23 | %2 = call @sptCopy(%1) : (!llvm.ptr) -> !llvm.ptr 24 | %3 = call @rtclock() : () -> f64 25 | %c0_i32 = arith.constant 0 : i32 26 | %c1_i32 = arith.constant 1 : i32 27 | %c2_i32 = arith.constant 2 : i32 28 | %c3_i32 = arith.constant 3 : i32 29 | %c4_i32 = arith.constant 4 : i32 30 | %c5_i32 = arith.constant 5 : i32 31 | %4 = call @sptSub(%2, %c0_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 32 | %5 = call @sptMove(%4, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 33 | %6 = call @sptFuse(%5, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 34 | %7 = call @sptVectorize(%6, %c1_i32) : (!llvm.ptr, i32) -> !llvm.ptr 35 | call @sptPrint(%7) : (!llvm.ptr) -> () 36 | %8 = call @rtclock() : () -> f64 37 | %9 = arith.subf %8, %3 : f64 38 | vector.print %9 : f64 39 | %c0_i32_0 = arith.constant 0 : i32 40 | %c1_i32_1 = arith.constant 1 : i32 41 | %c2_i32_2 = arith.constant 2 : i32 42 | %c3_i32_3 = arith.constant 3 : i32 43 | %c4_i32_4 = arith.constant 4 : i32 44 | %c5_i32_5 = arith.constant 5 : i32 45 | %10 = call @sptDevectorize(%7, %c1_i32_1) : (!llvm.ptr, i32) -> !llvm.ptr 46 | %11 = call @sptSeparate(%10, %c0_i32_0) : (!llvm.ptr, i32) -> !llvm.ptr 47 | %12 = call @sptAdd(%11, %c0_i32_0, %c1_i32_1) : (!llvm.ptr, i32, i32) -> !llvm.ptr 48 | %13 = call @sptMove(%12, %c0_i32_0, %c0_i32_0) : (!llvm.ptr, i32, i32) -> !llvm.ptr 49 | %14 = call @sptMove(%13, %c1_i32_1, %c1_i32_1) : (!llvm.ptr, i32, i32) -> !llvm.ptr 50 | call @sptPrint(%14) : (!llvm.ptr) -> () 51 | call @sptCheck(%14, %1) : (!llvm.ptr, !llvm.ptr) -> () 52 | call @delSparlayTensor(%1) : (!llvm.ptr) -> () 53 | call @delSparlayTensor(%14) : (!llvm.ptr) -> () 54 | return 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/temp_coo_to_dia4.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delSparlayTensor(!llvm.ptr) 3 | func.func private @sptCheck(!llvm.ptr, !llvm.ptr) attributes {llvm.emit_c_interface} 4 | func.func private @sptNeg(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptAdd(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptSeparate(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptDevectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptVectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptFuse(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptMove(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 11 | func.func private @sptSub(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @sptSwap(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 13 | func.func private @sptCopy(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 14 | func.func private @sptFromFile(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> !llvm.ptr 17 | func.func @main() { 18 | %cst = arith.constant 0.000000e+00 : f32 19 | %c0 = arith.constant 0 : index 20 | %c1 = arith.constant 1 : index 21 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 22 | %1 = call @sptFromFile(%0) : (!llvm.ptr) -> !llvm.ptr 23 | %2 = call @sptCopy(%1) : (!llvm.ptr) -> !llvm.ptr 24 | %3 = call @rtclock() : () -> f64 25 | %c0_i32 = arith.constant 0 : i32 26 | %c1_i32 = arith.constant 1 : i32 27 | %c2_i32 = arith.constant 2 : i32 28 | %c3_i32 = arith.constant 3 : i32 29 | %c4_i32 = arith.constant 4 : i32 30 | %c5_i32 = arith.constant 5 : i32 31 | %4 = call @sptSwap(%2, %c0_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 32 | %5 = call @sptSub(%4, %c0_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 33 | %6 = call @sptMove(%5, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 34 | %7 = call @sptFuse(%6, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 35 | %8 = call @sptVectorize(%7, %c1_i32) : (!llvm.ptr, i32) -> !llvm.ptr 36 | %9 = call @rtclock() : () -> f64 37 | %10 = arith.subf %9, %3 : f64 38 | vector.print %10 : f64 39 | %c0_i32_0 = arith.constant 0 : i32 40 | %c1_i32_1 = arith.constant 1 : i32 41 | %c2_i32_2 = arith.constant 2 : i32 42 | %c3_i32_3 = arith.constant 3 : i32 43 | %c4_i32_4 = arith.constant 4 : i32 44 | %c5_i32_5 = arith.constant 5 : i32 45 | %11 = call @sptDevectorize(%8, %c1_i32_1) : (!llvm.ptr, i32) -> !llvm.ptr 46 | %12 = call @sptSeparate(%11, %c0_i32_0) : (!llvm.ptr, i32) -> !llvm.ptr 47 | %13 = call @sptAdd(%12, %c1_i32_1, %c0_i32_0) : (!llvm.ptr, i32, i32) -> !llvm.ptr 48 | %14 = call @sptSub(%13, %c0_i32_0, %c1_i32_1) : (!llvm.ptr, i32, i32) -> !llvm.ptr 49 | %15 = call @sptNeg(%14, %c0_i32_0) : (!llvm.ptr, i32) -> !llvm.ptr 50 | %16 = call @sptMove(%15, %c0_i32_0, %c0_i32_0) : (!llvm.ptr, i32, i32) -> !llvm.ptr 51 | %17 = call @sptMove(%16, %c1_i32_1, %c1_i32_1) : (!llvm.ptr, i32, i32) -> !llvm.ptr 52 | call @sptCheck(%17, %1) : (!llvm.ptr, !llvm.ptr) -> () 53 | call @delSparlayTensor(%1) : (!llvm.ptr) -> () 54 | call @delSparlayTensor(%17) : (!llvm.ptr) -> () 55 | return 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/temp_coo_to_dia4_only.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delSparlayTensor(!llvm.ptr) 3 | func.func private @sptCheck(!llvm.ptr, !llvm.ptr) attributes {llvm.emit_c_interface} 4 | func.func private @sptNeg(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptAdd(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptSeparate(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptDevectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptVectorize(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptFuse(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptMove(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 11 | func.func private @sptSub(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @sptSwap(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 13 | func.func private @sptCopy(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 14 | func.func private @sptFromFile(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> !llvm.ptr 17 | func.func @main() { 18 | %cst = arith.constant 0.000000e+00 : f32 19 | %c0 = arith.constant 0 : index 20 | %c1 = arith.constant 1 : index 21 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 22 | %1 = call @sptFromFile(%0) : (!llvm.ptr) -> !llvm.ptr 23 | %2 = call @sptCopy(%1) : (!llvm.ptr) -> !llvm.ptr 24 | %3 = call @rtclock() : () -> f64 25 | %c0_i32 = arith.constant 0 : i32 26 | %c1_i32 = arith.constant 1 : i32 27 | %c2_i32 = arith.constant 2 : i32 28 | %c3_i32 = arith.constant 3 : i32 29 | %c4_i32 = arith.constant 4 : i32 30 | %c5_i32 = arith.constant 5 : i32 31 | %4 = call @sptSwap(%2, %c0_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 32 | %5 = call @sptSub(%4, %c0_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 33 | %6 = call @sptMove(%5, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 34 | %7 = call @sptFuse(%6, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 35 | %8 = call @sptVectorize(%7, %c1_i32) : (!llvm.ptr, i32) -> !llvm.ptr 36 | %9 = call @rtclock() : () -> f64 37 | %10 = arith.subf %9, %3 : f64 38 | vector.print %10 : f64 39 | call @delSparlayTensor(%1) : (!llvm.ptr) -> () 40 | call @delSparlayTensor(%8) : (!llvm.ptr) -> () 41 | return 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/temp_coo_to_ell.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delSparlayTensor(!llvm.ptr) 3 | func.func private @sptCheck(!llvm.ptr, !llvm.ptr) attributes {llvm.emit_c_interface} 4 | func.func private @sptMove(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptSwap(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptSeparate(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptTrim(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptGrow(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptFuse(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptSum(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 11 | func.func private @sptEnumerate(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @sptPad(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 13 | func.func private @sptCustPad(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 14 | func.func private @sptCopy(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 15 | func.func private @sptFromFile(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 16 | func.func private @rtclock() -> f64 17 | func.func private @getTensorFilename(index) -> !llvm.ptr 18 | func.func @main() { 19 | %cst = arith.constant 0.000000e+00 : f32 20 | %c0 = arith.constant 0 : index 21 | %c1 = arith.constant 1 : index 22 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 23 | %1 = call @sptFromFile(%0) : (!llvm.ptr) -> !llvm.ptr 24 | %2 = call @sptCopy(%1) : (!llvm.ptr) -> !llvm.ptr 25 | %3 = call @rtclock() : () -> f64 26 | %c0_i32 = arith.constant 0 : i32 27 | %c1_i32 = arith.constant 1 : i32 28 | %c2_i32 = arith.constant 2 : i32 29 | %c3_i32 = arith.constant 3 : i32 30 | %c4_i32 = arith.constant 4 : i32 31 | %c5_i32 = arith.constant 5 : i32 32 | %4 = call @sptSeparate(%2, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 33 | %5 = call @sptTrim(%4, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 34 | %6 = call @sptSum(%2, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 35 | %7 = call @sptEnumerate(%6, %c0_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 36 | %8 = call @sptMove(%7, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 37 | %9 = call @sptCustPad(%8, %c0_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 38 | // %10 = call @sptMove(%9, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 39 | // %11 = call @sptMove(%10, %c1_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 40 | %12 = call @rtclock() : () -> f64 41 | %13 = arith.subf %12, %3 : f64 42 | vector.print %12 : f64 43 | call @delSparlayTensor(%1) : (!llvm.ptr) -> () 44 | call @delSparlayTensor(%9) : (!llvm.ptr) -> () 45 | return 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/temp_dcsr_to_ell.mlir: -------------------------------------------------------------------------------- 1 | module { 2 | func.func private @delSparlayTensor(!llvm.ptr) 3 | func.func private @sptCheck(!llvm.ptr, !llvm.ptr) attributes {llvm.emit_c_interface} 4 | func.func private @sptMove(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 5 | func.func private @sptSwap(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 6 | func.func private @sptSeparate(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 7 | func.func private @sptTrim(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 8 | func.func private @sptGrow(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 9 | func.func private @sptFuse(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 10 | func.func private @sptSum(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 11 | func.func private @sptCustPad(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 12 | func.func private @sptEnumerate(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 13 | func.func private @sptPad(!llvm.ptr, i32, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 14 | func.func private @sptCopy(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 15 | func.func private @sptFromFile(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 16 | func.func private @rtclock() -> f64 17 | func.func private @getTensorFilename(index) -> !llvm.ptr 18 | func.func @main() { 19 | %cst = arith.constant 0.000000e+00 : f32 20 | %c0 = arith.constant 0 : index 21 | %c1 = arith.constant 1 : index 22 | %0 = call @getTensorFilename(%c0) : (index) -> !llvm.ptr 23 | %1 = call @sptFromFile(%0) : (!llvm.ptr) -> !llvm.ptr 24 | %2 = call @sptCopy(%1) : (!llvm.ptr) -> !llvm.ptr 25 | %c0_i32 = arith.constant 0 : i32 26 | %c1_i32 = arith.constant 1 : i32 27 | %c2_i32 = arith.constant 2 : i32 28 | %c3_i32 = arith.constant 3 : i32 29 | %c4_i32 = arith.constant 4 : i32 30 | %c5_i32 = arith.constant 5 : i32 31 | %4 = call @sptFuse(%2, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 32 | %3 = call @rtclock() : () -> f64 33 | %5 = call @sptSeparate(%2, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 34 | %6 = call @sptSum(%2, %c0_i32) : (!llvm.ptr, i32) -> !llvm.ptr 35 | %7 = call @sptEnumerate(%6, %c0_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 36 | %8 = call @sptMove(%7, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 37 | %9 = call @sptCustPad(%8, %c1_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 38 | // %10 = call @sptMove(%9, %c0_i32, %c0_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 39 | // %11 = call @sptMove(%10, %c1_i32, %c1_i32) : (!llvm.ptr, i32, i32) -> !llvm.ptr 40 | %12 = call @rtclock() : () -> f64 41 | %13 = arith.subf %12, %3 : f64 42 | vector.print %13 : f64 43 | call @delSparlayTensor(%1) : (!llvm.ptr) -> () 44 | call @delSparlayTensor(%9) : (!llvm.ptr) -> () 45 | return 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_csr_csc.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #CSR = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | #CSC = #sparlay.encoding<{ 15 | crdMap = #sparlay.crd<(i,j)->(j,i)>, 16 | compressMap = #sparlay.compress 17 | }> 18 | 19 | module { 20 | func.func private @rtclock() -> f64 21 | func.func private @getTensorFilename(index) -> (!Filename) 22 | 23 | //CHECK-LABEL: func.func @main 24 | func.func @main() { 25 | %i0 = arith.constant 0.0 : f32 26 | %c0 = arith.constant 0 : index 27 | %c1 = arith.constant 1 : index 28 | %c4 = arith.constant 1000 : index 29 | %c256 = arith.constant 916428 : index 30 | 31 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 32 | 33 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 34 | %a0 = sparlay.copy (%a_ori): tensor to tensor 35 | 36 | %t_start0 = call @rtclock() : () -> f64 37 | %a1 = sparlay.convert (%a0): tensor to tensor 38 | %t_end0 = call @rtclock() : () -> f64 39 | %t_0 = arith.subf %t_end0, %t_start0: f64 40 | vector.print %t_0 : f64 41 | 42 | %t_start1 = call @rtclock() : () -> f64 43 | %a2 = sparlay.convert (%a1): tensor to tensor 44 | %t_end1 = call @rtclock() : () -> f64 45 | %t_1 = arith.subf %t_end1, %t_start1: f64 46 | vector.print %t_1 : f64 47 | 48 | %t_start2 = call @rtclock() : () -> f64 49 | %a3 = sparlay.convert (%a2): tensor to tensor 50 | %t_end2 = call @rtclock() : () -> f64 51 | %t_2 = arith.subf %t_end2, %t_start2: f64 52 | vector.print %t_2 : f64 53 | 54 | %t_start3 = call @rtclock() : () -> f64 55 | %a4 = sparlay.convert (%a3): tensor to tensor 56 | %t_end3 = call @rtclock() : () -> f64 57 | %t_3 = arith.subf %t_end3, %t_start3: f64 58 | vector.print %t_3 : f64 59 | 60 | sparlay.check (%a4, %a_ori): tensor, tensor 61 | 62 | %t_start4 = call @rtclock() : () -> f64 63 | %a5 = sparlay.convert (%a4): tensor to tensor 64 | %t_end4 = call @rtclock() : () -> f64 65 | %t_4 = arith.subf %t_end4, %t_start0: f64 66 | vector.print %t_4 : f64 67 | 68 | %t_start5 = call @rtclock() : () -> f64 69 | %a6 = sparlay.convert (%a5): tensor to tensor 70 | %t_end5 = call @rtclock() : () -> f64 71 | %t_5 = arith.subf %t_end5, %t_start5: f64 72 | vector.print %t_5 : f64 73 | 74 | sparlay.check (%a6, %a_ori): tensor, tensor 75 | 76 | //Release the resources 77 | bufferization.dealloc_tensor %a_ori : tensor 78 | bufferization.dealloc_tensor %a6 : tensor 79 | return 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_dcsr_csr.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #DCSR = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | #CSR = #sparlay.encoding<{ 15 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 16 | compressMap = #sparlay.compress 17 | }> 18 | 19 | module { 20 | func.func private @rtclock() -> f64 21 | func.func private @getTensorFilename(index) -> (!Filename) 22 | 23 | //CHECK-LABEL: func.func @main 24 | func.func @main() { 25 | %i0 = arith.constant 0.0 : f32 26 | %c0 = arith.constant 0 : index 27 | %c1 = arith.constant 1 : index 28 | %c4 = arith.constant 1000 : index 29 | %c256 = arith.constant 916428 : index 30 | 31 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 32 | 33 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 34 | sparlay.printStorage (%a_ori): tensor 35 | %a0 = sparlay.copy (%a_ori): tensor to tensor 36 | sparlay.printStorage (%a0): tensor 37 | %t_start0 = call @rtclock() : () -> f64 38 | %a1 = sparlay.convert (%a0): tensor to tensor 39 | %t_end0 = call @rtclock() : () -> f64 40 | %t_0 = arith.subf %t_end0, %t_start0: f64 41 | vector.print %t_0 : f64 42 | 43 | %t_start1 = call @rtclock() : () -> f64 44 | %a2 = sparlay.convert (%a1): tensor to tensor 45 | %t_end1 = call @rtclock() : () -> f64 46 | %t_1 = arith.subf %t_end1, %t_start1: f64 47 | vector.print %t_1 : f64 48 | 49 | //Release the resources 50 | bufferization.dealloc_tensor %a_ori : tensor 51 | bufferization.dealloc_tensor %a2 : tensor 52 | return 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_dcsr_dcsc.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #DCSR = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | #DCSC = #sparlay.encoding<{ 15 | crdMap = #sparlay.crd<(i,j)->(j,i)>, 16 | compressMap = #sparlay.compress 17 | }> 18 | 19 | module { 20 | func.func private @rtclock() -> f64 21 | func.func private @getTensorFilename(index) -> (!Filename) 22 | 23 | //CHECK-LABEL: func.func @main 24 | func.func @main() { 25 | %i0 = arith.constant 0.0 : f32 26 | %c0 = arith.constant 0 : index 27 | %c1 = arith.constant 1 : index 28 | %c4 = arith.constant 1000 : index 29 | %c256 = arith.constant 916428 : index 30 | 31 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 32 | 33 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 34 | %a0 = sparlay.copy (%a_ori): tensor to tensor 35 | 36 | %t_start0 = call @rtclock() : () -> f64 37 | %a1 = sparlay.convert (%a0): tensor to tensor 38 | %t_end0 = call @rtclock() : () -> f64 39 | %t_0 = arith.subf %t_end0, %t_start0: f64 40 | vector.print %t_0 : f64 41 | 42 | %t_start1 = call @rtclock() : () -> f64 43 | %a2 = sparlay.convert (%a1): tensor to tensor 44 | %t_end1 = call @rtclock() : () -> f64 45 | %t_1 = arith.subf %t_end1, %t_start1: f64 46 | vector.print %t_1 : f64 47 | 48 | %t_start2 = call @rtclock() : () -> f64 49 | %a3 = sparlay.convert (%a2): tensor to tensor 50 | %t_end2 = call @rtclock() : () -> f64 51 | %t_2 = arith.subf %t_end2, %t_start2: f64 52 | vector.print %t_2 : f64 53 | 54 | %t_start3 = call @rtclock() : () -> f64 55 | %a4 = sparlay.convert (%a3): tensor to tensor 56 | %t_end3 = call @rtclock() : () -> f64 57 | %t_3 = arith.subf %t_end3, %t_start3: f64 58 | vector.print %t_3 : f64 59 | 60 | sparlay.check (%a4, %a_ori): tensor, tensor 61 | 62 | %t_start4 = call @rtclock() : () -> f64 63 | %a5 = sparlay.convert (%a4): tensor to tensor 64 | %t_end4 = call @rtclock() : () -> f64 65 | %t_4 = arith.subf %t_end4, %t_start0: f64 66 | vector.print %t_4 : f64 67 | 68 | %t_start5 = call @rtclock() : () -> f64 69 | %a6 = sparlay.convert (%a5): tensor to tensor 70 | %t_end5 = call @rtclock() : () -> f64 71 | %t_5 = arith.subf %t_end5, %t_start5: f64 72 | vector.print %t_5 : f64 73 | 74 | sparlay.check (%a6, %a_ori): tensor, tensor 75 | 76 | //Release the resources 77 | bufferization.dealloc_tensor %a_ori : tensor 78 | bufferization.dealloc_tensor %a6 : tensor 79 | return 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_dia_bcsr.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #DIA = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(i minus j, j)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | #BCSR = #sparlay.encoding<{ 15 | crdMap = #sparlay.crd<(i, j)->(i floordiv 2, j floordiv 3, i mod 2, j mod 3)>, 16 | compressMap = #sparlay.compress 17 | }> 18 | 19 | module { 20 | func.func private @rtclock() -> f64 21 | func.func private @getTensorFilename(index) -> (!Filename) 22 | 23 | //CHECK-LABEL: func.func @main 24 | func.func @main() { 25 | %i0 = arith.constant 0.0 : f32 26 | %c0 = arith.constant 0 : index 27 | %c1 = arith.constant 1 : index 28 | 29 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 30 | 31 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 32 | sparlay.printStorage (%a_ori): tensor 33 | %a1 = sparlay.copy (%a_ori): tensor to tensor 34 | %a2 = sparlay.convert (%a1): tensor to tensor 35 | 36 | %t_start0 = call @rtclock() : () -> f64 37 | %a3 = sparlay.convert (%a2): tensor to tensor 38 | sparlay.printStorage (%a3): tensor 39 | %t_end0 = call @rtclock() : () -> f64 40 | %t_0 = arith.subf %t_end0, %t_start0: f64 41 | vector.print %t_0 : f64 42 | 43 | %t_start1 = call @rtclock() : () -> f64 44 | %a4 = sparlay.convert (%a3): tensor to tensor 45 | sparlay.printStorage (%a4): tensor 46 | %t_end1 = call @rtclock() : () -> f64 47 | %t_1 = arith.subf %t_end1, %t_start1: f64 48 | vector.print %t_1 : f64 49 | 50 | %a5 = sparlay.convert (%a4): tensor to tensor 51 | sparlay.printStorage (%a5): tensor 52 | sparlay.check (%a5, %a_ori): tensor, tensor 53 | 54 | //Release the resources 55 | bufferization.dealloc_tensor %a_ori : tensor 56 | bufferization.dealloc_tensor %a5: tensor 57 | return 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_bcoo.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #BCOO = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i, j)->(i floordiv 2, j floordiv 3, i mod 2, j mod 3)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | %t_start0 = call @rtclock() : () -> f64 31 | %a2 = sparlay.convert (%a1): tensor to tensor 32 | sparlay.printStorage (%a2): tensor 33 | %t_end0 = call @rtclock() : () -> f64 34 | %t_0 = arith.subf %t_end0, %t_start0: f64 35 | vector.print %t_0 : f64 36 | 37 | %a3 = sparlay.convert (%a2): tensor to tensor 38 | sparlay.printStorage (%a3): tensor 39 | sparlay.check (%a3, %a_ori): tensor, tensor 40 | 41 | //Release the resources 42 | bufferization.dealloc_tensor %a_ori : tensor 43 | bufferization.dealloc_tensor %a3 : tensor 44 | return 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_bcsc.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #BCSC = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i, j)->(j floordiv 3, i floordiv 2, i mod 2, j mod 3)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | %t_start0 = call @rtclock() : () -> f64 31 | %a2 = sparlay.convert (%a1): tensor to tensor 32 | sparlay.printStorage (%a2): tensor 33 | %t_end0 = call @rtclock() : () -> f64 34 | %t_0 = arith.subf %t_end0, %t_start0: f64 35 | vector.print %t_0 : f64 36 | 37 | %a3 = sparlay.convert (%a2): tensor to tensor 38 | sparlay.printStorage (%a3): tensor 39 | sparlay.check (%a3, %a_ori): tensor, tensor 40 | 41 | //Release the resources 42 | bufferization.dealloc_tensor %a_ori : tensor 43 | bufferization.dealloc_tensor %a3 : tensor 44 | return 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_bcsr.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #BCSR = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i, j)->(i floordiv 2, j floordiv 3, i mod 2, j mod 3)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | // sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | %t_start0 = call @rtclock() : () -> f64 31 | %a2 = sparlay.convert (%a1): tensor to tensor 32 | // sparlay.printStorage (%a2): tensor 33 | %t_end0 = call @rtclock() : () -> f64 34 | %t_0 = arith.subf %t_end0, %t_start0: f64 35 | vector.print %t_0 : f64 36 | 37 | %a3 = sparlay.convert (%a2): tensor to tensor 38 | // sparlay.printStorage (%a3): tensor 39 | sparlay.check (%a3, %a_ori): tensor, tensor 40 | 41 | //Release the resources 42 | bufferization.dealloc_tensor %a_ori : tensor 43 | bufferization.dealloc_tensor %a3 : tensor 44 | return 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_bdcsr.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #BDCSR = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i, j)->(i floordiv 2, j floordiv 3, i mod 2, j mod 3)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | %t_start0 = call @rtclock() : () -> f64 31 | %a2 = sparlay.convert (%a1): tensor to tensor 32 | sparlay.printStorage (%a2): tensor 33 | %t_end0 = call @rtclock() : () -> f64 34 | %t_0 = arith.subf %t_end0, %t_start0: f64 35 | vector.print %t_0 : f64 36 | 37 | %a3 = sparlay.convert (%a2): tensor to tensor 38 | sparlay.printStorage (%a3): tensor 39 | sparlay.check (%a3, %a_ori): tensor, tensor 40 | 41 | //Release the resources 42 | bufferization.dealloc_tensor %a_ori : tensor 43 | bufferization.dealloc_tensor %a3 : tensor 44 | return 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_bdia.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #BDIA = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(i floordiv 2, j minus i, i mod 2)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | 31 | %t_start0 = call @rtclock() : () -> f64 32 | %a2 = sparlay.convert (%a1): tensor to tensor 33 | sparlay.printStorage (%a2): tensor 34 | %t_end0 = call @rtclock() : () -> f64 35 | %t_0 = arith.subf %t_end0, %t_start0: f64 36 | vector.print %t_0 : f64 37 | 38 | %a3 = sparlay.convert (%a2): tensor to tensor 39 | sparlay.printStorage (%a3): tensor 40 | sparlay.check (%a3, %a_ori): tensor, tensor 41 | 42 | //Release the resources 43 | bufferization.dealloc_tensor %a_ori : tensor 44 | bufferization.dealloc_tensor %a3 : tensor 45 | return 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_bdia_100.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #BDIA = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(i floordiv 100, j minus i, i mod 100)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | // sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | 31 | %t_start0 = call @rtclock() : () -> f64 32 | %a2 = sparlay.convert (%a1): tensor to tensor 33 | // sparlay.printStorage (%a2): tensor 34 | %t_end0 = call @rtclock() : () -> f64 35 | %t_0 = arith.subf %t_end0, %t_start0: f64 36 | vector.print %t_0 : f64 37 | 38 | %a3 = sparlay.convert (%a2): tensor to tensor 39 | // sparlay.printStorage (%a3): tensor 40 | sparlay.check (%a3, %a_ori): tensor, tensor 41 | 42 | //Release the resources 43 | bufferization.dealloc_tensor %a_ori : tensor 44 | bufferization.dealloc_tensor %a3 : tensor 45 | return 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_bdia_1000.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #BDIA = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(i floordiv 1000, j minus i, i mod 1000)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | // sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | 31 | %t_start0 = call @rtclock() : () -> f64 32 | %a2 = sparlay.convert (%a1): tensor to tensor 33 | // sparlay.printStorage (%a2): tensor 34 | %t_end0 = call @rtclock() : () -> f64 35 | %t_0 = arith.subf %t_end0, %t_start0: f64 36 | vector.print %t_0 : f64 37 | 38 | %a3 = sparlay.convert (%a2): tensor to tensor 39 | // sparlay.printStorage (%a3): tensor 40 | sparlay.check (%a3, %a_ori): tensor, tensor 41 | 42 | //Release the resources 43 | bufferization.dealloc_tensor %a_ori : tensor 44 | bufferization.dealloc_tensor %a3 : tensor 45 | return 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_bdia_500.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #BDIA = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(i floordiv 500, j minus i, i mod 500)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | // sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | 31 | %t_start0 = call @rtclock() : () -> f64 32 | %a2 = sparlay.convert (%a1): tensor to tensor 33 | // sparlay.printStorage (%a2): tensor 34 | %t_end0 = call @rtclock() : () -> f64 35 | %t_0 = arith.subf %t_end0, %t_start0: f64 36 | vector.print %t_0 : f64 37 | 38 | %a3 = sparlay.convert (%a2): tensor to tensor 39 | // sparlay.printStorage (%a3): tensor 40 | sparlay.check (%a3, %a_ori): tensor, tensor 41 | 42 | //Release the resources 43 | bufferization.dealloc_tensor %a_ori : tensor 44 | bufferization.dealloc_tensor %a3 : tensor 45 | return 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_c2sr.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #C2SR = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i, j)->(i mod 1024, i floordiv 1024, j)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | // sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | %t_start0 = call @rtclock() : () -> f64 31 | %a2 = sparlay.convert (%a1): tensor to tensor 32 | // sparlay.printStorage (%a2): tensor 33 | %t_end0 = call @rtclock() : () -> f64 34 | %t_0 = arith.subf %t_end0, %t_start0: f64 35 | vector.print %t_0 : f64 36 | 37 | %a3 = sparlay.convert (%a2): tensor to tensor 38 | // sparlay.printStorage (%a3): tensor 39 | sparlay.check (%a3, %a_ori): tensor, tensor 40 | 41 | //Release the resources 42 | bufferization.dealloc_tensor %a_ori : tensor 43 | bufferization.dealloc_tensor %a3 : tensor 44 | return 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_csb.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #CSB = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i, j)->(i floordiv 2, j floordiv 3, i mod 2, j mod 3)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | %t_start0 = call @rtclock() : () -> f64 31 | %a2 = sparlay.convert (%a1): tensor to tensor 32 | sparlay.printStorage (%a2): tensor 33 | %t_end0 = call @rtclock() : () -> f64 34 | %t_0 = arith.subf %t_end0, %t_start0: f64 35 | vector.print %t_0 : f64 36 | 37 | %a3 = sparlay.convert (%a2): tensor to tensor 38 | sparlay.printStorage (%a3): tensor 39 | sparlay.check (%a3, %a_ori): tensor, tensor 40 | 41 | //Release the resources 42 | bufferization.dealloc_tensor %a_ori : tensor 43 | bufferization.dealloc_tensor %a3 : tensor 44 | return 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_csbcsr.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #CSBCSR = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i, j)->(i floordiv 2, j floordiv 3, i mod 2, j mod 3)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | 31 | %t_start0 = call @rtclock() : () -> f64 32 | %a2 = sparlay.convert (%a1): tensor to tensor 33 | sparlay.printStorage (%a2): tensor 34 | %t_end0 = call @rtclock() : () -> f64 35 | %t_0 = arith.subf %t_end0, %t_start0: f64 36 | vector.print %t_0 : f64 37 | 38 | %a3 = sparlay.convert (%a2): tensor to tensor 39 | sparlay.printStorage (%a3): tensor 40 | sparlay.check (%a3, %a_ori): tensor, tensor 41 | 42 | //Release the resources 43 | bufferization.dealloc_tensor %a_ori : tensor 44 | bufferization.dealloc_tensor %a3 : tensor 45 | return 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_csbdcsr.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #CSBDCSR = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i, j)->(i floordiv 2, j floordiv 3, i mod 2, j mod 3)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | 31 | %t_start0 = call @rtclock() : () -> f64 32 | %a2 = sparlay.convert (%a1): tensor to tensor 33 | sparlay.printStorage (%a2): tensor 34 | %t_end0 = call @rtclock() : () -> f64 35 | %t_0 = arith.subf %t_end0, %t_start0: f64 36 | vector.print %t_0 : f64 37 | 38 | %a3 = sparlay.convert (%a2): tensor to tensor 39 | sparlay.printStorage (%a3): tensor 40 | sparlay.check (%a3, %a_ori): tensor, tensor 41 | 42 | //Release the resources 43 | bufferization.dealloc_tensor %a_ori : tensor 44 | bufferization.dealloc_tensor %a3 : tensor 45 | return 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_dia1.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #DIA = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(j minus i, j)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | 31 | %t_start0 = call @rtclock() : () -> f64 32 | %a2 = sparlay.convert (%a1): tensor to tensor 33 | sparlay.printStorage (%a2): tensor 34 | %t_end0 = call @rtclock() : () -> f64 35 | %t_0 = arith.subf %t_end0, %t_start0: f64 36 | vector.print %t_0 : f64 37 | 38 | %a3 = sparlay.convert (%a2): tensor to tensor 39 | sparlay.printStorage (%a3): tensor 40 | sparlay.check (%a3, %a_ori): tensor, tensor 41 | 42 | //Release the resources 43 | bufferization.dealloc_tensor %a_ori : tensor 44 | bufferization.dealloc_tensor %a3 : tensor 45 | return 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_dia2.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #DIA = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(i minus j, i)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | 31 | %t_start0 = call @rtclock() : () -> f64 32 | %a2 = sparlay.convert (%a1): tensor to tensor 33 | sparlay.printStorage (%a2): tensor 34 | %t_end0 = call @rtclock() : () -> f64 35 | %t_0 = arith.subf %t_end0, %t_start0: f64 36 | vector.print %t_0 : f64 37 | 38 | %a3 = sparlay.convert (%a2): tensor to tensor 39 | sparlay.printStorage (%a3): tensor 40 | sparlay.check (%a3, %a_ori): tensor, tensor 41 | 42 | //Release the resources 43 | bufferization.dealloc_tensor %a_ori : tensor 44 | bufferization.dealloc_tensor %a3 : tensor 45 | return 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_dia3.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #DIA = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(i minus j, j)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | 31 | %t_start0 = call @rtclock() : () -> f64 32 | %a2 = sparlay.convert (%a1): tensor to tensor 33 | sparlay.printStorage (%a2): tensor 34 | %t_end0 = call @rtclock() : () -> f64 35 | %t_0 = arith.subf %t_end0, %t_start0: f64 36 | vector.print %t_0 : f64 37 | 38 | %a3 = sparlay.convert (%a2): tensor to tensor 39 | sparlay.printStorage (%a3): tensor 40 | sparlay.check (%a3, %a_ori): tensor, tensor 41 | 42 | //Release the resources 43 | bufferization.dealloc_tensor %a_ori : tensor 44 | bufferization.dealloc_tensor %a3 : tensor 45 | return 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_coo_to_dia4.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #DIA = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(j minus i, i)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | module { 15 | func.func private @rtclock() -> f64 16 | func.func private @getTensorFilename(index) -> (!Filename) 17 | 18 | //CHECK-LABEL: func.func @main 19 | func.func @main() { 20 | %i0 = arith.constant 0.0 : f32 21 | %c0 = arith.constant 0 : index 22 | %c1 = arith.constant 1 : index 23 | 24 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 25 | 26 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 27 | // sparlay.printStorage (%a_ori): tensor 28 | %a1 = sparlay.copy (%a_ori): tensor to tensor 29 | 30 | 31 | %t_start0 = call @rtclock() : () -> f64 32 | %a2 = sparlay.convert (%a1): tensor to tensor 33 | // sparlay.printStorage (%a2): tensor 34 | %t_end0 = call @rtclock() : () -> f64 35 | %t_0 = arith.subf %t_end0, %t_start0: f64 36 | vector.print %t_0 : f64 37 | 38 | %t_start1 = call @rtclock() : () -> f64 39 | %a3 = sparlay.convert (%a2): tensor to tensor 40 | // sparlay.printStorage (%a3): tensor 41 | sparlay.check (%a3, %a_ori): tensor, tensor 42 | %t_end1 = call @rtclock() : () -> f64 43 | %t_1 = arith.subf %t_end1, %t_start1: f64 44 | vector.print %t_1 : f64 45 | 46 | //Release the resources 47 | bufferization.dealloc_tensor %a_ori : tensor 48 | bufferization.dealloc_tensor %a3 : tensor 49 | return 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_csr_to_csbdcsr.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #CSR = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | #CSBDCSR = #sparlay.encoding<{ 15 | crdMap = #sparlay.crd<(i, j)->(i floordiv 2, j floordiv 3, i mod 2, j mod 3)>, 16 | compressMap = #sparlay.compress 17 | }> 18 | 19 | module { 20 | func.func private @rtclock() -> f64 21 | func.func private @getTensorFilename(index) -> (!Filename) 22 | 23 | //CHECK-LABEL: func.func @main 24 | func.func @main() { 25 | %i0 = arith.constant 0.0 : f32 26 | %c0 = arith.constant 0 : index 27 | %c1 = arith.constant 1 : index 28 | 29 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 30 | 31 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 32 | sparlay.printStorage (%a_ori): tensor 33 | %a1 = sparlay.copy (%a_ori): tensor to tensor 34 | %a6 = sparlay.convert (%a1): tensor to tensor 35 | sparlay.printStorage (%a6): tensor 36 | 37 | 38 | %t_start0 = call @rtclock() : () -> f64 39 | %a2 = sparlay.convert (%a6): tensor to tensor 40 | sparlay.printStorage (%a2): tensor 41 | %t_end0 = call @rtclock() : () -> f64 42 | %t_0 = arith.subf %t_end0, %t_start0: f64 43 | vector.print %t_0 : f64 44 | 45 | %a3 = sparlay.convert (%a2): tensor to tensor 46 | sparlay.printStorage (%a3): tensor 47 | 48 | %a4 = sparlay.convert (%a3): tensor to tensor 49 | sparlay.check (%a4, %a_ori): tensor, tensor 50 | 51 | //Release the resources 52 | bufferization.dealloc_tensor %a_ori : tensor 53 | bufferization.dealloc_tensor %a4 : tensor 54 | return 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_csr_to_dia1.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #CSR = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | #DIA = #sparlay.encoding<{ 15 | crdMap = #sparlay.crd<(i,j)->(j minus i, j)>, 16 | compressMap = #sparlay.compress 17 | }> 18 | 19 | module { 20 | func.func private @rtclock() -> f64 21 | func.func private @getTensorFilename(index) -> (!Filename) 22 | 23 | //CHECK-LABEL: func.func @main 24 | func.func @main() { 25 | %i0 = arith.constant 0.0 : f32 26 | %c0 = arith.constant 0 : index 27 | %c1 = arith.constant 1 : index 28 | 29 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 30 | 31 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 32 | sparlay.printStorage (%a_ori): tensor 33 | %a1 = sparlay.copy (%a_ori): tensor to tensor 34 | 35 | %a2 = sparlay.convert (%a1): tensor to tensor 36 | sparlay.printStorage (%a2): tensor 37 | 38 | %t_start0 = call @rtclock() : () -> f64 39 | %a3 = sparlay.convert (%a2): tensor to tensor 40 | sparlay.printStorage (%a3): tensor 41 | %t_end0 = call @rtclock() : () -> f64 42 | %t_0 = arith.subf %t_end0, %t_start0: f64 43 | vector.print %t_0 : f64 44 | 45 | %a4 = sparlay.convert (%a3): tensor to tensor 46 | sparlay.printStorage (%a4): tensor 47 | 48 | %a5 = sparlay.convert (%a4): tensor to tensor 49 | sparlay.printStorage (%a5): tensor 50 | 51 | sparlay.check (%a5, %a_ori): tensor, tensor 52 | 53 | //Release the resources 54 | bufferization.dealloc_tensor %a_ori : tensor 55 | bufferization.dealloc_tensor %a5 : tensor 56 | return 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_dcsc_to_bcsr.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #DCSC = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(j,i)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | #BCSR = #sparlay.encoding<{ 15 | crdMap = #sparlay.crd<(i, j)->(i floordiv 4, j floordiv 4, i mod 4, j mod 4)>, 16 | compressMap = #sparlay.compress 17 | }> 18 | 19 | module { 20 | func.func private @rtclock() -> f64 21 | func.func private @getTensorFilename(index) -> (!Filename) 22 | 23 | //CHECK-LABEL: func.func @main 24 | func.func @main() { 25 | %i0 = arith.constant 0.0 : f32 26 | %c0 = arith.constant 0 : index 27 | %c1 = arith.constant 1 : index 28 | 29 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 30 | 31 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 32 | // sparlay.printStorage (%a_ori): tensor 33 | %a1 = sparlay.copy (%a_ori): tensor to tensor 34 | 35 | %a2 = sparlay.convert (%a1): tensor to tensor 36 | // sparlay.printStorage (%a2): tensor 37 | 38 | %t_start0 = call @rtclock() : () -> f64 39 | %a3 = sparlay.convert (%a2): tensor to tensor 40 | // sparlay.printStorage (%a3): tensor 41 | %t_end0 = call @rtclock() : () -> f64 42 | %t_0 = arith.subf %t_end0, %t_start0: f64 43 | vector.print %t_0 : f64 44 | 45 | %t_start1 = call @rtclock() : () -> f64 46 | %a4 = sparlay.convert (%a3): tensor to tensor 47 | // sparlay.printStorage (%a4): tensor 48 | %t_end1 = call @rtclock() : () -> f64 49 | %t_1 = arith.subf %t_end1, %t_start1: f64 50 | vector.print %t_1 : f64 51 | 52 | %a5 = sparlay.convert (%a4): tensor to tensor 53 | // sparlay.printStorage (%a5): tensor 54 | 55 | sparlay.check (%a5, %a_ori): tensor, tensor 56 | 57 | //Release the resources 58 | bufferization.dealloc_tensor %a_ori : tensor 59 | bufferization.dealloc_tensor %a5 : tensor 60 | return 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_dia1_to_csb.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #DIA = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(j minus i, j)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | #CSB = #sparlay.encoding<{ 15 | crdMap = #sparlay.crd<(i, j)->(i floordiv 64, j floordiv 64, i mod 64, j mod 64)>, 16 | compressMap = #sparlay.compress 17 | }> 18 | 19 | module { 20 | func.func private @rtclock() -> f64 21 | func.func private @getTensorFilename(index) -> (!Filename) 22 | 23 | //CHECK-LABEL: func.func @main 24 | func.func @main() { 25 | %i0 = arith.constant 0.0 : f32 26 | %c0 = arith.constant 0 : index 27 | %c1 = arith.constant 1 : index 28 | 29 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 30 | 31 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 32 | // sparlay.printStorage (%a_ori): tensor 33 | %a1 = sparlay.copy (%a_ori): tensor to tensor 34 | 35 | %a2 = sparlay.convert (%a1): tensor to tensor 36 | // sparlay.printStorage (%a2): tensor 37 | 38 | %t_start0 = call @rtclock() : () -> f64 39 | %a3 = sparlay.convert (%a2): tensor to tensor 40 | // sparlay.printStorage (%a3): tensor 41 | %t_end0 = call @rtclock() : () -> f64 42 | %t_0 = arith.subf %t_end0, %t_start0: f64 43 | vector.print %t_0 : f64 44 | 45 | %t_start1 = call @rtclock() : () -> f64 46 | %a4 = sparlay.convert (%a3): tensor to tensor 47 | // sparlay.printStorage (%a4): tensor 48 | %t_end1 = call @rtclock() : () -> f64 49 | %t_1 = arith.subf %t_end1, %t_start1: f64 50 | vector.print %t_1 : f64 51 | 52 | %a5 = sparlay.convert (%a4): tensor to tensor 53 | // sparlay.printStorage (%a5): tensor 54 | 55 | sparlay.check (%a5, %a_ori): tensor, tensor 56 | 57 | //Release the resources 58 | bufferization.dealloc_tensor %a_ori : tensor 59 | bufferization.dealloc_tensor %a5 : tensor 60 | return 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/conversion/unisparse_dia1_to_dia4.mlir: -------------------------------------------------------------------------------- 1 | 2 | !Filename = !llvm.ptr 3 | 4 | #COO = #sparlay.encoding<{ 5 | crdMap = #sparlay.crd<(i,j)->(i,j)>, 6 | compressMap = #sparlay.compress 7 | }> 8 | 9 | #DIA = #sparlay.encoding<{ 10 | crdMap = #sparlay.crd<(i,j)->(i minus j, j)>, 11 | compressMap = #sparlay.compress 12 | }> 13 | 14 | #DIAA = #sparlay.encoding<{ 15 | crdMap = #sparlay.crd<(i,j)->(j minus i, i)>, 16 | compressMap = #sparlay.compress 17 | }> 18 | 19 | module { 20 | func.func private @rtclock() -> f64 21 | func.func private @getTensorFilename(index) -> (!Filename) 22 | 23 | //CHECK-LABEL: func.func @main 24 | func.func @main() { 25 | %i0 = arith.constant 0.0 : f32 26 | %c0 = arith.constant 0 : index 27 | %c1 = arith.constant 1 : index 28 | 29 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 30 | 31 | %a_ori = sparlay.fromFile (%fileName) : !Filename to tensor 32 | sparlay.printStorage (%a_ori): tensor 33 | %a1 = sparlay.copy (%a_ori): tensor to tensor 34 | %a2 = sparlay.convert (%a1): tensor to tensor 35 | 36 | %t_start0 = call @rtclock() : () -> f64 37 | %a3 = sparlay.convert (%a2): tensor to tensor 38 | sparlay.printStorage (%a3): tensor 39 | %t_end0 = call @rtclock() : () -> f64 40 | %t_0 = arith.subf %t_end0, %t_start0: f64 41 | vector.print %t_0 : f64 42 | 43 | %t_start1 = call @rtclock() : () -> f64 44 | %a4 = sparlay.convert (%a3): tensor to tensor 45 | sparlay.printStorage (%a4): tensor 46 | %t_end1 = call @rtclock() : () -> f64 47 | %t_1 = arith.subf %t_end1, %t_start1: f64 48 | vector.print %t_1 : f64 49 | 50 | %a5 = sparlay.convert (%a4): tensor to tensor 51 | sparlay.printStorage (%a5): tensor 52 | sparlay.check (%a5, %a_ori): tensor, tensor 53 | 54 | //Release the resources 55 | bufferization.dealloc_tensor %a_ori : tensor 56 | bufferization.dealloc_tensor %a5: tensor 57 | return 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /test/UniSparse/FormatPreprocess/convert-perf-all.mlir: -------------------------------------------------------------------------------- 1 | // unisparse-opt test/UniSparse/convert-perf-all.mlir -lower-format-conversion -lower-struct -dce | \ 2 | // mlir-opt -convert-vector-to-scf --convert-scf-to-cf --tensor-bufferize \ 3 | // --scf-bufferize --func-bufferize --finalizing-bufferize --convert-vector-to-llvm \ 4 | // --convert-memref-to-llvm --convert-cf-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts | \ 5 | // mlir-translate -mlir-to-llvmir | opt -O3 -S | llc -O3 -relocation-model=pic -filetype=obj -o 1.o 6 | 7 | // clang++ 1.o -L$SPLHOME/build/lib -lmlir_unisparse_runner_utils \ 8 | // -L$LLVMHOME/build/lib -lmlir_runner_utils -lmlir_c_runner_utils -o exec_all 9 | 10 | // ./exec_all 11 | 12 | // RUN: unisparse-opt %s -lower-format-conversion -lower-struct -dce | FileCheck %s 13 | 14 | !Filename = !llvm.ptr 15 | 16 | #COO = #unisparse.encoding<{ 17 | crdMap = #unisparse.crd<(i,j)->(i,j)>, 18 | compressMap = #unisparse.compress 19 | }> 20 | 21 | #CSR = #unisparse.encoding<{ 22 | crdMap = #unisparse.crd<(i,j)->(i,j)>, 23 | compressMap = #unisparse.compress 24 | }> 25 | 26 | #DCSR = #unisparse.encoding<{ 27 | crdMap = #unisparse.crd<(i,j)->(i,j)>, 28 | compressMap = #unisparse.compress 29 | }> 30 | 31 | #CSC = #unisparse.encoding<{ 32 | crdMap = #unisparse.crd<(i,j)->(j,i)>, 33 | compressMap = #unisparse.compress 34 | }> 35 | 36 | #DCSC = #unisparse.encoding<{ 37 | crdMap = #unisparse.crd<(i,j)->(j,i)>, 38 | compressMap = #unisparse.compress 39 | }> 40 | 41 | #CSB = #unisparse.encoding<{ 42 | crdMap = #unisparse.crd<(i,j)->(i floordiv 2, j floordiv 3, i mod 2, j mod 3)>, 43 | compressMap = #unisparse.compress 44 | }> 45 | 46 | #DIA = #unisparse.encoding<{ 47 | crdMap = #unisparse.crd<(i,j)->(j minus i,i)>, 48 | compressMap = #unisparse.compress 49 | }> 50 | 51 | module { 52 | func.func private @getTensorFilename(index) -> (!Filename) 53 | //CHECK-LABEL: func.func @main 54 | func.func @main() { 55 | %i0 = arith.constant 0: index 56 | %fileName = call @getTensorFilename(%i0) : (index) -> (!Filename) 57 | %A_1 = unisparse.fromFile (%fileName) : !Filename to tensor 58 | %A_ori = unisparse.copy (%A_1): tensor to tensor 59 | unisparse.tic() 60 | %A_2 = unisparse.convert (%A_1): tensor to tensor 61 | unisparse.toc() 62 | %A_3 = unisparse.convert (%A_2) : tensor to tensor 63 | unisparse.tic() 64 | %A_4 = unisparse.convert (%A_3): tensor to tensor 65 | unisparse.toc() 66 | %A_5 = unisparse.convert (%A_4): tensor to tensor 67 | unisparse.tic() 68 | %A_6 = unisparse.convert (%A_5): tensor to tensor 69 | unisparse.toc() 70 | %A_7 = unisparse.convert (%A_6): tensor to tensor 71 | unisparse.tic() 72 | %A_8 = unisparse.convert (%A_7): tensor to tensor 73 | unisparse.toc() 74 | unisparse.tic() 75 | %A_9 = unisparse.convert (%A_8): tensor to tensor 76 | unisparse.toc() 77 | %A_10 = unisparse.convert (%A_9): tensor to tensor 78 | unisparse.check (%A_10, %A_ori): tensor, tensor 79 | return 80 | } 81 | } -------------------------------------------------------------------------------- /test/UniSparse/IR/linalg.mlir: -------------------------------------------------------------------------------- 1 | // unisparse-opt test/UniSparse/linalg.mlir -unisparse-codegen 2 | 3 | !Filename = !llvm.ptr 4 | 5 | #COO = #unisparse.encoding<{ 6 | crdMap = #unisparse.crd<(i,j)->(i,j)>, 7 | compressMap = #unisparse.compress 8 | }> 9 | 10 | #CSR = #unisparse.encoding<{ 11 | crdMap = #unisparse.crd<(i,j)->(i,j)>, 12 | compressMap = #unisparse.compress 13 | }> 14 | 15 | #CSC = #unisparse.encoding<{ 16 | crdMap = #unisparse.crd<(i,j)->(j,i)>, 17 | compressMap = #unisparse.compress 18 | }> 19 | 20 | #DIA = #unisparse.encoding<{ 21 | crdMap = #unisparse.crd<(i,j)->(j minus i,i)>, 22 | compressMap = #unisparse.compress 23 | }> 24 | 25 | #matvec = { 26 | indexing_maps = [ 27 | affine_map<(i,j) -> (i,j)>, // A 28 | affine_map<(i,j) -> (j)>, // b 29 | affine_map<(i,j) -> (i)> // x (out) 30 | ], 31 | iterator_types = ["parallel", "reduction"], 32 | doc = "X(i) += A(i,j) * B(j)" 33 | } 34 | 35 | // 36 | // Integration test that lowers a kernel annotated as sparse to 37 | // actual sparse code, initializes a matching sparse storage scheme 38 | // from file, and runs the resulting code with the JIT compiler. 39 | // 40 | module { 41 | // 42 | // A kernel that multiplies a sparse matrix A with a dense vector b 43 | // into a dense vector x. 44 | // 45 | func.func @kernel_matvec(%arga: tensor, 46 | %argb: tensor, 47 | %argx: tensor) 48 | -> tensor { 49 | %0 = linalg.generic #matvec 50 | ins(%arga, %argb: tensor, tensor) 51 | outs(%argx: tensor) { 52 | ^bb(%a: i32, %b: i32, %x: i32): 53 | %0 = arith.muli %a, %b : i32 54 | %1 = arith.addi %x, %0 : i32 55 | linalg.yield %1 : i32 56 | } -> tensor 57 | return %0 : tensor 58 | } 59 | 60 | func.func private @getTensorFilename(index) -> (!Filename) 61 | 62 | // 63 | // Main driver that reads matrix from file and calls the sparse kernel. 64 | // 65 | func.func @entry() { 66 | %i0 = arith.constant 0 : i32 67 | %c0 = arith.constant 0 : index 68 | %c1 = arith.constant 1 : index 69 | %c4 = arith.constant 4 : index 70 | %c256 = arith.constant 256 : index 71 | 72 | // Read the sparse matrix from file, construct sparse storage. 73 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 74 | %a_1 = unisparse.fromFile (%fileName): !llvm.ptr to tensor 75 | %a = unisparse.convert (%a_1): tensor to tensor 76 | 77 | // Initialize dense vectors. 78 | %init_256 = bufferization.alloc_tensor(%c256) : tensor 79 | %b = scf.for %i = %c0 to %c256 step %c1 iter_args(%t = %init_256) -> tensor { 80 | %k = arith.addi %i, %c1 : index 81 | %j = arith.index_cast %k : index to i32 82 | %t2 = tensor.insert %j into %t[%i] : tensor 83 | scf.yield %t2 : tensor 84 | } 85 | %init_4 = bufferization.alloc_tensor(%c4) : tensor 86 | %x = scf.for %i = %c0 to %c4 step %c1 iter_args(%t = %init_4) -> tensor { 87 | %t2 = tensor.insert %i0 into %t[%i] : tensor 88 | scf.yield %t2 : tensor 89 | } 90 | 91 | 92 | 93 | // Call kernel. 94 | %0 = call @kernel_matvec(%a, %b, %x) 95 | : (tensor, tensor, tensor) -> tensor 96 | 97 | // Print the result for verification. 98 | // 99 | // CHECK: ( 889, 1514, -21, -3431 ) 100 | // 101 | %v = vector.transfer_read %0[%c0], %i0: tensor, vector<4xi32> 102 | vector.print %v : vector<4xi32> 103 | 104 | // Release the resources. 105 | bufferization.dealloc_tensor %a : tensor 106 | 107 | return 108 | } 109 | } -------------------------------------------------------------------------------- /test/UniSparse/IR/to-ops.mlir: -------------------------------------------------------------------------------- 1 | // unisparse-opt test/UniSparse/to-ops.mlir -lower-struct-convert -lower-struct -dce -lower-format-conversion | \ 2 | // mlir-opt -convert-vector-to-scf --convert-scf-to-cf --arith-bufferize --tensor-bufferize \ 3 | // --scf-bufferize --func-bufferize --finalizing-bufferize --convert-vector-to-llvm \ 4 | // --convert-memref-to-llvm --convert-cf-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts | \ 5 | // mlir-translate -mlir-to-llvmir | opt -O3 -S | llc -O3 -relocation-model=pic -filetype=obj -o 1.o 6 | 7 | // clang++ 1.o -L$SPLHOME/build/lib -lmlir_unisparse_runner_utils \ 8 | // -L$LLVMHOME/build/lib -lmlir_runner_utils -lmlir_c_runner_utils -o exec 9 | 10 | // ./exec 11 | 12 | // RUN: unisparse-opt %s -lower-struct-convert -lower-struct -dce -lower-format-conversion | FileCheck %s 13 | 14 | !Filename = !llvm.ptr 15 | 16 | #COO = #unisparse.encoding<{ 17 | crdMap = #unisparse.crd<(i,j)->(i,j)>, 18 | compressMap = #unisparse.compress 19 | }> 20 | 21 | #DCSR = #unisparse.encoding<{ 22 | crdMap = #unisparse.crd<(i,j)->(i,j)>, 23 | compressMap = #unisparse.compress 24 | }> 25 | 26 | module { 27 | //CHECK-LABEL: func.func private @getSize(!llvm.ptr, index) -> index attributes {llvm.emit_c_interface} 28 | //CHECK-LABEL: func.func private @getValue(!llvm.ptr, index) -> memref<9xf32> attributes {llvm.emit_c_interface} 29 | //CHECK-LABEL: func.func private @getPtr(!llvm.ptr, index) -> memref<7xi32> attributes {llvm.emit_c_interface} 30 | //CHECK-LABEL: func.func private @getCrd(!llvm.ptr, index) -> memref<6xi32> attributes {llvm.emit_c_interface} 31 | //CHECK-LABEL: func.func private @sptFuse(!llvm.ptr, i32) -> !llvm.ptr attributes {llvm.emit_c_interface} 32 | //CHECK-LABEL: func.func private @sptFromFile(!llvm.ptr) -> !llvm.ptr attributes {llvm.emit_c_interface} 33 | //CHECK-LABEL: func.func private @getTensorFilename(index) -> !llvm.ptr 34 | func.func private @getTensorFilename(index) -> (!Filename) 35 | func.func @main() { 36 | %i0 = arith.constant 0: index 37 | %fileName = call @getTensorFilename(%i0) : (index) -> (!Filename) 38 | %A0 = unisparse.fromFile (%fileName): !llvm.ptr to tensor<7x7xf32, #COO> 39 | %A1 = unisparse.convert (%A0): tensor<7x7xf32, #COO> to tensor<7x7xf32, #DCSR> 40 | //CHECK: %4 = call @getPtr(%2, %c0) : (!llvm.ptr, index) -> memref<7xi32> 41 | //CHECK: %5 = call @getValue(%2, %c0) : (!llvm.ptr, index) -> memref<9xf32> 42 | //CHECK: %6 = call @getSize(%2, %c0) : (!llvm.ptr, index) -> index 43 | %crd = unisparse.crd %A1, %i0: tensor<7x7xf32, #DCSR> to memref<6xi32> 44 | %ptr = unisparse.ptr %A1, %i0: tensor<7x7xf32, #DCSR> to memref<7xi32> 45 | %value = unisparse.value %A1, %i0: tensor<7x7xf32, #DCSR> to memref<9xf32> 46 | %size = unisparse.size %A1, %i0: tensor<7x7xf32, #DCSR> to index 47 | %vec_crd = vector.load %crd[%i0]: memref<6xi32>, vector<6xi32> 48 | %vec_ptr = vector.load %ptr[%i0]: memref<7xi32>, vector<7xi32> 49 | %vec_value = vector.load %value[%i0]: memref<9xf32>, vector<9xf32> 50 | vector.print %size: index 51 | vector.print %vec_crd: vector<6xi32> 52 | vector.print %vec_ptr: vector<7xi32> 53 | vector.print %vec_value: vector<9xf32> 54 | return 55 | } 56 | } -------------------------------------------------------------------------------- /test/UniSparse/IR/unisparse-attr.mlir: -------------------------------------------------------------------------------- 1 | // RUN: unisparse-opt %s | FileCheck %s 2 | 3 | // #1 = #unisparse.encoding<{ 4 | // compressMap = #unisparse.compress, 5 | // crdMap = #unisparse.crd<(i,j,k)[s0,s1]->(indirect (i+j minus s0)*4 mod 7, (k + (minus i)) floordiv s1)> 6 | // }> 7 | 8 | #2 = #unisparse.encoding<{ 9 | compressMap = #unisparse.compress, 10 | crdMap = #unisparse.crd<(i,j)->(j,i)> 11 | }> 12 | 13 | #3 = #unisparse.encoding<{ 14 | compressMap = #unisparse.compress, 15 | crdMap = #unisparse.crd<(i,j,k)[s0,s1]->(indirect(i,j), indirect (j), (k + (minus i)) floordiv s1)>, 16 | indirectFunc = #unisparse.indirect<{ 17 | sumVal = #unisparse.sum 1 | otherwise -> 0>, 18 | enumVal = #unisparse.enumerate sumVal | otherwise -> 0>, 19 | reorderVal = #unisparse.reorder, // map: original matrix A -> output A' [0, 1] 20 | schedVal = #unisparse.schedule //list[[]] -> list[] 21 | }> 22 | }> 23 | 24 | //CHECK-LABEL: func.func private @F 25 | // func.func private @F(%arg0: tensor) -> () 26 | 27 | //CHECK-LABEL: func.func private @G 28 | func.func private @G(%arg1: tensor) -> () 29 | 30 | func.func private @H(%arg2: tensor) -> () 31 | // #2 = #unisparse.encoding<{ 32 | // primaryMap = affine_map<(a1,a2,a3)->(a1)>, 33 | // secondaryMap = #unisparse.affine<(a2,a3)->(trim a2)> 34 | // }> 35 | 36 | // #3 = #unisparse.encoding<{ 37 | // primaryMap = affine_map<(i,j,k)->(j,k,i)>, 38 | // secondaryMap = #unisparse.affine<()->()> 39 | // }> 40 | 41 | // #4 = #unisparse.encoding<{ 42 | // secondaryMap = #unisparse.affine<(a1, a2)->(fuse fuse fuse trim a2, a1)>, 43 | // bitWidth=3 44 | // }> 45 | 46 | // func private @F1(%arg0: tensor) -> (tensor) 47 | 48 | // func private @F2(%arg0: tensor) -> () 49 | 50 | // func private @F3(%arg0: tensor) -> () 51 | 52 | // //failed 53 | // #100 = #unisparse.encoding<{ 54 | // secondaryMap = #unisparse.affine<()->(trim d1)> 55 | // }> 56 | 57 | // func private @F100(%arg0: tensor) -> () 58 | -------------------------------------------------------------------------------- /test/UniSparse/KernelGen/CPU/unisparse_coo_spmv_F32.mlir: -------------------------------------------------------------------------------- 1 | // unisparse-opt ./unisparse_coo_spmv_F32.mlir -unisparse-codegen -lower-format-conversion -lower-struct -dce | \ 2 | // mlir-opt -one-shot-bufferize="bufferize-function-boundaries=1 allow-return-allocs unknown-type-conversion=identity-layout-map function-boundary-type-conversion=identity-layout-map" \ 3 | // -finalizing-bufferize -convert-linalg-to-loops -convert-vector-to-scf -convert-scf-to-cf -lower-affine \ 4 | // -convert-vector-to-llvm -convert-memref-to-llvm -convert-complex-to-standard -convert-math-to-llvm \ 5 | // -convert-math-to-libm -convert-complex-to-libm -convert-complex-to-llvm -convert-func-to-llvm \ 6 | // -reconcile-unrealized-casts | mlir-translate -mlir-to-llvmir | opt -O3 -S | llc -O3 -relocation-model=pic -filetype=obj -o coo_spmv_F32.o 7 | 8 | // clang++ coo_spmv_F32.o -L$SPLHOME/build/lib -lmlir_unisparse_runner_utils \ 9 | // -L$LLVMHOME/build/lib -lmlir_runner_utils -lmlir_c_runner_utils -o coo_spmv_F32 10 | 11 | // ./coo_spmv_F32 12 | 13 | !Filename = !llvm.ptr 14 | 15 | #COO = #unisparse.encoding<{ 16 | crdMap = #unisparse.crd<(i,j)->(i,j)>, 17 | compressMap = #unisparse.compress 18 | }> 19 | 20 | #trait1 = { 21 | indexing_maps = [ 22 | affine_map<(i,j) -> (i, j)>, // A 23 | affine_map<(i,j) -> (j)>, // B 24 | affine_map<(i,j) -> (i)> // X (out) 25 | ], 26 | iterator_types = ["parallel", "reduction"], 27 | doc = "X(i) =+ A(i,j) * B(j)" 28 | } 29 | 30 | module { 31 | func.func private @rtclock() -> f64 32 | func.func private @getTensorFilename(index) -> (!Filename) 33 | func.func private @getTensorDim(!Filename, index) -> (index) 34 | func.func private @printU64(index) -> () 35 | 36 | //CHECK-LABEL: func.func @main 37 | func.func @main() { 38 | %i0 = arith.constant 0.0 : f32 39 | %c0 = arith.constant 0 : index 40 | %c1 = arith.constant 1 : index 41 | 42 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 43 | 44 | %A_0 = unisparse.fromFile (%fileName) : !Filename to tensor 45 | %dim0 = call @getTensorDim(%fileName, %c0) : (!Filename, index) -> (index) 46 | %dim1 = call @getTensorDim(%fileName, %c1) : (!Filename, index) -> (index) 47 | call @printU64(%dim0) : (index) -> () 48 | call @printU64(%dim1) : (index) -> () 49 | // %dim0 = tensor.dim %A_0, %c0 : tensor 50 | // %dim1 = tensor.dim %A_0, %c1 : tensor 51 | 52 | // Initialize vector matrix. 53 | %init_256_4 = memref.alloc(%dim1) : memref 54 | %b = scf.for %i = %c0 to %dim1 step %c1 iter_args(%t = %init_256_4) -> memref { 55 | %k0 = arith.muli %i, %c1 : index 56 | %k1 = arith.index_cast %k0 : index to i32 57 | %k = arith.sitofp %k1 : i32 to f32 58 | memref.store %k, %t[%i] : memref 59 | scf.yield %t : memref 60 | } 61 | 62 | %o0_4_4 = memref.alloc(%dim0) : memref 63 | %o0 = scf.for %i = %c0 to %dim0 step %c1 iter_args(%t = %o0_4_4) -> memref { 64 | memref.store %i0, %t[%i] : memref 65 | scf.yield %t : memref 66 | } 67 | 68 | %t_start4 = call @rtclock() : () -> f64 69 | %0 = unisparse.coo_spmv %A_0, %init_256_4, %o0_4_4: tensor, memref, memref to memref 70 | %t_end4 = call @rtclock() : () -> f64 71 | %t_4 = arith.subf %t_end4, %t_start4: f64 72 | vector.print %t_4 : f64 73 | %v1 = vector.transfer_read %init_256_4[%c0], %i0: memref, vector<4xf32> 74 | vector.print %v1 : vector<4xf32> 75 | %v0 = vector.transfer_read %0[%c0], %i0: memref, vector<4xf32> 76 | vector.print %v0 : vector<4xf32> 77 | 78 | //Release the resources 79 | bufferization.dealloc_tensor %A_0 : tensor 80 | // bufferization.dealloc_tensor %init_256_4 : tensor 81 | // bufferization.dealloc_tensor %o0_4_4 : tensor 82 | return 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /test/UniSparse/KernelGen/CPU/unisparse_coo_spmv_F64.mlir: -------------------------------------------------------------------------------- 1 | // unisparse-opt ./unisparse_coo_spmv_F64.mlir -unisparse-codegen -lower-format-conversion -lower-struct -dce | \ 2 | // mlir-opt -one-shot-bufferize="bufferize-function-boundaries=1 allow-return-allocs unknown-type-conversion=identity-layout-map function-boundary-type-conversion=identity-layout-map" \ 3 | // -finalizing-bufferize -convert-linalg-to-loops -convert-vector-to-scf -convert-scf-to-cf -lower-affine \ 4 | // -convert-vector-to-llvm -convert-memref-to-llvm -convert-complex-to-standard -convert-math-to-llvm \ 5 | // -convert-math-to-libm -convert-complex-to-libm -convert-complex-to-llvm -convert-func-to-llvm \ 6 | // -reconcile-unrealized-casts | mlir-translate -mlir-to-llvmir | opt -O3 -S | llc -O3 -relocation-model=pic -filetype=obj -o coo_spmv_F64.o 7 | 8 | // clang++ coo_spmv_F64.o -L$SPLHOME/build/lib -lmlir_unisparse_runner_utils \ 9 | // -L$LLVMHOME/build/lib -lmlir_runner_utils -lmlir_c_runner_utils -o coo_spmv_F64 10 | 11 | // ./coo_spmv_F64 12 | 13 | !Filename = !llvm.ptr 14 | 15 | #COO = #unisparse.encoding<{ 16 | crdMap = #unisparse.crd<(i,j)->(i,j)>, 17 | compressMap = #unisparse.compress 18 | }> 19 | 20 | #trait1 = { 21 | indexing_maps = [ 22 | affine_map<(i,j) -> (i, j)>, // A 23 | affine_map<(i,j) -> (j)>, // B 24 | affine_map<(i,j) -> (i)> // X (out) 25 | ], 26 | iterator_types = ["parallel", "reduction"], 27 | doc = "X(i) =+ A(i,j) * B(j)" 28 | } 29 | 30 | module { 31 | func.func private @rtclock() -> f64 32 | func.func private @getTensorFilename(index) -> (!Filename) 33 | func.func private @getTensorDim(!Filename, index) -> (index) 34 | func.func private @printU64(index) -> () 35 | 36 | //CHECK-LABEL: func.func @main 37 | func.func @main() { 38 | %i0 = arith.constant 0.0 : f64 39 | %c0 = arith.constant 0 : index 40 | %c1 = arith.constant 1 : index 41 | 42 | %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename) 43 | 44 | %A_0 = unisparse.fromFile (%fileName) : !Filename to tensor 45 | %dim0 = call @getTensorDim(%fileName, %c0) : (!Filename, index) -> (index) 46 | %dim1 = call @getTensorDim(%fileName, %c1) : (!Filename, index) -> (index) 47 | call @printU64(%dim0) : (index) -> () 48 | call @printU64(%dim1) : (index) -> () 49 | // %dim0 = tensor.dim %A_0, %c0 : tensor 50 | // %dim1 = tensor.dim %A_0, %c1 : tensor 51 | 52 | // Initialize vector matrix. 53 | %init_256_4 = memref.alloc(%dim1) : memref 54 | %b = scf.for %i = %c0 to %dim1 step %c1 iter_args(%t = %init_256_4) -> memref { 55 | %k0 = arith.muli %i, %c1 : index 56 | %k1 = arith.index_cast %k0 : index to i32 57 | %k = arith.sitofp %k1 : i32 to f64 58 | memref.store %k, %t[%i] : memref 59 | scf.yield %t : memref 60 | } 61 | 62 | %o0_4_4 = memref.alloc(%dim0) : memref 63 | %o0 = scf.for %i = %c0 to %dim0 step %c1 iter_args(%t = %o0_4_4) -> memref { 64 | memref.store %i0, %t[%i] : memref 65 | scf.yield %t : memref 66 | } 67 | 68 | %t_start4 = call @rtclock() : () -> f64 69 | %0 = unisparse.coo_spmv %A_0, %init_256_4, %o0_4_4: tensor, memref, memref to memref 70 | %t_end4 = call @rtclock() : () -> f64 71 | %t_4 = arith.subf %t_end4, %t_start4: f64 72 | vector.print %t_4 : f64 73 | %v1 = vector.transfer_read %init_256_4[%c0], %i0: memref, vector<4xf64> 74 | vector.print %v1 : vector<4xf64> 75 | %v0 = vector.transfer_read %0[%c0], %i0: memref, vector<4xf64> 76 | vector.print %v0 : vector<4xf64> 77 | 78 | //Release the resources 79 | bufferization.dealloc_tensor %A_0 : tensor 80 | // bufferization.dealloc_tensor %init_256_4 : tensor 81 | // bufferization.dealloc_tensor %o0_4_4 : tensor 82 | return 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /test/lit.cfg.py: -------------------------------------------------------------------------------- 1 | # -*- Python -*- 2 | 3 | import os 4 | import platform 5 | import re 6 | import subprocess 7 | import tempfile 8 | 9 | import lit.formats 10 | import lit.util 11 | 12 | from lit.llvm import llvm_config 13 | from lit.llvm.subst import ToolSubst 14 | from lit.llvm.subst import FindTool 15 | 16 | # Configuration file for the 'lit' test runner. 17 | 18 | # name: The name of this test suite. 19 | config.name = 'UNISPARSE' 20 | 21 | config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) 22 | 23 | # suffixes: A list of file extensions to treat as test files. 24 | config.suffixes = ['.mlir'] 25 | 26 | # test_source_root: The root path where tests are located. 27 | config.test_source_root = os.path.dirname(__file__) 28 | 29 | # test_exec_root: The root path where tests should be run. 30 | config.test_exec_root = os.path.join(config.unisparse_obj_root, 'test') 31 | 32 | config.substitutions.append(('%PATH%', config.environment['PATH'])) 33 | config.substitutions.append(('%shlibext', config.llvm_shlib_ext)) 34 | 35 | llvm_config.with_system_environment( 36 | ['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP']) 37 | 38 | llvm_config.use_default_substitutions() 39 | 40 | # excludes: A list of directories to exclude from the testsuite. The 'Inputs' 41 | # subdirectories contain auxiliary inputs for various tests in their parent 42 | # directories. 43 | config.excludes = ['Inputs', 'Examples', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt'] 44 | 45 | # test_source_root: The root path where tests are located. 46 | config.test_source_root = os.path.dirname(__file__) 47 | 48 | # test_exec_root: The root path where tests should be run. 49 | config.test_exec_root = os.path.join(config.unisparse_obj_root, 'test') 50 | config.unisparse_tools_dir = os.path.join(config.unisparse_obj_root, 'bin') 51 | 52 | # Tweak the PATH to include the tools dir. 53 | llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True) 54 | 55 | tool_dirs = [config.unisparse_tools_dir, config.llvm_tools_dir] 56 | tools = [ 57 | 'unisparse-opt', 58 | 'unisparse-translate' 59 | ] 60 | 61 | llvm_config.add_tool_substitutions(tools, tool_dirs) 62 | -------------------------------------------------------------------------------- /test/lit.site.cfg.py.in: -------------------------------------------------------------------------------- 1 | @LIT_SITE_CFG_IN_HEADER@ 2 | 3 | import sys 4 | 5 | config.host_triple = "@LLVM_HOST_TRIPLE@" 6 | config.target_triple = "@TARGET_TRIPLE@" 7 | config.llvm_src_root = "@LLVM_SOURCE_DIR@" 8 | config.llvm_obj_root = "@LLVM_BINARY_DIR@" 9 | config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" 10 | config.llvm_lib_dir = "@LLVM_LIBS_DIR@" 11 | config.llvm_shlib_dir = "@SHLIBDIR@" 12 | config.llvm_shlib_ext = "@SHLIBEXT@" 13 | config.llvm_exe_ext = "@EXEEXT@" 14 | config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" 15 | config.python_executable = "@PYTHON_EXECUTABLE@" 16 | config.gold_executable = "@GOLD_EXECUTABLE@" 17 | config.ld64_executable = "@LD64_EXECUTABLE@" 18 | config.enable_shared = @ENABLE_SHARED@ 19 | config.enable_assertions = @ENABLE_ASSERTIONS@ 20 | config.targets_to_build = "@TARGETS_TO_BUILD@" 21 | config.native_target = "@LLVM_NATIVE_ARCH@" 22 | config.llvm_bindings = "@LLVM_BINDINGS@".split(' ') 23 | config.host_os = "@HOST_OS@" 24 | config.host_cc = "@HOST_CC@" 25 | config.host_cxx = "@HOST_CXX@" 26 | config.enable_libcxx = "@LLVM_ENABLE_LIBCXX@" 27 | # Note: ldflags can contain double-quoted paths, so must use single quotes here. 28 | config.host_ldflags = '@HOST_LDFLAGS@' 29 | config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@" 30 | config.llvm_host_triple = '@LLVM_HOST_TRIPLE@' 31 | config.host_arch = "@HOST_ARCH@" 32 | config.unisparse_src_root = "@CMAKE_SOURCE_DIR@" 33 | config.unisparse_obj_root = "@CMAKE_BINARY_DIR@" 34 | 35 | # Support substitution of the tools_dir with user parameters. This is 36 | # used when we can't determine the tool dir at configuration time. 37 | try: 38 | config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params 39 | config.llvm_lib_dir = config.llvm_lib_dir % lit_config.params 40 | config.llvm_shlib_dir = config.llvm_shlib_dir % lit_config.params 41 | except KeyError: 42 | e = sys.exc_info()[1] 43 | key, = e.args 44 | lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key)) 45 | 46 | 47 | import lit.llvm 48 | lit.llvm.initialize(lit_config, config) 49 | 50 | # Let the main config do the real work. 51 | lit_config.load_config(config, "@CMAKE_SOURCE_DIR@/test/lit.cfg.py") 52 | -------------------------------------------------------------------------------- /unisparse-opt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) 2 | get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) 3 | set(LIBS 4 | ${dialect_libs} 5 | ${conversion_libs} 6 | MLIROptLib 7 | MLIRUniSparse 8 | ) 9 | add_llvm_executable(unisparse-opt unisparse-opt.cpp) 10 | 11 | llvm_update_compile_flags(unisparse-opt) 12 | target_link_libraries(unisparse-opt PRIVATE ${LIBS}) 13 | 14 | mlir_check_all_link_libraries(unisparse-opt) 15 | -------------------------------------------------------------------------------- /unisparse-translate/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | Support 3 | ) 4 | 5 | get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) 6 | get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) 7 | 8 | add_llvm_executable(unisparse-translate 9 | unisparse-translate.cpp 10 | ) 11 | llvm_update_compile_flags(unisparse-translate) 12 | target_link_libraries(unisparse-translate 13 | PRIVATE 14 | ${dialect_libs} 15 | ${translation_libs} 16 | MLIRIR 17 | MLIRParser 18 | MLIRPass 19 | MLIRSPIRVDialect 20 | MLIRTranslateLib 21 | MLIRSupport 22 | ) 23 | 24 | mlir_check_link_libraries(unisparse-translate) 25 | -------------------------------------------------------------------------------- /unisparse-translate/unisparse-translate.cpp: -------------------------------------------------------------------------------- 1 | //===- unisparse-translate.cpp ---------------------------------*- C++ -*-===// 2 | // 3 | // This file is licensed under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // 9 | // This is a command line utility that translates a file from/to MLIR using one 10 | // of the registered translations. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include "mlir/InitAllTranslations.h" 15 | #include "mlir/Support/LogicalResult.h" 16 | #include "mlir/Tools/mlir-translate/MlirTranslateMain.h" 17 | 18 | #include "IR/UniSparseDialect.h" 19 | 20 | int main(int argc, char **argv) { 21 | mlir::registerAllTranslations(); 22 | 23 | // TODO: Register unisparse translations here. 24 | 25 | return failed( 26 | mlir::mlirTranslateMain(argc, argv, "MLIR Translation Testing Tool")); 27 | } 28 | --------------------------------------------------------------------------------