mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-21 06:49:02 +00:00
Synchronise with Khronos-private Gitlab branch
The maintenance of the conformance tests is moving to Github. This commit contains all the changes that have been done in Gitlab since the first public release of the conformance tests. Signed-off-by: Kevin Petit <kevin.petit@arm.com>
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
project
|
||||
: requirements
|
||||
-<library>/harness//harness <use>/harness//harness
|
||||
# <toolset>gcc:<cflags>-xc
|
||||
<toolset>msvc:<cflags>"/TP"
|
||||
;
|
||||
|
||||
exe test_step
|
||||
: test_step.c
|
||||
globals.c
|
||||
main.c
|
||||
/harness//mt19937.c
|
||||
;
|
||||
|
||||
install dist
|
||||
: test_step
|
||||
: <variant>debug:<location>$(DIST)/debug/tests/test_conformance/vec_step
|
||||
<variant>release:<location>$(DIST)/release/tests/test_conformance/vec_step
|
||||
;
|
||||
project
|
||||
: requirements
|
||||
-<library>/harness//harness <use>/harness//harness
|
||||
# <toolset>gcc:<cflags>-xc
|
||||
<toolset>msvc:<cflags>"/TP"
|
||||
;
|
||||
|
||||
exe test_step
|
||||
: test_step.c
|
||||
globals.c
|
||||
main.c
|
||||
/harness//mt19937.c
|
||||
;
|
||||
|
||||
install dist
|
||||
: test_step
|
||||
: <variant>debug:<location>$(DIST)/debug/tests/test_conformance/vec_step
|
||||
<variant>release:<location>$(DIST)/release/tests/test_conformance/vec_step
|
||||
;
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
ifdef BUILD_WITH_ATF
|
||||
ATF = -framework ATF
|
||||
USE_ATF = -DUSE_ATF
|
||||
endif
|
||||
|
||||
SRCS = main.c \
|
||||
structs.c \
|
||||
test_step.c \
|
||||
globals.c \
|
||||
type_replacer.c \
|
||||
../../test_common/harness/errorHelpers.c \
|
||||
../../test_common/harness/threadTesting.c \
|
||||
../../test_common/harness/testHarness.c \
|
||||
../../test_common/harness/kernelHelpers.c \
|
||||
../../test_common/harness/mt19937.c \
|
||||
../../test_common/harness/conversions.c
|
||||
|
||||
DEFINES =
|
||||
|
||||
SOURCES = $(abspath $(SRCS))
|
||||
LIBPATH += -L/System/Library/Frameworks/OpenCL.framework/Libraries
|
||||
LIBPATH += -L.
|
||||
FRAMEWORK = $(SOURCES)
|
||||
HEADERS =
|
||||
TARGET = test_vecstep
|
||||
INCLUDE =
|
||||
COMPILERFLAGS = -c -Wall -g -Wshorten-64-to-32 -Os
|
||||
CC = c++
|
||||
CFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%) $(INCLUDE)
|
||||
CXXFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%) $(INCLUDE)
|
||||
LIBRARIES = -framework OpenCL -framework OpenGL -framework GLUT -framework AppKit ${ATF}
|
||||
|
||||
OBJECTS := ${SOURCES:.c=.o}
|
||||
OBJECTS := ${OBJECTS:.cpp=.o}
|
||||
|
||||
TARGETOBJECT =
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJECTS)
|
||||
$(CC) $(RC_CFLAGS) $(OBJECTS) -o $@ $(LIBPATH) $(LIBRARIES)
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) $(OBJECTS)
|
||||
|
||||
.DEFAULT:
|
||||
@echo The target \"$@\" does not exist in Makefile.
|
||||
ifdef BUILD_WITH_ATF
|
||||
ATF = -framework ATF
|
||||
USE_ATF = -DUSE_ATF
|
||||
endif
|
||||
|
||||
SRCS = main.c \
|
||||
structs.c \
|
||||
test_step.c \
|
||||
globals.c \
|
||||
type_replacer.c \
|
||||
../../test_common/harness/errorHelpers.c \
|
||||
../../test_common/harness/threadTesting.c \
|
||||
../../test_common/harness/testHarness.c \
|
||||
../../test_common/harness/kernelHelpers.c \
|
||||
../../test_common/harness/mt19937.c \
|
||||
../../test_common/harness/conversions.c
|
||||
|
||||
DEFINES =
|
||||
|
||||
SOURCES = $(abspath $(SRCS))
|
||||
LIBPATH += -L/System/Library/Frameworks/OpenCL.framework/Libraries
|
||||
LIBPATH += -L.
|
||||
FRAMEWORK = $(SOURCES)
|
||||
HEADERS =
|
||||
TARGET = test_vecstep
|
||||
INCLUDE =
|
||||
COMPILERFLAGS = -c -Wall -g -Wshorten-64-to-32 -Os
|
||||
CC = c++
|
||||
CFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%) $(INCLUDE)
|
||||
CXXFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%) $(INCLUDE)
|
||||
LIBRARIES = -framework OpenCL -framework OpenGL -framework GLUT -framework AppKit ${ATF}
|
||||
|
||||
OBJECTS := ${SOURCES:.c=.o}
|
||||
OBJECTS := ${OBJECTS:.cpp=.o}
|
||||
|
||||
TARGETOBJECT =
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJECTS)
|
||||
$(CC) $(RC_CFLAGS) $(OBJECTS) -o $@ $(LIBPATH) $(LIBRARIES)
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) $(OBJECTS)
|
||||
|
||||
.DEFAULT:
|
||||
@echo The target \"$@\" does not exist in Makefile.
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
//
|
||||
// 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 "../../test_common/harness/errorHelpers.h"
|
||||
#include "../../test_common/harness/kernelHelpers.h"
|
||||
#include "../../test_common/harness/threadTesting.h"
|
||||
#include "../../test_common/harness/typeWrappers.h"
|
||||
#include "../../test_common/harness/conversions.h"
|
||||
#include "../../test_common/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[];
|
||||
//
|
||||
// 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 "../../test_common/harness/errorHelpers.h"
|
||||
#include "../../test_common/harness/kernelHelpers.h"
|
||||
#include "../../test_common/harness/threadTesting.h"
|
||||
#include "../../test_common/harness/typeWrappers.h"
|
||||
#include "../../test_common/harness/conversions.h"
|
||||
#include "../../test_common/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[];
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
//
|
||||
// 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
|
||||
};
|
||||
|
||||
//
|
||||
// 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
|
||||
};
|
||||
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
//
|
||||
// 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include "procs.h"
|
||||
#include "../../test_common/harness/testHarness.h"
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
basefn basefn_list[] = {
|
||||
test_step_type,
|
||||
test_step_var,
|
||||
test_step_typedef_type,
|
||||
test_step_typedef_var,
|
||||
};
|
||||
|
||||
const char *basefn_names[] = {
|
||||
"step_type",
|
||||
"step_var",
|
||||
"step_typedef_type",
|
||||
"step_typedef_var",
|
||||
"all"
|
||||
};
|
||||
|
||||
ct_assert((sizeof(basefn_names) / sizeof(basefn_names[0]) - 1) == (sizeof(basefn_list) / sizeof(basefn_list[0])));
|
||||
|
||||
int num_fns = sizeof(basefn_names) / sizeof(char *);
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
return runTestHarness( argc, argv, num_fns, basefn_list, basefn_names, false, false, 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include "procs.h"
|
||||
#include "../../test_common/harness/testHarness.h"
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
basefn basefn_list[] = {
|
||||
test_step_type,
|
||||
test_step_var,
|
||||
test_step_typedef_type,
|
||||
test_step_typedef_var,
|
||||
};
|
||||
|
||||
const char *basefn_names[] = {
|
||||
"step_type",
|
||||
"step_var",
|
||||
"step_typedef_type",
|
||||
"step_typedef_var",
|
||||
"all"
|
||||
};
|
||||
|
||||
ct_assert((sizeof(basefn_names) / sizeof(basefn_names[0]) - 1) == (sizeof(basefn_list) / sizeof(basefn_list[0])));
|
||||
|
||||
int num_fns = sizeof(basefn_names) / sizeof(char *);
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
return runTestHarness( argc, argv, num_fns, basefn_list, basefn_names, false, false, 0 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
//
|
||||
// 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 "../../test_common/harness/errorHelpers.h"
|
||||
#include "../../test_common/harness/kernelHelpers.h"
|
||||
#include "../../test_common/harness/threadTesting.h"
|
||||
#include "../../test_common/harness/typeWrappers.h"
|
||||
#include "../../test_common/harness/conversions.h"
|
||||
#include "../../test_common/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);
|
||||
//
|
||||
// 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 "../../test_common/harness/errorHelpers.h"
|
||||
#include "../../test_common/harness/kernelHelpers.h"
|
||||
#include "../../test_common/harness/threadTesting.h"
|
||||
#include "../../test_common/harness/typeWrappers.h"
|
||||
#include "../../test_common/harness/conversions.h"
|
||||
#include "../../test_common/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);
|
||||
|
||||
@@ -1,285 +1,285 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
//
|
||||
// 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 "../../test_common/harness/conversions.h"
|
||||
#include "../../test_common/harness/typeWrappers.h"
|
||||
#include<math.h>
|
||||
#include<float.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);
|
||||
//
|
||||
// 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 "../../test_common/harness/conversions.h"
|
||||
#include "../../test_common/harness/typeWrappers.h"
|
||||
#include<math.h>
|
||||
#include<float.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);
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
//
|
||||
// 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "procs.h"
|
||||
|
||||
#endif // _testBase_h
|
||||
//
|
||||
// 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "procs.h"
|
||||
|
||||
#endif // _testBase_h
|
||||
|
||||
@@ -1,233 +1,233 @@
|
||||
//
|
||||
// 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 "../../test_common/harness/conversions.h"
|
||||
#include "../../test_common/harness/typeWrappers.h"
|
||||
#include<math.h>
|
||||
#include<float.h>
|
||||
|
||||
#include "structs.h"
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
#include "type_replacer.h"
|
||||
|
||||
|
||||
/*
|
||||
test_step_type,
|
||||
test_step_var,
|
||||
test_step_typedef_type,
|
||||
test_step_typedef_var,
|
||||
*/
|
||||
|
||||
|
||||
|
||||
int test_step_internal(cl_device_id deviceID, cl_context context, cl_command_queue queue, const char * pattern, const char * testName)
|
||||
{
|
||||
int err;
|
||||
int typeIdx, vecSizeIdx;
|
||||
|
||||
char tempBuffer[2048];
|
||||
|
||||
clState * pClState = newClState(deviceID, context, queue);
|
||||
bufferStruct * pBuffers =
|
||||
newBufferStruct(BUFFER_SIZE, BUFFER_SIZE, pClState);
|
||||
|
||||
if(pBuffers == NULL) {
|
||||
destroyClState(pClState);
|
||||
vlog_error("%s : Could not create buffer\n", testName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(typeIdx = 0; types[typeIdx] != kNumExplicitTypes; ++typeIdx)
|
||||
{
|
||||
if( types[ typeIdx ] == kDouble )
|
||||
{
|
||||
// If we're testing doubles, we need to check for support first
|
||||
if( !is_extension_available( deviceID, "cl_khr_fp64" ) )
|
||||
{
|
||||
log_info( "Not testing doubles (unsupported on this device)\n" );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
char srcBuffer[2048];
|
||||
|
||||
doSingleReplace(tempBuffer, 2048, pattern,
|
||||
".EXTENSIONS.", types[typeIdx] == kDouble
|
||||
? "#pragma OPENCL EXTENSION cl_khr_fp64 : enable"
|
||||
: "");
|
||||
|
||||
for(vecSizeIdx = 0; vecSizeIdx < NUM_VECTOR_SIZES; ++vecSizeIdx)
|
||||
{
|
||||
doReplace(srcBuffer, 2048, tempBuffer,
|
||||
".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",
|
||||
testName,
|
||||
g_arrTypeNames[typeIdx],
|
||||
g_arrVecSizeNames[vecSizeIdx]);
|
||||
destroyBufferStruct(pBuffers, pClState);
|
||||
destroyClState(pClState);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = clStateMakeProgram(pClState, srcBuffer, testName );
|
||||
if (err)
|
||||
{
|
||||
vlog_error("%s: Error compiling \"\n%s\n\"",
|
||||
testName, srcBuffer);
|
||||
destroyBufferStruct(pBuffers, pClState);
|
||||
destroyClState(pClState);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = pushArgs(pBuffers, pClState);
|
||||
if(err != 0)
|
||||
{
|
||||
vlog_error("%s: failed to push args %s%s\n",
|
||||
testName,
|
||||
g_arrTypeNames[typeIdx],
|
||||
g_arrVecSizeNames[vecSizeIdx]);
|
||||
destroyBufferStruct(pBuffers, pClState);
|
||||
destroyClState(pClState);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// now we run the kernel
|
||||
err = runKernel(pClState, 1024);
|
||||
if(err != 0)
|
||||
{
|
||||
vlog_error("%s: runKernel fail (%ld threads) %s%s\n",
|
||||
testName, pClState->m_numThreads,
|
||||
g_arrTypeNames[typeIdx],
|
||||
g_arrVecSizeNames[vecSizeIdx]);
|
||||
destroyBufferStruct(pBuffers, pClState);
|
||||
destroyClState(pClState);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = retrieveResults(pBuffers, pClState);
|
||||
if(err != 0)
|
||||
{
|
||||
vlog_error("%s: failed to retrieve results %s%s\n",
|
||||
testName,
|
||||
g_arrTypeNames[typeIdx],
|
||||
g_arrVecSizeNames[vecSizeIdx]);
|
||||
destroyBufferStruct(pBuffers, pClState);
|
||||
destroyClState(pClState);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = checkCorrectness(pBuffers, pClState,
|
||||
g_arrTypeSizes[typeIdx],
|
||||
g_arrVecSizes[vecSizeIdx]);
|
||||
|
||||
if(err != 0)
|
||||
{
|
||||
vlog_error("%s: incorrect results %s%s\n",
|
||||
testName,
|
||||
g_arrTypeNames[typeIdx],
|
||||
g_arrVecSizeNames[vecSizeIdx]);
|
||||
vlog_error("%s: Source was \"\n%s\n\"",
|
||||
testName, srcBuffer);
|
||||
destroyBufferStruct(pBuffers, pClState);
|
||||
destroyClState(pClState);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
destroyBufferStruct(pBuffers, pClState);
|
||||
|
||||
destroyClState(pClState);
|
||||
|
||||
|
||||
// vlog_error("%s : implementation incomplete : FAIL\n", testName);
|
||||
return 0; // -1; // fails on account of not being written.
|
||||
}
|
||||
|
||||
const char * patterns[] = {
|
||||
".EXTENSIONS.\n"
|
||||
"__kernel void test_step_type(__global .TYPE..NUM. *source, __global int *dest)\n"
|
||||
"{\n"
|
||||
" int tid = get_global_id(0);\n"
|
||||
" dest[tid] = vec_step(.TYPE..NUM.);\n"
|
||||
"\n"
|
||||
"}\n",
|
||||
|
||||
".EXTENSIONS.\n"
|
||||
"__kernel void test_step_var(__global .TYPE..NUM. *source, __global int *dest)\n"
|
||||
"{\n"
|
||||
" int tid = get_global_id(0);\n"
|
||||
" dest[tid] = vec_step(source[tid]);\n"
|
||||
"\n"
|
||||
"}\n",
|
||||
|
||||
".EXTENSIONS.\n"
|
||||
" typedef .TYPE..NUM. TypeToTest;\n"
|
||||
"__kernel void test_step_typedef_type(__global TypeToTest *source, __global int *dest)\n"
|
||||
"{\n"
|
||||
" int tid = get_global_id(0);\n"
|
||||
" dest[tid] = vec_step(TypeToTest);\n"
|
||||
"\n"
|
||||
"}\n",
|
||||
|
||||
".EXTENSIONS.\n"
|
||||
" typedef .TYPE..NUM. TypeToTest;\n"
|
||||
"__kernel void test_step_typedef_var(__global TypeToTest *source, __global int *dest)\n"
|
||||
"{\n"
|
||||
" int tid = get_global_id(0);\n"
|
||||
" dest[tid] = vec_step(source[tid]);\n"
|
||||
"\n"
|
||||
"}\n",
|
||||
};
|
||||
|
||||
/*
|
||||
test_step_type,
|
||||
test_step_var,
|
||||
test_step_typedef_type,
|
||||
test_step_typedef_var,
|
||||
*/
|
||||
|
||||
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],
|
||||
"test_step_type");
|
||||
}
|
||||
|
||||
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],
|
||||
"test_step_var");
|
||||
}
|
||||
|
||||
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],
|
||||
"test_step_typedef_type");
|
||||
}
|
||||
|
||||
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],
|
||||
"test_step_typedef_var");
|
||||
}
|
||||
//
|
||||
// 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 "../../test_common/harness/conversions.h"
|
||||
#include "../../test_common/harness/typeWrappers.h"
|
||||
#include<math.h>
|
||||
#include<float.h>
|
||||
|
||||
#include "structs.h"
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
#include "type_replacer.h"
|
||||
|
||||
|
||||
/*
|
||||
test_step_type,
|
||||
test_step_var,
|
||||
test_step_typedef_type,
|
||||
test_step_typedef_var,
|
||||
*/
|
||||
|
||||
|
||||
|
||||
int test_step_internal(cl_device_id deviceID, cl_context context, cl_command_queue queue, const char * pattern, const char * testName)
|
||||
{
|
||||
int err;
|
||||
int typeIdx, vecSizeIdx;
|
||||
|
||||
char tempBuffer[2048];
|
||||
|
||||
clState * pClState = newClState(deviceID, context, queue);
|
||||
bufferStruct * pBuffers =
|
||||
newBufferStruct(BUFFER_SIZE, BUFFER_SIZE, pClState);
|
||||
|
||||
if(pBuffers == NULL) {
|
||||
destroyClState(pClState);
|
||||
vlog_error("%s : Could not create buffer\n", testName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(typeIdx = 0; types[typeIdx] != kNumExplicitTypes; ++typeIdx)
|
||||
{
|
||||
if( types[ typeIdx ] == kDouble )
|
||||
{
|
||||
// If we're testing doubles, we need to check for support first
|
||||
if( !is_extension_available( deviceID, "cl_khr_fp64" ) )
|
||||
{
|
||||
log_info( "Not testing doubles (unsupported on this device)\n" );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
char srcBuffer[2048];
|
||||
|
||||
doSingleReplace(tempBuffer, 2048, pattern,
|
||||
".EXTENSIONS.", types[typeIdx] == kDouble
|
||||
? "#pragma OPENCL EXTENSION cl_khr_fp64 : enable"
|
||||
: "");
|
||||
|
||||
for(vecSizeIdx = 0; vecSizeIdx < NUM_VECTOR_SIZES; ++vecSizeIdx)
|
||||
{
|
||||
doReplace(srcBuffer, 2048, tempBuffer,
|
||||
".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",
|
||||
testName,
|
||||
g_arrTypeNames[typeIdx],
|
||||
g_arrVecSizeNames[vecSizeIdx]);
|
||||
destroyBufferStruct(pBuffers, pClState);
|
||||
destroyClState(pClState);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = clStateMakeProgram(pClState, srcBuffer, testName );
|
||||
if (err)
|
||||
{
|
||||
vlog_error("%s: Error compiling \"\n%s\n\"",
|
||||
testName, srcBuffer);
|
||||
destroyBufferStruct(pBuffers, pClState);
|
||||
destroyClState(pClState);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = pushArgs(pBuffers, pClState);
|
||||
if(err != 0)
|
||||
{
|
||||
vlog_error("%s: failed to push args %s%s\n",
|
||||
testName,
|
||||
g_arrTypeNames[typeIdx],
|
||||
g_arrVecSizeNames[vecSizeIdx]);
|
||||
destroyBufferStruct(pBuffers, pClState);
|
||||
destroyClState(pClState);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// now we run the kernel
|
||||
err = runKernel(pClState, 1024);
|
||||
if(err != 0)
|
||||
{
|
||||
vlog_error("%s: runKernel fail (%ld threads) %s%s\n",
|
||||
testName, pClState->m_numThreads,
|
||||
g_arrTypeNames[typeIdx],
|
||||
g_arrVecSizeNames[vecSizeIdx]);
|
||||
destroyBufferStruct(pBuffers, pClState);
|
||||
destroyClState(pClState);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = retrieveResults(pBuffers, pClState);
|
||||
if(err != 0)
|
||||
{
|
||||
vlog_error("%s: failed to retrieve results %s%s\n",
|
||||
testName,
|
||||
g_arrTypeNames[typeIdx],
|
||||
g_arrVecSizeNames[vecSizeIdx]);
|
||||
destroyBufferStruct(pBuffers, pClState);
|
||||
destroyClState(pClState);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = checkCorrectness(pBuffers, pClState,
|
||||
g_arrTypeSizes[typeIdx],
|
||||
g_arrVecSizes[vecSizeIdx]);
|
||||
|
||||
if(err != 0)
|
||||
{
|
||||
vlog_error("%s: incorrect results %s%s\n",
|
||||
testName,
|
||||
g_arrTypeNames[typeIdx],
|
||||
g_arrVecSizeNames[vecSizeIdx]);
|
||||
vlog_error("%s: Source was \"\n%s\n\"",
|
||||
testName, srcBuffer);
|
||||
destroyBufferStruct(pBuffers, pClState);
|
||||
destroyClState(pClState);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
destroyBufferStruct(pBuffers, pClState);
|
||||
|
||||
destroyClState(pClState);
|
||||
|
||||
|
||||
// vlog_error("%s : implementation incomplete : FAIL\n", testName);
|
||||
return 0; // -1; // fails on account of not being written.
|
||||
}
|
||||
|
||||
const char * patterns[] = {
|
||||
".EXTENSIONS.\n"
|
||||
"__kernel void test_step_type(__global .TYPE..NUM. *source, __global int *dest)\n"
|
||||
"{\n"
|
||||
" int tid = get_global_id(0);\n"
|
||||
" dest[tid] = vec_step(.TYPE..NUM.);\n"
|
||||
"\n"
|
||||
"}\n",
|
||||
|
||||
".EXTENSIONS.\n"
|
||||
"__kernel void test_step_var(__global .TYPE..NUM. *source, __global int *dest)\n"
|
||||
"{\n"
|
||||
" int tid = get_global_id(0);\n"
|
||||
" dest[tid] = vec_step(source[tid]);\n"
|
||||
"\n"
|
||||
"}\n",
|
||||
|
||||
".EXTENSIONS.\n"
|
||||
" typedef .TYPE..NUM. TypeToTest;\n"
|
||||
"__kernel void test_step_typedef_type(__global TypeToTest *source, __global int *dest)\n"
|
||||
"{\n"
|
||||
" int tid = get_global_id(0);\n"
|
||||
" dest[tid] = vec_step(TypeToTest);\n"
|
||||
"\n"
|
||||
"}\n",
|
||||
|
||||
".EXTENSIONS.\n"
|
||||
" typedef .TYPE..NUM. TypeToTest;\n"
|
||||
"__kernel void test_step_typedef_var(__global TypeToTest *source, __global int *dest)\n"
|
||||
"{\n"
|
||||
" int tid = get_global_id(0);\n"
|
||||
" dest[tid] = vec_step(source[tid]);\n"
|
||||
"\n"
|
||||
"}\n",
|
||||
};
|
||||
|
||||
/*
|
||||
test_step_type,
|
||||
test_step_var,
|
||||
test_step_typedef_type,
|
||||
test_step_typedef_var,
|
||||
*/
|
||||
|
||||
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],
|
||||
"test_step_type");
|
||||
}
|
||||
|
||||
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],
|
||||
"test_step_var");
|
||||
}
|
||||
|
||||
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],
|
||||
"test_step_typedef_type");
|
||||
}
|
||||
|
||||
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],
|
||||
"test_step_typedef_var");
|
||||
}
|
||||
|
||||
@@ -1,115 +1,115 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
//
|
||||
// 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);
|
||||
//
|
||||
// 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);
|
||||
|
||||
Reference in New Issue
Block a user