From efcf839d05ace1b842908755832704920b72d092 Mon Sep 17 00:00:00 2001 From: Alberto Gallegos Date: Wed, 27 May 2026 22:07:08 +0000 Subject: [PATCH 01/27] build(fbgemm-xpu): add pyproject.toml for PEP 517 build system --- packages/fbgemm-xpu/pyproject.toml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 packages/fbgemm-xpu/pyproject.toml diff --git a/packages/fbgemm-xpu/pyproject.toml b/packages/fbgemm-xpu/pyproject.toml new file mode 100644 index 0000000..291e1fc --- /dev/null +++ b/packages/fbgemm-xpu/pyproject.toml @@ -0,0 +1,19 @@ +[build-system] +requires = [ + "setuptools", + "wheel", + "torch", +] +build-backend = "setuptools.build_meta" + +[project] +name = "fbgemm" +version = "0.1.0" +description = "FBGEMM XPU operators for Intel GPUs (temporal)" +readme = "README.md" +requires-python = ">=3.9" +license = {text = "BSD-3-Clause"} +dependencies = [] + +[project.urls] +Repository = "TBD" From abd1972ac543ed41ffe247dfe37b8bab55bdcafd Mon Sep 17 00:00:00 2001 From: Alberto Gallegos Date: Wed, 27 May 2026 22:10:21 +0000 Subject: [PATCH 02/27] build(fbgemm-xpu): add MANIFEST.in for source distribution --- packages/fbgemm-xpu/MANIFEST.in | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 packages/fbgemm-xpu/MANIFEST.in diff --git a/packages/fbgemm-xpu/MANIFEST.in b/packages/fbgemm-xpu/MANIFEST.in new file mode 100644 index 0000000..befe118 --- /dev/null +++ b/packages/fbgemm-xpu/MANIFEST.in @@ -0,0 +1,4 @@ +include LICENSE +include README.md +include requirements.txt +recursive-include src *.cpp *.h *.sycl *.py From 317d08dbb5fc1bcb330f0a6e9fc55c65fd7aa0f5 Mon Sep 17 00:00:00 2001 From: Alberto Gallegos Date: Wed, 27 May 2026 22:11:22 +0000 Subject: [PATCH 03/27] build(fbgemm-xpu): add requirements.txt with build dependencies --- packages/fbgemm-xpu/requirements.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 packages/fbgemm-xpu/requirements.txt diff --git a/packages/fbgemm-xpu/requirements.txt b/packages/fbgemm-xpu/requirements.txt new file mode 100644 index 0000000..dd7caef --- /dev/null +++ b/packages/fbgemm-xpu/requirements.txt @@ -0,0 +1,3 @@ +torch +numpy +ninja \ No newline at end of file From 5eab91218c6fda40b2b4f65b7ddb08473aefd57f Mon Sep 17 00:00:00 2001 From: Alberto Gallegos Date: Wed, 27 May 2026 22:12:22 +0000 Subject: [PATCH 04/27] docs(fbgemm-xpu): add README.md placeholder --- packages/fbgemm-xpu/README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 packages/fbgemm-xpu/README.md diff --git a/packages/fbgemm-xpu/README.md b/packages/fbgemm-xpu/README.md new file mode 100644 index 0000000..e69de29 From 0142efbbb0eb8db07a38349aeccbdf8bb8979d0a Mon Sep 17 00:00:00 2001 From: Alberto Gallegos Date: Wed, 27 May 2026 22:16:38 +0000 Subject: [PATCH 05/27] docs(fbgemm-xpu): add BSD-3-Clause license and third-party notices Adds BSD 3-Clause license (Copyright 2026 Intel Corporation) for the fbgemm-xpu package and third-party-programs.txt documenting the original FBGEMM software license from Meta Platforms, Inc. Ensures proper legal attribution for derivative work. --- packages/fbgemm-xpu/ third-party-programs.txt | 32 +++++++++++++++++++ packages/fbgemm-xpu/LICENSE | 28 ++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 packages/fbgemm-xpu/ third-party-programs.txt create mode 100644 packages/fbgemm-xpu/LICENSE diff --git a/packages/fbgemm-xpu/ third-party-programs.txt b/packages/fbgemm-xpu/ third-party-programs.txt new file mode 100644 index 0000000..b54dbde --- /dev/null +++ b/packages/fbgemm-xpu/ third-party-programs.txt @@ -0,0 +1,32 @@ +For FBGEMM software + +BSD License + +Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name Facebook nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +-------------------------------------------------------------------------------- diff --git a/packages/fbgemm-xpu/LICENSE b/packages/fbgemm-xpu/LICENSE new file mode 100644 index 0000000..8df07b8 --- /dev/null +++ b/packages/fbgemm-xpu/LICENSE @@ -0,0 +1,28 @@ +BSD 3-Clause License + +Copyright (c) 2026 Intel Corporation. All Rights Reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From de487a128892996854f4efd15234258094e2c38a Mon Sep 17 00:00:00 2001 From: Alberto Gallegos Date: Wed, 27 May 2026 22:22:19 +0000 Subject: [PATCH 06/27] build(fbgemm-xpu): add setup.py for SYCL extension compilation - Implements setuptools configuration for building fbgemm XPU operators with Intel SYCL backend. - NOTE: setup.py will be replaced by toml build system for torchlib-xpu integration in a future PR. So far setup.py is needed to build fbgemm-xpu independently to run tests. --- packages/fbgemm-xpu/setup.py | 186 +++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 packages/fbgemm-xpu/setup.py diff --git a/packages/fbgemm-xpu/setup.py b/packages/fbgemm-xpu/setup.py new file mode 100644 index 0000000..e8eca73 --- /dev/null +++ b/packages/fbgemm-xpu/setup.py @@ -0,0 +1,186 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# This source code is licensed under the license found in the +# LICENSE file in the root directory of this source tree. + +import os +from pathlib import Path + +import torch + +from setuptools import find_packages, setup + +from torch.utils.cpp_extension import BuildExtension, CppExtension, SyclExtension + +# Package name for the extension - this becomes the importable module name +library_name = value = os.getenv("EXTENSION_NAME", "fbgemm_xpu") +print(f"Building extension with library name: {library_name}") +# Determine if we can use Python's stable ABI for wheel compatibility +# py_limited_api allows wheels to work across different Python 3.x versions +# Only available in PyTorch 2.6.0+ +if torch.__version__ >= "2.6.0": + py_limited_api = True +else: + py_limited_api = False + + +def _normalize_xpu_arch_list() -> str: + arch_list = os.getenv("TORCH_XPU_ARCH_LIST", "").strip() + if not arch_list: + arch_list = "pvc" + os.environ["TORCH_XPU_ARCH_LIST"] = arch_list + print("TORCH_XPU_ARCH_LIST not set; defaulting to pvc") + return arch_list + + +def get_extensions(): + """ + Configure and return the list of extensions to build + + This function determines whether to compile the primary SYCL extension + or the CPU fallback extension based on system capabilities, then + configures the appropriate compilation settings. + + Returns: + List of Extension objects to be built by setuptools + """ + debug_mode = os.getenv("DEBUG", "0") == "1" + use_sycl = os.getenv("USE_SYCL", "1") == "1" # Default enabled + + if debug_mode: + print("Compiling in debug mode") + + # Only enable the SYCL backend if both requested and available. + use_sycl = use_sycl and torch.xpu.is_available() + + if use_sycl: + extension = SyclExtension + else: + extension = CppExtension + + # Link-time optimization and debugging flags + extra_link_args = [] + + xpu_arch_list = _normalize_xpu_arch_list() if use_sycl else "" + + extra_compile_args = { + "cxx": [ + "-O3" if not debug_mode else "-O0", + "-fdiagnostics-color=always", + "-DPy_LIMITED_API=0x03090000", + "-Wno-c++11-narrowing", + ], + "sycl": [ + "-O3" if not debug_mode else "-O0", + "-Xs", f"-device {xpu_arch_list}", + "-fdiagnostics-color=always", + "-DPy_LIMITED_API=0x03090000", + "-Wno-c++11-narrowing", + ], + } + + if debug_mode: + extra_compile_args["cxx"].extend([ + "-g", + "-ggdb", + "-fno-inline", + "-fno-inline-functions", + ]) + extra_compile_args["sycl"].extend([ + "-g", "-ggdb", + "-fno-inline", + "-fno-inline-functions", + "-gline-tables-only", + "-fdebug-info-for-profiling", + "-fno-sycl-early-optimizations", + "-fsycl-device-code-split=per_kernel", + ]) + extra_link_args.extend([ + "-O0", + "-g", "-ggdb", + "-fno-inline", + "-fno-inline-functions", + "-fdiagnostics-color=always" + ]) + + project_root = Path(__file__).resolve().parent + extensions_dir = project_root / "src" / library_name + + # Vendored torch-xpu-ops comm/ headers live under the local SYCL tree. + vendored_sycl_dir = extensions_dir / "sycl_kernels" + vendored_comm_dir = vendored_sycl_dir / "comm" + if use_sycl and vendored_comm_dir.is_dir(): + extra_compile_args["sycl"].append(f"-I{vendored_sycl_dir}") + extra_compile_args["cxx"].append(f"-I{vendored_sycl_dir}") + print(f"Using vendored comm headers from: {vendored_comm_dir}") + elif use_sycl: + print( + f"WARNING: vendored comm headers not found at {vendored_comm_dir}.\n" + f"Builds for vendored FBGEMM XPU operators will fail until they are present." + ) + + # Find all C++ source files in the main csrc directory + sources = [str(p.relative_to(project_root)) for p in extensions_dir.glob("*.cpp")] + + # Sanity check: ensure we found source files + if not sources: + raise RuntimeError(f"No C++ sources found in {extensions_dir}") + + # Copy link args for SYCL-specific linking + sycl_link_args = extra_link_args.copy() + + # Add SYCL source files if SYCL backend is enabled + if use_sycl: + sycl_dir = extensions_dir / "sycl_kernels" + fbgemm_utils_dir = extensions_dir / "fbgemm_utils" + # Collect all SYCL sources recursively so utility kernels are also linked. + sycl_sources = [str(p.relative_to(project_root)) for p in sycl_dir.rglob("*.sycl")] + sycl_sources += [str(p.relative_to(project_root)) for p in sycl_dir.rglob("*.cpp")] + sycl_sources += [str(p.relative_to(project_root)) for p in fbgemm_utils_dir.rglob("*.sycl")] + sycl_sources += [str(p.relative_to(project_root)) for p in fbgemm_utils_dir.rglob("*.cpp")] + sources += sycl_sources + if not sycl_sources: + print("WARNING: USE_SYCL=1 but no .sycl files found") + + print("Building extension with sources:") + for s in sources: + print(" -", s) + + link_args = sycl_link_args if use_sycl else extra_link_args + + return [ + extension( + "fbgemm._C", + sources, + extra_compile_args=extra_compile_args, + extra_link_args=link_args, + py_limited_api=py_limited_api, + ) + ] + +# Main setuptools configuration +setup( + # Package metadata + name="fbgemm", # Package name for pip install + version="0.1.0", # Version number + package_dir={"fbgemm": f"src/{library_name}"}, # Map fbgemm to actual directory + packages=["fbgemm"], + include_package_data=True, + package_data={"fbgemm": ["src/**/*.cpp", "src/**/*.h", "src/**/*.sycl"]}, + + # Extension configuration + ext_modules=get_extensions(), # C++/SYCL extensions to build + + # Dependencies + install_requires=[], # torch is provided by the target xpuTorch environment + + # Documentation + description="FBGEMM XPU operators for Intel GPUs", + long_description=Path("README.md").read_text(encoding="utf-8"), + long_description_content_type="text/markdown", + + # Build system configuration + cmdclass={"build_ext": BuildExtension}, # Use PyTorch's build system + + options={"bdist_wheel": {"py_limited_api": "cp39"}} if py_limited_api else {}, +) From af721e3e83770de512876bd0cae1a68633d704aa Mon Sep 17 00:00:00 2001 From: Alberto Gallegos Date: Wed, 27 May 2026 22:45:59 +0000 Subject: [PATCH 07/27] docs(fbgemm-xpu): fix typo in third-party-programs.txt file name --- .../{ third-party-programs.txt => third-party-programs.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/fbgemm-xpu/{ third-party-programs.txt => third-party-programs.txt} (100%) diff --git a/packages/fbgemm-xpu/ third-party-programs.txt b/packages/fbgemm-xpu/third-party-programs.txt similarity index 100% rename from packages/fbgemm-xpu/ third-party-programs.txt rename to packages/fbgemm-xpu/third-party-programs.txt From 1fef4aa756c3fbec430f50f28c17899551876c14 Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Thu, 28 May 2026 18:16:10 +0000 Subject: [PATCH 08/27] Initial configurations for build step with cmake --- packages/fbgemm-xpu/CMakeLists.txt | 4 + packages/fbgemm-xpu/LICENSE | 40 ++-- packages/fbgemm-xpu/pyproject.toml | 50 +++-- packages/fbgemm-xpu/requirements.txt | 3 - packages/fbgemm-xpu/setup.py | 186 ------------------ .../fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt | 126 ++++++++++++ .../fbgemm-xpu/src/fbgemm_xpu/__init__.py | 3 + .../src/fbgemm_xpu/fbgemm_utils/.gitkeep | 0 .../src/fbgemm_xpu/sycl_kernels/.gitkeep | 0 packages/fbgemm-xpu/test/.gitkeep | 0 packages/fbgemm-xpu/version.txt | 1 + pyproject.toml | 6 +- 12 files changed, 198 insertions(+), 221 deletions(-) create mode 100644 packages/fbgemm-xpu/CMakeLists.txt delete mode 100644 packages/fbgemm-xpu/requirements.txt delete mode 100644 packages/fbgemm-xpu/setup.py create mode 100644 packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt create mode 100644 packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py create mode 100644 packages/fbgemm-xpu/src/fbgemm_xpu/fbgemm_utils/.gitkeep create mode 100644 packages/fbgemm-xpu/src/fbgemm_xpu/sycl_kernels/.gitkeep create mode 100644 packages/fbgemm-xpu/test/.gitkeep create mode 100644 packages/fbgemm-xpu/version.txt diff --git a/packages/fbgemm-xpu/CMakeLists.txt b/packages/fbgemm-xpu/CMakeLists.txt new file mode 100644 index 0000000..e0872ee --- /dev/null +++ b/packages/fbgemm-xpu/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.18) +project(${SKBUILD_PROJECT_NAME}) + +add_subdirectory(src/fbgemm_xpu) diff --git a/packages/fbgemm-xpu/LICENSE b/packages/fbgemm-xpu/LICENSE index 8df07b8..1c8dd93 100644 --- a/packages/fbgemm-xpu/LICENSE +++ b/packages/fbgemm-xpu/LICENSE @@ -1,28 +1,30 @@ -BSD 3-Clause License +BSD License -Copyright (c) 2026 Intel Corporation. All Rights Reserved. +For FBGEMM software -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: +Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved. -1. Redistributions of source code must retain the above copyright notice, this +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. + * Neither the name Facebook nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/fbgemm-xpu/pyproject.toml b/packages/fbgemm-xpu/pyproject.toml index 291e1fc..6c788f0 100644 --- a/packages/fbgemm-xpu/pyproject.toml +++ b/packages/fbgemm-xpu/pyproject.toml @@ -1,19 +1,47 @@ [build-system] requires = [ - "setuptools", - "wheel", - "torch", + "pybind11", + "scikit-build-core>=0.10", + "torch~=2.12.0", # WA: must be specified in root project with build-constraint-dependencies ] -build-backend = "setuptools.build_meta" +build-backend = "scikit_build_core.build" [project] -name = "fbgemm" -version = "0.1.0" -description = "FBGEMM XPU operators for Intel GPUs (temporal)" +name = "fbgemm-xpu" +description = "FBGEMM XPU operators for Intel GPUs" readme = "README.md" -requires-python = ">=3.9" -license = {text = "BSD-3-Clause"} -dependencies = [] +requires-python = ">=3.10" +license = { text = "BSD-3-Clause" } +authors = [ + { name = "Dmitry Rogozhkin", email = "dmitry.v.rogozhkin@intel.com" }, +] +dynamic = ["version"] +dependencies = [ + "torch~=2.12.0", +] + +[project.optional-dependencies] +test = [ + "numpy", + "pytest", + "hypothesis", +] [project.urls] -Repository = "TBD" +GitHub = "https://github.com/intel/torchlib-xpu" + +[tool.scikit-build] +cmake.version = ">=3.18" +wheel.packages = ["src/fbgemm_xpu"] + +[tool.scikit-build.cmake.define] +CMAKE_CXX_COMPILER = {env="CXX", default="icpx"} + +[[tool.scikit-build.generate]] +path = "src/fbgemm_xpu/_version.py" +template = '__version__ = "${version}"' + +[tool.scikit-build.metadata.version] +provider = "scikit_build_core.metadata.regex" +input = "version.txt" +regex = "^v?(?P[0-9a-zA-Z.+-_]+)" diff --git a/packages/fbgemm-xpu/requirements.txt b/packages/fbgemm-xpu/requirements.txt deleted file mode 100644 index dd7caef..0000000 --- a/packages/fbgemm-xpu/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -torch -numpy -ninja \ No newline at end of file diff --git a/packages/fbgemm-xpu/setup.py b/packages/fbgemm-xpu/setup.py deleted file mode 100644 index e8eca73..0000000 --- a/packages/fbgemm-xpu/setup.py +++ /dev/null @@ -1,186 +0,0 @@ -# Copyright (c) Meta Platforms, Inc. and affiliates. -# All rights reserved. -# This source code is licensed under the license found in the -# LICENSE file in the root directory of this source tree. - -import os -from pathlib import Path - -import torch - -from setuptools import find_packages, setup - -from torch.utils.cpp_extension import BuildExtension, CppExtension, SyclExtension - -# Package name for the extension - this becomes the importable module name -library_name = value = os.getenv("EXTENSION_NAME", "fbgemm_xpu") -print(f"Building extension with library name: {library_name}") -# Determine if we can use Python's stable ABI for wheel compatibility -# py_limited_api allows wheels to work across different Python 3.x versions -# Only available in PyTorch 2.6.0+ -if torch.__version__ >= "2.6.0": - py_limited_api = True -else: - py_limited_api = False - - -def _normalize_xpu_arch_list() -> str: - arch_list = os.getenv("TORCH_XPU_ARCH_LIST", "").strip() - if not arch_list: - arch_list = "pvc" - os.environ["TORCH_XPU_ARCH_LIST"] = arch_list - print("TORCH_XPU_ARCH_LIST not set; defaulting to pvc") - return arch_list - - -def get_extensions(): - """ - Configure and return the list of extensions to build - - This function determines whether to compile the primary SYCL extension - or the CPU fallback extension based on system capabilities, then - configures the appropriate compilation settings. - - Returns: - List of Extension objects to be built by setuptools - """ - debug_mode = os.getenv("DEBUG", "0") == "1" - use_sycl = os.getenv("USE_SYCL", "1") == "1" # Default enabled - - if debug_mode: - print("Compiling in debug mode") - - # Only enable the SYCL backend if both requested and available. - use_sycl = use_sycl and torch.xpu.is_available() - - if use_sycl: - extension = SyclExtension - else: - extension = CppExtension - - # Link-time optimization and debugging flags - extra_link_args = [] - - xpu_arch_list = _normalize_xpu_arch_list() if use_sycl else "" - - extra_compile_args = { - "cxx": [ - "-O3" if not debug_mode else "-O0", - "-fdiagnostics-color=always", - "-DPy_LIMITED_API=0x03090000", - "-Wno-c++11-narrowing", - ], - "sycl": [ - "-O3" if not debug_mode else "-O0", - "-Xs", f"-device {xpu_arch_list}", - "-fdiagnostics-color=always", - "-DPy_LIMITED_API=0x03090000", - "-Wno-c++11-narrowing", - ], - } - - if debug_mode: - extra_compile_args["cxx"].extend([ - "-g", - "-ggdb", - "-fno-inline", - "-fno-inline-functions", - ]) - extra_compile_args["sycl"].extend([ - "-g", "-ggdb", - "-fno-inline", - "-fno-inline-functions", - "-gline-tables-only", - "-fdebug-info-for-profiling", - "-fno-sycl-early-optimizations", - "-fsycl-device-code-split=per_kernel", - ]) - extra_link_args.extend([ - "-O0", - "-g", "-ggdb", - "-fno-inline", - "-fno-inline-functions", - "-fdiagnostics-color=always" - ]) - - project_root = Path(__file__).resolve().parent - extensions_dir = project_root / "src" / library_name - - # Vendored torch-xpu-ops comm/ headers live under the local SYCL tree. - vendored_sycl_dir = extensions_dir / "sycl_kernels" - vendored_comm_dir = vendored_sycl_dir / "comm" - if use_sycl and vendored_comm_dir.is_dir(): - extra_compile_args["sycl"].append(f"-I{vendored_sycl_dir}") - extra_compile_args["cxx"].append(f"-I{vendored_sycl_dir}") - print(f"Using vendored comm headers from: {vendored_comm_dir}") - elif use_sycl: - print( - f"WARNING: vendored comm headers not found at {vendored_comm_dir}.\n" - f"Builds for vendored FBGEMM XPU operators will fail until they are present." - ) - - # Find all C++ source files in the main csrc directory - sources = [str(p.relative_to(project_root)) for p in extensions_dir.glob("*.cpp")] - - # Sanity check: ensure we found source files - if not sources: - raise RuntimeError(f"No C++ sources found in {extensions_dir}") - - # Copy link args for SYCL-specific linking - sycl_link_args = extra_link_args.copy() - - # Add SYCL source files if SYCL backend is enabled - if use_sycl: - sycl_dir = extensions_dir / "sycl_kernels" - fbgemm_utils_dir = extensions_dir / "fbgemm_utils" - # Collect all SYCL sources recursively so utility kernels are also linked. - sycl_sources = [str(p.relative_to(project_root)) for p in sycl_dir.rglob("*.sycl")] - sycl_sources += [str(p.relative_to(project_root)) for p in sycl_dir.rglob("*.cpp")] - sycl_sources += [str(p.relative_to(project_root)) for p in fbgemm_utils_dir.rglob("*.sycl")] - sycl_sources += [str(p.relative_to(project_root)) for p in fbgemm_utils_dir.rglob("*.cpp")] - sources += sycl_sources - if not sycl_sources: - print("WARNING: USE_SYCL=1 but no .sycl files found") - - print("Building extension with sources:") - for s in sources: - print(" -", s) - - link_args = sycl_link_args if use_sycl else extra_link_args - - return [ - extension( - "fbgemm._C", - sources, - extra_compile_args=extra_compile_args, - extra_link_args=link_args, - py_limited_api=py_limited_api, - ) - ] - -# Main setuptools configuration -setup( - # Package metadata - name="fbgemm", # Package name for pip install - version="0.1.0", # Version number - package_dir={"fbgemm": f"src/{library_name}"}, # Map fbgemm to actual directory - packages=["fbgemm"], - include_package_data=True, - package_data={"fbgemm": ["src/**/*.cpp", "src/**/*.h", "src/**/*.sycl"]}, - - # Extension configuration - ext_modules=get_extensions(), # C++/SYCL extensions to build - - # Dependencies - install_requires=[], # torch is provided by the target xpuTorch environment - - # Documentation - description="FBGEMM XPU operators for Intel GPUs", - long_description=Path("README.md").read_text(encoding="utf-8"), - long_description_content_type="text/markdown", - - # Build system configuration - cmdclass={"build_ext": BuildExtension}, # Use PyTorch's build system - - options={"bdist_wheel": {"py_limited_api": "cp39"}} if py_limited_api else {}, -) diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt new file mode 100644 index 0000000..1a2ecfb --- /dev/null +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt @@ -0,0 +1,126 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# Copyright (c) 2026 Intel Corporation. All Rights Reserved. + +cmake_minimum_required(VERSION 3.18) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(PYBIND11_FINDPYTHON ON) +find_package(pybind11 REQUIRED) +find_package(Torch REQUIRED) +find_package(Python3 COMPONENTS Development REQUIRED) + +# -------------------------------------------------------------------------- +# SYCL backend detection: enabled only when CXX is the Intel oneAPI compiler +# (icpx). Falls back to a host-only CPU build otherwise. Mirrors the previous +# setup.py behavior driven by USE_SYCL / torch.xpu.is_available(). +# -------------------------------------------------------------------------- +if($ENV{CXX} MATCHES "icpx") + set(WITH_SYCL ON) + message(STATUS "Intel compiler detected: SYCL kernels enabled") +else() + set(WITH_SYCL OFF) + message(STATUS "Non-Intel compiler in use: SYCL kernels disabled") +endif() + +# -------------------------------------------------------------------------- +# XPU architecture list. Honors TORCH_XPU_ARCH_LIST env var, otherwise queries +# torch.xpu.get_arch_list(), otherwise defaults to "pvc". +# -------------------------------------------------------------------------- +if(NOT "$ENV{TORCH_XPU_ARCH_LIST}" STREQUAL "") + set(TORCH_XPU_ARCH_LIST "$ENV{TORCH_XPU_ARCH_LIST}") +else() + execute_process( + COMMAND ${Python3_EXECUTABLE} -c "import torch; print(','.join(torch.xpu.get_arch_list()))" + OUTPUT_VARIABLE TORCH_XPU_ARCH_LIST + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE _arch_rc + ) + if(NOT _arch_rc EQUAL 0 OR TORCH_XPU_ARCH_LIST STREQUAL "") + set(TORCH_XPU_ARCH_LIST "pvc") + endif() +endif() +message(STATUS "Building for XPU architectures: ${TORCH_XPU_ARCH_LIST}") + +set(SYCL_TARGETS -fsycl-targets=spir64_gen,spir64) +set(SYCL_DEVICE_LIST -Xs "-device ${TORCH_XPU_ARCH_LIST} -options -cl-poison-unsupported-fp64-kernels") + +# -------------------------------------------------------------------------- +# Sources +# +# Skeleton: lists are intentionally empty. Add host C++ files alongside this +# CMakeLists (e.g. your_op.cpp) and list them in host_sources. SYCL kernels +# (.sycl) and companion .cpp files under sycl_kernels/ or fbgemm_utils/ are +# picked up automatically by the GLOB_RECURSE below. +# -------------------------------------------------------------------------- +set(host_sources + # your_op.cpp +) + +file(GLOB_RECURSE sycl_sources CONFIGURE_DEPENDS + sycl_kernels/*.sycl + sycl_kernels/*.cpp + fbgemm_utils/*.sycl + fbgemm_utils/*.cpp +) + +# CMake does not recognize the .sycl extension as a C++ source. Mirror every +# .sycl file into the build tree with a .cpp suffix so CMake schedules a +# proper compile step for it; the icpx driver then handles SYCL via -fsycl. +set(sycl_sources_cxx "") +foreach(_src IN LISTS sycl_sources) + if(_src MATCHES "\\.sycl$") + file(RELATIVE_PATH _rel ${CMAKE_CURRENT_SOURCE_DIR} ${_src}) + set(_mirrored ${CMAKE_CURRENT_BINARY_DIR}/${_rel}.cpp) + configure_file(${_src} ${_mirrored} COPYONLY) + list(APPEND sycl_sources_cxx ${_mirrored}) + else() + list(APPEND sycl_sources_cxx ${_src}) + endif() +endforeach() + +if(WITH_SYCL) + set(all_sources ${host_sources} ${sycl_sources_cxx}) +else() + set(all_sources ${host_sources}) +endif() + +# -------------------------------------------------------------------------- +# Extension module: fbgemm._C +# +# Skip target creation if no sources have been added yet — this lets the +# scaffolding configure cleanly before any code is written. +# -------------------------------------------------------------------------- +if(NOT all_sources) + message(WARNING "fbgemm._C: no sources defined yet; skipping extension target.") + return() +endif() + +python_add_library(_C MODULE WITH_SOABI ${all_sources}) +set_target_properties(_C PROPERTIES PREFIX "") +set_target_properties(_C PROPERTIES CXX_STANDARD 17) + +# The package root is needed because host sources include +# "fbgemm_utils/torch_library.h". sycl_kernels and fbgemm_utils are added so +# SYCL sources mirrored into the build tree can still resolve same-dir headers +# ("feature_gates.h", "utils.h", ...). +target_include_directories(_C PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/sycl_kernels + ${CMAKE_CURRENT_SOURCE_DIR}/fbgemm_utils + ${Python3_INCLUDE_DIRS} +) + +target_link_libraries(_C PRIVATE ${TORCH_LIBRARIES}) + +target_compile_options(_C PRIVATE + -fdiagnostics-color=always + -Wno-c++11-narrowing +) + +if(WITH_SYCL) + target_compile_options(_C PRIVATE -fsycl ${SYCL_TARGETS}) + target_link_options(_C PRIVATE -fsycl ${SYCL_TARGETS} ${SYCL_DEVICE_LIST}) +endif() + +install(TARGETS _C DESTINATION fbgemm_xpu) diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py b/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py new file mode 100644 index 0000000..a92ec77 --- /dev/null +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py @@ -0,0 +1,3 @@ +# Main package initialization for the fbgemm_xpu module. +# Imports the compiled C extension (_C) once sources are added under this dir. +from . import _C # noqa: F401 diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/fbgemm_utils/.gitkeep b/packages/fbgemm-xpu/src/fbgemm_xpu/fbgemm_utils/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/sycl_kernels/.gitkeep b/packages/fbgemm-xpu/src/fbgemm_xpu/sycl_kernels/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/packages/fbgemm-xpu/test/.gitkeep b/packages/fbgemm-xpu/test/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/packages/fbgemm-xpu/version.txt b/packages/fbgemm-xpu/version.txt new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/packages/fbgemm-xpu/version.txt @@ -0,0 +1 @@ +0.1.0 diff --git a/pyproject.toml b/pyproject.toml index e29bc25..7f4d5fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,12 +8,13 @@ license = { file = "LICENSE" } authors = [ { name = "Dmitry Rogozhkin", email = "dmitry.v.rogozhkin@intel.com" }, ] -dependencies = [ "torchcodec-xpu" ] +dependencies = [ "torchcodec-xpu", "fbgemm-xpu" ] [project.optional-dependencies] test = [ "ruff", - "torchcodec-xpu[test]" + "torchcodec-xpu[test]", + "fbgemm-xpu[test]", ] [project.urls] @@ -29,6 +30,7 @@ package = true # set root project as a buildable package # 'workspace = true' indicates that project will be provided by the workspace # rather than fetched from PyPI torchcodec-xpu = { workspace = true } +fbgemm-xpu = { workspace = true } [tool.uv.workspace] members = [ "packages/*" ] From 4f59cec26f7537100ea5640933d0db9d583338ff Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Thu, 28 May 2026 18:42:25 +0000 Subject: [PATCH 09/27] Update cmake file to search in the fbgemm paths --- .../fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt | 13 ++++------- .../fbgemm-xpu/src/fbgemm_xpu/__init__.py | 23 ++++++++++++++++--- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt index 1a2ecfb..035a74c 100644 --- a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt @@ -1,6 +1,3 @@ -# Copyright (c) Meta Platforms, Inc. and affiliates. -# Copyright (c) 2026 Intel Corporation. All Rights Reserved. - cmake_minimum_required(VERSION 3.18) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -48,13 +45,13 @@ set(SYCL_DEVICE_LIST -Xs "-device ${TORCH_XPU_ARCH_LIST} -options -cl-poison-uns # -------------------------------------------------------------------------- # Sources # -# Skeleton: lists are intentionally empty. Add host C++ files alongside this -# CMakeLists (e.g. your_op.cpp) and list them in host_sources. SYCL kernels -# (.sycl) and companion .cpp files under sycl_kernels/ or fbgemm_utils/ are -# picked up automatically by the GLOB_RECURSE below. +# host_sources lists host C++ files that live alongside this CMakeLists. +# SYCL kernels (.sycl) and companion .cpp files under sycl_kernels/ or +# fbgemm_utils/ are picked up automatically by the GLOB_RECURSE below. # -------------------------------------------------------------------------- set(host_sources - # your_op.cpp + ops_registry.cpp + fbgemm_dense_lookups_ops.cpp ) file(GLOB_RECURSE sycl_sources CONFIGURE_DEPENDS diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py b/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py index a92ec77..4f09efa 100644 --- a/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py @@ -1,3 +1,20 @@ -# Main package initialization for the fbgemm_xpu module. -# Imports the compiled C extension (_C) once sources are added under this dir. -from . import _C # noqa: F401 +# Copyright 2026 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Portions of this file are derived from FBGEMM +# Copyright (c) Meta Platforms, Inc. and affiliates. +# SPDX-License-Identifier: BSD-3-Clause + +# Main package initialization for the fbgemm module +# This imports the C extension and Python operator wrappers +import torch +from pathlib import Path + +# Import the compiled C extension (_C) which contains the registered operators +# Import ops module which provides Python wrapper functions with autograd support +from . import _C, ops From 3dd2b181543248076c54f18744b060ec785b9769 Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Wed, 3 Jun 2026 22:35:43 +0000 Subject: [PATCH 10/27] Fix dependencies, add instrucctions to build in readme and fix instructions in cmake to include all cpp files --- packages/fbgemm-xpu/README.md | 44 +++++++++++++++++++ packages/fbgemm-xpu/pyproject.toml | 14 +++--- .../fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt | 17 ++++--- 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/packages/fbgemm-xpu/README.md b/packages/fbgemm-xpu/README.md index e69de29..3f69066 100644 --- a/packages/fbgemm-xpu/README.md +++ b/packages/fbgemm-xpu/README.md @@ -0,0 +1,44 @@ +# fbgemm-xpu + +Intel XPU plugin package for FBGEMM operators. + +## Build from source + +* Install [uv] + +* Install Intel oneAPI (DPC++ compiler `icpx`), version 2025.3 or newer + +* Clone the repository: + +```bash +git clone https://github.com/intel/torchlib-xpu.git && cd torchlib-xpu +``` + +* Create and activate a virtual environment: + +```bash +uv venv +source .venv/bin/activate +``` + +* Build and install `fbgemm-xpu`: + +```bash +uv pip install -e packages/fbgemm-xpu \ + --index https://download.pytorch.org/whl/xpu +``` + +* (Optional) Install test dependencies: + +```bash +uv pip install -e "packages/fbgemm-xpu[test]" \ + --index https://download.pytorch.org/whl/xpu +``` + +* Run tests: + +```bash +pytest packages/fbgemm-xpu/test/ -vv +``` + +[uv]: https://github.com/astral-sh/uv diff --git a/packages/fbgemm-xpu/pyproject.toml b/packages/fbgemm-xpu/pyproject.toml index 6c788f0..86ba0db 100644 --- a/packages/fbgemm-xpu/pyproject.toml +++ b/packages/fbgemm-xpu/pyproject.toml @@ -1,8 +1,9 @@ [build-system] requires = [ + "numpy~=2.0", "pybind11", "scikit-build-core>=0.10", - "torch~=2.12.0", # WA: must be specified in root project with build-constraint-dependencies + "torch~=2.12.0", ] build-backend = "scikit_build_core.build" @@ -13,18 +14,21 @@ readme = "README.md" requires-python = ">=3.10" license = { text = "BSD-3-Clause" } authors = [ - { name = "Dmitry Rogozhkin", email = "dmitry.v.rogozhkin@intel.com" }, + { name = "Alberto Gallegos Muro", email = "alberto.gallegos.muro@intel.com" }, + { name = "Felipe Leza Alvarez", email = "felipe.leza.alvarez@intel.com" }, + { name = "Manuel Santana Castolo", email = "manuel.santana.castolo@intel.com" }, ] dynamic = ["version"] dependencies = [ + "numpy~=2.0", "torch~=2.12.0", ] [project.optional-dependencies] test = [ - "numpy", - "pytest", - "hypothesis", + "numpy~=2.0", + "pytest~=8.0", + "hypothesis~=6.0", ] [project.urls] diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt index 035a74c..af88f86 100644 --- a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt @@ -3,9 +3,16 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(PYBIND11_FINDPYTHON ON) +# Prefer the active virtual environment Python when available. +set(Python3_FIND_VIRTUALENV FIRST) +if(DEFINED ENV{VIRTUAL_ENV}) + set(Python3_ROOT_DIR "$ENV{VIRTUAL_ENV}") + set(Python3_EXECUTABLE "$ENV{VIRTUAL_ENV}/bin/python") +endif() + +find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module) find_package(pybind11 REQUIRED) find_package(Torch REQUIRED) -find_package(Python3 COMPONENTS Development REQUIRED) # -------------------------------------------------------------------------- # SYCL backend detection: enabled only when CXX is the Intel oneAPI compiler @@ -49,9 +56,9 @@ set(SYCL_DEVICE_LIST -Xs "-device ${TORCH_XPU_ARCH_LIST} -options -cl-poison-uns # SYCL kernels (.sycl) and companion .cpp files under sycl_kernels/ or # fbgemm_utils/ are picked up automatically by the GLOB_RECURSE below. # -------------------------------------------------------------------------- -set(host_sources - ops_registry.cpp - fbgemm_dense_lookups_ops.cpp +# Auto-include all host C++ sources in this directory. +file(GLOB host_sources CONFIGURE_DEPENDS + *.cpp ) file(GLOB_RECURSE sycl_sources CONFIGURE_DEPENDS @@ -93,7 +100,7 @@ if(NOT all_sources) return() endif() -python_add_library(_C MODULE WITH_SOABI ${all_sources}) +Python3_add_library(_C MODULE WITH_SOABI ${all_sources}) set_target_properties(_C PROPERTIES PREFIX "") set_target_properties(_C PROPERTIES CXX_STANDARD 17) From 5a0e9c3dacb4c433b9f3716a5356a12a30b4327c Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Thu, 4 Jun 2026 18:25:07 +0000 Subject: [PATCH 11/27] Fix PyTorch version to 2.11.0 --- packages/fbgemm-xpu/pyproject.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/fbgemm-xpu/pyproject.toml b/packages/fbgemm-xpu/pyproject.toml index 86ba0db..fe95d4e 100644 --- a/packages/fbgemm-xpu/pyproject.toml +++ b/packages/fbgemm-xpu/pyproject.toml @@ -3,7 +3,7 @@ requires = [ "numpy~=2.0", "pybind11", "scikit-build-core>=0.10", - "torch~=2.12.0", + "torch~=2.11.0", ] build-backend = "scikit_build_core.build" @@ -21,7 +21,7 @@ authors = [ dynamic = ["version"] dependencies = [ "numpy~=2.0", - "torch~=2.12.0", + "torch~=2.11.0", ] [project.optional-dependencies] @@ -29,6 +29,7 @@ test = [ "numpy~=2.0", "pytest~=8.0", "hypothesis~=6.0", + "expecttest~=0.3.0" ] [project.urls] From 6791a9d3988ba8a223edfd11355c970950b58b60 Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Sat, 6 Jun 2026 00:16:03 +0000 Subject: [PATCH 12/27] Fix errors in license files and configurations in cmake and toml files --- packages/fbgemm-xpu/LICENSE | 40 +++++++++---------- packages/fbgemm-xpu/MANIFEST.in | 1 - packages/fbgemm-xpu/README.md | 4 +- packages/fbgemm-xpu/pyproject.toml | 3 +- .../fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt | 2 +- .../fbgemm-xpu/src/fbgemm_xpu/__init__.py | 17 ++++---- pyproject.toml | 2 +- 7 files changed, 34 insertions(+), 35 deletions(-) diff --git a/packages/fbgemm-xpu/LICENSE b/packages/fbgemm-xpu/LICENSE index 1c8dd93..a80680e 100644 --- a/packages/fbgemm-xpu/LICENSE +++ b/packages/fbgemm-xpu/LICENSE @@ -1,30 +1,28 @@ -BSD License +BSD 3-Clause License -For FBGEMM software +Copyright (c) 2026 Intel Corporation. All Rights Reserved. -Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name Facebook nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/packages/fbgemm-xpu/MANIFEST.in b/packages/fbgemm-xpu/MANIFEST.in index befe118..6d8aa75 100644 --- a/packages/fbgemm-xpu/MANIFEST.in +++ b/packages/fbgemm-xpu/MANIFEST.in @@ -1,4 +1,3 @@ include LICENSE include README.md -include requirements.txt recursive-include src *.cpp *.h *.sycl *.py diff --git a/packages/fbgemm-xpu/README.md b/packages/fbgemm-xpu/README.md index 3f69066..cc43659 100644 --- a/packages/fbgemm-xpu/README.md +++ b/packages/fbgemm-xpu/README.md @@ -35,10 +35,10 @@ uv pip install -e "packages/fbgemm-xpu[test]" \ --index https://download.pytorch.org/whl/xpu ``` -* Run tests: +* Get installed package version: ```bash -pytest packages/fbgemm-xpu/test/ -vv +python -c "import fbgemm_xpu; print(fbgemm_xpu.__version__)" ``` [uv]: https://github.com/astral-sh/uv diff --git a/packages/fbgemm-xpu/pyproject.toml b/packages/fbgemm-xpu/pyproject.toml index fe95d4e..0fb5245 100644 --- a/packages/fbgemm-xpu/pyproject.toml +++ b/packages/fbgemm-xpu/pyproject.toml @@ -12,7 +12,7 @@ name = "fbgemm-xpu" description = "FBGEMM XPU operators for Intel GPUs" readme = "README.md" requires-python = ">=3.10" -license = { text = "BSD-3-Clause" } +license = { file = "LICENSE" } authors = [ { name = "Alberto Gallegos Muro", email = "alberto.gallegos.muro@intel.com" }, { name = "Felipe Leza Alvarez", email = "felipe.leza.alvarez@intel.com" }, @@ -26,7 +26,6 @@ dependencies = [ [project.optional-dependencies] test = [ - "numpy~=2.0", "pytest~=8.0", "hypothesis~=6.0", "expecttest~=0.3.0" diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt index af88f86..23838d0 100644 --- a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt @@ -19,7 +19,7 @@ find_package(Torch REQUIRED) # (icpx). Falls back to a host-only CPU build otherwise. Mirrors the previous # setup.py behavior driven by USE_SYCL / torch.xpu.is_available(). # -------------------------------------------------------------------------- -if($ENV{CXX} MATCHES "icpx") +if(CMAKE_CXX_COMPILER MATCHES "icpx") set(WITH_SYCL ON) message(STATUS "Intel compiler detected: SYCL kernels enabled") else() diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py b/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py index 4f09efa..3ceca93 100644 --- a/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py @@ -1,10 +1,4 @@ -# Copyright 2026 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 +# Copyright (c) 2026 Intel Corporation. All Rights Reserved. # # Portions of this file are derived from FBGEMM # Copyright (c) Meta Platforms, Inc. and affiliates. @@ -18,3 +12,12 @@ # Import the compiled C extension (_C) which contains the registered operators # Import ops module which provides Python wrapper functions with autograd support from . import _C, ops + +try: + from ._version import __version__ +except ModuleNotFoundError: + try: + from importlib.metadata import PackageNotFoundError, version + __version__ = version("fbgemm-xpu") + except (ImportError, PackageNotFoundError): + __version__ = "unknown" diff --git a/pyproject.toml b/pyproject.toml index 7f4d5fa..ee42728 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ package = true # set root project as a buildable package # 'workspace = true' indicates that project will be provided by the workspace # rather than fetched from PyPI torchcodec-xpu = { workspace = true } -fbgemm-xpu = { workspace = true } +fbgemm-xpu = { workspace = true } [tool.uv.workspace] members = [ "packages/*" ] From 2e75207d976ac714eb8eef20ce18f3153b55637e Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Sat, 6 Jun 2026 00:28:02 +0000 Subject: [PATCH 13/27] Add an operator template to build the package --- packages/fbgemm-xpu/src/fbgemm_xpu/ops.py | 21 +++++ .../src/fbgemm_xpu/ops_registry.cpp | 78 +++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 packages/fbgemm-xpu/src/fbgemm_xpu/ops.py create mode 100644 packages/fbgemm-xpu/src/fbgemm_xpu/ops_registry.cpp diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/ops.py b/packages/fbgemm-xpu/src/fbgemm_xpu/ops.py new file mode 100644 index 0000000..50adcca --- /dev/null +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/ops.py @@ -0,0 +1,21 @@ +# Copyright (c) 2026 Intel Corporation. All Rights Reserved. +# +# Portions of this file are derived from FBGEMM +# Copyright (c) Meta Platforms, Inc. and affiliates. +# SPDX-License-Identifier: BSD-3-Clause + +# Python wrapper functions for all custom operators under the fbgemm namespace +# This module provides user-friendly interfaces to the C++ operators + +import torch +from torch import Tensor + +__all__ = [ + "dense_embedding_codegen_lookup_function", +] + +def dense_embedding_codegen_lookup_function(*args, **kwargs): + """Temporary stub for the planned dense embedding API.""" + raise NotImplementedError( + "dense_embedding_codegen_lookup_function is not implemented yet in src/fbgemm_xpu/ops.py" + ) diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/ops_registry.cpp b/packages/fbgemm-xpu/src/fbgemm_xpu/ops_registry.cpp new file mode 100644 index 0000000..16fe11d --- /dev/null +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/ops_registry.cpp @@ -0,0 +1,78 @@ +/* + * Copyright 2026 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Portions of this file are derived from FBGEMM + * Copyright (c) Meta Platforms, Inc. and affiliates. + * SPDX-License-Identifier: BSD-3-Clause + */ + + #include + +#include +#include + + +extern "C" { + /** + * Creates a dummy empty _C module that can be imported from Python. + * + * When this module is imported from Python (via 'import fbgemm._C'), + * it loads the shared library (.so file) and runs all TORCH_LIBRARY + * static initializers to register the custom operators with PyTorch's + * dispatch system. + * + * @return PyObject* pointer to the created module + */ + PyObject* PyInit__C(void) + { + static struct PyModuleDef module_def = { + PyModuleDef_HEAD_INIT, + "_C", /* name of module - imported as fbgemm._C */ + NULL, /* module documentation, may be NULL */ + -1, /* size of per-interpreter state of the module, + or -1 if the module keeps state in global variables. */ + NULL, /* methods - no Python-callable methods needed */ + }; + return PyModule_Create(&module_def); + } +} +/** + * Central operator registry for ALL custom operators under the "fbgemm" namespace. + * + * Uses TORCH_LIBRARY_FRAGMENT so this can coexist with upstream fbgemm_gpu + * which may already own the "fbgemm" namespace via TORCH_LIBRARY(fbgemm, m). + * + * Operator schemas are declared here; device-specific implementations are + * registered separately via TORCH_LIBRARY_IMPL(fbgemm, , m) in the + * respective .cpp / .sycl / .cu files. + */ +TORCH_LIBRARY_FRAGMENT(fbgemm, m) +{ + m.def("dense_embedding_codegen_lookup_function(" + " Tensor dev_weights, " + " Tensor weights_offsets, " + " Tensor D_offsets, " + " SymInt total_D, " + " SymInt max_D, " + " Tensor hash_size_cumsum, " + " int total_hash_size_bits, " + " Tensor indices, " + " Tensor offsets, " + " int pooling_mode, " + " Tensor? indice_weights, " + " Tensor? feature_requires_grad, " + " int output_dtype=0, " + " Tensor? B_offsets=None, " + " Tensor? vbe_output_offsets_feature_rank=None, " + " Tensor? vbe_B_offsets_rank_per_feature=None, " + " SymInt max_B=-1, " + " SymInt max_B_feature_rank=-1, " + " SymInt vbe_output_size=-1, " + " bool mixed_D=True) -> Tensor"); +} From 351b18215538ca83f2df7ad98a737f5d03433a65 Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Tue, 9 Jun 2026 17:02:47 +0000 Subject: [PATCH 14/27] Attend issues reported by ruff linter; fix dependencies in root package --- packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py | 17 ++++++++++------- packages/fbgemm-xpu/src/fbgemm_xpu/ops.py | 3 --- pyproject.toml | 6 ++---- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py b/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py index 3ceca93..478bd0b 100644 --- a/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py @@ -4,14 +4,17 @@ # Copyright (c) Meta Platforms, Inc. and affiliates. # SPDX-License-Identifier: BSD-3-Clause -# Main package initialization for the fbgemm module -# This imports the C extension and Python operator wrappers -import torch -from pathlib import Path +# Import the compiled C extension (_C) which contains the registered operators. +# If native dependencies (for example libtorch.so) are unavailable, keep import +# working so metadata like __version__ remains accessible. +try: + from . import _C as _C +except ImportError: + _C = None + +from . import ops as ops -# Import the compiled C extension (_C) which contains the registered operators -# Import ops module which provides Python wrapper functions with autograd support -from . import _C, ops +__all__ = ["_C", "ops", "__version__"] try: from ._version import __version__ diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/ops.py b/packages/fbgemm-xpu/src/fbgemm_xpu/ops.py index 50adcca..1226915 100644 --- a/packages/fbgemm-xpu/src/fbgemm_xpu/ops.py +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/ops.py @@ -7,9 +7,6 @@ # Python wrapper functions for all custom operators under the fbgemm namespace # This module provides user-friendly interfaces to the C++ operators -import torch -from torch import Tensor - __all__ = [ "dense_embedding_codegen_lookup_function", ] diff --git a/pyproject.toml b/pyproject.toml index ee42728..0452076 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,13 +8,12 @@ license = { file = "LICENSE" } authors = [ { name = "Dmitry Rogozhkin", email = "dmitry.v.rogozhkin@intel.com" }, ] -dependencies = [ "torchcodec-xpu", "fbgemm-xpu" ] +dependencies = [ "torchcodec-xpu"] [project.optional-dependencies] test = [ "ruff", - "torchcodec-xpu[test]", - "fbgemm-xpu[test]", + "torchcodec-xpu[test]" ] [project.urls] @@ -30,7 +29,6 @@ package = true # set root project as a buildable package # 'workspace = true' indicates that project will be provided by the workspace # rather than fetched from PyPI torchcodec-xpu = { workspace = true } -fbgemm-xpu = { workspace = true } [tool.uv.workspace] members = [ "packages/*" ] From 02a9b2c590add347d72e74b7ce81fd440173dc0c Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Tue, 9 Jun 2026 17:33:14 +0000 Subject: [PATCH 15/27] Fix original format instruction --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0452076..e29bc25 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ license = { file = "LICENSE" } authors = [ { name = "Dmitry Rogozhkin", email = "dmitry.v.rogozhkin@intel.com" }, ] -dependencies = [ "torchcodec-xpu"] +dependencies = [ "torchcodec-xpu" ] [project.optional-dependencies] test = [ From 6e00bf562ac5d83eea7dc214dccdbfb8cb98d441 Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Tue, 9 Jun 2026 23:06:44 +0000 Subject: [PATCH 16/27] Simplify fbgemm-xpu packaging and deduplicate third-party file --- packages/fbgemm-xpu/pyproject.toml | 7 ++-- packages/fbgemm-xpu/third-party-programs.txt | 32 ------------------ third-party-programs.txt | 35 ++++++++++++++++++++ 3 files changed, 38 insertions(+), 36 deletions(-) delete mode 100644 packages/fbgemm-xpu/third-party-programs.txt diff --git a/packages/fbgemm-xpu/pyproject.toml b/packages/fbgemm-xpu/pyproject.toml index 0fb5245..0737e73 100644 --- a/packages/fbgemm-xpu/pyproject.toml +++ b/packages/fbgemm-xpu/pyproject.toml @@ -26,9 +26,9 @@ dependencies = [ [project.optional-dependencies] test = [ - "pytest~=8.0", - "hypothesis~=6.0", - "expecttest~=0.3.0" + "pytest", + "hypothesis", + "expecttest" ] [project.urls] @@ -36,7 +36,6 @@ GitHub = "https://github.com/intel/torchlib-xpu" [tool.scikit-build] cmake.version = ">=3.18" -wheel.packages = ["src/fbgemm_xpu"] [tool.scikit-build.cmake.define] CMAKE_CXX_COMPILER = {env="CXX", default="icpx"} diff --git a/packages/fbgemm-xpu/third-party-programs.txt b/packages/fbgemm-xpu/third-party-programs.txt deleted file mode 100644 index b54dbde..0000000 --- a/packages/fbgemm-xpu/third-party-programs.txt +++ /dev/null @@ -1,32 +0,0 @@ -For FBGEMM software - -BSD License - -Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name Facebook nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - --------------------------------------------------------------------------------- diff --git a/third-party-programs.txt b/third-party-programs.txt index c2d18da..a181918 100644 --- a/third-party-programs.txt +++ b/third-party-programs.txt @@ -43,3 +43,38 @@ torchcodec: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +-------------------------------------------------------------------------------- + +FBGEMM: + + BSD License + + For FBGEMM software + + Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name Facebook nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From 4c870d2008458983a6dc394a9de6854f2ae389a0 Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Wed, 10 Jun 2026 16:07:16 +0000 Subject: [PATCH 17/27] Add fbgemm-gpu dependency and update install indexes --- packages/fbgemm-xpu/README.md | 8 ++++++-- packages/fbgemm-xpu/pyproject.toml | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/fbgemm-xpu/README.md b/packages/fbgemm-xpu/README.md index cc43659..06acd62 100644 --- a/packages/fbgemm-xpu/README.md +++ b/packages/fbgemm-xpu/README.md @@ -25,14 +25,18 @@ source .venv/bin/activate ```bash uv pip install -e packages/fbgemm-xpu \ - --index https://download.pytorch.org/whl/xpu + --index https://download.pytorch.org/whl/xpu \ + --extra-index-url https://download.pytorch.org/whl/cpu \ + --index-strategy unsafe-best-match ``` * (Optional) Install test dependencies: ```bash uv pip install -e "packages/fbgemm-xpu[test]" \ - --index https://download.pytorch.org/whl/xpu + --index https://download.pytorch.org/whl/xpu \ + --extra-index-url https://download.pytorch.org/whl/cpu \ + --index-strategy unsafe-best-match ``` * Get installed package version: diff --git a/packages/fbgemm-xpu/pyproject.toml b/packages/fbgemm-xpu/pyproject.toml index 0737e73..04be0e3 100644 --- a/packages/fbgemm-xpu/pyproject.toml +++ b/packages/fbgemm-xpu/pyproject.toml @@ -20,6 +20,7 @@ authors = [ ] dynamic = ["version"] dependencies = [ + "fbgemm-gpu==1.6.0+cpu", "numpy~=2.0", "torch~=2.11.0", ] From a4d9124a58df4ad8e4ad914591f2548f45379539 Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Thu, 11 Jun 2026 20:30:00 +0000 Subject: [PATCH 18/27] Update fbgemm dependency version --- packages/fbgemm-xpu/README.md | 8 ++------ packages/fbgemm-xpu/pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/fbgemm-xpu/README.md b/packages/fbgemm-xpu/README.md index 06acd62..cc43659 100644 --- a/packages/fbgemm-xpu/README.md +++ b/packages/fbgemm-xpu/README.md @@ -25,18 +25,14 @@ source .venv/bin/activate ```bash uv pip install -e packages/fbgemm-xpu \ - --index https://download.pytorch.org/whl/xpu \ - --extra-index-url https://download.pytorch.org/whl/cpu \ - --index-strategy unsafe-best-match + --index https://download.pytorch.org/whl/xpu ``` * (Optional) Install test dependencies: ```bash uv pip install -e "packages/fbgemm-xpu[test]" \ - --index https://download.pytorch.org/whl/xpu \ - --extra-index-url https://download.pytorch.org/whl/cpu \ - --index-strategy unsafe-best-match + --index https://download.pytorch.org/whl/xpu ``` * Get installed package version: diff --git a/packages/fbgemm-xpu/pyproject.toml b/packages/fbgemm-xpu/pyproject.toml index 04be0e3..6f30fc2 100644 --- a/packages/fbgemm-xpu/pyproject.toml +++ b/packages/fbgemm-xpu/pyproject.toml @@ -20,7 +20,7 @@ authors = [ ] dynamic = ["version"] dependencies = [ - "fbgemm-gpu==1.6.0+cpu", + "fbgemm-gpu-cpu==1.7.0", "numpy~=2.0", "torch~=2.11.0", ] From ff9ee1f4a7c988ffcfa3e4e6720a26042485bb83 Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Mon, 15 Jun 2026 11:29:05 -0600 Subject: [PATCH 19/27] Update packages/fbgemm-xpu/src/fbgemm_xpu/ops_registry.cpp Co-authored-by: Dmitry Rogozhkin --- packages/fbgemm-xpu/src/fbgemm_xpu/ops_registry.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/ops_registry.cpp b/packages/fbgemm-xpu/src/fbgemm_xpu/ops_registry.cpp index 16fe11d..8fdb2a5 100644 --- a/packages/fbgemm-xpu/src/fbgemm_xpu/ops_registry.cpp +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/ops_registry.cpp @@ -1,14 +1,6 @@ /* - * Copyright 2026 Intel Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Portions of this file are derived from FBGEMM - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved. + * Copyright (c) 2026 Intel Corporation. All Rights Reserved. * SPDX-License-Identifier: BSD-3-Clause */ From 2644774182982b06238a2f29612050c367e6575e Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Mon, 15 Jun 2026 11:29:38 -0600 Subject: [PATCH 20/27] Update packages/fbgemm-xpu/src/fbgemm_xpu/ops.py Co-authored-by: Dmitry Rogozhkin --- packages/fbgemm-xpu/src/fbgemm_xpu/ops.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/ops.py b/packages/fbgemm-xpu/src/fbgemm_xpu/ops.py index 1226915..0d10647 100644 --- a/packages/fbgemm-xpu/src/fbgemm_xpu/ops.py +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/ops.py @@ -1,7 +1,5 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved. # Copyright (c) 2026 Intel Corporation. All Rights Reserved. -# -# Portions of this file are derived from FBGEMM -# Copyright (c) Meta Platforms, Inc. and affiliates. # SPDX-License-Identifier: BSD-3-Clause # Python wrapper functions for all custom operators under the fbgemm namespace From 2ecdfc9b3d26bf7fa426bc29de06621f76100b34 Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Mon, 15 Jun 2026 11:30:13 -0600 Subject: [PATCH 21/27] Update packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py Co-authored-by: Dmitry Rogozhkin --- packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py b/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py index 478bd0b..31522c0 100644 --- a/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/__init__.py @@ -1,7 +1,5 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved. # Copyright (c) 2026 Intel Corporation. All Rights Reserved. -# -# Portions of this file are derived from FBGEMM -# Copyright (c) Meta Platforms, Inc. and affiliates. # SPDX-License-Identifier: BSD-3-Clause # Import the compiled C extension (_C) which contains the registered operators. From 33addcf4aab3555e099c82e48c2851ba2e9baa6d Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Mon, 15 Jun 2026 11:48:17 -0600 Subject: [PATCH 22/27] Update packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt Co-authored-by: Dmitry Rogozhkin --- packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt index 23838d0..d00cd6b 100644 --- a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt @@ -40,8 +40,8 @@ else() OUTPUT_STRIP_TRAILING_WHITESPACE RESULT_VARIABLE _arch_rc ) - if(NOT _arch_rc EQUAL 0 OR TORCH_XPU_ARCH_LIST STREQUAL "") - set(TORCH_XPU_ARCH_LIST "pvc") + if(NOT _arch_rc EQUAL 0) + message(WARNING "Failed to retrieve torch.xpu.get_arch_list()") endif() endif() message(STATUS "Building for XPU architectures: ${TORCH_XPU_ARCH_LIST}") From a3a82aaf5a9694f7c1a39d51cf9e5a839395d5c5 Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Mon, 15 Jun 2026 11:57:49 -0600 Subject: [PATCH 23/27] Update packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt Co-authored-by: Dmitry Rogozhkin --- packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt index d00cd6b..0f16a48 100644 --- a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt @@ -44,6 +44,9 @@ else() message(WARNING "Failed to retrieve torch.xpu.get_arch_list()") endif() endif() +if (NOT TORCH_XPU_ARCH_LIST) + message(FATAL_ERROR "Empty XPU architecture list" +endif() message(STATUS "Building for XPU architectures: ${TORCH_XPU_ARCH_LIST}") set(SYCL_TARGETS -fsycl-targets=spir64_gen,spir64) From f60cee6c9269f88924d319355a0a889c02a8e10e Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Mon, 15 Jun 2026 23:14:57 +0000 Subject: [PATCH 24/27] Address PR comments: mandate SYCL, restrict to PVC, improve docs --- packages/fbgemm-xpu/MANIFEST.in | 3 - packages/fbgemm-xpu/README.md | 36 ++++++++++- packages/fbgemm-xpu/pyproject.toml | 4 +- .../fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt | 62 +++++++------------ 4 files changed, 56 insertions(+), 49 deletions(-) delete mode 100644 packages/fbgemm-xpu/MANIFEST.in diff --git a/packages/fbgemm-xpu/MANIFEST.in b/packages/fbgemm-xpu/MANIFEST.in deleted file mode 100644 index 6d8aa75..0000000 --- a/packages/fbgemm-xpu/MANIFEST.in +++ /dev/null @@ -1,3 +0,0 @@ -include LICENSE -include README.md -recursive-include src *.cpp *.h *.sycl *.py diff --git a/packages/fbgemm-xpu/README.md b/packages/fbgemm-xpu/README.md index cc43659..be2884c 100644 --- a/packages/fbgemm-xpu/README.md +++ b/packages/fbgemm-xpu/README.md @@ -1,8 +1,27 @@ -# fbgemm-xpu +# Intel XPU Plugin for FBGEMM -Intel XPU plugin package for FBGEMM operators. +## Overview -## Build from source +[FBGEMM] is an optimized library for GEMMs and low-precision training. The Intel® XPU plugin for [FBGEMM] enables hardware acceleration for specific [FBGEMM] operators on Intel GPUs using SYCL kernels. Currently, acceleration is primarily targeted for DLRM v3 workloads. + +To use Intel® XPU plugin for [FBGEMM], load it in your Python script and ensure tensors are on XPU device: + +```python +import torch +import fbgemm_xpu + +# Usage examples will be added as operators are integrated into this project +``` + +## Supported hardware + +Currently, only [Intel® Data Center GPU Max Series][PVC] (Ponte Vecchio, PVC) GPUs are supported. + +## Installation + +Pre-built wheels will be available on [PyPI](https://pypi.org) in the future. + +For now, build from source: * Install [uv] @@ -41,4 +60,15 @@ uv pip install -e "packages/fbgemm-xpu[test]" \ python -c "import fbgemm_xpu; print(fbgemm_xpu.__version__)" ``` +## Environment variables + +Environment variables will be added as new FBGEMM operators are integrated into this project. + +## Known limitations + +Known limitations will be documented as new FBGEMM operators are integrated into this project. + +[FBGEMM]: https://github.com/pytorch/FBGEMM [uv]: https://github.com/astral-sh/uv +[PVC]: https://www.intel.com/content/www/us/en/ark/products/series/232874/intel-data-center-gpu-max-series.html + diff --git a/packages/fbgemm-xpu/pyproject.toml b/packages/fbgemm-xpu/pyproject.toml index 6f30fc2..5ee2ee8 100644 --- a/packages/fbgemm-xpu/pyproject.toml +++ b/packages/fbgemm-xpu/pyproject.toml @@ -3,7 +3,7 @@ requires = [ "numpy~=2.0", "pybind11", "scikit-build-core>=0.10", - "torch~=2.11.0", + "torch~=2.12.0", ] build-backend = "scikit_build_core.build" @@ -22,7 +22,7 @@ dynamic = ["version"] dependencies = [ "fbgemm-gpu-cpu==1.7.0", "numpy~=2.0", - "torch~=2.11.0", + "torch~=2.12.0", ] [project.optional-dependencies] diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt index 0f16a48..e0fbe1e 100644 --- a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt @@ -15,37 +15,25 @@ find_package(pybind11 REQUIRED) find_package(Torch REQUIRED) # -------------------------------------------------------------------------- -# SYCL backend detection: enabled only when CXX is the Intel oneAPI compiler -# (icpx). Falls back to a host-only CPU build otherwise. Mirrors the previous -# setup.py behavior driven by USE_SYCL / torch.xpu.is_available(). +# SYCL backend: required for fbgemm-xpu. All kernels are SYCL-based, so the +# Intel oneAPI compiler (icpx) is mandatory. # -------------------------------------------------------------------------- -if(CMAKE_CXX_COMPILER MATCHES "icpx") - set(WITH_SYCL ON) - message(STATUS "Intel compiler detected: SYCL kernels enabled") -else() - set(WITH_SYCL OFF) - message(STATUS "Non-Intel compiler in use: SYCL kernels disabled") +if(NOT CMAKE_CXX_COMPILER MATCHES "icpx") + message(FATAL_ERROR "fbgemm-xpu requires Intel oneAPI compiler (icpx) with SYCL support") endif() +message(STATUS "Intel compiler detected: SYCL kernels enabled") # -------------------------------------------------------------------------- -# XPU architecture list. Honors TORCH_XPU_ARCH_LIST env var, otherwise queries -# torch.xpu.get_arch_list(), otherwise defaults to "pvc". +# XPU architecture: currently only PVC (Ponte Vecchio) is supported. # -------------------------------------------------------------------------- if(NOT "$ENV{TORCH_XPU_ARCH_LIST}" STREQUAL "") - set(TORCH_XPU_ARCH_LIST "$ENV{TORCH_XPU_ARCH_LIST}") -else() - execute_process( - COMMAND ${Python3_EXECUTABLE} -c "import torch; print(','.join(torch.xpu.get_arch_list()))" - OUTPUT_VARIABLE TORCH_XPU_ARCH_LIST - OUTPUT_STRIP_TRAILING_WHITESPACE - RESULT_VARIABLE _arch_rc - ) - if(NOT _arch_rc EQUAL 0) - message(WARNING "Failed to retrieve torch.xpu.get_arch_list()") + set(_requested_arch "$ENV{TORCH_XPU_ARCH_LIST}") + if(NOT _requested_arch MATCHES "pvc") + message(FATAL_ERROR "fbgemm-xpu currently only supports PVC architecture, requested: ${_requested_arch}") endif() -endif() -if (NOT TORCH_XPU_ARCH_LIST) - message(FATAL_ERROR "Empty XPU architecture list" + set(TORCH_XPU_ARCH_LIST ${_requested_arch}) +else() + set(TORCH_XPU_ARCH_LIST "pvc") endif() message(STATUS "Building for XPU architectures: ${TORCH_XPU_ARCH_LIST}") @@ -53,11 +41,9 @@ set(SYCL_TARGETS -fsycl-targets=spir64_gen,spir64) set(SYCL_DEVICE_LIST -Xs "-device ${TORCH_XPU_ARCH_LIST} -options -cl-poison-unsupported-fp64-kernels") # -------------------------------------------------------------------------- -# Sources -# -# host_sources lists host C++ files that live alongside this CMakeLists. -# SYCL kernels (.sycl) and companion .cpp files under sycl_kernels/ or -# fbgemm_utils/ are picked up automatically by the GLOB_RECURSE below. +# Sources: both host and SYCL kernel sources must be present for fbgemm-xpu +# to function. SYCL kernels (.sycl) and companion .cpp files are collected +# from sycl_kernels/ and fbgemm_utils/ directories. # -------------------------------------------------------------------------- # Auto-include all host C++ sources in this directory. file(GLOB host_sources CONFIGURE_DEPENDS @@ -86,17 +72,14 @@ foreach(_src IN LISTS sycl_sources) endif() endforeach() -if(WITH_SYCL) - set(all_sources ${host_sources} ${sycl_sources_cxx}) -else() - set(all_sources ${host_sources}) -endif() +set(all_sources ${host_sources} ${sycl_sources_cxx}) # -------------------------------------------------------------------------- # Extension module: fbgemm._C # -# Skip target creation if no sources have been added yet — this lets the -# scaffolding configure cleanly before any code is written. +# SYCL kernels are required. Skip target creation if no sources have been +# added yet, this lets the scaffolding configure cleanly before any code +# is written. # -------------------------------------------------------------------------- if(NOT all_sources) message(WARNING "fbgemm._C: no sources defined yet; skipping extension target.") @@ -122,12 +105,9 @@ target_link_libraries(_C PRIVATE ${TORCH_LIBRARIES}) target_compile_options(_C PRIVATE -fdiagnostics-color=always - -Wno-c++11-narrowing ) -if(WITH_SYCL) - target_compile_options(_C PRIVATE -fsycl ${SYCL_TARGETS}) - target_link_options(_C PRIVATE -fsycl ${SYCL_TARGETS} ${SYCL_DEVICE_LIST}) -endif() +target_compile_options(_C PRIVATE -fsycl ${SYCL_TARGETS}) +target_link_options(_C PRIVATE -fsycl ${SYCL_TARGETS} ${SYCL_DEVICE_LIST}) install(TARGETS _C DESTINATION fbgemm_xpu) From e51937451504503752b38d82038dd739a277a07c Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Tue, 16 Jun 2026 17:44:53 +0000 Subject: [PATCH 25/27] Enforce PVC-only CMake configuration for fbgemm-xpu --- packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt index e0fbe1e..9ec9b06 100644 --- a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt @@ -28,7 +28,7 @@ message(STATUS "Intel compiler detected: SYCL kernels enabled") # -------------------------------------------------------------------------- if(NOT "$ENV{TORCH_XPU_ARCH_LIST}" STREQUAL "") set(_requested_arch "$ENV{TORCH_XPU_ARCH_LIST}") - if(NOT _requested_arch MATCHES "pvc") + if(NOT _requested_arch STREQUAL "pvc") message(FATAL_ERROR "fbgemm-xpu currently only supports PVC architecture, requested: ${_requested_arch}") endif() set(TORCH_XPU_ARCH_LIST ${_requested_arch}) From 20fc96851d0c76ac4ab8ab92d26d8535b7b4f12d Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Tue, 16 Jun 2026 16:27:11 -0600 Subject: [PATCH 26/27] Update packages/fbgemm-xpu/version.txt Co-authored-by: Dmitry Rogozhkin --- packages/fbgemm-xpu/version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fbgemm-xpu/version.txt b/packages/fbgemm-xpu/version.txt index 6e8bf73..faef31a 100644 --- a/packages/fbgemm-xpu/version.txt +++ b/packages/fbgemm-xpu/version.txt @@ -1 +1 @@ -0.1.0 +0.7.0 From 8990c272fa4d55217f406059527db6dee5d53015 Mon Sep 17 00:00:00 2001 From: Felipe Leza Alvarez Date: Tue, 16 Jun 2026 16:51:21 -0600 Subject: [PATCH 27/27] Update packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt Co-authored-by: Dmitry Rogozhkin --- packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt index 9ec9b06..bd07716 100644 --- a/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt +++ b/packages/fbgemm-xpu/src/fbgemm_xpu/CMakeLists.txt @@ -27,11 +27,7 @@ message(STATUS "Intel compiler detected: SYCL kernels enabled") # XPU architecture: currently only PVC (Ponte Vecchio) is supported. # -------------------------------------------------------------------------- if(NOT "$ENV{TORCH_XPU_ARCH_LIST}" STREQUAL "") - set(_requested_arch "$ENV{TORCH_XPU_ARCH_LIST}") - if(NOT _requested_arch STREQUAL "pvc") - message(FATAL_ERROR "fbgemm-xpu currently only supports PVC architecture, requested: ${_requested_arch}") - endif() - set(TORCH_XPU_ARCH_LIST ${_requested_arch}) + set(TORCH_XPU_ARCH_LIST "$ENV{TORCH_XPU_ARCH_LIST}") else() set(TORCH_XPU_ARCH_LIST "pvc") endif()