1 //
2 // Copyright (c) 2017 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 #include "harness/compat.h"
17
18 #include <stdio.h>
19 #include <string.h>
20 #include "procs.h"
21 #include "harness/testHarness.h"
22
23 // FIXME: To use certain functions in harness/imageHelpers.h
24 // (for example, generate_random_image_data()), the tests are required to declare
25 // the following variables (<rdar://problem/11111245>):
26
27 test_definition test_list[] = {
28 ADD_TEST( read_array_int ),
29 ADD_TEST( read_array_uint ),
30 ADD_TEST( read_array_long ),
31 ADD_TEST( read_array_ulong ),
32 ADD_TEST( read_array_short ),
33 ADD_TEST( read_array_ushort ),
34 ADD_TEST( read_array_float ),
35 ADD_TEST( read_array_char ),
36 ADD_TEST( read_array_uchar ),
37 ADD_TEST( read_array_struct ),
38 ADD_TEST( write_array_int ),
39 ADD_TEST( write_array_uint ),
40 ADD_TEST( write_array_long ),
41 ADD_TEST( write_array_ulong ),
42 ADD_TEST( write_array_short ),
43 ADD_TEST( write_array_ushort ),
44 ADD_TEST( write_array_float ),
45 ADD_TEST( write_array_char ),
46 ADD_TEST( write_array_uchar ),
47 ADD_TEST( write_array_struct ),
48 ADD_TEST( read_image_float ),
49 ADD_TEST( read_image_char ),
50 ADD_TEST( read_image_uchar ),
51 ADD_TEST( write_image_float ),
52 ADD_TEST( write_image_char ),
53 ADD_TEST( write_image_uchar ),
54 ADD_TEST( copy_array ),
55 ADD_TEST( copy_partial_array ),
56 ADD_TEST( copy_image ),
57 ADD_TEST( copy_array_to_image ),
58 ADD_TEST( execute ),
59 };
60
61 const int test_num = ARRAY_SIZE( test_list );
62
63 // FIXME: use timer resolution rather than hardcoding 1µs per tick.
64
65 #define QUEUE_SECONDS_LIMIT 30
66 #define SUBMIT_SECONDS_LIMIT 30
67 #define COMMAND_SECONDS_LIMIT 30
check_times(cl_ulong queueStart,cl_ulong commandSubmit,cl_ulong commandStart,cl_ulong commandEnd,cl_device_id device)68 int check_times(cl_ulong queueStart, cl_ulong commandSubmit, cl_ulong commandStart, cl_ulong commandEnd, cl_device_id device) {
69 int err = 0;
70
71 size_t profiling_resolution = 0;
72 err = clGetDeviceInfo(device, CL_DEVICE_PROFILING_TIMER_RESOLUTION, sizeof(profiling_resolution), &profiling_resolution, NULL);
73 test_error(err, "clGetDeviceInfo for CL_DEVICE_PROFILING_TIMER_RESOLUTION failed.\n");
74
75 log_info("CL_PROFILING_COMMAND_QUEUED: %llu CL_PROFILING_COMMAND_SUBMIT: %llu CL_PROFILING_COMMAND_START: %llu CL_PROFILING_COMMAND_END: %llu CL_DEVICE_PROFILING_TIMER_RESOLUTION: %ld\n",
76 queueStart, commandSubmit, commandStart, commandEnd, profiling_resolution);
77
78 double queueTosubmitTimeS = (double)(commandSubmit - queueStart)*1e-9;
79 double submitToStartTimeS = (double)(commandStart - commandSubmit)*1e-9;
80 double startToEndTimeS = (double)(commandEnd - commandStart)*1e-9;
81
82 log_info( "Profiling info:\n" );
83 log_info( "Time from queue to submit : %fms\n", (double)(queueTosubmitTimeS) * 1000.f );
84 log_info( "Time from submit to start : %fms\n", (double)(submitToStartTimeS) * 1000.f );
85 log_info( "Time from start to end: %fms\n", (double)(startToEndTimeS) * 1000.f );
86
87 if(queueStart > commandSubmit) {
88 log_error("CL_PROFILING_COMMAND_QUEUED > CL_PROFILING_COMMAND_SUBMIT.\n");
89 err = -1;
90 }
91
92 if (commandSubmit > commandStart) {
93 log_error("CL_PROFILING_COMMAND_SUBMIT > CL_PROFILING_COMMAND_START.\n");
94 err = -1;
95 }
96
97 if (commandStart > commandEnd) {
98 log_error("CL_PROFILING_COMMAND_START > CL_PROFILING_COMMAND_END.\n");
99 err = -1;
100 }
101
102 if (queueStart == 0 && commandStart == 0 && commandEnd == 0) {
103 log_error("All values are 0. This is exceedingly unlikely.\n");
104 err = -1;
105 }
106
107 if (queueTosubmitTimeS > QUEUE_SECONDS_LIMIT) {
108 log_error("Time between queue and submit is too big: %fs, test limit: %fs.\n",
109 queueTosubmitTimeS , (double)QUEUE_SECONDS_LIMIT);
110 err = -1;
111 }
112
113 if (submitToStartTimeS > SUBMIT_SECONDS_LIMIT) {
114 log_error("Time between submit and start is too big: %fs, test limit: %fs.\n",
115 submitToStartTimeS , (double)QUEUE_SECONDS_LIMIT);
116 err = -1;
117 }
118
119 if (startToEndTimeS > COMMAND_SECONDS_LIMIT) {
120 log_error("Time between queue and start is too big: %fs, test limit: %fs.\n",
121 startToEndTimeS , (double)QUEUE_SECONDS_LIMIT);
122 err = -1;
123 }
124 return err;
125 }
126
main(int argc,const char * argv[])127 int main( int argc, const char *argv[] )
128 {
129 return runTestHarness(argc, argv, test_num, test_list, false,
130 CL_QUEUE_PROFILING_ENABLE);
131 }
132
133