Skip to content

Commit

Permalink
Snakemake: Add support for transform-copy (#311)
Browse files Browse the repository at this point in the history
* Move transform_copy flow to snakemake

* Add snakefile for transform-copy

* Remove old makefile

* Fix typo

* Add all to running the snakemake experiments
  • Loading branch information
JosseVanDelm authored Dec 19, 2024
1 parent db2ea35 commit c523293
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 57 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-run-kernel-snake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
- name: Build and run kernels
run: pixi run snakemake -k -j `nproc`
run: pixi run snakemake -k -j `nproc` all
working-directory: kernels/${{ matrix.kernel }}
strategy:
matrix:
kernel: [alloc]
kernel: [alloc, transform_copy]
2 changes: 1 addition & 1 deletion .github/workflows/build-run-kernel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
working-directory: kernels/${{ matrix.kernel }}
strategy:
matrix:
kernel: [simple_copy, transform_copy, streamer_alu, tiled_add, streamer_matmul, gemmini, rescale, gemm]
kernel: [simple_copy, streamer_alu, tiled_add, streamer_matmul, gemmini, rescale, gemm]
46 changes: 0 additions & 46 deletions kernels/transform_copy/Makefile

This file was deleted.

72 changes: 72 additions & 0 deletions kernels/transform_copy/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from util.snake.configs import get_snax_mac_config

config = get_snax_mac_config()
config["snaxoptflags"] = ",".join(
[
"dispatch-kernels",
"set-memory-space",
"set-memory-layout",
"realize-memref-casts",
"reuse-memref-allocs",
"insert-sync-barrier",
"linalg-to-library-call",
"snax-copy-to-dma",
"memref-to-snax",
"snax-to-func",
"clear-memory-space",
]
)


module default_rules:
snakefile:
"../../util/snake/default_rules.smk"
config:
config


use rule * from default_rules as default_*


from gendata import create_files


# Rules
rule all:
input:
"transform_copy.x",
"transform_from_none.x",
"transform_from_strided.x",
run:
shell("{config[vltsim]} {input[0]} {input[0]}")
shell("{config[vltsim]} {input[1]} {input[1]}")
shell("{config[vltsim]} {input[2]} {input[2]}")


rule generate_data:
output:
"{folder}/data.c",
"{folder}/data.h",
run:
create_files(f"{wildcards.folder}/data")


rule compile_snax_binary:
input:
"{file}.o",
"main_{file}.o",
"{file}/data.o",
output:
"{file}.x",
shell:
"{config[ld]} {config[ldflags]} {input} -o {output}"


rule compile_main:
input:
"{file}/data.h",
"main.c",
output:
temp("main_{file}.o"),
shell:
"{config[cc]} {config[cflags]} -I./{wildcards.file} -c {input[1]} -o {output}"
12 changes: 4 additions & 8 deletions kernels/transform_copy/gendata.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
# simple script to generate inputs and expected outputs for simple_mult
from math import sqrt

import numpy as np

from util.gendata import create_data, create_header

if __name__ == "__main__":

def create_files(filename: str):
array_size = 64
A = np.linspace(1, array_size, array_size, dtype=np.int32)
B = np.reshape(A, [2, 4, 2, 4])
B = np.swapaxes(B, 1, 2)
B = B.flatten()
sizes = {"N": array_size, "N_sqrt": sqrt(array_size)}
variables = {"A": A, "B": B}
create_header("transform_copy/data.h", sizes, variables)
create_data("transform_copy/data.c", variables)
create_header("transform_from_none/data.h", sizes, variables)
create_data("transform_from_none/data.c", variables)
create_header("transform_from_strided/data.h", sizes, variables)
create_data("transform_from_strided/data.c", variables)
create_header(f"{filename}.h", sizes, variables)
create_data(f"{filename}.c", variables)

0 comments on commit c523293

Please sign in to comment.