File: test_queue_creation_with_hints.c

package info (click to toggle)
pocl 6.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,320 kB
  • sloc: lisp: 149,513; ansic: 103,778; cpp: 54,947; python: 1,513; sh: 949; ruby: 255; pascal: 226; tcl: 180; makefile: 175; java: 72; xml: 49
file content (155 lines) | stat: -rw-r--r-- 6,351 bytes parent folder | download | duplicates (2)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* Tests command queue hints (cl_khr_priority_hints, cl_khr_throttle_hints)

   Copyright (c) 2024 Jan Solanti / Tampere University

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to
   deal in the Software without restriction, including without limitation the
   rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
   sell copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
   IN THE SOFTWARE.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <CL/cl_ext.h>

#include "poclu.h"

int
main ()
{
  cl_int err;
  cl_platform_id platforms[1];
  cl_uint nplatforms;
  cl_device_id devices[1];

  err = clGetPlatformIDs (1, platforms, &nplatforms);
  CHECK_OPENCL_ERROR_IN ("clGetPlatformIDs");
  if (!nplatforms)
    return EXIT_FAILURE;

  size_t extensions_len;
  err = clGetPlatformInfo (platforms[0], CL_PLATFORM_EXTENSIONS_WITH_VERSION,
                           0, NULL, &extensions_len);
  CHECK_OPENCL_ERROR_IN ("clGetPlatformInfo (size_ret)");

  cl_name_version *extensions = malloc (extensions_len);
  err = clGetPlatformInfo (platforms[0], CL_PLATFORM_EXTENSIONS_WITH_VERSION,
                           extensions_len, extensions, NULL);
  CHECK_OPENCL_ERROR_IN ("clGetPlatformInfo (value)");

  int cl_khr_priority_hints_found = 0;
  int cl_khr_throttle_hints_found = 0;

  for (size_t i = 0; i < extensions_len / sizeof (cl_name_version); ++i)
    {
      if (strcmp ("cl_khr_priority_hints", extensions[i].name) == 0
          && extensions[i].version >= CL_MAKE_VERSION (1, 0, 0))
        cl_khr_priority_hints_found = 1;
      if (strcmp ("cl_khr_throttle_hints", extensions[i].name) == 0
          && extensions[i].version >= CL_MAKE_VERSION (1, 0, 0))
        cl_khr_throttle_hints_found = 1;
    }

  free (extensions);
  extensions = NULL;

  if (!cl_khr_priority_hints_found || !cl_khr_throttle_hints_found)
    {
      printf ("Queue hint extensions not supported\n");
      return 77;
    }

  err = clGetDeviceIDs (platforms[0], CL_DEVICE_TYPE_ALL, 1, devices, NULL);
  CHECK_OPENCL_ERROR_IN ("clGetDeviceIDs");

  cl_context context = clCreateContext (NULL, 1, devices, NULL, NULL, &err);
  CHECK_OPENCL_ERROR_IN ("clCreateContext");

  err = clGetContextInfo (context, CL_CONTEXT_DEVICES, sizeof (cl_device_id),
                          devices, NULL);
  CHECK_OPENCL_ERROR_IN ("clGetContextInfo");

  cl_queue_properties valid_hints[][5] = {
    { CL_QUEUE_PRIORITY_KHR, CL_QUEUE_PRIORITY_HIGH_KHR, 0, 0, 0 },
    { CL_QUEUE_PRIORITY_KHR, CL_QUEUE_PRIORITY_MED_KHR, 0, 0, 0 },
    { CL_QUEUE_PRIORITY_KHR, CL_QUEUE_PRIORITY_LOW_KHR, 0, 0, 0 },
    { CL_QUEUE_THROTTLE_KHR, CL_QUEUE_THROTTLE_HIGH_KHR, 0, 0, 0 },
    { CL_QUEUE_THROTTLE_KHR, CL_QUEUE_THROTTLE_MED_KHR, 0, 0, 0 },
    { CL_QUEUE_THROTTLE_KHR, CL_QUEUE_THROTTLE_LOW_KHR, 0, 0, 0 },
    { CL_QUEUE_THROTTLE_KHR, CL_QUEUE_THROTTLE_HIGH_KHR, CL_QUEUE_PRIORITY_KHR,
      CL_QUEUE_PRIORITY_HIGH_KHR, 0 },
    { CL_QUEUE_THROTTLE_KHR, CL_QUEUE_THROTTLE_MED_KHR, CL_QUEUE_PRIORITY_KHR,
      CL_QUEUE_PRIORITY_HIGH_KHR, 0 },
    { CL_QUEUE_THROTTLE_KHR, CL_QUEUE_THROTTLE_LOW_KHR, CL_QUEUE_PRIORITY_KHR,
      CL_QUEUE_PRIORITY_HIGH_KHR, 0 },
    { CL_QUEUE_THROTTLE_KHR, CL_QUEUE_THROTTLE_HIGH_KHR, CL_QUEUE_PRIORITY_KHR,
      CL_QUEUE_PRIORITY_MED_KHR, 0 },
    { CL_QUEUE_THROTTLE_KHR, CL_QUEUE_THROTTLE_MED_KHR, CL_QUEUE_PRIORITY_KHR,
      CL_QUEUE_PRIORITY_MED_KHR, 0 },
    { CL_QUEUE_THROTTLE_KHR, CL_QUEUE_THROTTLE_LOW_KHR, CL_QUEUE_PRIORITY_KHR,
      CL_QUEUE_PRIORITY_MED_KHR, 0 },
    { CL_QUEUE_THROTTLE_KHR, CL_QUEUE_THROTTLE_HIGH_KHR, CL_QUEUE_PRIORITY_KHR,
      CL_QUEUE_PRIORITY_LOW_KHR, 0 },
    { CL_QUEUE_THROTTLE_KHR, CL_QUEUE_THROTTLE_MED_KHR, CL_QUEUE_PRIORITY_KHR,
      CL_QUEUE_PRIORITY_LOW_KHR, 0 },
    { CL_QUEUE_THROTTLE_KHR, CL_QUEUE_THROTTLE_LOW_KHR, CL_QUEUE_PRIORITY_KHR,
      CL_QUEUE_PRIORITY_LOW_KHR, 0 },
  };
  for (size_t i = 0;
       i < (sizeof (valid_hints) / sizeof (cl_queue_properties[5])); ++i)
    {
      fprintf (stderr, "%d\n", (int)i);
      cl_command_queue queueA = clCreateCommandQueueWithProperties (
          context, devices[0], valid_hints[i], &err);
      CHECK_OPENCL_ERROR_IN ("clCreateCommandQueue");
      TEST_ASSERT (queueA);
      CHECK_CL_ERROR (clReleaseCommandQueue (queueA));
    }

  cl_queue_properties bad_hints[][5] = {
    { CL_QUEUE_PRIORITY_KHR, 0, 0, 0, 0 },
    { CL_QUEUE_PRIORITY_KHR, CL_QUEUE_PRIORITY_LOW_KHR + 1, 0, 0, 0 },
    { CL_QUEUE_THROTTLE_KHR, 0, 0, 0, 0 },
    { CL_QUEUE_THROTTLE_KHR, CL_QUEUE_THROTTLE_LOW_KHR + 1, 0, 0, 0 },
    { CL_QUEUE_THROTTLE_KHR, CL_QUEUE_THROTTLE_HIGH_KHR, CL_QUEUE_PRIORITY_KHR,
      0, 0 },
    { CL_QUEUE_THROTTLE_KHR, 0, CL_QUEUE_PRIORITY_KHR,
      CL_QUEUE_PRIORITY_HIGH_KHR, 0 },
    { CL_QUEUE_PROPERTIES,
      CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE,
      CL_QUEUE_PRIORITY_KHR, CL_QUEUE_PRIORITY_HIGH_KHR, 0 },
    { CL_QUEUE_PROPERTIES,
      CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE,
      CL_QUEUE_THROTTLE_KHR, CL_QUEUE_THROTTLE_HIGH_KHR, 0 },
  };
  for (size_t i = 0;
       i < (sizeof (bad_hints) / sizeof (cl_queue_properties[5])); ++i)
    {
      cl_command_queue queueA = clCreateCommandQueueWithProperties (
          context, devices[0], bad_hints[i], &err);
      TEST_ASSERT (!queueA && err != CL_SUCCESS);
      if (queueA)
        CHECK_CL_ERROR (clReleaseCommandQueue (queueA));
    }

  CHECK_CL_ERROR (clReleaseContext (context));
  CHECK_CL_ERROR (clUnloadPlatformCompiler (platforms[0]));

  printf ("OK\n");
  return EXIT_SUCCESS;
}