mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-24 15:59:03 +00:00
Initial open source release of OpenCL 2.0 CTS.
This commit is contained in:
17
test_conformance/generic_address_space/CMakeLists.txt
Normal file
17
test_conformance/generic_address_space/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
set(MODULE_NAME GENERIC_ADDRESS_SPACE)
|
||||
|
||||
set(${MODULE_NAME}_SOURCES
|
||||
advanced_tests.cpp
|
||||
basic_tests.cpp
|
||||
main.cpp
|
||||
stress_tests.cpp
|
||||
../../test_common/harness/testHarness.c
|
||||
../../test_common/harness/kernelHelpers.c
|
||||
../../test_common/harness/errorHelpers.c
|
||||
../../test_common/harness/mt19937.c
|
||||
../../test_common/harness/msvc9.c
|
||||
)
|
||||
|
||||
include(../CMakeCommon.txt)
|
||||
|
||||
# end of file #
|
||||
44
test_conformance/generic_address_space/Makefile
Normal file
44
test_conformance/generic_address_space/Makefile
Normal file
@@ -0,0 +1,44 @@
|
||||
ifdef BUILD_WITH_ATF
|
||||
ATF = -framework ATF
|
||||
USE_ATF = -DUSE_ATF
|
||||
endif
|
||||
|
||||
SRCS = main.c \
|
||||
basic_tests.cpp \
|
||||
advanced_tests.cpp \
|
||||
stress_tests.cpp \
|
||||
../../test_common/harness/errorHelpers.c \
|
||||
../../test_common/harness/threadTesting.c \
|
||||
../../test_common/harness/testHarness.c \
|
||||
../../test_common/harness/kernelHelpers.c \
|
||||
../../test_common/harness/typeWrappers.cpp \
|
||||
../../test_common/harness/mt19937.c \
|
||||
|
||||
DEFINES = DONT_TEST_GARBAGE_POINTERS
|
||||
|
||||
SOURCES = $(abspath $(SRCS))
|
||||
LIBPATH += -L/System/Library/Frameworks/OpenCL.framework/Libraries
|
||||
LIBPATH += -L.
|
||||
HEADERS =
|
||||
TARGET = test_uniform_address_space
|
||||
INCLUDE =
|
||||
COMPILERFLAGS = -c -Wall -g -Wshorten-64-to-32
|
||||
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.
|
||||
1031
test_conformance/generic_address_space/advanced_tests.cpp
Normal file
1031
test_conformance/generic_address_space/advanced_tests.cpp
Normal file
File diff suppressed because it is too large
Load Diff
39
test_conformance/generic_address_space/base.h
Normal file
39
test_conformance/generic_address_space/base.h
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// 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/testHarness.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class CTest {
|
||||
public:
|
||||
virtual int Execute(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) = 0;
|
||||
};
|
||||
|
||||
#define NL "\n"
|
||||
|
||||
namespace common {
|
||||
static const std::string CONFORMANCE_VERIFY_FENCE =
|
||||
NL
|
||||
NL "// current spec says get_fence can return any valid fence"
|
||||
NL "bool isFenceValid(cl_mem_fence_flags fence) {"
|
||||
NL " if ((fence == 0) || (fence == CLK_GLOBAL_MEM_FENCE) || (fence == CLK_LOCAL_MEM_FENCE) "
|
||||
NL " || (fence == (CLK_GLOBAL_MEM_FENCE | CLK_LOCAL_MEM_FENCE)))"
|
||||
NL " return true;"
|
||||
NL " else"
|
||||
NL " return false;"
|
||||
NL "}"
|
||||
NL;
|
||||
}
|
||||
883
test_conformance/generic_address_space/basic_tests.cpp
Normal file
883
test_conformance/generic_address_space/basic_tests.cpp
Normal file
@@ -0,0 +1,883 @@
|
||||
//
|
||||
// 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/testHarness.h"
|
||||
#include "../../test_common/harness/typeWrappers.h"
|
||||
#include "base.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
class CBasicTest : CTest {
|
||||
public:
|
||||
CBasicTest(const std::vector<std::string>& kernel) : CTest(), _kernels(kernel) {
|
||||
|
||||
}
|
||||
|
||||
CBasicTest(const std::string& kernel) : CTest(), _kernels(1, kernel) {
|
||||
|
||||
}
|
||||
|
||||
int ExecuteSubcase(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements, const std::string& src) {
|
||||
cl_int error;
|
||||
|
||||
clProgramWrapper program;
|
||||
clKernelWrapper kernel;
|
||||
|
||||
const char *srcPtr = src.c_str();
|
||||
|
||||
if (create_single_kernel_helper_with_build_options(context, &program, &kernel, 1, &srcPtr, "testKernel", "-cl-std=CL2.0")) {
|
||||
log_error("create_single_kernel_helper failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t bufferSize = num_elements * sizeof(cl_uint);
|
||||
clMemWrapper buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, bufferSize, NULL, &error);
|
||||
test_error(error, "clCreateBuffer failed");
|
||||
|
||||
error = clSetKernelArg(kernel, 0, sizeof(buffer), &buffer);
|
||||
test_error(error, "clSetKernelArg failed");
|
||||
|
||||
size_t globalWorkGroupSize = num_elements;
|
||||
size_t localWorkGroupSize = 0;
|
||||
error = get_max_common_work_group_size(context, kernel, globalWorkGroupSize, &localWorkGroupSize);
|
||||
test_error(error, "Unable to get common work group size");
|
||||
|
||||
error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &globalWorkGroupSize, &localWorkGroupSize, 0, NULL, NULL);
|
||||
test_error(error, "clEnqueueNDRangeKernel failed");
|
||||
|
||||
// verify results
|
||||
std::vector<cl_uint> results(num_elements);
|
||||
|
||||
error = clEnqueueReadBuffer(queue, buffer, CL_TRUE, 0, bufferSize, &results[0], 0, NULL, NULL);
|
||||
test_error(error, "clEnqueueReadBuffer failed");
|
||||
|
||||
size_t passCount = std::count(results.begin(), results.end(), 1);
|
||||
if (passCount != results.size()) {
|
||||
std::vector<cl_uint>::iterator iter = std::find(results.begin(), results.end(), 0);
|
||||
log_error("Verification on device failed at index %ld\n", std::distance(results.begin(), iter));
|
||||
log_error("%ld out of %ld failed\n", (results.size()-passCount), results.size());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
int Execute(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) {
|
||||
cl_int result = CL_SUCCESS;
|
||||
|
||||
for (std::vector<std::string>::const_iterator it = _kernels.begin(); it != _kernels.end(); ++it) {
|
||||
log_info("Executing subcase #%ld out of %ld\n", (it - _kernels.begin() + 1), _kernels.size());
|
||||
|
||||
result |= ExecuteSubcase(deviceID, context, queue, num_elements, *it);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::vector<std::string> _kernels;
|
||||
};
|
||||
|
||||
int test_function_params_get_fence(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) {
|
||||
const std::string KERNEL_FUNCTION = common::CONFORMANCE_VERIFY_FENCE +
|
||||
NL
|
||||
NL "__global int gint = 1;"
|
||||
NL "__global uchar guchar = 3;"
|
||||
NL
|
||||
NL "bool helperFunction(int *intp, float *floatp, uchar *ucharp, ushort *ushortp, long *longp) {"
|
||||
NL " if (!isFenceValid(get_fence(intp)))"
|
||||
NL " return false;"
|
||||
NL " if (!isFenceValid(get_fence(floatp)))"
|
||||
NL " return false;"
|
||||
NL " if (!isFenceValid(get_fence(ucharp)))"
|
||||
NL " return false;"
|
||||
NL " if (!isFenceValid(get_fence(ushortp)))"
|
||||
NL " return false;"
|
||||
NL " if (!isFenceValid(get_fence(longp)))"
|
||||
NL " return false;"
|
||||
NL
|
||||
NL " if (*intp != 1 || *floatp != 2.0f || *ucharp != 3 || *ushortp != 4 || *longp != 5)"
|
||||
NL " return false;"
|
||||
NL
|
||||
NL " return true;"
|
||||
NL "}"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " __local float lfloat;"
|
||||
NL " lfloat = 2.0f;"
|
||||
NL " __local ushort lushort;"
|
||||
NL " lushort = 4;"
|
||||
NL " long plong = 5;"
|
||||
NL
|
||||
NL " __global int *gintp = &gint;"
|
||||
NL " __local float *lfloatp = &lfloat;"
|
||||
NL " __global uchar *gucharp = &guchar;"
|
||||
NL " __local ushort *lushortp = &lushort;"
|
||||
NL " __private long *plongp = &plong;"
|
||||
NL
|
||||
NL " results[tid] = helperFunction(gintp, lfloatp, gucharp, lushortp, plongp);"
|
||||
NL "}"
|
||||
NL;
|
||||
|
||||
CBasicTest test(KERNEL_FUNCTION);
|
||||
|
||||
return test.Execute(deviceID, context, queue, num_elements);
|
||||
}
|
||||
|
||||
int test_function_params_to_address_space(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) {
|
||||
const std::string KERNEL_FUNCTION =
|
||||
NL
|
||||
NL "__global int gint = 1;"
|
||||
NL "__global uchar guchar = 3;"
|
||||
NL
|
||||
NL "bool helperFunction(int *gintp, float *lfloatp, uchar *gucharp, ushort *lushortp, long *plongp) {"
|
||||
NL " if (to_global(gintp) == NULL)"
|
||||
NL " return false;"
|
||||
NL " if (to_local(lfloatp) == NULL)"
|
||||
NL " return false;"
|
||||
NL " if (to_global(gucharp) == NULL)"
|
||||
NL " return false;"
|
||||
NL " if (to_local(lushortp) == NULL)"
|
||||
NL " return false;"
|
||||
NL " if (to_private(plongp) == NULL)"
|
||||
NL " return false;"
|
||||
NL
|
||||
NL " if (*gintp != 1 || *lfloatp != 2.0f || *gucharp != 3 || *lushortp != 4 || *plongp != 5)"
|
||||
NL " return false;"
|
||||
NL
|
||||
NL " return true;"
|
||||
NL "}"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " __local float lfloat;"
|
||||
NL " lfloat = 2.0f;"
|
||||
NL " __local ushort lushort;"
|
||||
NL " lushort = 4;"
|
||||
NL " long plong = 5;"
|
||||
NL
|
||||
NL " __global int *gintp = &gint;"
|
||||
NL " __local float *lfloatp = &lfloat;"
|
||||
NL " __global uchar *gucharp = &guchar;"
|
||||
NL " __local ushort *lushortp = &lushort;"
|
||||
NL " __private long *plongp = &plong;"
|
||||
NL
|
||||
NL " results[tid] = helperFunction(gintp, lfloatp, gucharp, lushortp, plongp);"
|
||||
NL "}"
|
||||
NL;
|
||||
|
||||
CBasicTest test(KERNEL_FUNCTION);
|
||||
|
||||
return test.Execute(deviceID, context, queue, num_elements);
|
||||
}
|
||||
|
||||
int test_variable_get_fence(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) {
|
||||
const std::string KERNEL_FUNCTION = common::CONFORMANCE_VERIFY_FENCE +
|
||||
NL
|
||||
NL "__global int gint = 1;"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " __local ushort lushort;"
|
||||
NL " lushort = 2;"
|
||||
NL " float pfloat = 3.0f;"
|
||||
NL
|
||||
NL " // tested pointers"
|
||||
NL " __global int *gintp = &gint;"
|
||||
NL " __local ushort *lushortp = &lushort;"
|
||||
NL " __private float *pfloatp = &pfloat;"
|
||||
NL
|
||||
NL " int failures = 0;"
|
||||
NL " if (!isFenceValid(get_fence(gintp)))"
|
||||
NL " failures++;"
|
||||
NL " if (!isFenceValid(get_fence(lushortp)))"
|
||||
NL " failures++;"
|
||||
NL " if (!isFenceValid(get_fence(pfloatp)))"
|
||||
NL " failures++;"
|
||||
NL " results[tid] = (failures == 0);"
|
||||
NL "}"
|
||||
NL;
|
||||
|
||||
CBasicTest test(KERNEL_FUNCTION);
|
||||
|
||||
return test.Execute(deviceID, context, queue, num_elements);
|
||||
}
|
||||
|
||||
int test_variable_to_address_space(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) {
|
||||
const std::string KERNEL_FUNCTION =
|
||||
NL
|
||||
NL "__global int gint = 1;"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " __local ushort lushort;"
|
||||
NL " lushort = 2;"
|
||||
NL " float pfloat = 3.0f;"
|
||||
NL
|
||||
NL " // tested pointers"
|
||||
NL " __global int * gintp = &gint;"
|
||||
NL " __local ushort *lushortp = &lushort;"
|
||||
NL " __private float *pfloatp = &pfloat;"
|
||||
NL
|
||||
NL " int failures = 0;"
|
||||
NL " if (to_global(gintp) == NULL)"
|
||||
NL " failures++;"
|
||||
NL " if (to_local(lushortp) == NULL)"
|
||||
NL " failures++;"
|
||||
NL " if (to_private(pfloatp) == NULL)"
|
||||
NL " failures++;"
|
||||
NL " results[tid] = (failures == 0);"
|
||||
NL "}"
|
||||
NL;
|
||||
|
||||
CBasicTest test(KERNEL_FUNCTION);
|
||||
|
||||
return test.Execute(deviceID, context, queue, num_elements);
|
||||
}
|
||||
|
||||
int test_casting(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) {
|
||||
std::vector<std::string> KERNEL_FUNCTIONS;
|
||||
|
||||
// pointers to global, local or private are implicitly convertible to generic
|
||||
KERNEL_FUNCTIONS.push_back(common::CONFORMANCE_VERIFY_FENCE +
|
||||
NL
|
||||
NL "__global int gint = 1;"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " __local int lint;"
|
||||
NL " lint = 2;"
|
||||
NL " int pint = 3;"
|
||||
NL
|
||||
NL " // count mismatches with expected fence types"
|
||||
NL " int failures = 0;"
|
||||
NL
|
||||
NL " // tested pointer"
|
||||
NL " // generic can be reassigned to different named address spaces"
|
||||
NL " int * intp;"
|
||||
NL
|
||||
NL " intp = &gint;"
|
||||
NL " failures += !(isFenceValid(get_fence(intp)));"
|
||||
NL " failures += !(to_global(intp));"
|
||||
NL " failures += (*intp != 1);"
|
||||
NL
|
||||
NL " intp = &lint;"
|
||||
NL " failures += !(isFenceValid(get_fence(intp)));"
|
||||
NL " failures += !(to_local(intp));"
|
||||
NL " failures += (*intp != 2);"
|
||||
NL
|
||||
NL " intp = &pint;"
|
||||
NL " failures += !(isFenceValid(get_fence(intp)));"
|
||||
NL " failures += !(to_private(intp));"
|
||||
NL " failures += (*intp != 3);"
|
||||
NL
|
||||
NL " results[tid] = (failures == 0);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
// converting from a generic pointer to a named address space is legal only with explicit casting
|
||||
KERNEL_FUNCTIONS.push_back(common::CONFORMANCE_VERIFY_FENCE +
|
||||
NL
|
||||
NL "__global int gint = 1;"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " __local int lint;"
|
||||
NL " lint = 2;"
|
||||
NL " int pint = 3;"
|
||||
NL
|
||||
NL " // count mismatches with expected fence types"
|
||||
NL " int failures = 0;"
|
||||
NL
|
||||
NL " // tested pointer"
|
||||
NL " // generic can be reassigned to different named address spaces"
|
||||
NL " int * intp;"
|
||||
NL
|
||||
NL " intp = &gint;"
|
||||
NL " global int * gintp = (global int *)intp;"
|
||||
NL " failures += !(isFenceValid(get_fence(gintp)));"
|
||||
NL " failures += !(to_global(gintp));"
|
||||
NL " failures += (*gintp != 1);"
|
||||
NL
|
||||
NL " intp = &lint;"
|
||||
NL " local int * lintp = (local int *)intp;"
|
||||
NL " failures += !(isFenceValid(get_fence(lintp)));"
|
||||
NL " failures += !(to_local(lintp));"
|
||||
NL " failures += (*lintp != 2);"
|
||||
NL
|
||||
NL " intp = &pint;"
|
||||
NL " private int * pintp = (private int *)intp;"
|
||||
NL " failures += !(isFenceValid(get_fence(pintp)));"
|
||||
NL " failures += !(to_private(pintp));"
|
||||
NL " failures += (*pintp != 3);"
|
||||
NL
|
||||
NL " results[tid] = (failures == 0);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
CBasicTest test(KERNEL_FUNCTIONS);
|
||||
|
||||
return test.Execute(deviceID, context, queue, num_elements);
|
||||
}
|
||||
|
||||
int test_conditional_casting(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) {
|
||||
const std::string KERNEL_FUNCTION = common::CONFORMANCE_VERIFY_FENCE +
|
||||
NL
|
||||
NL "__global int gint = 1;"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " int *ptr;"
|
||||
NL " __local int lint;"
|
||||
NL " lint = 2;"
|
||||
NL
|
||||
NL " if (tid % 2)"
|
||||
NL " ptr = &gint;"
|
||||
NL " else"
|
||||
NL " ptr = &lint;"
|
||||
NL
|
||||
NL " barrier(CLK_GLOBAL_MEM_FENCE);"
|
||||
NL
|
||||
NL " if (tid % 2)"
|
||||
NL " results[tid] = (isFenceValid(get_fence(ptr)) && to_global(ptr) && *ptr == 1);"
|
||||
NL " else"
|
||||
NL " results[tid] = (isFenceValid(get_fence(ptr)) && to_local(ptr) && *ptr == 2);"
|
||||
NL "}"
|
||||
NL;
|
||||
|
||||
CBasicTest test(KERNEL_FUNCTION);
|
||||
|
||||
return test.Execute(deviceID, context, queue, num_elements);
|
||||
}
|
||||
|
||||
int test_chain_casting(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) {
|
||||
const std::string KERNEL_FUNCTION = common::CONFORMANCE_VERIFY_FENCE +
|
||||
NL
|
||||
NL "__global int gint = 1;"
|
||||
NL
|
||||
NL "int f4(int val, int *ptr) { return (isFenceValid(get_fence(ptr)) && val == *ptr) ? 0 : 1; }"
|
||||
NL "int f3(int val, int *ptr) { return f4(val, ptr); }"
|
||||
NL "int f2(int *ptr, int val) { return f3(val, ptr); }"
|
||||
NL "int f1(int *ptr, int val) { return f2(ptr, val); }"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " int *ptr;"
|
||||
NL " __local int lint;"
|
||||
NL " lint = 2;"
|
||||
NL " __private int pint = 3;"
|
||||
NL
|
||||
NL " int failures = 0;"
|
||||
NL " failures += f1(&gint, gint);"
|
||||
NL " failures += f1(&lint, lint);"
|
||||
NL " failures += f1(&pint, pint);"
|
||||
NL
|
||||
NL " results[tid] = (failures == 0);"
|
||||
NL "}"
|
||||
NL;
|
||||
CBasicTest test(KERNEL_FUNCTION);
|
||||
|
||||
return test.Execute(deviceID, context, queue, num_elements);
|
||||
}
|
||||
|
||||
int test_ternary_operator_casting(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) {
|
||||
const std::string KERNEL_FUNCTION = common::CONFORMANCE_VERIFY_FENCE +
|
||||
NL
|
||||
NL "__global int gint = 1;"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " int *ptr;"
|
||||
NL " __local int lint;"
|
||||
NL " lint = 2;"
|
||||
NL
|
||||
NL " ptr = (tid % 2) ? &gint : (int *)&lint; // assuming there is an implicit conversion from named address space to generic"
|
||||
NL
|
||||
NL " barrier(CLK_GLOBAL_MEM_FENCE);"
|
||||
NL
|
||||
NL " if (tid % 2)"
|
||||
NL " results[tid] = (isFenceValid(get_fence(ptr)) && to_global(ptr) && *ptr == gint);"
|
||||
NL " else"
|
||||
NL " results[tid] = (isFenceValid(get_fence(ptr)) && to_local(ptr) && *ptr == lint);"
|
||||
NL "}"
|
||||
NL;
|
||||
|
||||
CBasicTest test(KERNEL_FUNCTION);
|
||||
|
||||
return test.Execute(deviceID, context, queue, num_elements);
|
||||
}
|
||||
|
||||
int test_language_struct(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) {
|
||||
std::vector<std::string> KERNEL_FUNCTIONS;
|
||||
|
||||
// implicit private struct
|
||||
KERNEL_FUNCTIONS.push_back(common::CONFORMANCE_VERIFY_FENCE +
|
||||
NL
|
||||
NL "__global int gint = 1;"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL " int failures = 0;"
|
||||
NL
|
||||
NL " __local int lint;"
|
||||
NL " lint = 2;"
|
||||
NL " __private int pint = 3;"
|
||||
NL
|
||||
NL " struct {"
|
||||
NL " __global int *gintp;"
|
||||
NL " __local int *lintp;"
|
||||
NL " __private int *pintp;"
|
||||
NL " } structWithPointers;"
|
||||
NL
|
||||
NL " structWithPointers.gintp = &gint;"
|
||||
NL " structWithPointers.lintp = &lint;"
|
||||
NL " structWithPointers.pintp = &pint;"
|
||||
NL
|
||||
NL " failures += !(isFenceValid(get_fence(structWithPointers.gintp)));"
|
||||
NL " failures += !(isFenceValid(get_fence(structWithPointers.lintp)));"
|
||||
NL " failures += !(isFenceValid(get_fence(structWithPointers.pintp)));"
|
||||
NL
|
||||
NL " failures += !(to_global(structWithPointers.gintp));"
|
||||
NL " failures += !(to_local(structWithPointers.lintp));"
|
||||
NL " failures += !(to_private(structWithPointers.pintp));"
|
||||
NL
|
||||
NL " results[tid] = (failures == 0);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
// explicit __private struct
|
||||
KERNEL_FUNCTIONS.push_back(common::CONFORMANCE_VERIFY_FENCE +
|
||||
NL
|
||||
NL "__global int gint = 1;"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL " int failures = 0;"
|
||||
NL
|
||||
NL " __local int lint;"
|
||||
NL " lint = 2;"
|
||||
NL " __private int pint = 3;"
|
||||
NL
|
||||
NL " typedef struct {"
|
||||
NL " __global int * gintp;"
|
||||
NL " __local int * lintp;"
|
||||
NL " __private int * pintp;"
|
||||
NL " } S;"
|
||||
NL
|
||||
NL " __private S structWithPointers;"
|
||||
NL " structWithPointers.gintp = &gint;"
|
||||
NL " structWithPointers.lintp = &lint;"
|
||||
NL " structWithPointers.pintp = &pint;"
|
||||
NL
|
||||
NL " failures += !(isFenceValid(get_fence(structWithPointers.gintp)));"
|
||||
NL " failures += !(isFenceValid(get_fence(structWithPointers.lintp)));"
|
||||
NL " failures += !(isFenceValid(get_fence(structWithPointers.pintp)));"
|
||||
NL
|
||||
NL " failures += !(to_global(structWithPointers.gintp));"
|
||||
NL " failures += !(to_local(structWithPointers.lintp));"
|
||||
NL " failures += !(to_private(structWithPointers.pintp));"
|
||||
NL
|
||||
NL " results[tid] = (failures == 0);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
KERNEL_FUNCTIONS.push_back(common::CONFORMANCE_VERIFY_FENCE +
|
||||
NL
|
||||
NL "__global int gint = 1;"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL " int failures = 0;"
|
||||
NL
|
||||
NL " __local int lint;"
|
||||
NL " lint = 2;"
|
||||
NL " __private int pint = 3;"
|
||||
NL
|
||||
NL " typedef struct {"
|
||||
NL " __global int * gintp;"
|
||||
NL " __local int * lintp;"
|
||||
NL " __private int * pintp;"
|
||||
NL " } S;"
|
||||
NL
|
||||
NL " __local S structWithPointers;"
|
||||
NL " structWithPointers.gintp = &gint;"
|
||||
NL " structWithPointers.lintp = &lint;"
|
||||
NL " structWithPointers.pintp = &pint;"
|
||||
NL
|
||||
NL " failures += !(isFenceValid(get_fence(structWithPointers.gintp)));"
|
||||
NL " failures += !(isFenceValid(get_fence(structWithPointers.lintp)));"
|
||||
NL " failures += !(isFenceValid(get_fence(structWithPointers.pintp)));"
|
||||
NL
|
||||
NL " failures += !(to_global(structWithPointers.gintp));"
|
||||
NL " failures += !(to_local(structWithPointers.lintp));"
|
||||
NL " failures += !(to_private(structWithPointers.pintp));"
|
||||
NL
|
||||
NL " results[tid] = (failures == 0);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
KERNEL_FUNCTIONS.push_back(common::CONFORMANCE_VERIFY_FENCE +
|
||||
NL
|
||||
NL "typedef struct {"
|
||||
NL " __global int *gintp;"
|
||||
NL " __local int *lintp;"
|
||||
NL " __private int *pintp;"
|
||||
NL "} S;"
|
||||
NL
|
||||
NL "__global S structWithPointers;"
|
||||
NL "__global int gint = 1;"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL " int failures = 0;"
|
||||
NL
|
||||
NL " __local int lint;"
|
||||
NL " lint = 2;"
|
||||
NL " __private int pint = 3;"
|
||||
NL
|
||||
NL " structWithPointers.gintp = &gint;"
|
||||
NL " structWithPointers.lintp = &lint;"
|
||||
NL " structWithPointers.pintp = &pint;"
|
||||
NL
|
||||
NL " failures += !(isFenceValid(get_fence(structWithPointers.gintp)));"
|
||||
NL " failures += !(isFenceValid(get_fence(structWithPointers.lintp)));"
|
||||
NL " failures += !(isFenceValid(get_fence(structWithPointers.pintp)));"
|
||||
NL
|
||||
NL " failures += !(to_global(structWithPointers.gintp));"
|
||||
NL " failures += !(to_local(structWithPointers.lintp));"
|
||||
NL " failures += !(to_private(structWithPointers.pintp));"
|
||||
NL
|
||||
NL " results[tid] = (failures == 0);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
CBasicTest test(KERNEL_FUNCTIONS);
|
||||
|
||||
return test.Execute(deviceID, context, queue, num_elements);
|
||||
}
|
||||
|
||||
int test_language_union(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) {
|
||||
std::vector<std::string> KERNEL_FUNCTIONS;
|
||||
|
||||
KERNEL_FUNCTIONS.push_back(common::CONFORMANCE_VERIFY_FENCE +
|
||||
NL
|
||||
NL "__global int g = 1;"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL " int failures = 0;"
|
||||
NL
|
||||
NL " __local int l;"
|
||||
NL " l = 2;"
|
||||
NL " int p = 3;"
|
||||
NL
|
||||
NL " union {"
|
||||
NL " __global int *gintp;"
|
||||
NL " __local int *lintp;"
|
||||
NL " __private int *pintp;"
|
||||
NL " } u;"
|
||||
NL
|
||||
NL " u.gintp = &g;"
|
||||
NL " failures += !(isFenceValid(get_fence(u.gintp)));"
|
||||
NL " failures += !to_global(u.gintp);"
|
||||
NL " failures += (*(u.gintp) != 1);"
|
||||
NL
|
||||
NL " u.lintp = &l;"
|
||||
NL " failures += !(isFenceValid(get_fence(u.lintp)));"
|
||||
NL " failures += !to_local(u.lintp);"
|
||||
NL " failures += (*(u.lintp) != 2);"
|
||||
NL
|
||||
NL " u.pintp = &p;"
|
||||
NL " failures += !(isFenceValid(get_fence(u.pintp)));"
|
||||
NL " failures += !to_private(u.pintp);"
|
||||
NL " failures += (*(u.pintp) != 3);"
|
||||
NL
|
||||
NL " results[tid] = (failures == 0);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
KERNEL_FUNCTIONS.push_back(common::CONFORMANCE_VERIFY_FENCE +
|
||||
NL
|
||||
NL "__global int g = 1;"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL " int failures = 0;"
|
||||
NL
|
||||
NL " __local int l;"
|
||||
NL " l = 2;"
|
||||
NL " int p = 3;"
|
||||
NL
|
||||
NL " typedef union {"
|
||||
NL " __global int * gintp;"
|
||||
NL " __local int * lintp;"
|
||||
NL " __private int * pintp;"
|
||||
NL " } U;"
|
||||
NL
|
||||
NL " __local U u;"
|
||||
NL
|
||||
NL " u.gintp = &g;"
|
||||
NL " work_group_barrier(CLK_LOCAL_MEM_FENCE);"
|
||||
NL " failures += !(isFenceValid(get_fence(u.gintp)));"
|
||||
NL " failures += !to_global(u.gintp);"
|
||||
NL " failures += (*(u.gintp) != 1);"
|
||||
NL
|
||||
NL " work_group_barrier(CLK_LOCAL_MEM_FENCE);"
|
||||
NL " u.lintp = &l;"
|
||||
NL " work_group_barrier(CLK_LOCAL_MEM_FENCE);"
|
||||
NL " failures += !(isFenceValid(get_fence(u.lintp)));"
|
||||
NL " failures += !to_local(u.lintp);"
|
||||
NL " failures += (*(u.lintp) != 2);"
|
||||
NL
|
||||
NL " work_group_barrier(CLK_LOCAL_MEM_FENCE);"
|
||||
NL " if(get_local_id(0) == 0) {"
|
||||
NL " u.pintp = &p;"
|
||||
NL " failures += !(isFenceValid(get_fence(u.pintp)));"
|
||||
NL " failures += !to_private(u.pintp);"
|
||||
NL " failures += (*(u.pintp) != 3);"
|
||||
NL " }"
|
||||
NL
|
||||
NL " results[tid] = (failures == 0);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
KERNEL_FUNCTIONS.push_back(common::CONFORMANCE_VERIFY_FENCE +
|
||||
NL
|
||||
NL "typedef union {"
|
||||
NL " __global int * gintp;"
|
||||
NL " __local int * lintp;"
|
||||
NL " __private int * pintp;"
|
||||
NL "} U;"
|
||||
NL
|
||||
NL "__global U u;"
|
||||
NL "__global int g = 1;"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " // for global unions only one thread should modify union's content"
|
||||
NL " if (tid != 0) {"
|
||||
NL " results[tid] = 1;"
|
||||
NL " return;"
|
||||
NL " }"
|
||||
NL
|
||||
NL " int failures = 0;"
|
||||
NL
|
||||
NL " __local int l;"
|
||||
NL " l = 2;"
|
||||
NL " int p = 3;"
|
||||
NL
|
||||
NL " u.gintp = &g;"
|
||||
NL " failures += !(isFenceValid(get_fence(u.gintp)));"
|
||||
NL " failures += !to_global(u.gintp);"
|
||||
NL " failures += (*(u.gintp) != 1);"
|
||||
NL
|
||||
NL " u.lintp = &l;"
|
||||
NL " failures += !(isFenceValid(get_fence(u.lintp)));"
|
||||
NL " failures += !to_local(u.lintp);"
|
||||
NL " failures += (*(u.lintp) != 2);"
|
||||
NL
|
||||
NL " u.pintp = &p;"
|
||||
NL " failures += !(isFenceValid(get_fence(u.pintp)));"
|
||||
NL " failures += !to_private(u.pintp);"
|
||||
NL " failures += (*(u.pintp) != 3);"
|
||||
NL
|
||||
NL " results[tid] = (failures == 0);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
CBasicTest test(KERNEL_FUNCTIONS);
|
||||
|
||||
return test.Execute(deviceID, context, queue, num_elements);
|
||||
}
|
||||
|
||||
int test_multiple_calls_same_function(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) {
|
||||
const std::string KERNEL_FUNCTION =
|
||||
NL
|
||||
NL "int shift2(const int *ptr, int arg) {"
|
||||
NL " return *ptr << arg;"
|
||||
NL "}"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL " int failures = 0;"
|
||||
NL
|
||||
NL " __local int val;"
|
||||
NL " val = get_group_id(0);"
|
||||
NL
|
||||
NL " for (int i = 0; i < 5; i++) {"
|
||||
NL " if (shift2(&val, i) != (val << i))"
|
||||
NL " failures++;"
|
||||
NL " }"
|
||||
NL
|
||||
NL " for (int i = 10; i > 5; i--) {"
|
||||
NL " if (shift2(&val, i) != (val << i))"
|
||||
NL " failures++;"
|
||||
NL " }"
|
||||
NL
|
||||
NL " results[tid] = (failures == 0);"
|
||||
NL "}"
|
||||
NL;
|
||||
|
||||
CBasicTest test(KERNEL_FUNCTION);
|
||||
|
||||
return test.Execute(deviceID, context, queue, num_elements);
|
||||
}
|
||||
|
||||
int test_compare_pointers(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) {
|
||||
std::vector<std::string> KERNEL_FUNCTIONS;
|
||||
|
||||
KERNEL_FUNCTIONS.push_back(
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " int *ptr = NULL;"
|
||||
NL
|
||||
NL " results[tid] = (ptr == NULL);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
KERNEL_FUNCTIONS.push_back(
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " int *ptr = NULL;"
|
||||
NL " __global int *gptr = NULL;"
|
||||
NL
|
||||
NL " results[tid] = (ptr == gptr);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
KERNEL_FUNCTIONS.push_back(
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " int *ptr = NULL;"
|
||||
NL " __local int *lptr = NULL;"
|
||||
NL
|
||||
NL " results[tid] = (ptr == lptr);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
KERNEL_FUNCTIONS.push_back(
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " int *ptr = NULL;"
|
||||
NL " __private int *pptr = NULL;"
|
||||
NL
|
||||
NL " results[tid] = (ptr == pptr);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
KERNEL_FUNCTIONS.push_back(
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " int *ptr = NULL;"
|
||||
NL " __local int *lptr = NULL;"
|
||||
NL " __global int *gptr = NULL;"
|
||||
NL
|
||||
NL " ptr = lptr;"
|
||||
NL
|
||||
NL " results[tid] = (gptr == ptr) && (lptr == ptr);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
KERNEL_FUNCTIONS.push_back(
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " int some_value = 7;"
|
||||
NL " int *ptr = NULL;"
|
||||
NL " __private int *pptr = &some_value;"
|
||||
NL
|
||||
NL " results[tid] = (ptr != pptr);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
KERNEL_FUNCTIONS.push_back(
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " __local int some_value;"
|
||||
NL " some_value = 7;"
|
||||
NL " int *ptr = NULL;"
|
||||
NL " __local int *lptr = &some_value;"
|
||||
NL
|
||||
NL " results[tid] = (ptr != lptr);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
KERNEL_FUNCTIONS.push_back(
|
||||
NL "__global int some_value = 7;"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " int *ptr = NULL;"
|
||||
NL " __global int *gptr = &some_value;"
|
||||
NL
|
||||
NL " results[tid] = (ptr != gptr);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
KERNEL_FUNCTIONS.push_back(
|
||||
NL "__global int arr[5] = { 0, 1, 2, 3, 4 };"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " int *ptr = &arr[1];"
|
||||
NL " __global int *gptr = &arr[3];"
|
||||
NL
|
||||
NL " results[tid] = (gptr >= ptr);"
|
||||
NL "}"
|
||||
NL
|
||||
);
|
||||
|
||||
CBasicTest test(KERNEL_FUNCTIONS);
|
||||
|
||||
return test.Execute(deviceID, context, queue, num_elements);
|
||||
}
|
||||
106
test_conformance/generic_address_space/main.cpp
Normal file
106
test_conformance/generic_address_space/main.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
//
|
||||
// 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/testHarness.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// basic tests
|
||||
extern int test_function_params_get_fence(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_function_params_to_address_space(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_variable_get_fence(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_variable_to_address_space(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_casting(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_conditional_casting(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_chain_casting(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_ternary_operator_casting(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_language_struct(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_language_union(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_multiple_calls_same_function(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_compare_pointers(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
// advanced tests
|
||||
extern int test_library_function(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_generic_variable_volatile(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_generic_variable_const(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_generic_variable_gentype(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_builtin_functions(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_generic_advanced_casting(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_generic_ptr_to_host_mem(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_max_number_of_params(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
|
||||
basefn basefn_list[] = {
|
||||
// basic tests
|
||||
test_function_params_get_fence,
|
||||
test_function_params_to_address_space,
|
||||
test_variable_get_fence,
|
||||
test_variable_to_address_space,
|
||||
test_casting,
|
||||
test_conditional_casting,
|
||||
test_chain_casting,
|
||||
test_ternary_operator_casting,
|
||||
test_language_struct,
|
||||
test_language_union,
|
||||
test_multiple_calls_same_function,
|
||||
test_compare_pointers,
|
||||
// advanced tests
|
||||
test_library_function,
|
||||
test_generic_variable_volatile,
|
||||
test_generic_variable_const,
|
||||
test_generic_variable_gentype,
|
||||
test_builtin_functions,
|
||||
test_generic_advanced_casting,
|
||||
test_generic_ptr_to_host_mem,
|
||||
test_max_number_of_params,
|
||||
};
|
||||
|
||||
const char *basefn_names[] = {
|
||||
//basic tests
|
||||
"function_get_fence",
|
||||
"function_to_address_space",
|
||||
"variable_get_fence",
|
||||
"variable_to_address_space",
|
||||
"casting",
|
||||
"conditional_casting",
|
||||
"chain_casting",
|
||||
"ternary_operator_casting",
|
||||
"language_struct",
|
||||
"language_union",
|
||||
"multiple_calls_same_function",
|
||||
"compare_pointers",
|
||||
// advanced tests
|
||||
"library_function",
|
||||
"generic_variable_volatile",
|
||||
"generic_variable_const",
|
||||
"generic_variable_gentype",
|
||||
"builtin_functions",
|
||||
"generic_advanced_casting",
|
||||
"generic_ptr_to_host_mem",
|
||||
"max_number_of_params",
|
||||
};
|
||||
|
||||
ct_assert((sizeof(basefn_names) / sizeof(basefn_names[0])) == (sizeof(basefn_list) / sizeof(basefn_list[0])));
|
||||
|
||||
int num_fns = sizeof(basefn_names) / sizeof(char *);
|
||||
|
||||
/*
|
||||
Generic Address Space
|
||||
Tests for unnamed generic address space. This feature allows developers to create single generic functions
|
||||
that are able to operate on pointers from various address spaces instead of writing separate instances for every combination.
|
||||
*/
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
return runTestHarness(argc, argv, num_fns, basefn_list, basefn_names, false, false, NULL);
|
||||
}
|
||||
173
test_conformance/generic_address_space/stress_tests.cpp
Normal file
173
test_conformance/generic_address_space/stress_tests.cpp
Normal file
@@ -0,0 +1,173 @@
|
||||
//
|
||||
// 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/testHarness.h"
|
||||
#include "../../test_common/harness/typeWrappers.h"
|
||||
#include "../../test_common/harness/mt19937.h"
|
||||
#include "base.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
class CStressTest : public CTest {
|
||||
public:
|
||||
CStressTest(const std::vector<std::string>& kernel) : CTest(), _kernels(kernel) {
|
||||
|
||||
}
|
||||
|
||||
CStressTest(const std::string& kernel) : CTest(), _kernels(1, kernel) {
|
||||
|
||||
}
|
||||
|
||||
int ExecuteSubcase(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements, const std::string& src) {
|
||||
cl_int error;
|
||||
|
||||
clProgramWrapper program;
|
||||
clKernelWrapper kernel;
|
||||
|
||||
const char *srcPtr = src.c_str();
|
||||
|
||||
if (create_single_kernel_helper_with_build_options(context, &program, &kernel, 1, &srcPtr, "testKernel", "-cl-std=CL2.0")) {
|
||||
log_error("create_single_kernel_helper failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t bufferSize = num_elements * sizeof(cl_uint);
|
||||
clMemWrapper buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, bufferSize, NULL, &error);
|
||||
test_error(error, "clCreateBuffer failed");
|
||||
|
||||
error = clSetKernelArg(kernel, 0, sizeof(buffer), &buffer);
|
||||
test_error(error, "clSetKernelArg failed");
|
||||
|
||||
size_t globalWorkGroupSize = num_elements;
|
||||
size_t localWorkGroupSize = 0;
|
||||
error = get_max_common_work_group_size(context, kernel, globalWorkGroupSize, &localWorkGroupSize);
|
||||
test_error(error, "Unable to get common work group size");
|
||||
|
||||
error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &globalWorkGroupSize, &localWorkGroupSize, 0, NULL, NULL);
|
||||
test_error(error, "clEnqueueNDRangeKernel failed");
|
||||
|
||||
// verify results
|
||||
std::vector<cl_uint> results(num_elements);
|
||||
|
||||
error = clEnqueueReadBuffer(queue, buffer, CL_TRUE, 0, bufferSize, &results[0], 0, NULL, NULL);
|
||||
test_error(error, "clEnqueueReadBuffer failed");
|
||||
|
||||
size_t passCount = std::count(results.begin(), results.end(), 1);
|
||||
if (passCount != results.size()) {
|
||||
std::vector<cl_uint>::iterator iter = std::find(results.begin(), results.end(), 0);
|
||||
log_error("Verification on device failed at index %ld\n", std::distance(results.begin(), iter));
|
||||
log_error("%ld out of %ld failed\n", (results.size()-passCount), results.size());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
int Execute(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) {
|
||||
cl_int result = CL_SUCCESS;
|
||||
|
||||
for (std::vector<std::string>::const_iterator it = _kernels.begin(); it != _kernels.end(); ++it) {
|
||||
log_info("Executing subcase #%ld out of %ld\n", (it - _kernels.begin() + 1), _kernels.size());
|
||||
|
||||
result |= ExecuteSubcase(deviceID, context, queue, num_elements, *it);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::vector<std::string> _kernels;
|
||||
};
|
||||
|
||||
int test_max_number_of_params(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) {
|
||||
cl_int error;
|
||||
|
||||
size_t deviceMaxParameterSize;
|
||||
error = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_PARAMETER_SIZE, sizeof(deviceMaxParameterSize), &deviceMaxParameterSize, NULL);
|
||||
test_error(error, "clGetDeviceInfo failed");
|
||||
|
||||
size_t deviceAddressBits;
|
||||
error = clGetDeviceInfo(deviceID, CL_DEVICE_ADDRESS_BITS, sizeof(deviceAddressBits), &deviceAddressBits, NULL);
|
||||
test_error(error, "clGetDeviceInfo failed");
|
||||
|
||||
size_t maxParams = deviceMaxParameterSize / (deviceAddressBits / 8);
|
||||
|
||||
const std::string KERNEL_FUNCTION_TEMPLATE[] = {
|
||||
common::CONFORMANCE_VERIFY_FENCE +
|
||||
NL
|
||||
NL "bool helperFunction(int *ptr0 ",
|
||||
// the rest of arguments goes here
|
||||
") {"
|
||||
NL " // check first pointer only"
|
||||
NL " if (!isFenceValid(get_fence(ptr0)))"
|
||||
NL " return false;"
|
||||
NL
|
||||
NL " return true;"
|
||||
NL "}"
|
||||
NL
|
||||
NL "__kernel void testKernel(__global uint *results) {"
|
||||
NL " uint tid = get_global_id(0);"
|
||||
NL
|
||||
NL " __global int * gptr;"
|
||||
NL " __local int * lptr;"
|
||||
NL " __private int * pptr;"
|
||||
NL
|
||||
NL " size_t failures = 0;"
|
||||
NL
|
||||
NL,
|
||||
// the function body goes here
|
||||
NL
|
||||
NL " results[tid] = (failures == 0);"
|
||||
NL "}"
|
||||
NL
|
||||
};
|
||||
|
||||
std::ostringstream type_params;
|
||||
std::ostringstream function_calls;
|
||||
|
||||
for (size_t i = 0; i < maxParams; i++) {
|
||||
type_params << ", int *ptr" << i+1;
|
||||
}
|
||||
|
||||
// use pseudo random generator to shuffle params
|
||||
MTdata d = init_genrand(gRandomSeed);
|
||||
if (!d)
|
||||
return -1;
|
||||
|
||||
std::string pointers[] = { "gptr", "lptr", "pptr" };
|
||||
|
||||
size_t totalCalls = maxParams / 2;
|
||||
for (size_t i = 0; i < totalCalls; i++) {
|
||||
function_calls << "\tif (!helperFunction(gptr";
|
||||
|
||||
for (size_t j = 0; j < maxParams; j++) {
|
||||
function_calls << ", " << pointers[genrand_int32(d)%3];
|
||||
}
|
||||
|
||||
function_calls << ")) failures++;" << NL;
|
||||
}
|
||||
|
||||
free_mtdata(d);
|
||||
d = NULL;
|
||||
|
||||
const std::string KERNEL_FUNCTION = KERNEL_FUNCTION_TEMPLATE[0] + type_params.str() + KERNEL_FUNCTION_TEMPLATE[1] + function_calls.str() + KERNEL_FUNCTION_TEMPLATE[2];
|
||||
|
||||
CStressTest test(KERNEL_FUNCTION);
|
||||
|
||||
return test.Execute(deviceID, context, queue, num_elements);
|
||||
}
|
||||
Reference in New Issue
Block a user