Skip to content

Commit c047950

Browse files
Rhett-Yingmfbalin
andauthored
[GraphBolt][CUDA] Dataloader num_workers > 0 fix. (#6924) (#6928)
Co-authored-by: Muhammed Fatih BALIN <[email protected]>
1 parent 92d4ba9 commit c047950

File tree

6 files changed

+17
-18
lines changed

6 files changed

+17
-18
lines changed

graphbolt/src/fused_csc_sampling_graph.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,8 @@ FusedCSCSamplingGraph::GetState() const {
274274

275275
c10::intrusive_ptr<FusedSampledSubgraph> FusedCSCSamplingGraph::InSubgraph(
276276
const torch::Tensor& nodes) const {
277-
if (utils::is_accessible_from_gpu(indptr_) &&
277+
if (utils::is_on_gpu(nodes) && utils::is_accessible_from_gpu(indptr_) &&
278278
utils::is_accessible_from_gpu(indices_) &&
279-
utils::is_accessible_from_gpu(nodes) &&
280279
(!type_per_edge_.has_value() ||
281280
utils::is_accessible_from_gpu(type_per_edge_.value()))) {
282281
GRAPHBOLT_DISPATCH_CUDA_ONLY_DEVICE(c10::DeviceType::CUDA, "InSubgraph", {
@@ -614,9 +613,9 @@ c10::intrusive_ptr<FusedSampledSubgraph> FusedCSCSamplingGraph::SampleNeighbors(
614613
probs_or_mask = this->EdgeAttribute(probs_name);
615614
}
616615

617-
if (!replace && utils::is_accessible_from_gpu(indptr_) &&
616+
if (!replace && utils::is_on_gpu(nodes) &&
617+
utils::is_accessible_from_gpu(indptr_) &&
618618
utils::is_accessible_from_gpu(indices_) &&
619-
utils::is_accessible_from_gpu(nodes) &&
620619
(!probs_or_mask.has_value() ||
621620
utils::is_accessible_from_gpu(probs_or_mask.value()))) {
622621
GRAPHBOLT_DISPATCH_CUDA_ONLY_DEVICE(

graphbolt/src/index_select.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ namespace graphbolt {
1313
namespace ops {
1414

1515
torch::Tensor IndexSelect(torch::Tensor input, torch::Tensor index) {
16-
if (input.is_pinned() &&
17-
(index.is_pinned() || index.device().type() == c10::DeviceType::CUDA)) {
16+
if (utils::is_on_gpu(index) && input.is_pinned()) {
1817
GRAPHBOLT_DISPATCH_CUDA_ONLY_DEVICE(
1918
c10::DeviceType::CUDA, "UVAIndexSelect",
2019
{ return UVAIndexSelectImpl(input, index); });
@@ -26,9 +25,8 @@ std::tuple<torch::Tensor, torch::Tensor> IndexSelectCSC(
2625
torch::Tensor indptr, torch::Tensor indices, torch::Tensor nodes) {
2726
TORCH_CHECK(
2827
indices.sizes().size() == 1, "IndexSelectCSC only supports 1d tensors");
29-
if (utils::is_accessible_from_gpu(indptr) &&
30-
utils::is_accessible_from_gpu(indices) &&
31-
utils::is_accessible_from_gpu(nodes)) {
28+
if (utils::is_on_gpu(nodes) && utils::is_accessible_from_gpu(indptr) &&
29+
utils::is_accessible_from_gpu(indices)) {
3230
GRAPHBOLT_DISPATCH_CUDA_ONLY_DEVICE(
3331
c10::DeviceType::CUDA, "IndexSelectCSCImpl",
3432
{ return IndexSelectCSCImpl(indptr, indices, nodes); });

graphbolt/src/isin.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ torch::Tensor IsInCPU(
4848

4949
torch::Tensor IsIn(
5050
const torch::Tensor& elements, const torch::Tensor& test_elements) {
51-
if (utils::is_accessible_from_gpu(elements) &&
52-
utils::is_accessible_from_gpu(test_elements)) {
51+
if (utils::is_on_gpu(elements) && utils::is_on_gpu(test_elements)) {
5352
GRAPHBOLT_DISPATCH_CUDA_ONLY_DEVICE(
5453
c10::DeviceType::CUDA, "IsInOperation",
5554
{ return ops::IsIn(elements, test_elements); });

graphbolt/src/unique_and_compact.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ namespace sampling {
1919
std::tuple<torch::Tensor, torch::Tensor, torch::Tensor> UniqueAndCompact(
2020
const torch::Tensor& src_ids, const torch::Tensor& dst_ids,
2121
const torch::Tensor unique_dst_ids) {
22-
if (utils::is_accessible_from_gpu(src_ids) &&
23-
utils::is_accessible_from_gpu(dst_ids) &&
24-
utils::is_accessible_from_gpu(unique_dst_ids)) {
22+
if (utils::is_on_gpu(src_ids) && utils::is_on_gpu(dst_ids) &&
23+
utils::is_on_gpu(unique_dst_ids)) {
2524
GRAPHBOLT_DISPATCH_CUDA_ONLY_DEVICE(
2625
c10::DeviceType::CUDA, "unique_and_compact",
2726
{ return ops::UniqueAndCompact(src_ids, dst_ids, unique_dst_ids); });

graphbolt/src/utils.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@
1212
namespace graphbolt {
1313
namespace utils {
1414

15+
/**
16+
* @brief Checks whether the tensor is stored on the GPU.
17+
*/
18+
inline bool is_on_gpu(torch::Tensor tensor) {
19+
return tensor.device().is_cuda();
20+
}
21+
1522
/**
1623
* @brief Checks whether the tensor is stored on the GPU or the pinned memory.
1724
*/
1825
inline bool is_accessible_from_gpu(torch::Tensor tensor) {
19-
return tensor.is_pinned() || tensor.device().type() == c10::DeviceType::CUDA;
26+
return is_on_gpu(tensor) || tensor.is_pinned();
2027
}
2128

2229
/**

tests/python/pytorch/graphbolt/test_dataloader.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010

1111
def test_DataLoader():
12-
# https://pytorch.org/docs/master/notes/multiprocessing.html#cuda-in-multiprocessing
13-
mp.set_start_method("spawn", force=True)
14-
1512
N = 40
1613
B = 4
1714
itemset = dgl.graphbolt.ItemSet(torch.arange(N), names="seed_nodes")

0 commit comments

Comments
 (0)