| 38 | enum ArithOp { ADD, SUB, DIV, MUL }; |
| 39 | |
| 40 | void calc(ArithOp opcode, array op1, array op2, float outValue, |
| 41 | int iteration_count) { |
| 42 | setDevice(0); |
| 43 | array res; |
| 44 | for (int i = 0; i < iteration_count; ++i) { |
| 45 | switch (opcode) { |
| 46 | case ADD: res = op1 + op2; break; |
| 47 | case SUB: res = op1 - op2; break; |
| 48 | case DIV: res = op1 / op2; break; |
| 49 | case MUL: res = op1 * op2; break; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | vector<float> out(res.elements()); |
| 54 | res.host((void*)out.data()); |
| 55 | |
| 56 | for (unsigned i = 0; i < out.size(); ++i) ASSERT_FLOAT_EQ(out[i], outValue); |
| 57 | af::sync(); |
| 58 | } |
| 59 | |
| 60 | TEST(Threading, SimultaneousRead) { |
| 61 | setDevice(0); |