|
| 1 | +// REQUIRES: aspect-ext_intel_legacy_image, cpu |
| 2 | +// |
| 3 | +// This test ensures that the correct pitch is used for cases when |
| 4 | +// UR_MEM_FLAG_USE_HOST_POINTER is passed to the backend. |
| 5 | +// UR_MEM_FLAG_USE_HOST_POINTER is used for contexts where CPU virtual memory |
| 6 | +// is accessible on device, so restrict this test to CPU platforms, although |
| 7 | +// there may be other additional platforms that support this behavior. |
| 8 | +// |
| 9 | +// RUN: %{build} -o %t.out |
| 10 | +// RUN: env SYCL_UR_TRACE=-1 %{run} %t.out | FileCheck %s |
| 11 | +// |
| 12 | +//==------------------- image_trace.cpp - SYCL image trace test ------------==// |
| 13 | +// |
| 14 | +// Ensures the correct params are being passed to urMemImageCreate |
| 15 | +// |
| 16 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 17 | +// See https://llvm.org/LICENSE.txt for license information. |
| 18 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 19 | +// |
| 20 | +//===----------------------------------------------------------------------===// |
| 21 | + |
| 22 | +#include <sycl/accessor_image.hpp> |
| 23 | +#include <sycl/builtins.hpp> |
| 24 | +#include <sycl/detail/core.hpp> |
| 25 | +#include <sycl/image.hpp> |
| 26 | + |
| 27 | +#include <iostream> |
| 28 | +#include <vector> |
| 29 | + |
| 30 | +#include "../../helpers.hpp" |
| 31 | + |
| 32 | +int main() { |
| 33 | + const sycl::image_channel_order ChanOrder = sycl::image_channel_order::rgba; |
| 34 | + const sycl::image_channel_type ChanType = sycl::image_channel_type::fp32; |
| 35 | + |
| 36 | + constexpr auto SYCLRead = sycl::access::mode::read; |
| 37 | + constexpr auto SYCLWrite = sycl::access::mode::write; |
| 38 | + |
| 39 | + const sycl::range<2> Img1Size(4, 4); |
| 40 | + const sycl::range<2> Img2Size(4, 4); |
| 41 | + |
| 42 | + std::vector<sycl::float4> Img1HostData(Img1Size.size(), {1, 2, 3, 4}); |
| 43 | + std::vector<sycl::float4> Img2HostData(Img2Size.size(), {0, 0, 0, 0}); |
| 44 | + |
| 45 | + { |
| 46 | + sycl::image<2> Img1(Img1HostData.data(), ChanOrder, ChanType, Img1Size); |
| 47 | + sycl::image<2> Img2(Img2HostData.data(), ChanOrder, ChanType, Img2Size); |
| 48 | + |
| 49 | + TestQueue Q{sycl::default_selector_v}; |
| 50 | + Q.submit([&](sycl::handler &CGH) { |
| 51 | + auto Img1Acc = Img1.get_access<sycl::float4, SYCLRead>(CGH); |
| 52 | + auto Img2Acc = Img2.get_access<sycl::float4, SYCLWrite>(CGH); |
| 53 | + |
| 54 | + CGH.parallel_for<class ImgCopy>(Img1Size, [=](sycl::item<2> Item) { |
| 55 | + sycl::float4 Data = Img1Acc.read(sycl::int2{Item[0], Item[1]}); |
| 56 | + Img2Acc.write(sycl::int2{Item[0], Item[1]}, Data); |
| 57 | + }); |
| 58 | + // CHECK: <--- urMemImageCreate |
| 59 | + // CHECK-SAME: UR_MEM_FLAG_USE_HOST_POINTER |
| 60 | + // CHECK-SAME: .width = 4, .height = 4, .depth = 1, .arraySize = 0, .rowPitch = 64, .slicePitch = 256 |
| 61 | + // CHECK: <--- urMemImageCreate |
| 62 | + // CHECK-SAME: UR_MEM_FLAG_USE_HOST_POINTER |
| 63 | + // CHECK-SAME: .width = 4, .height = 4, .depth = 1, .arraySize = 0, .rowPitch = 64, .slicePitch = 256 |
| 64 | + }); |
| 65 | + } |
| 66 | + |
| 67 | + for (int X = 0; X < Img2Size[0]; ++X) |
| 68 | + for (int Y = 0; Y < Img2Size[1]; ++Y) { |
| 69 | + sycl::float4 Vec1 = Img1HostData[X * Img1Size[1] + Y]; |
| 70 | + sycl::float4 Vec2 = Img2HostData[X * Img2Size[1] + Y]; |
| 71 | + |
| 72 | + if (sycl::any(sycl::isnotequal(Vec1, Vec2))) { |
| 73 | + std::cerr << "Failed" << std::endl; |
| 74 | + std::cerr << "Element [ " << X << ", " << Y << " ]" << std::endl; |
| 75 | + std::cerr << "Expected: " << printableVec(Vec1) << std::endl; |
| 76 | + std::cerr << " Got : " << printableVec(Vec2) << std::endl; |
| 77 | + return 1; |
| 78 | + } |
| 79 | + } |
| 80 | +} |
0 commit comments