gigl.utils.csr_parallel#

Multi-threaded kernels for gigl.utils.csr.build_csr_from_coo().

Each thread owns a range of rows, scans the whole edge list and writes only its own rows, so there are no atomics or write collisions. Columns match the torch path exactly; edge ids of duplicate edges keep input order, which the torch path does not guarantee. Ranges are balanced by edge count through indptr.

The kernels run on numba’s OpenMP threading layer, which is not fork safe: a process that has run a kernel must not fork() a child that runs one. GiGL builds datasets in mp.spawn children.

Functions#

parallel_degrees(row, num_rows)

torch.bincount(row, minlength=num_rows) across all cores, as int64.

parallel_scatter(row, col, indptr, indices, edge_ids)

Place every edge in its row of indices (and its COO position in edge_ids).

parallel_sort_within_rows(indptr, indices, edge_ids)

Sort each row's columns ascending in place, permuting edge_ids alongside.

Module Contents#

gigl.utils.csr_parallel.parallel_degrees(row, num_rows)[source]#

torch.bincount(row, minlength=num_rows) across all cores, as int64.

Parameters:
  • row (torch.Tensor)

  • num_rows (int)

Return type:

torch.Tensor

gigl.utils.csr_parallel.parallel_scatter(row, col, indptr, indices, edge_ids)[source]#

Place every edge in its row of indices (and its COO position in edge_ids).

Parameters:
  • row (torch.Tensor) – Source node id of each edge.

  • col (torch.Tensor) – Destination node id of each edge.

  • indptr (torch.Tensor) – CSR row pointers built from the degrees of row.

  • indices (torch.Tensor) – Output column ids, one slot per edge; written in place.

  • edge_ids (Optional[torch.Tensor]) – Output COO position of each edge, written in place, or None to skip them.

Raises:

ValueError – If the edges do not fill every row exactly.

Return type:

None

gigl.utils.csr_parallel.parallel_sort_within_rows(indptr, indices, edge_ids)[source]#

Sort each row’s columns ascending in place, permuting edge_ids alongside.

Parameters:
  • indptr (torch.Tensor) – CSR row pointers.

  • indices (torch.Tensor) – Column ids to sort within each row; sorted in place.

  • edge_ids (Optional[torch.Tensor]) – Edge ids to permute with indices, or None. A stable sort keeps duplicate edges in input order.

Return type:

None