-
Notifications
You must be signed in to change notification settings - Fork 790
[SYCL] Initial PI API unit test setup #407
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
add_custom_target(PiUnitTests) | ||
set_target_properties(PiUnitTests PROPERTIES FOLDER "Tests") | ||
|
||
function(add_llvm_unittest test_dirname) | ||
nyalloc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
add_unittest(PiUnitTests ${test_dirname} ${ARGN}) | ||
endfunction() | ||
|
||
function(add_llvm_unittest_with_input_files test_dirname) | ||
add_unittest_with_input_files(PiUnitTests ${test_dirname} ${ARGN}) | ||
endfunction() | ||
|
||
add_subdirectory(pi) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
|
||
# Enable exception handling for these unit tests | ||
set(LLVM_REQUIRES_EH 1) | ||
add_llvm_unittest(PiTests | ||
PlatformTest.cpp | ||
) | ||
|
||
add_dependencies(PiTests sycl) | ||
target_link_libraries(PiTests PRIVATE sycl LLVMTestingSupport) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//==---- PlatformTest.cpp --- PI unit tests --------------------------------==// | ||
// | ||
// 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 "CL/sycl/detail/pi.hpp" | ||
#include <CL/sycl.hpp> | ||
#include <gtest/gtest.h> | ||
#include <memory> | ||
|
||
using namespace cl::sycl; | ||
|
||
namespace pi { | ||
class PlatformTest : public ::testing::Test { | ||
protected: | ||
|
||
constexpr static size_t out_string_size = | ||
8192u; // Using values from OpenCL CTS clGetPlatforms test | ||
|
||
PlatformTest() { detail::pi::piInitialize(); } | ||
|
||
~PlatformTest() = default; | ||
}; | ||
|
||
TEST_F(PlatformTest, piPlatformsGet) { | ||
pi_uint32 platformCount = 0; | ||
|
||
ASSERT_EQ(PI_CALL_RESULT(RT::piPlatformsGet(0, 0, &platformCount)), | ||
PI_SUCCESS) | ||
<< "piPlatformsGet failed"; | ||
|
||
ASSERT_GT(platformCount, 0) << "piPlatformsGet found 0 platforms.\n"; | ||
|
||
std::vector<pi_platform> platforms(platformCount); | ||
|
||
ASSERT_EQ(PI_CALL_RESULT( | ||
RT::piPlatformsGet(platformCount, platforms.data(), nullptr)), | ||
PI_SUCCESS) | ||
<< "piPlatformsGet failed with nullptr for return size.\n"; | ||
} | ||
|
||
TEST_F(PlatformTest, piPlatformGetInfo) { | ||
auto get_info_test = [](char *out_string, pi_platform platform, | ||
_pi_platform_info info) { | ||
|
||
auto info_name = detail::pi::platformInfoToString(info); | ||
|
||
size_t reported_string_length = 0; | ||
memset(out_string, 0, out_string_size); | ||
|
||
ASSERT_EQ(PI_CALL_RESULT(RT::piPlatformGetInfo(platform, info, | ||
out_string_size, out_string, | ||
&reported_string_length)), | ||
PI_SUCCESS) | ||
<< "piPlatformGetInfo for " << info_name << " failed.\n"; | ||
|
||
auto returned_string_length = strlen(out_string) + 1; | ||
|
||
EXPECT_EQ(returned_string_length, reported_string_length) | ||
<< "Returned string length " << returned_string_length | ||
<< " does not equal reported string length " << reported_string_length | ||
<< ".\n"; | ||
}; | ||
|
||
pi_uint32 platformCount = 0; | ||
PI_CALL(RT::piPlatformsGet(0, 0, &platformCount)); | ||
std::vector<pi_platform> platforms(platformCount); | ||
PI_CALL(RT::piPlatformsGet(platformCount, platforms.data(), nullptr)); | ||
|
||
auto out_string_buffer = std::unique_ptr<char[]>(new char[out_string_size]); | ||
auto out_string = out_string_buffer.get(); | ||
|
||
for (auto i = 0u; i < platformCount; ++i) { | ||
const auto &platform = platforms[i]; | ||
get_info_test(out_string, platform, PI_PLATFORM_INFO_NAME); | ||
get_info_test(out_string, platform, PI_PLATFORM_INFO_VENDOR); | ||
get_info_test(out_string, platform, PI_PLATFORM_INFO_PROFILE); | ||
get_info_test(out_string, platform, PI_PLATFORM_INFO_VERSION); | ||
get_info_test(out_string, platform, PI_PLATFORM_INFO_EXTENSIONS); | ||
} | ||
} | ||
} // Namespace |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.