-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·109 lines (89 loc) · 3.46 KB
/
main.cpp
File metadata and controls
executable file
·109 lines (89 loc) · 3.46 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
//#include <cstdlib>
//#include <omp.h>
//#include <stdio.h>
//#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <OpenCL/opencl.h>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
//#include <CL/opencl.h>
//#include <CL/CL.h>
////////////////////////////////////////////////////////////////////////////////
// Use a static data size for simplicity
//
#define DATA_SIZE (1024)
////////////////////////////////////////////////////////////////////////////////
// Simple compute kernel which computes the square of an input array
//
/*const char *KernelSource = "\n" \
"__kernel void square( \n" \
" __global float* input, \n" \
" __global float* output, \n" \
" const unsigned int count) \n" \
"{ \n" \
" int i = get_global_id(0); \n" \
" if(i < count) \n" \
" output[i] = input[i] * input[i]; \n" \
"} \n" \
"\n";*/
////////////////////////////////////////////////////////////////////////////////
int main(int argc, const char * argv[]) {
cl_context context;
cl_device_id *devices;
char *devname;
size_t cb;
IplImage *Image1=cvLoadImage("Koala.jpg",1);
// create a GPU context
context = clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU, NULL, NULL, NULL);
if(context == 0) {
printf("Can't create GPU context\n");
return 0;
}
// get a list of devices
clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &cb);
devices = (cl_device_id*) malloc(cb);
clGetContextInfo(context, CL_CONTEXT_DEVICES, cb, devices, 0);
// show the name of the first device
clGetDeviceInfo(devices[0], CL_DEVICE_NAME, 0, NULL, &cb);
devname = (char*) malloc(cb);
clGetDeviceInfo(devices[0], CL_DEVICE_NAME, cb, devname, 0);
printf("Device GPU : %s\n", devname);
// release everything
free(devname);
free(devices);
clReleaseContext(context);
////////////////////////////////////////////////////////////////////////////////////
// create a CPU context
context = clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU, NULL, NULL, NULL);
if(context == 0) {
printf("Can't create CPU context\n");
return 0;
}
// get a list of devices
clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &cb);
devices = (cl_device_id*) malloc(cb);
clGetContextInfo(context, CL_CONTEXT_DEVICES, cb, devices, 0);
// show the name of the first device
clGetDeviceInfo(devices[0], CL_DEVICE_NAME, 0, NULL, &cb);
devname = (char*) malloc(cb);
clGetDeviceInfo(devices[0], CL_DEVICE_NAME, cb, devname, 0);
printf("Device CPU : %s\n", devname);
// release everything
free(devname);
free(devices);
clReleaseContext(context);
cvShowImage("Result",Image1);
cvWaitKey(0);
system( "read -n 1 -s -p \"Press any key to continue...\"; echo" );
cvDestroyWindow("Result");
return 0;
}