diff --git a/.github/workflows/build-run-kernel-snake.yml b/.github/workflows/build-run-kernel-snake.yml index d9b80e72..d3af9d1f 100644 --- a/.github/workflows/build-run-kernel-snake.yml +++ b/.github/workflows/build-run-kernel-snake.yml @@ -20,4 +20,4 @@ jobs: working-directory: kernels/${{ matrix.kernel }} strategy: matrix: - kernel: [alloc, simple_copy, transform_copy, gemm, rescale, gemmini, streamer_alu] + kernel: [alloc, simple_copy, transform_copy, gemm, rescale, gemmini, streamer_alu, streamer_matmul] diff --git a/.github/workflows/build-run-kernel.yml b/.github/workflows/build-run-kernel.yml index c58f00f9..3cb113ef 100644 --- a/.github/workflows/build-run-kernel.yml +++ b/.github/workflows/build-run-kernel.yml @@ -20,4 +20,4 @@ jobs: working-directory: kernels/${{ matrix.kernel }} strategy: matrix: - kernel: [tiled_add, streamer_matmul] + kernel: [tiled_add] diff --git a/kernels/streamer_matmul/Makefile b/kernels/streamer_matmul/Makefile deleted file mode 100644 index 1e3e4afc..00000000 --- a/kernels/streamer_matmul/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -# Courtesy of Federico Ficarelli - -.DEFAULT_GOAL := all - -include ../../runtime/snax-gemmx.rules -include ../../runtime/Makefile.rules - -TESTS = -TESTS += quantized_matmul.x -TESTS += tiled_quantized_matmul.x - -SNAXOPTFLAGS = -p convert-linalg-to-kernel,insert-accfg-op{accelerator=snax_gemmx},dispatch-kernels,convert-linalg-to-stream,fuse-streaming-regions,snax-bufferize,alloc-to-global,set-memory-space,set-memory-layout,realize-memref-casts,insert-sync-barrier,dispatch-regions{nb_cores=2},convert-stream-to-snax-stream,convert-linalg-to-accfg,convert-accfg-to-csr,snax-copy-to-dma,memref-to-snax,snax-to-func,clear-memory-space - -CFLAGS += -std=gnu11 -CFLAGS += -Wall -Wextra - -quantized_matmul.mlir: quantized_matmul.py - $(PYTHON) quantized_matmul.py - -tiled_quantized_matmul.transform.mlir: tiled_quantized_matmul.py - $(PYTHON) tiled_quantized_matmul.py - -%.x: %.o main.o - $(LD) $(LDFLAGS) $^ -o $@ - -sim_%: % - rm -fr ./logs/ - $(VLTSIM) $< - -RUN = $(addprefix run_, $(TESTS)) -$(RUN): run_%: sim_% - mv logs $(subst sim_,,$<).logs - -all: $(TESTS) - -allrun: $(RUN) - -clean: - rm -fr *.mlir *.ll12 *.x *.o *.logs/ logs/ data.h data.c diff --git a/kernels/streamer_matmul/Snakefile b/kernels/streamer_matmul/Snakefile new file mode 100644 index 00000000..36ea7b47 --- /dev/null +++ b/kernels/streamer_matmul/Snakefile @@ -0,0 +1,83 @@ +from util.snake.configs import get_snax_gemmx_config + +config = get_snax_gemmx_config() +config["snaxoptflags"] = ",".join( + [ + "convert-linalg-to-kernel", + "insert-accfg-op{accelerator=snax_gemmx}", + "dispatch-kernels", + "convert-linalg-to-stream", + "fuse-streaming-regions", + "snax-bufferize", + "alloc-to-global", + "set-memory-space", + "set-memory-layout", + "realize-memref-casts", + "insert-sync-barrier", + "dispatch-regions{nb_cores=2}", + "convert-stream-to-snax-stream", + "convert-linalg-to-accfg", + "convert-accfg-to-csr", + "snax-copy-to-dma", + "memref-to-snax", + "snax-to-func", + "clear-memory-space", + ] +) + +config["mlirtransformflags"] = [ + "--pass-pipeline='builtin.module(transform-interpreter{debug-bind-trailing-args=linalg.quantized_matmul}, test-transform-dialect-erase-schedule)'" +] + + +module default_rules: + snakefile: + "../../util/snake/default_rules.smk" + config: + config + + +use rule * from default_rules as default_* + + +# Rules +rule all: + input: + "quantized_matmul.x", + "tiled_quantized_matmul.x", + run: + for item in input: + shell("{config[vltsim]} {item}") + + +rule generate_quantized_matmul: + output: + "quantized_matmul.mlir", + script: + "quantized_matmul.py" + + +rule generate_tiled_quantized_matmul: + output: + "tiled_quantized_matmul.transform.mlir", + script: + "tiled_quantized_matmul.py" + + +rule apply_transforms_mlir: + input: + "{file}.transform.mlir", + output: + "{file}.mlir", + shell: + "{config[mlir-opt]} {config[mlirtransformflags]} -o {output} {input}" + + +rule link_snax_binary: + input: + "{file}.o", + "main.o", + output: + "{file}.x", + shell: + "{config[ld]} {config[ldflags]} {input} -o {output}"