Skip to content

Commit 179e304

Browse files
authored
[SYCL] Map sampler addressing mode differently depending on L0 version. (#4765)
Level Zero runtime with API version 1.2 and lower has a bug: ZE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER is implemented as "clamp to edge" and ZE_SAMPLER_ADDRESS_MODE_CLAMP is implemented as "clamp to border", i.e. logic is flipped. Starting from API version 1.3 this problem is going to be fixed. That's why check for API version to set an address mode in the Level Zero plugin.
1 parent e7cc7b0 commit 179e304

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,6 @@ pi_result _pi_platform::initialize() {
15261526
auto VersionBuild = std::to_string(DriverVersion & 0x0000FFFF);
15271527
ZeDriverVersion = VersionMajor + "." + VersionMinor + "." + VersionBuild;
15281528

1529-
ze_api_version_t ZeApiVersion;
15301529
ZE_CALL(zeDriverGetApiVersion, (ZeDriver, &ZeApiVersion));
15311530
ZeDriverApiVersion = std::to_string(ZE_MAJOR_VERSION(ZeApiVersion)) + "." +
15321531
std::to_string(ZE_MINOR_VERSION(ZeApiVersion));
@@ -5098,6 +5097,14 @@ pi_result piSamplerCreate(pi_context Context,
50985097
pi_cast<pi_sampler_addressing_mode>(
50995098
pi_cast<pi_uint32>(*(++CurProperty)));
51005099

5100+
// Level Zero runtime with API version 1.2 and lower has a bug:
5101+
// ZE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER is implemented as "clamp to
5102+
// edge" and ZE_SAMPLER_ADDRESS_MODE_CLAMP is implemented as "clamp to
5103+
// border", i.e. logic is flipped. Starting from API version 1.3 this
5104+
// problem is going to be fixed. That's why check for API version to set
5105+
// an address mode.
5106+
ze_api_version_t ZeApiVersion =
5107+
Context->Devices[0]->Platform->ZeApiVersion;
51015108
// TODO: add support for PI_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE
51025109
switch (CurValueAddressingMode) {
51035110
case PI_SAMPLER_ADDRESSING_MODE_NONE:
@@ -5107,10 +5114,16 @@ pi_result piSamplerCreate(pi_context Context,
51075114
ZeSamplerDesc.addressMode = ZE_SAMPLER_ADDRESS_MODE_REPEAT;
51085115
break;
51095116
case PI_SAMPLER_ADDRESSING_MODE_CLAMP:
5110-
ZeSamplerDesc.addressMode = ZE_SAMPLER_ADDRESS_MODE_CLAMP;
5117+
ZeSamplerDesc.addressMode =
5118+
ZeApiVersion < ZE_MAKE_VERSION(1, 3)
5119+
? ZE_SAMPLER_ADDRESS_MODE_CLAMP
5120+
: ZE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
51115121
break;
51125122
case PI_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE:
5113-
ZeSamplerDesc.addressMode = ZE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
5123+
ZeSamplerDesc.addressMode =
5124+
ZeApiVersion < ZE_MAKE_VERSION(1, 3)
5125+
? ZE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
5126+
: ZE_SAMPLER_ADDRESS_MODE_CLAMP;
51145127
break;
51155128
case PI_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT:
51165129
ZeSamplerDesc.addressMode = ZE_SAMPLER_ADDRESS_MODE_MIRROR;

sycl/plugins/level_zero/pi_level_zero.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ struct _pi_platform {
226226
// Cache versions info from zeDriverGetProperties.
227227
std::string ZeDriverVersion;
228228
std::string ZeDriverApiVersion;
229+
ze_api_version_t ZeApiVersion;
229230

230231
// Cache driver extensions
231232
std::unordered_map<std::string, uint32_t> zeDriverExtensionMap;

0 commit comments

Comments
 (0)