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

Refactor build system #287

Merged
merged 107 commits into from Nov 14, 2022
Merged

Refactor build system #287

merged 107 commits into from Nov 14, 2022

Conversation

COM8
Copy link
Contributor

@COM8 COM8 commented May 11, 2022

Why this PR?

I have a couple of problems with the current way Kompute handles dependencies:

  1. git-Submodules are a rather outdated concept in my eyes and should be replaced since they are always a pain to use and are not flexible in any way.
  2. When including Kompute in a project that also uses Spdlog, it beaks a lot of stuff, e.g. Log-Macros stay in code, but we do not link Kompute against Spdlog.
  3. On my System (Fedora) Vulkan-Headers >= 1.3.0 are available, but my driver (mesa/intel) supports only >= 1.2.131. Well I need to link against a different version Vulkan-Headers without downgrading my System Vulkan-Headers since other applications depend on those. If I don't change the Vulkan-Header version, I always run into the following assertion: VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION );

Proposed Solutions

  • Replace git-Submodules with CMake fetch_content
    • This solves 1. and 3.
    • I also replaced KOMPUTE_OPT_REPO_SUBMODULE_BUILD with KOMPUTE_OPT_USE_BUILD_IN_{SPDLOG, VULKAN_HEADER, ...} and added a deprecation warning for the old way.
    • I added KOMPUTE_OPT_BUILD_IN_VULKAN_HEADER_TAG which allows consumers to set their specific Vulkan-Header version.
    • I added a check_vulkan_version to CMake that checks if your hardware supports for example Vulkan 1.3 if you link against Vulkan-Headers 1.3 and prints a warning if only the patch version of your hardware is < that the Vulkan-Header version. There is also an option to disable this: KOMPUTE_OPT_DISABLE_VULKAN_VERSION_CHECK
  • I also cleaned up all CMake options related to dependencies and fixed a few bugs here and there to solve 2.

What is left to do?

Things that need to be done once the PR has been merged

Let me know what you think about this.

@axsaucedo
Copy link
Member

Hey @COM8 - thank you for this PR, this all sounds great. Here's a couple of comments on the proposed actions:

  • Replace git-Submodules with CMake fetch_content

I haven't used FetchContent, but it does look quite good. It seems we'd need to bump CMAKE from min 3.4.x to 3.11.x, and make sure to mention this somewhere as defaults may be lower in older systems. Overall it does seem like a good step as it would avoid a common error that people don't init the submodules.

  • I also replaced KOMPUTE_OPT_REPO_SUBMODULE_BUILD with KOMPUTE_OPT_USE_BUILD_IN_{SPDLOG, VULKAN_HEADER, ...} and added a deprecation warning for the old way.

That sounds good. For naming it would be better to name it explicitly KOMPUTE_OPT_USE_FETCH_REPO_{...}, as otherwise "build in" sounds like "built-in" which implies it's internal as opposed to cloned.

  • I added KOMPUTE_OPT_BUILD_IN_VULKAN_HEADER_TAG which allows consumers to set their specific Vulkan-Header version.

This sounds good, I've been meaning to do this for a while. Will be good to make sure it's for both HPP and H headers.

  • I added a check_vulkan_version to CMake that checks if your hardware supports for example Vulkan 1.3 if you link against Vulkan-Headers 1.3 and prints a warning if only the patch version of your hardware is < that the Vulkan-Header version. There is also an option to disable this: KOMPUTE_OPT_DISABLE_VULKAN_VERSION_CHECK

This sounds good.

I also cleaned up all CMake options related to dependencies and fixed a few bugs here and there to solve 2.

Sounds good, would be good to explicitly list them in the PR description.

My main suggestion would be to do this in iterative chunks, as opposed to a massive PR, mainyl to avoid potentially a situation where there's too much at once. Only mentioning this as I've started to see some changes in the git jobs, which I actually do like, but mainly to break down into different PRs so it's simpler/smoother to merge.

@COM8
Copy link
Contributor Author

COM8 commented May 11, 2022

Agree with all of your points, Then I will keep this PR open as "current" stat and as soon as I'm happy with the result, I will create smaller PRs.

