forked from codeplaysoftware/syclacademy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.cpp
33 lines (25 loc) · 817 Bytes
/
source.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
SYCL Academy (c)
SYCL Academy is licensed under a Creative Commons
Attribution-ShareAlike 4.0 International License.
You should have received a copy of the license along with this
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>.
*/
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
TEST_CASE("usm_vector_add", "usm_vector_add_source") {
constexpr size_t dataSize = 1024;
float a[dataSize], b[dataSize], r[dataSize];
for (int i = 0; i < dataSize; ++i) {
a[i] = static_cast<float>(i);
b[i] = static_cast<float>(i);
r[i] = 0.0f;
}
// Task: Allocate the arrays in USM, and compute r[i] = a[i] + b[i] on the SYCL device
for (int i = 0; i < dataSize; ++i) {
r[i] = a[i] + b[i];
}
for (int i = 0; i < dataSize; ++i) {
REQUIRE(r[i] == i * 2);
}
}