[llvm] [Offload] Add framework for math conformance tests (PR #149242)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 17 09:31:35 PDT 2025
================
@@ -0,0 +1,121 @@
+#pragma once
+
+#include "mathtest/DeviceResources.hpp"
+#include "mathtest/Dim.hpp"
+#include "mathtest/ErrorHandling.hpp"
+#include "mathtest/Support.hpp"
+
+#include "llvm/ADT/StringRef.h"
+
+#include <cassert>
+#include <cstddef>
+#include <memory>
+#include <string>
+#include <tuple>
+#include <type_traits>
+#include <utility>
+
+namespace mathtest {
+
+std::size_t countDevices();
+
+namespace detail {
+
+void allocManagedMemory(ol_device_handle_t DeviceHandle, std::size_t Size,
+ void **AllocationOut) noexcept;
+} // namespace detail
+
+class DeviceContext {
+ // For simplicity, the current design of this class doesn't have support for
+ // asynchronous operations and all types of memory allocation.
+ //
+ // Other use cases could benefit from operations like enqueued kernel launch
+ // and enqueued memcpy, as well as device and host memory allocation.
+
+public:
+ // TODO: Add a constructor that also takes a 'Provider'.
+ explicit DeviceContext(std::size_t DeviceId = 0);
+
+ template <typename T>
+ ManagedBuffer<T> createManagedBuffer(std::size_t Size) const noexcept {
+ void *UntypedAddress = nullptr;
+
+ detail::allocManagedMemory(DeviceHandle, Size * sizeof(T), &UntypedAddress);
+ T *TypedAddress = static_cast<T *>(UntypedAddress);
+
+ return ManagedBuffer<T>(TypedAddress, Size);
+ }
+
+ [[nodiscard]] std::shared_ptr<DeviceImage>
+ loadBinary(llvm::StringRef Directory, llvm::StringRef BinaryName,
+ llvm::StringRef Extension) const;
+
+ [[nodiscard]] std::shared_ptr<DeviceImage>
+ loadBinary(llvm::StringRef Directory, llvm::StringRef BinaryName) const;
+
+ template <typename KernelSignature>
+ DeviceKernel<KernelSignature>
+ getKernel(const std::shared_ptr<DeviceImage> &Image,
+ llvm::StringRef KernelName) const noexcept {
+ assert(Image && "Image provided to getKernel is null");
+
+ if (Image->DeviceHandle != this->DeviceHandle) {
----------------
jhuber6 wrote:
Here and elsewhere, blocks with one line don't need braces as per LLVM style.
https://github.com/llvm/llvm-project/pull/149242
More information about the llvm-commits
mailing list