[llvm] WIP: [Offload] Add testing for Offload program and kernel related entry points (PR #127803)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 21 13:28:30 PST 2025
================
@@ -94,3 +95,53 @@ ol_platform_handle_t TestEnvironment::getPlatform() {
return Platform;
}
+
+// TODO: Define via cmake, also override via cmd line arg
+const std::string DeviceBinsDirectory = DEVICE_CODE_PATH;
+
+bool TestEnvironment::loadDeviceBinary(
+ const std::string &BinaryName, ol_platform_handle_t Platform,
+ std::shared_ptr<std::vector<char>> &BinaryOut) {
+
+ // Get the platform type
+ ol_platform_backend_t Backend = OL_PLATFORM_BACKEND_UNKNOWN;
+ olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND, sizeof(Backend),
+ &Backend);
+ std::string FileExtension;
+ if (Backend == OL_PLATFORM_BACKEND_AMDGPU) {
+ FileExtension = ".amdgpu.bin";
+ } else if (Backend == OL_PLATFORM_BACKEND_CUDA) {
+ FileExtension = ".nvptx64.bin";
+ } else {
+ errs() << "Unsupported platform type for a device binary test.\n";
+ return false;
+ }
+
+ std::string SourcePath =
+ DeviceBinsDirectory + "/" + BinaryName + FileExtension;
+
+ std::ifstream SourceFile;
+ SourceFile.open(SourcePath, std::ios::binary | std::ios::in | std::ios::ate);
+
+ if (!SourceFile.is_open()) {
----------------
jhuber6 wrote:
`llvm::MemoryBuffer::getFileOrSTDIN` is much easier to use and is backed by `mmap()` i believe.
https://github.com/llvm/llvm-project/pull/127803
More information about the llvm-commits
mailing list