-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL] atomic_memory_order_capabilities query for device and context (#…
…8517) This patch implements the `atomic_memory_order_capabilities` query in the OpenCL and Level Zero backends/plugins for `device` and `context` Specifically: - OpenCL <2.0 returns the minimum required capability set (`relaxed`) defined in [Section 4.2 of the OpenCL 3.0 specification](https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_API.html#CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES). - OpenCL <3.0 and Level Zero backends return all memory order capabilities. - OpenCL >=3.0 queries the actual device to get the supported memory order capabilities. E2E test have also been updated to reflect these changes: intel/llvm-test-suite#1627
- Loading branch information
Andrew Lamzed-Short
authored
Mar 23, 2023
1 parent
7663dc2
commit b18e6ea
Showing
8 changed files
with
166 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//==---- AtomicMemoryOrderCapabilities.cpp --- memory order query test -----==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <algorithm> | ||
#include <gtest/gtest.h> | ||
#include <helpers/PiMock.hpp> | ||
#include <sycl/sycl.hpp> | ||
|
||
using namespace sycl; | ||
|
||
namespace { | ||
|
||
static constexpr size_t expectedCapabilityVecSize = 5; | ||
static thread_local bool deviceGetInfoCalled = false; | ||
|
||
static bool has_capability(const std::vector<memory_order> &deviceCapabilities, | ||
memory_order capabilityToFind) { | ||
return std::find(deviceCapabilities.begin(), deviceCapabilities.end(), | ||
capabilityToFind) != deviceCapabilities.end(); | ||
} | ||
|
||
pi_result redefinedDeviceGetInfo(pi_device device, pi_device_info param_name, | ||
size_t param_value_size, void *param_value, | ||
size_t *param_value_size_ret) { | ||
if (param_name == PI_DEVICE_INFO_ATOMIC_MEMORY_ORDER_CAPABILITIES) { | ||
deviceGetInfoCalled = true; | ||
if (param_value) { | ||
pi_memory_order_capabilities *Capabilities = | ||
reinterpret_cast<pi_memory_order_capabilities *>(param_value); | ||
*Capabilities = PI_MEMORY_ORDER_RELAXED | PI_MEMORY_ORDER_ACQUIRE | | ||
PI_MEMORY_ORDER_RELEASE | PI_MEMORY_ORDER_ACQ_REL | | ||
PI_MEMORY_ORDER_SEQ_CST; | ||
} | ||
} | ||
return PI_SUCCESS; | ||
} | ||
|
||
TEST(AtomicMemoryOrderCapabilities, DeviceQueryReturnsCorrectCapabilities) { | ||
unittest::PiMock Mock; | ||
platform Plt = Mock.getPlatform(); | ||
|
||
Mock.redefineAfter<detail::PiApiKind::piDeviceGetInfo>( | ||
redefinedDeviceGetInfo); | ||
|
||
const device Dev = Plt.get_devices()[0]; | ||
context Ctx{Dev}; | ||
|
||
auto Capabilities = | ||
Dev.get_info<info::device::atomic_memory_order_capabilities>(); | ||
EXPECT_TRUE(deviceGetInfoCalled); | ||
EXPECT_EQ(Capabilities.size(), expectedCapabilityVecSize); | ||
|
||
EXPECT_TRUE(has_capability(Capabilities, memory_order::relaxed)); | ||
EXPECT_TRUE(has_capability(Capabilities, memory_order::acquire)); | ||
EXPECT_TRUE(has_capability(Capabilities, memory_order::release)); | ||
EXPECT_TRUE(has_capability(Capabilities, memory_order::acq_rel)); | ||
EXPECT_TRUE(has_capability(Capabilities, memory_order::seq_cst)); | ||
} | ||
|
||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters