@@ -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
5459void 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
7989void 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
111126void 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 ;
0 commit comments