Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a snitch_stream kernel for relu #62

Merged
merged 6 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kernels/relu/16x16xf64/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ TESTS += ssr.x
TESTS += ssr_frep.x
TESTS += ssr_frep_unroll.x
TESTS += linalg.x
TESTS += snitch_stream.x

include ../../Makefile.kernels
22 changes: 22 additions & 0 deletions kernels/relu/16x16xf64/snitch_stream.xdsl.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
riscv.assembly_section ".text" {
riscv.directive ".globl" "relu"
riscv.directive ".p2align" "2"
riscv_func.func @relu(%X : !riscv.reg<a0>, %Y : !riscv.reg<a1>) {
%X_moved = riscv.mv %X : (!riscv.reg<a0>) -> !riscv.reg<>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unallocated

%Y_moved = riscv.mv %Y : (!riscv.reg<a1>) -> !riscv.reg<>

%zero_int = riscv.get_register : () -> !riscv.reg<zero>
%zero_float = riscv.fcvt.d.w %zero_int : (!riscv.reg<zero>) -> !riscv.freg<ft3>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allocated in order not to clash with ft2, still haven't implemented that


%stride_pattern = "snitch_stream.stride_pattern"() {"ub" = [#int<16>, #int<16>], "strides" = [#int<128>, #int<8>], "dm" = #int<31>} : () -> !snitch_stream.stride_pattern_type
%X_stream = "snitch_stream.strided_read"(%X_moved, %stride_pattern) {"dm" = #int<0>, "rank" = #int<2>} : (!riscv.reg<>, !snitch_stream.stride_pattern_type) -> !stream.readable<!riscv.freg<ft0>>
%Y_stream = "snitch_stream.strided_write"(%Y_moved, %stride_pattern) {"dm" = #int<1>, "rank" = #int<2>} : (!riscv.reg<>, !snitch_stream.stride_pattern_type) -> !stream.writable<!riscv.freg<ft1>>
%count = riscv.li 256 : () -> !riscv.reg<>
"snitch_stream.generic"(%count, %X_stream, %Y_stream) <{"operandSegmentSizes" = array<i32: 1, 1, 1>}> ({
^0(%x : !riscv.freg<ft0>):
%res = riscv.fmax.d %x, %zero_float : (!riscv.freg<ft0>, !riscv.freg<ft3>) -> !riscv.freg<ft1>
snitch_stream.yield %res : !riscv.freg<ft1>
}) : (!riscv.reg<>, !stream.readable<!riscv.freg<ft0>>, !stream.writable<!riscv.freg<ft1>>) -> ()
riscv_func.return
}
}
9 changes: 8 additions & 1 deletion snitch/Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,21 @@ LDFLAGS += -lsnRuntime

# XDSL

XDSLOPT_PASSES =
XDSLOPT_PASSES =
XDSLOPT_PASSES += lower-affine
XDSLOPT_PASSES += convert-func-to-riscv-func
XDSLOPT_PASSES += convert-memref-to-riscv
XDSLOPT_PASSES += convert-arith-to-riscv
XDSLOPT_PASSES += convert-scf-to-riscv-scf
XDSLOPT_PASSES += dce
XDSLOPT_PASSES += reconcile-unrealized-casts
XDSLOPT_PASSES += snitch-allocate-registers
XDSLOPT_PASSES += convert-snitch-stream-to-snitch
XDSLOPT_PASSES += lower-snitch
XDSLOPT_PASSES += canonicalize
XDSLOPT_PASSES += riscv-scf-loop-range-folding
XDSLOPT_PASSES += canonicalize
XDSLOPT_PASSES += riscv-reduce-register-pressure
XDSLOPT_PASSES += riscv-allocate-registers
XDSLOPT_PASSES += canonicalize
XDSLOPT_PASSES += lower-riscv-func
Expand Down