xref: /aosp_15_r20/external/OpenCL-CTS/test_conformance/pipes/test_pipe_info.cpp (revision 6467f958c7de8070b317fc65bcb0f6472e388d82)
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 "procs.h"
17 #include "harness/parseParameters.h"
18 
19 const char* pipe_kernel_code = {
20     "__kernel void pipe_kernel(__write_only pipe int out_pipe)\n"
21     "{}\n" };
22 
test_pipe_info(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)23 int test_pipe_info( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
24 {
25     clMemWrapper pipe;
26     cl_int err;
27     cl_uint pipe_width = 512;
28     cl_uint pipe_depth = 1024;
29     cl_uint returnVal;
30     clProgramWrapper program;
31     clKernelWrapper kernel;
32 
33     pipe = clCreatePipe(context, CL_MEM_HOST_NO_ACCESS, pipe_width, pipe_depth,
34                         NULL, &err);
35     test_error(err, "clCreatePipe failed.");
36 
37     err = clGetPipeInfo(pipe, CL_PIPE_PACKET_SIZE, sizeof(pipe_width),
38                         (void *)&returnVal, NULL);
39     test_error(err, "clGetPipeInfo failed.");
40 
41     if (pipe_width != returnVal)
42     {
43         test_fail("Error in clGetPipeInfo() check of pipe packet size\n");
44     }
45     else
46     {
47         log_info( " CL_PIPE_PACKET_SIZE passed.\n" );
48     }
49 
50     err = clGetPipeInfo(pipe, CL_PIPE_MAX_PACKETS, sizeof(pipe_depth), (void *)&returnVal, NULL);
51     test_error(err, "clGetPipeInfo failed.");
52 
53     if(pipe_depth != returnVal)
54     {
55         test_fail("Error in clGetPipeInfo() check of pipe max packets\n");
56     }
57     else
58     {
59         log_info( " CL_PIPE_MAX_PACKETS passed.\n" );
60     }
61 
62     err = create_single_kernel_helper_with_build_options(
63         context, &program, &kernel, 1, &pipe_kernel_code, "pipe_kernel",
64         "-cl-std=CL2.0 -cl-kernel-arg-info");
65     test_error_fail(err, "Error creating program");
66 
67     cl_kernel_arg_type_qualifier arg_type_qualifier = 0;
68     err = clGetKernelArgInfo(kernel, 0, CL_KERNEL_ARG_TYPE_QUALIFIER,
69                              sizeof(arg_type_qualifier), &arg_type_qualifier,
70                              NULL);
71     if (gCompilationMode == kOnline)
72     {
73         test_error_fail(err, "clGetKernelArgInfo failed");
74         if (arg_type_qualifier != CL_KERNEL_ARG_TYPE_PIPE)
75         {
76             test_fail("ERROR: Incorrect type qualifier: %i\n",
77                       arg_type_qualifier);
78         }
79     }
80     else
81     {
82         test_failure_error_ret(err, CL_KERNEL_ARG_INFO_NOT_AVAILABLE,
83                                "clGetKernelArgInfo error not as expected",
84                                TEST_FAIL);
85     }
86 
87     return TEST_PASS;
88 }
89