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

BUILD: Help cmake find UCX on system #7096

Merged
merged 1 commit into from
Jul 17, 2021
Merged

Conversation

zasdfgbnm-nvidia
Copy link
Contributor

This PR makes the installation script writes cmake config files to ${prefix}/lib/cmake/ucx so that cmake projects can easily find UCX installed on the system. PyTorch uses cmake, so this will be helpful for PyTorch to integrate the ucx/ucc backend to upstream.

This PR is tested by: https://github.com/zasdfgbnm/cmake-ucx-ucc, please let me know if you want cmake testes to be included in this repository as well.

Related: openucx/ucc#255

@swx-jenkins3
Copy link
Collaborator

Can one of the admins verify this patch?

Copy link
Contributor

@yosefe yosefe left a comment

Choose a reason for hiding this comment

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

shall we add it to rpm/deb files as well?

cmake/ucx-config-version.cmake.in Show resolved Hide resolved
# Copyright (C) NVIDIA Corporation. 2021. ALL RIGHTS RESERVED.
#

set(UCX_LIBRARIES "@prefix@/lib")
Copy link
Contributor

Choose a reason for hiding this comment

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

@libdir@ (it could be lib64)

Choose a reason for hiding this comment

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

@libdir@ will be replaced by ${exec_prefix}/lib, but in the context of cmake, exec_prefix is not defined. But I can do something like

set(prefix "@prefix@")
set(exec_prefix "@exec_prefix@")

set_target_properties(ucx::ucs PROPERTIES
  IMPORTED_LOCATION "@libdir@/libucs.so"
  INTERFACE_INCLUDE_DIRECTORIES "@includedir@"
)

add_library(ucx::ucs SHARED IMPORTED)

