Skip to content

Commit 4849f66

Browse files
committed
initial file io benchmark
1 parent 5dd673c commit 4849f66

4 files changed

Lines changed: 353 additions & 51 deletions

File tree

samples/11_apitimes/main.cpp

Lines changed: 71 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,27 @@ void test_clGetDeviceIDs(cl::Platform& platform)
3333

3434
cl_platform_id p = platform();
3535

36-
auto start = std::chrono::system_clock::now();
37-
for( int i = 0; i < iterations; i++ )
36+
float ms = 0.0f;
37+
for( int w = 0; w < 2; w++ )
3838
{
39-
cl_uint numDevices = 0;
40-
clGetDeviceIDs(
41-
p,
42-
CL_DEVICE_TYPE_ALL,
43-
0,
44-
NULL,
45-
&numDevices);
39+
auto start = std::chrono::system_clock::now();
40+
for( int i = 0; i < iterations; i++ )
41+
{
42+
cl_uint numDevices = 0;
43+
clGetDeviceIDs(
44+
p,
45+
CL_DEVICE_TYPE_ALL,
46+
0,
47+
NULL,
48+
&numDevices);
49+
}
50+
auto end = std::chrono::system_clock::now();
51+
52+
std::chrono::duration<float> elapsed_seconds = end - start;
53+
ms = elapsed_seconds.count() * 1000;
4654
}
47-
auto end = std::chrono::system_clock::now();
4855

49-
std::chrono::duration<float> elapsed_seconds = end - start;
50-
float ms = elapsed_seconds.count() * 1000;
51-
printf("finished in %f ms\n", ms);
56+
printf("finished in %f ms (%f ns/iteration)\n", ms, ms * iterations / 1000000.0f);
5257
}
5358

5459
void test_clGetDeviceInfo(cl::Device& device)
@@ -58,22 +63,27 @@ void test_clGetDeviceInfo(cl::Device& device)
5863

5964
cl_device_id d = device();
6065

61-
auto start = std::chrono::system_clock::now();
62-
for( int i = 0; i < iterations; i++ )
66+
float ms = 0.0f;
67+
for( int w = 0; w < 2; w++ )
6368
{
64-
cl_device_type type = 0;
65-
clGetDeviceInfo(
66-
d,
67-
CL_DEVICE_TYPE,
68-
sizeof(type),
69-
&type,
70-
NULL);
69+
auto start = std::chrono::system_clock::now();
70+
for( int i = 0; i < iterations; i++ )
71+
{
72+
cl_device_type type = 0;
73+
clGetDeviceInfo(
74+
d,
75+
CL_DEVICE_TYPE,
76+
sizeof(type),
77+
&type,
78+
NULL);
79+
}
80+
auto end = std::chrono::system_clock::now();
81+
82+
std::chrono::duration<float> elapsed_seconds = end - start;
83+
ms = elapsed_seconds.count() * 1000;
7184
}
72-
auto end = std::chrono::system_clock::now();
7385

74-
std::chrono::duration<float> elapsed_seconds = end - start;
75-
float ms = elapsed_seconds.count() * 1000;
76-
printf("finished in %f ms\n", ms);
86+
printf("finished in %f ms (%f ns/iteration)\n", ms, ms * iterations / 1000000.0f);
7787
}
7888

7989
void test_clSetKernelArg(cl::Device& device)
@@ -91,21 +101,26 @@ void test_clSetKernelArg(cl::Device& device)
91101

92102
cl_kernel k = kernel();
93103

94-
auto start = std::chrono::system_clock::now();
95-
for( int i = 0; i < iterations; i++ )
104+
float ms = 0.0f;
105+
for( int w = 0; w < 2; w++ )
96106
{
97-
int x = 0;
98-
clSetKernelArg(
99-
k,
100-
0,
101-
sizeof(x),
102-
&x);
107+
auto start = std::chrono::system_clock::now();
108+
for( int i = 0; i < iterations; i++ )
109+
{
110+
int x = 0;
111+
clSetKernelArg(
112+
k,
113+
0,
114+
sizeof(x),
115+
&x);
116+
}
117+
auto end = std::chrono::system_clock::now();
118+
119+
std::chrono::duration<float> elapsed_seconds = end - start;
120+
ms = elapsed_seconds.count() * 1000;
103121
}
104-
auto end = std::chrono::system_clock::now();
105122

106-
std::chrono::duration<float> elapsed_seconds = end - start;
107-
float ms = elapsed_seconds.count() * 1000;
108-
printf("finished in %f ms\n", ms);
123+
printf("finished in %f ms (%f ns/iteration)\n", ms, ms * iterations / 1000000.0f);
109124
}
110125

111126
void test_clSetKernelArgSVMPointer(cl::Device& device)
@@ -127,19 +142,24 @@ void test_clSetKernelArgSVMPointer(cl::Device& device)
127142

128143
cl_kernel k = kernel();
129144

130-
auto start = std::chrono::system_clock::now();
131-
for( int i = 0; i < iterations; i++ )
145+
float ms = 0.0f;
146+
for( int w = 0; w < 2; w++ )
132147
{
133-
clSetKernelArgSVMPointer(
134-
k,
135-
0,
136-
ptrs[i&1] );
148+
auto start = std::chrono::system_clock::now();
149+
for( int i = 0; i < iterations; i++ )
150+
{
151+
clSetKernelArgSVMPointer(
152+
k,
153+
0,
154+
ptrs[i&1] );
155+
}
156+
auto end = std::chrono::system_clock::now();
157+
158+
std::chrono::duration<float> elapsed_seconds = end - start;
159+
ms = elapsed_seconds.count() * 1000;
137160
}
138-
auto end = std::chrono::system_clock::now();
139161

140-
std::chrono::duration<float> elapsed_seconds = end - start;
141-
float ms = elapsed_seconds.count() * 1000;
142-
printf("finished in %f ms\n", ms);
162+
printf("finished in %f ms (%f ns/iteration)\n", ms, ms * iterations / 1000000.0f);
143163

144164
for (auto ptr : ptrs)
145165
{
@@ -187,9 +207,9 @@ int main(
187207
printf("Running on device: %s\n",
188208
devices[deviceIndex].getInfo<CL_DEVICE_NAME>().c_str() );
189209

190-
//test_clGetDeviceIDs(platforms[platformIndex]);
191-
//test_clGetDeviceInfo(devices[deviceIndex]);
192-
//test_clSetKernelArg(devices[deviceIndex]);
210+
test_clGetDeviceIDs(platforms[platformIndex]);
211+
test_clGetDeviceInfo(devices[deviceIndex]);
212+
test_clSetKernelArg(devices[deviceIndex]);
193213
test_clSetKernelArgSVMPointer(devices[deviceIndex]);
194214

195215
return 0;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2022 Ben Ashbaugh
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in all
11+
# copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
add_opencl_sample(
22+
TEST
23+
NUMBER 00
24+
TARGET fileiobenchmark
25+
VERSION 200
26+
CATEGORY benchmarks
27+
SOURCES main.cpp
28+
LIBS benchmark::benchmark)

0 commit comments

Comments
 (0)