@COM8
Copy link
Contributor Author

COM8 commented May 18, 2022

When I tried splitting up my changes into multiple smaller PRs I noticed a lot of other stuff needing to be fixed. So basically I'm planing to do a rewrite of the complete build system over at my fork: https://github.com/COM8/kompute

This will roughly take me one month and since especially the Makefile stuff is not really portable I plan to integrate what ever possible directly into CMake e.g. compiling shaders: https://github.com/COM8/movement-sim/blob/main/cmake/vulkan_shader_compiler.cmake

I will the try to outline every breaking change I did and why it was necessary in a clear manner and try to get in touch with you in case I need to change anything large.

@axsaucedo
Copy link
Member

Ok interesting @COM8 - I would still be keen to look towards merging the initial improvements in an iterative way where possible, as I like already some of the ideas on moving away from git modules as that would already make it much better. Certianly if you do need a hand let me know - happy to help here, or you can also join the discord and I am active there for any questions

@COM8 COM8 changed the title [WIP] Replaced Submodules with fetch_content and CMake cleanup [WIP] Refactore build system May 19, 2022
@COM8
Copy link
Contributor Author

COM8 commented Jun 24, 2022

This PR is now ready for its first review.
Things that need to be done:

  • Update Android integration
  • Update GoDot integration
  • Python CI is timing out since it needs too much resources
  • Sign off commits
  • Windows CI - Working on it, but I cant get CMake to find the Vulkan installation: initial Windows CI setup COM8/kompute#1 Will be a separate PR
  • MacOS CI - Can be done in a different PR Will be a separate PR
  • What should we do with the Makefile? It's not required any more for normal use and contains only convenience helpers.

@COM8 COM8 marked this pull request as ready for review June 24, 2022 15:11
@axsaucedo axsaucedo changed the title [WIP] Refactore build system [WIP] Refactor build system Jun 25, 2022
Copy link
Member

@axsaucedo axsaucedo left a comment

Choose a reason for hiding this comment

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

Looks great @COM8 - thank you so much for investing the time to having an initial look, the work so far is great! Apologies I didn't get through this before, I actually completely missed your comment saying ti was ready for review - I have done a first pass of comments, overall the core additions are great in principle, the main things that we'll have to consider are:

  • Ensuring spdlog is still an optional dependency
  • Validate the need for helper components in the logger files
  • Discuss further the separation of various components into different libraries
  • Explore simplify the shader compilation (ie compile all shaders in a single folder instead of one by one)
  • Making shader compilation optional

Once again awesome effort - I will do a deeper dive later today, if you provide thoughts on the comments I can also provide deeper detial as required.

CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
docs/overview/shaders-to-headers.rst Show resolved Hide resolved
test/TestLogisticRegression.cpp Outdated Show resolved Hide resolved
test/shaders/CMakeLists.txt Show resolved Hide resolved
test/shaders/glsl/CMakeLists.txt Show resolved Hide resolved
src/logger/CMakeLists.txt Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
@axsaucedo
Copy link
Member

I'm currently testing locally and I'm getting

Cannot create Vulkan instance.
This problem is often caused by a faulty installation of the Vulkan driver or attempting to use a GPU that does not support Vulkan.
ERROR at /build/vulkan-tools-1.2.148.0-1ubuntu18.04/vulkaninfo/vulkaninfo.h:641:vkCreateInstance failed with ERROR_INCOMPATIBLE_DRIVER
CMake Error at cmake/check_vulkan_version.cmake:61 (string):
  string sub-command REGEX, mode MATCHALL needs at least 5 arguments total to
  command.
Call Stack (most recent call first):
  CMakeLists.txt:116 (check_vulkan_version)

Have you seen this before? Would it be due to the version of my vulkan setup?

@COM8
Copy link
Contributor Author

COM8 commented Jul 12, 2022

I'm currently testing locally and I'm getting

Cannot create Vulkan instance.
This problem is often caused by a faulty installation of the Vulkan driver or attempting to use a GPU that does not support Vulkan.
ERROR at /build/vulkan-tools-1.2.148.0-1ubuntu18.04/vulkaninfo/vulkaninfo.h:641:vkCreateInstance failed with ERROR_INCOMPATIBLE_DRIVER
CMake Error at cmake/check_vulkan_version.cmake:61 (string):
  string sub-command REGEX, mode MATCHALL needs at least 5 arguments total to
  command.
Call Stack (most recent call first):
  CMakeLists.txt:116 (check_vulkan_version)

Have you seen this before? Would it be due to the version of my vulkan setup?

Hmmm, I have never seen such an error before. But I see a potential error in cmake/check_vulkan_version.cmake:61 resulting from this "crash".

@COM8 COM8 requested a review from axsaucedo July 12, 2022 12:40
@axsaucedo
Copy link
Member

Just tried from the latest to build but it seems it gets frozen iwth infinite loop on:

...etc
--   KOMPUTE_OPT_BUILD_SHADERS: 1
--   KOMPUTE_OPT_USE_BUILD_IN_SPDLOG: ON
--   KOMPUTE_OPT_USE_BUILD_IN_FMT: ON
--   KOMPUTE_OPT_USE_BUILD_IN_GOOGLE_TEST: ON
--   KOMPUTE_OPT_USE_BUILD_IN_PYBIND11: ON
--   KOMPUTE_OPT_USE_BUILD_IN_VULKAN_HEADER: ON
--   KOMPUTE_OPT_BUILD_IN_VULKAN_HEADER_TAG: v1.2.203
-- =======================================================
-- Ensuring the currently installed driver supports the Vulkan version requested by the Vulkan Header.
-- Found Vulkan Header version 1.2.203.

Wondering if the trailing . could be causing an issue?

CMakeLists.txt Outdated Show resolved Hide resolved
docs/overview/shaders-to-headers.rst Show resolved Hide resolved
test/TestLogisticRegression.cpp Outdated Show resolved Hide resolved
Copy link
Member

@axsaucedo axsaucedo left a comment

Choose a reason for hiding this comment

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

Nice one - I added a couple more comments. Overall the new amendments are great. I have given it more thought on specifically the logger module, and added a few suggestions that may need rethinking on that part specifically.

CMakeLists.txt Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
cmake/bin_file_to_header.cmake Show resolved Hide resolved
cmake/check_vulkan_version.cmake Show resolved Hide resolved
src/include/kompute/Kompute.hpp Show resolved Hide resolved
src/logger/Logger.cpp Outdated Show resolved Hide resolved
src/logger/Logger.cpp Show resolved Hide resolved
src/logger/Logger.cpp Outdated Show resolved Hide resolved
src/shaders/glsl/ShaderOpMult.hpp.in Show resolved Hide resolved
test/shaders/glsl/CMakeLists.txt Show resolved Hide resolved
Copy link
Member

@axsaucedo axsaucedo left a comment

Choose a reason for hiding this comment

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

Nice one with updates, it seems it's getting closer, I was now able to run the build and start compiling some of the tests. I added a couple of extra comments and questions on build errors as well as how tests can be run. There's still the outstanding question on the logger, but as suggested we can discuss during the next community call - i also replied on the community discord with suggestion for other times that could work as an alternate. Let me know if you have any thoughts ahead of then.

test/CMakeLists.txt Outdated Show resolved Hide resolved
test/CMakeLists.txt Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
@COM8 COM8 requested a review from axsaucedo July 26, 2022 11:58
Makefile Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
python/src/utils.hpp Outdated Show resolved Hide resolved
@COM8
Copy link
Contributor Author

COM8 commented Sep 5, 2022

@axsaucedo Is there anything else I can do on this PR?

@axsaucedo
Copy link
Member

@COM8 thank you for following up - just pinged on Discord, I will be keen to merge soon, planning to do a pass asap in the next / following week

@axsaucedo
Copy link
Member

@COM8 I am thinking of merging this quite soon to make sure we can get the ball rolling on the rest of the PRs, however I can't seem to get the Android examples working unfortunately - are you able to run these example successfully on your end?

@COM8
Copy link
Contributor Author

COM8 commented Sep 16, 2022

