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 #include "testBase.h" 17 18 19 #include "harness/conversions.h" 20 #include "harness/typeWrappers.h" 21 22 typedef struct _clState 23 { 24 cl_device_id m_device; 25 cl_context m_context; 26 cl_command_queue m_queue; 27 28 cl_program m_program; 29 cl_kernel m_kernel; 30 size_t m_numThreads; 31 } clState; 32 33 clState* newClState(cl_device_id device, cl_context context, 34 cl_command_queue queue); 35 clState* destroyClState(clState* pState); 36 37 int clStateMakeProgram(clState* pState, const char* prog, 38 const char* kernelName); 39 void clStateDestroyProgramAndKernel(clState* pState); 40 41 int runKernel(clState* pState, size_t numThreads); 42 43 typedef struct _bufferStruct 44 { 45 void* m_pIn; 46 void* m_pOut; 47 48 cl_mem m_outBuffer; 49 cl_mem m_inBuffer; 50 51 size_t m_bufSizeIn, m_bufSizeOut; 52 53 int m_bufferUploaded; 54 } bufferStruct; 55 56 57 bufferStruct* newBufferStruct(size_t inSize, size_t outSize, clState* pClState); 58 59 bufferStruct* destroyBufferStruct(bufferStruct* destroyMe, clState* pClState); 60 61 void initContents(bufferStruct* pBufferStruct, clState* pClState, 62 size_t typeSize, size_t vecWidth); 63 64 int pushArgs(bufferStruct* pBufferStruct, clState* pClState); 65 int retrieveResults(bufferStruct* pBufferStruct, clState* pClState); 66 67 int checkCorrectnessStep(bufferStruct* pBufferStruct, clState* pClState, 68 size_t typeSize, size_t vecWidth); 69 // vecSizeIdx indexes into g_arrVecAlignMasks, g_arrVecSizeNames 70 // and g_arrVecSizes 71 int checkCorrectnessAlign(bufferStruct* pBufferStruct, clState* pClState, 72 size_t minAlign); 73 74 int checkPackedCorrectness(bufferStruct* pBufferStruct, clState* pClState, 75 size_t totSize, size_t beforeSize); 76