Skip to content

Commit

Permalink
Merge branch 'branch-24.08' of https://github.com/rapidsai/cugraph in…
Browse files Browse the repository at this point in the history
…to fea_biased_sampling
  • Loading branch information
seunghwak committed Jun 24, 2024
2 parents d159215 + 34f8471 commit 5b659e2
Show file tree
Hide file tree
Showing 34 changed files with 881 additions and 117 deletions.
8 changes: 7 additions & 1 deletion ci/build_wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ fi

cd "${package_dir}"

python -m pip wheel . -w dist -vvv --no-deps --disable-pip-version-check
python -m pip wheel \
-w dist \
-vvv \
--no-deps \
--disable-pip-version-check \
--extra-index-url https://pypi.nvidia.com \
.

# pure-python packages should be marked as pure, and not have auditwheel run on them.
if [[ ${package_name} == "nx-cugraph" ]] || \
Expand Down
6 changes: 5 additions & 1 deletion ci/build_wheel_cugraph.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, NVIDIA CORPORATION.

set -euo pipefail

Expand All @@ -12,6 +12,10 @@ RAPIDS_PY_CUDA_SUFFIX="$(rapids-wheel-ctk-name-gen ${RAPIDS_CUDA_VERSION})"
RAPIDS_PY_WHEEL_NAME=pylibcugraph_${RAPIDS_PY_CUDA_SUFFIX} rapids-download-wheels-from-s3 ./local-pylibcugraph
export PIP_FIND_LINKS=$(pwd)/local-pylibcugraph

PARALLEL_LEVEL=$(python -c \
"from math import ceil; from multiprocessing import cpu_count; print(ceil(cpu_count()/4))")

export SKBUILD_CMAKE_ARGS="-DDETECT_CONDA_ENV=OFF;-DFIND_CUGRAPH_CPP=OFF;-DCPM_cugraph-ops_SOURCE=${GITHUB_WORKSPACE}/cugraph-ops/"
export SKBUILD_BUILD_TOOL_ARGS="-j${PARALLEL_LEVEL};-l${PARALLEL_LEVEL}"

./ci/build_wheel.sh cugraph python/cugraph
6 changes: 5 additions & 1 deletion ci/build_wheel_pylibcugraph.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/bash
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, NVIDIA CORPORATION.

set -euo pipefail

PARALLEL_LEVEL=$(python -c \
"from math import ceil; from multiprocessing import cpu_count; print(ceil(cpu_count()/4))")

export SKBUILD_CMAKE_ARGS="-DDETECT_CONDA_ENV=OFF;-DFIND_CUGRAPH_CPP=OFF;-DCPM_cugraph-ops_SOURCE=${GITHUB_WORKSPACE}/cugraph-ops/"
export SKBUILD_BUILD_TOOL_ARGS="-j${PARALLEL_LEVEL};-l${PARALLEL_LEVEL}"

./ci/build_wheel.sh pylibcugraph python/pylibcugraph
15 changes: 5 additions & 10 deletions ci/test_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ rapids-mamba-retry install \
rapids-logger "Check GPU usage"
nvidia-smi

export LD_PRELOAD="${CONDA_PREFIX}/lib/libgomp.so.1"

# RAPIDS_DATASET_ROOT_DIR is used by test scripts
export RAPIDS_DATASET_ROOT_DIR="$(realpath datasets)"
pushd "${RAPIDS_DATASET_ROOT_DIR}"
Expand Down Expand Up @@ -191,6 +193,8 @@ if [[ "${RAPIDS_CUDA_VERSION}" == "11.8.0" ]]; then
conda activate test_cugraph_pyg
set -u

rapids-print-env

# TODO re-enable logic once CUDA 12 is testable
#if [[ "${RAPIDS_CUDA_VERSION}" == "11.8.0" ]]; then
CONDA_CUDA_VERSION="11.8"
Expand All @@ -204,18 +208,9 @@ if [[ "${RAPIDS_CUDA_VERSION}" == "11.8.0" ]]; then
rapids-mamba-retry install \
--channel "${CPP_CHANNEL}" \
--channel "${PYTHON_CHANNEL}" \
--channel pytorch \
--channel pyg \
--channel nvidia \
"cugraph-pyg" \
"pytorch=2.1.0" \
"pytorch-cuda=${CONDA_CUDA_VERSION}"

# Install pyg dependencies (which requires pip)

pip install \
ogb \
tensordict
"ogb"

pip install \
pyg_lib \
Expand Down
1 change: 0 additions & 1 deletion ci/test_wheel_cugraph-pyg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ rapids-retry python -m pip install \
pyg_lib \
torch_scatter \
torch_sparse \
tensordict \
-f ${PYG_URL}

rapids-logger "pytest cugraph-pyg (single GPU)"
Expand Down
7 changes: 6 additions & 1 deletion ci/test_wheel_nx-cugraph.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/bash
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, NVIDIA CORPORATION.

set -eoxu pipefail

# Download wheels built during this job.
RAPIDS_PY_CUDA_SUFFIX="$(rapids-wheel-ctk-name-gen ${RAPIDS_CUDA_VERSION})"
RAPIDS_PY_WHEEL_NAME="pylibcugraph_${RAPIDS_PY_CUDA_SUFFIX}" rapids-download-wheels-from-s3 ./local-deps
python -m pip install ./local-deps/*.whl

./ci/test_wheel.sh nx-cugraph python/nx-cugraph
3 changes: 2 additions & 1 deletion conda/environments/all_cuda-118_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies:
- numpy>=1.23,<2.0a0
- numpydoc
- nvcc_linux-64=11.8
- openmpi
- openmpi<5.0.3
- packaging>=21
- pandas
- pre-commit
Expand All @@ -56,6 +56,7 @@ dependencies:
- pytest-mpl
- pytest-xdist
- python-louvain
- pytorch>=2.0,<2.2.0a0
- raft-dask==24.8.*
- rapids-dask-dependency==24.8.*
- recommonmark
Expand Down
3 changes: 2 additions & 1 deletion conda/environments/all_cuda-122_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ dependencies:
- numba>=0.57
- numpy>=1.23,<2.0a0
- numpydoc
- openmpi
- openmpi<5.0.3
- packaging>=21
- pandas
- pre-commit
Expand All @@ -61,6 +61,7 @@ dependencies:
- pytest-mpl
- pytest-xdist
- python-louvain
- pytorch>=2.0,<2.2.0a0
- raft-dask==24.8.*
- rapids-dask-dependency==24.8.*
- recommonmark
Expand Down
2 changes: 1 addition & 1 deletion conda/recipes/libcugraph/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ requirements:
- {{ compiler('cxx') }}
- cmake {{ cmake_version }}
- ninja
- openmpi # Required for building cpp-mgtests (multi-GPU tests)
- openmpi<5.0.3 # Required for building cpp-mgtests (multi-GPU tests)
- {{ stdlib("c") }}
host:
{% if cuda_major == "11" %}
Expand Down
2 changes: 2 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,11 @@ set(CUGRAPH_SOURCES
src/link_prediction/jaccard_sg.cu
src/link_prediction/sorensen_sg.cu
src/link_prediction/overlap_sg.cu
src/link_prediction/cosine_sg.cu
src/link_prediction/jaccard_mg.cu
src/link_prediction/sorensen_mg.cu
src/link_prediction/overlap_mg.cu
src/link_prediction/cosine_mg.cu
src/layout/legacy/force_atlas2.cu
src/converters/legacy/COOtoCSR.cu
src/community/legacy/spectral_clustering.cu
Expand Down
87 changes: 87 additions & 0 deletions cpp/include/cugraph/algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,37 @@ rmm::device_uvector<weight_t> jaccard_coefficients(
std::tuple<raft::device_span<vertex_t const>, raft::device_span<vertex_t const>> vertex_pairs,
bool do_expensive_check = false);

/**
* @brief Compute Cosine similarity coefficient
*
* Similarity is computed for every pair of vertices specified. Note that
* similarity algorithms expect a symmetric graph.
*
* @throws cugraph::logic_error when an error occurs.
*
* @tparam vertex_t Type of vertex identifiers. Needs to be an integral type.
* @tparam edge_t Type of edge identifiers. Needs to be an integral type.
* @tparam weight_t Type of edge weights. Needs to be a floating point type.
* @tparam multi_gpu Flag indicating whether template instantiation should target single-GPU (false)
* @param handle RAFT handle object to encapsulate resources (e.g. CUDA stream, communicator, and
* handles to various CUDA libraries) to run graph algorithms.
* @param graph_view Graph view object.
* @param edge_weight_view Optional view object holding edge weights for @p graph_view. If @p
* edge_weight_view.has_value() == true, use the weights associated with the graph. If false, assume
* a weight of 1 for all edges.
* @param vertex_pairs tuple of device spans defining the vertex pairs to compute similarity for
* In a multi-gpu context each vertex pair should be local to this GPU.
* @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`).
* @return similarity coefficient for the corresponding @p vertex_pairs
*/
template <typename vertex_t, typename edge_t, typename weight_t, bool multi_gpu>
rmm::device_uvector<weight_t> cosine_similarity_coefficients(
raft::handle_t const& handle,
graph_view_t<vertex_t, edge_t, false, multi_gpu> const& graph_view,
std::optional<edge_property_view_t<edge_t, weight_t const*>> edge_weight_view,
std::tuple<raft::device_span<vertex_t const>, raft::device_span<vertex_t const>> vertex_pairs,
bool do_expensive_check = false);

