-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
73 lines (55 loc) · 1.8 KB
/
main.cpp
File metadata and controls
73 lines (55 loc) · 1.8 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
#include <CL/cl.hpp>
#include <vector>
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
std::vector<cl::Device> totalDevices;
for (unsigned int j = 0; j < platforms.size(); j++)
{
std::vector<cl::Device> devices;
platforms[j].getDevices(CL_DEVICE_TYPE_ALL, &devices);
for (unsigned int i = 0; i < devices.size(); i++)
{
cout << " DEVICE ID = " << totalDevices.size() << ", ";
totalDevices.push_back(devices[i]);
cout << " DEVICE_NAME = " << devices[i].getInfo<CL_DEVICE_NAME>() << endl;
}
}
unsigned int deviceID;
cout << "Select device: ";
cin >> deviceID;
if (deviceID >= totalDevices.size())
{
printf("Invalid selection\n");
return 1;
}
cl_int err;
cl::Device device = totalDevices[deviceID];
cl::Context context(device);
cl::CommandQueue queue(context, device);
cl::ImageFormat format;
format.image_channel_order = CL_R;
format.image_channel_data_type = CL_UNSIGNED_INT8;
size_t width = 8;
size_t height= 4;
size_t arraySize = 1;
cl::Image2DArray image(context, CL_MEM_READ_WRITE, format, arraySize, width, height, 0, 0);
size_t dim[3];
image.getImageInfo(CL_IMAGE_WIDTH, &dim[0]);
image.getImageInfo(CL_IMAGE_HEIGHT, &dim[1]);
image.getImageInfo(CL_IMAGE_ARRAY_SIZE, &dim[2]);
printf("Host: %ld %ld %ld\n", dim[0], dim[1], dim[2]);
const char src[] = "__kernel void imageinfo(__write_only image2d_array_t im){ \
printf(\"Kernel: %d %d %d\\n\", get_image_width(im), get_image_height(im), get_image_array_size(im));\
}";
cl::Program program(context, src);
err = program.build();
cl::Kernel kernel(program, "imageinfo");
err = kernel.setArg(0, image);
err = queue.enqueueNDRangeKernel(kernel, cl::NullRange, cl::NDRange(1,1,1), cl::NDRange(1,1,1) );
queue.finish();
}