Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable pipeline prefetching #2963

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 4 additions & 1 deletion fbgemm_gpu/fbgemm_gpu/tbe/cache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@

# pyre-unsafe

from .split_embeddings_cache_ops import get_unique_indices_v2 # noqa: F401
from .split_embeddings_cache_ops import SplitEmbeddingsCacheOpsRegistry # noqa: F401

# Register ops in `torch.ops.fbgemm`
SplitEmbeddingsCacheOpsRegistry.register()
48 changes: 35 additions & 13 deletions fbgemm_gpu/fbgemm_gpu/tbe/cache/split_embeddings_cache_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,12 @@

# pyre-unsafe

import logging
from typing import Optional, Tuple, Union

import torch

lib = torch.library.Library("fbgemm", "FRAGMENT")
lib.define(
"""
get_unique_indices_v2(
Tensor linear_indices,
int max_indices,
bool compute_count=False,
bool compute_inverse_indices=False
) -> (Tensor, Tensor, Tensor?, Tensor?)
"""
)


@torch.library.impl(lib, "get_unique_indices_v2", "CUDA")
def get_unique_indices_v2(
linear_indices: torch.Tensor,
max_indices: int,
Expand Down Expand Up @@ -60,3 +48,37 @@ def get_unique_indices_v2(
return ret[0], ret[1], ret[3]
# Return (unique_indices, length)
return ret[:-2]


class SplitEmbeddingsCacheOpsRegistry:
init = False

@staticmethod
def register():
"""
Register ops in `torch.ops.fbgemm`
"""
if not SplitEmbeddingsCacheOpsRegistry.init:
logging.info("Register split_embeddings_cache_ops")

for op_name, op_def, op_fn in (
(
"get_unique_indices_v2",
(
"("
" Tensor linear_indices, "
" int max_indices, "
" bool compute_count=False, "
" bool compute_inverse_indices=False"
") -> (Tensor, Tensor, Tensor?, Tensor?)"
),
get_unique_indices_v2,
),
):
fbgemm_op_name = "fbgemm::" + op_name
if fbgemm_op_name not in torch.library._defs:
# Define and register op
torch.library.define(fbgemm_op_name, op_def)
torch.library.impl(fbgemm_op_name, "CUDA", op_fn)

SplitEmbeddingsCacheOpsRegistry.init = True
Loading
Loading