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 #if (defined( __APPLE__ ) || defined( __linux__ ))
18 #include <unistd.h>
19 #endif
20 
21 const char * image_supported_source = "kernel void enabled(global int * buf) { \r\n" \
22 "int n = get_global_id(0); \r\n"\
23 "buf[n] = 0; \r\n "\
24 "#ifndef __IMAGE_SUPPORT__ \r\n" \
25 "ERROR; \r\n"\
26 "#endif \r\n"\
27 "\r\n } \r\n";
28 
29 
30 const char * image_not_supported_source = "kernel void not_enabled(global int * buf) { \r\n" \
31 "int n = get_global_id(0); \r\n"\
32 "buf[n] = 0; \r\n "\
33 "#ifdef __IMAGE_SUPPORT__ \r\n" \
34 "ERROR; \r\n"\
35 "#endif \r\n"\
36 "\r\n } \r\n";
37 
38 
test_image_macro(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)39 int test_image_macro(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
40 {
41     cl_bool image_support;
42     char buf[256];
43     int status;
44     cl_program program;
45 
46     status = clGetDeviceInfo( deviceID, CL_DEVICE_NAME, sizeof( buf ), buf, NULL );
47     if( status )
48     {
49       log_error( "getting device info (name): %d\n", status );
50       exit(-1);
51     }
52 
53     status = clGetDeviceInfo( deviceID, CL_DEVICE_IMAGE_SUPPORT, sizeof( image_support ), &image_support, NULL );
54     if( status )
55     {
56       log_error( "getting device info (image support): %d\n", status );
57       return status;
58     }
59 
60     if (image_support == CL_TRUE)
61     {
62         status = create_single_kernel_helper_create_program(context, &program, 1, (const char**)&image_supported_source);
63 
64         if( status )
65         {
66             log_error ("Failure creating program, [%d] \n", status );
67             return status;
68         }
69 
70         status = clBuildProgram( program, 1, &deviceID, NULL, NULL, NULL );
71         if( status )
72             log_error("CL_DEVICE_IMAGE_SUPPORT is set, __IMAGE_SUPPORT__ macro not set \n");
73         else
74             log_info("CL_DEVICE_IMAGE_SUPPORT is set, __IMAGE_SUPPORT__ macro is set \n");
75     }
76     else
77     {
78         status = create_single_kernel_helper_create_program(context, &program, 1, (const char**)&image_not_supported_source);
79         if( status )
80         {
81             log_error ("Failure creating program, [%d] \n", status );
82             return status;
83         }
84 
85         status = clBuildProgram( program, 1, &deviceID, NULL, NULL, NULL );
86         if( status )
87             log_error("CL_DEVICE_IMAGE_SUPPORT not set, __IMAGE_SUPPORT__ macro is set \n");
88         else
89             log_info("CL_DEVICE_IMAGE_SUPPORT not set, __IMAGE_SUPPORT__ macro not set \n");
90     }
91 
92     status = clReleaseProgram( program );
93     if( status )
94     {
95         log_error ("Unable to release program object, [%d] \n", status );
96         return status;
97     }
98 
99     return status;
100 }
101 
102