diff --git a/sycl/test/basic_tests/image.cpp b/sycl/test/basic_tests/image.cpp index 7497821315d4a..f062f426623ff 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..d9c5cc36d5e79 --- /dev/null +++ b/sycl/test/basic_tests/image/image_read.cpp @@ -0,0 +1,28 @@ +// 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 + +#include "image_read.h" + +int main() { + + s::default_selector selector; + s::queue myQueue(selector); + + bool passed = true; + + // Float image + if (!test(myQueue)) + passed = false; + + // 32-bit signed integer image + if (!test(myQueue)) + passed = false; + + // 32-bit unsigned integer image + if (!test(myQueue)) + passed = false; + + return passed ? 0 : -1; +} 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..4b9685617dbea --- /dev/null +++ b/sycl/test/basic_tests/image/image_read_fp16.cpp @@ -0,0 +1,21 @@ +// 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 + +#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_sample.cpp b/sycl/test/basic_tests/image/image_sample.cpp new file mode 100644 index 0000000000000..3f1a4ecdc797a --- /dev/null +++ b/sycl/test/basic_tests/image/image_sample.cpp @@ -0,0 +1,244 @@ +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out +// RUN: %CPU_RUN_PLACEHOLDER %t.out +// RUN: %GPU_RUN_PLACEHOLDER %t.out + +#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..d9a60465eae4d --- /dev/null +++ b/sycl/test/basic_tests/image/image_write.cpp @@ -0,0 +1,28 @@ +// 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 + +#include "image_write.h" + +int main() { + + s::default_selector selector; + s::queue myQueue(selector); + + bool passed = true; + + // Float image + if (!test(myQueue)) + passed = false; + + // 32-bit signed integer image + if (!test(myQueue)) + passed = false; + + // 32-bit unsigned integer image + if (!test(myQueue)) + passed = false; + + return passed ? 0 : -1; +} 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..11fc418425991 --- /dev/null +++ b/sycl/test/basic_tests/image/image_write_fp16.cpp @@ -0,0 +1,21 @@ +// 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 + +#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; +} diff --git a/sycl/test/basic_tests/image_accessor_readsampler.cpp b/sycl/test/basic_tests/image_accessor_readsampler.cpp index 5c8a4247b7cbc..847a4b83e6c9a 100644 --- a/sycl/test/basic_tests/image_accessor_readsampler.cpp +++ b/sycl/test/basic_tests/image_accessor_readsampler.cpp @@ -6,7 +6,6 @@ // RUN: %CPU_RUN_PLACEHOLDER %t.out // RUN: %GPU_RUN_PLACEHOLDER %t.out // -//==------------------- image_accessor_readsampler.cpp ---------------------==// //==-----------------image_accessor read API test with sampler--------------==// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 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