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

[REVIEW] Clean Up #include Dependencies #3402

Merged
merged 31 commits into from
Feb 5, 2021

Conversation

mdemoret-nv
Copy link
Contributor

Closes #3376

This PR moves a few header files around to fix bad dependencies from include -> src. Moving forward, the only allowed #include direction will be:

  • src -> include
  • src -> src_prims
  • src_prims -> include

To facilitate this, a few changes needed to be made:

  1. Functions for the C-API have been separated into their own *_api.cpp file (some were combined with C++ files)
  2. host_buffer, device_buffer, hostAllocator and deviceAllocator were moved from src_prims to include
  3. #include <common/cumlHandle.hpp> has been removed from all C++ files.

This PR includes some additional improvements:

  • Updated the include_checker.py script:
    • Added functionality to check for badly placed #pragma once
    • Added functionality to fix some of the existing warnings
    • General refactor to support more checks
  • Fixed all incorrect uses of #pragma once
  • Fixed incorrect uses of using namespace ... in header files outside of a namespace
  • Removed some unnecessary #include

While this touches a lot of files, the actual number of changes is relatively small. Below is a before/after comparison of the include graphs:

src/include:
Before:
image
After:
image

src/src_prims:
Before:
image
After:
image

@mdemoret-nv mdemoret-nv added bug Something isn't working 2 - In Progress Currenty a work in progress CUDA / C++ CUDA issue Build or Dep Issues related to building the code or dependencies Tech Debt Issues related to debt non-breaking Non-breaking change labels Jan 23, 2021
@mdemoret-nv mdemoret-nv requested review from a team as code owners January 23, 2021 00:57
@mdemoret-nv mdemoret-nv changed the title [WIP] Clean Up #include Dependencies [REVIEW] Clean Up #include Dependencies Jan 29, 2021
Copy link
Contributor

@JohnZed JohnZed left a comment

Choose a reason for hiding this comment

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

I read the python and cmakelists files in some detail, but went pretty quickly over the headers. Headers look good. Just a couple small changes to check out. Let's discuss timing separately.

cpp/scripts/include_checker.py Outdated Show resolved Hide resolved
cpp/scripts/include_checker.py Outdated Show resolved Hide resolved
cpp/scripts/include_checker.py Outdated Show resolved Hide resolved
cpp/scripts/include_checker.py Outdated Show resolved Hide resolved
cpp/src/knn/knn_mg.cu Outdated Show resolved Hide resolved
cpp/include/cuml/cluster/dbscan_api.h Outdated Show resolved Hide resolved
Copy link
Member

@teju85 teju85 left a comment

Choose a reason for hiding this comment

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

It is finally great to see our C-API also evolving!

cpp/include/cuml/cluster/dbscan_api.h Outdated Show resolved Hide resolved
cpp/src/knn/knn_api.cpp Outdated Show resolved Hide resolved
cpp/src/knn/knn_api.cpp Outdated Show resolved Hide resolved
cpp/include/cuml/neighbors/knn_api.h Show resolved Hide resolved
@mdemoret-nv
Copy link
Contributor Author

After reviewing @teju85 comments, I've updated the C-API structure a bit and added back in the #ifdef __cplusplus to the C-API headers. I was under the impression we were actually building the C-API with gcc which would make these #ifdefs moot. However, it looks like we are actually using g++ and relying on the extern "C" to not mangle the names. This was interesting to discover since it was very unlikely any C program could actually use the C-API headers in their previous state.

To ensure the C-API can actually be used, I added a simple test library that is compiled only in C and imports libcuml.so. This flushed out a lot of errors that would have prevented anyone from using the C-API.

I would appreciate a re-review on the updated changes if possible. I still believe this PR is low ris because most changes are to #include statements which allows us to rely on the compiler to ensure everything is correct.

Copy link
Member

@dantegd dantegd left a comment

Choose a reason for hiding this comment

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

Just left 2 suggestions but changes, particularly the new C api tests look great!

cpp/bench/CMakeLists.txt Outdated Show resolved Hide resolved
cpp/include/cuml/cuml_api.h Show resolved Hide resolved
Copy link
Contributor

@JohnZed JohnZed 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, just one question (and one tiny change). You flipped a couple of includes from absolute to relative and others from relative to absolute. How should we think about the simplest rule for when to prefer absolute or relative #includes?

cpp/cmake/Dependencies.cmake Outdated Show resolved Hide resolved
cpp/include/cuml/cuml_api.h Show resolved Hide resolved
cpp/src_prims/sparse/distance/l2_distance.cuh Show resolved Hide resolved
@mdemoret-nv
Copy link
Contributor Author

Looks great, just one question (and one tiny change). You flipped a couple of includes from absolute to relative and others from relative to absolute. How should we think about the simplest rule for when to prefer absolute or relative #includes?

@JohnZed The changes between relative and absolute were due to the script include_checker.py which has an --inplace option. Relative includes should only be used if you jump <2 directories in a single direction. Everything else should be absolute. For example:

  • #include ../../my_header.hpp
    • This is ok because we only jump 2 directories
  • #include ../distance/my_header.hpp
    • This should be avoided (and will be corrected by the script) because we are going up one and over one. Convert to absolute.

While these rules are the ones the include_checker.py script will change, I have been working on a comprehensive set of rules that we should adopt as part of a larger rework of the include structure (that Will and I have been looking at to improve compilation speed). Between the include_checker.py script and clang-format version 10, almost all of this can be automated and could be run in the style check

@mdemoret-nv
Copy link
Contributor Author

rerun tests

Copy link
Member

@teju85 teju85 left a comment

Choose a reason for hiding this comment

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

Yes, @mdemoret-nv you are right. For the libraries which expose a C-API, but use g++ (for whatever reasons), we'll have to put these __cplusplus guards. Thank you for fixing it.

Really appreciate you adding a C-API testing in here!

LGTM.

@JohnZed
Copy link
Contributor

JohnZed commented Feb 5, 2021

@gpucibot merge

@rapids-bot rapids-bot bot merged commit d49dd1a into rapidsai:branch-0.18 Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 - In Progress Currenty a work in progress bug Something isn't working Build or Dep Issues related to building the code or dependencies CMake CUDA / C++ CUDA issue libcuml non-breaking Non-breaking change Tech Debt Issues related to debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Clean Up #include Dependencies
4 participants