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