-
Notifications
You must be signed in to change notification settings - Fork 1
/
demohost.cpp
75 lines (56 loc) · 1.5 KB
/
demohost.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
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
#include "clwrap.hpp"
#include <sys/time.h>
#include <iomanip>
// A sample code for simpleOCLInit.hpp
// Written by Kaz Yoshii <[email protected]>
// source $OPENCLENV
// g++ -I. -Wall -O2 -g -Wno-unknown-pragmas `aocl compile-config` -std=c++11 -o testclwrap testclwrap.cpp `aocl link-config`
// aocl
using namespace std;
static void test_clwrap()
{
clwrap cw;
bool failed = false;
cw.info();
int gsiz = 8;
int lsiz = 4;
int *a0 = new int[gsiz];
int *a1 = new int[gsiz];
// find demokernel.cl and use 'demokernel' as the kernel name
bool ret = cw.prepKernel("demokernel");
if (!ret) {
cout << "prepKernel() failed!" << endl;
return;
}
cw.appendArg(sizeof(int)*gsiz, a0, cw.DEV2HOST);
cw.appendArg(sizeof(int)*gsiz, a1, cw.DEV2HOST);
cw.runKernel(gsiz, lsiz);
cw.finish();
// validate the results
for (int i = 0; i < gsiz; i++) {
if (a0[i] != i + 10) {
cout << "Error: a0[" << i << "] should be " << i+10 << ", not " << a0[i] << endl;
failed = true;
}
if (a1[i] != (i%lsiz) + 20) {
cout << "Error: a1[" << i << "] should be " << (i%lsiz)+20 << ", not " << a1[i] << endl;
failed = true;
}
}
if (! failed) cout << "Validation passed" << endl;
cout << "Elapsed [sec]: " << cw.getKernelElapsedNanoSec() * 1e-9 << endl;
cout << "[output]" << endl;
cout << "a0: ";
for (int i = 0; i < gsiz; i++)
cout << setw(3) << a0[i];
cout << endl;
cout << "a1: ";
for (int i = 0; i < gsiz; i++)
cout << setw(3) << a1[i];
cout << endl;
};
int main()
{
test_clwrap();
return 0;
}