set_target_properties(ucx::ucs PROPERTIES
IMPORTED_LOCATION "@prefix@/lib/libucs.so"
Copy link
Contributor

Choose a reason for hiding this comment

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

@libdir@ instead of @prefix/lib in all places


set_target_properties(ucx::ucp PROPERTIES
IMPORTED_LOCATION "@prefix@/lib/libucp.so"
INTERFACE_INCLUDE_DIRECTORIES "@prefix@/include"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is also @includedir

@zasdfgbnm
Copy link

With this PR it is automatically added to the deb package. I don't know about rpm, but it should be automatic as well.

cmake/ucx-config-version.cmake.in Show resolved Hide resolved
Comment on lines 5 to 6
set(prefix "@prefix@")
set(exec_prefix "@exec_prefix@")
Copy link
Contributor

Choose a reason for hiding this comment

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

since we include ucx-targets.cmake, can avoid re-defining prefix and exec_prefix?
BTW, why need to separate to 2 cmake files (ucx-config and ucx-targets)?

Choose a reason for hiding this comment

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

I have updated this PR to avoid redefinition. There are two separate files because other projects do so. I guess this is how cmake generates these files (See https://cmake.org/cmake/help/git-stage/guide/importing-exporting/index.html#exporting-targets-from-the-build-tree). But I don't know if this separation is required or not.

Comment on lines 6 to 11
cmake_DATA = \
ucx-targets.cmake \
ucx-config.cmake \
ucx-config-version.cmake
Copy link
Contributor

Choose a reason for hiding this comment

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

pls remove horizontal spaces before \

Choose a reason for hiding this comment

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

removed

@yosefe
Copy link
Contributor

yosefe commented Jul 15, 2021

With this PR it is automatically added to the deb package. I don't know about rpm, but it should be automatic as well.
https://dev.azure.com/ucfconsort/ucx/_build/results?buildId=21404&view=logs&jobId=388a871c-1c79-55fb-9b87-030460a06453&j=8cc70074-80e3-506d-e80d-a542b02430e7&t=da02301d-00be-54d1-aa97-9bf0b310a3f6

There is build error from RPM:

Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/swx-azure-svc_azpcontainer/21404-20210715.10/build/_rpm
error: Installed (but unpackaged) file(s) found:
   /usr/lib64/cmake/ucx/ucx-config-version.cmake
   /usr/lib64/cmake/ucx/ucx-config.cmake
   /usr/lib64/cmake/ucx/ucx-targets.cmake
    Installed (but unpackaged) file(s) found:
   /usr/lib64/cmake/ucx/ucx-config-version.cmake
   /usr/lib64/cmake/ucx/ucx-config.cmake
   /usr/lib64/cmake/ucx/ucx-targets.cmake

@zasdfgbnm
Copy link

@yosefe The rpm problem should be fixed now.

@yosefe
Copy link
Contributor

yosefe commented Jul 15, 2021

@zasdfgbnm-nvidia BTW, maybe it's worth adding a small test for cmake?
e.g in buildlib/builds.sh add a step which:

  1. make install (into build-test/installs)
  2. add CMakeLists.txt with find_package(ucx)
  3. run cmake in some dummy folder and make sure UCX is found (from cmake output)?
  4. this will also serve as demo of how to use UCX with Cmake

@zasdfgbnm
Copy link

@yosefe Yes, I think it is worth it. I will copy-paste https://github.com/zasdfgbnm/cmake-ucx-ucc/tree/master/Tests/ucx to this repository and take a look at how to add it to CI here.

@yosefe
Copy link
Contributor

yosefe commented Jul 15, 2021

@zasdfgbnm one option is to copy-paste this to examples/cmake and run it from buildlib/builds.sh (which is part of "build-on-all-containers" stage)

Comment on lines 333 to 334
cd /tmp/cmake-ucx
cmake --build .
Copy link
Contributor

Choose a reason for hiding this comment

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

need to return to previous directory after the test

Comment on lines 7 to 20
ucp_context_h ucp_context;
ucp_params_t ucp_params;
memset(&ucp_params, 0, sizeof(ucp_params));
ucp_params.field_mask = UCP_PARAM_FIELD_FEATURES;
ucp_params.features = UCP_FEATURE_AM;
ucs_status_t status = ucp_init(&ucp_params, NULL, &ucp_context);
assert(status == UCS_OK);
Copy link
Contributor

@yosefe yosefe Jul 15, 2021

Choose a reason for hiding this comment

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

{
    ucp_params_t ucp_params = {};
    ucp_context_h ucp_context;
    ucs_status_t status;

    ucp_params.field_mask = UCP_PARAM_FIELD_FEATURES;
    ucp_params.features   = UCP_FEATURE_AM;
    status = ucp_init(&ucp_params, NULL, &ucp_context);
    assert(status == UCS_OK);

    ucp_cleanup(ucp_context)
    return 0;
}

assert(UCS_OK == status);

/* Create a worker object */
status = uct_worker_create(async, UCS_THREAD_MODE_SINGLE, &worker);
Copy link
Contributor

Choose a reason for hiding this comment

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

pls destroy the created objects and return 0

Choose a reason for hiding this comment

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

Added

@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.5)
Copy link
Contributor

Choose a reason for hiding this comment

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

need to add NVIDIA copyright

Choose a reason for hiding this comment

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

Added

@@ -0,0 +1,14 @@
#include <ucp/api/ucp.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

need to add NVIDIA copyright

Choose a reason for hiding this comment

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

Added

@@ -0,0 +1,16 @@
#include <uct/api/uct.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

need to add NVIDIA copyright

Choose a reason for hiding this comment

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

Added

@yosefe
Copy link
Contributor

yosefe commented Jul 15, 2021

+ mkdir -p /tmp/cmake-ucx
+ cmake -DUCX_DIR=/home/swx-azure-svc_azpcontainer/21448-20210715.19/build/install -S examples/cmake -B /tmp/cmake-ucx
CMake Error: The source directory "/tmp/cmake-ucx" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.

@zasdfgbnm
Copy link

zasdfgbnm commented Jul 15, 2021

The cmake in CI is super old (2.8), the latest is 3.21, that's why it fails with

The source directory "/tmp/cmake-ucx" does not appear to contain CMakeLists.txt.

I have changed the

cmake_minimum_required(VERSION 3.5)

in the example to

cmake_minimum_required(VERSION 2.8)

Let's see if it works now. If not, I recommend upgrading the cmake, instead of writing workarounds to support old versions.

@yosefe
Copy link
Contributor

yosefe commented Jul 15, 2021

The cmake in CI is super old (2.8), the latest is 3.21, that's why it fails with

The source directory "/tmp/cmake-ucx" does not appear to contain CMakeLists.txt.

I have changed the

cmake_minimum_required(VERSION 3.5)

in the example to

cmake_minimum_required(VERSION 2.8)

Let's see if it works now. If not, I recommend upgrading the cmake, instead of writing workarounds to support old versions.

The CI is running on multiple different systems per the required support matrix. In this case, can skip this particular test if cmake version on the system is too old.

build_cmake_examples() {
echo "==== Build CMake sample ===="

${WORKSPACE}/contrib/configure-release --prefix=$ucx_inst
Copy link
Contributor

Choose a reason for hiding this comment

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

if which cmake
then 
   ... (the current test script)
else
    azure_log_warning "cmake executable not found, skipping cmake test"
fi

@zasdfgbnm
Copy link

Test failures seem unrelated

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.

4 participants