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_check_mem_host_no_access_h
17 #define test_conformance_check_mem_host_no_access_h
18
19
20 #include "checker_mem_host_write_only.hpp"
21
22 template <class T>
23 class cBuffer_check_mem_host_no_access
24 : public cBuffer_check_mem_host_write_only<T> {
25 public:
cBuffer_check_mem_host_no_access(cl_device_id deviceID,cl_context context,cl_command_queue queue)26 cBuffer_check_mem_host_no_access(cl_device_id deviceID, cl_context context,
27 cl_command_queue queue)
28 : cBuffer_check_mem_host_write_only<T>(deviceID, context, queue){};
29
cBuffer_check_mem_host_no_access()30 cBuffer_check_mem_host_no_access(){};
31
32 virtual cl_int SetupBuffer();
33 virtual cl_int SetupASSubBuffer(cl_mem_flags parent_buffer_flag);
34 virtual cl_int Setup_Test_Environment();
35
36 cl_int verify_RW_Buffer();
37 cl_int verify_RW_Buffer_rect();
38 cl_int verify_RW_Buffer_mapping();
39 };
40
SetupBuffer()41 template <class T> cl_int cBuffer_check_mem_host_no_access<T>::SetupBuffer()
42 {
43 this->m_nNumber_elements = 1000;
44 T vv1 = TEST_VALUE;
45 this->host_m_1.Init(this->m_nNumber_elements, vv1);
46
47 T vv2 = 0;
48 this->host_m_2.Init(this->m_nNumber_elements, vv2);
49
50 cl_int err;
51 int block_size_in_byte = this->get_block_size_bytes();
52 this->m_buffer =
53 clCreateBuffer(this->m_context, this->buffer_mem_flag,
54 block_size_in_byte, this->host_m_1.pData, &err);
55 test_error(err, "clCreateBuffer error");
56 err = this->Check_GetMemObjectInfo(this->buffer_mem_flag);
57
58 if (this->buffer_mem_flag | CL_MEM_USE_HOST_PTR)
59 {
60 this->pHost_ptr = (void *)this->host_m_1.pData;
61 }
62
63 return err;
64 }
65
66 template <class T>
SetupASSubBuffer(cl_mem_flags parent_buffer_flag)67 cl_int cBuffer_check_mem_host_no_access<T>::SetupASSubBuffer(
68 cl_mem_flags parent_buffer_flag)
69 {
70 return cBuffer_checker<T>::SetupASSubBuffer(parent_buffer_flag);
71 }
72
73 template <class T>
Setup_Test_Environment()74 cl_int cBuffer_check_mem_host_no_access<T>::Setup_Test_Environment()
75 {
76 cBuffer_check_mem_host_write_only<T>::Setup_Test_Environment();
77
78 return CL_SUCCESS;
79 }
80
81 template <class T>
verify_RW_Buffer()82 cl_int cBuffer_check_mem_host_no_access<T>::verify_RW_Buffer()
83 {
84 cl_event event;
85 cl_int err = clEnqueueReadBuffer(
86 this->m_queue, this->m_buffer, this->m_blocking, 0,
87 this->get_block_size_bytes(), this->host_m_1.pData, 0, NULL, &event);
88
89 if (err == CL_SUCCESS)
90 {
91 log_error(
92 "Calling clEnqueueWriteBuffer on a memory object created with the "
93 "CL_MEM_HOST_NO_ACCESS flag should not return CL_SUCCESS\n");
94 err = FAILURE;
95 return FAILURE;
96 }
97 else
98 {
99 log_info("Test succeeded\n\n");
100 err = CL_SUCCESS;
101 }
102
103 err = clEnqueueWriteBuffer(this->m_queue, this->m_buffer, this->m_blocking,
104 0, this->get_block_size_bytes(),
105 this->host_m_1.pData, 0, NULL, &event);
106
107 if (err == CL_SUCCESS)
108 {
109 log_error(
110 "Calling clEnqueueWriteBuffer on a memory object created with the "
111 "CL_MEM_HOST_NO_ACCESS flag should not return CL_SUCCESS\n");
112 err = FAILURE;
113 return FAILURE;
114 }
115 else
116 {
117 log_info("Test succeeded\n\n");
118 err = CL_SUCCESS;
119 }
120
121 return err;
122 }
123
124 template <class T>
verify_RW_Buffer_rect()125 cl_int cBuffer_check_mem_host_no_access<T>::verify_RW_Buffer_rect()
126 {
127 this->Init_rect();
128 cl_event event;
129 cl_int err = CL_SUCCESS;
130 err = clEnqueueReadBufferRect(
131 this->m_queue, this->m_buffer, this->m_blocking,
132 this->buffer_origin_bytes, this->host_origin_bytes, this->region_bytes,
133 this->buffer_row_pitch_bytes, this->buffer_slice_pitch_bytes,
134 this->host_row_pitch_bytes, this->host_slice_pitch_bytes,
135 this->host_m_2.pData, 0, NULL, &event);
136
137 if (err == CL_SUCCESS)
138 {
139 log_error(
140 "Calling clEnqueueReadBufferRect on a memory object created with "
141 "the CL_MEM_HOST_NO_ACCESS flag should not return CL_SUCCESS\n");
142 err = FAILURE;
143 return FAILURE;
144 }
145 else
146 {
147 log_info("Test succeeded\n\n");
148 err = CL_SUCCESS;
149 }
150
151 err = clEnqueueWriteBufferRect(
152 this->m_queue, this->m_buffer, this->m_blocking,
153 this->buffer_origin_bytes, this->host_origin_bytes, this->region_bytes,
154 this->buffer_row_pitch_bytes, this->buffer_slice_pitch_bytes,
155 this->host_row_pitch_bytes, this->host_slice_pitch_bytes,
156 this->host_m_2.pData, 0, NULL, &event);
157
158 if (err == CL_SUCCESS)
159 {
160 log_error(
161 "Calling clEnqueueWriteBufferRect on a memory object created with "
162 "the CL_MEM_HOST_NO_ACCESS flag should not return CL_SUCCESS\n");
163 err = FAILURE;
164 return FAILURE;
165 }
166 else
167 {
168 log_info("Test succeeded\n\n");
169 err = CL_SUCCESS;
170 }
171
172 return err;
173 }
174
175 template <class T>
verify_RW_Buffer_mapping()176 cl_int cBuffer_check_mem_host_no_access<T>::verify_RW_Buffer_mapping()
177 {
178 cl_event event;
179 cl_int err;
180
181 void *dataPtr;
182 dataPtr = clEnqueueMapBuffer(
183 this->m_queue, this->m_buffer, this->m_blocking, CL_MAP_READ, 0,
184 this->get_block_size_bytes(), 0, NULL, &event, &err);
185 if (err == CL_SUCCESS)
186 {
187 log_error("Calling clEnqueueMapBuffer (CL_MAP_READ) on a memory object "
188 "created with the CL_MEM_HOST_NO_ACCESS flag should not "
189 "return CL_SUCCESS\n");
190 err = FAILURE;
191 return FAILURE;
192 }
193 else
194 {
195 log_info("Test succeeded\n\n");
196 err = CL_SUCCESS;
197 }
198
199 dataPtr = clEnqueueMapBuffer(
200 this->m_queue, this->m_buffer, this->m_blocking, CL_MAP_WRITE, 0,
201 this->get_block_size_bytes(), 0, NULL, &event, &err);
202 if (err == CL_SUCCESS)
203 {
204 log_error("Calling clEnqueueMapBuffer (CL_MAP_WRITE) on a memory "
205 "object created with the CL_MEM_HOST_NO_ACCESS flag should "
206 "not return CL_SUCCESS\n");
207 err = FAILURE;
208 return FAILURE;
209 }
210 else
211 {
212 log_info("Test succeeded\n\n");
213 err = CL_SUCCESS;
214 }
215
216 return err;
217 }
218
219 #endif
220