|
| 1 | +//==---- PlatformTest.cpp --- PI unit tests --------------------------------==// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "TestGetPlugin.hpp" |
| 10 | +#include <CL/sycl.hpp> |
| 11 | +#include <CL/sycl/detail/pi.hpp> |
| 12 | +#include <detail/plugin.hpp> |
| 13 | +#include <gtest/gtest.h> |
| 14 | +#include <vector> |
| 15 | + |
| 16 | +namespace { |
| 17 | + |
| 18 | +using namespace cl::sycl; |
| 19 | + |
| 20 | +class SamplerPropertiesTest |
| 21 | + : public ::testing::TestWithParam<std::tuple< |
| 22 | + pi_bool, pi_sampler_filter_mode, pi_sampler_addressing_mode>> { |
| 23 | +protected: |
| 24 | + detail::plugin plugin = pi::initializeAndGet(backend::cuda); |
| 25 | + |
| 26 | + pi_platform platform_; |
| 27 | + pi_device device_; |
| 28 | + pi_context context_; |
| 29 | + pi_sampler sampler_; |
| 30 | + |
| 31 | + pi_bool normalizedCoords_; |
| 32 | + pi_sampler_filter_mode filterMode_; |
| 33 | + pi_sampler_addressing_mode addressMode_; |
| 34 | + |
| 35 | + SamplerPropertiesTest() = default; |
| 36 | + |
| 37 | + ~SamplerPropertiesTest() override = default; |
| 38 | + |
| 39 | + void SetUp() override { |
| 40 | + std::tie(normalizedCoords_, filterMode_, addressMode_) = GetParam(); |
| 41 | + |
| 42 | + pi_uint32 numPlatforms = 0; |
| 43 | + ASSERT_EQ(plugin.getBackend(), backend::cuda); |
| 44 | + |
| 45 | + ASSERT_EQ((plugin.call_nocheck<detail::PiApiKind::piPlatformsGet>( |
| 46 | + 0, nullptr, &numPlatforms)), |
| 47 | + PI_SUCCESS) |
| 48 | + << "piPlatformsGet failed.\n"; |
| 49 | + |
| 50 | + ASSERT_EQ((plugin.call_nocheck<detail::PiApiKind::piPlatformsGet>( |
| 51 | + numPlatforms, &platform_, nullptr)), |
| 52 | + PI_SUCCESS) |
| 53 | + << "piPlatformsGet failed.\n"; |
| 54 | + |
| 55 | + ASSERT_EQ((plugin.call_nocheck<detail::PiApiKind::piDevicesGet>( |
| 56 | + platform_, PI_DEVICE_TYPE_GPU, 1, &device_, nullptr)), |
| 57 | + PI_SUCCESS); |
| 58 | + ASSERT_EQ((plugin.call_nocheck<detail::PiApiKind::piContextCreate>( |
| 59 | + nullptr, 1, &device_, nullptr, nullptr, &context_)), |
| 60 | + PI_SUCCESS); |
| 61 | + EXPECT_NE(context_, nullptr); |
| 62 | + |
| 63 | + pi_sampler_properties sampler_properties[] = { |
| 64 | + PI_SAMPLER_PROPERTIES_NORMALIZED_COORDS, |
| 65 | + normalizedCoords_, |
| 66 | + PI_SAMPLER_PROPERTIES_ADDRESSING_MODE, |
| 67 | + addressMode_, |
| 68 | + PI_SAMPLER_PROPERTIES_FILTER_MODE, |
| 69 | + filterMode_, |
| 70 | + 0}; |
| 71 | + |
| 72 | + ASSERT_EQ((plugin.call_nocheck<detail::PiApiKind::piSamplerCreate>( |
| 73 | + context_, sampler_properties, &sampler_)), |
| 74 | + PI_SUCCESS); |
| 75 | + } |
| 76 | + |
| 77 | + void TearDown() override { |
| 78 | + plugin.call<detail::PiApiKind::piSamplerRelease>(sampler_); |
| 79 | + plugin.call<detail::PiApiKind::piDeviceRelease>(device_); |
| 80 | + plugin.call<detail::PiApiKind::piContextRelease>(context_); |
| 81 | + } |
| 82 | +}; |
| 83 | + |
| 84 | +TEST_P(SamplerPropertiesTest, piCheckNormalizedCoords) { |
| 85 | + pi_bool actualNormalizedCoords = !normalizedCoords_; |
| 86 | + |
| 87 | + plugin.call<detail::PiApiKind::piSamplerGetInfo>( |
| 88 | + sampler_, PI_SAMPLER_INFO_NORMALIZED_COORDS, sizeof(pi_bool), |
| 89 | + &actualNormalizedCoords, nullptr); |
| 90 | + |
| 91 | + ASSERT_EQ(actualNormalizedCoords, normalizedCoords_); |
| 92 | +} |
| 93 | + |
| 94 | +TEST_P(SamplerPropertiesTest, piCheckFilterMode) { |
| 95 | + pi_sampler_filter_mode actualFilterMode; |
| 96 | + |
| 97 | + plugin.call<detail::PiApiKind::piSamplerGetInfo>( |
| 98 | + sampler_, PI_SAMPLER_INFO_FILTER_MODE, sizeof(pi_sampler_filter_mode), |
| 99 | + &actualFilterMode, nullptr); |
| 100 | + |
| 101 | + ASSERT_EQ(actualFilterMode, filterMode_); |
| 102 | +} |
| 103 | + |
| 104 | +TEST_P(SamplerPropertiesTest, piCheckAddressingMode) { |
| 105 | + pi_sampler_addressing_mode actualAddressMode; |
| 106 | + |
| 107 | + plugin.call<detail::PiApiKind::piSamplerGetInfo>( |
| 108 | + sampler_, PI_SAMPLER_INFO_ADDRESSING_MODE, |
| 109 | + sizeof(pi_sampler_addressing_mode), &actualAddressMode, nullptr); |
| 110 | + |
| 111 | + ASSERT_EQ(actualAddressMode, addressMode_); |
| 112 | +} |
| 113 | + |
| 114 | +INSTANTIATE_TEST_CASE_P( |
| 115 | + SamplerPropertiesTesttImpl, SamplerPropertiesTest, |
| 116 | + ::testing::Combine( |
| 117 | + ::testing::Values(PI_TRUE, PI_FALSE), |
| 118 | + ::testing::Values(PI_SAMPLER_FILTER_MODE_LINEAR, |
| 119 | + PI_SAMPLER_FILTER_MODE_NEAREST), |
| 120 | + ::testing::Values(PI_SAMPLER_ADDRESSING_MODE_CLAMP, |
| 121 | + PI_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE, |
| 122 | + PI_SAMPLER_ADDRESSING_MODE_NONE, |
| 123 | + PI_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT, |
| 124 | + PI_SAMPLER_ADDRESSING_MODE_REPEAT)), ); |
| 125 | +} // namespace |
0 commit comments