mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-21 14:59:02 +00:00
Initial open source release of OpenCL 2.2 CTS.
This commit is contained in:
134
test_conformance/clcpp/utils_common/errors.hpp
Normal file
134
test_conformance/clcpp/utils_common/errors.hpp
Normal file
@@ -0,0 +1,134 @@
|
||||
//
|
||||
// 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 TEST_CONFORMANCE_CLCPP_UTILS_COMMON_ERRORS_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_COMMON_ERRORS_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../../../test_common/harness/errorHelpers.h"
|
||||
|
||||
// ------------- Check OpenCL error helpers (marcos) -----------------
|
||||
|
||||
std::string get_cl_error_string(cl_int error)
|
||||
{
|
||||
#define CASE_CL_ERROR(x) case x: return #x;
|
||||
switch (error)
|
||||
{
|
||||
CASE_CL_ERROR(CL_SUCCESS)
|
||||
CASE_CL_ERROR(CL_DEVICE_NOT_FOUND)
|
||||
CASE_CL_ERROR(CL_DEVICE_NOT_AVAILABLE)
|
||||
CASE_CL_ERROR(CL_COMPILER_NOT_AVAILABLE)
|
||||
CASE_CL_ERROR(CL_MEM_OBJECT_ALLOCATION_FAILURE)
|
||||
CASE_CL_ERROR(CL_OUT_OF_RESOURCES)
|
||||
CASE_CL_ERROR(CL_OUT_OF_HOST_MEMORY)
|
||||
CASE_CL_ERROR(CL_PROFILING_INFO_NOT_AVAILABLE)
|
||||
CASE_CL_ERROR(CL_MEM_COPY_OVERLAP)
|
||||
CASE_CL_ERROR(CL_IMAGE_FORMAT_MISMATCH)
|
||||
CASE_CL_ERROR(CL_IMAGE_FORMAT_NOT_SUPPORTED)
|
||||
CASE_CL_ERROR(CL_BUILD_PROGRAM_FAILURE)
|
||||
CASE_CL_ERROR(CL_MAP_FAILURE)
|
||||
CASE_CL_ERROR(CL_MISALIGNED_SUB_BUFFER_OFFSET)
|
||||
CASE_CL_ERROR(CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST)
|
||||
CASE_CL_ERROR(CL_COMPILE_PROGRAM_FAILURE)
|
||||
CASE_CL_ERROR(CL_LINKER_NOT_AVAILABLE)
|
||||
CASE_CL_ERROR(CL_LINK_PROGRAM_FAILURE)
|
||||
CASE_CL_ERROR(CL_DEVICE_PARTITION_FAILED)
|
||||
CASE_CL_ERROR(CL_KERNEL_ARG_INFO_NOT_AVAILABLE)
|
||||
|
||||
CASE_CL_ERROR(CL_INVALID_VALUE)
|
||||
CASE_CL_ERROR(CL_INVALID_DEVICE_TYPE)
|
||||
CASE_CL_ERROR(CL_INVALID_PLATFORM)
|
||||
CASE_CL_ERROR(CL_INVALID_DEVICE)
|
||||
CASE_CL_ERROR(CL_INVALID_CONTEXT)
|
||||
CASE_CL_ERROR(CL_INVALID_QUEUE_PROPERTIES)
|
||||
CASE_CL_ERROR(CL_INVALID_COMMAND_QUEUE)
|
||||
CASE_CL_ERROR(CL_INVALID_HOST_PTR)
|
||||
CASE_CL_ERROR(CL_INVALID_MEM_OBJECT)
|
||||
CASE_CL_ERROR(CL_INVALID_IMAGE_FORMAT_DESCRIPTOR)
|
||||
CASE_CL_ERROR(CL_INVALID_IMAGE_SIZE)
|
||||
CASE_CL_ERROR(CL_INVALID_SAMPLER)
|
||||
CASE_CL_ERROR(CL_INVALID_BINARY)
|
||||
CASE_CL_ERROR(CL_INVALID_BUILD_OPTIONS)
|
||||
CASE_CL_ERROR(CL_INVALID_PROGRAM)
|
||||
CASE_CL_ERROR(CL_INVALID_PROGRAM_EXECUTABLE)
|
||||
CASE_CL_ERROR(CL_INVALID_KERNEL_NAME)
|
||||
CASE_CL_ERROR(CL_INVALID_KERNEL_DEFINITION)
|
||||
CASE_CL_ERROR(CL_INVALID_KERNEL)
|
||||
CASE_CL_ERROR(CL_INVALID_ARG_INDEX)
|
||||
CASE_CL_ERROR(CL_INVALID_ARG_VALUE)
|
||||
CASE_CL_ERROR(CL_INVALID_ARG_SIZE)
|
||||
CASE_CL_ERROR(CL_INVALID_KERNEL_ARGS)
|
||||
CASE_CL_ERROR(CL_INVALID_WORK_DIMENSION)
|
||||
CASE_CL_ERROR(CL_INVALID_WORK_GROUP_SIZE)
|
||||
CASE_CL_ERROR(CL_INVALID_WORK_ITEM_SIZE)
|
||||
CASE_CL_ERROR(CL_INVALID_GLOBAL_OFFSET)
|
||||
CASE_CL_ERROR(CL_INVALID_EVENT_WAIT_LIST)
|
||||
CASE_CL_ERROR(CL_INVALID_EVENT)
|
||||
CASE_CL_ERROR(CL_INVALID_OPERATION)
|
||||
CASE_CL_ERROR(CL_INVALID_GL_OBJECT)
|
||||
CASE_CL_ERROR(CL_INVALID_BUFFER_SIZE)
|
||||
CASE_CL_ERROR(CL_INVALID_MIP_LEVEL)
|
||||
CASE_CL_ERROR(CL_INVALID_GLOBAL_WORK_SIZE)
|
||||
CASE_CL_ERROR(CL_INVALID_PROPERTY)
|
||||
CASE_CL_ERROR(CL_INVALID_IMAGE_DESCRIPTOR)
|
||||
CASE_CL_ERROR(CL_INVALID_COMPILER_OPTIONS)
|
||||
CASE_CL_ERROR(CL_INVALID_LINKER_OPTIONS)
|
||||
CASE_CL_ERROR(CL_INVALID_DEVICE_PARTITION_COUNT)
|
||||
CASE_CL_ERROR(CL_INVALID_PIPE_SIZE)
|
||||
CASE_CL_ERROR(CL_INVALID_DEVICE_QUEUE)
|
||||
CASE_CL_ERROR(CL_INVALID_SPEC_ID)
|
||||
CASE_CL_ERROR(CL_MAX_SIZE_RESTRICTION_EXCEEDED)
|
||||
default: return "(unknown error code)";
|
||||
}
|
||||
#undef CASE_CL_ERROR
|
||||
}
|
||||
|
||||
#define CHECK_ERROR(x) \
|
||||
if(x != CL_SUCCESS) \
|
||||
{ \
|
||||
log_error("ERROR: %d, file: %s, line: %d\n", x, __FILE__, __LINE__);\
|
||||
}
|
||||
#define CHECK_ERROR_MSG(x, ...) \
|
||||
if(x != CL_SUCCESS) \
|
||||
{ \
|
||||
log_error("ERROR: " __VA_ARGS__);\
|
||||
log_error("\n");\
|
||||
log_error("ERROR: %d, file: %s, line: %d\n", x, __FILE__, __LINE__);\
|
||||
}
|
||||
#define RETURN_ON_ERROR(x) \
|
||||
if(x != CL_SUCCESS) \
|
||||
{ \
|
||||
log_error("ERROR: %d, file: %s, line: %d\n", x, __FILE__, __LINE__);\
|
||||
return x;\
|
||||
}
|
||||
#define RETURN_ON_ERROR_MSG(x, ...) \
|
||||
if(x != CL_SUCCESS) \
|
||||
{ \
|
||||
log_error("ERROR: " __VA_ARGS__);\
|
||||
log_error("\n");\
|
||||
log_error("ERROR: %d, file: %s, line: %d\n", x, __FILE__, __LINE__);\
|
||||
return x;\
|
||||
}
|
||||
|
||||
#define RETURN_ON_CL_ERROR(x, cl_func_name) \
|
||||
if(x != CL_SUCCESS) \
|
||||
{ \
|
||||
log_error("ERROR: %s failed: %s (%d)\n", cl_func_name, get_cl_error_string(x).c_str(), x);\
|
||||
log_error("ERROR: %d, file: %s, line: %d\n", x, __FILE__, __LINE__);\
|
||||
return x;\
|
||||
}
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_TEST_ERRORS_HPP
|
||||
60
test_conformance/clcpp/utils_common/is_vector_type.hpp
Normal file
60
test_conformance/clcpp/utils_common/is_vector_type.hpp
Normal file
@@ -0,0 +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.
|
||||
//
|
||||
#ifndef TEST_CONFORMANCE_CLCPP_UTILS_COMMON_IS_VECTOR_TYPE_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_COMMON_IS_VECTOR_TYPE_HPP
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
// is_vector_type<Type>::value is true if Type is an OpenCL
|
||||
// vector type; otherwise - false.
|
||||
//
|
||||
// Examples:
|
||||
// * is_vector_type<cl_float>::value == false
|
||||
// * is_vector_type<cl_float4>::value == true
|
||||
template<class Type>
|
||||
struct is_vector_type
|
||||
{
|
||||
const static bool value = false;
|
||||
};
|
||||
|
||||
#define ADD_VECTOR_TYPE(Type, n) \
|
||||
template<> \
|
||||
struct is_vector_type<Type ## n> \
|
||||
{ \
|
||||
const static bool value = true; \
|
||||
};
|
||||
|
||||
#define ADD_VECTOR_TYPES(Type) \
|
||||
ADD_VECTOR_TYPE(Type, 2) \
|
||||
ADD_VECTOR_TYPE(Type, 4) \
|
||||
ADD_VECTOR_TYPE(Type, 8) \
|
||||
ADD_VECTOR_TYPE(Type, 16)
|
||||
|
||||
ADD_VECTOR_TYPES(cl_char)
|
||||
ADD_VECTOR_TYPES(cl_uchar)
|
||||
ADD_VECTOR_TYPES(cl_short)
|
||||
ADD_VECTOR_TYPES(cl_ushort)
|
||||
ADD_VECTOR_TYPES(cl_int)
|
||||
ADD_VECTOR_TYPES(cl_uint)
|
||||
ADD_VECTOR_TYPES(cl_long)
|
||||
ADD_VECTOR_TYPES(cl_ulong)
|
||||
ADD_VECTOR_TYPES(cl_float)
|
||||
ADD_VECTOR_TYPES(cl_double)
|
||||
|
||||
#undef ADD_VECTOR_TYPES
|
||||
#undef ADD_VECTOR_TYPE
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_COMMON_IS_VECTOR_TYPE_HPP
|
||||
50
test_conformance/clcpp/utils_common/kernel_helpers.hpp
Normal file
50
test_conformance/clcpp/utils_common/kernel_helpers.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// 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 TEST_CONFORMANCE_CLCPP_UTILS_COMMON_KERNEL_HELPERS_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_COMMON_KERNEL_HELPERS_HPP
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
// Creates a OpenCL C++/C program out_program and kernel out_kernel.
|
||||
int create_opencl_kernel(cl_context context,
|
||||
cl_program *out_program,
|
||||
cl_kernel *out_kernel,
|
||||
const char *source,
|
||||
const std::string& kernel_name,
|
||||
const std::string& build_options = "",
|
||||
const bool openclCXX = true)
|
||||
{
|
||||
return create_single_kernel_helper(
|
||||
context, out_program, out_kernel, 1, &source,
|
||||
kernel_name.c_str(), build_options.c_str(), openclCXX
|
||||
);
|
||||
}
|
||||
|
||||
int create_opencl_kernel(cl_context context,
|
||||
cl_program *out_program,
|
||||
cl_kernel *out_kernel,
|
||||
const std::string& source,
|
||||
const std::string& kernel_name,
|
||||
const std::string& build_options = "",
|
||||
const bool openclCXX = true)
|
||||
{
|
||||
return create_opencl_kernel(
|
||||
context, out_program, out_kernel,
|
||||
source.c_str(), kernel_name, build_options, openclCXX
|
||||
);
|
||||
}
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_COMMON_KERNEL_HELPERS_HPP
|
||||
65
test_conformance/clcpp/utils_common/make_vector_type.hpp
Normal file
65
test_conformance/clcpp/utils_common/make_vector_type.hpp
Normal file
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// 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 TEST_CONFORMANCE_CLCPP_UTILS_COMMON_MAKE_VECTOR_TYPE_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_COMMON_MAKE_VECTOR_TYPE_HPP
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
// Using scalar_type and i creates a type scalar_typei.
|
||||
//
|
||||
// Example:
|
||||
// * make_vector_type<cl_uint, 8>::type is cl_uint8
|
||||
// * make_vector_type<cl_uint, 1>::type is cl_uint
|
||||
template<class scalar_type, size_t i>
|
||||
struct make_vector_type
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
#define ADD_MAKE_VECTOR_TYPE(Type, n) \
|
||||
template<> \
|
||||
struct make_vector_type<Type, n> \
|
||||
{ \
|
||||
typedef Type ## n type; \
|
||||
};
|
||||
|
||||
#define ADD_MAKE_VECTOR_TYPES(Type) \
|
||||
template<> \
|
||||
struct make_vector_type<Type, 1> \
|
||||
{ \
|
||||
typedef Type type; \
|
||||
}; \
|
||||
ADD_MAKE_VECTOR_TYPE(Type, 2) \
|
||||
ADD_MAKE_VECTOR_TYPE(Type, 3) \
|
||||
ADD_MAKE_VECTOR_TYPE(Type, 4) \
|
||||
ADD_MAKE_VECTOR_TYPE(Type, 8) \
|
||||
ADD_MAKE_VECTOR_TYPE(Type, 16)
|
||||
|
||||
ADD_MAKE_VECTOR_TYPES(cl_char)
|
||||
ADD_MAKE_VECTOR_TYPES(cl_uchar)
|
||||
ADD_MAKE_VECTOR_TYPES(cl_short)
|
||||
ADD_MAKE_VECTOR_TYPES(cl_ushort)
|
||||
ADD_MAKE_VECTOR_TYPES(cl_int)
|
||||
ADD_MAKE_VECTOR_TYPES(cl_uint)
|
||||
ADD_MAKE_VECTOR_TYPES(cl_long)
|
||||
ADD_MAKE_VECTOR_TYPES(cl_ulong)
|
||||
ADD_MAKE_VECTOR_TYPES(cl_float)
|
||||
ADD_MAKE_VECTOR_TYPES(cl_double)
|
||||
|
||||
#undef ADD_MAKE_VECTOR_TYPES
|
||||
#undef ADD_MAKE_VECTOR_TYPE
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_COMMON_MAKE_VECTOR_TYPE_HPP
|
||||
64
test_conformance/clcpp/utils_common/scalar_type.hpp
Normal file
64
test_conformance/clcpp/utils_common/scalar_type.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// 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 TEST_CONFORMANCE_CLCPP_UTILS_COMMON_SCALAR_TYPE_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_COMMON_SCALAR_TYPE_HPP
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
// scalar_type<Type>::type returns scalar type of Type.
|
||||
//
|
||||
// Examples:
|
||||
// * scalar_type<cl_float>::type is cl_float
|
||||
// * scalar_type<cl_float4>::types is cl_float
|
||||
template<class Type>
|
||||
struct scalar_type
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
#define ADD_VECTOR_TYPE(Type, n) \
|
||||
template<> \
|
||||
struct scalar_type<Type ## n> \
|
||||
{ \
|
||||
typedef Type type; \
|
||||
};
|
||||
|
||||
#define ADD_VECTOR_TYPES(Type) \
|
||||
template<> \
|
||||
struct scalar_type<Type> \
|
||||
{ \
|
||||
typedef Type type; \
|
||||
}; \
|
||||
ADD_VECTOR_TYPE(Type, 2) \
|
||||
ADD_VECTOR_TYPE(Type, 4) \
|
||||
ADD_VECTOR_TYPE(Type, 8) \
|
||||
ADD_VECTOR_TYPE(Type, 16)
|
||||
|
||||
ADD_VECTOR_TYPES(cl_char)
|
||||
ADD_VECTOR_TYPES(cl_uchar)
|
||||
ADD_VECTOR_TYPES(cl_short)
|
||||
ADD_VECTOR_TYPES(cl_ushort)
|
||||
ADD_VECTOR_TYPES(cl_int)
|
||||
ADD_VECTOR_TYPES(cl_uint)
|
||||
ADD_VECTOR_TYPES(cl_long)
|
||||
ADD_VECTOR_TYPES(cl_ulong)
|
||||
ADD_VECTOR_TYPES(cl_float)
|
||||
ADD_VECTOR_TYPES(cl_double)
|
||||
|
||||
#undef ADD_VECTOR_TYPES
|
||||
#undef ADD_VECTOR_TYPE
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_COMMON_SCALAR_TYPE_HPP
|
||||
70
test_conformance/clcpp/utils_common/string.hpp
Normal file
70
test_conformance/clcpp/utils_common/string.hpp
Normal file
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// 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 TEST_CONFORMANCE_CLCPP_UTILS_COMMON_STRING_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_COMMON_STRING_HPP
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <type_traits>
|
||||
|
||||
#include "is_vector_type.hpp"
|
||||
#include "scalar_type.hpp"
|
||||
#include "type_name.hpp"
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
|
||||
template<class type>
|
||||
std::string format_value(const type& value,
|
||||
typename std::enable_if<is_vector_type<type>::value>::type* = 0)
|
||||
{
|
||||
std::stringstream s;
|
||||
s << type_name<type>() << "{ ";
|
||||
s << std::scientific << std::setprecision(6);
|
||||
for (size_t j = 0; j < vector_size<type>::value; j++)
|
||||
{
|
||||
if (j > 0)
|
||||
s << ", ";
|
||||
s << value.s[j];
|
||||
}
|
||||
s << " }";
|
||||
return s.str();
|
||||
}
|
||||
|
||||
template<class type>
|
||||
std::string format_value(const type& value,
|
||||
typename std::enable_if<!is_vector_type<type>::value>::type* = 0)
|
||||
{
|
||||
std::stringstream s;
|
||||
s << type_name<type>() << "{ ";
|
||||
s << std::scientific << std::setprecision(6);
|
||||
s << value;
|
||||
s << " }";
|
||||
return s.str();
|
||||
}
|
||||
|
||||
void replace_all(std::string& str, const std::string& from, const std::string& to)
|
||||
{
|
||||
size_t start_pos = 0;
|
||||
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
|
||||
str.replace(start_pos, from.length(), to);
|
||||
start_pos += to.length();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_COMMON_STRING_HPP
|
||||
65
test_conformance/clcpp/utils_common/type_name.hpp
Normal file
65
test_conformance/clcpp/utils_common/type_name.hpp
Normal file
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// 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 TEST_CONFORMANCE_CLCPP_UTILS_COMMON_TYPE_NAME_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_COMMON_TYPE_NAME_HPP
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
// Returns type name (in OpenCL device).
|
||||
// cl_uint - "uint", cl_float2 -> "float2"
|
||||
template<class Type>
|
||||
std::string type_name()
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
#define ADD_TYPE_NAME(Type, str) \
|
||||
template<> \
|
||||
std::string type_name<Type>() \
|
||||
{ \
|
||||
return #str; \
|
||||
}
|
||||
|
||||
#define ADD_TYPE_NAME2(Type) \
|
||||
ADD_TYPE_NAME(cl_ ## Type, Type)
|
||||
|
||||
#define ADD_TYPE_NAME3(Type, x) \
|
||||
ADD_TYPE_NAME2(Type ## x)
|
||||
|
||||
#define ADD_TYPE_NAMES(Type) \
|
||||
ADD_TYPE_NAME2(Type) \
|
||||
ADD_TYPE_NAME3(Type, 2) \
|
||||
ADD_TYPE_NAME3(Type, 4) \
|
||||
ADD_TYPE_NAME3(Type, 8) \
|
||||
ADD_TYPE_NAME3(Type, 16)
|
||||
|
||||
ADD_TYPE_NAMES(char)
|
||||
ADD_TYPE_NAMES(uchar)
|
||||
ADD_TYPE_NAMES(short)
|
||||
ADD_TYPE_NAMES(ushort)
|
||||
ADD_TYPE_NAMES(int)
|
||||
ADD_TYPE_NAMES(uint)
|
||||
ADD_TYPE_NAMES(long)
|
||||
ADD_TYPE_NAMES(ulong)
|
||||
ADD_TYPE_NAMES(float)
|
||||
ADD_TYPE_NAMES(double)
|
||||
|
||||
#undef ADD_TYPE_NAMES
|
||||
#undef ADD_TYPE_NAME3
|
||||
#undef ADD_TYPE_NAME2
|
||||
#undef ADD_TYPE_NAME
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_COMMON_TYPE_NAME_HPP
|
||||
106
test_conformance/clcpp/utils_common/type_supported.hpp
Normal file
106
test_conformance/clcpp/utils_common/type_supported.hpp
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.
|
||||
//
|
||||
#ifndef TEST_CONFORMANCE_CLCPP_UTILS_COMMON_TYPE_SUPPORTED_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_COMMON_TYPE_SUPPORTED_HPP
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
// Returns true if type is supported by device; otherwise - false;
|
||||
template<class Type>
|
||||
bool type_supported(cl_device_id device)
|
||||
{
|
||||
(void) device;
|
||||
return false;
|
||||
}
|
||||
|
||||
#define ADD_SUPPORTED_TYPE(Type) \
|
||||
template<> \
|
||||
bool type_supported<Type>(cl_device_id device) \
|
||||
{ \
|
||||
(void) device; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
ADD_SUPPORTED_TYPE(cl_char)
|
||||
ADD_SUPPORTED_TYPE(cl_uchar)
|
||||
ADD_SUPPORTED_TYPE(cl_short)
|
||||
ADD_SUPPORTED_TYPE(cl_ushort)
|
||||
ADD_SUPPORTED_TYPE(cl_int)
|
||||
ADD_SUPPORTED_TYPE(cl_uint)
|
||||
|
||||
// ulong
|
||||
template<>
|
||||
bool type_supported<cl_ulong>(cl_device_id device)
|
||||
{
|
||||
// long types do not have to be supported in EMBEDDED_PROFILE.
|
||||
char profile[128];
|
||||
int error;
|
||||
|
||||
error = clGetDeviceInfo(device, CL_DEVICE_PROFILE, sizeof(profile), (void *)&profile, NULL);
|
||||
if (error != CL_SUCCESS)
|
||||
{
|
||||
log_error("ERROR: clGetDeviceInfo failed with CL_DEVICE_PROFILE\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (std::strcmp(profile, "EMBEDDED_PROFILE") == 0)
|
||||
return is_extension_available(device, "cles_khr_int64");
|
||||
|
||||
return true;
|
||||
}
|
||||
// long
|
||||
template<>
|
||||
bool type_supported<cl_long>(cl_device_id device)
|
||||
{
|
||||
return type_supported<cl_ulong>(device);
|
||||
}
|
||||
ADD_SUPPORTED_TYPE(cl_float)
|
||||
// double
|
||||
template<>
|
||||
bool type_supported<cl_double>(cl_device_id device)
|
||||
{
|
||||
return is_extension_available(device, "cl_khr_fp64");
|
||||
}
|
||||
|
||||
#define ADD_SUPPORTED_VEC_TYPE1(Type, n) \
|
||||
template<> \
|
||||
bool type_supported<Type ## n>(cl_device_id device) \
|
||||
{ \
|
||||
return type_supported<Type>(device); \
|
||||
}
|
||||
|
||||
#define ADD_SUPPORTED_VEC_TYPE2(Type) \
|
||||
ADD_SUPPORTED_VEC_TYPE1(Type, 2) \
|
||||
ADD_SUPPORTED_VEC_TYPE1(Type, 4) \
|
||||
ADD_SUPPORTED_VEC_TYPE1(Type, 8) \
|
||||
ADD_SUPPORTED_VEC_TYPE1(Type, 16)
|
||||
|
||||
ADD_SUPPORTED_VEC_TYPE2(cl_char)
|
||||
ADD_SUPPORTED_VEC_TYPE2(cl_uchar)
|
||||
ADD_SUPPORTED_VEC_TYPE2(cl_short)
|
||||
ADD_SUPPORTED_VEC_TYPE2(cl_ushort)
|
||||
ADD_SUPPORTED_VEC_TYPE2(cl_int)
|
||||
ADD_SUPPORTED_VEC_TYPE2(cl_uint)
|
||||
ADD_SUPPORTED_VEC_TYPE2(cl_long)
|
||||
ADD_SUPPORTED_VEC_TYPE2(cl_ulong)
|
||||
ADD_SUPPORTED_VEC_TYPE2(cl_float)
|
||||
// ADD_SUPPORTED_VEC_TYPE2(cl_double)
|
||||
|
||||
#undef ADD_SUPPORTED_VEC_TYPE2
|
||||
#undef ADD_SUPPORTED_VEC_TYPE1
|
||||
#undef ADD_SUPPORTED_TYPE
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_COMMON_TYPE_SUPPORTED_HPP
|
||||
61
test_conformance/clcpp/utils_common/vector_size.hpp
Normal file
61
test_conformance/clcpp/utils_common/vector_size.hpp
Normal file
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// 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 TEST_CONFORMANCE_CLCPP_UTILS_COMMON_VECTOR_SIZE_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_COMMON_VECTOR_SIZE_HPP
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
// Returns 1 if Type is a scalar type; otherwise if it's a vector type,
|
||||
// it returns number of components in that Type.
|
||||
template<class Type>
|
||||
struct vector_size
|
||||
{
|
||||
const static size_t value = 1;
|
||||
};
|
||||
|
||||
#define ADD_VECTOR_SIZE_TYPE(Type, n) \
|
||||
template<> \
|
||||
struct vector_size<Type ## n> \
|
||||
{ \
|
||||
const static size_t value = n; \
|
||||
};
|
||||
|
||||
#define ADD_VECTOR_SIZE_TYPES(Type) \
|
||||
template<> \
|
||||
struct vector_size<Type> \
|
||||
{ \
|
||||
const static size_t value = 1; \
|
||||
}; \
|
||||
ADD_VECTOR_SIZE_TYPE(Type, 2) \
|
||||
ADD_VECTOR_SIZE_TYPE(Type, 4) \
|
||||
ADD_VECTOR_SIZE_TYPE(Type, 8) \
|
||||
ADD_VECTOR_SIZE_TYPE(Type, 16)
|
||||
|
||||
ADD_VECTOR_SIZE_TYPES(cl_char)
|
||||
ADD_VECTOR_SIZE_TYPES(cl_uchar)
|
||||
ADD_VECTOR_SIZE_TYPES(cl_short)
|
||||
ADD_VECTOR_SIZE_TYPES(cl_ushort)
|
||||
ADD_VECTOR_SIZE_TYPES(cl_int)
|
||||
ADD_VECTOR_SIZE_TYPES(cl_uint)
|
||||
ADD_VECTOR_SIZE_TYPES(cl_long)
|
||||
ADD_VECTOR_SIZE_TYPES(cl_ulong)
|
||||
ADD_VECTOR_SIZE_TYPES(cl_float)
|
||||
ADD_VECTOR_SIZE_TYPES(cl_double)
|
||||
|
||||
#undef ADD_VECTOR_SIZE_TYPES
|
||||
#undef ADD_VECTOR_SIZE_TYPE
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_COMMON_VECTOR_SIZE_HPP
|
||||
Reference in New Issue
Block a user