Skip to content

Commit e32661f

Browse files
committed
Implemented test_sampler_properties.cpp
1 parent d4e7929 commit e32661f

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed

sycl/unittests/pi/cuda/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_sycl_unittest(PiCudaTests OBJECT
88
test_mem_obj.cpp
99
test_primary_context.cpp
1010
test_queue.cpp
11+
test_sampler_properties.cpp
1112
)
1213

1314
add_dependencies(PiCudaTests sycl)
@@ -16,6 +17,9 @@ target_link_libraries(PiCudaTests PRIVATE
1617
LLVMTestingSupport
1718
OpenCL-Headers)
1819

20+
target_compile_definitions(PiCudaTests PRIVATE
21+
GTEST_HAS_COMBINE=1)
22+
1923
target_include_directories(
2024
PiCudaTests PUBLIC
2125
${CUDA_INCLUDE_DIRS}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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(){};
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

Comments
 (0)