Files
OpenCL-CTS/test_conformance/spirv_new/test_op_copy_object.cpp
ellnor01 617e7cb233 Re-enabling narrowing errors (#1144)
Fixes narrowing conversion build errors in test_common

Removing disable of narrowing errors in main CMakeLists.txt
and moving it down to specific test_conformance suite's 
CMakeLists.txt where there are many more build errors revealed
from this fix. 

Fixes a few simple issues under test_conformance in the process.

Contributes #787

Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>

---------

Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>
2024-10-08 09:54:32 -07:00

147 lines
5.1 KiB
C++

//
// Copyright (c) 2016-2023 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 "types.hpp"
template<typename T>
int test_copy(cl_device_id deviceID, cl_context context,
cl_command_queue queue, const char *name,
std::vector<T> &results,
bool (*notEqual)(const T&, const T&) = isNotEqual<T>)
{
if(std::string(name).find("double") != std::string::npos) {
if(!is_extension_available(deviceID, "cl_khr_fp64")) {
log_info("Extension cl_khr_fp64 not supported; skipping double tests.\n");
return 0;
}
}
clProgramWrapper prog;
cl_int err = get_program_with_il(prog, deviceID, context, name);
SPIRV_CHECK_ERROR(err, "Failed to build program");
clKernelWrapper kernel = clCreateKernel(prog, name, &err);
SPIRV_CHECK_ERROR(err, "Failed to create kernel");
int num = (int)results.size();
size_t bytes = num * sizeof(T);
clMemWrapper mem = clCreateBuffer(context, CL_MEM_READ_WRITE, bytes, NULL, &err);
SPIRV_CHECK_ERROR(err, "Failed to create buffer");
err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &mem);
SPIRV_CHECK_ERROR(err, "Failed to set kernel argument");
size_t global = num;
err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, NULL, 0, NULL, NULL);
SPIRV_CHECK_ERROR(err, "Failed to enqueue kernel");
std::vector<T> host(num);
err = clEnqueueReadBuffer(queue, mem, CL_TRUE, 0, bytes, &host[0], 0, NULL, NULL);
SPIRV_CHECK_ERROR(err, "Failed to copy from cl_buffer");
for (int i = 0; i < num; i++) {
if (notEqual(host[i], results[i])) {
log_error("Values do not match at location %d\n", i);
return -1;
}
}
return 0;
}
#define TEST_COPY(NAME, type, value) \
TEST_SPIRV_FUNC(op_copy_##NAME##_simple) \
{ \
std::vector<type> results(1024, (type)value); \
return test_copy(deviceID, context, queue, \
"copy_" #NAME "_simple", \
results); \
} \
// Integer tests
TEST_COPY(int , cl_int , 123 )
TEST_COPY(uint , cl_uint , 54321 )
TEST_COPY(char , cl_char , 20 )
TEST_COPY(uchar , cl_uchar , 19 )
TEST_COPY(ushort, cl_ushort, 65000 )
TEST_COPY(long , cl_long , 34359738368L )
TEST_COPY(ulong , cl_ulong , 9223372036854775810UL)
#ifdef __GNUC__
// std::vector<cl_short> is causing compilation errors on GCC 5.3 (works on gcc 4.8)
// Needs further investigation
TEST_COPY(short , int16_t , 32000 )
#else
TEST_COPY(short , cl_short , 32000 )
#endif
// Float tests
TEST_COPY(float , cl_float , 3.1415927 )
TEST_COPY(double , cl_double , 3.141592653589793)
TEST_SPIRV_FUNC(op_copy_int4_simple)
{
cl_int4 value = { { 123, 122, 121, 119 } };
std::vector<cl_int4> results(256, value);
return test_copy(deviceID, context, queue, "copy_int4_simple", results);
}
TEST_SPIRV_FUNC(op_copy_int3_simple)
{
cl_int3 value = { { 123, 122, 121, 0 } };
std::vector<cl_int3> results(256, value);
return test_copy(deviceID, context, queue, "copy_int3_simple",
results, isVectorNotEqual<cl_int3, 3>);
}
TEST_SPIRV_FUNC(op_copy_struct_int_float_simple)
{
AbstractStruct2<int, float> value = {1024, 3.1415};
std::vector<AbstractStruct2<int, float> > results(256, value);
return test_copy(deviceID, context, queue, "copy_struct_int_float_simple", results);
}
TEST_SPIRV_FUNC(op_copy_struct_int_char_simple)
{
AbstractStruct2<int, char> value = { 2100483600, (char)128 };
std::vector<AbstractStruct2<int, char> > results(256, value);
return test_copy(deviceID, context, queue, "copy_struct_int_char_simple", results);
}
TEST_SPIRV_FUNC(op_copy_struct_struct_simple)
{
typedef AbstractStruct2<int, char> CustomType1;
typedef AbstractStruct2<cl_int2, CustomType1> CustomType2;
CustomType1 value1 = { 2100483600, (char)128 };
cl_int2 intvals = { { 2100480000, 2100480000 } };
CustomType2 value2 = {intvals, value1};
std::vector<CustomType2> results(256, value2);
return test_copy(deviceID, context, queue, "copy_struct_struct_simple", results);
}
TEST_SPIRV_FUNC(op_copy_half_simple)
{
PASSIVE_REQUIRE_FP16_SUPPORT(deviceID);
std::vector<cl_float> results(1024, 3.25);
return test_copy(deviceID, context, queue,
"copy_half_simple",
results);
}