Skip to content
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

[SYCL][PI] Fix PI unittests and always build them #585

Merged
merged 2 commits into from
Oct 14, 2019
Merged

[SYCL][PI] Fix PI unittests and always build them #585

merged 2 commits into from
Oct 14, 2019

Conversation

bjoernknafla
Copy link
Contributor

Enforce building of SYCL PI API unittests by default to catch build
problems due to CMake changes.

The PI API unittests use LLVM's add_unittest infrastructure which
only builds unittests if the CMake flag LLVM_BUILD_TESTS is ON.
The fix always sets this CMake variable locally when adding PI API
unittests.

This commit also contains other fixes required to build PI API
unittests again.

Signed-off-by: Bjoern Knafla [email protected]

@nyalloc nyalloc self-requested a review September 2, 2019 16:29
nyalloc
nyalloc previously approved these changes Sep 2, 2019
Copy link
Contributor

@nyalloc nyalloc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Ruyk
Ruyk previously approved these changes Sep 2, 2019
Copy link
Contributor

@Ruyk Ruyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think is important the PI API is always tested !

@bjoernknafla
Copy link
Contributor Author

@Ruyk With the change it will be build by default but it is not part of any check-... tests, so no testing will happen automatically. Testing requires calling the built tools/sycl/unittests/pi/PiTests executable.

bader
bader previously requested changes Sep 2, 2019
@bjoernknafla bjoernknafla dismissed stale reviews from Ruyk and nyalloc via be18556 September 4, 2019 15:08
add_subdirectory( tools )
if (NOT DEFINED LLVM_INCLUDE_TESTS)
set(LLVM_INCLUDE_TESTS ON)
endif()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aligns testing and unittests with other LLVM projects CMake usage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this as a comment too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit contains a comment that SYCL CMake is now stronger aligned with how the other LLVM projects are set up.

Other LLVM projects I checked do not comment on where they copied and adapted from other LLVM projects though it is clear that they are aligned.

add_custom_target(PiUnitTests)
set_target_properties(PiUnitTests PROPERTIES FOLDER "Tests")
add_custom_target(SYCLUnitTests)
set_target_properties(SYCLUnitTests PROPERTIES FOLDER "SYCL tests")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aligns testing and unittests with other LLVM projects CMake usage, e.g., Clang

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other LLVM projects I checked do not comment on where they copied and adapted from other LLVM projects though it is clear that they are aligned.

@bader bader requested a review from AlexeySachkov September 6, 2019 14:51
Copy link
Contributor

@keryell keryell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification!

add_subdirectory( tools )
if (NOT DEFINED LLVM_INCLUDE_TESTS)
set(LLVM_INCLUDE_TESTS ON)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this as a comment too.

add_custom_target(PiUnitTests)
set_target_properties(PiUnitTests PROPERTIES FOLDER "Tests")
add_custom_target(SYCLUnitTests)
set_target_properties(SYCLUnitTests PROPERTIES FOLDER "SYCL tests")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem.

@@ -0,0 +1,29 @@
@LIT_SITE_CFG_IN_HEADER@
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied and adapted from Clang.

@@ -0,0 +1,59 @@
# -*- Python -*-
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied and adapted from Clang.

