From a54db3509515de25bbff388ce33467abb5b9ca7a Mon Sep 17 00:00:00 2001 From: Stuart Adams Date: Wed, 24 Jun 2020 11:03:02 +0100 Subject: [PATCH 01/12] Implemented basic_tests/image --- sycl/test/basic_tests/image.cpp | 3 - sycl/test/basic_tests/image/image_read.cpp | 263 ++++++++++++++++ sycl/test/basic_tests/image/image_sample.cpp | 254 ++++++++++++++++ sycl/test/basic_tests/image/image_write.cpp | 284 ++++++++++++++++++ .../image_accessor_readsampler.cpp | 4 +- sycl/test/basic_tests/image_constructors.cpp | 3 - 6 files changed, 804 insertions(+), 7 deletions(-) create mode 100644 sycl/test/basic_tests/image/image_read.cpp create mode 100644 sycl/test/basic_tests/image/image_sample.cpp create mode 100644 sycl/test/basic_tests/image/image_write.cpp diff --git a/sycl/test/basic_tests/image.cpp b/sycl/test/basic_tests/image.cpp index 8b9b93ac360f3..42a5bcd516fbc 100644 --- a/sycl/test/basic_tests/image.cpp +++ b/sycl/test/basic_tests/image.cpp @@ -1,6 +1,3 @@ -// UNSUPPORTED: cuda -// CUDA cannot support SYCL 1.2.1 images. -// // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out // RUN: env SYCL_DEVICE_TYPE=HOST %t.out // RUN: %CPU_RUN_PLACEHOLDER %t.out diff --git a/sycl/test/basic_tests/image/image_read.cpp b/sycl/test/basic_tests/image/image_read.cpp new file mode 100644 index 0000000000000..b03d02ede0eb5 --- /dev/null +++ b/sycl/test/basic_tests/image/image_read.cpp @@ -0,0 +1,263 @@ +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out + +// RUN: env SYCL_DEVICE_TYPE=HOST %t.out +// RUN: %CPU_RUN_PLACEHOLDER %t.out +// RUN: %GPU_RUN_PLACEHOLDER %t.out +// RUN: %ACC_RUN_PLACEHOLDER %t.out + +/** + * Tests clamp_to_edge addressing mode with nearest and linear filtering modes + * on a 4x4 image. + * + * Expected addressing mode and filtering results are given by the algorithm in + * the OpenCL 1.2 specification, Section 8. Image Addressing and Filtering + * + * https://www.khronos.org/registry/OpenCL/specs/opencl-1.2.pdf#page=329 + * + * Confirmed to pass with -fsycl-targets=spir64-unknown-linux-sycldevice + * + * Enable sampled test with -DSAMPLED_TEST + * + * Enabled unsampled tests with -DUNSAMPLED_TEST + * + */ + +#include + +#include + +template class test_1d_class; +template class test_2d_class; +template class test_3d_class; + +namespace s = cl::sycl; + +template +bool test1d_coord(dataT *hostPtr, coordT coord, + dataT expectedColour) { + dataT resultData; + + s::default_selector selector; + + { // Scope everything to force destruction + s::image<1> image(hostPtr, s::image_channel_order::rgba, + channelType, s::range<1>{3}); + + s::buffer resultDataBuf(&resultData, + s::range<1>(1)); + + // Do the test by reading a single pixel from the image + s::queue myQueue(selector); + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = + image.get_access(cgh); + s::accessor + resultDataAcc(resultDataBuf, cgh); + + cgh.single_task>([=]() { + dataT RetColor = imageAcc.read(coord); + resultDataAcc[0] = RetColor; + }); + }); + } +#ifdef DEBUG_OUTPUT + std::cout << "Expected: " << expectedColour.r() << ", " << expectedColour.g() + << ", " << expectedColour.b() << ", " << expectedColour.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() + << ", " << resultData.b() << ", " << resultData.a() << "\n"; +#endif // DEBUG_OUTPUT + bool correct = true; + if (resultData.r() != expectedColour.r()) + correct = false; + if (resultData.g() != expectedColour.g()) + correct = false; + if (resultData.b() != expectedColour.b()) + correct = false; + if (resultData.a() != expectedColour.a()) + correct = false; + return correct; +} + +template +bool test2d_coord(dataT *hostPtr, coordT coord, + dataT expectedColour) { + dataT resultData; + + s::default_selector selector; + + { // Scope everything to force destruction + s::image<2> image(hostPtr, s::image_channel_order::rgba, + channelType, s::range<2>{3, 3}); + + s::buffer resultDataBuf(&resultData, + s::range<1>(1)); + + // Do the test by reading a single pixel from the image + s::queue myQueue(selector); + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = + image.get_access(cgh); + s::accessor + resultDataAcc(resultDataBuf, cgh); + + cgh.single_task>([=]() { + dataT RetColor = imageAcc.read(coord); + resultDataAcc[0] = RetColor; + }); + }); + } +#ifdef DEBUG_OUTPUT + std::cout << "Got: " << resultData.r() << ", " << resultData.g() +#endif // DEBUG_OUTPUT + bool correct = true; + if (resultData.r() != expectedColour.r()) + correct = false; + if (resultData.g() != expectedColour.g()) + correct = false; + if (resultData.b() != expectedColour.b()) + correct = false; + if (resultData.a() != expectedColour.a()) + correct = false; + return correct; +} + +template +bool test3d_coord(dataT *hostPtr, coordT coord, + dataT expectedColour) { + dataT resultData; + + s::default_selector selector; + + { // Scope everything to force destruction + s::image<3> image(hostPtr, s::image_channel_order::rgba, + channelType, s::range<3>{3, 3, 3}); + + s::buffer resultDataBuf(&resultData, + s::range<1>(1)); + + // Do the test by reading a single pixel from the image + s::queue myQueue(selector); + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = + image.get_access(cgh); + s::accessor + resultDataAcc(resultDataBuf, cgh); + + cgh.single_task>([=]() { + dataT RetColor = imageAcc.read(coord); + resultDataAcc[0] = RetColor; + }); + }); + } +#ifdef DEBUG_OUTPUT + std::cout << "Expected: " << expectedColour.r() << ", " << expectedColour.g() + << ", " << expectedColour.b() << ", " << expectedColour.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() + << ", " << resultData.b() << ", " << resultData.a() << "\n"; +#endif // DEBUG_OUTPUT + bool correct = true; + if (resultData.r() != expectedColour.r()) + correct = false; + if (resultData.g() != expectedColour.g()) + correct = false; + if (resultData.b() != expectedColour.b()) + correct = false; + if (resultData.a() != expectedColour.a()) + correct = false; + return correct; +} + +template +bool test1d(coordT coord, dataT expectedResult) { + dataT hostPtr[3]; + for (int i = 0; i < 3; i++) + hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); + return test1d_coord(hostPtr, coord, expectedResult); +} + +template +bool test2d(coordT coord, dataT expectedResult) { + dataT hostPtr[9]; + for (int i = 0; i < 9; i++) + hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); + return test2d_coord(hostPtr, coord, expectedResult); +} + +template +bool test3d(coordT coord, dataT expectedResult) { + dataT hostPtr[27]; + for (int i = 0; i < 27; i++) + hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); + return test3d_coord(hostPtr, coord, expectedResult); +} + +template +bool test() { + bool passed = true; + + // 1d image tests + if (!test1d(0, dataT(0, 20, 40, 60))) + passed = false; + if (!test1d(1, dataT(1, 21, 41, 61))) + passed = false; + if (!test1d(2, dataT(2, 22, 42, 62))) + passed = false; + + // 2d image tests + if (!test2d(s::int2(0, 0), dataT(0, 20, 40, 60))) + passed = false; + if (!test2d(s::int2(1, 0), dataT(1, 21, 41, 61))) + passed = false; + if (!test2d(s::int2(0, 1), dataT(3, 23, 43, 63))) + passed = false; + if (!test2d(s::int2(1, 1), dataT(4, 24, 44, 64))) + passed = false; + + // 3d image tests + if (!test3d( + s::int4(0, 0, 0, 0), dataT(0, 20, 40, 60))) + passed = false; + if (!test3d( + s::int4(1, 0, 0, 0), dataT(1, 21, 41, 61))) + passed = false; + if (!test3d( + s::int4(0, 1, 0, 0), dataT(3, 23, 43, 63))) + passed = false; + if (!test3d( + s::int4(1, 1, 0, 0), dataT(4, 24, 44, 64))) + passed = false; + if (!test3d( + s::int4(1, 0, 1, 0), dataT(10, 30, 50, 70))) + passed = false; + if (!test3d( + s::int4(0, 1, 1, 0), dataT(12, 32, 52, 72))) + passed = false; + if (!test3d( + s::int4(1, 1, 1, 0), dataT(13, 33, 53, 73))) + passed = false; + + return passed; +} + +int main() { + + bool passed = true; + + // Half image + if(!test()) + passed = false; + + // Float image + if(!test()) + passed = false; + + // 32-bit signed integer image + if(!test()) + passed = false; + + // 32-bit unsigned integer image + if(!test()) + passed = false; + + return passed ? 0 : -1; +} diff --git a/sycl/test/basic_tests/image/image_sample.cpp b/sycl/test/basic_tests/image/image_sample.cpp new file mode 100644 index 0000000000000..fa3d5fb65c2cf --- /dev/null +++ b/sycl/test/basic_tests/image/image_sample.cpp @@ -0,0 +1,254 @@ +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out +// RUN: %CPU_RUN_PLACEHOLDER %t.out +// RUN: %GPU_RUN_PLACEHOLDER %t.out +// XFAIL: level0 +// "die: piextKernelSetArgSampler: not implemented" + +#include + +#include + +class test_1d_class; +class test_2d_class; +class test_3d_class; + +namespace s = cl::sycl; + +template +bool check_result(dataT resultData, dataT expectedData, float epsilon = 0.1) { + bool correct = true; + if (std::abs(resultData.r() - expectedData.r()) > epsilon) + correct = false; + if (std::abs(resultData.g() - expectedData.g()) > epsilon) + correct = false; + if (std::abs(resultData.b() - expectedData.b()) > epsilon) + correct = false; + if (std::abs(resultData.a() - expectedData.a()) > epsilon) + correct = false; +#ifdef DEBUG_OUTPUT + if (!correct) { + std::cout << "Expected: " << expectedData.r() << ", " << expectedData.g() + << ", " << expectedData.b() << ", " << expectedData.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() + << ", " << resultData.b() << ", " << resultData.a() << "\n"; + } +#endif // DEBUG_OUTPUT + return correct; +} + +template +bool test1d_coord(dataT *hostPtr, coordT coord, + dataT expectedColour) { + dataT resultData; + + s::sampler testSampler(s::coordinate_normalization_mode::unnormalized, + s::addressing_mode::clamp, + s::filtering_mode::linear); + + s::default_selector selector; + + { // Scope everything to force destruction + s::image<1> image(hostPtr, s::image_channel_order::rgba, + channelType, s::range<1>{3}); + + s::buffer resultDataBuf(&resultData, + s::range<1>(1)); + + // Do the test by reading a single pixel from the image + s::queue myQueue(selector); + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = + image.get_access(cgh); + s::accessor + resultDataAcc(resultDataBuf, cgh); + + cgh.single_task([=]() { + dataT RetColor = imageAcc.read(coord, testSampler); + resultDataAcc[0] = RetColor; + }); + }); + } + bool correct = check_result(resultData, expectedColour); +#ifdef DEBUG_OUTPUT + if (!correct) { + std::cout << "Coord: " << coord << "\n"; + } +#endif // DEBUG_OUTPUT + return correct; +} + +template +bool test2d_coord(dataT *hostPtr, coordT coord, + dataT expectedColour) { + dataT resultData; + + s::sampler testSampler(s::coordinate_normalization_mode::unnormalized, + s::addressing_mode::clamp, + s::filtering_mode::linear); + + s::default_selector selector; + + { // Scope everything to force destruction + s::image<2> image(hostPtr, s::image_channel_order::rgba, + channelType, s::range<2>{3, 3}); + + s::buffer resultDataBuf(&resultData, + s::range<1>(1)); + + // Do the test by reading a single pixel from the image + s::queue myQueue(selector); + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = + image.get_access(cgh); + s::accessor + resultDataAcc(resultDataBuf, cgh); + + cgh.single_task([=]() { + dataT RetColor = imageAcc.read(coord, testSampler); + resultDataAcc[0] = RetColor; + }); + }); + } + bool correct = check_result(resultData, expectedColour); +#ifdef DEBUG_OUTPUT + if (!correct) { + std::cout << "Coord: " << coord.x() << ", " << coord.y() << "\n"; + } +#endif // DEBUG_OUTPUT + return correct; +} + +template +bool test3d_coord(dataT *hostPtr, coordT coord, + dataT expectedColour) { + dataT resultData; + + s::sampler testSampler(s::coordinate_normalization_mode::unnormalized, + s::addressing_mode::clamp, + s::filtering_mode::linear); + + s::default_selector selector; + + { // Scope everything to force destruction + s::image<3> image(hostPtr, s::image_channel_order::rgba, + channelType, s::range<3>{3, 3, 3}); + + s::buffer resultDataBuf(&resultData, + s::range<1>(1)); + + // Do the test by reading a single pixel from the image + s::queue myQueue(selector); + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = + image.get_access(cgh); + s::accessor + resultDataAcc(resultDataBuf, cgh); + + cgh.single_task([=]() { + dataT RetColor = imageAcc.read(coord, testSampler); + resultDataAcc[0] = RetColor; + }); + }); + } + bool correct = check_result(resultData, expectedColour); +#ifdef DEBUG_OUTPUT + if (!correct) { + std::cout << "Coord: " << coord.x() << ", " << coord.y() << ", " << coord.z() << "\n"; + } +#endif // DEBUG_OUTPUT + return correct; +} + +template +bool test1d(coordT coord, dataT expectedResult) { + dataT hostPtr[3]; + for (int i = 0; i < 3; i++) + hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); + return test1d_coord(hostPtr, coord, expectedResult); +} + +template +bool test2d(coordT coord, dataT expectedResult) { + dataT hostPtr[9]; + for (int i = 0; i < 9; i++) + hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); + return test2d_coord(hostPtr, coord, expectedResult); +} + +template +bool test3d(coordT coord, dataT expectedResult) { + dataT hostPtr[27]; + for (int i = 0; i < 27; i++) + hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); + return test3d_coord(hostPtr, coord, expectedResult); +} + +int main() { + + bool passed = true; + + // 1d image read tests + if (!test1d( + 0.0f, s::float4(0, 10, 20, 30))) + passed = false; + if (!test1d( + 0.5f, s::float4(0, 20, 40, 60))) + passed = false; + if (!test1d( + 0.9f, s::float4(0.4, 20.4, 40.4, 60.4))) + passed = false; + + // 2d image read tests + if (!test2d( + s::float2(0.0f, 0.0f), s::float4(0, 5, 10, 15))) + passed = false; + if (!test2d( + s::float2(0.5f, 0.0f), s::float4(0, 10, 20, 30))) + passed = false; + if (!test2d( + s::float2(0.0f, 0.5f), s::float4(0, 10, 20, 30))) + passed = false; + if (!test2d( + s::float2(0.5f, 0.5f), s::float4(0, 20, 40, 60))) + passed = false; + if (!test2d( + s::float2(0.9f, 0.0f), s::float4(0.2, 10.2, 20.2, 30.2))) + passed = false; + if (!test2d( + s::float2(0.0f, 0.9f), s::float4(0.6, 10.6, 20.6, 30.6))) + passed = false; + if (!test2d( + s::float2(0.9f, 0.9f), s::float4(1.6, 21.6, 41.6, 61.6))) + passed = false; + + // 3d image read tests + if (!test3d( + s::float4(0.0f, 0.0f, 0.0f, 0.0f), s::float4(0, 2.5, 5, 7.5))) + passed = false; + if (!test3d( + s::float4(0.5f, 0.0f, 0.0f, 0.0f), s::float4(0, 5, 10, 15))) + passed = false; + if (!test3d( + s::float4(0.0f, 0.5f, 0.0f, 0.0f), s::float4(0, 5, 10, 15))) + passed = false; + if (!test3d( + s::float4(0.0f, 0.0f, 0.5f, 0.0f), s::float4(0, 5, 10, 15))) + passed = false; + if (!test3d( + s::float4(0.5f, 0.5f, 0.5f, 0.0f), s::float4(0, 20, 40, 60))) + passed = false; + if (!test3d( + s::float4(0.9f, 0.0f, 0.0f, 0.0f), s::float4(0.1, 5.1, 10.1, 15.1))) + passed = false; + if (!test3d( + s::float4(0.0f, 0.9f, 0.0f, 0.0f), s::float4(0.3, 5.3, 10.3, 15.3))) + passed = false; + if (!test3d( + s::float4(0.0f, 0.0f, 0.9f, 0.0f), s::float4(0.9, 5.9, 10.9, 15.9))) + passed = false; + if (!test3d( + s::float4(0.9f, 0.9f, 0.9f, 0.0f), s::float4(5.2, 25.2, 45.2, 65.2))) + passed = false; + + return passed ? 0 : -1; +} diff --git a/sycl/test/basic_tests/image/image_write.cpp b/sycl/test/basic_tests/image/image_write.cpp new file mode 100644 index 0000000000000..32a62844f09c8 --- /dev/null +++ b/sycl/test/basic_tests/image/image_write.cpp @@ -0,0 +1,284 @@ +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out +// RUN: env SYCL_DEVICE_TYPE=HOST %t.out +// RUN: %CPU_RUN_PLACEHOLDER %t.out +// RUN: %GPU_RUN_PLACEHOLDER %t.out +// RUN: %ACC_RUN_PLACEHOLDER %t.out + +/** + * Tests clamp_to_edge addressing mode with nearest and linear filtering modes + * on a 4x4 image. + * + * Expected addressing mode and filtering results are given by the algorithm in + * the OpenCL 1.2 specification, Section 8. Image Addressing and Filtering + * + * https://www.khronos.org/registry/OpenCL/specs/opencl-1.2.pdf#page=329 + * + * Confirmed to pass with -fsycl-targets=spir64-unknown-linux-sycldevice + * + * Enable sampled test with -DSAMPLED_TEST + * + * Enabled unsampled tests with -DUNSAMPLED_TEST + * + */ + +#include + +#include + +template class test_1d_write_class; +template class test_1d_read_class; +template class test_2d_write_class; +template class test_2d_read_class; +template class test_3d_write_class; +template class test_3d_read_class; + +namespace s = cl::sycl; + +template +bool test1d_coord(dataT *hostPtr, coordT coord, dataT colour) { + dataT resultData; + + s::default_selector selector; + + { // Scope everything to force destruction + s::image<1> image(hostPtr, s::image_channel_order::rgba, + channelType, s::range<1>{3}); + + s::buffer resultDataBuf(&resultData, + s::range<1>(1)); + + // Do the test by reading a single pixel from the image + s::queue myQueue(selector); + + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = image.get_access(cgh); + cgh.single_task>([=]() { + imageAcc.write(coord, colour); + }); + }); + + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = image.get_access(cgh); + s::accessor + resultDataAcc(resultDataBuf, cgh); + + cgh.single_task>([=]() { + dataT RetColor = imageAcc.read(coord); + resultDataAcc[0] = RetColor; + }); + }); + } +#ifdef DEBUG_OUTPUT + std::cout << "Expected: " << colour.r() << ", " << colour.g() + << ", " << colour.b() << ", " << colour.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() + << ", " << resultData.b() << ", " << resultData.a() << "\n"; +#endif // DEBUG_OUTPUT + bool correct = true; + if (resultData.r() != colour.r()) + correct = false; + if (resultData.g() != colour.g()) + correct = false; + if (resultData.b() != colour.b()) + correct = false; + if (resultData.a() != colour.a()) + correct = false; + return correct; +} + +template +bool test2d_coord(dataT *hostPtr, coordT coord, dataT colour) { + dataT resultData; + + s::default_selector selector; + + { // Scope everything to force destruction + s::image<2> image(hostPtr, s::image_channel_order::rgba, + channelType, s::range<2>{3, 3}); + + s::buffer resultDataBuf(&resultData, + s::range<1>(1)); + + // Do the test by reading a single pixel from the image + s::queue myQueue(selector); + + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = image.get_access(cgh); + + cgh.single_task>([=]() { + imageAcc.write(coord, colour); + }); + }); + + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = image.get_access(cgh); + s::accessor + resultDataAcc(resultDataBuf, cgh); + + cgh.single_task>([=]() { + dataT RetColor = imageAcc.read(coord); + resultDataAcc[0] = RetColor; + }); + }); + } +#ifdef DEBUG_OUTPUT + std::cout << "Expected: " << colour.r() << ", " << colour.g() + << ", " << colour.b() << ", " << colour.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() + << ", " << resultData.b() << ", " << resultData.a() << "\n"; +#endif // DEBUG_OUTPUT + bool correct = true; + if (resultData.r() != colour.r()) + correct = false; + if (resultData.g() != colour.g()) + correct = false; + if (resultData.b() != colour.b()) + correct = false; + if (resultData.a() != colour.a()) + correct = false; + return correct; +} + +template +bool test3d_coord(dataT *hostPtr, coordT coord, dataT colour) { + dataT resultData; + + s::default_selector selector; + + { // Scope everything to force destruction + s::image<3> image(hostPtr, s::image_channel_order::rgba, + channelType, s::range<3>{3, 3, 3}); + + s::buffer resultDataBuf(&resultData, + s::range<1>(1)); + + // Do the test by reading a single pixel from the image + s::queue myQueue(selector); + + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = image.get_access(cgh); + cgh.single_task>([=]() { + imageAcc.write(coord, colour); + }); + }); + + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = image.get_access(cgh); + s::accessor + resultDataAcc(resultDataBuf, cgh); + + cgh.single_task>([=]() { + dataT RetColor = imageAcc.read(coord); + resultDataAcc[0] = RetColor; + }); + }); + } +#ifdef DEBUG_OUTPUT + std::cout << "Expected: " << colour.r() << ", " << colour.g() + << ", " << colour.b() << ", " << colour.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() + << ", " << resultData.b() << ", " << resultData.a() << "\n"; +#endif // DEBUG_OUTPUT + bool correct = true; + if (resultData.r() != colour.r()) + correct = false; + if (resultData.g() != colour.g()) + correct = false; + if (resultData.b() != colour.b()) + correct = false; + if (resultData.a() != colour.a()) + correct = false; + return correct; +} + +template +bool test1d(coordT coord, dataT colour) { + dataT hostPtr[3]; + memset(&hostPtr, 0, sizeof(dataT) * 3); + return test1d_coord(hostPtr, coord, colour); +} + +template +bool test2d(coordT coord, dataT colour) { + dataT hostPtr[9]; + memset(&hostPtr, 0, sizeof(dataT) * 9); + return test2d_coord(hostPtr, coord, colour); +} + +template +bool test3d(coordT coord, dataT colour) { + dataT hostPtr[27]; + memset(&hostPtr, 0, sizeof(dataT) * 27); + return test3d_coord(hostPtr, coord, colour); +} + +template +bool test() { + bool passed = true; + + // 1d image tests + if (!test1d(0, dataT(0, 20, 40, 60))) + passed = false; + if (!test1d(1, dataT(1, 21, 41, 61))) + passed = false; + if (!test1d(2, dataT(2, 22, 42, 62))) + passed = false; + + // 2d image tests + if (!test2d(s::int2(0, 0), dataT(0, 20, 40, 60))) + passed = false; + if (!test2d(s::int2(1, 0), dataT(1, 21, 41, 61))) + passed = false; + if (!test2d(s::int2(0, 1), dataT(3, 23, 43, 63))) + passed = false; + if (!test2d(s::int2(1, 1), dataT(4, 24, 44, 64))) + passed = false; + + // 3d image tests + if (!test3d( + s::int4(0, 0, 0, 0), dataT(0, 20, 40, 60))) + passed = false; + if (!test3d( + s::int4(1, 0, 0, 0), dataT(1, 21, 41, 61))) + passed = false; + if (!test3d( + s::int4(0, 1, 0, 0), dataT(3, 23, 43, 63))) + passed = false; + if (!test3d( + s::int4(1, 1, 0, 0), dataT(4, 24, 44, 64))) + passed = false; + if (!test3d( + s::int4(1, 0, 1, 0), dataT(10, 30, 50, 70))) + passed = false; + if (!test3d( + s::int4(0, 1, 1, 0), dataT(12, 32, 52, 72))) + passed = false; + if (!test3d( + s::int4(1, 1, 1, 0), dataT(13, 33, 53, 73))) + passed = false; + + return passed; +} + +int main() { + + bool passed = true; + + // Half image + if(!test()) + passed = false; + + // Float image + if(!test()) + passed = false; + + // 32-bit signed integer image + if(!test()) + passed = false; + + // 32-bit unsigned integer image + if(!test()) + passed = false; + + return passed ? 0 : -1; +} diff --git a/sycl/test/basic_tests/image_accessor_readsampler.cpp b/sycl/test/basic_tests/image_accessor_readsampler.cpp index a15e55f2087cd..06240bda8f5a6 100644 --- a/sycl/test/basic_tests/image_accessor_readsampler.cpp +++ b/sycl/test/basic_tests/image_accessor_readsampler.cpp @@ -1,4 +1,5 @@ // UNSUPPORTED: cuda +// UNSUPPORTED: level0 // CUDA cannot support SYCL 1.2.1 images. // // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out @@ -23,7 +24,8 @@ namespace s = cl::sycl; -template class kernel_class; +template +class kernel_class; void validateReadData(s::cl_float4 ReadData, s::cl_float4 ExpectedColor, s::cl_int precision = 1) { diff --git a/sycl/test/basic_tests/image_constructors.cpp b/sycl/test/basic_tests/image_constructors.cpp index 337101ef97fde..8891393f9f1fe 100644 --- a/sycl/test/basic_tests/image_constructors.cpp +++ b/sycl/test/basic_tests/image_constructors.cpp @@ -1,6 +1,3 @@ -// UNSUPPORTED: cuda -// CUDA cannot support SYCL 1.2.1 images. -// // RUN: %clangxx %s -o %t1.out -lsycl -I %sycl_include // RUN: env SYCL_DEVICE_TYPE=HOST %t1.out // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t2.out From f12e71d7fcbde71a37310b6237bf0734a8dff7de Mon Sep 17 00:00:00 2001 From: Stuart Adams Date: Mon, 13 Jul 2020 14:36:45 +0100 Subject: [PATCH 02/12] Clang format --- sycl/test/basic_tests/image/image_write.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/sycl/test/basic_tests/image/image_write.cpp b/sycl/test/basic_tests/image/image_write.cpp index 32a62844f09c8..66b3b970eedb0 100644 --- a/sycl/test/basic_tests/image/image_write.cpp +++ b/sycl/test/basic_tests/image/image_write.cpp @@ -25,12 +25,18 @@ #include -template class test_1d_write_class; -template class test_1d_read_class; -template class test_2d_write_class; -template class test_2d_read_class; -template class test_3d_write_class; -template class test_3d_read_class; +template +class test_1d_write_class; +template +class test_1d_read_class; +template +class test_2d_write_class; +template +class test_2d_read_class; +template +class test_3d_write_class; +template +class test_3d_read_class; namespace s = cl::sycl; From 9855f64b6c884b93529d619f7b18a202f7b5fdc8 Mon Sep 17 00:00:00 2001 From: Stuart Adams Date: Mon, 13 Jul 2020 14:45:12 +0100 Subject: [PATCH 03/12] Clang format --- sycl/test/basic_tests/image/image_read.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sycl/test/basic_tests/image/image_read.cpp b/sycl/test/basic_tests/image/image_read.cpp index b03d02ede0eb5..449136e7d9047 100644 --- a/sycl/test/basic_tests/image/image_read.cpp +++ b/sycl/test/basic_tests/image/image_read.cpp @@ -26,9 +26,12 @@ #include -template class test_1d_class; -template class test_2d_class; -template class test_3d_class; +template +class test_1d_class; +template +class test_2d_class; +template +class test_3d_class; namespace s = cl::sycl; From fffd4a4da710990b3aa8bc3155ac7f3b6510e2e5 Mon Sep 17 00:00:00 2001 From: Stuart Adams Date: Mon, 13 Jul 2020 14:47:40 +0100 Subject: [PATCH 04/12] Clang format --- sycl/test/basic_tests/image/image_read.cpp | 12 ++++++------ sycl/test/basic_tests/image/image_write.cpp | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sycl/test/basic_tests/image/image_read.cpp b/sycl/test/basic_tests/image/image_read.cpp index 449136e7d9047..d06bbba65b141 100644 --- a/sycl/test/basic_tests/image/image_read.cpp +++ b/sycl/test/basic_tests/image/image_read.cpp @@ -112,7 +112,7 @@ bool test2d_coord(dataT *hostPtr, coordT coord, #ifdef DEBUG_OUTPUT std::cout << "Got: " << resultData.r() << ", " << resultData.g() #endif // DEBUG_OUTPUT - bool correct = true; + bool correct = true; if (resultData.r() != expectedColour.r()) correct = false; if (resultData.g() != expectedColour.g()) @@ -245,21 +245,21 @@ bool test() { int main() { bool passed = true; - + // Half image - if(!test()) + if (!test()) passed = false; // Float image - if(!test()) + if (!test()) passed = false; // 32-bit signed integer image - if(!test()) + if (!test()) passed = false; // 32-bit unsigned integer image - if(!test()) + if (!test()) passed = false; return passed ? 0 : -1; diff --git a/sycl/test/basic_tests/image/image_write.cpp b/sycl/test/basic_tests/image/image_write.cpp index 66b3b970eedb0..50a2e8131cbf0 100644 --- a/sycl/test/basic_tests/image/image_write.cpp +++ b/sycl/test/basic_tests/image/image_write.cpp @@ -55,7 +55,7 @@ bool test1d_coord(dataT *hostPtr, coordT coord, dataT colour) { // Do the test by reading a single pixel from the image s::queue myQueue(selector); - + myQueue.submit([&](s::handler &cgh) { auto imageAcc = image.get_access(cgh); cgh.single_task>([=]() { @@ -269,21 +269,21 @@ bool test() { int main() { bool passed = true; - + // Half image - if(!test()) + if (!test()) passed = false; // Float image - if(!test()) + if (!test()) passed = false; // 32-bit signed integer image - if(!test()) + if (!test()) passed = false; // 32-bit unsigned integer image - if(!test()) + if (!test()) passed = false; return passed ? 0 : -1; From 0b2635ccfa879dbb7da7252801a4e7b875c35632 Mon Sep 17 00:00:00 2001 From: Stuart Adams Date: Tue, 14 Jul 2020 12:31:54 +0100 Subject: [PATCH 05/12] Check for half support before running tests --- sycl/test/basic_tests/image/image_read.cpp | 110 +++++++++++--------- sycl/test/basic_tests/image/image_write.cpp | 92 ++++++++-------- 2 files changed, 103 insertions(+), 99 deletions(-) diff --git a/sycl/test/basic_tests/image/image_read.cpp b/sycl/test/basic_tests/image/image_read.cpp index d06bbba65b141..2f79b6d515582 100644 --- a/sycl/test/basic_tests/image/image_read.cpp +++ b/sycl/test/basic_tests/image/image_read.cpp @@ -36,12 +36,10 @@ class test_3d_class; namespace s = cl::sycl; template -bool test1d_coord(dataT *hostPtr, coordT coord, +bool test1d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT expectedColour) { dataT resultData; - s::default_selector selector; - { // Scope everything to force destruction s::image<1> image(hostPtr, s::image_channel_order::rgba, channelType, s::range<1>{3}); @@ -50,7 +48,6 @@ bool test1d_coord(dataT *hostPtr, coordT coord, s::range<1>(1)); // Do the test by reading a single pixel from the image - s::queue myQueue(selector); myQueue.submit([&](s::handler &cgh) { auto imageAcc = image.get_access(cgh); @@ -82,12 +79,10 @@ bool test1d_coord(dataT *hostPtr, coordT coord, } template -bool test2d_coord(dataT *hostPtr, coordT coord, +bool test2d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT expectedColour) { dataT resultData; - s::default_selector selector; - { // Scope everything to force destruction s::image<2> image(hostPtr, s::image_channel_order::rgba, channelType, s::range<2>{3, 3}); @@ -96,7 +91,6 @@ bool test2d_coord(dataT *hostPtr, coordT coord, s::range<1>(1)); // Do the test by reading a single pixel from the image - s::queue myQueue(selector); myQueue.submit([&](s::handler &cgh) { auto imageAcc = image.get_access(cgh); @@ -109,10 +103,12 @@ bool test2d_coord(dataT *hostPtr, coordT coord, }); }); } + #ifdef DEBUG_OUTPUT - std::cout << "Got: " << resultData.r() << ", " << resultData.g() + std::cout << "Got: " << resultData.r() << ", " << resultData.g(); #endif // DEBUG_OUTPUT - bool correct = true; + + bool correct = true; if (resultData.r() != expectedColour.r()) correct = false; if (resultData.g() != expectedColour.g()) @@ -125,12 +121,10 @@ bool test2d_coord(dataT *hostPtr, coordT coord, } template -bool test3d_coord(dataT *hostPtr, coordT coord, +bool test3d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT expectedColour) { dataT resultData; - s::default_selector selector; - { // Scope everything to force destruction s::image<3> image(hostPtr, s::image_channel_order::rgba, channelType, s::range<3>{3, 3, 3}); @@ -139,7 +133,6 @@ bool test3d_coord(dataT *hostPtr, coordT coord, s::range<1>(1)); // Do the test by reading a single pixel from the image - s::queue myQueue(selector); myQueue.submit([&](s::handler &cgh) { auto imageAcc = image.get_access(cgh); @@ -171,72 +164,86 @@ bool test3d_coord(dataT *hostPtr, coordT coord, } template -bool test1d(coordT coord, dataT expectedResult) { +bool test1d(s::queue myQueue, coordT coord, dataT expectedResult) { dataT hostPtr[3]; for (int i = 0; i < 3; i++) hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); - return test1d_coord(hostPtr, coord, expectedResult); + + return test1d_coord(myQueue, hostPtr, coord, expectedResult); } template -bool test2d(coordT coord, dataT expectedResult) { +bool test2d(s::queue myQueue, coordT coord, dataT expectedResult) { dataT hostPtr[9]; for (int i = 0; i < 9; i++) hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); - return test2d_coord(hostPtr, coord, expectedResult); + + return test2d_coord(myQueue, hostPtr, coord, expectedResult); } template -bool test3d(coordT coord, dataT expectedResult) { +bool test3d(s::queue myQueue, coordT coord, dataT expectedResult) { dataT hostPtr[27]; for (int i = 0; i < 27; i++) hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); - return test3d_coord(hostPtr, coord, expectedResult); + + return test3d_coord(myQueue, hostPtr, coord, expectedResult); } template -bool test() { +bool test(s::queue myQueue) { bool passed = true; - // 1d image tests - if (!test1d(0, dataT(0, 20, 40, 60))) + if (!test1d(myQueue, 0, dataT(0, 20, 40, 60))) passed = false; - if (!test1d(1, dataT(1, 21, 41, 61))) + + if (!test1d(myQueue, 1, dataT(1, 21, 41, 61))) passed = false; - if (!test1d(2, dataT(2, 22, 42, 62))) + + if (!test1d(myQueue, 2, dataT(2, 22, 42, 62))) passed = false; // 2d image tests - if (!test2d(s::int2(0, 0), dataT(0, 20, 40, 60))) + if (!test2d(myQueue, s::int2(0, 0), dataT(0, 20, 40, 60))) passed = false; - if (!test2d(s::int2(1, 0), dataT(1, 21, 41, 61))) + + if (!test2d(myQueue, s::int2(1, 0), dataT(1, 21, 41, 61))) passed = false; - if (!test2d(s::int2(0, 1), dataT(3, 23, 43, 63))) + + if (!test2d(myQueue, s::int2(0, 1), dataT(3, 23, 43, 63))) passed = false; - if (!test2d(s::int2(1, 1), dataT(4, 24, 44, 64))) + + if (!test2d(myQueue, s::int2(1, 1), dataT(4, 24, 44, 64))) passed = false; // 3d image tests - if (!test3d( - s::int4(0, 0, 0, 0), dataT(0, 20, 40, 60))) + if (!test3d(myQueue, + s::int4(0, 0, 0, 0), dataT(0, 20, 40, 60))) passed = false; - if (!test3d( - s::int4(1, 0, 0, 0), dataT(1, 21, 41, 61))) + + if (!test3d(myQueue, + s::int4(1, 0, 0, 0), dataT(1, 21, 41, 61))) passed = false; - if (!test3d( - s::int4(0, 1, 0, 0), dataT(3, 23, 43, 63))) + + if (!test3d(myQueue, + s::int4(0, 1, 0, 0), dataT(3, 23, 43, 63))) passed = false; - if (!test3d( - s::int4(1, 1, 0, 0), dataT(4, 24, 44, 64))) + + if (!test3d(myQueue, + s::int4(1, 1, 0, 0), dataT(4, 24, 44, 64))) passed = false; - if (!test3d( - s::int4(1, 0, 1, 0), dataT(10, 30, 50, 70))) + + if (!test3d(myQueue, + s::int4(1, 0, 1, 0), dataT(10, 30, 50, 70))) passed = false; - if (!test3d( - s::int4(0, 1, 1, 0), dataT(12, 32, 52, 72))) + + if (!test3d(myQueue, + s::int4(0, 1, 1, 0), dataT(12, 32, 52, 72))) passed = false; - if (!test3d( - s::int4(1, 1, 1, 0), dataT(13, 33, 53, 73))) + + if (!test3d(myQueue, + s::int4(1, 1, 1, 0), + dataT(13, 33, 53, 73))) passed = false; return passed; @@ -244,22 +251,27 @@ bool test() { int main() { + s::default_selector selector; + s::queue myQueue(selector); + bool passed = true; - // Half image - if (!test()) - passed = false; + if (myQueue.get_device().has_extension("cl_khr_fp16")) { + // Half image + if (!test(myQueue)) + passed = false; + } // Float image - if (!test()) + if (!test(myQueue)) passed = false; // 32-bit signed integer image - if (!test()) + if (!test(myQueue)) passed = false; // 32-bit unsigned integer image - if (!test()) + if (!test(myQueue)) passed = false; return passed ? 0 : -1; diff --git a/sycl/test/basic_tests/image/image_write.cpp b/sycl/test/basic_tests/image/image_write.cpp index 50a2e8131cbf0..f58953d9b3069 100644 --- a/sycl/test/basic_tests/image/image_write.cpp +++ b/sycl/test/basic_tests/image/image_write.cpp @@ -41,11 +41,9 @@ class test_3d_read_class; namespace s = cl::sycl; template -bool test1d_coord(dataT *hostPtr, coordT coord, dataT colour) { +bool test1d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT colour) { dataT resultData; - s::default_selector selector; - { // Scope everything to force destruction s::image<1> image(hostPtr, s::image_channel_order::rgba, channelType, s::range<1>{3}); @@ -53,9 +51,6 @@ bool test1d_coord(dataT *hostPtr, coordT coord, dataT colour) { s::buffer resultDataBuf(&resultData, s::range<1>(1)); - // Do the test by reading a single pixel from the image - s::queue myQueue(selector); - myQueue.submit([&](s::handler &cgh) { auto imageAcc = image.get_access(cgh); cgh.single_task>([=]() { @@ -93,11 +88,9 @@ bool test1d_coord(dataT *hostPtr, coordT coord, dataT colour) { } template -bool test2d_coord(dataT *hostPtr, coordT coord, dataT colour) { +bool test2d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT colour) { dataT resultData; - s::default_selector selector; - { // Scope everything to force destruction s::image<2> image(hostPtr, s::image_channel_order::rgba, channelType, s::range<2>{3, 3}); @@ -105,9 +98,6 @@ bool test2d_coord(dataT *hostPtr, coordT coord, dataT colour) { s::buffer resultDataBuf(&resultData, s::range<1>(1)); - // Do the test by reading a single pixel from the image - s::queue myQueue(selector); - myQueue.submit([&](s::handler &cgh) { auto imageAcc = image.get_access(cgh); @@ -146,7 +136,7 @@ bool test2d_coord(dataT *hostPtr, coordT coord, dataT colour) { } template -bool test3d_coord(dataT *hostPtr, coordT coord, dataT colour) { +bool test3d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT colour) { dataT resultData; s::default_selector selector; @@ -158,9 +148,6 @@ bool test3d_coord(dataT *hostPtr, coordT coord, dataT colour) { s::buffer resultDataBuf(&resultData, s::range<1>(1)); - // Do the test by reading a single pixel from the image - s::queue myQueue(selector); - myQueue.submit([&](s::handler &cgh) { auto imageAcc = image.get_access(cgh); cgh.single_task>([=]() { @@ -198,69 +185,69 @@ bool test3d_coord(dataT *hostPtr, coordT coord, dataT colour) { } template -bool test1d(coordT coord, dataT colour) { +bool test1d(s::queue myQueue, coordT coord, dataT colour) { dataT hostPtr[3]; memset(&hostPtr, 0, sizeof(dataT) * 3); - return test1d_coord(hostPtr, coord, colour); + return test1d_coord(myQueue, hostPtr, coord, colour); } template -bool test2d(coordT coord, dataT colour) { +bool test2d(s::queue myQueue, coordT coord, dataT colour) { dataT hostPtr[9]; memset(&hostPtr, 0, sizeof(dataT) * 9); - return test2d_coord(hostPtr, coord, colour); + return test2d_coord(myQueue, hostPtr, coord, colour); } template -bool test3d(coordT coord, dataT colour) { +bool test3d(s::queue myQueue, coordT coord, dataT colour) { dataT hostPtr[27]; memset(&hostPtr, 0, sizeof(dataT) * 27); - return test3d_coord(hostPtr, coord, colour); + return test3d_coord(myQueue, hostPtr, coord, colour); } template -bool test() { +bool test(s::queue myQueue) { bool passed = true; // 1d image tests - if (!test1d(0, dataT(0, 20, 40, 60))) + if (!test1d(myQueue, 0, dataT(0, 20, 40, 60))) passed = false; - if (!test1d(1, dataT(1, 21, 41, 61))) + if (!test1d(myQueue, 1, dataT(1, 21, 41, 61))) passed = false; - if (!test1d(2, dataT(2, 22, 42, 62))) + if (!test1d(myQueue, 2, dataT(2, 22, 42, 62))) passed = false; // 2d image tests - if (!test2d(s::int2(0, 0), dataT(0, 20, 40, 60))) + if (!test2d(myQueue, s::int2(0, 0), dataT(0, 20, 40, 60))) passed = false; - if (!test2d(s::int2(1, 0), dataT(1, 21, 41, 61))) + if (!test2d(myQueue, s::int2(1, 0), dataT(1, 21, 41, 61))) passed = false; - if (!test2d(s::int2(0, 1), dataT(3, 23, 43, 63))) + if (!test2d(myQueue, s::int2(0, 1), dataT(3, 23, 43, 63))) passed = false; - if (!test2d(s::int2(1, 1), dataT(4, 24, 44, 64))) + if (!test2d(myQueue, s::int2(1, 1), dataT(4, 24, 44, 64))) passed = false; // 3d image tests - if (!test3d( - s::int4(0, 0, 0, 0), dataT(0, 20, 40, 60))) + if (!test3d(myQueue, + s::int4(0, 0, 0, 0), dataT(0, 20, 40, 60))) passed = false; - if (!test3d( - s::int4(1, 0, 0, 0), dataT(1, 21, 41, 61))) + if (!test3d(myQueue, + s::int4(1, 0, 0, 0), dataT(1, 21, 41, 61))) passed = false; - if (!test3d( - s::int4(0, 1, 0, 0), dataT(3, 23, 43, 63))) + if (!test3d(myQueue, + s::int4(0, 1, 0, 0), dataT(3, 23, 43, 63))) passed = false; - if (!test3d( - s::int4(1, 1, 0, 0), dataT(4, 24, 44, 64))) + if (!test3d(myQueue, + s::int4(1, 1, 0, 0), dataT(4, 24, 44, 64))) passed = false; - if (!test3d( - s::int4(1, 0, 1, 0), dataT(10, 30, 50, 70))) + if (!test3d(myQueue, + s::int4(1, 0, 1, 0), dataT(10, 30, 50, 70))) passed = false; - if (!test3d( - s::int4(0, 1, 1, 0), dataT(12, 32, 52, 72))) + if (!test3d(myQueue, + s::int4(0, 1, 1, 0), dataT(12, 32, 52, 72))) passed = false; - if (!test3d( - s::int4(1, 1, 1, 0), dataT(13, 33, 53, 73))) + if (!test3d(myQueue, + s::int4(1, 1, 1, 0), dataT(13, 33, 53, 73))) passed = false; return passed; @@ -268,22 +255,27 @@ bool test() { int main() { + s::default_selector selector; + s::queue myQueue(selector); + bool passed = true; - // Half image - if (!test()) - passed = false; + if (myQueue.get_device().has_extension("cl_khr_fp16")) { + // Half image + if (!test(myQueue)) + passed = false; + } // Float image - if (!test()) + if (!test(myQueue)) passed = false; // 32-bit signed integer image - if (!test()) + if (!test(myQueue)) passed = false; // 32-bit unsigned integer image - if (!test()) + if (!test(myQueue)) passed = false; return passed ? 0 : -1; From c9987855518f5fccf618fbd475e15b7a72f72894 Mon Sep 17 00:00:00 2001 From: Stuart Adams Date: Tue, 14 Jul 2020 16:51:29 +0100 Subject: [PATCH 06/12] XFAIL CUDA --- sycl/test/basic_tests/image/image_sample.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sycl/test/basic_tests/image/image_sample.cpp b/sycl/test/basic_tests/image/image_sample.cpp index fa3d5fb65c2cf..297c15cd38313 100644 --- a/sycl/test/basic_tests/image/image_sample.cpp +++ b/sycl/test/basic_tests/image/image_sample.cpp @@ -1,8 +1,12 @@ // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out // RUN: %CPU_RUN_PLACEHOLDER %t.out // RUN: %GPU_RUN_PLACEHOLDER %t.out -// XFAIL: level0 -// "die: piextKernelSetArgSampler: not implemented" +// XFAIL: cuda + +/* + XFAIL CUDA due to driver bug. + Newer CUDA drivers cannot build valid programs here, failing with CUDA_ERROR_NOT_FOUND. +*/ #include From 0c8b008201d89f3794f0242aa24a1f952ff8a11a Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Mon, 12 Oct 2020 11:30:03 +0300 Subject: [PATCH 07/12] Update image_write.cpp --- sycl/test/basic_tests/image/image_write.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sycl/test/basic_tests/image/image_write.cpp b/sycl/test/basic_tests/image/image_write.cpp index f58953d9b3069..ebd8ffa51d9d8 100644 --- a/sycl/test/basic_tests/image/image_write.cpp +++ b/sycl/test/basic_tests/image/image_write.cpp @@ -14,11 +14,6 @@ * https://www.khronos.org/registry/OpenCL/specs/opencl-1.2.pdf#page=329 * * Confirmed to pass with -fsycl-targets=spir64-unknown-linux-sycldevice - * - * Enable sampled test with -DSAMPLED_TEST - * - * Enabled unsampled tests with -DUNSAMPLED_TEST - * */ #include From a1271553c7a03351a79c1c58615cae1f76f63e58 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Mon, 12 Oct 2020 11:30:30 +0300 Subject: [PATCH 08/12] Update image_read.cpp --- sycl/test/basic_tests/image/image_read.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sycl/test/basic_tests/image/image_read.cpp b/sycl/test/basic_tests/image/image_read.cpp index 2f79b6d515582..c3273c9ce759c 100644 --- a/sycl/test/basic_tests/image/image_read.cpp +++ b/sycl/test/basic_tests/image/image_read.cpp @@ -15,11 +15,6 @@ * https://www.khronos.org/registry/OpenCL/specs/opencl-1.2.pdf#page=329 * * Confirmed to pass with -fsycl-targets=spir64-unknown-linux-sycldevice - * - * Enable sampled test with -DSAMPLED_TEST - * - * Enabled unsampled tests with -DUNSAMPLED_TEST - * */ #include From f7ca9939bb58a131939c544dbe1283d1c1a5542a Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Mon, 12 Oct 2020 11:37:35 +0300 Subject: [PATCH 09/12] Apply clang-format --- sycl/test/basic_tests/image/image_read.cpp | 107 ++++++------- sycl/test/basic_tests/image/image_sample.cpp | 75 ++++----- sycl/test/basic_tests/image/image_write.cpp | 148 +++++++++--------- .../image_accessor_readsampler.cpp | 3 +- 4 files changed, 160 insertions(+), 173 deletions(-) diff --git a/sycl/test/basic_tests/image/image_read.cpp b/sycl/test/basic_tests/image/image_read.cpp index c3273c9ce759c..4bf9713e7a8b4 100644 --- a/sycl/test/basic_tests/image/image_read.cpp +++ b/sycl/test/basic_tests/image/image_read.cpp @@ -21,12 +21,9 @@ #include -template -class test_1d_class; -template -class test_2d_class; -template -class test_3d_class; +template class test_1d_class; +template class test_2d_class; +template class test_3d_class; namespace s = cl::sycl; @@ -36,18 +33,16 @@ bool test1d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT resultData; { // Scope everything to force destruction - s::image<1> image(hostPtr, s::image_channel_order::rgba, - channelType, s::range<1>{3}); + s::image<1> image(hostPtr, s::image_channel_order::rgba, channelType, + s::range<1>{3}); - s::buffer resultDataBuf(&resultData, - s::range<1>(1)); + s::buffer resultDataBuf(&resultData, s::range<1>(1)); // Do the test by reading a single pixel from the image myQueue.submit([&](s::handler &cgh) { - auto imageAcc = - image.get_access(cgh); - s::accessor - resultDataAcc(resultDataBuf, cgh); + auto imageAcc = image.get_access(cgh); + s::accessor resultDataAcc(resultDataBuf, + cgh); cgh.single_task>([=]() { dataT RetColor = imageAcc.read(coord); @@ -58,8 +53,8 @@ bool test1d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, #ifdef DEBUG_OUTPUT std::cout << "Expected: " << expectedColour.r() << ", " << expectedColour.g() << ", " << expectedColour.b() << ", " << expectedColour.a() << "\n"; - std::cout << "Got: " << resultData.r() << ", " << resultData.g() - << ", " << resultData.b() << ", " << resultData.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() << ", " + << resultData.b() << ", " << resultData.a() << "\n"; #endif // DEBUG_OUTPUT bool correct = true; if (resultData.r() != expectedColour.r()) @@ -79,18 +74,16 @@ bool test2d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT resultData; { // Scope everything to force destruction - s::image<2> image(hostPtr, s::image_channel_order::rgba, - channelType, s::range<2>{3, 3}); + s::image<2> image(hostPtr, s::image_channel_order::rgba, channelType, + s::range<2>{3, 3}); - s::buffer resultDataBuf(&resultData, - s::range<1>(1)); + s::buffer resultDataBuf(&resultData, s::range<1>(1)); // Do the test by reading a single pixel from the image myQueue.submit([&](s::handler &cgh) { - auto imageAcc = - image.get_access(cgh); - s::accessor - resultDataAcc(resultDataBuf, cgh); + auto imageAcc = image.get_access(cgh); + s::accessor resultDataAcc(resultDataBuf, + cgh); cgh.single_task>([=]() { dataT RetColor = imageAcc.read(coord); @@ -121,18 +114,16 @@ bool test3d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT resultData; { // Scope everything to force destruction - s::image<3> image(hostPtr, s::image_channel_order::rgba, - channelType, s::range<3>{3, 3, 3}); + s::image<3> image(hostPtr, s::image_channel_order::rgba, channelType, + s::range<3>{3, 3, 3}); - s::buffer resultDataBuf(&resultData, - s::range<1>(1)); + s::buffer resultDataBuf(&resultData, s::range<1>(1)); // Do the test by reading a single pixel from the image myQueue.submit([&](s::handler &cgh) { - auto imageAcc = - image.get_access(cgh); - s::accessor - resultDataAcc(resultDataBuf, cgh); + auto imageAcc = image.get_access(cgh); + s::accessor resultDataAcc(resultDataBuf, + cgh); cgh.single_task>([=]() { dataT RetColor = imageAcc.read(coord); @@ -143,8 +134,8 @@ bool test3d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, #ifdef DEBUG_OUTPUT std::cout << "Expected: " << expectedColour.r() << ", " << expectedColour.g() << ", " << expectedColour.b() << ", " << expectedColour.a() << "\n"; - std::cout << "Got: " << resultData.r() << ", " << resultData.g() - << ", " << resultData.b() << ", " << resultData.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() << ", " + << resultData.b() << ", " << resultData.a() << "\n"; #endif // DEBUG_OUTPUT bool correct = true; if (resultData.r() != expectedColour.r()) @@ -164,7 +155,8 @@ bool test1d(s::queue myQueue, coordT coord, dataT expectedResult) { for (int i = 0; i < 3; i++) hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); - return test1d_coord(myQueue, hostPtr, coord, expectedResult); + return test1d_coord(myQueue, hostPtr, coord, + expectedResult); } template @@ -173,7 +165,8 @@ bool test2d(s::queue myQueue, coordT coord, dataT expectedResult) { for (int i = 0; i < 9; i++) hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); - return test2d_coord(myQueue, hostPtr, coord, expectedResult); + return test2d_coord(myQueue, hostPtr, coord, + expectedResult); } template @@ -182,7 +175,8 @@ bool test3d(s::queue myQueue, coordT coord, dataT expectedResult) { for (int i = 0; i < 27; i++) hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); - return test3d_coord(myQueue, hostPtr, coord, expectedResult); + return test3d_coord(myQueue, hostPtr, coord, + expectedResult); } template @@ -199,45 +193,48 @@ bool test(s::queue myQueue) { passed = false; // 2d image tests - if (!test2d(myQueue, s::int2(0, 0), dataT(0, 20, 40, 60))) + if (!test2d(myQueue, s::int2(0, 0), + dataT(0, 20, 40, 60))) passed = false; - if (!test2d(myQueue, s::int2(1, 0), dataT(1, 21, 41, 61))) + if (!test2d(myQueue, s::int2(1, 0), + dataT(1, 21, 41, 61))) passed = false; - if (!test2d(myQueue, s::int2(0, 1), dataT(3, 23, 43, 63))) + if (!test2d(myQueue, s::int2(0, 1), + dataT(3, 23, 43, 63))) passed = false; - if (!test2d(myQueue, s::int2(1, 1), dataT(4, 24, 44, 64))) + if (!test2d(myQueue, s::int2(1, 1), + dataT(4, 24, 44, 64))) passed = false; // 3d image tests - if (!test3d(myQueue, - s::int4(0, 0, 0, 0), dataT(0, 20, 40, 60))) + if (!test3d(myQueue, s::int4(0, 0, 0, 0), + dataT(0, 20, 40, 60))) passed = false; - if (!test3d(myQueue, - s::int4(1, 0, 0, 0), dataT(1, 21, 41, 61))) + if (!test3d(myQueue, s::int4(1, 0, 0, 0), + dataT(1, 21, 41, 61))) passed = false; - if (!test3d(myQueue, - s::int4(0, 1, 0, 0), dataT(3, 23, 43, 63))) + if (!test3d(myQueue, s::int4(0, 1, 0, 0), + dataT(3, 23, 43, 63))) passed = false; - if (!test3d(myQueue, - s::int4(1, 1, 0, 0), dataT(4, 24, 44, 64))) + if (!test3d(myQueue, s::int4(1, 1, 0, 0), + dataT(4, 24, 44, 64))) passed = false; - if (!test3d(myQueue, - s::int4(1, 0, 1, 0), dataT(10, 30, 50, 70))) + if (!test3d(myQueue, s::int4(1, 0, 1, 0), + dataT(10, 30, 50, 70))) passed = false; - if (!test3d(myQueue, - s::int4(0, 1, 1, 0), dataT(12, 32, 52, 72))) + if (!test3d(myQueue, s::int4(0, 1, 1, 0), + dataT(12, 32, 52, 72))) passed = false; - if (!test3d(myQueue, - s::int4(1, 1, 1, 0), + if (!test3d(myQueue, s::int4(1, 1, 1, 0), dataT(13, 33, 53, 73))) passed = false; diff --git a/sycl/test/basic_tests/image/image_sample.cpp b/sycl/test/basic_tests/image/image_sample.cpp index 297c15cd38313..19d0d3f53242a 100644 --- a/sycl/test/basic_tests/image/image_sample.cpp +++ b/sycl/test/basic_tests/image/image_sample.cpp @@ -5,7 +5,8 @@ /* XFAIL CUDA due to driver bug. - Newer CUDA drivers cannot build valid programs here, failing with CUDA_ERROR_NOT_FOUND. + Newer CUDA drivers cannot build valid programs here, failing with + CUDA_ERROR_NOT_FOUND. */ #include @@ -41,30 +42,26 @@ bool check_result(dataT resultData, dataT expectedData, float epsilon = 0.1) { } template -bool test1d_coord(dataT *hostPtr, coordT coord, - dataT expectedColour) { +bool test1d_coord(dataT *hostPtr, coordT coord, dataT expectedColour) { dataT resultData; s::sampler testSampler(s::coordinate_normalization_mode::unnormalized, - s::addressing_mode::clamp, - s::filtering_mode::linear); + s::addressing_mode::clamp, s::filtering_mode::linear); s::default_selector selector; { // Scope everything to force destruction - s::image<1> image(hostPtr, s::image_channel_order::rgba, - channelType, s::range<1>{3}); + s::image<1> image(hostPtr, s::image_channel_order::rgba, channelType, + s::range<1>{3}); - s::buffer resultDataBuf(&resultData, - s::range<1>(1)); + s::buffer resultDataBuf(&resultData, s::range<1>(1)); // Do the test by reading a single pixel from the image s::queue myQueue(selector); myQueue.submit([&](s::handler &cgh) { - auto imageAcc = - image.get_access(cgh); - s::accessor - resultDataAcc(resultDataBuf, cgh); + auto imageAcc = image.get_access(cgh); + s::accessor resultDataAcc(resultDataBuf, + cgh); cgh.single_task([=]() { dataT RetColor = imageAcc.read(coord, testSampler); @@ -82,30 +79,26 @@ bool test1d_coord(dataT *hostPtr, coordT coord, } template -bool test2d_coord(dataT *hostPtr, coordT coord, - dataT expectedColour) { +bool test2d_coord(dataT *hostPtr, coordT coord, dataT expectedColour) { dataT resultData; s::sampler testSampler(s::coordinate_normalization_mode::unnormalized, - s::addressing_mode::clamp, - s::filtering_mode::linear); + s::addressing_mode::clamp, s::filtering_mode::linear); s::default_selector selector; { // Scope everything to force destruction - s::image<2> image(hostPtr, s::image_channel_order::rgba, - channelType, s::range<2>{3, 3}); + s::image<2> image(hostPtr, s::image_channel_order::rgba, channelType, + s::range<2>{3, 3}); - s::buffer resultDataBuf(&resultData, - s::range<1>(1)); + s::buffer resultDataBuf(&resultData, s::range<1>(1)); // Do the test by reading a single pixel from the image s::queue myQueue(selector); myQueue.submit([&](s::handler &cgh) { - auto imageAcc = - image.get_access(cgh); - s::accessor - resultDataAcc(resultDataBuf, cgh); + auto imageAcc = image.get_access(cgh); + s::accessor resultDataAcc(resultDataBuf, + cgh); cgh.single_task([=]() { dataT RetColor = imageAcc.read(coord, testSampler); @@ -123,30 +116,26 @@ bool test2d_coord(dataT *hostPtr, coordT coord, } template -bool test3d_coord(dataT *hostPtr, coordT coord, - dataT expectedColour) { +bool test3d_coord(dataT *hostPtr, coordT coord, dataT expectedColour) { dataT resultData; s::sampler testSampler(s::coordinate_normalization_mode::unnormalized, - s::addressing_mode::clamp, - s::filtering_mode::linear); + s::addressing_mode::clamp, s::filtering_mode::linear); s::default_selector selector; { // Scope everything to force destruction - s::image<3> image(hostPtr, s::image_channel_order::rgba, - channelType, s::range<3>{3, 3, 3}); + s::image<3> image(hostPtr, s::image_channel_order::rgba, channelType, + s::range<3>{3, 3, 3}); - s::buffer resultDataBuf(&resultData, - s::range<1>(1)); + s::buffer resultDataBuf(&resultData, s::range<1>(1)); // Do the test by reading a single pixel from the image s::queue myQueue(selector); myQueue.submit([&](s::handler &cgh) { - auto imageAcc = - image.get_access(cgh); - s::accessor - resultDataAcc(resultDataBuf, cgh); + auto imageAcc = image.get_access(cgh); + s::accessor resultDataAcc(resultDataBuf, + cgh); cgh.single_task([=]() { dataT RetColor = imageAcc.read(coord, testSampler); @@ -157,7 +146,8 @@ bool test3d_coord(dataT *hostPtr, coordT coord, bool correct = check_result(resultData, expectedColour); #ifdef DEBUG_OUTPUT if (!correct) { - std::cout << "Coord: " << coord.x() << ", " << coord.y() << ", " << coord.z() << "\n"; + std::cout << "Coord: " << coord.x() << ", " << coord.y() << ", " + << coord.z() << "\n"; } #endif // DEBUG_OUTPUT return correct; @@ -168,7 +158,8 @@ bool test1d(coordT coord, dataT expectedResult) { dataT hostPtr[3]; for (int i = 0; i < 3; i++) hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); - return test1d_coord(hostPtr, coord, expectedResult); + return test1d_coord(hostPtr, coord, + expectedResult); } template @@ -176,7 +167,8 @@ bool test2d(coordT coord, dataT expectedResult) { dataT hostPtr[9]; for (int i = 0; i < 9; i++) hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); - return test2d_coord(hostPtr, coord, expectedResult); + return test2d_coord(hostPtr, coord, + expectedResult); } template @@ -184,7 +176,8 @@ bool test3d(coordT coord, dataT expectedResult) { dataT hostPtr[27]; for (int i = 0; i < 27; i++) hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); - return test3d_coord(hostPtr, coord, expectedResult); + return test3d_coord(hostPtr, coord, + expectedResult); } int main() { diff --git a/sycl/test/basic_tests/image/image_write.cpp b/sycl/test/basic_tests/image/image_write.cpp index ebd8ffa51d9d8..15d4961e83b3d 100644 --- a/sycl/test/basic_tests/image/image_write.cpp +++ b/sycl/test/basic_tests/image/image_write.cpp @@ -20,43 +20,36 @@ #include -template -class test_1d_write_class; -template -class test_1d_read_class; -template -class test_2d_write_class; -template -class test_2d_read_class; -template -class test_3d_write_class; -template -class test_3d_read_class; +template class test_1d_write_class; +template class test_1d_read_class; +template class test_2d_write_class; +template class test_2d_read_class; +template class test_3d_write_class; +template class test_3d_read_class; namespace s = cl::sycl; template -bool test1d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT colour) { +bool test1d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, + dataT colour) { dataT resultData; { // Scope everything to force destruction - s::image<1> image(hostPtr, s::image_channel_order::rgba, - channelType, s::range<1>{3}); + s::image<1> image(hostPtr, s::image_channel_order::rgba, channelType, + s::range<1>{3}); - s::buffer resultDataBuf(&resultData, - s::range<1>(1)); + s::buffer resultDataBuf(&resultData, s::range<1>(1)); myQueue.submit([&](s::handler &cgh) { auto imageAcc = image.get_access(cgh); - cgh.single_task>([=]() { - imageAcc.write(coord, colour); - }); + cgh.single_task>( + [=]() { imageAcc.write(coord, colour); }); }); myQueue.submit([&](s::handler &cgh) { auto imageAcc = image.get_access(cgh); - s::accessor - resultDataAcc(resultDataBuf, cgh); + s::accessor resultDataAcc(resultDataBuf, + cgh); cgh.single_task>([=]() { dataT RetColor = imageAcc.read(coord); @@ -65,10 +58,10 @@ bool test1d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT colour) }); } #ifdef DEBUG_OUTPUT - std::cout << "Expected: " << colour.r() << ", " << colour.g() - << ", " << colour.b() << ", " << colour.a() << "\n"; - std::cout << "Got: " << resultData.r() << ", " << resultData.g() - << ", " << resultData.b() << ", " << resultData.a() << "\n"; + std::cout << "Expected: " << colour.r() << ", " << colour.g() << ", " + << colour.b() << ", " << colour.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() << ", " + << resultData.b() << ", " << resultData.a() << "\n"; #endif // DEBUG_OUTPUT bool correct = true; if (resultData.r() != colour.r()) @@ -83,28 +76,27 @@ bool test1d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT colour) } template -bool test2d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT colour) { +bool test2d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, + dataT colour) { dataT resultData; { // Scope everything to force destruction - s::image<2> image(hostPtr, s::image_channel_order::rgba, - channelType, s::range<2>{3, 3}); + s::image<2> image(hostPtr, s::image_channel_order::rgba, channelType, + s::range<2>{3, 3}); - s::buffer resultDataBuf(&resultData, - s::range<1>(1)); + s::buffer resultDataBuf(&resultData, s::range<1>(1)); myQueue.submit([&](s::handler &cgh) { auto imageAcc = image.get_access(cgh); - cgh.single_task>([=]() { - imageAcc.write(coord, colour); - }); + cgh.single_task>( + [=]() { imageAcc.write(coord, colour); }); }); myQueue.submit([&](s::handler &cgh) { auto imageAcc = image.get_access(cgh); - s::accessor - resultDataAcc(resultDataBuf, cgh); + s::accessor resultDataAcc(resultDataBuf, + cgh); cgh.single_task>([=]() { dataT RetColor = imageAcc.read(coord); @@ -113,10 +105,10 @@ bool test2d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT colour) }); } #ifdef DEBUG_OUTPUT - std::cout << "Expected: " << colour.r() << ", " << colour.g() - << ", " << colour.b() << ", " << colour.a() << "\n"; - std::cout << "Got: " << resultData.r() << ", " << resultData.g() - << ", " << resultData.b() << ", " << resultData.a() << "\n"; + std::cout << "Expected: " << colour.r() << ", " << colour.g() << ", " + << colour.b() << ", " << colour.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() << ", " + << resultData.b() << ", " << resultData.a() << "\n"; #endif // DEBUG_OUTPUT bool correct = true; if (resultData.r() != colour.r()) @@ -131,29 +123,28 @@ bool test2d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT colour) } template -bool test3d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT colour) { +bool test3d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, + dataT colour) { dataT resultData; s::default_selector selector; { // Scope everything to force destruction - s::image<3> image(hostPtr, s::image_channel_order::rgba, - channelType, s::range<3>{3, 3, 3}); + s::image<3> image(hostPtr, s::image_channel_order::rgba, channelType, + s::range<3>{3, 3, 3}); - s::buffer resultDataBuf(&resultData, - s::range<1>(1)); + s::buffer resultDataBuf(&resultData, s::range<1>(1)); myQueue.submit([&](s::handler &cgh) { auto imageAcc = image.get_access(cgh); - cgh.single_task>([=]() { - imageAcc.write(coord, colour); - }); + cgh.single_task>( + [=]() { imageAcc.write(coord, colour); }); }); myQueue.submit([&](s::handler &cgh) { auto imageAcc = image.get_access(cgh); - s::accessor - resultDataAcc(resultDataBuf, cgh); + s::accessor resultDataAcc(resultDataBuf, + cgh); cgh.single_task>([=]() { dataT RetColor = imageAcc.read(coord); @@ -162,10 +153,10 @@ bool test3d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, dataT colour) }); } #ifdef DEBUG_OUTPUT - std::cout << "Expected: " << colour.r() << ", " << colour.g() - << ", " << colour.b() << ", " << colour.a() << "\n"; - std::cout << "Got: " << resultData.r() << ", " << resultData.g() - << ", " << resultData.b() << ", " << resultData.a() << "\n"; + std::cout << "Expected: " << colour.r() << ", " << colour.g() << ", " + << colour.b() << ", " << colour.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() << ", " + << resultData.b() << ", " << resultData.a() << "\n"; #endif // DEBUG_OUTPUT bool correct = true; if (resultData.r() != colour.r()) @@ -183,21 +174,24 @@ template bool test1d(s::queue myQueue, coordT coord, dataT colour) { dataT hostPtr[3]; memset(&hostPtr, 0, sizeof(dataT) * 3); - return test1d_coord(myQueue, hostPtr, coord, colour); + return test1d_coord(myQueue, hostPtr, coord, + colour); } template bool test2d(s::queue myQueue, coordT coord, dataT colour) { dataT hostPtr[9]; memset(&hostPtr, 0, sizeof(dataT) * 9); - return test2d_coord(myQueue, hostPtr, coord, colour); + return test2d_coord(myQueue, hostPtr, coord, + colour); } template bool test3d(s::queue myQueue, coordT coord, dataT colour) { dataT hostPtr[27]; memset(&hostPtr, 0, sizeof(dataT) * 27); - return test3d_coord(myQueue, hostPtr, coord, colour); + return test3d_coord(myQueue, hostPtr, coord, + colour); } template @@ -213,36 +207,40 @@ bool test(s::queue myQueue) { passed = false; // 2d image tests - if (!test2d(myQueue, s::int2(0, 0), dataT(0, 20, 40, 60))) + if (!test2d(myQueue, s::int2(0, 0), + dataT(0, 20, 40, 60))) passed = false; - if (!test2d(myQueue, s::int2(1, 0), dataT(1, 21, 41, 61))) + if (!test2d(myQueue, s::int2(1, 0), + dataT(1, 21, 41, 61))) passed = false; - if (!test2d(myQueue, s::int2(0, 1), dataT(3, 23, 43, 63))) + if (!test2d(myQueue, s::int2(0, 1), + dataT(3, 23, 43, 63))) passed = false; - if (!test2d(myQueue, s::int2(1, 1), dataT(4, 24, 44, 64))) + if (!test2d(myQueue, s::int2(1, 1), + dataT(4, 24, 44, 64))) passed = false; // 3d image tests - if (!test3d(myQueue, - s::int4(0, 0, 0, 0), dataT(0, 20, 40, 60))) + if (!test3d(myQueue, s::int4(0, 0, 0, 0), + dataT(0, 20, 40, 60))) passed = false; - if (!test3d(myQueue, - s::int4(1, 0, 0, 0), dataT(1, 21, 41, 61))) + if (!test3d(myQueue, s::int4(1, 0, 0, 0), + dataT(1, 21, 41, 61))) passed = false; - if (!test3d(myQueue, - s::int4(0, 1, 0, 0), dataT(3, 23, 43, 63))) + if (!test3d(myQueue, s::int4(0, 1, 0, 0), + dataT(3, 23, 43, 63))) passed = false; - if (!test3d(myQueue, - s::int4(1, 1, 0, 0), dataT(4, 24, 44, 64))) + if (!test3d(myQueue, s::int4(1, 1, 0, 0), + dataT(4, 24, 44, 64))) passed = false; - if (!test3d(myQueue, - s::int4(1, 0, 1, 0), dataT(10, 30, 50, 70))) + if (!test3d(myQueue, s::int4(1, 0, 1, 0), + dataT(10, 30, 50, 70))) passed = false; - if (!test3d(myQueue, - s::int4(0, 1, 1, 0), dataT(12, 32, 52, 72))) + if (!test3d(myQueue, s::int4(0, 1, 1, 0), + dataT(12, 32, 52, 72))) passed = false; - if (!test3d(myQueue, - s::int4(1, 1, 1, 0), dataT(13, 33, 53, 73))) + if (!test3d(myQueue, s::int4(1, 1, 1, 0), + dataT(13, 33, 53, 73))) passed = false; return passed; diff --git a/sycl/test/basic_tests/image_accessor_readsampler.cpp b/sycl/test/basic_tests/image_accessor_readsampler.cpp index 1332cc6029158..847a4b83e6c9a 100644 --- a/sycl/test/basic_tests/image_accessor_readsampler.cpp +++ b/sycl/test/basic_tests/image_accessor_readsampler.cpp @@ -22,8 +22,7 @@ namespace s = cl::sycl; -template -class kernel_class; +template class kernel_class; void validateReadData(s::cl_float4 ReadData, s::cl_float4 ExpectedColor, s::cl_int precision = 1) { From 1adffa21398c9674770a02c6497695234307bcb2 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Mon, 12 Oct 2020 13:29:40 +0300 Subject: [PATCH 10/12] Fix LIT tests --- sycl/test/basic_tests/image/image_read.cpp | 3 +-- sycl/test/basic_tests/image/image_sample.cpp | 7 ------- sycl/test/basic_tests/image/image_write.cpp | 2 +- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/sycl/test/basic_tests/image/image_read.cpp b/sycl/test/basic_tests/image/image_read.cpp index 4bf9713e7a8b4..7d02ace9f9571 100644 --- a/sycl/test/basic_tests/image/image_read.cpp +++ b/sycl/test/basic_tests/image/image_read.cpp @@ -1,5 +1,4 @@ -// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out - +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fsycl-device-code-split=per_kernel %s -o %t.out // RUN: env SYCL_DEVICE_TYPE=HOST %t.out // RUN: %CPU_RUN_PLACEHOLDER %t.out // RUN: %GPU_RUN_PLACEHOLDER %t.out diff --git a/sycl/test/basic_tests/image/image_sample.cpp b/sycl/test/basic_tests/image/image_sample.cpp index 19d0d3f53242a..3f1a4ecdc797a 100644 --- a/sycl/test/basic_tests/image/image_sample.cpp +++ b/sycl/test/basic_tests/image/image_sample.cpp @@ -1,13 +1,6 @@ // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out // RUN: %CPU_RUN_PLACEHOLDER %t.out // RUN: %GPU_RUN_PLACEHOLDER %t.out -// XFAIL: cuda - -/* - XFAIL CUDA due to driver bug. - Newer CUDA drivers cannot build valid programs here, failing with - CUDA_ERROR_NOT_FOUND. -*/ #include diff --git a/sycl/test/basic_tests/image/image_write.cpp b/sycl/test/basic_tests/image/image_write.cpp index 15d4961e83b3d..5f11a263b8958 100644 --- a/sycl/test/basic_tests/image/image_write.cpp +++ b/sycl/test/basic_tests/image/image_write.cpp @@ -1,4 +1,4 @@ -// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fsycl-device-code-split=per_kernel %s -o %t.out // RUN: env SYCL_DEVICE_TYPE=HOST %t.out // RUN: %CPU_RUN_PLACEHOLDER %t.out // RUN: %GPU_RUN_PLACEHOLDER %t.out From f8897d10635b3be2b3ff4c5a841a5cb9360437ba Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Mon, 12 Oct 2020 14:28:48 +0300 Subject: [PATCH 11/12] Refactor tests to skip FP16 checks on unsupported platforms. --- sycl/test/basic_tests/image/image_read.cpp | 244 +---------------- sycl/test/basic_tests/image/image_read.h | 235 ++++++++++++++++ .../basic_tests/image/image_read_fp16.cpp | 22 ++ sycl/test/basic_tests/image/image_write.cpp | 250 +----------------- sycl/test/basic_tests/image/image_write.h | 241 +++++++++++++++++ .../basic_tests/image/image_write_fp16.cpp | 22 ++ 6 files changed, 524 insertions(+), 490 deletions(-) create mode 100644 sycl/test/basic_tests/image/image_read.h create mode 100644 sycl/test/basic_tests/image/image_read_fp16.cpp create mode 100644 sycl/test/basic_tests/image/image_write.h create mode 100644 sycl/test/basic_tests/image/image_write_fp16.cpp diff --git a/sycl/test/basic_tests/image/image_read.cpp b/sycl/test/basic_tests/image/image_read.cpp index 7d02ace9f9571..2c2459d039a05 100644 --- a/sycl/test/basic_tests/image/image_read.cpp +++ b/sycl/test/basic_tests/image/image_read.cpp @@ -1,244 +1,10 @@ -// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fsycl-device-code-split=per_kernel %s -o %t.out +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out // RUN: env SYCL_DEVICE_TYPE=HOST %t.out // RUN: %CPU_RUN_PLACEHOLDER %t.out // RUN: %GPU_RUN_PLACEHOLDER %t.out // RUN: %ACC_RUN_PLACEHOLDER %t.out -/** - * Tests clamp_to_edge addressing mode with nearest and linear filtering modes - * on a 4x4 image. - * - * Expected addressing mode and filtering results are given by the algorithm in - * the OpenCL 1.2 specification, Section 8. Image Addressing and Filtering - * - * https://www.khronos.org/registry/OpenCL/specs/opencl-1.2.pdf#page=329 - * - * Confirmed to pass with -fsycl-targets=spir64-unknown-linux-sycldevice - */ - -#include - -#include - -template class test_1d_class; -template class test_2d_class; -template class test_3d_class; - -namespace s = cl::sycl; - -template -bool test1d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, - dataT expectedColour) { - dataT resultData; - - { // Scope everything to force destruction - s::image<1> image(hostPtr, s::image_channel_order::rgba, channelType, - s::range<1>{3}); - - s::buffer resultDataBuf(&resultData, s::range<1>(1)); - - // Do the test by reading a single pixel from the image - myQueue.submit([&](s::handler &cgh) { - auto imageAcc = image.get_access(cgh); - s::accessor resultDataAcc(resultDataBuf, - cgh); - - cgh.single_task>([=]() { - dataT RetColor = imageAcc.read(coord); - resultDataAcc[0] = RetColor; - }); - }); - } -#ifdef DEBUG_OUTPUT - std::cout << "Expected: " << expectedColour.r() << ", " << expectedColour.g() - << ", " << expectedColour.b() << ", " << expectedColour.a() << "\n"; - std::cout << "Got: " << resultData.r() << ", " << resultData.g() << ", " - << resultData.b() << ", " << resultData.a() << "\n"; -#endif // DEBUG_OUTPUT - bool correct = true; - if (resultData.r() != expectedColour.r()) - correct = false; - if (resultData.g() != expectedColour.g()) - correct = false; - if (resultData.b() != expectedColour.b()) - correct = false; - if (resultData.a() != expectedColour.a()) - correct = false; - return correct; -} - -template -bool test2d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, - dataT expectedColour) { - dataT resultData; - - { // Scope everything to force destruction - s::image<2> image(hostPtr, s::image_channel_order::rgba, channelType, - s::range<2>{3, 3}); - - s::buffer resultDataBuf(&resultData, s::range<1>(1)); - - // Do the test by reading a single pixel from the image - myQueue.submit([&](s::handler &cgh) { - auto imageAcc = image.get_access(cgh); - s::accessor resultDataAcc(resultDataBuf, - cgh); - - cgh.single_task>([=]() { - dataT RetColor = imageAcc.read(coord); - resultDataAcc[0] = RetColor; - }); - }); - } - -#ifdef DEBUG_OUTPUT - std::cout << "Got: " << resultData.r() << ", " << resultData.g(); -#endif // DEBUG_OUTPUT - - bool correct = true; - if (resultData.r() != expectedColour.r()) - correct = false; - if (resultData.g() != expectedColour.g()) - correct = false; - if (resultData.b() != expectedColour.b()) - correct = false; - if (resultData.a() != expectedColour.a()) - correct = false; - return correct; -} - -template -bool test3d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, - dataT expectedColour) { - dataT resultData; - - { // Scope everything to force destruction - s::image<3> image(hostPtr, s::image_channel_order::rgba, channelType, - s::range<3>{3, 3, 3}); - - s::buffer resultDataBuf(&resultData, s::range<1>(1)); - - // Do the test by reading a single pixel from the image - myQueue.submit([&](s::handler &cgh) { - auto imageAcc = image.get_access(cgh); - s::accessor resultDataAcc(resultDataBuf, - cgh); - - cgh.single_task>([=]() { - dataT RetColor = imageAcc.read(coord); - resultDataAcc[0] = RetColor; - }); - }); - } -#ifdef DEBUG_OUTPUT - std::cout << "Expected: " << expectedColour.r() << ", " << expectedColour.g() - << ", " << expectedColour.b() << ", " << expectedColour.a() << "\n"; - std::cout << "Got: " << resultData.r() << ", " << resultData.g() << ", " - << resultData.b() << ", " << resultData.a() << "\n"; -#endif // DEBUG_OUTPUT - bool correct = true; - if (resultData.r() != expectedColour.r()) - correct = false; - if (resultData.g() != expectedColour.g()) - correct = false; - if (resultData.b() != expectedColour.b()) - correct = false; - if (resultData.a() != expectedColour.a()) - correct = false; - return correct; -} - -template -bool test1d(s::queue myQueue, coordT coord, dataT expectedResult) { - dataT hostPtr[3]; - for (int i = 0; i < 3; i++) - hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); - - return test1d_coord(myQueue, hostPtr, coord, - expectedResult); -} - -template -bool test2d(s::queue myQueue, coordT coord, dataT expectedResult) { - dataT hostPtr[9]; - for (int i = 0; i < 9; i++) - hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); - - return test2d_coord(myQueue, hostPtr, coord, - expectedResult); -} - -template -bool test3d(s::queue myQueue, coordT coord, dataT expectedResult) { - dataT hostPtr[27]; - for (int i = 0; i < 27; i++) - hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); - - return test3d_coord(myQueue, hostPtr, coord, - expectedResult); -} - -template -bool test(s::queue myQueue) { - bool passed = true; - // 1d image tests - if (!test1d(myQueue, 0, dataT(0, 20, 40, 60))) - passed = false; - - if (!test1d(myQueue, 1, dataT(1, 21, 41, 61))) - passed = false; - - if (!test1d(myQueue, 2, dataT(2, 22, 42, 62))) - passed = false; - - // 2d image tests - if (!test2d(myQueue, s::int2(0, 0), - dataT(0, 20, 40, 60))) - passed = false; - - if (!test2d(myQueue, s::int2(1, 0), - dataT(1, 21, 41, 61))) - passed = false; - - if (!test2d(myQueue, s::int2(0, 1), - dataT(3, 23, 43, 63))) - passed = false; - - if (!test2d(myQueue, s::int2(1, 1), - dataT(4, 24, 44, 64))) - passed = false; - - // 3d image tests - if (!test3d(myQueue, s::int4(0, 0, 0, 0), - dataT(0, 20, 40, 60))) - passed = false; - - if (!test3d(myQueue, s::int4(1, 0, 0, 0), - dataT(1, 21, 41, 61))) - passed = false; - - if (!test3d(myQueue, s::int4(0, 1, 0, 0), - dataT(3, 23, 43, 63))) - passed = false; - - if (!test3d(myQueue, s::int4(1, 1, 0, 0), - dataT(4, 24, 44, 64))) - passed = false; - - if (!test3d(myQueue, s::int4(1, 0, 1, 0), - dataT(10, 30, 50, 70))) - passed = false; - - if (!test3d(myQueue, s::int4(0, 1, 1, 0), - dataT(12, 32, 52, 72))) - passed = false; - - if (!test3d(myQueue, s::int4(1, 1, 1, 0), - dataT(13, 33, 53, 73))) - passed = false; - - return passed; -} +#include "image_read.h" int main() { @@ -247,12 +13,6 @@ int main() { bool passed = true; - if (myQueue.get_device().has_extension("cl_khr_fp16")) { - // Half image - if (!test(myQueue)) - passed = false; - } - // Float image if (!test(myQueue)) passed = false; diff --git a/sycl/test/basic_tests/image/image_read.h b/sycl/test/basic_tests/image/image_read.h new file mode 100644 index 0000000000000..a51a61df744bd --- /dev/null +++ b/sycl/test/basic_tests/image/image_read.h @@ -0,0 +1,235 @@ +/** + * Tests clamp_to_edge addressing mode with nearest and linear filtering modes + * on a 4x4 image. + * + * Expected addressing mode and filtering results are given by the algorithm in + * the OpenCL 1.2 specification, Section 8. Image Addressing and Filtering + * + * https://www.khronos.org/registry/OpenCL/specs/opencl-1.2.pdf#page=329 + * + * Confirmed to pass with -fsycl-targets=spir64-unknown-linux-sycldevice + */ + +#include + +#include + +template class test_1d_class; +template class test_2d_class; +template class test_3d_class; + +namespace s = cl::sycl; + +template +bool test1d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, + dataT expectedColour) { + dataT resultData; + + { // Scope everything to force destruction + s::image<1> image(hostPtr, s::image_channel_order::rgba, channelType, + s::range<1>{3}); + + s::buffer resultDataBuf(&resultData, s::range<1>(1)); + + // Do the test by reading a single pixel from the image + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = image.get_access(cgh); + s::accessor resultDataAcc(resultDataBuf, + cgh); + + cgh.single_task>([=]() { + dataT RetColor = imageAcc.read(coord); + resultDataAcc[0] = RetColor; + }); + }); + } +#ifdef DEBUG_OUTPUT + std::cout << "Expected: " << expectedColour.r() << ", " << expectedColour.g() + << ", " << expectedColour.b() << ", " << expectedColour.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() << ", " + << resultData.b() << ", " << resultData.a() << "\n"; +#endif // DEBUG_OUTPUT + bool correct = true; + if (resultData.r() != expectedColour.r()) + correct = false; + if (resultData.g() != expectedColour.g()) + correct = false; + if (resultData.b() != expectedColour.b()) + correct = false; + if (resultData.a() != expectedColour.a()) + correct = false; + return correct; +} + +template +bool test2d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, + dataT expectedColour) { + dataT resultData; + + { // Scope everything to force destruction + s::image<2> image(hostPtr, s::image_channel_order::rgba, channelType, + s::range<2>{3, 3}); + + s::buffer resultDataBuf(&resultData, s::range<1>(1)); + + // Do the test by reading a single pixel from the image + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = image.get_access(cgh); + s::accessor resultDataAcc(resultDataBuf, + cgh); + + cgh.single_task>([=]() { + dataT RetColor = imageAcc.read(coord); + resultDataAcc[0] = RetColor; + }); + }); + } + +#ifdef DEBUG_OUTPUT + std::cout << "Got: " << resultData.r() << ", " << resultData.g(); +#endif // DEBUG_OUTPUT + + bool correct = true; + if (resultData.r() != expectedColour.r()) + correct = false; + if (resultData.g() != expectedColour.g()) + correct = false; + if (resultData.b() != expectedColour.b()) + correct = false; + if (resultData.a() != expectedColour.a()) + correct = false; + return correct; +} + +template +bool test3d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, + dataT expectedColour) { + dataT resultData; + + { // Scope everything to force destruction + s::image<3> image(hostPtr, s::image_channel_order::rgba, channelType, + s::range<3>{3, 3, 3}); + + s::buffer resultDataBuf(&resultData, s::range<1>(1)); + + // Do the test by reading a single pixel from the image + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = image.get_access(cgh); + s::accessor resultDataAcc(resultDataBuf, + cgh); + + cgh.single_task>([=]() { + dataT RetColor = imageAcc.read(coord); + resultDataAcc[0] = RetColor; + }); + }); + } +#ifdef DEBUG_OUTPUT + std::cout << "Expected: " << expectedColour.r() << ", " << expectedColour.g() + << ", " << expectedColour.b() << ", " << expectedColour.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() << ", " + << resultData.b() << ", " << resultData.a() << "\n"; +#endif // DEBUG_OUTPUT + bool correct = true; + if (resultData.r() != expectedColour.r()) + correct = false; + if (resultData.g() != expectedColour.g()) + correct = false; + if (resultData.b() != expectedColour.b()) + correct = false; + if (resultData.a() != expectedColour.a()) + correct = false; + return correct; +} + +template +bool test1d(s::queue myQueue, coordT coord, dataT expectedResult) { + dataT hostPtr[3]; + for (int i = 0; i < 3; i++) + hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); + + return test1d_coord(myQueue, hostPtr, coord, + expectedResult); +} + +template +bool test2d(s::queue myQueue, coordT coord, dataT expectedResult) { + dataT hostPtr[9]; + for (int i = 0; i < 9; i++) + hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); + + return test2d_coord(myQueue, hostPtr, coord, + expectedResult); +} + +template +bool test3d(s::queue myQueue, coordT coord, dataT expectedResult) { + dataT hostPtr[27]; + for (int i = 0; i < 27; i++) + hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i); + + return test3d_coord(myQueue, hostPtr, coord, + expectedResult); +} + +template +bool test(s::queue myQueue) { + bool passed = true; + // 1d image tests + if (!test1d(myQueue, 0, dataT(0, 20, 40, 60))) + passed = false; + + if (!test1d(myQueue, 1, dataT(1, 21, 41, 61))) + passed = false; + + if (!test1d(myQueue, 2, dataT(2, 22, 42, 62))) + passed = false; + + // 2d image tests + if (!test2d(myQueue, s::int2(0, 0), + dataT(0, 20, 40, 60))) + passed = false; + + if (!test2d(myQueue, s::int2(1, 0), + dataT(1, 21, 41, 61))) + passed = false; + + if (!test2d(myQueue, s::int2(0, 1), + dataT(3, 23, 43, 63))) + passed = false; + + if (!test2d(myQueue, s::int2(1, 1), + dataT(4, 24, 44, 64))) + passed = false; + + // 3d image tests + if (!test3d(myQueue, s::int4(0, 0, 0, 0), + dataT(0, 20, 40, 60))) + passed = false; + + if (!test3d(myQueue, s::int4(1, 0, 0, 0), + dataT(1, 21, 41, 61))) + passed = false; + + if (!test3d(myQueue, s::int4(0, 1, 0, 0), + dataT(3, 23, 43, 63))) + passed = false; + + if (!test3d(myQueue, s::int4(1, 1, 0, 0), + dataT(4, 24, 44, 64))) + passed = false; + + if (!test3d(myQueue, s::int4(1, 0, 1, 0), + dataT(10, 30, 50, 70))) + passed = false; + + if (!test3d(myQueue, s::int4(0, 1, 1, 0), + dataT(12, 32, 52, 72))) + passed = false; + + if (!test3d(myQueue, s::int4(1, 1, 1, 0), + dataT(13, 33, 53, 73))) + passed = false; + + return passed; +} \ No newline at end of file diff --git a/sycl/test/basic_tests/image/image_read_fp16.cpp b/sycl/test/basic_tests/image/image_read_fp16.cpp new file mode 100644 index 0000000000000..98003a7f86fa3 --- /dev/null +++ b/sycl/test/basic_tests/image/image_read_fp16.cpp @@ -0,0 +1,22 @@ +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out +// RUN: env SYCL_DEVICE_TYPE=HOST %t.out +// RUN: %CPU_RUN_PLACEHOLDER %t.out +// RUN: %GPU_RUN_PLACEHOLDER %t.out +// RUN: %ACC_RUN_PLACEHOLDER %t.out + +#include "image_read.h" + +int main() { + s::default_selector selector; + s::queue myQueue(selector); + + // Device doesn't support cl_khr_fp16 extension - skip. + if (!myQueue.get_device().has_extension("cl_khr_fp16")) + return 0; + + // Half image + if (!test(myQueue)) + return -1; + + return 0; +} diff --git a/sycl/test/basic_tests/image/image_write.cpp b/sycl/test/basic_tests/image/image_write.cpp index 5f11a263b8958..a3674c921ef0e 100644 --- a/sycl/test/basic_tests/image/image_write.cpp +++ b/sycl/test/basic_tests/image/image_write.cpp @@ -1,250 +1,10 @@ -// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fsycl-device-code-split=per_kernel %s -o %t.out +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out // RUN: env SYCL_DEVICE_TYPE=HOST %t.out // RUN: %CPU_RUN_PLACEHOLDER %t.out // RUN: %GPU_RUN_PLACEHOLDER %t.out // RUN: %ACC_RUN_PLACEHOLDER %t.out -/** - * Tests clamp_to_edge addressing mode with nearest and linear filtering modes - * on a 4x4 image. - * - * Expected addressing mode and filtering results are given by the algorithm in - * the OpenCL 1.2 specification, Section 8. Image Addressing and Filtering - * - * https://www.khronos.org/registry/OpenCL/specs/opencl-1.2.pdf#page=329 - * - * Confirmed to pass with -fsycl-targets=spir64-unknown-linux-sycldevice - */ - -#include - -#include - -template class test_1d_write_class; -template class test_1d_read_class; -template class test_2d_write_class; -template class test_2d_read_class; -template class test_3d_write_class; -template class test_3d_read_class; - -namespace s = cl::sycl; - -template -bool test1d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, - dataT colour) { - dataT resultData; - - { // Scope everything to force destruction - s::image<1> image(hostPtr, s::image_channel_order::rgba, channelType, - s::range<1>{3}); - - s::buffer resultDataBuf(&resultData, s::range<1>(1)); - - myQueue.submit([&](s::handler &cgh) { - auto imageAcc = image.get_access(cgh); - cgh.single_task>( - [=]() { imageAcc.write(coord, colour); }); - }); - - myQueue.submit([&](s::handler &cgh) { - auto imageAcc = image.get_access(cgh); - s::accessor resultDataAcc(resultDataBuf, - cgh); - - cgh.single_task>([=]() { - dataT RetColor = imageAcc.read(coord); - resultDataAcc[0] = RetColor; - }); - }); - } -#ifdef DEBUG_OUTPUT - std::cout << "Expected: " << colour.r() << ", " << colour.g() << ", " - << colour.b() << ", " << colour.a() << "\n"; - std::cout << "Got: " << resultData.r() << ", " << resultData.g() << ", " - << resultData.b() << ", " << resultData.a() << "\n"; -#endif // DEBUG_OUTPUT - bool correct = true; - if (resultData.r() != colour.r()) - correct = false; - if (resultData.g() != colour.g()) - correct = false; - if (resultData.b() != colour.b()) - correct = false; - if (resultData.a() != colour.a()) - correct = false; - return correct; -} - -template -bool test2d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, - dataT colour) { - dataT resultData; - - { // Scope everything to force destruction - s::image<2> image(hostPtr, s::image_channel_order::rgba, channelType, - s::range<2>{3, 3}); - - s::buffer resultDataBuf(&resultData, s::range<1>(1)); - - myQueue.submit([&](s::handler &cgh) { - auto imageAcc = image.get_access(cgh); - - cgh.single_task>( - [=]() { imageAcc.write(coord, colour); }); - }); - - myQueue.submit([&](s::handler &cgh) { - auto imageAcc = image.get_access(cgh); - s::accessor resultDataAcc(resultDataBuf, - cgh); - - cgh.single_task>([=]() { - dataT RetColor = imageAcc.read(coord); - resultDataAcc[0] = RetColor; - }); - }); - } -#ifdef DEBUG_OUTPUT - std::cout << "Expected: " << colour.r() << ", " << colour.g() << ", " - << colour.b() << ", " << colour.a() << "\n"; - std::cout << "Got: " << resultData.r() << ", " << resultData.g() << ", " - << resultData.b() << ", " << resultData.a() << "\n"; -#endif // DEBUG_OUTPUT - bool correct = true; - if (resultData.r() != colour.r()) - correct = false; - if (resultData.g() != colour.g()) - correct = false; - if (resultData.b() != colour.b()) - correct = false; - if (resultData.a() != colour.a()) - correct = false; - return correct; -} - -template -bool test3d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, - dataT colour) { - dataT resultData; - - s::default_selector selector; - - { // Scope everything to force destruction - s::image<3> image(hostPtr, s::image_channel_order::rgba, channelType, - s::range<3>{3, 3, 3}); - - s::buffer resultDataBuf(&resultData, s::range<1>(1)); - - myQueue.submit([&](s::handler &cgh) { - auto imageAcc = image.get_access(cgh); - cgh.single_task>( - [=]() { imageAcc.write(coord, colour); }); - }); - - myQueue.submit([&](s::handler &cgh) { - auto imageAcc = image.get_access(cgh); - s::accessor resultDataAcc(resultDataBuf, - cgh); - - cgh.single_task>([=]() { - dataT RetColor = imageAcc.read(coord); - resultDataAcc[0] = RetColor; - }); - }); - } -#ifdef DEBUG_OUTPUT - std::cout << "Expected: " << colour.r() << ", " << colour.g() << ", " - << colour.b() << ", " << colour.a() << "\n"; - std::cout << "Got: " << resultData.r() << ", " << resultData.g() << ", " - << resultData.b() << ", " << resultData.a() << "\n"; -#endif // DEBUG_OUTPUT - bool correct = true; - if (resultData.r() != colour.r()) - correct = false; - if (resultData.g() != colour.g()) - correct = false; - if (resultData.b() != colour.b()) - correct = false; - if (resultData.a() != colour.a()) - correct = false; - return correct; -} - -template -bool test1d(s::queue myQueue, coordT coord, dataT colour) { - dataT hostPtr[3]; - memset(&hostPtr, 0, sizeof(dataT) * 3); - return test1d_coord(myQueue, hostPtr, coord, - colour); -} - -template -bool test2d(s::queue myQueue, coordT coord, dataT colour) { - dataT hostPtr[9]; - memset(&hostPtr, 0, sizeof(dataT) * 9); - return test2d_coord(myQueue, hostPtr, coord, - colour); -} - -template -bool test3d(s::queue myQueue, coordT coord, dataT colour) { - dataT hostPtr[27]; - memset(&hostPtr, 0, sizeof(dataT) * 27); - return test3d_coord(myQueue, hostPtr, coord, - colour); -} - -template -bool test(s::queue myQueue) { - bool passed = true; - - // 1d image tests - if (!test1d(myQueue, 0, dataT(0, 20, 40, 60))) - passed = false; - if (!test1d(myQueue, 1, dataT(1, 21, 41, 61))) - passed = false; - if (!test1d(myQueue, 2, dataT(2, 22, 42, 62))) - passed = false; - - // 2d image tests - if (!test2d(myQueue, s::int2(0, 0), - dataT(0, 20, 40, 60))) - passed = false; - if (!test2d(myQueue, s::int2(1, 0), - dataT(1, 21, 41, 61))) - passed = false; - if (!test2d(myQueue, s::int2(0, 1), - dataT(3, 23, 43, 63))) - passed = false; - if (!test2d(myQueue, s::int2(1, 1), - dataT(4, 24, 44, 64))) - passed = false; - - // 3d image tests - if (!test3d(myQueue, s::int4(0, 0, 0, 0), - dataT(0, 20, 40, 60))) - passed = false; - if (!test3d(myQueue, s::int4(1, 0, 0, 0), - dataT(1, 21, 41, 61))) - passed = false; - if (!test3d(myQueue, s::int4(0, 1, 0, 0), - dataT(3, 23, 43, 63))) - passed = false; - if (!test3d(myQueue, s::int4(1, 1, 0, 0), - dataT(4, 24, 44, 64))) - passed = false; - if (!test3d(myQueue, s::int4(1, 0, 1, 0), - dataT(10, 30, 50, 70))) - passed = false; - if (!test3d(myQueue, s::int4(0, 1, 1, 0), - dataT(12, 32, 52, 72))) - passed = false; - if (!test3d(myQueue, s::int4(1, 1, 1, 0), - dataT(13, 33, 53, 73))) - passed = false; - - return passed; -} +#include "image_write.h" int main() { @@ -253,12 +13,6 @@ int main() { bool passed = true; - if (myQueue.get_device().has_extension("cl_khr_fp16")) { - // Half image - if (!test(myQueue)) - passed = false; - } - // Float image if (!test(myQueue)) passed = false; diff --git a/sycl/test/basic_tests/image/image_write.h b/sycl/test/basic_tests/image/image_write.h new file mode 100644 index 0000000000000..34f34fb9b6a31 --- /dev/null +++ b/sycl/test/basic_tests/image/image_write.h @@ -0,0 +1,241 @@ +/** + * Tests clamp_to_edge addressing mode with nearest and linear filtering modes + * on a 4x4 image. + * + * Expected addressing mode and filtering results are given by the algorithm in + * the OpenCL 1.2 specification, Section 8. Image Addressing and Filtering + * + * https://www.khronos.org/registry/OpenCL/specs/opencl-1.2.pdf#page=329 + * + * Confirmed to pass with -fsycl-targets=spir64-unknown-linux-sycldevice + */ + +#include + +#include + +template class test_1d_write_class; +template class test_1d_read_class; +template class test_2d_write_class; +template class test_2d_read_class; +template class test_3d_write_class; +template class test_3d_read_class; + +namespace s = cl::sycl; + +template +bool test1d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, + dataT colour) { + dataT resultData; + + { // Scope everything to force destruction + s::image<1> image(hostPtr, s::image_channel_order::rgba, channelType, + s::range<1>{3}); + + s::buffer resultDataBuf(&resultData, s::range<1>(1)); + + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = image.get_access(cgh); + cgh.single_task>( + [=]() { imageAcc.write(coord, colour); }); + }); + + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = image.get_access(cgh); + s::accessor resultDataAcc(resultDataBuf, + cgh); + + cgh.single_task>([=]() { + dataT RetColor = imageAcc.read(coord); + resultDataAcc[0] = RetColor; + }); + }); + } +#ifdef DEBUG_OUTPUT + std::cout << "Expected: " << colour.r() << ", " << colour.g() << ", " + << colour.b() << ", " << colour.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() << ", " + << resultData.b() << ", " << resultData.a() << "\n"; +#endif // DEBUG_OUTPUT + bool correct = true; + if (resultData.r() != colour.r()) + correct = false; + if (resultData.g() != colour.g()) + correct = false; + if (resultData.b() != colour.b()) + correct = false; + if (resultData.a() != colour.a()) + correct = false; + return correct; +} + +template +bool test2d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, + dataT colour) { + dataT resultData; + + { // Scope everything to force destruction + s::image<2> image(hostPtr, s::image_channel_order::rgba, channelType, + s::range<2>{3, 3}); + + s::buffer resultDataBuf(&resultData, s::range<1>(1)); + + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = image.get_access(cgh); + + cgh.single_task>( + [=]() { imageAcc.write(coord, colour); }); + }); + + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = image.get_access(cgh); + s::accessor resultDataAcc(resultDataBuf, + cgh); + + cgh.single_task>([=]() { + dataT RetColor = imageAcc.read(coord); + resultDataAcc[0] = RetColor; + }); + }); + } +#ifdef DEBUG_OUTPUT + std::cout << "Expected: " << colour.r() << ", " << colour.g() << ", " + << colour.b() << ", " << colour.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() << ", " + << resultData.b() << ", " << resultData.a() << "\n"; +#endif // DEBUG_OUTPUT + bool correct = true; + if (resultData.r() != colour.r()) + correct = false; + if (resultData.g() != colour.g()) + correct = false; + if (resultData.b() != colour.b()) + correct = false; + if (resultData.a() != colour.a()) + correct = false; + return correct; +} + +template +bool test3d_coord(s::queue myQueue, dataT *hostPtr, coordT coord, + dataT colour) { + dataT resultData; + + s::default_selector selector; + + { // Scope everything to force destruction + s::image<3> image(hostPtr, s::image_channel_order::rgba, channelType, + s::range<3>{3, 3, 3}); + + s::buffer resultDataBuf(&resultData, s::range<1>(1)); + + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = image.get_access(cgh); + cgh.single_task>( + [=]() { imageAcc.write(coord, colour); }); + }); + + myQueue.submit([&](s::handler &cgh) { + auto imageAcc = image.get_access(cgh); + s::accessor resultDataAcc(resultDataBuf, + cgh); + + cgh.single_task>([=]() { + dataT RetColor = imageAcc.read(coord); + resultDataAcc[0] = RetColor; + }); + }); + } +#ifdef DEBUG_OUTPUT + std::cout << "Expected: " << colour.r() << ", " << colour.g() << ", " + << colour.b() << ", " << colour.a() << "\n"; + std::cout << "Got: " << resultData.r() << ", " << resultData.g() << ", " + << resultData.b() << ", " << resultData.a() << "\n"; +#endif // DEBUG_OUTPUT + bool correct = true; + if (resultData.r() != colour.r()) + correct = false; + if (resultData.g() != colour.g()) + correct = false; + if (resultData.b() != colour.b()) + correct = false; + if (resultData.a() != colour.a()) + correct = false; + return correct; +} + +template +bool test1d(s::queue myQueue, coordT coord, dataT colour) { + dataT hostPtr[3]; + memset(&hostPtr, 0, sizeof(dataT) * 3); + return test1d_coord(myQueue, hostPtr, coord, + colour); +} + +template +bool test2d(s::queue myQueue, coordT coord, dataT colour) { + dataT hostPtr[9]; + memset(&hostPtr, 0, sizeof(dataT) * 9); + return test2d_coord(myQueue, hostPtr, coord, + colour); +} + +template +bool test3d(s::queue myQueue, coordT coord, dataT colour) { + dataT hostPtr[27]; + memset(&hostPtr, 0, sizeof(dataT) * 27); + return test3d_coord(myQueue, hostPtr, coord, + colour); +} + +template +bool test(s::queue myQueue) { + bool passed = true; + + // 1d image tests + if (!test1d(myQueue, 0, dataT(0, 20, 40, 60))) + passed = false; + if (!test1d(myQueue, 1, dataT(1, 21, 41, 61))) + passed = false; + if (!test1d(myQueue, 2, dataT(2, 22, 42, 62))) + passed = false; + + // 2d image tests + if (!test2d(myQueue, s::int2(0, 0), + dataT(0, 20, 40, 60))) + passed = false; + if (!test2d(myQueue, s::int2(1, 0), + dataT(1, 21, 41, 61))) + passed = false; + if (!test2d(myQueue, s::int2(0, 1), + dataT(3, 23, 43, 63))) + passed = false; + if (!test2d(myQueue, s::int2(1, 1), + dataT(4, 24, 44, 64))) + passed = false; + + // 3d image tests + if (!test3d(myQueue, s::int4(0, 0, 0, 0), + dataT(0, 20, 40, 60))) + passed = false; + if (!test3d(myQueue, s::int4(1, 0, 0, 0), + dataT(1, 21, 41, 61))) + passed = false; + if (!test3d(myQueue, s::int4(0, 1, 0, 0), + dataT(3, 23, 43, 63))) + passed = false; + if (!test3d(myQueue, s::int4(1, 1, 0, 0), + dataT(4, 24, 44, 64))) + passed = false; + if (!test3d(myQueue, s::int4(1, 0, 1, 0), + dataT(10, 30, 50, 70))) + passed = false; + if (!test3d(myQueue, s::int4(0, 1, 1, 0), + dataT(12, 32, 52, 72))) + passed = false; + if (!test3d(myQueue, s::int4(1, 1, 1, 0), + dataT(13, 33, 53, 73))) + passed = false; + + return passed; +} diff --git a/sycl/test/basic_tests/image/image_write_fp16.cpp b/sycl/test/basic_tests/image/image_write_fp16.cpp new file mode 100644 index 0000000000000..23d254139cf67 --- /dev/null +++ b/sycl/test/basic_tests/image/image_write_fp16.cpp @@ -0,0 +1,22 @@ +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out +// RUN: env SYCL_DEVICE_TYPE=HOST %t.out +// RUN: %CPU_RUN_PLACEHOLDER %t.out +// RUN: %GPU_RUN_PLACEHOLDER %t.out +// RUN: %ACC_RUN_PLACEHOLDER %t.out + +#include "image_write.h" + +int main() { + s::default_selector selector; + s::queue myQueue(selector); + + // Device doesn't support cl_khr_fp16 extension - skip. + if (!myQueue.get_device().has_extension("cl_khr_fp16")) + return 0; + + // Half image + if (!test(myQueue)) + return -1; + + return 0; +} From ee351bf78a036aaf33db78602e2278fbf6a1b75e Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Mon, 12 Oct 2020 14:33:10 +0300 Subject: [PATCH 12/12] Do not run image tests on FPGA emulator. --- sycl/test/basic_tests/image/image_read.cpp | 1 - sycl/test/basic_tests/image/image_read_fp16.cpp | 1 - sycl/test/basic_tests/image/image_write.cpp | 1 - sycl/test/basic_tests/image/image_write_fp16.cpp | 1 - 4 files changed, 4 deletions(-) diff --git a/sycl/test/basic_tests/image/image_read.cpp b/sycl/test/basic_tests/image/image_read.cpp index 2c2459d039a05..d9c5cc36d5e79 100644 --- a/sycl/test/basic_tests/image/image_read.cpp +++ b/sycl/test/basic_tests/image/image_read.cpp @@ -2,7 +2,6 @@ // RUN: env SYCL_DEVICE_TYPE=HOST %t.out // RUN: %CPU_RUN_PLACEHOLDER %t.out // RUN: %GPU_RUN_PLACEHOLDER %t.out -// RUN: %ACC_RUN_PLACEHOLDER %t.out #include "image_read.h" diff --git a/sycl/test/basic_tests/image/image_read_fp16.cpp b/sycl/test/basic_tests/image/image_read_fp16.cpp index 98003a7f86fa3..4b9685617dbea 100644 --- a/sycl/test/basic_tests/image/image_read_fp16.cpp +++ b/sycl/test/basic_tests/image/image_read_fp16.cpp @@ -2,7 +2,6 @@ // RUN: env SYCL_DEVICE_TYPE=HOST %t.out // RUN: %CPU_RUN_PLACEHOLDER %t.out // RUN: %GPU_RUN_PLACEHOLDER %t.out -// RUN: %ACC_RUN_PLACEHOLDER %t.out #include "image_read.h" diff --git a/sycl/test/basic_tests/image/image_write.cpp b/sycl/test/basic_tests/image/image_write.cpp index a3674c921ef0e..d9a60465eae4d 100644 --- a/sycl/test/basic_tests/image/image_write.cpp +++ b/sycl/test/basic_tests/image/image_write.cpp @@ -2,7 +2,6 @@ // RUN: env SYCL_DEVICE_TYPE=HOST %t.out // RUN: %CPU_RUN_PLACEHOLDER %t.out // RUN: %GPU_RUN_PLACEHOLDER %t.out -// RUN: %ACC_RUN_PLACEHOLDER %t.out #include "image_write.h" diff --git a/sycl/test/basic_tests/image/image_write_fp16.cpp b/sycl/test/basic_tests/image/image_write_fp16.cpp index 23d254139cf67..11fc418425991 100644 --- a/sycl/test/basic_tests/image/image_write_fp16.cpp +++ b/sycl/test/basic_tests/image/image_write_fp16.cpp @@ -2,7 +2,6 @@ // RUN: env SYCL_DEVICE_TYPE=HOST %t.out // RUN: %CPU_RUN_PLACEHOLDER %t.out // RUN: %GPU_RUN_PLACEHOLDER %t.out -// RUN: %ACC_RUN_PLACEHOLDER %t.out #include "image_write.h"