-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[Offload] Implement 'olIsValidBinary' in offload and clean up #159658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -899,6 +899,15 @@ Error olCreateProgram_impl(ol_device_handle_t Device, const void *ProgData, | |
| return Error::success(); | ||
| } | ||
|
|
||
| Error olIsValidBinary_impl(ol_device_handle_t Device, const void *ProgData, | ||
| size_t ProgDataSize, bool *IsValid) { | ||
| // Make a copy of the program binary in case it is released by the caller. | ||
|
||
| StringRef Buffer(reinterpret_cast<const char *>(ProgData), ProgDataSize); | ||
| *IsValid = Device->Device->Plugin.isDeviceCompatible( | ||
| Device->Device->getDeviceId(), Buffer); | ||
| return Error::success(); | ||
| } | ||
|
|
||
| Error olDestroyProgram_impl(ol_program_handle_t Program) { | ||
| auto &Device = Program->Image->getDevice(); | ||
| if (auto Err = Device.unloadBinary(Program->Image)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| //===------- Offload API tests - olIsValidBinary --------------------------===// | ||
| // | ||
| // 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 "../common/Fixtures.hpp" | ||
| #include <OffloadAPI.h> | ||
| #include <gtest/gtest.h> | ||
|
|
||
| using olIsValidBinaryTest = OffloadDeviceTest; | ||
jhuber6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olIsValidBinaryTest); | ||
|
|
||
| TEST_P(olIsValidBinaryTest, Success) { | ||
|
|
||
| std::unique_ptr<llvm::MemoryBuffer> DeviceBin; | ||
| ASSERT_TRUE(TestEnvironment::loadDeviceBinary("foo", Device, DeviceBin)); | ||
| ASSERT_GE(DeviceBin->getBufferSize(), 0lu); | ||
|
|
||
| bool IsValid = false; | ||
| ASSERT_SUCCESS(olIsValidBinary(Device, DeviceBin->getBufferStart(), | ||
| DeviceBin->getBufferSize(), &IsValid)); | ||
| ASSERT_TRUE(IsValid); | ||
|
|
||
jhuber6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ASSERT_SUCCESS( | ||
| olIsValidBinary(Device, DeviceBin->getBufferStart(), 0, &IsValid)); | ||
| ASSERT_FALSE(IsValid); | ||
|
|
||
| ASSERT_ERROR( | ||
| OL_ERRC_INVALID_NULL_POINTER, | ||
| olIsValidBinary(Device, nullptr, DeviceBin->getBufferSize(), &IsValid)); | ||
| ASSERT_FALSE(IsValid); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer
olIsCompatibleBinary; an ELF file (for example) can be a perfectly valid file yet not be compatible with the device.