${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aligning with Clang.

@bjoernknafla bjoernknafla requested a review from bader October 7, 2019 16:35
@bjoernknafla
Copy link
Contributor Author

buildbot/sycl-ubu-x64-pr does not run - do I need to do something specific to trigger it?

@smaslov-intel
Copy link
Contributor

Great thanks for doing this! The PI tests will be build always, but when/how are they run?

@smaslov-intel smaslov-intel self-requested a review October 9, 2019 03:40
smaslov-intel
smaslov-intel previously approved these changes Oct 9, 2019
@bjoernknafla
Copy link
Contributor Author

Great thanks for doing this! The PI tests will be build always, but when/how are they run?

@smaslov-intel This now works as in Clang and the other LLVM projects:

  • When SYCL testing is enabled with the CMake flag SYCL_INCLUDE_TESTS then the unittests are added as a dependency to the LIT tests (see CMake variable SYCL_TEST_DEPS).
  • This in itself ensures that the unittests are build when the other LIT tests are build, e.g., by running the build for the check-sycl target.
  • The LIT tests folder now has a Unit sub-folder which contains LIT config files that are gtest aware and are pointed to the unittests build directory to discover all included test executables to run.

@bjoernknafla
Copy link
Contributor Author

I have addressed the changes requested by @bader and resolved the discussion though GitHub has not marked the change request as resolved.

@smaslov-intel
Copy link
Contributor

Great thanks for doing this! The PI tests will be build always, but when/how are they run?

@smaslov-intel This now works as in Clang and the other LLVM projects:

  • When SYCL testing is enabled with the CMake flag SYCL_INCLUDE_TESTS then the unittests are added as a dependency to the LIT tests (see CMake variable SYCL_TEST_DEPS).
  • This in itself ensures that the unittests are build when the other LIT tests are build, e.g., by running the build for the check-sycl target.
  • The LIT tests folder now has a Unit sub-folder which contains LIT config files that are gtest aware and are pointed to the unittests build directory to discover all included test executables to run.

Thanks for the detailed explanation, but I still have these questions:

  1. is there any way to run (not only build) these PI tests during a build, how?
  2. how to run them outside of any build?

@romanovvlad romanovvlad dismissed bader’s stale review October 11, 2019 08:57

Comment is resolved.

@bjoernknafla
Copy link
Contributor Author

bjoernknafla commented Oct 11, 2019

1. is there any way to run (not only build) these PI tests during a build, how?

After configuring the project CMake (for example with the buildbot config script that now sets SYCL_INCLUDE_TEST=ON) run ninja check-sycl which will build and run the unittests as part of the check-sycl target. (Replace ninja with the build system of your choice or use CMake to run it, e.g., cmake --build /path/to/build/dir --target check-sycl

To only build and run the SYCL unittests use: ninja check-sycl-unit.

2. how to run them outside of any build?

Four ways (I know of):

  1. After a build run ninja check-sycl or ninja check-all. As the build has already been done the LIT tests will be run directly and the unittests are now part of the check-sycl target LIT test run.
  2. Only run the SYCL unittests after a build by calling ninja check-sycl-unit.
  3. Run LIT by hand, e.g., from inside the build directory:
  • ./bin/llvm-lit ./tools/sycl/test/Unit or
  • ./bin/llvm-lit --filter .*SYCL-Unit.* ./tools/sycl/test
  1. Run the unittests executable directly, e.g., from the build directory:
  • ./tools/sycl/unittests/pi/PiTests

@bjoernknafla
Copy link
Contributor Author

1. is there any way to run (not only build) these PI tests during a build, how?

After configuring the project CMake (for example with the buildbot config script that now sets SYCL_INCLUDE_TEST=ON) run ninja check-sycl which will build and run the unittests as part of the check-sycl target. (Replace ninja with the build system of your choice or use CMake to run it, e.g., cmake --build /path/to/build/dir --target check-sycl

There is no target to only build and run the SYCL unittests which is in-line with for example the Clang unittests.

I just noticed that this is not correct: for LLVM and Clang (and some other LLVM projects) special unit test targets exist, e.g.: check-llvm-unit and check-clang-unit - though I am not sure where these targets come from or how they are created...

@bjoernknafla
Copy link
Contributor Author

bjoernknafla commented Oct 11, 2019

I just noticed that this is not correct: for LLVM and Clang (and some other LLVM projects) special unit test targets exist, e.g.: check-llvm-unit and check-clang-unit - though I am not sure where these targets come from or how they are created...

I found it. I will push an update that enables a target called check-sycl-unit to build and run all SYCL unittests.

This update will also add build and run targets for all individual LIT tests of SYCL that you can list by doing the following on the command line:

ninja -t targets | grep check-sycl-

LLVM has two CMake options to include/build unittests:
* `LLVM_INCLUDE_TESTS` to generate CMake targets for all kind of
  testing, which is `ON` by default.
* `LLVM_BUILD_TESTS` to build the included unittests CMake targets,
  which is `OFF` by default.

Other LLVM projects introduce a `<PROJECT>_INCLUDE_TESTS` option to
control if CMake targets should be created for their different tests.
If their unittests are build by default is controlled by the
`LLVM_BUILD_TESTS` option.

This commit aligns SYCL testing and unittesting with other LLVM
projects, e.g.:

* introduces a `SYCL_INCLUDE_TESTS` option,
* renames the SYCL unittest suite to `SYCLUnitTests`, and
* introduces the `add_sycl_unittest` CMake function to simplify adding
  SYCL-specific unittests.
* Aligns naming of CMake unittest folder with Clang.
* Copies Clang unittest LIT infrastructure to SYCL unittests.
* Renames LIT testsuite names of SYCL to "SYCL" and
* names the unittests in LIT as "SYCL-Unit".
* Adapts other LLVM projects LIT config files naming scheme.
* Cleans up CMake variables used by LIT config `.in` files and aligns
  variable names stronger with other LLVM projects.
* Makes the SYCL unittests part of the `check-sycl` target, i.e., builds
  them on demand.
* Adds a CMake target to build/run every SYLC LIT test including unit
  tests with `check-sycl-unit`.

Signed-off-by: Bjoern Knafla <[email protected]>
SYCL examples, e.g., in the Khronos specs, include the SYCL header as
system headers.

Adapt includes in the `CL/sycl/detail/pi.hpp` header to this style.

Signed-off-by: Bjoern Knafla <[email protected]>
)
set_target_properties(check-sycl PROPERTIES FOLDER "SYCL tests")

add_lit_testsuites(SYCL ${CMAKE_CURRENT_SOURCE_DIR}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a check-sycl-<subdir> target for every sub-directory of sycl/test including for the Unit sub-directory which will run the unittests from sycl/unittests.

@@ -14,7 +14,7 @@
# Configuration file for the 'lit' test runner.

# name: The name of this test suite.
config.name = 'SYCLUnitTests'
config.name = 'SYCL'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in line with Clang now.

@smaslov-intel
Copy link
Contributor

Thanks @bjoernknafla.
I have no further questions at this point.

Just a comment that in a longer run pi::initialize() can see multiple PI plugins, and hence there should be a way in these PI tests to check running through all of them (or the one that is somehow forced).

@bjoernknafla
Copy link
Contributor Author

Just a comment that in a longer run pi::initialize() can see multiple PI plugins, and hence there should be a way in these PI tests to check running through all of them (or the one that is somehow forced).

Makes sense.

@romanovvlad romanovvlad merged commit 58ef151 into intel:sycl Oct 14, 2019
@bjoernknafla bjoernknafla deleted the bjoern/fix-pi-unittest-cmake branch October 29, 2019 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants