Merge vec_step and vec_align binaries into a new vectors binary (#926)

* Merge vec_step and vec_align binaries into a new vectors binary

This change just merges the two suites to reuse common functions
and definitions. There is probably room for further code consolidation
but probably best done as a separate change.

Contributes to #683

Signed-off-by: Kevin Petit <kevin.petit@arm.com>

* format fixes
This commit is contained in:
Kévin Petit
2020-09-08 18:16:08 +01:00
committed by GitHub
parent 75ce4c5b0e
commit 869d5a1032
33 changed files with 618 additions and 1273 deletions

View File

@@ -39,8 +39,7 @@ add_subdirectory( profiling )
add_subdirectory( relationals ) add_subdirectory( relationals )
add_subdirectory( select ) add_subdirectory( select )
add_subdirectory( thread_dimensions ) add_subdirectory( thread_dimensions )
add_subdirectory( vec_align ) add_subdirectory( vectors )
add_subdirectory( vec_step )
add_subdirectory( c11_atomics ) add_subdirectory( c11_atomics )
add_subdirectory( device_execution ) add_subdirectory( device_execution )
add_subdirectory( non_uniform_work_group ) add_subdirectory( non_uniform_work_group )

View File

@@ -31,8 +31,7 @@ Profiling,profiling/test_profiling
Events,events/test_events Events,events/test_events
Allocations (single maximum),allocations/test_allocations single 5 all Allocations (single maximum),allocations/test_allocations single 5 all
Allocations (total maximum),allocations/test_allocations multiple 5 all Allocations (total maximum),allocations/test_allocations multiple 5 all
VecAlign, vec_align/test_vecalign Vectors, vectors/test_vectors
VecStep, vec_step/test_vecstep
Printf,printf/test_printf Printf,printf/test_printf
Device Partitioning,device_partition/test_device_partition Device Partitioning,device_partition/test_device_partition
1 #
31 VecStep, vec_step/test_vecstep Printf,printf/test_printf
32 Printf,printf/test_printf Device Partitioning,device_partition/test_device_partition
33 Device Partitioning,device_partition/test_device_partition # #########################################
34 # ######################################### # Buffers and images
# Buffers and images
35 # #########################################
36 Buffers,buffers/test_buffers
37 Images (API Info),images/clGetInfo/test_cl_get_info

View File

@@ -31,8 +31,7 @@ Profiling,profiling/test_profiling
Events,events/test_events Events,events/test_events
Allocations (single maximum),allocations/test_allocations single 5 all Allocations (single maximum),allocations/test_allocations single 5 all
Allocations (total maximum),allocations/test_allocations multiple 5 all Allocations (total maximum),allocations/test_allocations multiple 5 all
VecAlign, vec_align/test_vecalign Vectors, vectors/test_vectors
VecStep, vec_step/test_vecstep
# ######################################### # #########################################
# Buffers and images # Buffers and images
1 #
31 VecStep, vec_step/test_vecstep # #########################################
32 # ######################################### # Buffers and images
33 # Buffers and images # #########################################
34 # ######################################### Buffers,buffers/test_buffers
Buffers,buffers/test_buffers
35 Images (API Info),images/clGetInfo/test_cl_get_info
36 Images (Kernel Methods),images/kernel_image_methods/test_kernel_image_methods
37 Images (Kernel),images/kernel_read_write/test_image_streams CL_FILTER_NEAREST

View File

@@ -31,8 +31,7 @@ Profiling,profiling/test_profiling
Events,events/test_events Events,events/test_events
Allocations (single maximum),allocations/test_allocations single 5 all Allocations (single maximum),allocations/test_allocations single 5 all
Allocations (total maximum),allocations/test_allocations multiple 5 all Allocations (total maximum),allocations/test_allocations multiple 5 all
VecAlign, vec_align/test_vecalign Vectors, vectors/test_vectors
VecStep, vec_step/test_vecstep
Printf,printf/test_printf Printf,printf/test_printf
Device Partitioning,device_partition/test_device_partition Device Partitioning,device_partition/test_device_partition
1 #
31 VecStep, vec_step/test_vecstep Printf,printf/test_printf
32 Printf,printf/test_printf Device Partitioning,device_partition/test_device_partition
33 Device Partitioning,device_partition/test_device_partition # #########################################
34 # ######################################### # Buffers and images
# Buffers and images
35 # #########################################
36 Buffers,buffers/test_buffers
37 Images (API Info),images/clGetInfo/test_cl_get_info

View File

@@ -31,8 +31,7 @@ Profiling,profiling/test_profiling
Events,events/test_events Events,events/test_events
Allocations (single maximum),allocations/test_allocations single 5 all Allocations (single maximum),allocations/test_allocations single 5 all
Allocations (total maximum),allocations/test_allocations multiple 5 all Allocations (total maximum),allocations/test_allocations multiple 5 all
VecAlign, vec_align/test_vecalign Vectors, vectors/test_vectors
VecStep, vec_step/test_vecstep
# ######################################### # #########################################
# Buffers and images # Buffers and images
1 #
31 VecStep, vec_step/test_vecstep # #########################################
32 # ######################################### # Buffers and images
33 # Buffers and images # #########################################
34 # ######################################### Buffers,buffers/test_buffers
Buffers,buffers/test_buffers
35 Images (API Info),images/clGetInfo/test_cl_get_info
36 Images (Kernel Methods),images/kernel_image_methods/test_kernel_image_methods
37 Images (Kernel),images/kernel_read_write/test_image_streams CL_FILTER_NEAREST

View File

@@ -31,8 +31,7 @@ Profiling,profiling/test_profiling --compilation-mode spir-v --compilation-cache
Events,events/test_events --compilation-mode spir-v --compilation-cache-path . Events,events/test_events --compilation-mode spir-v --compilation-cache-path .
Allocations (single maximum),allocations/test_allocations single 5 all --compilation-mode spir-v --compilation-cache-path . Allocations (single maximum),allocations/test_allocations single 5 all --compilation-mode spir-v --compilation-cache-path .
Allocations (total maximum),allocations/test_allocations multiple 5 all --compilation-mode spir-v --compilation-cache-path . Allocations (total maximum),allocations/test_allocations multiple 5 all --compilation-mode spir-v --compilation-cache-path .
VecAlign, vec_align/test_vecalign --compilation-mode spir-v --compilation-cache-path . Vectors, vectors/test_vectors --compilation-mode spir-v --compilation-cache-path .
VecStep, vec_step/test_vecstep --compilation-mode spir-v --compilation-cache-path .
Printf,printf/test_printf --compilation-mode spir-v --compilation-cache-path . Printf,printf/test_printf --compilation-mode spir-v --compilation-cache-path .
Device Partitioning,device_partition/test_device_partition --compilation-mode spir-v --compilation-cache-path . Device Partitioning,device_partition/test_device_partition --compilation-mode spir-v --compilation-cache-path .
1 #
31 VecStep, vec_step/test_vecstep --compilation-mode spir-v --compilation-cache-path . Printf,printf/test_printf --compilation-mode spir-v --compilation-cache-path .
32 Printf,printf/test_printf --compilation-mode spir-v --compilation-cache-path . Device Partitioning,device_partition/test_device_partition --compilation-mode spir-v --compilation-cache-path .
33 Device Partitioning,device_partition/test_device_partition --compilation-mode spir-v --compilation-cache-path . # #########################################
34 # ######################################### # Buffers and images
# Buffers and images
35 # #########################################
36 Images (API Info),images/clGetInfo/test_cl_get_info
37 Buffers,buffers/test_buffers --compilation-mode spir-v --compilation-cache-path .

View File

@@ -33,8 +33,7 @@ Profiling,profiling/test_profiling
Events,events/test_events Events,events/test_events
Allocations (single maximum),allocations/test_allocations single 5 all Allocations (single maximum),allocations/test_allocations single 5 all
Allocations (total maximum),allocations/test_allocations multiple 5 all Allocations (total maximum),allocations/test_allocations multiple 5 all
VecAlign, vec_align/test_vecalign Vectors, vectors/test_vectors
VecStep, vec_step/test_vecstep
Printf,printf/test_printf Printf,printf/test_printf
Device Partitioning,device_partition/test_device_partition Device Partitioning,device_partition/test_device_partition
1 #
33 VecStep, vec_step/test_vecstep Printf,printf/test_printf
34 Printf,printf/test_printf Device Partitioning,device_partition/test_device_partition
35 Device Partitioning,device_partition/test_device_partition # #########################################
36 # ######################################### # Buffers and images
# Buffers and images
37 # #########################################
38 Buffers,buffers/test_buffers
39 Images (Kernel Methods),images/kernel_image_methods/test_kernel_image_methods

View File

@@ -31,8 +31,7 @@ Profiling,profiling/test_profiling
Events,events/test_events Events,events/test_events
Allocations (single maximum),allocations/test_allocations single 5 all Allocations (single maximum),allocations/test_allocations single 5 all
Allocations (total maximum),allocations/test_allocations multiple 5 all Allocations (total maximum),allocations/test_allocations multiple 5 all
VecAlign, vec_align/test_vecalign Vectors, vectors/test_vectors
VecStep, vec_step/test_vecstep
Printf,printf/test_printf Printf,printf/test_printf
Device Partitioning,device_partition/test_device_partition Device Partitioning,device_partition/test_device_partition
1 #
31 VecStep, vec_step/test_vecstep Printf,printf/test_printf
32 Printf,printf/test_printf Device Partitioning,device_partition/test_device_partition
33 Device Partitioning,device_partition/test_device_partition # #########################################
34 # ######################################### # Buffers and images
# Buffers and images
35 # #########################################
36 Buffers,buffers/test_buffers
37 Images (API Info),images/clGetInfo/test_cl_get_info

View File

@@ -31,8 +31,7 @@ Profiling,profiling/test_profiling
Events,events/test_events Events,events/test_events
Allocations (single maximum),allocations/test_allocations single 5 all Allocations (single maximum),allocations/test_allocations single 5 all
Allocations (total maximum),allocations/test_allocations multiple 5 all Allocations (total maximum),allocations/test_allocations multiple 5 all
VecAlign, vec_align/test_vecalign Vectors, vectors/test_vectors
VecStep, vec_step/test_vecstep
Printf,printf/test_printf Printf,printf/test_printf
Device Partitioning,device_partition/test_device_partition Device Partitioning,device_partition/test_device_partition
1 #
31 VecStep, vec_step/test_vecstep Printf,printf/test_printf
32 Printf,printf/test_printf Device Partitioning,device_partition/test_device_partition
33 Device Partitioning,device_partition/test_device_partition # #########################################
34 # ######################################### # Buffers and images
# Buffers and images
35 # #########################################
36 Buffers,buffers/test_buffers
37 Images (API Info),images/clGetInfo/test_cl_get_info

View File

@@ -1,59 +0,0 @@
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "defines.h"
// 1,2,3,4,8,16 or
// 1,2,4,8,16,3
int g_arrVecSizes[NUM_VECTOR_SIZES] = {1,2,3,4,8,16};
int g_arrVecSteps[NUM_VECTOR_SIZES] = {1,2,4,4,8,16};
const char * g_arrVecSizeNames[NUM_VECTOR_SIZES] = {"", "2","3","4","8","16"};
size_t g_arrVecAlignMasks[NUM_VECTOR_SIZES] = {(size_t)0,
(size_t)0x1, // 2
(size_t)0x3, // 3
(size_t)0x3, // 4
(size_t)0x7, // 8
(size_t)0xf // 16
};
bool g_wimpyMode = false;
ExplicitType types[] = { kChar, kUChar,
kShort, kUShort,
kInt, kUInt,
kLong, kULong,
kFloat, kDouble,
kNumExplicitTypes };
const char *g_arrTypeNames[] =
{
"char", "uchar",
"short", "ushort",
"int", "uint",
"long", "ulong",
"float", "double"
};
extern const size_t g_arrTypeSizes[] =
{
1, 1,
2, 2,
4, 4,
8, 8,
4, 8
};

View File

@@ -1,41 +0,0 @@
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "harness/compat.h"
#include <stdio.h>
#include <string.h>
#include "procs.h"
#include "harness/testHarness.h"
#if !defined(_WIN32)
#include <unistd.h>
#endif
test_definition test_list[] = {
ADD_TEST( vec_align_array ),
ADD_TEST( vec_align_struct ),
ADD_TEST( vec_align_packed_struct ),
ADD_TEST( vec_align_struct_arr ),
ADD_TEST( vec_align_packed_struct_arr ),
};
const int test_num = ARRAY_SIZE( test_list );
int main(int argc, const char *argv[])
{
return runTestHarness( argc, argv, test_num, test_list, false, false, 0 );
}

View File

@@ -1,73 +0,0 @@
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "testBase.h"
#include "harness/conversions.h"
#include "harness/typeWrappers.h"
typedef struct _clState
{
cl_device_id m_device;
cl_context m_context;
cl_command_queue m_queue;
cl_program m_program;
cl_kernel m_kernel;
size_t m_numThreads;
} clState;
clState * newClState(cl_device_id device, cl_context context, cl_command_queue queue);
clState * destroyClState(clState * pState);
int clStateMakeProgram(clState * pState, const char * prog,
const char * kernelName);
void clStateDestroyProgramAndKernel(clState * pState);
int runKernel(clState * pState, size_t numThreads);
typedef struct _bufferStruct
{
void * m_pIn;
void * m_pOut;
cl_mem m_outBuffer;
cl_mem m_inBuffer;
size_t m_bufSizeIn, m_bufSizeOut;
int m_bufferUploaded;
} bufferStruct;
bufferStruct * newBufferStruct(size_t inSize, size_t outSize, clState * pClState);
bufferStruct * destroyBufferStruct(bufferStruct * destroyMe, clState * pClState);
void initContents(bufferStruct * pBufferStruct, clState * pClState,
size_t typeSize,
size_t vecWidth);
int pushArgs(bufferStruct * pBufferStruct, clState * pClState);
int retrieveResults(bufferStruct * pBufferStruct, clState * pClState);
// vecSizeIdx indexes into g_arrVecAlignMasks, g_arrVecSizeNames
// and g_arrVecSizes
int checkCorrectness(bufferStruct * pBufferStruct, clState * pClState,
size_t minAlign);
int checkPackedCorrectness(bufferStruct * pBufferStruct, clState * pClState,
size_t totSize, size_t beforeSize);

View File

@@ -1,23 +0,0 @@
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include <stdlib.h>
size_t doReplace(char * dest, size_t destLength, const char * source,
const char * stringToReplace1, const char * replaceWith1,
const char * stringToReplace2, const char * replaceWith2);
size_t doSingleReplace(char * dest, size_t destLength, const char * source,
const char * stringToReplace, const char * replaceWith);

View File

@@ -1,11 +0,0 @@
set(MODULE_NAME VECSTEP)
set(${MODULE_NAME}_SOURCES
globals.cpp
test_step.cpp
main.cpp
structs.cpp
type_replacer.cpp
)
include(../CMakeCommon.txt)

View File

@@ -1,41 +0,0 @@
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "harness/errorHelpers.h"
#include "harness/kernelHelpers.h"
#include "harness/threadTesting.h"
#include "harness/typeWrappers.h"
#include "harness/conversions.h"
#include "harness/mt19937.h"
// 1,2,3,4,8,16 or
// 1,2,4,8,16,3
#define NUM_VECTOR_SIZES 6
extern int g_arrVecSizes[NUM_VECTOR_SIZES];
extern int g_arrVecSteps[NUM_VECTOR_SIZES];
extern bool g_wimpyMode;
extern const char * g_arrVecSizeNames[NUM_VECTOR_SIZES];
// Define the buffer size that we want to block our test with
#define BUFFER_SIZE (1024*1024)
#define KPAGESIZE 4096
extern ExplicitType types[];
extern const char *g_arrTypeNames[];
extern const size_t g_arrTypeSizes[];

View File

@@ -1,52 +0,0 @@
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "defines.h"
// 1,2,3,4,8,16 or
// 1,2,4,8,16,3
int g_arrVecSizes[NUM_VECTOR_SIZES] = {1,2,3,4,8,16};
int g_arrVecSteps[NUM_VECTOR_SIZES] = {1,2,4,4,8,16};
const char * g_arrVecSizeNames[NUM_VECTOR_SIZES] = {"", "2","3","4","8","16"};
bool g_wimpyMode = false;
ExplicitType types[] = { kChar, kUChar,
kShort, kUShort,
kInt, kUInt,
kLong, kULong,
kFloat, kDouble,
kNumExplicitTypes };
const char *g_arrTypeNames[] =
{
"char", "uchar",
"short", "ushort",
"int", "uint",
"long", "ulong",
"float", "double"
};
extern const size_t g_arrTypeSizes[] =
{
1, 1,
2, 2,
4, 4,
8, 8,
4, 8
};

View File

@@ -1,43 +0,0 @@
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "harness/errorHelpers.h"
#include "harness/kernelHelpers.h"
#include "harness/threadTesting.h"
#include "harness/typeWrappers.h"
#include "harness/conversions.h"
#include "harness/mt19937.h"
// The number of errors to print out for each test in the shuffle tests
#define MAX_ERRORS_TO_PRINT 1
extern int create_program_and_kernel(const char *source, const char *kernel_name, cl_program *program_ret, cl_kernel *kernel_ret);
/*
test_step_type,
test_step_var,
test_step_typedef_type,
test_step_typedef_var,
*/
extern int test_step_type(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
extern int test_step_var(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
extern int test_step_typedef_type(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
extern int test_step_typedef_var(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);

View File

@@ -1,285 +0,0 @@
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "structs.h"
#include "defines.h"
/** typedef struct _bufferStruct
{
void * m_pIn;
void * m_pOut;
cl_mem m_outBuffer;
cl_mem m_inBuffer;
size_t m_bufSize;
} bufferStruct;
*/
clState * newClState(cl_device_id device, cl_context context, cl_command_queue queue)
{
clState * pResult = (clState *)malloc(sizeof(clState));
pResult->m_device = device;
pResult->m_context = context;
pResult->m_queue = queue;
pResult->m_kernel = NULL; pResult->m_program = NULL;
return pResult;
}
clState * destroyClState(clState * pState)
{
clStateDestroyProgramAndKernel(pState);
free(pState);
return NULL;
}
int clStateMakeProgram(clState * pState, const char * prog,
const char * kernelName)
{
const char * srcArr[1] = {NULL};
srcArr[0] = prog;
int err = create_single_kernel_helper(pState->m_context,
&(pState->m_program),
&(pState->m_kernel),
1, srcArr, kernelName );
return err;
}
int runKernel(clState * pState, size_t numThreads) {
int err;
pState->m_numThreads = numThreads;
err = clEnqueueNDRangeKernel(pState->m_queue, pState->m_kernel,
1, NULL, &(pState->m_numThreads),
NULL, 0, NULL, NULL);
if(err != CL_SUCCESS)
{
log_error("clEnqueueNDRangeKernel returned %d (%x)\n",
err, err);
return -1;
}
return 0;
}
void clStateDestroyProgramAndKernel(clState * pState)
{
if(pState->m_kernel != NULL) {
clReleaseKernel( pState->m_kernel );
pState->m_kernel = NULL;
}
if(pState->m_program != NULL) {
clReleaseProgram( pState->m_program );
pState->m_program = NULL;
}
}
bufferStruct * newBufferStruct(size_t inSize, size_t outSize, clState * pClState) {
int error;
bufferStruct * pResult = (bufferStruct *)malloc(sizeof(bufferStruct));
pResult->m_bufSizeIn = inSize;
pResult->m_bufSizeOut = outSize;
pResult->m_pIn = malloc(inSize);
pResult->m_pOut = malloc(outSize);
pResult->m_inBuffer = clCreateBuffer(pClState->m_context, CL_MEM_READ_ONLY,
inSize, NULL, &error);
if( pResult->m_inBuffer == NULL )
{
vlog_error( "clCreateArray failed for input (%d)\n", error );
return destroyBufferStruct(pResult, pClState);
}
pResult->m_outBuffer = clCreateBuffer( pClState->m_context,
CL_MEM_WRITE_ONLY,
outSize,
NULL,
&error );
if( pResult->m_outBuffer == NULL )
{
vlog_error( "clCreateArray failed for output (%d)\n", error );
return destroyBufferStruct(pResult, pClState);
}
return pResult;
}
bufferStruct * destroyBufferStruct(bufferStruct * destroyMe, clState * pClState) {
if(destroyMe)
{
if(destroyMe->m_outBuffer != NULL) {
clReleaseMemObject(destroyMe->m_outBuffer);
destroyMe->m_outBuffer = NULL;
}
if(destroyMe->m_inBuffer != NULL) {
clReleaseMemObject(destroyMe->m_inBuffer);
destroyMe->m_inBuffer = NULL;
}
if(destroyMe->m_pIn != NULL) {
free(destroyMe->m_pIn);
destroyMe->m_pIn = NULL;
}
if(destroyMe->m_pOut != NULL) {
free(destroyMe->m_pOut);
destroyMe->m_pOut = NULL;
}
free((void *)destroyMe);
destroyMe = NULL;
}
return destroyMe;
}
void initContents(bufferStruct * pBufferStruct, clState * pClState,
size_t typeSize,
size_t countIn, size_t countOut )
{
size_t i;
uint64_t start = 0;
switch(typeSize)
{
case 1: {
uint8_t* ub = (uint8_t *)(pBufferStruct->m_pIn);
for (i=0; i < countIn; ++i)
{
ub[i] = (uint8_t)start++;
}
break;
}
case 2: {
uint16_t* us = (uint16_t *)(pBufferStruct->m_pIn);
for (i=0; i < countIn; ++i)
{
us[i] = (uint16_t)start++;
}
break;
}
case 4: {
if (!g_wimpyMode) {
uint32_t* ui = (uint32_t *)(pBufferStruct->m_pIn);
for (i=0; i < countIn; ++i) {
ui[i] = (uint32_t)start++;
}
}
else {
// The short test doesn't iterate over the entire 32 bit space so
// we alternate between positive and negative values
int32_t* ui = (int32_t *)(pBufferStruct->m_pIn);
int32_t sign = 1;
for (i=0; i < countIn; ++i, ++start) {
ui[i] = (int32_t)start*sign;
sign = sign * -1;
}
}
break;
}
case 8: {
// We don't iterate over the entire space of 64 bit so for the
// selects, we want to test positive and negative values
int64_t* ll = (int64_t *)(pBufferStruct->m_pIn);
int64_t sign = 1;
for (i=0; i < countIn; ++i, ++start) {
ll[i] = start*sign;
sign = sign * -1;
}
break;
}
default: {
log_error("invalid type size %x\n", (int)typeSize);
}
}
// pBufferStruct->m_bufSizeIn
// pBufferStruct->m_bufSizeOut
}
int pushArgs(bufferStruct * pBufferStruct, clState * pClState)
{
int err;
err = clEnqueueWriteBuffer(pClState->m_queue, pBufferStruct->m_inBuffer,
CL_TRUE, 0, pBufferStruct->m_bufSizeIn,
pBufferStruct->m_pIn, 0, NULL, NULL);
if(err != CL_SUCCESS)
{
log_error("clEnqueueWriteBuffer failed\n");
return -1;
}
err = clSetKernelArg(pClState->m_kernel, 0,
sizeof(pBufferStruct->m_inBuffer), // pBufferStruct->m_bufSizeIn,
&(pBufferStruct->m_inBuffer));
if(err != CL_SUCCESS)
{
log_error("clSetKernelArgs failed, first arg (0)\n");
return -1;
}
err = clSetKernelArg(pClState->m_kernel, 1,
sizeof(pBufferStruct->m_outBuffer), // pBufferStruct->m_bufSizeOut,
&(pBufferStruct->m_outBuffer));
if(err != CL_SUCCESS)
{
log_error("clSetKernelArgs failed, second arg (1)\n");
return -1;
}
return 0;
}
int retrieveResults(bufferStruct * pBufferStruct, clState * pClState)
{
int err;
err = clEnqueueReadBuffer(pClState->m_queue, pBufferStruct->m_outBuffer,
CL_TRUE, 0, pBufferStruct->m_bufSizeOut,
pBufferStruct->m_pOut, 0, NULL, NULL);
if(err != CL_SUCCESS)
{
log_error("clEnqueueReadBuffer failed\n");
return -1;
}
return 0;
}
int checkCorrectness(bufferStruct * pBufferStruct, clState * pClState,
size_t typeSize,
size_t vecWidth)
{
size_t i;
cl_int targetSize = (cl_int) vecWidth;
cl_int * targetArr = (cl_int *)(pBufferStruct->m_pOut);
if(targetSize == 3)
{
targetSize = 4; // hack for 4-aligned vec3 types
}
for(i = 0; i < pClState->m_numThreads; ++i)
{
if(targetArr[i] != targetSize)
{
vlog_error("Error %ld (of %ld). Expected %d, got %d\n",
i, pClState->m_numThreads,
targetSize, targetArr[i]);
return -1;
}
}
return 0;
}

View File

@@ -1,67 +0,0 @@
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "testBase.h"
#include "harness/conversions.h"
#include "harness/typeWrappers.h"
typedef struct _clState
{
cl_device_id m_device;
cl_context m_context;
cl_command_queue m_queue;
cl_program m_program;
cl_kernel m_kernel;
size_t m_numThreads;
} clState;
clState * newClState(cl_device_id device, cl_context context, cl_command_queue queue);
clState * destroyClState(clState * pState);
int clStateMakeProgram(clState * pState, const char * prog,
const char * kernelName);
void clStateDestroyProgramAndKernel(clState * pState);
int runKernel(clState * pState, size_t numThreads);
typedef struct _bufferStruct
{
void * m_pIn;
void * m_pOut;
cl_mem m_outBuffer;
cl_mem m_inBuffer;
size_t m_bufSizeIn, m_bufSizeOut;
} bufferStruct;
bufferStruct * newBufferStruct(size_t inSize, size_t outSize, clState * pClState);
bufferStruct * destroyBufferStruct(bufferStruct * destroyMe, clState * pClState);
void initContents(bufferStruct * pBufferStruct, clState * pClState,
size_t typeSize,
size_t vecWidth);
int pushArgs(bufferStruct * pBufferStruct, clState * pClState);
int retrieveResults(bufferStruct * pBufferStruct, clState * pClState);
int checkCorrectness(bufferStruct * pBufferStruct, clState * pClState,
size_t typeSize,
size_t vecWidth);

View File

@@ -1,28 +0,0 @@
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef _testBase_h
#define _testBase_h
#include "harness/compat.h"
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "procs.h"
#endif // _testBase_h

View File

@@ -1,115 +0,0 @@
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include <string.h>
#if !defined(_MSC_VER)
#include <stdint.h>
#endif // !_MSC_VER
size_t doReplace(char * dest, size_t destLength, const char * source,
const char * stringToReplace1, const char * replaceWith1,
const char * stringToReplace2, const char * replaceWith2)
{
size_t copyCount = 0;
const char * sourcePtr = source;
char * destPtr = dest;
const char * ptr1;
const char * ptr2;
size_t nJump;
size_t len1, len2;
size_t lenReplace1, lenReplace2;
len1 = strlen(stringToReplace1);
len2 = strlen(stringToReplace2);
lenReplace1 = strlen(replaceWith1);
lenReplace2 = strlen(replaceWith2);
for(;copyCount < destLength && *sourcePtr; )
{
ptr1 = strstr(sourcePtr, stringToReplace1);
ptr2 = strstr(sourcePtr, stringToReplace2);
if(ptr1 != NULL && (ptr2 == NULL || ptr2 > ptr1))
{
nJump = ptr1-sourcePtr;
if(((uintptr_t)ptr1-(uintptr_t)sourcePtr) > destLength-copyCount) { return -1; }
copyCount += nJump;
strncpy(destPtr, sourcePtr, nJump);
destPtr += nJump;
sourcePtr += nJump + len1;
strcpy(destPtr, replaceWith1);
destPtr += lenReplace1;
}
else if(ptr2 != NULL && (ptr1 == NULL || ptr1 >= ptr2))
{
nJump = ptr2-sourcePtr;
if(nJump > destLength-copyCount) { return -2; }
copyCount += nJump;
strncpy(destPtr, sourcePtr, nJump);
destPtr += nJump;
sourcePtr += nJump + len2;
strcpy(destPtr, replaceWith2);
destPtr += lenReplace2;
}
else
{
nJump = strlen(sourcePtr);
if(nJump > destLength-copyCount) { return -3; }
copyCount += nJump;
strcpy(destPtr, sourcePtr);
destPtr += nJump;
sourcePtr += nJump;
}
}
*destPtr = '\0';
return copyCount;
}
size_t doSingleReplace(char * dest, size_t destLength, const char * source,
const char * stringToReplace, const char * replaceWith)
{
size_t copyCount = 0;
const char * sourcePtr = source;
char * destPtr = dest;
const char * ptr;
size_t nJump;
size_t len;
size_t lenReplace;
len = strlen(stringToReplace);
lenReplace = strlen(replaceWith);
for(;copyCount < destLength && *sourcePtr; )
{
ptr = strstr(sourcePtr, stringToReplace);
if(ptr != NULL)
{
nJump = ptr-sourcePtr;
if(((uintptr_t)ptr-(uintptr_t)sourcePtr) > destLength-copyCount) { return -1; }
copyCount += nJump;
strncpy(destPtr, sourcePtr, nJump);
destPtr += nJump;
sourcePtr += nJump + len;
strcpy(destPtr, replaceWith);
destPtr += lenReplace;
}
else
{
nJump = strlen(sourcePtr);
if(nJump > destLength-copyCount) { return -3; }
copyCount += nJump;
strcpy(destPtr, sourcePtr);
destPtr += nJump;
sourcePtr += nJump;
}
}
*destPtr = '\0';
return copyCount;
}

View File

@@ -1,9 +1,10 @@
set(MODULE_NAME VECALIGN) set(MODULE_NAME VECTORS)
set(${MODULE_NAME}_SOURCES set(${MODULE_NAME}_SOURCES
globals.cpp globals.cpp
main.cpp main.cpp
structs.cpp structs.cpp
test_step.cpp
test_vec_align.cpp test_vec_align.cpp
type_replacer.cpp type_replacer.cpp
) )

View File

@@ -1,6 +1,6 @@
// //
// Copyright (c) 2017 The Khronos Group Inc. // Copyright (c) 2017 The Khronos Group Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
@@ -29,11 +29,11 @@ extern int g_arrVecSizes[NUM_VECTOR_SIZES];
extern int g_arrVecSteps[NUM_VECTOR_SIZES]; extern int g_arrVecSteps[NUM_VECTOR_SIZES];
extern bool g_wimpyMode; extern bool g_wimpyMode;
extern const char * g_arrVecSizeNames[NUM_VECTOR_SIZES]; extern const char *g_arrVecSizeNames[NUM_VECTOR_SIZES];
extern size_t g_arrVecAlignMasks[NUM_VECTOR_SIZES]; extern size_t g_arrVecAlignMasks[NUM_VECTOR_SIZES];
// Define the buffer size that we want to block our test with // Define the buffer size that we want to block our test with
#define BUFFER_SIZE (1024*1024) #define BUFFER_SIZE (1024 * 1024)
#define KPAGESIZE 4096 #define KPAGESIZE 4096
extern ExplicitType types[]; extern ExplicitType types[];

View File

@@ -0,0 +1,46 @@
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "defines.h"
// 1,2,3,4,8,16 or
// 1,2,4,8,16,3
int g_arrVecSizes[NUM_VECTOR_SIZES] = { 1, 2, 3, 4, 8, 16 };
int g_arrVecSteps[NUM_VECTOR_SIZES] = { 1, 2, 4, 4, 8, 16 };
const char *g_arrVecSizeNames[NUM_VECTOR_SIZES] = {
"", "2", "3", "4", "8", "16"
};
size_t g_arrVecAlignMasks[NUM_VECTOR_SIZES] = {
(size_t)0,
(size_t)0x1, // 2
(size_t)0x3, // 3
(size_t)0x3, // 4
(size_t)0x7, // 8
(size_t)0xf // 16
};
bool g_wimpyMode = false;
ExplicitType types[] = {
kChar, kUChar, kShort, kUShort, kInt, kUInt, kLong,
kULong, kFloat, kDouble, kNumExplicitTypes
};
const char *g_arrTypeNames[] = { "char", "uchar", "short", "ushort", "int",
"uint", "long", "ulong", "float", "double" };
extern const size_t g_arrTypeSizes[] = { 1, 1, 2, 2, 4, 4, 8, 8, 4, 8 };

View File

@@ -1,6 +1,6 @@
// //
// Copyright (c) 2017 The Khronos Group Inc. // Copyright (c) 2017 The Khronos Group Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
@@ -25,16 +25,20 @@
#endif #endif
test_definition test_list[] = { test_definition test_list[] = {
ADD_TEST( step_type ), ADD_TEST(step_type),
ADD_TEST( step_var ), ADD_TEST(step_var),
ADD_TEST( step_typedef_type ), ADD_TEST(step_typedef_type),
ADD_TEST( step_typedef_var ), ADD_TEST(step_typedef_var),
ADD_TEST(vec_align_array),
ADD_TEST(vec_align_struct),
ADD_TEST(vec_align_packed_struct),
ADD_TEST(vec_align_struct_arr),
ADD_TEST(vec_align_packed_struct_arr),
}; };
const int test_num = ARRAY_SIZE( test_list ); const int test_num = ARRAY_SIZE(test_list);
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
return runTestHarness( argc, argv, test_num, test_list, false, false, 0 ); return runTestHarness(argc, argv, test_num, test_list, false, false, 0);
} }

View File

@@ -1,6 +1,6 @@
// //
// Copyright (c) 2017 The Khronos Group Inc. // Copyright (c) 2017 The Khronos Group Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
@@ -24,16 +24,32 @@
#define MAX_ERRORS_TO_PRINT 1 #define MAX_ERRORS_TO_PRINT 1
extern int create_program_and_kernel(const char *source, const char *kernel_name, cl_program *program_ret, cl_kernel *kernel_ret); extern int create_program_and_kernel(const char *source,
const char *kernel_name,
cl_program *program_ret,
cl_kernel *kernel_ret);
extern int test_step_type(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_step_var(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_step_typedef_type(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_step_typedef_var(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements);
int test_vec_align_array(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements);
int test_vec_align_struct(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements);
int test_vec_align_packed_struct(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements);
int test_vec_align_array(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); int test_vec_align_struct_arr(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements);
int test_vec_align_struct(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); int test_vec_align_packed_struct_arr(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements);
int test_vec_align_packed_struct(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
int test_vec_align_struct_arr(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
int test_vec_align_packed_struct_arr(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);

View File

@@ -1,6 +1,6 @@
// //
// Copyright (c) 2017 The Khronos Group Inc. // Copyright (c) 2017 The Khronos Group Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
@@ -33,9 +33,10 @@
*/ */
clState * newClState(cl_device_id device, cl_context context, cl_command_queue queue) clState *newClState(cl_device_id device, cl_context context,
cl_command_queue queue)
{ {
clState * pResult = (clState *)malloc(sizeof(clState)); clState *pResult = (clState *)malloc(sizeof(clState));
#if DEBUG_MEM_ALLOC #if DEBUG_MEM_ALLOC
log_info("malloc clState * %x\n", pResult); log_info("malloc clState * %x\n", pResult);
#endif #endif
@@ -44,11 +45,12 @@ clState * newClState(cl_device_id device, cl_context context, cl_command_queue q
pResult->m_context = context; pResult->m_context = context;
pResult->m_queue = queue; pResult->m_queue = queue;
pResult->m_kernel = NULL; pResult->m_program = NULL; pResult->m_kernel = NULL;
pResult->m_program = NULL;
return pResult; return pResult;
} }
clState * destroyClState(clState * pState) clState *destroyClState(clState *pState)
{ {
clStateDestroyProgramAndKernel(pState); clStateDestroyProgramAndKernel(pState);
#if DEBUG_MEM_ALLOC #if DEBUG_MEM_ALLOC
@@ -59,55 +61,56 @@ clState * destroyClState(clState * pState)
} }
int clStateMakeProgram(clState * pState, const char * prog, int clStateMakeProgram(clState *pState, const char *prog,
const char * kernelName) const char *kernelName)
{ {
const char * srcArr[1] = {NULL}; const char *srcArr[1] = { NULL };
srcArr[0] = prog; srcArr[0] = prog;
int err = create_single_kernel_helper(pState->m_context, int err =
&(pState->m_program), create_single_kernel_helper(pState->m_context, &(pState->m_program),
&(pState->m_kernel), &(pState->m_kernel), 1, srcArr, kernelName);
1, srcArr, kernelName );
#if DEBUG_MEM_ALLOC #if DEBUG_MEM_ALLOC
log_info("create program and kernel\n"); log_info("create program and kernel\n");
#endif #endif
return err; return err;
} }
int runKernel(clState * pState, size_t numThreads) { int runKernel(clState *pState, size_t numThreads)
{
int err; int err;
pState->m_numThreads = numThreads; pState->m_numThreads = numThreads;
err = clEnqueueNDRangeKernel(pState->m_queue, pState->m_kernel, err = clEnqueueNDRangeKernel(pState->m_queue, pState->m_kernel, 1, NULL,
1, NULL, &(pState->m_numThreads), &(pState->m_numThreads), NULL, 0, NULL, NULL);
NULL, 0, NULL, NULL); if (err != CL_SUCCESS)
if(err != CL_SUCCESS)
{ {
log_error("clEnqueueNDRangeKernel returned %d (%x)\n", log_error("clEnqueueNDRangeKernel returned %d (%x)\n", err, err);
err, err);
return -1; return -1;
} }
return 0; return 0;
} }
void clStateDestroyProgramAndKernel(clState * pState) void clStateDestroyProgramAndKernel(clState *pState)
{ {
#if DEBUG_MEM_ALLOC #if DEBUG_MEM_ALLOC
log_info("destroy program and kernel\n"); log_info("destroy program and kernel\n");
#endif #endif
if(pState->m_kernel != NULL) { if (pState->m_kernel != NULL)
clReleaseKernel( pState->m_kernel ); {
clReleaseKernel(pState->m_kernel);
pState->m_kernel = NULL; pState->m_kernel = NULL;
} }
if(pState->m_program != NULL) { if (pState->m_program != NULL)
clReleaseProgram( pState->m_program ); {
clReleaseProgram(pState->m_program);
pState->m_program = NULL; pState->m_program = NULL;
} }
} }
bufferStruct * newBufferStruct(size_t inSize, size_t outSize, clState * pClState) { bufferStruct *newBufferStruct(size_t inSize, size_t outSize, clState *pClState)
{
int error; int error;
bufferStruct * pResult = (bufferStruct *)malloc(sizeof(bufferStruct)); bufferStruct *pResult = (bufferStruct *)malloc(sizeof(bufferStruct));
#if DEBUG_MEM_ALLOC #if DEBUG_MEM_ALLOC
log_info("malloc bufferStruct * %x\n", pResult); log_info("malloc bufferStruct * %x\n", pResult);
#endif #endif
@@ -124,23 +127,20 @@ bufferStruct * newBufferStruct(size_t inSize, size_t outSize, clState * pClState
pResult->m_inBuffer = clCreateBuffer(pClState->m_context, CL_MEM_READ_ONLY, pResult->m_inBuffer = clCreateBuffer(pClState->m_context, CL_MEM_READ_ONLY,
inSize, NULL, &error); inSize, NULL, &error);
if( pResult->m_inBuffer == NULL ) if (pResult->m_inBuffer == NULL)
{ {
vlog_error( "clCreateArray failed for input (%d)\n", error ); vlog_error("clCreateArray failed for input (%d)\n", error);
return destroyBufferStruct(pResult, pClState); return destroyBufferStruct(pResult, pClState);
} }
#if DEBUG_MEM_ALLOC #if DEBUG_MEM_ALLOC
log_info("clCreateBuffer %x\n", pResult->m_inBuffer); log_info("clCreateBuffer %x\n", pResult->m_inBuffer);
#endif #endif
pResult->m_outBuffer = clCreateBuffer( pClState->m_context, pResult->m_outBuffer = clCreateBuffer(
CL_MEM_WRITE_ONLY, pClState->m_context, CL_MEM_WRITE_ONLY, outSize, NULL, &error);
outSize, if (pResult->m_outBuffer == NULL)
NULL,
&error );
if( pResult->m_outBuffer == NULL )
{ {
vlog_error( "clCreateArray failed for output (%d)\n", error ); vlog_error("clCreateArray failed for output (%d)\n", error);
return destroyBufferStruct(pResult, pClState); return destroyBufferStruct(pResult, pClState);
} }
#if DEBUG_MEM_ALLOC #if DEBUG_MEM_ALLOC
@@ -152,31 +152,36 @@ bufferStruct * newBufferStruct(size_t inSize, size_t outSize, clState * pClState
return pResult; return pResult;
} }
bufferStruct * destroyBufferStruct(bufferStruct * destroyMe, clState * pClState) { bufferStruct *destroyBufferStruct(bufferStruct *destroyMe, clState *pClState)
if(destroyMe) {
if (destroyMe)
{ {
if(destroyMe->m_outBuffer != NULL) { if (destroyMe->m_outBuffer != NULL)
{
#if DEBUG_MEM_ALLOC #if DEBUG_MEM_ALLOC
log_info("clReleaseMemObject %x\n", destroyMe->m_outBuffer); log_info("clReleaseMemObject %x\n", destroyMe->m_outBuffer);
#endif #endif
clReleaseMemObject(destroyMe->m_outBuffer); clReleaseMemObject(destroyMe->m_outBuffer);
destroyMe->m_outBuffer = NULL; destroyMe->m_outBuffer = NULL;
} }
if(destroyMe->m_inBuffer != NULL) { if (destroyMe->m_inBuffer != NULL)
{
#if DEBUG_MEM_ALLOC #if DEBUG_MEM_ALLOC
log_info("clReleaseMemObject %x\n", destroyMe->m_outBuffer); log_info("clReleaseMemObject %x\n", destroyMe->m_outBuffer);
#endif #endif
clReleaseMemObject(destroyMe->m_inBuffer); clReleaseMemObject(destroyMe->m_inBuffer);
destroyMe->m_inBuffer = NULL; destroyMe->m_inBuffer = NULL;
} }
if(destroyMe->m_pIn != NULL) { if (destroyMe->m_pIn != NULL)
{
#if DEBUG_MEM_ALLOC #if DEBUG_MEM_ALLOC
log_info("delete (free) m_pIn %x\n", destroyMe->m_pIn); log_info("delete (free) m_pIn %x\n", destroyMe->m_pIn);
#endif #endif
free(destroyMe->m_pIn); free(destroyMe->m_pIn);
destroyMe->m_pIn = NULL; destroyMe->m_pIn = NULL;
} }
if(destroyMe->m_pOut != NULL) { if (destroyMe->m_pOut != NULL)
{
#if DEBUG_MEM_ALLOC #if DEBUG_MEM_ALLOC
log_info("delete (free) m_pOut %x\n", destroyMe->m_pOut); log_info("delete (free) m_pOut %x\n", destroyMe->m_pOut);
#endif #endif
@@ -192,46 +197,49 @@ bufferStruct * destroyBufferStruct(bufferStruct * destroyMe, clState * pClState)
return destroyMe; return destroyMe;
} }
void initContents(bufferStruct * pBufferStruct, clState * pClState, void initContents(bufferStruct *pBufferStruct, clState *pClState,
size_t typeSize, size_t typeSize, size_t countIn, size_t countOut)
size_t countIn, size_t countOut )
{ {
size_t i; size_t i;
uint64_t start = 0; uint64_t start = 0;
switch(typeSize) switch (typeSize)
{ {
case 1: { case 1: {
uint8_t* ub = (uint8_t *)(pBufferStruct->m_pIn); uint8_t *ub = (uint8_t *)(pBufferStruct->m_pIn);
for (i=0; i < countIn; ++i) for (i = 0; i < countIn; ++i)
{ {
ub[i] = (uint8_t)start++; ub[i] = (uint8_t)start++;
} }
break; break;
} }
case 2: { case 2: {
uint16_t* us = (uint16_t *)(pBufferStruct->m_pIn); uint16_t *us = (uint16_t *)(pBufferStruct->m_pIn);
for (i=0; i < countIn; ++i) for (i = 0; i < countIn; ++i)
{ {
us[i] = (uint16_t)start++; us[i] = (uint16_t)start++;
} }
break; break;
} }
case 4: { case 4: {
if (!g_wimpyMode) { if (!g_wimpyMode)
uint32_t* ui = (uint32_t *)(pBufferStruct->m_pIn); {
for (i=0; i < countIn; ++i) { uint32_t *ui = (uint32_t *)(pBufferStruct->m_pIn);
for (i = 0; i < countIn; ++i)
{
ui[i] = (uint32_t)start++; ui[i] = (uint32_t)start++;
} }
} }
else { else
// The short test doesn't iterate over the entire 32 bit space so {
// we alternate between positive and negative values // The short test doesn't iterate over the entire 32 bit space
int32_t* ui = (int32_t *)(pBufferStruct->m_pIn); // so we alternate between positive and negative values
int32_t *ui = (int32_t *)(pBufferStruct->m_pIn);
int32_t sign = 1; int32_t sign = 1;
for (i=0; i < countIn; ++i, ++start) { for (i = 0; i < countIn; ++i, ++start)
ui[i] = (int32_t)start*sign; {
ui[i] = (int32_t)start * sign;
sign = sign * -1; sign = sign * -1;
} }
} }
@@ -240,10 +248,11 @@ void initContents(bufferStruct * pBufferStruct, clState * pClState,
case 8: { case 8: {
// We don't iterate over the entire space of 64 bit so for the // We don't iterate over the entire space of 64 bit so for the
// selects, we want to test positive and negative values // selects, we want to test positive and negative values
int64_t* ll = (int64_t *)(pBufferStruct->m_pIn); int64_t *ll = (int64_t *)(pBufferStruct->m_pIn);
int64_t sign = 1; int64_t sign = 1;
for (i=0; i < countIn; ++i, ++start) { for (i = 0; i < countIn; ++i, ++start)
ll[i] = start*sign; {
ll[i] = start * sign;
sign = sign * -1; sign = sign * -1;
} }
break; break;
@@ -256,10 +265,10 @@ void initContents(bufferStruct * pBufferStruct, clState * pClState,
// pBufferStruct->m_bufSizeOut // pBufferStruct->m_bufSizeOut
} }
int pushArgs(bufferStruct * pBufferStruct, clState * pClState) int pushArgs(bufferStruct *pBufferStruct, clState *pClState)
{ {
int err; int err;
if( !pBufferStruct->m_bufferUploaded ) if (!pBufferStruct->m_bufferUploaded)
{ {
err = clEnqueueWriteBuffer(pClState->m_queue, pBufferStruct->m_inBuffer, err = clEnqueueWriteBuffer(pClState->m_queue, pBufferStruct->m_inBuffer,
CL_TRUE, 0, pBufferStruct->m_bufSizeIn, CL_TRUE, 0, pBufferStruct->m_bufSizeIn,
@@ -267,7 +276,7 @@ int pushArgs(bufferStruct * pBufferStruct, clState * pClState)
#if DEBUG_MEM_ALLOC #if DEBUG_MEM_ALLOC
log_info("clEnqueueWriteBuffer %x\n", pBufferStruct->m_inBuffer); log_info("clEnqueueWriteBuffer %x\n", pBufferStruct->m_inBuffer);
#endif #endif
if(err != CL_SUCCESS) if (err != CL_SUCCESS)
{ {
log_error("clEnqueueWriteBuffer failed\n"); log_error("clEnqueueWriteBuffer failed\n");
return -1; return -1;
@@ -275,22 +284,24 @@ int pushArgs(bufferStruct * pBufferStruct, clState * pClState)
pBufferStruct->m_bufferUploaded = true; pBufferStruct->m_bufferUploaded = true;
} }
err = clSetKernelArg(pClState->m_kernel, 0, err = clSetKernelArg(
sizeof(pBufferStruct->m_inBuffer), // pBufferStruct->m_bufSizeIn, pClState->m_kernel, 0,
&(pBufferStruct->m_inBuffer)); sizeof(pBufferStruct->m_inBuffer), // pBufferStruct->m_bufSizeIn,
&(pBufferStruct->m_inBuffer));
#if DEBUG_MEM_ALLOC #if DEBUG_MEM_ALLOC
// log_info("clSetKernelArg 0, %x\n", pBufferStruct->m_inBuffer); // log_info("clSetKernelArg 0, %x\n", pBufferStruct->m_inBuffer);
#endif #endif
if(err != CL_SUCCESS) if (err != CL_SUCCESS)
{ {
log_error("clSetKernelArgs failed, first arg (0)\n"); log_error("clSetKernelArgs failed, first arg (0)\n");
return -1; return -1;
} }
err = clSetKernelArg(pClState->m_kernel, 1, err = clSetKernelArg(
sizeof(pBufferStruct->m_outBuffer), // pBufferStruct->m_bufSizeOut, pClState->m_kernel, 1,
&(pBufferStruct->m_outBuffer)); sizeof(pBufferStruct->m_outBuffer), // pBufferStruct->m_bufSizeOut,
if(err != CL_SUCCESS) &(pBufferStruct->m_outBuffer));
if (err != CL_SUCCESS)
{ {
log_error("clSetKernelArgs failed, second arg (1)\n"); log_error("clSetKernelArgs failed, second arg (1)\n");
return -1; return -1;
@@ -303,13 +314,13 @@ int pushArgs(bufferStruct * pBufferStruct, clState * pClState)
return 0; return 0;
} }
int retrieveResults(bufferStruct * pBufferStruct, clState * pClState) int retrieveResults(bufferStruct *pBufferStruct, clState *pClState)
{ {
int err; int err;
err = clEnqueueReadBuffer(pClState->m_queue, pBufferStruct->m_outBuffer, err = clEnqueueReadBuffer(pClState->m_queue, pBufferStruct->m_outBuffer,
CL_TRUE, 0, pBufferStruct->m_bufSizeOut, CL_TRUE, 0, pBufferStruct->m_bufSizeOut,
pBufferStruct->m_pOut, 0, NULL, NULL); pBufferStruct->m_pOut, 0, NULL, NULL);
if(err != CL_SUCCESS) if (err != CL_SUCCESS)
{ {
log_error("clEnqueueReadBuffer failed\n"); log_error("clEnqueueReadBuffer failed\n");
return -1; return -1;
@@ -319,19 +330,17 @@ int retrieveResults(bufferStruct * pBufferStruct, clState * pClState)
// vecSizeIdx indexes into g_arrVecAlignMasks, g_arrVecSizeNames // vecSizeIdx indexes into g_arrVecAlignMasks, g_arrVecSizeNames
// and g_arrVecSizes // and g_arrVecSizes
int checkCorrectness(bufferStruct * pBufferStruct, clState * pClState, int checkCorrectnessAlign(bufferStruct *pBufferStruct, clState *pClState,
size_t minAlign) size_t minAlign)
{ {
size_t i; size_t i;
cl_uint * targetArr = (cl_uint *)(pBufferStruct->m_pOut); cl_uint *targetArr = (cl_uint *)(pBufferStruct->m_pOut);
for(i = 0; i < pClState->m_numThreads; ++i) for (i = 0; i < pClState->m_numThreads; ++i)
{ {
if((targetArr[i])%minAlign != (cl_uint)0) if ((targetArr[i]) % minAlign != (cl_uint)0)
{ {
vlog_error("Error %d (of %d). Expected a multple of %x, got %x\n", vlog_error("Error %d (of %d). Expected a multple of %x, got %x\n",
i, pClState->m_numThreads, i, pClState->m_numThreads, minAlign, targetArr[i]);
minAlign,
targetArr[i]);
return -1; return -1;
} }
} }
@@ -345,21 +354,42 @@ int checkCorrectness(bufferStruct * pBufferStruct, clState * pClState,
return 0; return 0;
} }
int checkCorrectnessStep(bufferStruct *pBufferStruct, clState *pClState,
size_t typeSize, size_t vecWidth)
{
size_t i;
cl_int targetSize = (cl_int)vecWidth;
cl_int *targetArr = (cl_int *)(pBufferStruct->m_pOut);
if (targetSize == 3)
{
targetSize = 4; // hack for 4-aligned vec3 types
}
for (i = 0; i < pClState->m_numThreads; ++i)
{
if (targetArr[i] != targetSize)
{
vlog_error("Error %ld (of %ld). Expected %d, got %d\n", i,
pClState->m_numThreads, targetSize, targetArr[i]);
return -1;
}
}
return 0;
}
// vecSizeIdx indexes into g_arrVecAlignMasks, g_arrVecSizeNames // vecSizeIdx indexes into g_arrVecAlignMasks, g_arrVecSizeNames
// and g_arrVecSizes // and g_arrVecSizes
int checkPackedCorrectness(bufferStruct * pBufferStruct, clState * pClState, int checkPackedCorrectness(bufferStruct *pBufferStruct, clState *pClState,
size_t totSize, size_t beforeSize) size_t totSize, size_t beforeSize)
{ {
size_t i; size_t i;
cl_uint * targetArr = (cl_uint *)(pBufferStruct->m_pOut); cl_uint *targetArr = (cl_uint *)(pBufferStruct->m_pOut);
for(i = 0; i < pClState->m_numThreads; ++i) for (i = 0; i < pClState->m_numThreads; ++i)
{ {
if((targetArr[i]-beforeSize)%totSize != (cl_uint)0) if ((targetArr[i] - beforeSize) % totSize != (cl_uint)0)
{ {
vlog_error("Error %d (of %d). Expected %d more than a multple of %d, got %d \n", vlog_error("Error %d (of %d). Expected %d more than a multple of "
i, pClState->m_numThreads, beforeSize, "%d, got %d \n",
totSize, i, pClState->m_numThreads, beforeSize, totSize,
targetArr[i]); targetArr[i]);
return -1; return -1;
} }

View File

@@ -0,0 +1,75 @@
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "testBase.h"
#include "harness/conversions.h"
#include "harness/typeWrappers.h"
typedef struct _clState
{
cl_device_id m_device;
cl_context m_context;
cl_command_queue m_queue;
cl_program m_program;
cl_kernel m_kernel;
size_t m_numThreads;
} clState;
clState* newClState(cl_device_id device, cl_context context,
cl_command_queue queue);
clState* destroyClState(clState* pState);
int clStateMakeProgram(clState* pState, const char* prog,
const char* kernelName);
void clStateDestroyProgramAndKernel(clState* pState);
int runKernel(clState* pState, size_t numThreads);
typedef struct _bufferStruct
{
void* m_pIn;
void* m_pOut;
cl_mem m_outBuffer;
cl_mem m_inBuffer;
size_t m_bufSizeIn, m_bufSizeOut;
int m_bufferUploaded;
} bufferStruct;
bufferStruct* newBufferStruct(size_t inSize, size_t outSize, clState* pClState);
bufferStruct* destroyBufferStruct(bufferStruct* destroyMe, clState* pClState);
void initContents(bufferStruct* pBufferStruct, clState* pClState,
size_t typeSize, size_t vecWidth);
int pushArgs(bufferStruct* pBufferStruct, clState* pClState);
int retrieveResults(bufferStruct* pBufferStruct, clState* pClState);
int checkCorrectnessStep(bufferStruct* pBufferStruct, clState* pClState,
size_t typeSize, size_t vecWidth);
// vecSizeIdx indexes into g_arrVecAlignMasks, g_arrVecSizeNames
// and g_arrVecSizes
int checkCorrectnessAlign(bufferStruct* pBufferStruct, clState* pClState,
size_t minAlign);
int checkPackedCorrectness(bufferStruct* pBufferStruct, clState* pClState,
size_t totSize, size_t beforeSize);

View File

@@ -1,6 +1,6 @@
// //
// Copyright (c) 2017 The Khronos Group Inc. // Copyright (c) 2017 The Khronos Group Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at

View File

@@ -1,6 +1,6 @@
// //
// Copyright (c) 2017 The Khronos Group Inc. // Copyright (c) 2017 The Khronos Group Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
@@ -35,94 +35,99 @@
*/ */
int test_step_internal(cl_device_id deviceID, cl_context context,
int test_step_internal(cl_device_id deviceID, cl_context context, cl_command_queue queue, const char * pattern, const char * testName) cl_command_queue queue, const char* pattern,
const char* testName)
{ {
int err; int err;
int typeIdx, vecSizeIdx; int typeIdx, vecSizeIdx;
char tempBuffer[2048]; char tempBuffer[2048];
clState * pClState = newClState(deviceID, context, queue); clState* pClState = newClState(deviceID, context, queue);
bufferStruct * pBuffers = bufferStruct* pBuffers =
newBufferStruct(BUFFER_SIZE, BUFFER_SIZE, pClState); newBufferStruct(BUFFER_SIZE, BUFFER_SIZE, pClState);
if(pBuffers == NULL) { if (pBuffers == NULL)
{
destroyClState(pClState); destroyClState(pClState);
vlog_error("%s : Could not create buffer\n", testName); vlog_error("%s : Could not create buffer\n", testName);
return -1; return -1;
} }
//detect whether profile of the device is embedded // detect whether profile of the device is embedded
char profile[1024] = ""; char profile[1024] = "";
err = clGetDeviceInfo(deviceID, CL_DEVICE_PROFILE, sizeof(profile), profile, NULL); err = clGetDeviceInfo(deviceID, CL_DEVICE_PROFILE, sizeof(profile), profile,
NULL);
if (err) if (err)
{ {
print_error(err, "clGetDeviceInfo for CL_DEVICE_PROFILE failed\n" ); print_error(err, "clGetDeviceInfo for CL_DEVICE_PROFILE failed\n");
return -1; return -1;
} }
gIsEmbedded = NULL != strstr(profile, "EMBEDDED_PROFILE"); gIsEmbedded = NULL != strstr(profile, "EMBEDDED_PROFILE");
for(typeIdx = 0; types[typeIdx] != kNumExplicitTypes; ++typeIdx) for (typeIdx = 0; types[typeIdx] != kNumExplicitTypes; ++typeIdx)
{ {
if( types[ typeIdx ] == kDouble ) if (types[typeIdx] == kDouble)
{ {
// If we're testing doubles, we need to check for support first // If we're testing doubles, we need to check for support first
if( !is_extension_available( deviceID, "cl_khr_fp64" ) ) if (!is_extension_available(deviceID, "cl_khr_fp64"))
{ {
log_info( "Not testing doubles (unsupported on this device)\n" ); log_info("Not testing doubles (unsupported on this device)\n");
continue; continue;
} }
} }
if( types[ typeIdx ] == kLong || types[ typeIdx ] == kULong ) if (types[typeIdx] == kLong || types[typeIdx] == kULong)
{
// If we're testing long/ulong, we need to check for embedded support
if( gIsEmbedded && !is_extension_available( deviceID, "cles_khr_int64") )
{ {
log_info( "Not testing longs (unsupported on this embedded device)\n" ); // If we're testing long/ulong, we need to check for embedded
continue; // support
if (gIsEmbedded
&& !is_extension_available(deviceID, "cles_khr_int64"))
{
log_info("Not testing longs (unsupported on this embedded "
"device)\n");
continue;
}
} }
}
char srcBuffer[2048]; char srcBuffer[2048];
doSingleReplace(tempBuffer, 2048, pattern, doSingleReplace(tempBuffer, 2048, pattern, ".EXTENSIONS.",
".EXTENSIONS.", types[typeIdx] == kDouble types[typeIdx] == kDouble
? "#pragma OPENCL EXTENSION cl_khr_fp64 : enable" ? "#pragma OPENCL EXTENSION cl_khr_fp64 : enable"
: ""); : "");
for(vecSizeIdx = 0; vecSizeIdx < NUM_VECTOR_SIZES; ++vecSizeIdx) for (vecSizeIdx = 0; vecSizeIdx < NUM_VECTOR_SIZES; ++vecSizeIdx)
{ {
doReplace(srcBuffer, 2048, tempBuffer, doReplace(srcBuffer, 2048, tempBuffer, ".TYPE.",
".TYPE.", g_arrTypeNames[typeIdx], g_arrTypeNames[typeIdx], ".NUM.",
".NUM.", g_arrVecSizeNames[vecSizeIdx]); g_arrVecSizeNames[vecSizeIdx]);
if(srcBuffer[0] == '\0') { if (srcBuffer[0] == '\0')
{
vlog_error("%s: failed to fill source buf for type %s%s\n", vlog_error("%s: failed to fill source buf for type %s%s\n",
testName, testName, g_arrTypeNames[typeIdx],
g_arrTypeNames[typeIdx],
g_arrVecSizeNames[vecSizeIdx]); g_arrVecSizeNames[vecSizeIdx]);
destroyBufferStruct(pBuffers, pClState); destroyBufferStruct(pBuffers, pClState);
destroyClState(pClState); destroyClState(pClState);
return -1; return -1;
} }
err = clStateMakeProgram(pClState, srcBuffer, testName ); err = clStateMakeProgram(pClState, srcBuffer, testName);
if (err) if (err)
{ {
vlog_error("%s: Error compiling \"\n%s\n\"", vlog_error("%s: Error compiling \"\n%s\n\"", testName,
testName, srcBuffer); srcBuffer);
destroyBufferStruct(pBuffers, pClState); destroyBufferStruct(pBuffers, pClState);
destroyClState(pClState); destroyClState(pClState);
return -1; return -1;
} }
err = pushArgs(pBuffers, pClState); err = pushArgs(pBuffers, pClState);
if(err != 0) if (err != 0)
{ {
vlog_error("%s: failed to push args %s%s\n", vlog_error("%s: failed to push args %s%s\n", testName,
testName,
g_arrTypeNames[typeIdx], g_arrTypeNames[typeIdx],
g_arrVecSizeNames[vecSizeIdx]); g_arrVecSizeNames[vecSizeIdx]);
destroyBufferStruct(pBuffers, pClState); destroyBufferStruct(pBuffers, pClState);
@@ -132,11 +137,10 @@ int test_step_internal(cl_device_id deviceID, cl_context context, cl_command_que
// now we run the kernel // now we run the kernel
err = runKernel(pClState, 1024); err = runKernel(pClState, 1024);
if(err != 0) if (err != 0)
{ {
vlog_error("%s: runKernel fail (%ld threads) %s%s\n", vlog_error("%s: runKernel fail (%ld threads) %s%s\n", testName,
testName, pClState->m_numThreads, pClState->m_numThreads, g_arrTypeNames[typeIdx],
g_arrTypeNames[typeIdx],
g_arrVecSizeNames[vecSizeIdx]); g_arrVecSizeNames[vecSizeIdx]);
destroyBufferStruct(pBuffers, pClState); destroyBufferStruct(pBuffers, pClState);
destroyClState(pClState); destroyClState(pClState);
@@ -144,10 +148,9 @@ int test_step_internal(cl_device_id deviceID, cl_context context, cl_command_que
} }
err = retrieveResults(pBuffers, pClState); err = retrieveResults(pBuffers, pClState);
if(err != 0) if (err != 0)
{ {
vlog_error("%s: failed to retrieve results %s%s\n", vlog_error("%s: failed to retrieve results %s%s\n", testName,
testName,
g_arrTypeNames[typeIdx], g_arrTypeNames[typeIdx],
g_arrVecSizeNames[vecSizeIdx]); g_arrVecSizeNames[vecSizeIdx]);
destroyBufferStruct(pBuffers, pClState); destroyBufferStruct(pBuffers, pClState);
@@ -155,24 +158,21 @@ int test_step_internal(cl_device_id deviceID, cl_context context, cl_command_que
return -1; return -1;
} }
err = checkCorrectness(pBuffers, pClState, err = checkCorrectnessStep(pBuffers, pClState,
g_arrTypeSizes[typeIdx], g_arrTypeSizes[typeIdx],
g_arrVecSizes[vecSizeIdx]); g_arrVecSizes[vecSizeIdx]);
if(err != 0) if (err != 0)
{ {
vlog_error("%s: incorrect results %s%s\n", vlog_error("%s: incorrect results %s%s\n", testName,
testName,
g_arrTypeNames[typeIdx], g_arrTypeNames[typeIdx],
g_arrVecSizeNames[vecSizeIdx]); g_arrVecSizeNames[vecSizeIdx]);
vlog_error("%s: Source was \"\n%s\n\"", vlog_error("%s: Source was \"\n%s\n\"", testName, srcBuffer);
testName, srcBuffer);
destroyBufferStruct(pBuffers, pClState); destroyBufferStruct(pBuffers, pClState);
destroyClState(pClState); destroyClState(pClState);
return -1; return -1;
} }
} }
} }
destroyBufferStruct(pBuffers, pClState); destroyBufferStruct(pBuffers, pClState);
@@ -184,9 +184,10 @@ int test_step_internal(cl_device_id deviceID, cl_context context, cl_command_que
return 0; // -1; // fails on account of not being written. return 0; // -1; // fails on account of not being written.
} }
const char * patterns[] = { static const char* patterns[] = {
".EXTENSIONS.\n" ".EXTENSIONS.\n"
"__kernel void test_step_type(__global .TYPE..NUM. *source, __global int *dest)\n" "__kernel void test_step_type(__global .TYPE..NUM. *source, __global int "
"*dest)\n"
"{\n" "{\n"
" int tid = get_global_id(0);\n" " int tid = get_global_id(0);\n"
" dest[tid] = vec_step(.TYPE..NUM.);\n" " dest[tid] = vec_step(.TYPE..NUM.);\n"
@@ -194,7 +195,8 @@ const char * patterns[] = {
"}\n", "}\n",
".EXTENSIONS.\n" ".EXTENSIONS.\n"
"__kernel void test_step_var(__global .TYPE..NUM. *source, __global int *dest)\n" "__kernel void test_step_var(__global .TYPE..NUM. *source, __global int "
"*dest)\n"
"{\n" "{\n"
" int tid = get_global_id(0);\n" " int tid = get_global_id(0);\n"
" dest[tid] = vec_step(source[tid]);\n" " dest[tid] = vec_step(source[tid]);\n"
@@ -203,7 +205,8 @@ const char * patterns[] = {
".EXTENSIONS.\n" ".EXTENSIONS.\n"
" typedef .TYPE..NUM. TypeToTest;\n" " typedef .TYPE..NUM. TypeToTest;\n"
"__kernel void test_step_typedef_type(__global TypeToTest *source, __global int *dest)\n" "__kernel void test_step_typedef_type(__global TypeToTest *source, "
"__global int *dest)\n"
"{\n" "{\n"
" int tid = get_global_id(0);\n" " int tid = get_global_id(0);\n"
" dest[tid] = vec_step(TypeToTest);\n" " dest[tid] = vec_step(TypeToTest);\n"
@@ -212,7 +215,8 @@ const char * patterns[] = {
".EXTENSIONS.\n" ".EXTENSIONS.\n"
" typedef .TYPE..NUM. TypeToTest;\n" " typedef .TYPE..NUM. TypeToTest;\n"
"__kernel void test_step_typedef_var(__global TypeToTest *source, __global int *dest)\n" "__kernel void test_step_typedef_var(__global TypeToTest *source, __global "
"int *dest)\n"
"{\n" "{\n"
" int tid = get_global_id(0);\n" " int tid = get_global_id(0);\n"
" dest[tid] = vec_step(source[tid]);\n" " dest[tid] = vec_step(source[tid]);\n"
@@ -227,25 +231,29 @@ const char * patterns[] = {
test_step_typedef_var, test_step_typedef_var,
*/ */
int test_step_type(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) int test_step_type(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{ {
return test_step_internal(deviceID, context, queue, patterns[0], return test_step_internal(deviceID, context, queue, patterns[0],
"test_step_type"); "test_step_type");
} }
int test_step_var(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) int test_step_var(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{ {
return test_step_internal(deviceID, context, queue, patterns[1], return test_step_internal(deviceID, context, queue, patterns[1],
"test_step_var"); "test_step_var");
} }
int test_step_typedef_type(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) int test_step_typedef_type(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{ {
return test_step_internal(deviceID, context, queue, patterns[2], return test_step_internal(deviceID, context, queue, patterns[2],
"test_step_typedef_type"); "test_step_typedef_type");
} }
int test_step_typedef_var(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) int test_step_typedef_var(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{ {
return test_step_internal(deviceID, context, queue, patterns[3], return test_step_internal(deviceID, context, queue, patterns[3],
"test_step_typedef_var"); "test_step_typedef_var");

View File

@@ -1,6 +1,6 @@
// //
// Copyright (c) 2017 The Khronos Group Inc. // Copyright (c) 2017 The Khronos Group Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
@@ -29,14 +29,15 @@
size_t get_align(size_t vecSize) size_t get_align(size_t vecSize)
{ {
if(vecSize == 3) if (vecSize == 3)
{ {
return 4; return 4;
} }
return vecSize; return vecSize;
} }
/* // Lots of conditionals means this is not gonna be an optimal min on intel. */ /* // Lots of conditionals means this is not gonna be an optimal min on intel.
*/
/* // That's okay, make sure we only call a few times per test, not for every */ /* // That's okay, make sure we only call a few times per test, not for every */
/* // element */ /* // element */
/* size_t min_of_nonzero(size_t a, size_t b) */ /* size_t min_of_nonzero(size_t a, size_t b) */
@@ -53,7 +54,8 @@ size_t get_align(size_t vecSize)
/* } */ /* } */
/* size_t get_min_packed_alignment(size_t preSize, size_t typeMultiplePreSize, */ /* size_t get_min_packed_alignment(size_t preSize, size_t typeMultiplePreSize,
*/
/* size_t postSize, size_t typeMultiplePostSize, */ /* size_t postSize, size_t typeMultiplePostSize, */
/* ExplicitType kType, size_t vecSize) */ /* ExplicitType kType, size_t vecSize) */
/* { */ /* { */
@@ -71,12 +73,11 @@ size_t get_align(size_t vecSize)
/* } */ /* } */
int test_vec_internal(cl_device_id deviceID, cl_context context, int test_vec_internal(cl_device_id deviceID, cl_context context,
cl_command_queue queue, const char * pattern, cl_command_queue queue, const char* pattern,
const char * testName, size_t bufSize, const char* testName, size_t bufSize, size_t preSize,
size_t preSize, size_t typeMultiplePreSize, size_t typeMultiplePreSize, size_t postSize,
size_t postSize, size_t typeMultiplePostSize) size_t typeMultiplePostSize)
{ {
int err; int err;
int typeIdx, vecSizeIdx; int typeIdx, vecSizeIdx;
@@ -86,58 +87,64 @@ int test_vec_internal(cl_device_id deviceID, cl_context context,
size_t preSizeBytes, postSizeBytes, typeSize, totSize; size_t preSizeBytes, postSizeBytes, typeSize, totSize;
clState * pClState = newClState(deviceID, context, queue); clState* pClState = newClState(deviceID, context, queue);
bufferStruct * pBuffers = bufferStruct* pBuffers = newBufferStruct(
newBufferStruct(bufSize, bufSize*sizeof(cl_uint)/sizeof(cl_char), pClState); bufSize, bufSize * sizeof(cl_uint) / sizeof(cl_char), pClState);
if(pBuffers == NULL) { if (pBuffers == NULL)
{
destroyClState(pClState); destroyClState(pClState);
vlog_error("%s : Could not create buffer\n", testName); vlog_error("%s : Could not create buffer\n", testName);
return -1; return -1;
} }
for(typeIdx = 0; types[typeIdx] != kNumExplicitTypes; ++typeIdx) for (typeIdx = 0; types[typeIdx] != kNumExplicitTypes; ++typeIdx)
{ {
// Skip doubles if it is not supported otherwise enable pragma // Skip doubles if it is not supported otherwise enable pragma
if (types[typeIdx] == kDouble) { if (types[typeIdx] == kDouble)
if (!is_extension_available(deviceID, "cl_khr_fp64")) { {
if (!is_extension_available(deviceID, "cl_khr_fp64"))
{
continue; continue;
} else {
doReplace(tmpBuffer, 2048, pattern,
".PRAGMA.", "#pragma OPENCL EXTENSION cl_khr_fp64: ",
".STATE.", "enable");
} }
} else { else
if (types[typeIdx] == kLong || types[typeIdx] == kULong) { {
if (gIsEmbedded) doReplace(tmpBuffer, 2048, pattern, ".PRAGMA.",
continue; "#pragma OPENCL EXTENSION cl_khr_fp64: ", ".STATE.",
"enable");
}
}
else
{
if (types[typeIdx] == kLong || types[typeIdx] == kULong)
{
if (gIsEmbedded) continue;
} }
doReplace(tmpBuffer, 2048, pattern, doReplace(tmpBuffer, 2048, pattern, ".PRAGMA.", " ", ".STATE.",
".PRAGMA.", " ", " ");
".STATE.", " ");
} }
typeSize = get_explicit_type_size(types[typeIdx]); typeSize = get_explicit_type_size(types[typeIdx]);
preSizeBytes = preSize + typeSize*typeMultiplePreSize; preSizeBytes = preSize + typeSize * typeMultiplePreSize;
postSizeBytes = postSize + typeSize*typeMultiplePostSize; postSizeBytes = postSize + typeSize * typeMultiplePostSize;
for (vecSizeIdx = 1; vecSizeIdx < NUM_VECTOR_SIZES; ++vecSizeIdx)
{
for(vecSizeIdx = 1; vecSizeIdx < NUM_VECTOR_SIZES; ++vecSizeIdx) { totSize = preSizeBytes + postSizeBytes
+ typeSize * get_align(g_arrVecSizes[vecSizeIdx]);
totSize = preSizeBytes + postSizeBytes + doReplace(srcBuffer, 2048, tmpBuffer, ".TYPE.",
typeSize*get_align(g_arrVecSizes[vecSizeIdx]); g_arrTypeNames[typeIdx], ".NUM.",
g_arrVecSizeNames[vecSizeIdx]);
doReplace(srcBuffer, 2048, tmpBuffer, if (srcBuffer[0] == '\0')
".TYPE.", g_arrTypeNames[typeIdx], {
".NUM.", g_arrVecSizeNames[vecSizeIdx]);
if(srcBuffer[0] == '\0') {
vlog_error("%s: failed to fill source buf for type %s%s\n", vlog_error("%s: failed to fill source buf for type %s%s\n",
testName, testName, g_arrTypeNames[typeIdx],
g_arrTypeNames[typeIdx],
g_arrVecSizeNames[vecSizeIdx]); g_arrVecSizeNames[vecSizeIdx]);
destroyBufferStruct(pBuffers, pClState); destroyBufferStruct(pBuffers, pClState);
destroyClState(pClState); destroyClState(pClState);
@@ -147,19 +154,20 @@ int test_vec_internal(cl_device_id deviceID, cl_context context,
// log_info("Buffer is \"\n%s\n\"\n", srcBuffer); // log_info("Buffer is \"\n%s\n\"\n", srcBuffer);
// fflush(stdout); // fflush(stdout);
err = clStateMakeProgram(pClState, srcBuffer, testName ); err = clStateMakeProgram(pClState, srcBuffer, testName);
if (err) { if (err)
vlog_error("%s: Error compiling \"\n%s\n\"", {
testName, srcBuffer); vlog_error("%s: Error compiling \"\n%s\n\"", testName,
srcBuffer);
destroyBufferStruct(pBuffers, pClState); destroyBufferStruct(pBuffers, pClState);
destroyClState(pClState); destroyClState(pClState);
return -1; return -1;
} }
err = pushArgs(pBuffers, pClState); err = pushArgs(pBuffers, pClState);
if(err != 0) { if (err != 0)
vlog_error("%s: failed to push args %s%s\n", {
testName, vlog_error("%s: failed to push args %s%s\n", testName,
g_arrTypeNames[typeIdx], g_arrTypeNames[typeIdx],
g_arrVecSizeNames[vecSizeIdx]); g_arrVecSizeNames[vecSizeIdx]);
destroyBufferStruct(pBuffers, pClState); destroyBufferStruct(pBuffers, pClState);
@@ -169,12 +177,14 @@ int test_vec_internal(cl_device_id deviceID, cl_context context,
// log_info("About to Run kernel\n"); fflush(stdout); // log_info("About to Run kernel\n"); fflush(stdout);
// now we run the kernel // now we run the kernel
err = runKernel(pClState, err = runKernel(
bufSize/(g_arrVecSizes[vecSizeIdx]* g_arrTypeSizes[typeIdx])); pClState,
if(err != 0) { bufSize
vlog_error("%s: runKernel fail (%ld threads) %s%s\n", / (g_arrVecSizes[vecSizeIdx] * g_arrTypeSizes[typeIdx]));
testName, pClState->m_numThreads, if (err != 0)
g_arrTypeNames[typeIdx], {
vlog_error("%s: runKernel fail (%ld threads) %s%s\n", testName,
pClState->m_numThreads, g_arrTypeNames[typeIdx],
g_arrVecSizeNames[vecSizeIdx]); g_arrVecSizeNames[vecSizeIdx]);
destroyBufferStruct(pBuffers, pClState); destroyBufferStruct(pBuffers, pClState);
destroyClState(pClState); destroyClState(pClState);
@@ -183,9 +193,9 @@ int test_vec_internal(cl_device_id deviceID, cl_context context,
// log_info("About to retrieve results\n"); fflush(stdout); // log_info("About to retrieve results\n"); fflush(stdout);
err = retrieveResults(pBuffers, pClState); err = retrieveResults(pBuffers, pClState);
if(err != 0) { if (err != 0)
vlog_error("%s: failed to retrieve results %s%s\n", {
testName, vlog_error("%s: failed to retrieve results %s%s\n", testName,
g_arrTypeNames[typeIdx], g_arrTypeNames[typeIdx],
g_arrVecSizeNames[vecSizeIdx]); g_arrVecSizeNames[vecSizeIdx]);
destroyBufferStruct(pBuffers, pClState); destroyBufferStruct(pBuffers, pClState);
@@ -194,13 +204,12 @@ int test_vec_internal(cl_device_id deviceID, cl_context context,
} }
if (preSizeBytes + postSizeBytes == 0)
if(preSizeBytes+postSizeBytes == 0)
{ {
// log_info("About to Check Correctness\n"); fflush(stdout); // log_info("About to Check Correctness\n"); fflush(stdout);
err = checkCorrectness(pBuffers, pClState, err = checkCorrectnessAlign(pBuffers, pClState,
get_align(g_arrVecSizes[vecSizeIdx])* get_align(g_arrVecSizes[vecSizeIdx])
typeSize); * typeSize);
} }
else else
{ {
@@ -209,20 +218,18 @@ int test_vec_internal(cl_device_id deviceID, cl_context context,
preSizeBytes); preSizeBytes);
} }
if(err != 0) { if (err != 0)
vlog_error("%s: incorrect results %s%s\n", {
testName, vlog_error("%s: incorrect results %s%s\n", testName,
g_arrTypeNames[typeIdx], g_arrTypeNames[typeIdx],
g_arrVecSizeNames[vecSizeIdx]); g_arrVecSizeNames[vecSizeIdx]);
vlog_error("%s: Source was \"\n%s\n\"", vlog_error("%s: Source was \"\n%s\n\"", testName, srcBuffer);
testName, srcBuffer);
destroyBufferStruct(pBuffers, pClState); destroyBufferStruct(pBuffers, pClState);
destroyClState(pClState); destroyClState(pClState);
return -1; return -1;
} }
clStateDestroyProgramAndKernel(pClState); clStateDestroyProgramAndKernel(pClState);
} }
} }
@@ -236,10 +243,10 @@ int test_vec_internal(cl_device_id deviceID, cl_context context,
} }
static const char* patterns[] = {
const char * patterns[] = {
".PRAGMA..STATE.\n" ".PRAGMA..STATE.\n"
"__kernel void test_vec_align_array(.SRC_SCOPE. .TYPE..NUM. *source, .DST_SCOPE. uint *dest)\n" "__kernel void test_vec_align_array(.SRC_SCOPE. .TYPE..NUM. *source, "
".DST_SCOPE. uint *dest)\n"
"{\n" "{\n"
" int tid = get_global_id(0);\n" " int tid = get_global_id(0);\n"
" dest[tid] = (uint)((.SRC_SCOPE. uchar *)(source+tid));\n" " dest[tid] = (uint)((.SRC_SCOPE. uchar *)(source+tid));\n"
@@ -250,7 +257,8 @@ const char * patterns[] = {
" .TYPE..NUM. vec;\n" " .TYPE..NUM. vec;\n"
".POST." ".POST."
"} testStruct;\n" "} testStruct;\n"
"__kernel void test_vec_align_struct(__constant .TYPE..NUM. *source, .DST_SCOPE. uint *dest)\n" "__kernel void test_vec_align_struct(__constant .TYPE..NUM. *source, "
".DST_SCOPE. uint *dest)\n"
"{\n" "{\n"
" .SRC_SCOPE. testStruct test;\n" " .SRC_SCOPE. testStruct test;\n"
" int tid = get_global_id(0);\n" " int tid = get_global_id(0);\n"
@@ -262,11 +270,13 @@ const char * patterns[] = {
" .TYPE..NUM. vec;\n" " .TYPE..NUM. vec;\n"
".POST." ".POST."
"} testStruct;\n" "} testStruct;\n"
"__kernel void test_vec_align_packed_struct(__constant .TYPE..NUM. *source, .DST_SCOPE. uint *dest)\n" "__kernel void test_vec_align_packed_struct(__constant .TYPE..NUM. "
"*source, .DST_SCOPE. uint *dest)\n"
"{\n" "{\n"
" .SRC_SCOPE. testStruct test;\n" " .SRC_SCOPE. testStruct test;\n"
" int tid = get_global_id(0);\n" " int tid = get_global_id(0);\n"
" dest[tid] = (uint)((.SRC_SCOPE. uchar *)&(test.vec) - (.SRC_SCOPE. uchar *)&test);\n" " dest[tid] = (uint)((.SRC_SCOPE. uchar *)&(test.vec) - (.SRC_SCOPE. "
"uchar *)&test);\n"
"}\n", "}\n",
".PRAGMA..STATE.\n" ".PRAGMA..STATE.\n"
"typedef struct myStruct { \n" "typedef struct myStruct { \n"
@@ -274,7 +284,8 @@ const char * patterns[] = {
" .TYPE..NUM. vec;\n" " .TYPE..NUM. vec;\n"
".POST." ".POST."
"} testStruct;\n" "} testStruct;\n"
"__kernel void test_vec_align_struct_arr(.SRC_SCOPE. testStruct *source, .DST_SCOPE. uint *dest)\n" "__kernel void test_vec_align_struct_arr(.SRC_SCOPE. testStruct *source, "
".DST_SCOPE. uint *dest)\n"
"{\n" "{\n"
" int tid = get_global_id(0);\n" " int tid = get_global_id(0);\n"
" dest[tid] = (uint)((.SRC_SCOPE. uchar *)&(source[tid].vec));\n" " dest[tid] = (uint)((.SRC_SCOPE. uchar *)&(source[tid].vec));\n"
@@ -285,142 +296,123 @@ const char * patterns[] = {
" .TYPE..NUM. vec;\n" " .TYPE..NUM. vec;\n"
".POST." ".POST."
"} testStruct;\n" "} testStruct;\n"
"__kernel void test_vec_align_packed_struct_arr(.SRC_SCOPE. testStruct *source, .DST_SCOPE. uint *dest)\n" "__kernel void test_vec_align_packed_struct_arr(.SRC_SCOPE. testStruct "
"*source, .DST_SCOPE. uint *dest)\n"
"{\n" "{\n"
" int tid = get_global_id(0);\n" " int tid = get_global_id(0);\n"
" dest[tid] = (uint)((.SRC_SCOPE. uchar *)&(source[tid].vec) - (.SRC_SCOPE. uchar *)&(source[0]));\n" " dest[tid] = (uint)((.SRC_SCOPE. uchar *)&(source[tid].vec) - "
"(.SRC_SCOPE. uchar *)&(source[0]));\n"
"}\n", "}\n",
// __attribute__ ((packed)) // __attribute__ ((packed))
}; };
const char* pre_substitution_arr[] = { "",
const char * pre_substitution_arr[] = { "char c;\n",
"", "short3 s;",
"char c;\n", ".TYPE.3 tPre;\n",
"short3 s;", ".TYPE. arrPre[5];\n",
".TYPE.3 tPre;\n", ".TYPE. arrPre[12];\n",
".TYPE. arrPre[5];\n", NULL };
".TYPE. arrPre[12];\n",
NULL
};
// alignments of everything in pre_substitution_arr as raw alignments // alignments of everything in pre_substitution_arr as raw alignments
// 0 if such a thing is meaningless // 0 if such a thing is meaningless
size_t pre_align_arr[] = { size_t pre_align_arr[] = { 0,
0, sizeof(cl_char),
sizeof(cl_char), 4 * sizeof(cl_short),
4*sizeof(cl_short), 0, // taken care of in type_multiple_pre_align_arr
0, // taken care of in type_multiple_pre_align_arr 0,
0, 0 };
0
};
// alignments of everything in pre_substitution_arr as multiples of // alignments of everything in pre_substitution_arr as multiples of
// sizeof(.TYPE.) // sizeof(.TYPE.)
// 0 if such a thing is meaningless // 0 if such a thing is meaningless
size_t type_multiple_pre_align_arr[] = { size_t type_multiple_pre_align_arr[] = { 0, 0, 0, 4, 5, 12 };
0,
0,
0,
4,
5,
12
};
const char * post_substitution_arr[] = { const char* post_substitution_arr[] = { "",
"", "char cPost;\n",
"char cPost;\n", ".TYPE. arrPost[3];\n",
".TYPE. arrPost[3];\n", ".TYPE. arrPost[5];\n",
".TYPE. arrPost[5];\n", ".TYPE.3 arrPost;\n",
".TYPE.3 arrPost;\n", ".TYPE. arrPost[12];\n",
".TYPE. arrPost[12];\n", NULL };
NULL
};
// alignments of everything in post_substitution_arr as raw alignments // alignments of everything in post_substitution_arr as raw alignments
// 0 if such a thing is meaningless // 0 if such a thing is meaningless
size_t post_align_arr[] = { size_t post_align_arr[] = { 0, sizeof(cl_char),
0, 0, // taken care of in type_multiple_post_align_arr
sizeof(cl_char), 0, 0,
0, // taken care of in type_multiple_post_align_arr 0 };
0,
0,
0
};
// alignments of everything in post_substitution_arr as multiples of // alignments of everything in post_substitution_arr as multiples of
// sizeof(.TYPE.) // sizeof(.TYPE.)
// 0 if such a thing is meaningless // 0 if such a thing is meaningless
size_t type_multiple_post_align_arr[] = { size_t type_multiple_post_align_arr[] = { 0, 0, 3, 5, 4, 12 };
0,
0,
3,
5,
4,
12
};
// there hsould be a packed version of this? // there hsould be a packed version of this?
int test_vec_align_array(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) int test_vec_align_array(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{ {
char tmp[2048]; char tmp[2048];
int result; int result;
log_info("Testing global\n"); log_info("Testing global\n");
doReplace(tmp, (size_t)2048, patterns[0], doReplace(tmp, (size_t)2048, patterns[0], ".SRC_SCOPE.", "__global",
".SRC_SCOPE.", "__global",
".DST_SCOPE.", "__global"); // ".DST_SCOPE.", "__global"); //
result = test_vec_internal(deviceID, context, queue, tmp, result = test_vec_internal(deviceID, context, queue, tmp,
"test_vec_align_array", "test_vec_align_array", BUFFER_SIZE, 0, 0, 0, 0);
BUFFER_SIZE, 0, 0, 0, 0);
return result; return result;
} }
int test_vec_align_struct(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) int test_vec_align_struct(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{ {
char tmp1[2048], tmp2[2048]; char tmp1[2048], tmp2[2048];
int result = 0; int result = 0;
int preIdx, postIdx; int preIdx, postIdx;
log_info("testing __private\n"); log_info("testing __private\n");
doReplace(tmp2, (size_t)2048, patterns[1], doReplace(tmp2, (size_t)2048, patterns[1], ".SRC_SCOPE.", "__private",
".SRC_SCOPE.", "__private",
".DST_SCOPE.", "__global"); // ".DST_SCOPE.", "__global"); //
for(preIdx = 0; pre_substitution_arr[preIdx] != NULL; ++preIdx) { for (preIdx = 0; pre_substitution_arr[preIdx] != NULL; ++preIdx)
for(postIdx = 0; post_substitution_arr[postIdx] != NULL; ++postIdx) { {
doReplace(tmp1, (size_t)2048, tmp2, for (postIdx = 0; post_substitution_arr[postIdx] != NULL; ++postIdx)
".PRE.", pre_substitution_arr[preIdx], {
".POST.", post_substitution_arr[postIdx]); doReplace(tmp1, (size_t)2048, tmp2, ".PRE.",
pre_substitution_arr[preIdx], ".POST.",
post_substitution_arr[postIdx]);
result = test_vec_internal(deviceID, context, queue, tmp1, result =
"test_vec_align_struct", test_vec_internal(deviceID, context, queue, tmp1,
512, 0, 0, 0, 0); "test_vec_align_struct", 512, 0, 0, 0, 0);
if (result != 0) { if (result != 0)
{
return result; return result;
} }
} }
} }
log_info("testing __local\n"); log_info("testing __local\n");
doReplace(tmp2, (size_t)2048, patterns[1], doReplace(tmp2, (size_t)2048, patterns[1], ".SRC_SCOPE.", "__local",
".SRC_SCOPE.", "__local",
".DST_SCOPE.", "__global"); // ".DST_SCOPE.", "__global"); //
for(preIdx = 0; pre_substitution_arr[preIdx] != NULL; ++preIdx) { for (preIdx = 0; pre_substitution_arr[preIdx] != NULL; ++preIdx)
for(postIdx = 0; post_substitution_arr[postIdx] != NULL; ++postIdx) { {
doReplace(tmp1, (size_t)2048, tmp2, for (postIdx = 0; post_substitution_arr[postIdx] != NULL; ++postIdx)
".PRE.", pre_substitution_arr[preIdx], {
".POST.", post_substitution_arr[postIdx]); doReplace(tmp1, (size_t)2048, tmp2, ".PRE.",
pre_substitution_arr[preIdx], ".POST.",
post_substitution_arr[postIdx]);
result = test_vec_internal(deviceID, context, queue, tmp1, result =
"test_vec_align_struct", test_vec_internal(deviceID, context, queue, tmp1,
512, 0, 0, 0, 0); "test_vec_align_struct", 512, 0, 0, 0, 0);
if(result != 0) { if (result != 0)
{
return result; return result;
} }
} }
@@ -428,7 +420,8 @@ int test_vec_align_struct(cl_device_id deviceID, cl_context context, cl_command_
return 0; return 0;
} }
int test_vec_align_packed_struct(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) int test_vec_align_packed_struct(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{ {
char tmp1[2048], tmp2[2048]; char tmp1[2048], tmp2[2048];
int result = 0; int result = 0;
@@ -436,46 +429,46 @@ int test_vec_align_packed_struct(cl_device_id deviceID, cl_context context, cl_c
log_info("Testing __private\n"); log_info("Testing __private\n");
doReplace(tmp2, (size_t)2048, patterns[2], doReplace(tmp2, (size_t)2048, patterns[2], ".SRC_SCOPE.", "__private",
".SRC_SCOPE.", "__private",
".DST_SCOPE.", "__global"); // ".DST_SCOPE.", "__global"); //
for(preIdx = 0; pre_substitution_arr[preIdx] != NULL; ++preIdx) { for (preIdx = 0; pre_substitution_arr[preIdx] != NULL; ++preIdx)
for(postIdx = 0; post_substitution_arr[postIdx] != NULL; ++postIdx) { {
doReplace(tmp1, (size_t)2048, tmp2, for (postIdx = 0; post_substitution_arr[postIdx] != NULL; ++postIdx)
".PRE.", pre_substitution_arr[preIdx], {
".POST.", post_substitution_arr[postIdx]); doReplace(tmp1, (size_t)2048, tmp2, ".PRE.",
pre_substitution_arr[preIdx], ".POST.",
post_substitution_arr[postIdx]);
result = test_vec_internal(deviceID, context, queue, tmp1, result = test_vec_internal(
"test_vec_align_packed_struct", deviceID, context, queue, tmp1, "test_vec_align_packed_struct",
512, pre_align_arr[preIdx], 512, pre_align_arr[preIdx], type_multiple_pre_align_arr[preIdx],
type_multiple_pre_align_arr[preIdx], post_align_arr[postIdx], type_multiple_post_align_arr[postIdx]);
post_align_arr[postIdx], if (result != 0)
type_multiple_post_align_arr[postIdx]); {
if(result != 0) {
return result; return result;
} }
} }
} }
log_info("testing __local\n"); log_info("testing __local\n");
doReplace(tmp2, (size_t)2048, patterns[2], doReplace(tmp2, (size_t)2048, patterns[2], ".SRC_SCOPE.", "__local",
".SRC_SCOPE.", "__local",
".DST_SCOPE.", "__global"); // ".DST_SCOPE.", "__global"); //
for(preIdx = 0; pre_substitution_arr[preIdx] != NULL; ++preIdx) { for (preIdx = 0; pre_substitution_arr[preIdx] != NULL; ++preIdx)
for(postIdx = 0; post_substitution_arr[postIdx] != NULL; ++postIdx) { {
doReplace(tmp1, (size_t)2048, tmp2, for (postIdx = 0; post_substitution_arr[postIdx] != NULL; ++postIdx)
".PRE.", pre_substitution_arr[preIdx], {
".POST.", post_substitution_arr[postIdx]); doReplace(tmp1, (size_t)2048, tmp2, ".PRE.",
pre_substitution_arr[preIdx], ".POST.",
post_substitution_arr[postIdx]);
result = test_vec_internal(deviceID, context, queue, tmp1, result = test_vec_internal(
"test_vec_align_packed_struct", deviceID, context, queue, tmp1, "test_vec_align_packed_struct",
512, pre_align_arr[preIdx], 512, pre_align_arr[preIdx], type_multiple_pre_align_arr[preIdx],
type_multiple_pre_align_arr[preIdx], post_align_arr[postIdx], type_multiple_post_align_arr[postIdx]);
post_align_arr[postIdx], if (result != 0)
type_multiple_post_align_arr[postIdx]); {
if (result != 0) {
return result; return result;
} }
} }
@@ -483,7 +476,8 @@ int test_vec_align_packed_struct(cl_device_id deviceID, cl_context context, cl_c
return 0; return 0;
} }
int test_vec_align_struct_arr(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) int test_vec_align_struct_arr(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{ {
char tmp1[2048], tmp2[2048]; char tmp1[2048], tmp2[2048];
int result = 0; int result = 0;
@@ -491,20 +485,22 @@ int test_vec_align_struct_arr(cl_device_id deviceID, cl_context context, cl_comm
log_info("testing __global\n"); log_info("testing __global\n");
doReplace(tmp2, (size_t)2048, patterns[3], doReplace(tmp2, (size_t)2048, patterns[3], ".SRC_SCOPE.", "__global",
".SRC_SCOPE.", "__global",
".DST_SCOPE.", "__global"); // ".DST_SCOPE.", "__global"); //
for(preIdx = 0; pre_substitution_arr[preIdx] != NULL; ++preIdx) { for (preIdx = 0; pre_substitution_arr[preIdx] != NULL; ++preIdx)
for(postIdx = 0; post_substitution_arr[postIdx] != NULL; ++postIdx) { {
doReplace(tmp1, (size_t)2048, tmp2, for (postIdx = 0; post_substitution_arr[postIdx] != NULL; ++postIdx)
".PRE.", pre_substitution_arr[preIdx], {
".POST.", post_substitution_arr[postIdx]); doReplace(tmp1, (size_t)2048, tmp2, ".PRE.",
pre_substitution_arr[preIdx], ".POST.",
post_substitution_arr[postIdx]);
result = test_vec_internal(deviceID, context, queue, tmp1, result = test_vec_internal(deviceID, context, queue, tmp1,
"test_vec_align_struct_arr", "test_vec_align_struct_arr", BUFFER_SIZE,
BUFFER_SIZE, 0, 0, 0, 0); 0, 0, 0, 0);
if(result != 0) { if (result != 0)
{
return result; return result;
} }
} }
@@ -512,7 +508,8 @@ int test_vec_align_struct_arr(cl_device_id deviceID, cl_context context, cl_comm
return 0; return 0;
} }
int test_vec_align_packed_struct_arr(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) int test_vec_align_packed_struct_arr(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{ {
char tmp1[2048], tmp2[2048]; char tmp1[2048], tmp2[2048];
int result = 0; int result = 0;
@@ -520,26 +517,24 @@ int test_vec_align_packed_struct_arr(cl_device_id deviceID, cl_context context,
log_info("Testing __global\n"); log_info("Testing __global\n");
doReplace(tmp2, (size_t)2048, patterns[4], doReplace(tmp2, (size_t)2048, patterns[4], ".SRC_SCOPE.", "__global",
".SRC_SCOPE.", "__global",
".DST_SCOPE.", "__global"); // ".DST_SCOPE.", "__global"); //
for(preIdx = 0; pre_substitution_arr[preIdx] != NULL; ++preIdx) { for (preIdx = 0; pre_substitution_arr[preIdx] != NULL; ++preIdx)
for(postIdx = 0; post_substitution_arr[postIdx] != NULL; ++postIdx) { {
doReplace(tmp1, (size_t)2048, tmp2, for (postIdx = 0; post_substitution_arr[postIdx] != NULL; ++postIdx)
".PRE.", pre_substitution_arr[preIdx], {
".POST.", post_substitution_arr[postIdx]); doReplace(tmp1, (size_t)2048, tmp2, ".PRE.",
pre_substitution_arr[preIdx], ".POST.",
post_substitution_arr[postIdx]);
result = test_vec_internal(deviceID, context, queue, tmp1, result = test_vec_internal(
"test_vec_align_packed_struct_arr", deviceID, context, queue, tmp1,
BUFFER_SIZE, pre_align_arr[preIdx], "test_vec_align_packed_struct_arr", BUFFER_SIZE,
type_multiple_pre_align_arr[preIdx], pre_align_arr[preIdx], type_multiple_pre_align_arr[preIdx],
post_align_arr[postIdx], post_align_arr[postIdx], type_multiple_post_align_arr[postIdx]);
type_multiple_post_align_arr[postIdx]); if (result != 0) return result;
if(result != 0)
return result;
} }
} }
return 0; return 0;
} }

View File

@@ -1,6 +1,6 @@
// //
// Copyright (c) 2017 The Khronos Group Inc. // Copyright (c) 2017 The Khronos Group Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
@@ -18,15 +18,15 @@
#include <stdint.h> #include <stdint.h>
#endif // !_MSC_VER #endif // !_MSC_VER
size_t doReplace(char * dest, size_t destLength, const char * source, size_t doReplace(char* dest, size_t destLength, const char* source,
const char * stringToReplace1, const char * replaceWith1, const char* stringToReplace1, const char* replaceWith1,
const char * stringToReplace2, const char * replaceWith2) const char* stringToReplace2, const char* replaceWith2)
{ {
size_t copyCount = 0; size_t copyCount = 0;
const char * sourcePtr = source; const char* sourcePtr = source;
char * destPtr = dest; char* destPtr = dest;
const char * ptr1; const char* ptr1;
const char * ptr2; const char* ptr2;
size_t nJump; size_t nJump;
size_t len1, len2; size_t len1, len2;
size_t lenReplace1, lenReplace2; size_t lenReplace1, lenReplace2;
@@ -34,14 +34,18 @@ size_t doReplace(char * dest, size_t destLength, const char * source,
len2 = strlen(stringToReplace2); len2 = strlen(stringToReplace2);
lenReplace1 = strlen(replaceWith1); lenReplace1 = strlen(replaceWith1);
lenReplace2 = strlen(replaceWith2); lenReplace2 = strlen(replaceWith2);
for(;copyCount < destLength && *sourcePtr; ) for (; copyCount < destLength && *sourcePtr;)
{ {
ptr1 = strstr(sourcePtr, stringToReplace1); ptr1 = strstr(sourcePtr, stringToReplace1);
ptr2 = strstr(sourcePtr, stringToReplace2); ptr2 = strstr(sourcePtr, stringToReplace2);
if(ptr1 != NULL && (ptr2 == NULL || ptr2 > ptr1)) if (ptr1 != NULL && (ptr2 == NULL || ptr2 > ptr1))
{ {
nJump = ptr1-sourcePtr; nJump = ptr1 - sourcePtr;
if(((uintptr_t)ptr1-(uintptr_t)sourcePtr) > destLength-copyCount) { return -1; } if (((uintptr_t)ptr1 - (uintptr_t)sourcePtr)
> destLength - copyCount)
{
return -1;
}
copyCount += nJump; copyCount += nJump;
strncpy(destPtr, sourcePtr, nJump); strncpy(destPtr, sourcePtr, nJump);
destPtr += nJump; destPtr += nJump;
@@ -49,10 +53,13 @@ size_t doReplace(char * dest, size_t destLength, const char * source,
strcpy(destPtr, replaceWith1); strcpy(destPtr, replaceWith1);
destPtr += lenReplace1; destPtr += lenReplace1;
} }
else if(ptr2 != NULL && (ptr1 == NULL || ptr1 >= ptr2)) else if (ptr2 != NULL && (ptr1 == NULL || ptr1 >= ptr2))
{ {
nJump = ptr2-sourcePtr; nJump = ptr2 - sourcePtr;
if(nJump > destLength-copyCount) { return -2; } if (nJump > destLength - copyCount)
{
return -2;
}
copyCount += nJump; copyCount += nJump;
strncpy(destPtr, sourcePtr, nJump); strncpy(destPtr, sourcePtr, nJump);
destPtr += nJump; destPtr += nJump;
@@ -63,7 +70,10 @@ size_t doReplace(char * dest, size_t destLength, const char * source,
else else
{ {
nJump = strlen(sourcePtr); nJump = strlen(sourcePtr);
if(nJump > destLength-copyCount) { return -3; } if (nJump > destLength - copyCount)
{
return -3;
}
copyCount += nJump; copyCount += nJump;
strcpy(destPtr, sourcePtr); strcpy(destPtr, sourcePtr);
destPtr += nJump; destPtr += nJump;
@@ -74,25 +84,29 @@ size_t doReplace(char * dest, size_t destLength, const char * source,
return copyCount; return copyCount;
} }
size_t doSingleReplace(char * dest, size_t destLength, const char * source, size_t doSingleReplace(char* dest, size_t destLength, const char* source,
const char * stringToReplace, const char * replaceWith) const char* stringToReplace, const char* replaceWith)
{ {
size_t copyCount = 0; size_t copyCount = 0;
const char * sourcePtr = source; const char* sourcePtr = source;
char * destPtr = dest; char* destPtr = dest;
const char * ptr; const char* ptr;
size_t nJump; size_t nJump;
size_t len; size_t len;
size_t lenReplace; size_t lenReplace;
len = strlen(stringToReplace); len = strlen(stringToReplace);
lenReplace = strlen(replaceWith); lenReplace = strlen(replaceWith);
for(;copyCount < destLength && *sourcePtr; ) for (; copyCount < destLength && *sourcePtr;)
{ {
ptr = strstr(sourcePtr, stringToReplace); ptr = strstr(sourcePtr, stringToReplace);
if(ptr != NULL) if (ptr != NULL)
{ {
nJump = ptr-sourcePtr; nJump = ptr - sourcePtr;
if(((uintptr_t)ptr-(uintptr_t)sourcePtr) > destLength-copyCount) { return -1; } if (((uintptr_t)ptr - (uintptr_t)sourcePtr)
> destLength - copyCount)
{
return -1;
}
copyCount += nJump; copyCount += nJump;
strncpy(destPtr, sourcePtr, nJump); strncpy(destPtr, sourcePtr, nJump);
destPtr += nJump; destPtr += nJump;
@@ -103,7 +117,10 @@ size_t doSingleReplace(char * dest, size_t destLength, const char * source,
else else
{ {
nJump = strlen(sourcePtr); nJump = strlen(sourcePtr);
if(nJump > destLength-copyCount) { return -3; } if (nJump > destLength - copyCount)
{
return -3;
}
copyCount += nJump; copyCount += nJump;
strcpy(destPtr, sourcePtr); strcpy(destPtr, sourcePtr);
destPtr += nJump; destPtr += nJump;

View File

@@ -1,6 +1,6 @@
// //
// Copyright (c) 2017 The Khronos Group Inc. // Copyright (c) 2017 The Khronos Group Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
@@ -15,9 +15,9 @@
// //
#include <stdlib.h> #include <stdlib.h>
size_t doReplace(char * dest, size_t destLength, const char * source, size_t doReplace(char* dest, size_t destLength, const char* source,
const char * stringToReplace1, const char * replaceWith1, const char* stringToReplace1, const char* replaceWith1,
const char * stringToReplace2, const char * replaceWith2); const char* stringToReplace2, const char* replaceWith2);
size_t doSingleReplace(char * dest, size_t destLength, const char * source, size_t doSingleReplace(char* dest, size_t destLength, const char* source,
const char * stringToReplace, const char * replaceWith); const char* stringToReplace, const char* replaceWith);