Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- PR #1227 Pin cmake policies to cmake 3.17 version
- PR #1269 Removed old db code that was not being used
- PR #1271 Add extra check to make SG Louvain deterministic
- PR #1273 Update Force Atlas 2 notebook, wrapper and coding style

## Bug Fixes
- PR #1242 Calling gunrock cmake using explicit -D options, re-enabling C++ tests
Expand Down
4 changes: 4 additions & 0 deletions conda/environments/cugraph_dev_cuda10.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- cudf=0.17.*
- libcudf=0.17.*
- rmm=0.17.*
- cuxfilter=0.17.*
- librmm=0.17.*
- dask>=2.12.0
- distributed>=2.12.0
Expand All @@ -29,6 +30,9 @@ dependencies:
- cython>=0.29,<0.30
- pytest
- scikit-learn>=0.23.1
- colorcet
- holoviews
- datashader
- sphinx
- sphinx_rtd_theme
- sphinxcontrib-websupport
Expand Down
4 changes: 4 additions & 0 deletions conda/environments/cugraph_dev_cuda10.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- cudf=0.17.*
- libcudf=0.17.*
- rmm=0.17.*
- cuxfilter=0.17.*
- librmm=0.17.*
- dask>=2.12.0
- distributed>=2.12.0
Expand All @@ -29,6 +30,9 @@ dependencies:
- cython>=0.29,<0.30
- pytest
- scikit-learn>=0.23.1
- colorcet
- holoviews
- datashader
- sphinx
- sphinx_rtd_theme
- sphinxcontrib-websupport
Expand Down
4 changes: 4 additions & 0 deletions conda/environments/cugraph_dev_cuda11.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- cudf=0.17.*
- libcudf=0.17.*
- rmm=0.17.*
- cuxfilter=0.17.*
- librmm=0.17.*
- dask>=2.12.0
- distributed>=2.12.0
Expand All @@ -29,6 +30,9 @@ dependencies:
- cython>=0.29,<0.30
- pytest
- scikit-learn>=0.23.1
- colorcet
- datashader
- holoviews
- sphinx
- sphinx_rtd_theme
- sphinxcontrib-websupport
Expand Down
26 changes: 12 additions & 14 deletions cpp/include/algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ void overlap_list(GraphCSRView<VT, ET, WT> const &graph,
*
* @throws cugraph::logic_error when an error occurs.
*
* @tparam VT Type of vertex identifiers. Supported value : int
* @tparam vertex_t Type of vertex identifiers. Supported value :
* int (signed, 32-bit)
* @tparam edge_t Type of edge identifiers. Supported value : int
* (signed, 32-bit)
* @tparam ET Type of edge identifiers. Supported value : int
* (signed, 32-bit)
* @tparam WT Type of edge weights. Supported values : float or
* double.
* @tparam weight_t Type of edge weights. Supported values : float
* or double.
*
* @param[in] graph cuGraph graph descriptor, should contain the
* connectivity information as a COO. Graph is considered undirected. Edge weights are used for this
Expand All @@ -228,27 +228,25 @@ void overlap_list(GraphCSRView<VT, ET, WT> const &graph,
* is “no influence” and 1 is “normal”.
* @param[in] jitter_tolerance How much swinging you allow. Above 1 discouraged.
* Lower gives less speed and more precision.
* @param[in] barnes_hut_optimize: Whether to use the fast Barnes Hut or use the slower
* exact version.
* @param[in] barnes_hut_optimize: Whether to use the Barnes Hut approximation or the
* slower exact version.
* @param[in] barnes_hut_theta: Float between 0 and 1. Tradeoff for speed (1) vs
* accuracy (0) for Barnes Hut only.
* @params[in] scaling_ratio Float strictly positive. How much repulsion you
* want. More makes a more sparse graph. Switching from regular mode to LinLog mode needs a
* readjustment of the scaling parameter.
* @params[in] strong_gravity_mode The “Strong gravity” option sets a force
* that attracts the nodes that are distant from the center more ( is this distance). This force has
* the drawback of being so strong that it is sometimes stronger than the other forces. It may
* result in a biased placement of the nodes. However, its advantage is to force a very compact
* layout, which may be useful for certain purposes.
* @params[in] strong_gravity_mode Sets a force
* that attracts the nodes that are distant from the center more. It is so strong that it can
* sometimes dominate other forces.
* @params[in] gravity Attracts nodes to the center. Prevents islands from
* drifting away.
* @params[in] verbose Output convergence info at each interation.
* @params[in] callback An instance of GraphBasedDimRedCallback class to
* intercept the internal state of positions while they are being trained.
*
*/
template <typename VT, typename ET, typename WT>
void force_atlas2(GraphCOOView<VT, ET, WT> &graph,
template <typename vertex_t, typename edge_t, typename weight_t>
void force_atlas2(GraphCOOView<vertex_t, edge_t, weight_t> &graph,
float *pos,
const int max_iter = 500,
float *x_start = nullptr,
Expand Down
135 changes: 65 additions & 70 deletions cpp/src/layout/barnes_hut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace detail {
template <typename vertex_t, typename edge_t, typename weight_t>
void barnes_hut(GraphCOOView<vertex_t, edge_t, weight_t> &graph,
float *pos,
const int max_iter = 1000,
const int max_iter = 500,
float *x_start = nullptr,
float *y_start = nullptr,
bool outbound_attraction_distribution = true,
Expand All @@ -50,8 +50,9 @@ void barnes_hut(GraphCOOView<vertex_t, edge_t, weight_t> &graph,
bool verbose = false,
internals::GraphBasedDimRedCallback *callback = nullptr)
{
const edge_t e = graph.number_of_edges;
const vertex_t n = graph.number_of_vertices;
cudaStream_t stream = {nullptr};
const edge_t e = graph.number_of_edges;
const vertex_t n = graph.number_of_vertices;

const int blocks = getMultiProcessorCount();
// A tiny jitter to promote numerical stability/
Expand All @@ -74,10 +75,7 @@ void barnes_hut(GraphCOOView<vertex_t, edge_t, weight_t> &graph,
int *bottomd = d_bottomd.data().get();
float *radiusd = d_radiusd.data().get();

cudaStream_t stream = {nullptr};

// FIXME: this should work on "stream"
InitializationKernel<<<1, 1>>>(limiter, maxdepthd, radiusd);
InitializationKernel<<<1, 1, 0, stream>>>(limiter, maxdepthd, radiusd);
CHECK_CUDA(stream);

const int FOUR_NNODES = 4 * nnodes;
Expand Down Expand Up @@ -125,12 +123,13 @@ void barnes_hut(GraphCOOView<vertex_t, edge_t, weight_t> &graph,

// Initialize positions with random values
int random_state = 0;
random_vector(nodes_pos, (nnodes + 1) * 2, random_state);

// Copy start x and y positions.
if (x_start && y_start) {
copy(n, x_start, nodes_pos);
copy(n, y_start, nodes_pos + nnodes + 1);
} else {
random_vector(nodes_pos, (nnodes + 1) * 2, random_state, stream);
}

// Allocate arrays for force computation
Expand All @@ -152,7 +151,7 @@ void barnes_hut(GraphCOOView<vertex_t, edge_t, weight_t> &graph,
// Sort COO for coalesced memory access.
sort(graph, stream);
CHECK_CUDA(stream);
// FIXME: this should work on "stream"

graph.degree(massl, cugraph::DegreeDirection::OUT);
CHECK_CUDA(stream);

Expand All @@ -169,7 +168,7 @@ void barnes_hut(GraphCOOView<vertex_t, edge_t, weight_t> &graph,
// If outboundAttractionDistribution active, compensate.
if (outbound_attraction_distribution) {
int sum =
thrust::reduce(rmm::exec_policy(nullptr)->on(nullptr), d_massl.begin(), d_massl.begin() + n);
thrust::reduce(rmm::exec_policy(stream)->on(stream), d_massl.begin(), d_massl.begin() + n);
outbound_att_compensation = sum / (float)n;
}

Expand Down Expand Up @@ -197,71 +196,64 @@ void barnes_hut(GraphCOOView<vertex_t, edge_t, weight_t> &graph,
fill(n, swinging, 0.f);
fill(n, traction, 0.f);

// FIXME: this should work on "stream"
ResetKernel<<<1, 1>>>(radiusd_squared, bottomd, NNODES, radiusd);
ResetKernel<<<1, 1, 0, stream>>>(radiusd_squared, bottomd, NNODES, radiusd);
CHECK_CUDA(stream);

// FIXME: this should work on "stream"
// Compute bounding box arround all bodies
BoundingBoxKernel<<<blocks * FACTOR1, THREADS1>>>(startl,
childl,
massl,
nodes_pos,
nodes_pos + nnodes + 1,
maxxl,
maxyl,
minxl,
minyl,
FOUR_NNODES,
NNODES,
n,
limiter,
radiusd);
BoundingBoxKernel<<<blocks * FACTOR1, THREADS1, 0, stream>>>(startl,
childl,
massl,
nodes_pos,
nodes_pos + nnodes + 1,
maxxl,
maxyl,
minxl,
minyl,
FOUR_NNODES,
NNODES,
n,
limiter,
radiusd);
CHECK_CUDA(stream);

// FIXME: this should work on "stream"
ClearKernel1<<<blocks, 1024>>>(childl, FOUR_NNODES, FOUR_N);
ClearKernel1<<<blocks, 1024, 0, stream>>>(childl, FOUR_NNODES, FOUR_N);
CHECK_CUDA(stream);

// FIXME: this should work on "stream"
// Build quadtree
TreeBuildingKernel<<<blocks * FACTOR2, THREADS2>>>(
TreeBuildingKernel<<<blocks * FACTOR2, THREADS2, 0, stream>>>(
childl, nodes_pos, nodes_pos + nnodes + 1, NNODES, n, maxdepthd, bottomd, radiusd);
CHECK_CUDA(stream);

// FIXME: this should work on "stream"
ClearKernel2<<<blocks, 1024>>>(startl, massl, NNODES, bottomd);
ClearKernel2<<<blocks, 1024, 0, stream>>>(startl, massl, NNODES, bottomd);
CHECK_CUDA(stream);

// FIXME: this should work on "stream"
// Summarizes mass and position for each cell, bottom up approach
SummarizationKernel<<<blocks * FACTOR3, THREADS3>>>(
SummarizationKernel<<<blocks * FACTOR3, THREADS3, 0, stream>>>(
countl, childl, massl, nodes_pos, nodes_pos + nnodes + 1, NNODES, n, bottomd);
CHECK_CUDA(stream);

// FIXME: this should work on "stream"
// Group closed bodies together, used to speed up Repulsion kernel
SortKernel<<<blocks * FACTOR4, THREADS4>>>(sortl, countl, startl, childl, NNODES, n, bottomd);
SortKernel<<<blocks * FACTOR4, THREADS4, 0, stream>>>(
sortl, countl, startl, childl, NNODES, n, bottomd);
CHECK_CUDA(stream);

// FIXME: this should work on "stream"
// Force computation O(n . log(n))
RepulsionKernel<<<blocks * FACTOR5, THREADS5>>>(scaling_ratio,
theta,
epssq,
sortl,
childl,
massl,
nodes_pos,
nodes_pos + nnodes + 1,
rep_forces,
rep_forces + nnodes + 1,
theta_squared,
NNODES,
FOUR_NNODES,
n,
radiusd_squared,
maxdepthd);
RepulsionKernel<<<blocks * FACTOR5, THREADS5, 0, stream>>>(scaling_ratio,
theta,
epssq,
sortl,
childl,
massl,
nodes_pos,
nodes_pos + nnodes + 1,
rep_forces,
rep_forces + nnodes + 1,
theta_squared,
NNODES,
FOUR_NNODES,
n,
radiusd_squared,
maxdepthd);
CHECK_CUDA(stream);

apply_gravity<vertex_t>(nodes_pos,
Expand All @@ -272,7 +264,8 @@ void barnes_hut(GraphCOOView<vertex_t, edge_t, weight_t> &graph,
gravity,
strong_gravity_mode,
scaling_ratio,
n);
n,
stream);

apply_attraction<vertex_t, edge_t, weight_t>(row,
col,
Expand All @@ -286,7 +279,8 @@ void barnes_hut(GraphCOOView<vertex_t, edge_t, weight_t> &graph,
outbound_attraction_distribution,
lin_log_mode,
edge_weight_influence,
outbound_att_compensation);
outbound_att_compensation,
stream);

compute_local_speed(rep_forces,
rep_forces + nnodes + 1,
Expand All @@ -297,30 +291,31 @@ void barnes_hut(GraphCOOView<vertex_t, edge_t, weight_t> &graph,
massl,
swinging,
traction,
n);
n,
stream);

// Compute global swinging and traction values
const float s =
thrust::reduce(rmm::exec_policy(nullptr)->on(nullptr), d_swinging.begin(), d_swinging.end());
thrust::reduce(rmm::exec_policy(stream)->on(stream), d_swinging.begin(), d_swinging.end());

const float t =
thrust::reduce(rmm::exec_policy(nullptr)->on(nullptr), d_traction.begin(), d_traction.end());
thrust::reduce(rmm::exec_policy(stream)->on(stream), d_traction.begin(), d_traction.end());

// Compute global speed based on gloab and local swinging and traction.
adapt_speed<vertex_t>(jitter_tolerance, &jt, &speed, &speed_efficiency, s, t, n);

// Update positions
apply_forces_bh<<<blocks * FACTOR6, THREADS6>>>(nodes_pos,
nodes_pos + nnodes + 1,
attract,
attract + n,
rep_forces,
rep_forces + nnodes + 1,
old_forces,
old_forces + n,
swinging,
speed,
n);
apply_forces_bh<<<blocks * FACTOR6, THREADS6, 0, stream>>>(nodes_pos,
nodes_pos + nnodes + 1,
attract,
attract + n,
rep_forces,
rep_forces + nnodes + 1,
old_forces,
old_forces + n,
swinging,
speed,
n);

if (callback) callback->on_epoch_end(nodes_pos);

Expand Down
Loading