Nope, never have tried compiling them for android since I have no toolchain set up for this. But I can try to set up one if this helps.

@axsaucedo
Copy link
Member

That would be great if you get a chance @COM8 - I will be diving into it during the weekend as well to get this and the rest of the examples working correctly, I want then to move towards merging so any further changes can be done from master as there's already also some other interesting PRs to explore (Such as upgrading to vulkan 1.3)

@COM8
Copy link
Contributor Author

COM8 commented Sep 18, 2022

ACK, will try to work on it during the next week.

@COM8
Copy link
Contributor Author

COM8 commented Sep 25, 2022

Quick update: I got it almost up and running. Just some minor things like fixing the Vulkan function templates still left to do.
Sadly I won't have too much time over the next three weeks while I'm finishing my thesis.
So this one might get delayed a bit. Sorry...

@axsaucedo
Copy link
Member

@COM8 that's fantastic news! It would be really helpful if you do manage to get it through as for some reason I'm still having issues in my set up - no worries at all tho, great to hear you're looking to finish/wrap your theses, hopefully I am able to finalise it before then but otherwise we can have a look once you get a chance again

Signed-off-by: Fabian Sauter <sauter.fabian@mailbox.org>
Signed-off-by: Fabian Sauter <sauter.fabian@mailbox.org>
@COM8 COM8 force-pushed the master branch 2 times, most recently from cf65cb6 to 6b6984a Compare October 27, 2022 12:23
Signed-off-by: Fabian Sauter <sauter.fabian@mailbox.org>
Signed-off-by: Fabian Sauter <sauter.fabian@mailbox.org>
@COM8
Copy link
Contributor Author

COM8 commented Oct 27, 2022

@axsaucedo it is done!
The android example builds again.
But when clicking on the button and when creating a kp::Manager it crashes with a segfault...

I'm looking into this one right now.

Could you please confirm quickly it's also building on your system?

Signed-off-by: Fabian Sauter <sauter.fabian@mailbox.org>
Signed-off-by: Fabian Sauter <sauter.fabian@mailbox.org>
@COM8 COM8 changed the title [WIP] Refactor build system Refactor build system Oct 28, 2022
@COM8
Copy link
Contributor Author

COM8 commented Oct 28, 2022

Done. Now everything works. Ready for a final review.

@axsaucedo
Copy link
Member

That's fantastic @COM8 ! I am just back from a conference this week so I will be able to review and rerun all the examples.

PS Hope everything went smooth with the thesis

@COM8
Copy link
Contributor Author

COM8 commented Nov 2, 2022

Great to hear. Yes, from my side everything worked perfectly!

Copy link
Member

@axsaucedo axsaucedo left a comment

Choose a reason for hiding this comment

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

@COM8 I have finally been able to test every single example and I have to say that this contribution is beyond fantastic - the additions and improvements to the project are really taking the project to the next level. I am very keen on expanding from this great work, I will highlight this contribution with the linux foundation group, and it gets us a significant step closer to full graduation as a project.

Thank you very much for persevering on this great contribution Fabian, it's a truly appreciated contribution!

# Consume Kompute via CMake fetch_content
include(FetchContent)
FetchContent_Declare(kompute GIT_REPOSITORY https://github.com/KomputeProject/kompute.git
GIT_TAG f4d72e2aa7b23ffe05d5ea3191bf72ad00def0ec) # The commit hash for a dev version before v0.9.0. Replace with the latest from: https://github.com/KomputeProject/kompute/releases
Copy link
Member

Choose a reason for hiding this comment

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

TODO replace once this is in master

set(VK_ANDROID_INCLUDE_DIR ${ANDROID_NDK}/sources/third_party/vulkan/src/include)
include(FetchContent)
FetchContent_Declare(kompute GIT_REPOSITORY https://github.com/COM8/kompute.git
GIT_TAG 675f6dc771cea044ead99a5467a9b817c2d8feb6) # The commit hash for a dev version before v0.9.0. Replace with the latest from: https://github.com/KomputeProject/kompute/releases
Copy link
Member

Choose a reason for hiding this comment

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

TODO: as comment suggests we'll replace with tag

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.

None yet

2 participants