/**
* @brief Compute Sorensen similarity coefficient
*
Expand Down Expand Up @@ -2093,6 +2124,62 @@ std::
std::optional<size_t> topk,
bool do_expensive_check = false);

/**
* @brief Compute Consine all pairs similarity coefficient
*
* Similarity is computed for all pairs of vertices. Note that in a sparse
* graph, many of the vertex pairs will have a score of zero. We actually
* compute similarity only for vertices that are two hop neighbors within
* the graph, since vertices that are not two hop neighbors will have
* a score of 0.
*
* If @p vertices is specified we will compute similarity on two hop
* neighbors the @p vertices. If @p vertices is not specified it will
* compute similarity on all two hop neighbors in the graph.
*
* If @p topk is specified only the top @p topk scoring vertex pairs
* will be returned, if not specified then scores for all computed vertex pairs
* will be returned.
*
* Note the list of two hop neighbors in the entire graph might be a large
* number of vertex pairs. If the graph is dense enough it could be as large
* as the the number of vertices squared, which might run out of memory.
*
* @throws cugraph::logic_error when an error occurs.
*
* @tparam vertex_t Type of vertex identifiers. Needs to be an integral type.
* @tparam edge_t Type of edge identifiers. Needs to be an integral type.
* @tparam weight_t Type of edge weights. Needs to be a floating point type.
* @tparam multi_gpu Flag indicating whether template instantiation should target single-GPU (false)
* @param handle RAFT handle object to encapsulate resources (e.g. CUDA stream, communicator, and
* handles to various CUDA libraries) to run graph algorithms.
* @param graph_view Graph view object.
* @param edge_weight_view Optional view object holding edge weights for @p graph_view. If @p
* edge_weight_view.has_value() == true, use the weights associated with the graph. If false, assume
* a weight of 1 for all edges.
* @param vertices optional device span defining the seed vertices. In a multi-gpu context the
* vertices should be local to this GPU.
* @param topk optional specification of the how many of the top scoring vertex pairs should be
* returned
* @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`).
* @return tuple containing three device vectors (v1, v2, score) of the same length. Corresponding
* elements in the vectors identify a result, v1 identifying a vertex in the graph, v2 identifying
* one of v1's two hop neighors, and the score identifying the similarity score between v1 and v2.
* If @p topk was specified then the vectors will be no longer than @p topk elements. In a
* multi-gpu context, if @p topk is specified all results will return on GPU rank 0, otherwise they
* will be returned on the local GPU for vertex v1.
*/
template <typename vertex_t, typename edge_t, typename weight_t, bool multi_gpu>
std::
tuple<rmm::device_uvector<vertex_t>, rmm::device_uvector<vertex_t>, rmm::device_uvector<weight_t>>
cosine_similarity_all_pairs_coefficients(
raft::handle_t const& handle,
graph_view_t<vertex_t, edge_t, false, multi_gpu> const& graph_view,
std::optional<edge_property_view_t<edge_t, weight_t const*>> edge_weight_view,
std::optional<raft::device_span<vertex_t const>> vertices,
std::optional<size_t> topk,
bool do_expensive_check = false);

