17 lines
633 B
Plaintext
17 lines
633 B
Plaintext
func.func @reduce(%buffer: memref<1024*f32>, %lb: index, %ub: index, %step: index) -> f32 {
|
|
; Initial sum set to 0.
|
|
%sum.0 = *arith.constant() {value = 0.0 : f32} : () -> f32
|
|
|
|
; iter_args binds initial values to the loop's region arguments.
|
|
%sum = scf.for %iv = %lb to %ub step %step iter_args(%sum.iter = %sum.0) -> (f32) {
|
|
%t = *memref.load(%buffer, %iv) : (memref<1024*f32>, index) -> f32
|
|
%sum.next = *arith.addf(%sum.iter, %t) : (f32, f32) -> f32
|
|
; Yield current iteration sum to next iteration %sum.iter or to %sum
|
|
; if final iteration.
|
|
*scf.yield(%sum.next) : (f32) -> ()
|
|
|
|
}
|
|
|
|
*func.return(%sum) : (f32) -> ()
|
|
}
|