Hey all,
I am trying to down-sample an image using SYCL. I must be doing something wrong though, as I get an exception while reading the pixel values. I am probably doing something wrong with my sampler. I am using
sycl::sampler sampler(sycl::coordinate_normalization_mode::normalized,
sycl::addressing_mode::none,
sycl::filtering_mode::linear);
And then, I am reading pixels with normalized values in [0,1]. Is that correct, or should it be in [-1,1]?
Also, it is valid to query the input image, which is based on a range that does not match the range that was given to the command group handler?
You can see the full code below:
sycl::range<2> image_in_range(height, width);
sycl::image<2> image_in(inputData, sycl::image_channel_order::rgba,
sycl::image_channel_type::unorm_int8,
image_in_range);
constexpr std::size_t out_dim = 256;
sycl::range<2> image_out_range(out_dim, out_dim);
sycl::image<2> image_out(outputData.data(), sycl::image_channel_order::rgba,
sycl::image_channel_type::unorm_int8,
image_out_range);
myQueue.submit([&](sycl::handler& cgh) {
auto r = get_optimal_local_range(image_out_range, myQueue.get_device());
auto myRange = sycl::nd_range<2>(image_out_range, r);
auto in =
image_in.get_access<sycl::float4, sycl::access::mode::read>(cgh);
auto out =
image_out.get_access<sycl::float4, sycl::access::mode::write>(cgh);
sycl::sampler sampler(sycl::coordinate_normalization_mode::normalized,
sycl::addressing_mode::none,
sycl::filtering_mode::linear);
cgh.parallel_for<DownSample>(myRange, [=](sycl::nd_item<2> itemID) {
auto coords =
sycl::int2(itemID.get_global_id(1), itemID.get_global_id(0));
auto coords_norm =
sycl::float2(itemID.get_global_id(1) / static_cast<float>(out_dim),
itemID.get_global_id(0) / static_cast<float>(out_dim));
auto newPixel = in.read(coords_norm, sampler);
newPixel.w() = 1.f;
out.write(coords, newPixel);
});
});
myQueue.wait_and_throw();
Thank you for your help!