reduce_common.rsh revision 4546f4b74db2655d36b2e19d1e839d7ef37cb27c
1/*
2* Copyright (C) 2016 The Android Open Source Project
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8*      http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
17int __attribute__((kernel)) my_foreach_kernel(int a) {
18  // This kernel is unused, but we want to make sure it is not listed as a
19  // reduction kernel by the debugger
20  return a + 1;
21}
22
23typedef struct MinUserType {
24  int32_t a;
25  int32_t b;
26} user_t;
27
28int32_t b_startval;
29int32_t a_startval;
30float multiplier;
31
32static void find_min_user_type_init(user_t *alloc) {
33  alloc->a = a_startval;
34  alloc->b = b_startval;
35}
36
37static void find_min_user_type_accum(user_t *accum, const user_t val) {
38  if (val.a + val.b * multiplier < accum->a + accum->b * multiplier) {
39    accum->a = val.a;
40    accum->b = val.b;
41  }
42}
43
44// Combiners are autogenerated if the user has not defined the combiner.
45// We specialise the tests for lldb's handling of this behaviour as well,
46// generating two test apps from the same source.
47// This combiner is equivalent to the accumulator.
48#if defined(RSTESTS_USER_COMBINER)
49static void find_min_user_type_comb(user_t *accum, const user_t *val) {
50  if (val->a + val->b * multiplier < accum->a + accum->b * multiplier) {
51    accum->a = val->a;
52    accum->b = val->b;
53  }
54}
55#endif
56
57static void find_min_user_type_outc(float *output, const user_t *val) {
58  *output = val->a + val->b * multiplier;
59}
60