/**
* @brief Compute Sorensen similarity coefficient
*
Expand Down
122 changes: 122 additions & 0 deletions cpp/src/link_prediction/cosine_mg.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Copyright (c) 2022-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "link_prediction/cosine_similarity_impl.cuh"

namespace cugraph {

template rmm::device_uvector<float> cosine_similarity_coefficients(
raft::handle_t const& handle,
graph_view_t<int32_t, int32_t, false, true> const& graph_view,
std::optional<edge_property_view_t<int32_t, float const*>> edge_weight_view,
std::tuple<raft::device_span<int32_t const>, raft::device_span<int32_t const>> vertex_pairs,
bool do_expensive_check);

template rmm::device_uvector<float> cosine_similarity_coefficients(
raft::handle_t const& handle,
graph_view_t<int32_t, int64_t, false, true> const& graph_view,
std::optional<edge_property_view_t<int64_t, float const*>> edge_weight_view,
std::tuple<raft::device_span<int32_t const>, raft::device_span<int32_t const>> vertex_pairs,
bool do_expensive_check);

template rmm::device_uvector<float> cosine_similarity_coefficients(
raft::handle_t const& handle,
graph_view_t<int64_t, int64_t, false, true> const& graph_view,
std::optional<edge_property_view_t<int64_t, float const*>> edge_weight_view,
std::tuple<raft::device_span<int64_t const>, raft::device_span<int64_t const>> vertex_pairs,
bool do_expensive_check);

template rmm::device_uvector<double> cosine_similarity_coefficients(
raft::handle_t const& handle,
graph_view_t<int32_t, int32_t, false, true> const& graph_view,
std::optional<edge_property_view_t<int32_t, double const*>> edge_weight_view,
std::tuple<raft::device_span<int32_t const>, raft::device_span<int32_t const>> vertex_pairs,
bool do_expensive_check);

template rmm::device_uvector<double> cosine_similarity_coefficients(
raft::handle_t const& handle,
graph_view_t<int32_t, int64_t, false, true> const& graph_view,
std::optional<edge_property_view_t<int64_t, double const*>> edge_weight_view,
std::tuple<raft::device_span<int32_t const>, raft::device_span<int32_t const>> vertex_pairs,
bool do_expensive_check);

template rmm::device_uvector<double> cosine_similarity_coefficients(
raft::handle_t const& handle,
graph_view_t<int64_t, int64_t, false, true> const& graph_view,
std::optional<edge_property_view_t<int64_t, double const*>> edge_weight_view,
std::tuple<raft::device_span<int64_t const>, raft::device_span<int64_t const>> vertex_pairs,
bool do_expensive_check);

template std::
tuple<rmm::device_uvector<int32_t>, rmm::device_uvector<int32_t>, rmm::device_uvector<float>>
cosine_similarity_all_pairs_coefficients(
raft::handle_t const& handle,
graph_view_t<int32_t, int32_t, false, true> const& graph_view,
std::optional<edge_property_view_t<int32_t, float const*>> edge_weight_view,
std::optional<raft::device_span<int32_t const>> vertices,
std::optional<size_t> topk,
bool do_expensive_check);

template std::
tuple<rmm::device_uvector<int32_t>, rmm::device_uvector<int32_t>, rmm::device_uvector<float>>
cosine_similarity_all_pairs_coefficients(
raft::handle_t const& handle,
graph_view_t<int32_t, int64_t, false, true> const& graph_view,
std::optional<edge_property_view_t<int64_t, float const*>> edge_weight_view,
std::optional<raft::device_span<int32_t const>> vertices,
std::optional<size_t> topk,
bool do_expensive_check);

template std::
tuple<rmm::device_uvector<int64_t>, rmm::device_uvector<int64_t>, rmm::device_uvector<float>>
cosine_similarity_all_pairs_coefficients(
raft::handle_t const& handle,
graph_view_t<int64_t, int64_t, false, true> const& graph_view,
std::optional<edge_property_view_t<int64_t, float const*>> edge_weight_view,
std::optional<raft::device_span<int64_t const>> vertices,
std::optional<size_t> topk,
bool do_expensive_check);

template std::
tuple<rmm::device_uvector<int32_t>, rmm::device_uvector<int32_t>, rmm::device_uvector<double>>
cosine_similarity_all_pairs_coefficients(
raft::handle_t const& handle,
graph_view_t<int32_t, int32_t, false, true> const& graph_view,
std::optional<edge_property_view_t<int32_t, double const*>> edge_weight_view,
std::optional<raft::device_span<int32_t const>> vertices,
std::optional<size_t> topk,
bool do_expensive_check);

template std::
tuple<rmm::device_uvector<int32_t>, rmm::device_uvector<int32_t>, rmm::device_uvector<double>>
cosine_similarity_all_pairs_coefficients(
raft::handle_t const& handle,
graph_view_t<int32_t, int64_t, false, true> const& graph_view,
std::optional<edge_property_view_t<int64_t, double const*>> edge_weight_view,
std::optional<raft::device_span<int32_t const>> vertices,
std::optional<size_t> topk,
bool do_expensive_check);

template std::
tuple<rmm::device_uvector<int64_t>, rmm::device_uvector<int64_t>, rmm::device_uvector<double>>
cosine_similarity_all_pairs_coefficients(
raft::handle_t const& handle,
graph_view_t<int64_t, int64_t, false, true> const& graph_view,
std::optional<edge_property_view_t<int64_t, double const*>> edge_weight_view,
std::optional<raft::device_span<int64_t const>> vertices,
std::optional<size_t> topk,
bool do_expensive_check);

} // namespace cugraph
Loading

0 comments on commit 5b659e2

Please sign in to comment.