diff options
Diffstat (limited to 'test_conformance/mem_host_flags/checker_mem_host_read_only.hpp')
-rw-r--r-- | test_conformance/mem_host_flags/checker_mem_host_read_only.hpp | 458 |
1 files changed, 237 insertions, 221 deletions
diff --git a/test_conformance/mem_host_flags/checker_mem_host_read_only.hpp b/test_conformance/mem_host_flags/checker_mem_host_read_only.hpp index 44910b04..ea23ae5a 100644 --- a/test_conformance/mem_host_flags/checker_mem_host_read_only.hpp +++ b/test_conformance/mem_host_flags/checker_mem_host_read_only.hpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 The Khronos Group Inc. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -18,259 +18,275 @@ #include "checker.h" -template < class T> class cBuffer_check_mem_host_read_only : public cBuffer_checker<T> -{ +template <class T> +class cBuffer_check_mem_host_read_only : public cBuffer_checker<T> { public: - cBuffer_check_mem_host_read_only(cl_device_id deviceID, cl_context context, cl_command_queue queue) - : cBuffer_checker <T> (deviceID, context, queue) - { - }; - - ~cBuffer_check_mem_host_read_only() - { - }; - - virtual cl_int Check_GetMemObjectInfo(cl_mem_flags buffer_mem_flag); - virtual cl_int SetupBuffer(); - virtual cl_int SetupASSubBuffer( cl_mem_flags flag_p); - virtual cl_int Setup_Test_Environment(); - - cl_int verifyData(cl_int err, cl_event & event); - cl_int verify_RW_Buffer(); - cl_int verify_RW_Buffer_rect(); - cl_int verify_RW_Buffer_mapping(); -}; + cBuffer_check_mem_host_read_only(cl_device_id deviceID, cl_context context, + cl_command_queue queue) + : cBuffer_checker<T>(deviceID, context, queue){}; -template < class T > -cl_int cBuffer_check_mem_host_read_only< T >::SetupBuffer() -{ - this->m_buffer_type = _BUFFER; + ~cBuffer_check_mem_host_read_only(){}; - this->m_nNumber_elements = 888; - T vv1 = TEST_VALUE; - this->host_m_1.Init(this->m_nNumber_elements, vv1); - this->host_m_0.Init(this->m_nNumber_elements, vv1); + virtual cl_int Check_GetMemObjectInfo(cl_mem_flags buffer_mem_flag); + virtual cl_int SetupBuffer(); + virtual cl_int SetupASSubBuffer(cl_mem_flags flag_p); + virtual cl_int Setup_Test_Environment(); - cl_int err = CL_SUCCESS; - int block_size_in_byte = (int)(this->m_nNumber_elements * sizeof(T)); - this->m_buffer = clCreateBuffer(this->m_context, this->buffer_mem_flag, - block_size_in_byte, this->host_m_1.pData, &err); - test_error(err, "clCreateBuffer error"); + cl_int verifyData(cl_int err, cl_event &event); + cl_int verify_RW_Buffer(); + cl_int verify_RW_Buffer_rect(); + cl_int verify_RW_Buffer_mapping(); +}; - if (this->buffer_mem_flag & CL_MEM_USE_HOST_PTR) - { - this->pHost_ptr = (void *)this->host_m_1.pData; - } +template <class T> cl_int cBuffer_check_mem_host_read_only<T>::SetupBuffer() +{ + this->m_buffer_type = _BUFFER; + + this->m_nNumber_elements = 888; + T vv1 = TEST_VALUE; + this->host_m_1.Init(this->m_nNumber_elements, vv1); + this->host_m_0.Init(this->m_nNumber_elements, vv1); + + cl_int err = CL_SUCCESS; + int block_size_in_byte = (int)(this->m_nNumber_elements * sizeof(T)); + this->m_buffer = + clCreateBuffer(this->m_context, this->buffer_mem_flag, + block_size_in_byte, this->host_m_1.pData, &err); + test_error(err, "clCreateBuffer error"); + + if (this->buffer_mem_flag & CL_MEM_USE_HOST_PTR) + { + this->pHost_ptr = (void *)this->host_m_1.pData; + } - return err; + return err; } -template < class T > -cl_int cBuffer_check_mem_host_read_only<T>::SetupASSubBuffer(cl_mem_flags flag_p) +template <class T> +cl_int +cBuffer_check_mem_host_read_only<T>::SetupASSubBuffer(cl_mem_flags flag_p) { - return cBuffer_checker<T>::SetupASSubBuffer(flag_p); + return cBuffer_checker<T>::SetupASSubBuffer(flag_p); } -template < class T> +template <class T> cl_int cBuffer_check_mem_host_read_only<T>::Setup_Test_Environment() { - cBuffer_checker<T>::Setup_Test_Environment(); - T vv2 = 0; - this->host_m_2.Init(this->m_nNumber_elements, vv2); + cBuffer_checker<T>::Setup_Test_Environment(); + T vv2 = 0; + this->host_m_2.Init(this->m_nNumber_elements, vv2); - return CL_SUCCESS; + return CL_SUCCESS; } -template < class T > -cl_int cBuffer_check_mem_host_read_only< T >::Check_GetMemObjectInfo(cl_mem_flags buffer_mem_flag) +template <class T> +cl_int cBuffer_check_mem_host_read_only<T>::Check_GetMemObjectInfo( + cl_mem_flags buffer_mem_flag) { - cl_int err = CL_SUCCESS; - cBuffer_checker<T>::Check_GetMemObjectInfo(buffer_mem_flag); - - if (buffer_mem_flag & CL_MEM_ALLOC_HOST_PTR) - { - size_t size = 0; - err = clGetMemObjectInfo(this->m_buffer, CL_MEM_SIZE, sizeof(size), &size, NULL); - void *pp = NULL; - err = clGetMemObjectInfo(this->m_buffer, CL_MEM_HOST_PTR, sizeof( pp ), &pp, NULL); - - if (!this->host_m_1.Equal( (T*) (this->pData), this->m_nNumber_elements )) { - log_error("Buffer data difference found\n"); - return FAILURE; + cl_int err = CL_SUCCESS; + cBuffer_checker<T>::Check_GetMemObjectInfo(buffer_mem_flag); + + if (buffer_mem_flag & CL_MEM_ALLOC_HOST_PTR) + { + size_t size = 0; + err = clGetMemObjectInfo(this->m_buffer, CL_MEM_SIZE, sizeof(size), + &size, NULL); + void *pp = NULL; + err = clGetMemObjectInfo(this->m_buffer, CL_MEM_HOST_PTR, sizeof(pp), + &pp, NULL); + + if (!this->host_m_1.Equal((T *)(this->pData), this->m_nNumber_elements)) + { + log_error("Buffer data difference found\n"); + return FAILURE; + } } - } - return err; + return err; } -template < class T > -cl_int cBuffer_check_mem_host_read_only< T >::verifyData( cl_int err, cl_event & event ) +template <class T> +cl_int cBuffer_check_mem_host_read_only<T>::verifyData(cl_int err, + cl_event &event) { - if (err != CL_SUCCESS) { - err = this->m_nERROR_RETURN_CODE; - test_error(err, "clEnqueueReadBuffer error"); - } + if (err != CL_SUCCESS) + { + err = this->m_nERROR_RETURN_CODE; + test_error(err, "clEnqueueReadBuffer error"); + } - if (!this->host_m_1.Equal(this->host_m_2)) { - err = this->m_nERROR_RETURN_CODE; - test_error(err, "clEnqueueReadBuffer data difference found"); - } + if (!this->host_m_1.Equal(this->host_m_2)) + { + err = this->m_nERROR_RETURN_CODE; + test_error(err, "clEnqueueReadBuffer data difference found"); + } - return err; + return err; } -template < class T > -cl_int cBuffer_check_mem_host_read_only< T >::verify_RW_Buffer() +template <class T> +cl_int cBuffer_check_mem_host_read_only<T>::verify_RW_Buffer() { - cl_event event; - cl_int err = CL_SUCCESS; - - err = clEnqueueReadBuffer(this->m_queue, this->m_buffer, this->m_blocking, - 0, this->get_block_size_bytes(), this->host_m_2.pData, - 0, NULL, &event); - test_error(err, "clEnqueueReadBuffer error"); - - if (!this->m_blocking) { - err = clWaitForEvents(1, &event); - test_error(err, "clWaitForEvents error"); - } - - if (!this->host_m_1.Equal(this->host_m_2)) { - log_error("Buffer data difference found\n"); - return FAILURE; - } - err = clReleaseEvent(event); - test_error(err, "clReleaseEvent error"); - - // test write - err = clEnqueueWriteBuffer(this->m_queue, this->m_buffer, this->m_blocking, - 0, this->get_block_size_bytes(), this->host_m_2.pData, - 0, NULL, &event); - - if (err == CL_SUCCESS) { - log_error("Calling clEnqueueWriteBuffer on a memory object created with the CL_MEM_HOST_READ_ONLY flag should not return CL_SUCCESS\n"); - err = FAILURE; - return FAILURE; - - } else { - log_info("Test succeeded\n\n"); - err = CL_SUCCESS; - } - - return err; + cl_event event; + cl_int err = CL_SUCCESS; + + err = clEnqueueReadBuffer(this->m_queue, this->m_buffer, this->m_blocking, + 0, this->get_block_size_bytes(), + this->host_m_2.pData, 0, NULL, &event); + test_error(err, "clEnqueueReadBuffer error"); + + if (!this->m_blocking) + { + err = clWaitForEvents(1, &event); + test_error(err, "clWaitForEvents error"); + } + + if (!this->host_m_1.Equal(this->host_m_2)) + { + log_error("Buffer data difference found\n"); + return FAILURE; + } + err = clReleaseEvent(event); + test_error(err, "clReleaseEvent error"); + + // test write + err = clEnqueueWriteBuffer(this->m_queue, this->m_buffer, this->m_blocking, + 0, this->get_block_size_bytes(), + this->host_m_2.pData, 0, NULL, &event); + + if (err == CL_SUCCESS) + { + log_error( + "Calling clEnqueueWriteBuffer on a memory object created with the " + "CL_MEM_HOST_READ_ONLY flag should not return CL_SUCCESS\n"); + err = FAILURE; + return FAILURE; + } + else + { + log_info("Test succeeded\n\n"); + err = CL_SUCCESS; + } + + return err; } -template < class T > -cl_int cBuffer_check_mem_host_read_only< T >::verify_RW_Buffer_rect() +template <class T> +cl_int cBuffer_check_mem_host_read_only<T>::verify_RW_Buffer_rect() { - this->Init_rect(); - - T vv2 = 0; - this->host_m_2.Set_to( vv2 ); - cl_event event; - cl_int err = CL_SUCCESS; - - err = clEnqueueReadBufferRect(this->m_queue, this->m_buffer, this->m_blocking, - this->buffer_origin_bytes, - this->host_origin_bytes, - this->region_bytes, - this->buffer_row_pitch_bytes, - this->buffer_slice_pitch_bytes, - this->host_row_pitch_bytes, - this->host_slice_pitch_bytes, - this->host_m_2.pData, - 0, NULL, &event); - test_error(err, "clEnqueueReadBufferRect error"); - - if (!this->m_blocking) { - err = clWaitForEvents(1, &event); - test_error(err, "clWaitForEvents error"); - } - - if (! this->host_m_1.Equal_rect(this->host_m_2, this->host_origin, this->region, - this->host_row_pitch, this->host_slice_pitch)) { - log_error("Buffer data diffeence found\n"); - return FAILURE; - } - err = clReleaseEvent(event); - test_error(err, "clReleaseEvent error"); - - // test blocking write rect - err = clEnqueueWriteBufferRect(this->m_queue, this->m_buffer, this->m_blocking, - this->buffer_origin_bytes, - this->host_origin_bytes, - this->region_bytes, - this->buffer_row_pitch_bytes, - this->buffer_slice_pitch_bytes, - this->host_row_pitch_bytes, - this->host_slice_pitch_bytes, - this->host_m_2.pData, - 0, NULL, &event); - - if (err == CL_SUCCESS) { - log_error("Calling clEnqueueWriteBufferRect on a memory object created with the CL_MEM_HOST_READ_ONLY flag should not return CL_SUCCESS\n"); - err = FAILURE; - return FAILURE; - - } else { - log_info("Test succeeded\n\n"); - err = CL_SUCCESS; - } - - return err; + this->Init_rect(); + + T vv2 = 0; + this->host_m_2.Set_to(vv2); + cl_event event; + cl_int err = CL_SUCCESS; + + err = clEnqueueReadBufferRect( + this->m_queue, this->m_buffer, this->m_blocking, + this->buffer_origin_bytes, this->host_origin_bytes, this->region_bytes, + this->buffer_row_pitch_bytes, this->buffer_slice_pitch_bytes, + this->host_row_pitch_bytes, this->host_slice_pitch_bytes, + this->host_m_2.pData, 0, NULL, &event); + test_error(err, "clEnqueueReadBufferRect error"); + + if (!this->m_blocking) + { + err = clWaitForEvents(1, &event); + test_error(err, "clWaitForEvents error"); + } + + if (!this->host_m_1.Equal_rect(this->host_m_2, this->host_origin, + this->region, this->host_row_pitch, + this->host_slice_pitch)) + { + log_error("Buffer data diffeence found\n"); + return FAILURE; + } + err = clReleaseEvent(event); + test_error(err, "clReleaseEvent error"); + + // test blocking write rect + err = clEnqueueWriteBufferRect( + this->m_queue, this->m_buffer, this->m_blocking, + this->buffer_origin_bytes, this->host_origin_bytes, this->region_bytes, + this->buffer_row_pitch_bytes, this->buffer_slice_pitch_bytes, + this->host_row_pitch_bytes, this->host_slice_pitch_bytes, + this->host_m_2.pData, 0, NULL, &event); + + if (err == CL_SUCCESS) + { + log_error( + "Calling clEnqueueWriteBufferRect on a memory object created with " + "the CL_MEM_HOST_READ_ONLY flag should not return CL_SUCCESS\n"); + err = FAILURE; + return FAILURE; + } + else + { + log_info("Test succeeded\n\n"); + err = CL_SUCCESS; + } + + return err; } -template < class T > -cl_int cBuffer_check_mem_host_read_only< T >::verify_RW_Buffer_mapping() +template <class T> +cl_int cBuffer_check_mem_host_read_only<T>::verify_RW_Buffer_mapping() { - cl_int err = CL_SUCCESS; - cl_event event; - void *dataPtr; - dataPtr = clEnqueueMapBuffer(this->m_queue, this->m_buffer, this->m_blocking, - CL_MAP_READ, - 0, this->get_block_size_bytes(), - 0, NULL, &event, &err); - test_error(err, "clEnqueueMapBuffer error"); - - if (!this->m_blocking) { - err = clWaitForEvents(1, &event ); - test_error(err, "clWaitForEvents error"); - } - - if ((this->buffer_mem_flag & CL_MEM_USE_HOST_PTR) && dataPtr != this->pHost_ptr ) { - log_error("Mapped host pointer difference found\n"); - return FAILURE; - } - - if(!this->host_m_1.Equal((T*)dataPtr, this->m_nNumber_elements)) { - log_error("Buffer content difference found\n"); - return FAILURE; - } - - err = clReleaseEvent(event); - test_error(err, "clReleaseEvent error"); - - err = clEnqueueUnmapMemObject(this->m_queue, this->m_buffer, dataPtr, 0, - nullptr, nullptr); - test_error(err, "clEnqueueUnmapMemObject error"); - - // test blocking map read - clEnqueueMapBuffer(this->m_queue, this->m_buffer, this->m_blocking, - CL_MAP_WRITE, - 0, this->get_block_size_bytes(), - 0, NULL, &event, &err); - - if (err == CL_SUCCESS) { - log_error("Calling clEnqueueMapBuffer (CL_MAP_WRITE) on a memory object created with the CL_MEM_HOST_READ_ONLY flag should not return CL_SUCCESS\n"); - err = FAILURE; - return FAILURE; - - } else { - log_info("Test succeeded\n\n"); - err = CL_SUCCESS; - } - - return err; + cl_int err = CL_SUCCESS; + cl_event event; + void *dataPtr; + dataPtr = clEnqueueMapBuffer( + this->m_queue, this->m_buffer, this->m_blocking, CL_MAP_READ, 0, + this->get_block_size_bytes(), 0, NULL, &event, &err); + test_error(err, "clEnqueueMapBuffer error"); + + if (!this->m_blocking) + { + err = clWaitForEvents(1, &event); + test_error(err, "clWaitForEvents error"); + } + + if ((this->buffer_mem_flag & CL_MEM_USE_HOST_PTR) + && dataPtr != this->pHost_ptr) + { + log_error("Mapped host pointer difference found\n"); + return FAILURE; + } + + if (!this->host_m_1.Equal((T *)dataPtr, this->m_nNumber_elements)) + { + log_error("Buffer content difference found\n"); + return FAILURE; + } + + err = clReleaseEvent(event); + test_error(err, "clReleaseEvent error"); + + err = clEnqueueUnmapMemObject(this->m_queue, this->m_buffer, dataPtr, 0, + nullptr, nullptr); + test_error(err, "clEnqueueUnmapMemObject error"); + + // test blocking map read + clEnqueueMapBuffer(this->m_queue, this->m_buffer, this->m_blocking, + CL_MAP_WRITE, 0, this->get_block_size_bytes(), 0, NULL, + &event, &err); + + if (err == CL_SUCCESS) + { + log_error("Calling clEnqueueMapBuffer (CL_MAP_WRITE) on a memory " + "object created with the CL_MEM_HOST_READ_ONLY flag should " + "not return CL_SUCCESS\n"); + err = FAILURE; + return FAILURE; + } + else + { + log_info("Test succeeded\n\n"); + err = CL_SUCCESS; + } + + return err; } #endif |