Skip to content

Commit 99b0261

Browse files
[Offload][Conformance] Update olMemFree calls in conformance tests (#157773)
This PR is a follow-up to the change introduced in #157478, which added a `platform` parameter to the `olMemFree` function.
1 parent 0dc7345 commit 99b0261

File tree

4 files changed

+14
-34
lines changed

4 files changed

+14
-34
lines changed

offload/unittests/Conformance/include/mathtest/DeviceContext.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ class DeviceContext {
5757
explicit DeviceContext(llvm::StringRef Platform, std::size_t DeviceId = 0);
5858

5959
template <typename T>
60-
ManagedBuffer<T> createManagedBuffer(std::size_t Size) noexcept {
60+
ManagedBuffer<T> createManagedBuffer(std::size_t Size) const noexcept {
6161
void *UntypedAddress = nullptr;
6262

6363
detail::allocManagedMemory(DeviceHandle, Size * sizeof(T), &UntypedAddress);
6464
T *TypedAddress = static_cast<T *>(UntypedAddress);
6565

66-
return ManagedBuffer<T>(getPlatformHandle(), TypedAddress, Size);
66+
return ManagedBuffer<T>(PlatformHandle, TypedAddress, Size);
6767
}
6868

6969
[[nodiscard]] llvm::Expected<std::shared_ptr<DeviceImage>>
@@ -120,9 +120,6 @@ class DeviceContext {
120120

121121
[[nodiscard]] llvm::StringRef getPlatform() const noexcept;
122122

123-
[[nodiscard]] llvm::Expected<ol_platform_handle_t>
124-
getPlatformHandle() noexcept;
125-
126123
private:
127124
[[nodiscard]] llvm::Expected<ol_symbol_handle_t>
128125
getKernelHandle(ol_program_handle_t ProgramHandle,
@@ -134,7 +131,7 @@ class DeviceContext {
134131

135132
std::size_t GlobalDeviceId;
136133
ol_device_handle_t DeviceHandle;
137-
ol_platform_handle_t PlatformHandle = nullptr;
134+
ol_platform_handle_t PlatformHandle;
138135
};
139136
} // namespace mathtest
140137

offload/unittests/Conformance/include/mathtest/DeviceResources.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ template <typename T> class [[nodiscard]] ManagedBuffer {
4747
ManagedBuffer &operator=(const ManagedBuffer &) = delete;
4848

4949
ManagedBuffer(ManagedBuffer &&Other) noexcept
50-
: Address(Other.Address), Size(Other.Size) {
50+
: Platform(Other.Platform), Address(Other.Address), Size(Other.Size) {
51+
Other.Platform = nullptr;
5152
Other.Address = nullptr;
5253
Other.Size = 0;
5354
}
@@ -59,9 +60,11 @@ template <typename T> class [[nodiscard]] ManagedBuffer {
5960
if (Address)
6061
detail::freeDeviceMemory(Platform, Address);
6162

63+
Platform = Other.Platform;
6264
Address = Other.Address;
6365
Size = Other.Size;
6466

67+
Other.Platform = nullptr;
6568
Other.Address = nullptr;
6669
Other.Size = 0;
6770

@@ -89,7 +92,7 @@ template <typename T> class [[nodiscard]] ManagedBuffer {
8992
std::size_t Size) noexcept
9093
: Platform(Platform), Address(Address), Size(Size) {}
9194

92-
ol_platform_handle_t Platform;
95+
ol_platform_handle_t Platform = nullptr;
9396
T *Address = nullptr;
9497
std::size_t Size = 0;
9598
};

offload/unittests/Conformance/include/mathtest/GpuMathTest.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class [[nodiscard]] GpuMathTest final {
7575

7676
ResultType run(GeneratorType &Generator,
7777
std::size_t BufferSize = DefaultBufferSize,
78-
uint32_t GroupSize = DefaultGroupSize) noexcept {
78+
uint32_t GroupSize = DefaultGroupSize) const noexcept {
7979
assert(BufferSize > 0 && "Buffer size must be a positive value");
8080
assert(GroupSize > 0 && "Group size must be a positive value");
8181

@@ -128,7 +128,7 @@ class [[nodiscard]] GpuMathTest final {
128128
return *ExpectedKernel;
129129
}
130130

131-
[[nodiscard]] auto createBuffers(std::size_t BufferSize) {
131+
[[nodiscard]] auto createBuffers(std::size_t BufferSize) const {
132132
auto InBuffersTuple = std::apply(
133133
[&](auto... InTypeIdentities) {
134134
return std::make_tuple(

offload/unittests/Conformance/lib/DeviceContext.cpp

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ getPlatformBackend(ol_platform_handle_t PlatformHandle) noexcept {
103103

104104
struct Device {
105105
ol_device_handle_t Handle;
106+
ol_platform_handle_t PlatformHandle;
106107
std::string Name;
107108
std::string Platform;
108109
ol_platform_backend_t Backend;
@@ -124,7 +125,7 @@ const std::vector<Device> &getDevices() {
124125
auto Platform = getPlatformName(PlatformHandle);
125126

126127
static_cast<std::vector<Device> *>(Data)->push_back(
127-
{DeviceHandle, Name, Platform, Backend});
128+
{DeviceHandle, PlatformHandle, Name, Platform, Backend});
128129
}
129130

130131
return true;
@@ -175,6 +176,7 @@ DeviceContext::DeviceContext(std::size_t GlobalDeviceId)
175176
llvm::Twine(Devices.size()));
176177

177178
DeviceHandle = Devices[GlobalDeviceId].Handle;
179+
PlatformHandle = Devices[GlobalDeviceId].PlatformHandle;
178180
}
179181

180182
DeviceContext::DeviceContext(llvm::StringRef Platform, std::size_t DeviceId)
@@ -210,6 +212,7 @@ DeviceContext::DeviceContext(llvm::StringRef Platform, std::size_t DeviceId)
210212

211213
GlobalDeviceId = *FoundGlobalDeviceId;
212214
DeviceHandle = Devices[GlobalDeviceId].Handle;
215+
PlatformHandle = Devices[GlobalDeviceId].PlatformHandle;
213216
}
214217

215218
[[nodiscard]] llvm::Expected<std::shared_ptr<DeviceImage>>
@@ -286,29 +289,6 @@ DeviceContext::getKernelHandle(ol_program_handle_t ProgramHandle,
286289
return Handle;
287290
}
288291

289-
llvm::Expected<ol_platform_handle_t>
290-
DeviceContext::getPlatformHandle() noexcept {
291-
if (!PlatformHandle) {
292-
const ol_result_t OlResult =
293-
olGetDeviceInfo(DeviceHandle, OL_DEVICE_INFO_PLATFORM,
294-
sizeof(PlatformHandle), &PlatformHandle);
295-
296-
if (OlResult != OL_SUCCESS) {
297-
PlatformHandle = nullptr;
298-
llvm::StringRef Details =
299-
OlResult->Details ? OlResult->Details : "No details provided";
300-
301-
// clang-format off
302-
return llvm::createStringError(
303-
llvm::Twine(Details) +
304-
" (code " + llvm::Twine(OlResult->Code) + ")");
305-
// clang-format on
306-
}
307-
}
308-
309-
return PlatformHandle;
310-
}
311-
312292
void DeviceContext::launchKernelImpl(
313293
ol_symbol_handle_t KernelHandle, uint32_t NumGroups, uint32_t GroupSize,
314294
const void *KernelArgs, std::size_t KernelArgsSize) const noexcept {

0 commit comments

Comments
 (0)