Commit b67b227
authored
Fix JaggedTensor single-element constructor unconditionally initializing CUDA via pinned_memory (openvdb#468)
## Summary
- Make `pinned_memory` conditional on the tensor device being CUDA in
two locations where single-element `JaggedTensor` construction
unconditionally allocated pinned (page-locked) memory via
`cudaHostAlloc`, which forced CUDA runtime initialization even for
CPU-only tensors.
- This caused crashes in forked `DataLoader` worker processes (where
re-initializing CUDA after `fork()` is forbidden) and added unnecessary
overhead for CPU-only workloads.
- Add a test verifying that CPU single-element `JaggedTensor` offsets
are not pinned.
Fixes openvdb#467
## Changes
### `src/fvdb/JaggedTensor.cpp`
`.pinned_memory(true)` → `.pinned_memory(mData.device().is_cuda())` in
the `JaggedTensor(const std::vector<torch::Tensor>&)` single-element
branch.
### `src/fvdb/detail/ops/JOffsetsFromJIdx.cu`
`.pinned_memory(true)` → `.pinned_memory(jdata.device().is_cuda())` in
`joffsetsFromJIdx()`, which is the shared implementation called by CPU,
CUDA, and PrivateUse1 dispatch paths.
### `tests/unit/test_jagged_tensor.py`
New `test_cpu_single_element_no_cuda_init` verifying both constructor
paths produce non-pinned offsets for CPU tensors.
Signed-off-by: Jonathan Swartz <jonathan@jswartz.info>1 parent f42ec34 commit b67b227
File tree
3 files changed
+33
-7
lines changed- src/fvdb
- detail/ops
- tests/unit
3 files changed
+33
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2738 | 2738 | | |
2739 | 2739 | | |
2740 | 2740 | | |
| 2741 | + | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
| 2754 | + | |
| 2755 | + | |
| 2756 | + | |
| 2757 | + | |
| 2758 | + | |
| 2759 | + | |
| 2760 | + | |
| 2761 | + | |
| 2762 | + | |
2741 | 2763 | | |
2742 | 2764 | | |
2743 | 2765 | | |
0 commit comments