testclwrap.cpp 972 Bytes
Newer Older
Kazutomo Yoshii's avatar
base  
Kazutomo Yoshii committed
1
2
3
4
5
6
7
8
#include "clwrap.hpp"
#include <sys/time.h>

// A sample code for simpleOCLInit.hpp
// Written by Kaz Yoshii <ky@anl.gov>

// source $OPENCLENV
// g++ -I. -Wall -O2 -g -Wno-unknown-pragmas `aocl compile-config` -std=c++11 -o testclwrap testclwrap.cpp `aocl link-config`
Kazutomo Yoshii's avatar
Kazutomo Yoshii committed
9
// aocl
Kazutomo Yoshii's avatar
base  
Kazutomo Yoshii committed
10

Kazutomo Yoshii's avatar
Kazutomo Yoshii committed
11
static void test_clwrap()
Kazutomo Yoshii's avatar
base  
Kazutomo Yoshii committed
12
13
14
15
16
17
18
19
20
{
	clWrap  cw;

	cw.listPlatforms();
	cw.listDevices();

	int gsiz = 8;
	int lsiz = 2;

Kazutomo Yoshii's avatar
Kazutomo Yoshii committed
21
22
	int *a0 = new int[gsiz];
	int *a1 = new int[gsiz];
Kazutomo Yoshii's avatar
base  
Kazutomo Yoshii committed
23

Kazutomo Yoshii's avatar
Kazutomo Yoshii committed
24
25
26
27
28
	bool ret = cw.prepKernel("dummy", "dummy"); // filename w/ ext, kernelname
	if (!ret) {
		cout << "prepKernel() failed!" << endl;
		return;
	}
Kazutomo Yoshii's avatar
base  
Kazutomo Yoshii committed
29
30
31

	cw.appendArg(sizeof(int)*gsiz, a0, cw.DEV2HOST);
	cw.appendArg(sizeof(int)*gsiz, a1, cw.DEV2HOST);
32

Kazutomo Yoshii's avatar
Kazutomo Yoshii committed
33
	cw.runKernel(gsiz, lsiz);
Kazutomo Yoshii's avatar
base  
Kazutomo Yoshii committed
34

Kazutomo Yoshii's avatar
Kazutomo Yoshii committed
35
	cout << "[output]" << endl;
Kazutomo Yoshii's avatar
base  
Kazutomo Yoshii committed
36
	for (int i = 0; i < gsiz; i++) 
Kazutomo Yoshii's avatar
Kazutomo Yoshii committed
37
		cout << i << ":" << a0[i] << "," << a1[i] << " ";
Kazutomo Yoshii's avatar
base  
Kazutomo Yoshii committed
38
	cout << endl;
39
40

	cout << "Elapsed [sec]: " << cw.getKernelElapsedNanoSec() * 1e-9 << endl;
Kazutomo Yoshii's avatar
base  
Kazutomo Yoshii committed
41
42
};

Kazutomo Yoshii's avatar
Kazutomo Yoshii committed
43
int main()
Kazutomo Yoshii's avatar
base  
Kazutomo Yoshii committed
44
{
Kazutomo Yoshii's avatar
Kazutomo Yoshii committed
45
	test_clwrap();
Kazutomo Yoshii's avatar
base  
Kazutomo Yoshii committed
46
47
48

	return 0;
}