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