Skip to content

Commit 9ec00e2

Browse files
sryapfacebook-github-bot
authored andcommitted
Add a host map option for a UVM tensor alloc (#3073)
Summary: X-link: facebookresearch/FBGEMM#167 Pull Request resolved: #3073 FBGEMM-GPU provides two options to allocate a UVM buffer: (1) `malloc` & `cudaHostRegister` and (2) `cudaMallocManaged`. Each one of them has a different performance implication (this is platform specific). This diff adds an option for a user to choose a UVM buffer allocation method in TBE. Reviewed By: q10, spcyppt Differential Revision: D61401239
1 parent 75ac3c0 commit 9ec00e2

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

fbgemm_gpu/fbgemm_gpu/split_table_batched_embeddings_ops_training.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ def apply_split_helper(
230230
make_dev_param: bool = False,
231231
dev_reshape: Optional[Tuple[int, ...]] = None,
232232
uvm_tensors_log: Optional[List[str]] = None,
233+
uvm_host_mapped: bool = False,
233234
) -> None:
234235
set_attr_fn(f"{prefix}_physical_placements", split.placements)
235236
set_attr_fn(f"{prefix}_physical_offsets", split.offsets)
@@ -313,11 +314,12 @@ def apply_split_helper(
313314
f"{prefix}_uvm",
314315
torch.zeros(
315316
split.uvm_size,
316-
out=torch.ops.fbgemm.new_managed_tensor(
317+
out=torch.ops.fbgemm.new_unified_tensor(
317318
# pyre-fixme[6]: Expected `Optional[Type[torch._dtype]]`
318319
# for 3rd param but got `Type[Type[torch._dtype]]`.
319320
torch.zeros(1, device=current_device, dtype=dtype),
320321
[split.uvm_size],
322+
is_host_mapped=uvm_host_mapped,
321323
),
322324
),
323325
)
@@ -540,6 +542,9 @@ def __init__( # noqa C901
540542
multipass_prefetch_config: Optional[MultiPassPrefetchConfig] = None,
541543
# Global weight decay params
542544
global_weight_decay: Optional[GlobalWeightDecayDefinition] = None,
545+
# Set to True to alloc a UVM tensor using malloc+cudaHostRegister.
546+
# Set to False to use cudaMallocManaged
547+
uvm_host_mapped: bool = False,
543548
) -> None:
544549
super(SplitTableBatchedEmbeddingBagsCodegen, self).__init__()
545550
self.uuid = str(uuid.uuid4())
@@ -746,6 +751,8 @@ def __init__( # noqa C901
746751
loc == locations[0] for loc in locations
747752
)
748753

754+
self.uvm_host_mapped = uvm_host_mapped
755+
749756
weight_split = construct_split_state(
750757
embedding_specs,
751758
rowwise=False,
@@ -763,6 +770,7 @@ def __init__( # noqa C901
763770
enforce_hbm=enforce_hbm,
764771
make_dev_param=optimizer == OptimType.NONE,
765772
dev_reshape=(-1, self.max_D) if optimizer == OptimType.NONE else None,
773+
uvm_host_mapped=self.uvm_host_mapped,
766774
)
767775

768776
assert optimizer not in (
@@ -936,6 +944,7 @@ def __init__( # noqa C901
936944
# but got `Type[torch.float32]`.
937945
dtype=momentum1_dtype,
938946
enforce_hbm=enforce_hbm,
947+
uvm_host_mapped=self.uvm_host_mapped,
939948
)
940949
if optimizer in (
941950
OptimType.ADAM,
@@ -972,6 +981,7 @@ def __init__( # noqa C901
972981
# pyre-fixme[6]: Expected `Type[Type[torch._dtype]]` for 3rd param
973982
# but got `Type[torch.float32]`.
974983
dtype=momentum2_dtype,
984+
uvm_host_mapped=self.uvm_host_mapped,
975985
)
976986
else:
977987
# NOTE: make TorchScript work!
@@ -990,6 +1000,7 @@ def __init__( # noqa C901
9901000
# pyre-fixme[6]: Expected `Type[Type[torch._dtype]]` for 3rd param
9911001
# but got `Type[torch.float32]`.
9921002
dtype=torch.float32,
1003+
uvm_host_mapped=self.uvm_host_mapped,
9931004
)
9941005
self._apply_split(
9951006
construct_split_state(
@@ -1001,6 +1012,7 @@ def __init__( # noqa C901
10011012
# pyre-fixme[6]: Expected `Type[Type[torch._dtype]]` for 3rd param
10021013
# but got `Type[torch.float32]`.
10031014
dtype=torch.float32,
1015+
uvm_host_mapped=self.uvm_host_mapped,
10041016
)
10051017
self.register_buffer(
10061018
"max_counter", torch.tensor([1], dtype=torch.float32)
@@ -1019,6 +1031,7 @@ def __init__( # noqa C901
10191031
# pyre-fixme[6]: Expected `Type[Type[torch._dtype]]` for 3rd param
10201032
# but got `Type[torch.float32]`.
10211033
dtype=torch.float32,
1034+
uvm_host_mapped=self.uvm_host_mapped,
10221035
)
10231036
self._register_nonpersistent_buffers("row_counter")
10241037
self.register_buffer(
@@ -2281,6 +2294,7 @@ def _apply_split(
22812294
enforce_hbm: bool = False,
22822295
make_dev_param: bool = False,
22832296
dev_reshape: Optional[Tuple[int, ...]] = None,
2297+
uvm_host_mapped: bool = False,
22842298
) -> None:
22852299
apply_split_helper(
22862300
self.register_buffer,
@@ -2295,6 +2309,7 @@ def _apply_split(
22952309
make_dev_param,
22962310
dev_reshape,
22972311
self._uvm_tensors_log,
2312+
uvm_host_mapped=uvm_host_mapped,
22982313
)
22992314

23002315
def _apply_cache_state(

0 commit comments

Comments
 (0)