• 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 #ifndef test_conformance_checker_Image_MEM_HOST_NO_ACCESS_h
17 #define test_conformance_checker_Image_MEM_HOST_NO_ACCESS_h
18 
19 #include "checker_image_mem_host_write_only.hpp"
20 
21 template < class T>
22 class cImage_check_mem_host_no_access : public cImage_check_mem_host_write_only<T>
23 {
24 public:
cImage_check_mem_host_no_access(cl_device_id deviceID,cl_context context,cl_command_queue queue)25   cImage_check_mem_host_no_access (cl_device_id deviceID, cl_context context, cl_command_queue queue)
26   : cImage_check_mem_host_write_only <T> (deviceID,context, queue)
27   {
28   }
29 
~cImage_check_mem_host_no_access()30   ~cImage_check_mem_host_no_access() {};
31 
32   cl_int verify_RW_Image();
33   cl_int verify_RW_Image_Mapping();
34 };
35 
36 template < class T>
verify_RW_Image()37 cl_int cImage_check_mem_host_no_access<T>:: verify_RW_Image()
38 {
39   this->Init_rect();
40 
41   cl_event event;
42   size_t img_orig[3] = {0, 0, 0};
43   size_t img_region[3] = {0, 0, 0};
44   img_region[0] = this->m_cl_Image_desc.image_width;
45   img_region[1] = this->m_cl_Image_desc.image_height;
46   img_region[2] = this->m_cl_Image_desc.image_depth;
47 
48   int color[4] = {0xFF, 0xFF, 0xFF, 0xFF};
49   cl_int err = CL_SUCCESS;
50   err = clEnqueueFillImage(this->m_queue, this->m_Image,
51                           &color,
52                           img_orig, img_region,
53                           0, NULL, &event);
54   test_error(err, "clEnqueueFillImage error");
55 
56   if (!this->m_blocking) {
57     err = clWaitForEvents(1, &event);
58     test_error(err, "clWaitForEvents error");
59   }
60 
61   err = clReleaseEvent(event);
62   test_error(err, "clReleaseEvent error");
63 
64   this->update_host_mem_2();
65 
66   int total = (int)(this->region[0] * this->region[1] * this->region[2]);
67 
68   T v = 0xFFFFFFFF;
69   int tot = (int)(this->host_m_2.Count(v));
70   if(tot != total){
71     log_error("Buffer data content difference found\n");
72     return FAILURE;
73   }
74 
75   err = clEnqueueWriteImage(this->m_queue, this->m_Image, this->m_blocking,
76                             this->buffer_origin, this->region,
77                             this-> buffer_row_pitch_bytes, this->buffer_slice_pitch_bytes,
78                             this->host_m_1.pData, 0, NULL, &event);
79 
80   if (err == CL_SUCCESS) {
81     log_error("Calling clEnqueueWriteImage on a memory object created with the CL_MEM_HOST_NO_ACCESS flag should not return CL_SUCCESS\n");
82     err = FAILURE;
83     return err;
84 
85   } else {
86     log_info("Test succeeded\n\n");
87     err = CL_SUCCESS;
88   }
89 
90   v = 0;
91   this->host_m_2.Set_to(v);
92   err = clEnqueueReadImage(this->m_queue, this->m_Image, this->m_blocking,
93                            this->buffer_origin, this->region,
94                            this-> buffer_row_pitch_bytes, this->buffer_slice_pitch_bytes,
95                            this->host_m_2.pData, 0, NULL, &event);
96 
97   if (err == CL_SUCCESS) {
98     log_error("Calling clEnqueueReadImage on a memory object created with the CL_MEM_HOST_NO_ACCESS flag should not return CL_SUCCESS\n");
99     err = FAILURE;
100     return err;
101 
102   } else {
103     log_info("Test succeeded\n\n");
104     err = CL_SUCCESS;
105   }
106 
107   return err;
108 }
109 
110 template < class T>
verify_RW_Image_Mapping()111 cl_int cImage_check_mem_host_no_access<T>::verify_RW_Image_Mapping()
112 {
113   this->Init_rect();
114 
115   cl_event event;
116   cl_int err = CL_SUCCESS;
117 
118   T * dataPtr = (T*) clEnqueueMapImage(this->m_queue, this->m_Image, this->m_blocking,
119                                        CL_MAP_WRITE,
120                                        this->buffer_origin, this->region,
121                                        &(this-> buffer_row_pitch_bytes),
122                                        &(this->buffer_slice_pitch_bytes),
123                                        0, NULL, &event, &err);
124 
125   if ( err ==  CL_SUCCESS)    {
126     log_error("Calling clEnqueueMapImage (CL_MAP_WRITE) on a memory object created with the CL_MEM_HOST_NO_ACCESS flag should not return CL_SUCCESS\n");
127     err = FAILURE;
128     return err;
129 
130   } else {
131     log_info("Test succeeded\n\n");
132     err = CL_SUCCESS;
133   }
134 
135   dataPtr = (T*) clEnqueueMapImage(this->m_queue, this->m_Image, this->m_blocking,
136                                    CL_MAP_READ,
137                                    this->buffer_origin, this->region,
138                                    &(this-> buffer_row_pitch_bytes),
139                                    &(this->buffer_slice_pitch_bytes),
140                                    0, NULL, &event, &err);
141 
142   if (err == CL_SUCCESS) {
143     log_error("Calling clEnqueueMapImage (CL_MAP_READ) on a memory object created with the CL_MEM_HOST_NO_ACCESS flag should not return CL_SUCCESS\n");
144     err = FAILURE;
145     return err;
146 
147   } else {
148     log_info("Test succeeded\n\n");
149     err = CL_SUCCESS;
150   }
151 
152   return err;
153 }
154 
155 #endif
156