| 77 | template<typename Ti, typename Tk, typename To, af_binary_op op, |
| 78 | bool inclusive_scan> |
| 79 | void verify(dim4 dims, const vector<Ti> &in, const vector<Tk> &key, |
| 80 | const vector<To> &out, int scanDim, double eps) { |
| 81 | std::srand(1); |
| 82 | Binary<To, op> binOp; |
| 83 | int elemCount = dims.elements(); |
| 84 | |
| 85 | int stride = 1; |
| 86 | for (int i = 0; i < scanDim; ++i) { stride *= dims[i]; } |
| 87 | |
| 88 | for (int start = 0; start < stride; ++start) { |
| 89 | Tk keyval = key[start]; |
| 90 | To gold = binOp.init(); |
| 91 | for (int index = start + (!inclusive_scan) * stride, |
| 92 | i = (!inclusive_scan); |
| 93 | index < elemCount; index += stride, i = (i + 1) % dims[scanDim]) { |
| 94 | if ((key[index] != keyval) || (i == 0)) { |
| 95 | keyval = key[index]; |
| 96 | if (inclusive_scan) { |
| 97 | gold = (To)in[index]; |
| 98 | ASSERT_NEAR(gold, out[index], eps); |
| 99 | } else { |
| 100 | gold = binOp.init(); |
| 101 | } |
| 102 | } else { |
| 103 | To dataval = (To)in[index - (!inclusive_scan) * stride]; |
| 104 | gold = binOp(gold, dataval); |
| 105 | ASSERT_NEAR(gold, out[index], eps); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | template<typename Ti, typename To, af_binary_op op, bool inclusive_scan> |
| 112 | void scanByKeyTest(dim4 dims, int scanDim, vector<int> nodeLengths, |