• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "testBase.h"
17 #include "harness/imageHelpers.h"
18 #include <stdlib.h>
19 #include <ctype.h>
20 
test_get_sampler_info_compatibility(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)21 int test_get_sampler_info_compatibility(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
22 {
23     int error;
24     size_t size;
25 
26     PASSIVE_REQUIRE_IMAGE_SUPPORT( deviceID )
27 
28     clSamplerWrapper sampler = clCreateSampler( context, CL_TRUE, CL_ADDRESS_CLAMP, CL_FILTER_LINEAR, &error );
29     test_error( error, "Unable to create sampler to test with" );
30 
31     cl_uint refCount;
32     error = clGetSamplerInfo( sampler, CL_SAMPLER_REFERENCE_COUNT, sizeof( refCount ), &refCount, &size );
33     test_error( error, "Unable to get sampler ref count" );
34     if( size != sizeof( refCount ) )
35     {
36         log_error( "ERROR: Returned size of sampler refcount does not validate! (expected %d, got %d)\n", (int)sizeof( refCount ), (int)size );
37         return -1;
38     }
39 
40     cl_context otherCtx;
41     error = clGetSamplerInfo( sampler, CL_SAMPLER_CONTEXT, sizeof( otherCtx ), &otherCtx, &size );
42     test_error( error, "Unable to get sampler context" );
43     if( otherCtx != context )
44     {
45         log_error( "ERROR: Sampler context does not validate! (expected %p, got %p)\n", context, otherCtx );
46         return -1;
47     }
48     if( size != sizeof( otherCtx ) )
49     {
50         log_error( "ERROR: Returned size of sampler context does not validate! (expected %d, got %d)\n", (int)sizeof( otherCtx ), (int)size );
51         return -1;
52     }
53 
54     cl_addressing_mode mode;
55     error = clGetSamplerInfo( sampler, CL_SAMPLER_ADDRESSING_MODE, sizeof( mode ), &mode, &size );
56     test_error( error, "Unable to get sampler addressing mode" );
57     if( mode != CL_ADDRESS_CLAMP )
58     {
59         log_error( "ERROR: Sampler addressing mode does not validate! (expected %d, got %d)\n", (int)CL_ADDRESS_CLAMP, (int)mode );
60         return -1;
61     }
62     if( size != sizeof( mode ) )
63     {
64         log_error( "ERROR: Returned size of sampler addressing mode does not validate! (expected %d, got %d)\n", (int)sizeof( mode ), (int)size );
65         return -1;
66     }
67 
68     cl_filter_mode fmode;
69     error = clGetSamplerInfo( sampler, CL_SAMPLER_FILTER_MODE, sizeof( fmode ), &fmode, &size );
70     test_error( error, "Unable to get sampler filter mode" );
71     if( fmode != CL_FILTER_LINEAR )
72     {
73         log_error( "ERROR: Sampler filter mode does not validate! (expected %d, got %d)\n", (int)CL_FILTER_LINEAR, (int)fmode );
74         return -1;
75     }
76     if( size != sizeof( fmode ) )
77     {
78         log_error( "ERROR: Returned size of sampler filter mode does not validate! (expected %d, got %d)\n", (int)sizeof( fmode ), (int)size );
79         return -1;
80     }
81 
82     cl_int norm;
83     error = clGetSamplerInfo( sampler, CL_SAMPLER_NORMALIZED_COORDS, sizeof( norm ), &norm, &size );
84     test_error( error, "Unable to get sampler normalized flag" );
85     if( norm != CL_TRUE )
86     {
87         log_error( "ERROR: Sampler normalized flag does not validate! (expected %d, got %d)\n", (int)CL_TRUE, (int)norm );
88         return -1;
89     }
90     if( size != sizeof( norm ) )
91     {
92         log_error( "ERROR: Returned size of sampler normalized flag does not validate! (expected %d, got %d)\n", (int)sizeof( norm ), (int)size );
93         return -1;
94     }
95 
96     return 0;
97 }
98 
99 #define TEST_COMMAND_QUEUE_PARAM( queue, paramName, val, expected, name, type, cast )    \
100 error = clGetCommandQueueInfo( queue, paramName, sizeof( val ), &val, &size );        \
101 test_error( error, "Unable to get command queue " name );                            \
102 if( val != expected )                                                                \
103 {                                                                                    \
104 log_error( "ERROR: Command queue " name " did not validate! (expected " type ", got " type ")\n", (cast)expected, (cast)val );    \
105 return -1;                                                                        \
106 }            \
107 if( size != sizeof( val ) )                \
108 {                                        \
109 log_error( "ERROR: Returned size of command queue " name " does not validate! (expected %d, got %d)\n", (int)sizeof( val ), (int)size );    \
110 return -1;    \
111 }
112 
test_get_command_queue_info_compatibility(cl_device_id deviceID,cl_context context,cl_command_queue ignoreQueue,int num_elements)113 int test_get_command_queue_info_compatibility(cl_device_id deviceID, cl_context context, cl_command_queue ignoreQueue, int num_elements)
114 {
115     int error;
116     size_t size;
117 
118     cl_command_queue_properties device_props;
119     clGetDeviceInfo(deviceID, CL_DEVICE_QUEUE_PROPERTIES, sizeof(device_props), &device_props, NULL);
120     log_info("CL_DEVICE_QUEUE_PROPERTIES is %d\n", (int)device_props);
121 
122     clCommandQueueWrapper queue = clCreateCommandQueue( context, deviceID, device_props, &error );
123     test_error( error, "Unable to create command queue to test with" );
124 
125     cl_uint refCount;
126     error = clGetCommandQueueInfo( queue, CL_QUEUE_REFERENCE_COUNT, sizeof( refCount ), &refCount, &size );
127     test_error( error, "Unable to get command queue reference count" );
128     if( size != sizeof( refCount ) )
129     {
130         log_error( "ERROR: Returned size of command queue reference count does not validate! (expected %d, got %d)\n", (int)sizeof( refCount ), (int)size );
131         return -1;
132     }
133 
134     cl_context otherCtx;
135     TEST_COMMAND_QUEUE_PARAM( queue, CL_QUEUE_CONTEXT, otherCtx, context, "context", "%p", cl_context )
136 
137     cl_device_id otherDevice;
138     error = clGetCommandQueueInfo( queue, CL_QUEUE_DEVICE, sizeof(otherDevice), &otherDevice, &size);
139     test_error(error, "clGetCommandQueue failed.");
140 
141     if (size != sizeof(cl_device_id)) {
142         log_error( " ERROR: Returned size of command queue CL_QUEUE_DEVICE does not validate! (expected %d, got %d)\n", (int)sizeof( otherDevice ), (int)size );
143         return -1;
144     }
145 
146     /* Since the device IDs are opaque types we check the CL_DEVICE_VENDOR_ID which is unique for identical hardware. */
147     cl_uint otherDevice_vid, deviceID_vid;
148     error = clGetDeviceInfo(otherDevice, CL_DEVICE_VENDOR_ID, sizeof(otherDevice_vid), &otherDevice_vid, NULL );
149     test_error( error, "Unable to get device CL_DEVICE_VENDOR_ID" );
150     error = clGetDeviceInfo(deviceID, CL_DEVICE_VENDOR_ID, sizeof(deviceID_vid), &deviceID_vid, NULL );
151     test_error( error, "Unable to get device CL_DEVICE_VENDOR_ID" );
152 
153     if( otherDevice_vid != deviceID_vid )
154     {
155         log_error( "ERROR: Incorrect device returned for queue! (Expected vendor ID 0x%x, got 0x%x)\n", deviceID_vid, otherDevice_vid );
156         return -1;
157     }
158 
159     cl_command_queue_properties props;
160     TEST_COMMAND_QUEUE_PARAM( queue, CL_QUEUE_PROPERTIES, props, (unsigned int)( device_props ), "properties", "%d", unsigned int )
161 
162     return 0;
163 }
164 
165