diff --git a/offload/unittests/Conformance/include/mathtest/DeviceContext.hpp b/offload/unittests/Conformance/include/mathtest/DeviceContext.hpp index 7a11798856550..95e90139593f9 100644 --- a/offload/unittests/Conformance/include/mathtest/DeviceContext.hpp +++ b/offload/unittests/Conformance/include/mathtest/DeviceContext.hpp @@ -57,13 +57,13 @@ class DeviceContext { explicit DeviceContext(llvm::StringRef Platform, std::size_t DeviceId = 0); template - ManagedBuffer createManagedBuffer(std::size_t Size) noexcept { + ManagedBuffer createManagedBuffer(std::size_t Size) const noexcept { void *UntypedAddress = nullptr; detail::allocManagedMemory(DeviceHandle, Size * sizeof(T), &UntypedAddress); T *TypedAddress = static_cast(UntypedAddress); - return ManagedBuffer(getPlatformHandle(), TypedAddress, Size); + return ManagedBuffer(PlatformHandle, TypedAddress, Size); } [[nodiscard]] llvm::Expected> @@ -120,9 +120,6 @@ class DeviceContext { [[nodiscard]] llvm::StringRef getPlatform() const noexcept; - [[nodiscard]] llvm::Expected - getPlatformHandle() noexcept; - private: [[nodiscard]] llvm::Expected getKernelHandle(ol_program_handle_t ProgramHandle, @@ -134,7 +131,7 @@ class DeviceContext { std::size_t GlobalDeviceId; ol_device_handle_t DeviceHandle; - ol_platform_handle_t PlatformHandle = nullptr; + ol_platform_handle_t PlatformHandle; }; } // namespace mathtest diff --git a/offload/unittests/Conformance/include/mathtest/DeviceResources.hpp b/offload/unittests/Conformance/include/mathtest/DeviceResources.hpp index 6084732baf6ee..d6d9be6525f5e 100644 --- a/offload/unittests/Conformance/include/mathtest/DeviceResources.hpp +++ b/offload/unittests/Conformance/include/mathtest/DeviceResources.hpp @@ -47,7 +47,8 @@ template class [[nodiscard]] ManagedBuffer { ManagedBuffer &operator=(const ManagedBuffer &) = delete; ManagedBuffer(ManagedBuffer &&Other) noexcept - : Address(Other.Address), Size(Other.Size) { + : Platform(Other.Platform), Address(Other.Address), Size(Other.Size) { + Other.Platform = nullptr; Other.Address = nullptr; Other.Size = 0; } @@ -59,9 +60,11 @@ template class [[nodiscard]] ManagedBuffer { if (Address) detail::freeDeviceMemory(Platform, Address); + Platform = Other.Platform; Address = Other.Address; Size = Other.Size; + Other.Platform = nullptr; Other.Address = nullptr; Other.Size = 0; @@ -89,7 +92,7 @@ template class [[nodiscard]] ManagedBuffer { std::size_t Size) noexcept : Platform(Platform), Address(Address), Size(Size) {} - ol_platform_handle_t Platform; + ol_platform_handle_t Platform = nullptr; T *Address = nullptr; std::size_t Size = 0; }; diff --git a/offload/unittests/Conformance/include/mathtest/GpuMathTest.hpp b/offload/unittests/Conformance/include/mathtest/GpuMathTest.hpp index fdf30d58ae1e7..b88d6e9aebdc8 100644 --- a/offload/unittests/Conformance/include/mathtest/GpuMathTest.hpp +++ b/offload/unittests/Conformance/include/mathtest/GpuMathTest.hpp @@ -75,7 +75,7 @@ class [[nodiscard]] GpuMathTest final { ResultType run(GeneratorType &Generator, std::size_t BufferSize = DefaultBufferSize, - uint32_t GroupSize = DefaultGroupSize) noexcept { + uint32_t GroupSize = DefaultGroupSize) const noexcept { assert(BufferSize > 0 && "Buffer size must be a positive value"); assert(GroupSize > 0 && "Group size must be a positive value"); @@ -128,7 +128,7 @@ class [[nodiscard]] GpuMathTest final { return *ExpectedKernel; } - [[nodiscard]] auto createBuffers(std::size_t BufferSize) { + [[nodiscard]] auto createBuffers(std::size_t BufferSize) const { auto InBuffersTuple = std::apply( [&](auto... InTypeIdentities) { return std::make_tuple( diff --git a/offload/unittests/Conformance/lib/DeviceContext.cpp b/offload/unittests/Conformance/lib/DeviceContext.cpp index d72f56ca1f175..987d7841fa763 100644 --- a/offload/unittests/Conformance/lib/DeviceContext.cpp +++ b/offload/unittests/Conformance/lib/DeviceContext.cpp @@ -103,6 +103,7 @@ getPlatformBackend(ol_platform_handle_t PlatformHandle) noexcept { struct Device { ol_device_handle_t Handle; + ol_platform_handle_t PlatformHandle; std::string Name; std::string Platform; ol_platform_backend_t Backend; @@ -124,7 +125,7 @@ const std::vector &getDevices() { auto Platform = getPlatformName(PlatformHandle); static_cast *>(Data)->push_back( - {DeviceHandle, Name, Platform, Backend}); + {DeviceHandle, PlatformHandle, Name, Platform, Backend}); } return true; @@ -175,6 +176,7 @@ DeviceContext::DeviceContext(std::size_t GlobalDeviceId) llvm::Twine(Devices.size())); DeviceHandle = Devices[GlobalDeviceId].Handle; + PlatformHandle = Devices[GlobalDeviceId].PlatformHandle; } DeviceContext::DeviceContext(llvm::StringRef Platform, std::size_t DeviceId) @@ -210,6 +212,7 @@ DeviceContext::DeviceContext(llvm::StringRef Platform, std::size_t DeviceId) GlobalDeviceId = *FoundGlobalDeviceId; DeviceHandle = Devices[GlobalDeviceId].Handle; + PlatformHandle = Devices[GlobalDeviceId].PlatformHandle; } [[nodiscard]] llvm::Expected> @@ -286,29 +289,6 @@ DeviceContext::getKernelHandle(ol_program_handle_t ProgramHandle, return Handle; } -llvm::Expected -DeviceContext::getPlatformHandle() noexcept { - if (!PlatformHandle) { - const ol_result_t OlResult = - olGetDeviceInfo(DeviceHandle, OL_DEVICE_INFO_PLATFORM, - sizeof(PlatformHandle), &PlatformHandle); - - if (OlResult != OL_SUCCESS) { - PlatformHandle = nullptr; - llvm::StringRef Details = - OlResult->Details ? OlResult->Details : "No details provided"; - - // clang-format off - return llvm::createStringError( - llvm::Twine(Details) + - " (code " + llvm::Twine(OlResult->Code) + ")"); - // clang-format on - } - } - - return PlatformHandle; -} - void DeviceContext::launchKernelImpl( ol_symbol_handle_t KernelHandle, uint32_t NumGroups, uint32_t GroupSize, const void *KernelArgs, std::size_t KernelArgsSize) const noexcept {