This repository was archived by the owner on Jul 21, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy patharray_copy.cpp
More file actions
78 lines (66 loc) · 2.73 KB
/
Copy patharray_copy.cpp
File metadata and controls
78 lines (66 loc) · 2.73 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// ====------ array_copy.cpp---------- -*- C++ -* ----===////
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//
// ===----------------------------------------------------------------------===//
#include <stdio.h>
#include <dpct/dpct.hpp>
bool check(const int *in, const int *out, size_t size) {
for (auto i = 0; i < size; ++i) {
if (in[i] != out[i])
return false;
}
return true;
}
bool check_zero(const int *in, size_t size) {
for (auto i = 0; i < size; ++i) {
if (in[i])
return false;
}
return true;
}
void init(int *in, size_t size) {
for (auto i = 0; i < size; ++i) {
in[i] = i;
}
}
void init_zero(int *in, size_t size) {
for (auto i = 0; i < size; ++i) {
in[i] = 0;
}
}
void print(int *in, size_t size) {
for (auto i = 0; i < size; ++i)
printf("[%d]: %d\n", i, in[i]);
printf("\n");
}
int main() {
dpct::image_matrix_p ain, aout;
dpct::image_channel chn =
dpct::image_channel(32, 0, 0, 0, dpct::image_channel_data_type::signed_int);
int *in, *out;
sycl::range<2> size = sycl::range<2>(256, 1);
in = (int *)std::malloc(size.size() * sizeof(int));
out = (int *)std::malloc(size.size() * sizeof(int));
ain = new dpct::image_matrix(chn, size);
aout = new dpct::image_matrix(chn, size);
init(in, size.size());
init_zero(out, size.size());
/// ain init zero.
dpct::dpct_memcpy(ain->to_pitched_data(), sycl::id<3>(0, 0, 0), dpct::pitched_data(out, 256 * sizeof(int), 256 * sizeof(int), 1), sycl::id<3>(0, 0, 0), sycl::range<3>(256 * sizeof(int), 1, 1));
/// aout init zero.
dpct::dpct_memcpy(aout->to_pitched_data(), sycl::id<3>(0, 0, 0), dpct::pitched_data(out, 256 * sizeof(int), 256 * sizeof(int), 1), sycl::id<3>(0, 0, 0), sycl::range<3>(256 * sizeof(int), 1, 1));
/// copy in [0, 224) to ain [32, 256).
dpct::dpct_memcpy(ain->to_pitched_data(), sycl::id<3>(32 * sizeof(int), 0, 0), dpct::pitched_data(in, 256 * sizeof(int), 256 * sizeof(int), 1), sycl::id<3>(0, 0, 0), sycl::range<3>(224 * sizeof(int), 1, 1));
/// copy ain [64, 224) to aout [32, 192).
dpct::dpct_memcpy(aout->to_pitched_data(), sycl::id<3>(32 * sizeof(int), 0, 0), ain->to_pitched_data(), sycl::id<3>(64 * sizeof(int), 0, 0), sycl::range<3>(160 * sizeof(int), 1, 1));
/// copy aout [0, 224) to out [0, 224).
dpct::dpct_memcpy(dpct::pitched_data(out, 256 * sizeof(int), 256 * sizeof(int), 1), sycl::id<3>(0, 0, 0), aout->to_pitched_data(), sycl::id<3>(0, 0, 0), sycl::range<3>(224 * sizeof(int), 1, 1));
if (check(in + 32, out + 32, 128) && check_zero(out, 32) && check_zero(out + 192, 64))
printf("Success!\n");
else
printf("Fail!\n");
}