@@ -1954,6 +1954,70 @@ acc.reduction.recipe @reduction_add_memref_i32 : memref<i32> reduction_operator
19541954// CHECK-LABEL: acc.reduction.recipe @reduction_add_memref_i32
19551955// CHECK: memref.alloca
19561956
1957+ // -----
1958+
1959+ // Test reduction recipe with destroy region using dynamic memory allocation
1960+ acc.reduction.recipe @reduction_add_with_destroy : memref <?xf32 > reduction_operator <add > init {
1961+ ^bb0 (%arg0: memref <?xf32 >):
1962+ %cst = arith.constant 0.000000e+00 : f32
1963+ %c0 = arith.constant 0 : index
1964+ %size = memref.dim %arg0 , %c0 : memref <?xf32 >
1965+ %alloc = memref.alloc (%size ) : memref <?xf32 >
1966+ %c1 = arith.constant 1 : index
1967+ scf.for %i = %c0 to %size step %c1 {
1968+ memref.store %cst , %alloc [%i ] : memref <?xf32 >
1969+ }
1970+ acc.yield %alloc : memref <?xf32 >
1971+ } combiner {
1972+ ^bb0 (%arg0: memref <?xf32 >, %arg1: memref <?xf32 >):
1973+ %c0 = arith.constant 0 : index
1974+ %c1 = arith.constant 1 : index
1975+ %size = memref.dim %arg0 , %c0 : memref <?xf32 >
1976+ scf.for %i = %c0 to %size step %c1 {
1977+ %val0 = memref.load %arg0 [%i ] : memref <?xf32 >
1978+ %val1 = memref.load %arg1 [%i ] : memref <?xf32 >
1979+ %sum = arith.addf %val0 , %val1 : f32
1980+ memref.store %sum , %arg0 [%i ] : memref <?xf32 >
1981+ }
1982+ acc.yield %arg0 : memref <?xf32 >
1983+ } destroy {
1984+ ^bb0 (%arg0: memref <?xf32 >):
1985+ // destroy region to deallocate dynamically allocated memory
1986+ memref.dealloc %arg0 : memref <?xf32 >
1987+ acc.yield
1988+ }
1989+
1990+ // CHECK-LABEL: acc.reduction.recipe @reduction_add_with_destroy : memref<?xf32> reduction_operator <add> init {
1991+ // CHECK: ^bb0(%[[ARG:.*]]: memref<?xf32>):
1992+ // CHECK: %[[CST:.*]] = arith.constant 0.000000e+00 : f32
1993+ // CHECK: %[[C0:.*]] = arith.constant 0 : index
1994+ // CHECK: %[[SIZE:.*]] = memref.dim %[[ARG]], %[[C0]] : memref<?xf32>
1995+ // CHECK: %[[ALLOC:.*]] = memref.alloc(%[[SIZE]]) : memref<?xf32>
1996+ // CHECK: %[[C1:.*]] = arith.constant 1 : index
1997+ // CHECK: scf.for %[[I:.*]] = %[[C0]] to %[[SIZE]] step %[[C1]] {
1998+ // CHECK: memref.store %[[CST]], %[[ALLOC]][%[[I]]] : memref<?xf32>
1999+ // CHECK: }
2000+ // CHECK: acc.yield %[[ALLOC]] : memref<?xf32>
2001+ // CHECK: } combiner {
2002+ // CHECK: ^bb0(%[[ARG0:.*]]: memref<?xf32>, %[[ARG1:.*]]: memref<?xf32>):
2003+ // CHECK: %[[C0_1:.*]] = arith.constant 0 : index
2004+ // CHECK: %[[C1_1:.*]] = arith.constant 1 : index
2005+ // CHECK: %[[SIZE_1:.*]] = memref.dim %[[ARG0]], %[[C0_1]] : memref<?xf32>
2006+ // CHECK: scf.for %[[I_1:.*]] = %[[C0_1]] to %[[SIZE_1]] step %[[C1_1]] {
2007+ // CHECK: %{{.*}} = memref.load %[[ARG0]][%[[I_1]]] : memref<?xf32>
2008+ // CHECK: %{{.*}} = memref.load %[[ARG1]][%[[I_1]]] : memref<?xf32>
2009+ // CHECK: %[[SUM:.*]] = arith.addf %{{.*}}, %{{.*}} : f32
2010+ // CHECK: memref.store %[[SUM]], %[[ARG0]][%[[I_1]]] : memref<?xf32>
2011+ // CHECK: }
2012+ // CHECK: acc.yield %[[ARG0]] : memref<?xf32>
2013+ // CHECK: } destroy {
2014+ // CHECK: ^bb0(%[[ARG_DESTROY:.*]]: memref<?xf32>):
2015+ // CHECK: memref.dealloc %[[ARG_DESTROY]] : memref<?xf32>
2016+ // CHECK: acc.yield
2017+ // CHECK: }
2018+
2019+ // -----
2020+
19572021acc.private.recipe @privatization_memref_i32 : memref <i32 > init {
19582022^bb0 (%arg0: memref <i32 >):
19592023 %alloca = memref.alloca () : memref <i32 >
0 commit comments