From 6687e2f2059f6b06411c323d0d2fa5913faa6832 Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Fri, 4 Oct 2024 12:31:16 +0200 Subject: [PATCH 01/13] treat Flex gpus same as Arc --- include/network/SwiftNetMLP.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/network/SwiftNetMLP.h b/include/network/SwiftNetMLP.h index 2a774bb..93cb36e 100644 --- a/include/network/SwiftNetMLP.h +++ b/include/network/SwiftNetMLP.h @@ -257,6 +257,8 @@ template class SwiftNetMLP : public Network { throw std::logic_error("Code built for PVC but tried to run on different device."); #elif TARGET_DEVICE == 1 if (Network::get_queue().get_device().template get_info().find("Arc") == + std::string::npos && + Network::get_queue().get_device().template get_info().find("Flex") == std::string::npos) throw std::logic_error("Code built for ARC GPU but tried to run on different device."); #else From 49789450233eab5cd6093ef56ac0c76053b4d0a2 Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Sat, 12 Oct 2024 09:06:25 +0200 Subject: [PATCH 02/13] Update device name check for WSL2 --- include/network/SwiftNetMLP.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/network/SwiftNetMLP.h b/include/network/SwiftNetMLP.h index 93cb36e..5875e58 100644 --- a/include/network/SwiftNetMLP.h +++ b/include/network/SwiftNetMLP.h @@ -259,6 +259,9 @@ template class SwiftNetMLP : public Network { if (Network::get_queue().get_device().template get_info().find("Arc") == std::string::npos && Network::get_queue().get_device().template get_info().find("Flex") == + std::string::npos && + // In WSL2 the device name is just "Intel(R) Graphics" + Network::get_queue().get_device().template get_info().find("Intel(R) Graphics") == std::string::npos) throw std::logic_error("Code built for ARC GPU but tried to run on different device."); #else From 6aead00c20b30e2eba9fe944aee3c6425f9a8298 Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Mon, 12 May 2025 15:27:41 +0000 Subject: [PATCH 03/13] debug snapshot --- dpcpp_bindings/setup2.py | 86 +++++++++++++++++++ .../tiny_dpcpp_nn/pybind_module.cpp | 8 +- include/common/tensor_legacy_helper.h | 18 ++++ include/network/SwiftNetMLP.h | 2 +- include/tnn_api.h | 12 +-- 5 files changed, 116 insertions(+), 10 deletions(-) create mode 100644 dpcpp_bindings/setup2.py create mode 100644 include/common/tensor_legacy_helper.h diff --git a/dpcpp_bindings/setup2.py b/dpcpp_bindings/setup2.py new file mode 100644 index 0000000..bee158a --- /dev/null +++ b/dpcpp_bindings/setup2.py @@ -0,0 +1,86 @@ +import os +from setuptools import setup + +from intel_extension_for_pytorch.xpu.cpp_extension import ( + DPCPPExtension, + DpcppBuildExtension, + IS_LINUX, +) + +# Here ze_loader is not necessary, just used to check libraries linker +# libraries = ["ze_loader"] if IS_LINUX else [] +libraries = [] + +dpcpp_path = os.getenv("CMPLR_ROOT") +dpcpp_sycl_path = os.path.join(dpcpp_path, "include", "sycl") + +conda_path = os.getenv("CONDA_PREFIX") +conda_sycl_path = os.path.join(conda_path, "include", "sycl") + +setup( + name="tiny_dpcpp_nn_pybind_module", + version="0.0.1", + description="Python bindings for the tiny-dpcpp-nn library", + ext_modules=[ + DPCPPExtension( + "tiny_dpcpp_nn_pybind_module", + [ + "tiny_dpcpp_nn/pybind_module.cpp", + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1664none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLP.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1664sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1616none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1632sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf16128none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp16128relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp16128none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf1664.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1632relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimd.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1616none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp1664.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1616relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp16128sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp1632.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf16128relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1664relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf1632.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp16128.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp1616.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1664relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1664sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1632sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf1616.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1664none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1616relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1616sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1616sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1632none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf16128.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1632relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1632none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf16128sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "optimizers", "sgd.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "optimizers", "adam.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "common", "SyclGraph.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "common", "common.cpp"), + ], + libraries=libraries, + extra_compile_args={'cxx': ['-DTARGET_DEVICE=1', '-std=c++20', '-fPIC']}, + include_dirs=( + [dpcpp_sycl_path] + if not os.path.exists(conda_sycl_path) + else [conda_sycl_path] + + [ + os.path.join(os.path.dirname(__file__), "../include"), + os.path.join(os.path.dirname(__file__), "../include/network"), + os.path.join(os.path.dirname(__file__), "../include/common"), + os.path.join(os.path.dirname(__file__), "../include/encodings"), + os.path.join(os.path.dirname(__file__), "../include/optimizers"), + os.path.join(os.path.dirname(__file__), "../extern/json"), + ] + ), + ) + ], + cmdclass={"build_ext": DpcppBuildExtension.with_options(use_ninja=True)}, +) \ No newline at end of file diff --git a/dpcpp_bindings/tiny_dpcpp_nn/pybind_module.cpp b/dpcpp_bindings/tiny_dpcpp_nn/pybind_module.cpp index 3842518..69cc373 100644 --- a/dpcpp_bindings/tiny_dpcpp_nn/pybind_module.cpp +++ b/dpcpp_bindings/tiny_dpcpp_nn/pybind_module.cpp @@ -10,14 +10,14 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include -#include -#include // for automatic conversion +// #include +// #include +// #include // for automatic conversion #include // clang-format off #include "tnn_api.h" // need to include json before pybind11_json -#include "pybind11_json.hpp" +// #include "pybind11_json.hpp" // clang-format off using json = nlohmann::json; diff --git a/include/common/tensor_legacy_helper.h b/include/common/tensor_legacy_helper.h new file mode 100644 index 0000000..2abfeb9 --- /dev/null +++ b/include/common/tensor_legacy_helper.h @@ -0,0 +1,18 @@ +#include + +namespace xpu { +namespace dpcpp { + + torch::Tensor fromUSM(void *ptr, torch::Dtype dtype, std::vector sizes, bool clone = true) { + const torch::TensorOptions &options = + torch::TensorOptions().dtype(dtype).device(torch::kXPU); + if (clone) { + return torch::from_blob(ptr, sizes, options).clone(); + } + else { + return torch::from_blob(ptr, sizes, options); + } + } + +} // namespace dpcpp +} // namespace xpu diff --git a/include/network/SwiftNetMLP.h b/include/network/SwiftNetMLP.h index 5875e58..1e3b310 100644 --- a/include/network/SwiftNetMLP.h +++ b/include/network/SwiftNetMLP.h @@ -12,7 +12,7 @@ #pragma once -#include +#include #include #include #include diff --git a/include/tnn_api.h b/include/tnn_api.h index 00faecd..e88e2aa 100644 --- a/include/tnn_api.h +++ b/include/tnn_api.h @@ -12,6 +12,7 @@ #pragma once +#include #include #include @@ -32,6 +33,7 @@ #include "json.hpp" #include "oneapi/mkl.hpp" #include "result_check.h" +#include "tensor_legacy_helper.h" extern template class SwiftNetMLP; extern template class SwiftNetMLP; @@ -292,11 +294,11 @@ class Module { private: sycl::queue &sycl_queue_; static sycl::queue &InitQueue() { - // return c10::xpu::getCurrentXPUStream().queue(); - auto device_type = c10::DeviceType::XPU; - c10::impl::VirtualGuardImpl impl(device_type); - c10::Stream xpu_stream = impl.getStream(c10::Device(device_type)); - return xpu::get_queue_from_stream(xpu_stream); + return c10::xpu::getCurrentXPUStream().queue(); + // auto device_type = c10::DeviceType::XPU; + // c10::impl::VirtualGuardImpl impl(device_type); + // c10::Stream xpu_stream = impl.getStream(c10::Device(device_type)); + // return xpu::get_queue_from_stream(xpu_stream); } }; From cab746caaef325e0132b8898c0ae0342a704e768 Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Tue, 13 May 2025 09:59:52 +0000 Subject: [PATCH 04/13] build system fixes --- dpcpp_bindings/setup.py | 229 ++++++++---------------- dpcpp_bindings/setup2.py | 86 --------- dpcpp_bindings/tiny_dpcpp_nn/modules.py | 2 +- 3 files changed, 80 insertions(+), 237 deletions(-) delete mode 100644 dpcpp_bindings/setup2.py diff --git a/dpcpp_bindings/setup.py b/dpcpp_bindings/setup.py index 1f75811..d48a993 100644 --- a/dpcpp_bindings/setup.py +++ b/dpcpp_bindings/setup.py @@ -1,158 +1,87 @@ import os -import re -import subprocess -import sys -from pathlib import Path -import torch +from setuptools import setup -from setuptools import Extension, setup -from setuptools.command.build_ext import build_ext - -# Convert distutils Windows platform specifiers to CMake -A arguments -PLAT_TO_CMAKE = { - "win32": "Win32", - "win-amd64": "x64", - "win-arm32": "ARM", - "win-arm64": "ARM64", -} - - -# A CMakeExtension needs a sourcedir instead of a file list. -# The name must be the _single_ output extension from the CMake build. -# If you need multiple extensions, see scikit-build. -class CMakeExtension(Extension): - def __init__(self, name: str, sourcedir: str = "") -> None: - super().__init__(name, sources=[]) - self.sourcedir = os.fspath(Path(sourcedir).resolve()) - - -class CMakeBuild(build_ext): - def build_extension(self, ext: CMakeExtension) -> None: - # Must be in this form due to bug in .resolve() only fixed in Python 3.10+ - ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name) - extdir = ext_fullpath.parent.resolve() - - # Using this requires trailing slash for auto-detection & inclusion of - # auxiliary "native" libs - - debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug - cfg = "Debug" if debug else "Release" - - # CMake lets you override the generator - we need to check this. - # Can be set with Conda-Build, for example. - cmake_generator = os.environ.get("CMAKE_GENERATOR", "") - - # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON - # EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code - # from Python. - target_device = os.environ.get("TARGET_DEVICE", "ARC") - - # Validate TARGET_DEVICE - if target_device not in {"ARC", "PVC"}: - raise ValueError( - "TARGET_DEVICE environment variable must be either 'ARC', 'PVC'." - ) - - cmake_args = [ - f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}", - f"-DPYTHON_EXECUTABLE={sys.executable}", - f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm - f"-DTORCH_CMAKE_PREFIX_PATH={torch.utils.cmake_prefix_path}", - "-DCMAKE_CXX_FLAGS=-fPIC", - f"-DTARGET_DEVICE={target_device}", - "-D BUILD_TEST=OFF", - "-D BUILD_BENCHMARK=OFF", - "-D BUILD_PYBIND=ON", - ] - build_args = [] - # Adding CMake arguments set as environment variable - # (needed e.g. to build for ARM OSx on conda-forge) - if "CMAKE_ARGS" in os.environ: - cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item] - - # In this example, we pass in the version to C++. You might not need to. - cmake_args += [f"-DEXAMPLE_VERSION_INFO={self.distribution.get_version()}"] - - if self.compiler.compiler_type != "msvc": - # Using Ninja-build since it a) is available as a wheel and b) - # multithreads automatically. MSVC would require all variables be - # exported for Ninja to pick it up, which is a little tricky to do. - # Users can override the generator with CMAKE_GENERATOR in CMake - # 3.15+. - if not cmake_generator or cmake_generator == "Ninja": - try: - import ninja - - ninja_executable_path = Path(ninja.BIN_DIR) / "ninja" - cmake_args += [ - "-GNinja", - f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}", - ] - except ImportError: - pass - - else: - # Single config generators are handled "normally" - single_config = any(x in cmake_generator for x in {"NMake", "Ninja"}) - - # CMake allows an arch-in-generator style for backward compatibility - contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"}) - - # Specify the arch if using MSVC generator, but only if it doesn't - # contain a backward-compatibility arch spec already in the - # generator name. - if not single_config and not contains_arch: - cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]] - - # Multi-config generators have a different way to specify configs - if not single_config: - cmake_args += [ - f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}" - ] - build_args += ["--config", cfg] - - if sys.platform.startswith("darwin"): - # Cross-compile support for macOS - respect ARCHFLAGS if set - archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", "")) - if archs: - cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))] - - # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level - # across all generators. - if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ: - # self.parallel is a Python 3 only way to set parallel jobs by hand - # using -j in the build_ext call, not supported by pip or PyPA-build. - if hasattr(self, "parallel") and self.parallel: - # CMake 3.12+ only. - build_args += [f"-j{self.parallel}"] - - build_temp = Path(self.build_temp) / ext.name - if not build_temp.exists(): - build_temp.mkdir(parents=True) +from intel_extension_for_pytorch.xpu.cpp_extension import ( + DPCPPExtension, + DpcppBuildExtension, + IS_LINUX, +) - subprocess.run( - ["cmake", ext.sourcedir, *cmake_args], - cwd=build_temp, - check=True, - capture_output=False, - ) +# Here ze_loader is not necessary, just used to check libraries linker +# libraries = ["ze_loader"] if IS_LINUX else [] +libraries = [] - subprocess.run( - ["cmake", "--build", ".", *build_args], - cwd=build_temp, - check=True, - capture_output=False, - ) +dpcpp_path = os.getenv("CMPLR_ROOT") +dpcpp_sycl_path = os.path.join(dpcpp_path, "include", "sycl") +conda_path = os.getenv("CONDA_PREFIX") +conda_sycl_path = os.path.join(conda_path, "include", "sycl") -# The information here can also be placed in setup.cfg - better separation of -# logic and declaration, and simpler if you include description/version in a file. setup( - name="tiny_dpcpp_nn_pybind_module", + name="tiny_dpcpp_nn", version="0.0.1", - description="A test project using pybind11 and CMake", - long_description="", - ext_modules=[CMakeExtension("tiny_dpcpp_nn_pybind_module", "../")], - cmdclass={"build_ext": CMakeBuild}, - python_requires=">=3.7", -) + description="Python bindings for the tiny-dpcpp-nn library", + packages=["tiny_dpcpp_nn"], + ext_modules=[ + DPCPPExtension( + "tiny_dpcpp_nn.tiny_dpcpp_nn_pybind_module", + [ + "tiny_dpcpp_nn/pybind_module.cpp", + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1664none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLP.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1664sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1616none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1632sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf16128none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp16128relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp16128none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf1664.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1632relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimd.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1616none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp1664.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1616relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp16128sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp1632.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf16128relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1664relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf1632.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp16128.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp1616.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1664relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1664sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1632sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf1616.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1664none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1616relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1616sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1616sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1632none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf16128.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1632relu.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1632none.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf16128sigmoid.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "optimizers", "sgd.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "optimizers", "adam.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "common", "SyclGraph.cpp"), + os.path.join(os.path.dirname(__file__), "..", "source", "common", "common.cpp"), + ], + libraries=libraries, + extra_compile_args={'cxx': ['-DTARGET_DEVICE=1', '-std=c++20', '-fPIC']}, + include_dirs=( + [dpcpp_sycl_path] + if not os.path.exists(conda_sycl_path) + else [conda_sycl_path] + + [ + os.path.join(os.path.dirname(__file__), "../include"), + os.path.join(os.path.dirname(__file__), "../include/network"), + os.path.join(os.path.dirname(__file__), "../include/common"), + os.path.join(os.path.dirname(__file__), "../include/encodings"), + os.path.join(os.path.dirname(__file__), "../include/optimizers"), + os.path.join(os.path.dirname(__file__), "../extern/json"), + ] + ), + ) + ], + cmdclass={"build_ext": DpcppBuildExtension.with_options(use_ninja=True)}, +) \ No newline at end of file diff --git a/dpcpp_bindings/setup2.py b/dpcpp_bindings/setup2.py deleted file mode 100644 index bee158a..0000000 --- a/dpcpp_bindings/setup2.py +++ /dev/null @@ -1,86 +0,0 @@ -import os -from setuptools import setup - -from intel_extension_for_pytorch.xpu.cpp_extension import ( - DPCPPExtension, - DpcppBuildExtension, - IS_LINUX, -) - -# Here ze_loader is not necessary, just used to check libraries linker -# libraries = ["ze_loader"] if IS_LINUX else [] -libraries = [] - -dpcpp_path = os.getenv("CMPLR_ROOT") -dpcpp_sycl_path = os.path.join(dpcpp_path, "include", "sycl") - -conda_path = os.getenv("CONDA_PREFIX") -conda_sycl_path = os.path.join(conda_path, "include", "sycl") - -setup( - name="tiny_dpcpp_nn_pybind_module", - version="0.0.1", - description="Python bindings for the tiny-dpcpp-nn library", - ext_modules=[ - DPCPPExtension( - "tiny_dpcpp_nn_pybind_module", - [ - "tiny_dpcpp_nn/pybind_module.cpp", - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1664none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLP.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1664sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1616none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1632sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf16128none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp16128relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp16128none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf1664.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1632relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimd.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1616none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp1664.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1616relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp16128sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp1632.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf16128relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1664relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf1632.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp16128.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp1616.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1664relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1664sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1632sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf1616.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1664none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1616relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1616sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1616sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1632none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf16128.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1632relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1632none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf16128sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "optimizers", "sgd.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "optimizers", "adam.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "common", "SyclGraph.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "common", "common.cpp"), - ], - libraries=libraries, - extra_compile_args={'cxx': ['-DTARGET_DEVICE=1', '-std=c++20', '-fPIC']}, - include_dirs=( - [dpcpp_sycl_path] - if not os.path.exists(conda_sycl_path) - else [conda_sycl_path] - + [ - os.path.join(os.path.dirname(__file__), "../include"), - os.path.join(os.path.dirname(__file__), "../include/network"), - os.path.join(os.path.dirname(__file__), "../include/common"), - os.path.join(os.path.dirname(__file__), "../include/encodings"), - os.path.join(os.path.dirname(__file__), "../include/optimizers"), - os.path.join(os.path.dirname(__file__), "../extern/json"), - ] - ), - ) - ], - cmdclass={"build_ext": DpcppBuildExtension.with_options(use_ninja=True)}, -) \ No newline at end of file diff --git a/dpcpp_bindings/tiny_dpcpp_nn/modules.py b/dpcpp_bindings/tiny_dpcpp_nn/modules.py index 8d2bf69..f3c2ae0 100644 --- a/dpcpp_bindings/tiny_dpcpp_nn/modules.py +++ b/dpcpp_bindings/tiny_dpcpp_nn/modules.py @@ -3,7 +3,7 @@ import numpy as np import time -from tiny_dpcpp_nn_pybind_module import ( +from .tiny_dpcpp_nn_pybind_module import ( Activation, create_network, create_encoding, From 2563bb80fc61df2f528762f13c64017d116ef5af Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Tue, 13 May 2025 10:00:50 +0000 Subject: [PATCH 05/13] fix capture of const DeviceMem objects --- source/optimizers/adam.cpp | 8 ++++++-- source/optimizers/sgd.cpp | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/source/optimizers/adam.cpp b/source/optimizers/adam.cpp index 9304a8e..984f458 100644 --- a/source/optimizers/adam.cpp +++ b/source/optimizers/adam.cpp @@ -148,16 +148,20 @@ void AdamOptimizer::step(queue q, float loss_scale, DeviceMem &weights, De auto first_moment = m_first_moments.data(); auto second_moment = m_second_moments.data(); + bf16* const weights_data = weights.data(); + bf16* const weightsT_data = weightsT.data(); + bf16* const gradients_data = gradients.data(); + q.parallel_for<>(range<1>(n_elements), [=](id<1> idx) { adam_step(idx, n_elements, relative_weight_decay, absolute_weight_decay, weight_clipping_magnitude, loss_scale, learning_rate, non_matrix_learning_rate_factor, beta1, beta2, epsilon, lower_lr_bound, - upper_lr_bound, l2_reg, weights.data(), gradients.data(), first_moment, second_moment, WIDTH); + upper_lr_bound, l2_reg, weights_data, gradients_data, first_moment, second_moment, WIDTH); }).wait(); q.parallel_for<>(range<1>(n_elements), [=](id<1> idx) { adam_stepT(idx, n_elements, relative_weight_decay, absolute_weight_decay, weight_clipping_magnitude, loss_scale, learning_rate, non_matrix_learning_rate_factor, beta1, beta2, epsilon, lower_lr_bound, - upper_lr_bound, l2_reg, weightsT.data(), gradients.data(), first_moment, second_moment, WIDTH); + upper_lr_bound, l2_reg, weightsT_data, gradients_data, first_moment, second_moment, WIDTH); }).wait(); } diff --git a/source/optimizers/sgd.cpp b/source/optimizers/sgd.cpp index 1a8dbfe..73a8e52 100644 --- a/source/optimizers/sgd.cpp +++ b/source/optimizers/sgd.cpp @@ -137,16 +137,20 @@ void SGDOptimizer::step(queue q, float loss_scale, DeviceMem &weights, Dev const int output_rows = m_output_rows; const int n_hidden_layers = m_n_hidden_layers; + bf16* const weights_data = weights.data(); + bf16* const weightsT_data = weightsT.data(); + bf16* const gradients_data = gradients.data(); + // Perform the SGD update for weight matrices q.parallel_for<>(range<1>(n_elements), [=](id<1> idx) { - sgd_step(idx, n_elements, output_rows, n_hidden_layers, loss_scale, learning_rate, l2_reg, weights.data(), - gradients.data(), WIDTH); + sgd_step(idx, n_elements, output_rows, n_hidden_layers, loss_scale, learning_rate, l2_reg, weights_data, + gradients_data, WIDTH); }).wait(); // Perform the SGD update for transposed weight matrices q.parallel_for<>(range<1>(n_elements), [=](id<1> idx) { - sgd_stepT(idx, n_elements, output_rows, n_hidden_layers, loss_scale, learning_rate, l2_reg, weightsT.data(), - gradients.data(), WIDTH); + sgd_stepT(idx, n_elements, output_rows, n_hidden_layers, loss_scale, learning_rate, l2_reg, weightsT_data, + gradients_data, WIDTH); }).wait(); } From 9fa28d38204463541303d19e06ba432eb09508d9 Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Tue, 13 May 2025 12:49:47 +0000 Subject: [PATCH 06/13] add pyproject.toml and requirements.txt --- dpcpp_bindings/pyproject.toml | 3 +++ dpcpp_bindings/requirements.txt | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 dpcpp_bindings/pyproject.toml create mode 100644 dpcpp_bindings/requirements.txt diff --git a/dpcpp_bindings/pyproject.toml b/dpcpp_bindings/pyproject.toml new file mode 100644 index 0000000..0ecf3aa --- /dev/null +++ b/dpcpp_bindings/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=62.6.0", "wheel"] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/dpcpp_bindings/requirements.txt b/dpcpp_bindings/requirements.txt new file mode 100644 index 0000000..22bd2f9 --- /dev/null +++ b/dpcpp_bindings/requirements.txt @@ -0,0 +1,7 @@ +--index-url https://download.pytorch.org/whl/xpu +--extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/ +torch==2.7.0 +torchvision==0.22.0 +torchaudio==2.7.0 +intel-extension-for-pytorch==2.7.10+xpu +oneccl_bind_pt==2.7.0+xpu \ No newline at end of file From 55fbf10319bd5a9950673b8f9b5e67428ffc6a46 Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Tue, 13 May 2025 12:50:32 +0000 Subject: [PATCH 07/13] fix some type warnings --- include/encodings/frequency.h | 2 +- include/encodings/grid.h | 2 +- include/network/Network.h | 30 +++++++++++++++++------------- include/network/SwiftNetMLP.h | 6 +++--- include/tnn_api.h | 2 +- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/include/encodings/frequency.h b/include/encodings/frequency.h index 81dc9e2..e0e3ccf 100644 --- a/include/encodings/frequency.h +++ b/include/encodings/frequency.h @@ -121,7 +121,7 @@ class FrequencyEncoding : public Encoding { const uint32_t outputs_per_input = n_frequencies * 2; float result = 0.0f; - for (int k = 0; k < outputs_per_input; ++k) { + for (int k = 0; k < int(outputs_per_input); ++k) { result += (float)dL_doutput(i, j * outputs_per_input + k) * dy_dx[i * n_dims_to_encode * outputs_per_input + j * outputs_per_input + k]; } loc_dL_dinput(i, j) = result; diff --git a/include/encodings/grid.h b/include/encodings/grid.h index aa2ba4d..b7e9909 100644 --- a/include/encodings/grid.h +++ b/include/encodings/grid.h @@ -258,7 +258,7 @@ void kernel_grid_backward_input(const size_t num_elements, dL_dx(i, dim) = 0.0f; } - for (int k = 0; k < num_grid_features; ++k) { + for (int k = 0; k < int(num_grid_features); ++k) { const float dL_dy_local = (float)dL_dy_rm(i, k); for (uint32_t dim = 0; dim < N_POS_DIMS; ++dim) { diff --git a/include/network/Network.h b/include/network/Network.h index 45c079c..c58c6df 100644 --- a/include/network/Network.h +++ b/include/network/Network.h @@ -63,15 +63,19 @@ template class Network : public NetworkBase { Network(sycl::queue &q, const int n_hidden_layers, const int input_width, const int network_width, const int output_width, const WeightInitMode mode, const bool use_bias) - : m_q(q), input_width_(PadWidths(input_width, network_width)), - output_width_(PadWidths(output_width, network_width)), original_input_width_(input_width), - original_output_width_(output_width), n_hidden_layers_(NonNegative(n_hidden_layers)), - network_width_(NonNegative(network_width)), - m_weights_matrices(get_n_hidden_layers() + 1, get_input_width(), get_network_width(), get_network_width(), + : m_q(q), + input_width_(PadWidths(input_width, network_width)), + output_width_(PadWidths(output_width, network_width)), + original_output_width_(output_width), + original_input_width_(input_width), + n_hidden_layers_(NonNegative(n_hidden_layers)), + network_width_(NonNegative(network_width)), + use_bias_(use_bias), + m_weights_matrices(get_n_hidden_layers() + 1, get_input_width(), get_network_width(), get_network_width(), get_network_width(), get_network_width(), get_output_width(), m_q), - m_weightsT_matrices(get_n_hidden_layers() + 1, get_network_width(), get_input_width(), get_network_width(), - get_network_width(), get_output_width(), get_network_width(), m_q), - use_bias_(use_bias) { + m_weightsT_matrices(get_n_hidden_layers() + 1, get_network_width(), get_input_width(), get_network_width(), + get_network_width(), get_output_width(), get_network_width(), m_q) + { SanityCheck(); initialize_weights_matrices(input_width, output_width, mode); @@ -135,14 +139,14 @@ template class Network : public NetworkBase { throw std::runtime_error(errorMessage); } - if (get_input_width() > network_width_) { + if (int(get_input_width()) > network_width_) { std::string errorMessage = "Input width of " + std::to_string(get_input_width()) + " is not supported. Value must be <= network width (" + std::to_string(network_width_) + ")."; throw std::runtime_error(errorMessage); } - if (get_output_width() > network_width_) { + if (int(get_output_width()) > network_width_) { std::string errorMessage = "Input width of " + std::to_string(get_output_width()) + " is not supported. Value must be <= network width (" + std::to_string(network_width_) + ")."; @@ -158,14 +162,14 @@ template class Network : public NetworkBase { if (network_width_ != 16 && network_width_ != 32 && network_width_ != 64 && network_width_ != 128) throw std::invalid_argument("Network width has to be a power of 2 between 16 and 128."); - if (network_width_ != get_input_width() || network_width_ != get_output_width()) + if (network_width_ != int(get_input_width()) || network_width_ != int(get_output_width())) throw std::invalid_argument("Only networks with same input, layer and output width are allowed."); } ///@brief Helper function which sets values of the weights matrices to 0 if /// the actual input/output width was padded to the network-allowed input/output width. void ZeroWeightsPadding(const int unpadded_input_width, const int unpadded_output_width) { - if (unpadded_input_width > get_input_width() || unpadded_output_width > get_output_width()) + if (unpadded_input_width > int(get_input_width()) || unpadded_output_width > int(get_output_width())) throw std::invalid_argument("Padded weights width cannot be less than the unpadded."); /// we need to copy everything here since we do not want to have an implicit copy of 'this' @@ -213,7 +217,7 @@ template class Network : public NetworkBase { } // output matrix set columns to 0 - const int output_matrix_pos = m_weights_matrices.GetNumberOfMatrices() - 1; + // const int output_matrix_pos = m_weights_matrices.GetNumberOfMatrices() - 1; if (unpadded_output_width != padded_output_width) { DeviceMatrixView weights = m_weights_matrices.Back(); m_q.parallel_for( diff --git a/include/network/SwiftNetMLP.h b/include/network/SwiftNetMLP.h index 1e3b310..b3979cc 100644 --- a/include/network/SwiftNetMLP.h +++ b/include/network/SwiftNetMLP.h @@ -331,7 +331,7 @@ template class SwiftNetMLP : public Network { std::to_string(intermediate_output_forward.output_n()) + ")"); } - if (intermediate_output_forward.GetNumberOfMatrices() != Network::get_n_hidden_layers() + 2) { + if (int(intermediate_output_forward.GetNumberOfMatrices()) != Network::get_n_hidden_layers() + 2) { throw std::invalid_argument("Not enough matrices in intermediate_output_forward array, expected: " + std::to_string(Network::get_n_hidden_layers() + 2) + " but got: " + std::to_string(intermediate_output_forward.GetNumberOfMatrices())); @@ -368,7 +368,7 @@ template class SwiftNetMLP : public Network { std::to_string(intermediate_output_forward.middle_n()) + ", " + std::to_string(intermediate_output_forward.output_n()) + ")"); - if (intermediate_output_forward.GetNumberOfMatrices() != Network::get_n_hidden_layers() + 2) + if (int(intermediate_output_forward.GetNumberOfMatrices()) != Network::get_n_hidden_layers() + 2) throw std::invalid_argument("Not enough matrices in intermediate_output_forward array. Required: " + std::to_string(Network::get_n_hidden_layers() + 2) + ", available: " + std::to_string(intermediate_output_forward.GetNumberOfMatrices())); @@ -392,7 +392,7 @@ template class SwiftNetMLP : public Network { std::to_string(intermediate_output_backward.middle_n()) + ", " + std::to_string(intermediate_output_backward.output_n()) + ")"); - if (intermediate_output_backward.GetNumberOfMatrices() != Network::get_n_hidden_layers() + 1) + if (int(intermediate_output_backward.GetNumberOfMatrices()) != Network::get_n_hidden_layers() + 1) throw std::invalid_argument("Not enough matrices in intermediate_output_backward array. Required: " + std::to_string(Network::get_n_hidden_layers() + 1) + ", available: " + std::to_string(intermediate_output_backward.GetNumberOfMatrices())); diff --git a/include/tnn_api.h b/include/tnn_api.h index e88e2aa..3af1ded 100644 --- a/include/tnn_api.h +++ b/include/tnn_api.h @@ -383,7 +383,7 @@ class EncodingModule : public Module { } std::unique_ptr model_ctx = nullptr; - const size_t batch_size = grad_output.sizes()[0]; + const auto batch_size = grad_output.sizes()[0]; const int64_t input_width = encoding_->get_input_width(); // Assuming input_from_fwd should have dimensions [batch_size, From 2d0875ad013bdd1ca3bdf41201b539e47bae88af Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Tue, 13 May 2025 13:08:58 +0000 Subject: [PATCH 08/13] fix unused var warning --- include/optimizers/adam.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/optimizers/adam.h b/include/optimizers/adam.h index 2e1e04f..13399c9 100644 --- a/include/optimizers/adam.h +++ b/include/optimizers/adam.h @@ -29,8 +29,8 @@ class AdamOptimizer : public Optimizer { DeviceMem m_first_moments; DeviceMem m_second_moments; - int m_output_rows; - int m_n_hidden_layers; + // int m_output_rows; + // int m_n_hidden_layers; float m_learning_rate = 1e-3f; float m_l2_reg = 1e-8f; }; From f8343e0f9ce0f94c57ba7d8916815545ea00403c Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Tue, 13 May 2025 13:09:18 +0000 Subject: [PATCH 09/13] add back pybind11 headers --- dpcpp_bindings/setup.py | 1 + dpcpp_bindings/tiny_dpcpp_nn/pybind_module.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dpcpp_bindings/setup.py b/dpcpp_bindings/setup.py index d48a993..eaac253 100644 --- a/dpcpp_bindings/setup.py +++ b/dpcpp_bindings/setup.py @@ -79,6 +79,7 @@ os.path.join(os.path.dirname(__file__), "../include/encodings"), os.path.join(os.path.dirname(__file__), "../include/optimizers"), os.path.join(os.path.dirname(__file__), "../extern/json"), + os.path.join(os.path.dirname(__file__), "../extern/pybind11_json"), ] ), ) diff --git a/dpcpp_bindings/tiny_dpcpp_nn/pybind_module.cpp b/dpcpp_bindings/tiny_dpcpp_nn/pybind_module.cpp index 69cc373..3842518 100644 --- a/dpcpp_bindings/tiny_dpcpp_nn/pybind_module.cpp +++ b/dpcpp_bindings/tiny_dpcpp_nn/pybind_module.cpp @@ -10,14 +10,14 @@ * SPDX-License-Identifier: BSD-3-Clause */ -// #include -// #include -// #include // for automatic conversion +#include +#include +#include // for automatic conversion #include // clang-format off #include "tnn_api.h" // need to include json before pybind11_json -// #include "pybind11_json.hpp" +#include "pybind11_json.hpp" // clang-format off using json = nlohmann::json; From 654749f90ba588cfe8f88443ca7cfe905b980d4e Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Tue, 13 May 2025 13:21:09 +0000 Subject: [PATCH 10/13] handle TARGET_DEVICE env var in setup.py --- dpcpp_bindings/setup.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/dpcpp_bindings/setup.py b/dpcpp_bindings/setup.py index eaac253..014191f 100644 --- a/dpcpp_bindings/setup.py +++ b/dpcpp_bindings/setup.py @@ -17,6 +17,18 @@ conda_path = os.getenv("CONDA_PREFIX") conda_sycl_path = os.path.join(conda_path, "include", "sycl") +target_device_map = { + "PVC": "0", + "ARC": "1", +} +target_device = target_device_map.get(os.getenv("TARGET_DEVICE", "ARC")) +if target_device is None: + raise ValueError(f"TARGET_DEVICE must be one of {sorted(target_device_map.keys())}") +if os.getenv("TARGET_DEVICE") is None: + print("Info: TARGET_DEVICE is not set, defaulting to ARC") +else: + print(f"Info: TARGET_DEVICE is set to {os.getenv('TARGET_DEVICE')}") + setup( name="tiny_dpcpp_nn", version="0.0.1", @@ -67,7 +79,7 @@ os.path.join(os.path.dirname(__file__), "..", "source", "common", "common.cpp"), ], libraries=libraries, - extra_compile_args={'cxx': ['-DTARGET_DEVICE=1', '-std=c++20', '-fPIC']}, + extra_compile_args={'cxx': [f'-DTARGET_DEVICE={target_device}', '-std=c++20', '-fPIC']}, include_dirs=( [dpcpp_sycl_path] if not os.path.exists(conda_sycl_path) From 10ba9e151ae03d746be7c740f254e89996c405a4 Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Tue, 13 May 2025 15:24:27 +0000 Subject: [PATCH 11/13] setup.py bugfix --- dpcpp_bindings/setup.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dpcpp_bindings/setup.py b/dpcpp_bindings/setup.py index 014191f..7f1168d 100644 --- a/dpcpp_bindings/setup.py +++ b/dpcpp_bindings/setup.py @@ -15,7 +15,12 @@ dpcpp_sycl_path = os.path.join(dpcpp_path, "include", "sycl") conda_path = os.getenv("CONDA_PREFIX") -conda_sycl_path = os.path.join(conda_path, "include", "sycl") +conda_sycl_path = None +if conda_path is not None: + conda_sycl_path = os.path.join(conda_path, "include", "sycl") + if not os.path.exists(conda_sycl_path): + conda_sycl_path = None + target_device_map = { "PVC": "0", @@ -82,7 +87,7 @@ extra_compile_args={'cxx': [f'-DTARGET_DEVICE={target_device}', '-std=c++20', '-fPIC']}, include_dirs=( [dpcpp_sycl_path] - if not os.path.exists(conda_sycl_path) + if conda_sycl_path is None else [conda_sycl_path] + [ os.path.join(os.path.dirname(__file__), "../include"), From 615f2f49f27265e71ce6393609febecba1d3ae29 Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Tue, 13 May 2025 15:27:15 +0000 Subject: [PATCH 12/13] setup.py bugfix --- dpcpp_bindings/setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dpcpp_bindings/setup.py b/dpcpp_bindings/setup.py index 7f1168d..b375ca3 100644 --- a/dpcpp_bindings/setup.py +++ b/dpcpp_bindings/setup.py @@ -86,9 +86,9 @@ libraries=libraries, extra_compile_args={'cxx': [f'-DTARGET_DEVICE={target_device}', '-std=c++20', '-fPIC']}, include_dirs=( - [dpcpp_sycl_path] + ([dpcpp_sycl_path] if conda_sycl_path is None - else [conda_sycl_path] + else [conda_sycl_path]) + [ os.path.join(os.path.dirname(__file__), "../include"), os.path.join(os.path.dirname(__file__), "../include/network"), From b3e67c9626931b23bac66d491232c8a07b62c005 Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Wed, 21 May 2025 03:52:33 -0700 Subject: [PATCH 13/13] Reverting build to no dependcy on ipex --- CMakeLists.txt | 68 +---------- README.md | 17 ++- dpcpp_bindings/CMakeLists.txt | 12 +- dpcpp_bindings/pyproject.toml | 4 +- dpcpp_bindings/requirements.txt | 11 +- dpcpp_bindings/setup.py | 209 +++++++++++++++++--------------- 6 files changed, 136 insertions(+), 185 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77456e3..24e9a62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,82 +21,18 @@ option(BUILD_BENCHMARK "Build benchmarks in 'benchmark' directory" ON) option(BUILD_DOCUMENTATION "Build the documentation which is online available" OFF) option(BUILD_EXAMPLE "Build the examples" OFF) -set(IPEX_VERSION "2.1.30" CACHE STRING "The version of Intel Extension for PyTorch") -set(TARGET_DEVICE "PVC" CACHE STRING "Valid values {PVC, ARC}") +set(TARGET_DEVICE "PVC" CACHE STRING "Valid values {PVC, ARC}") # Note that ARC includes FLEX systems if (TARGET_DEVICE STREQUAL "PVC") message(STATUS "Building for PVC") add_definitions(-DTARGET_DEVICE=0) elseif (TARGET_DEVICE STREQUAL "ARC") - message(STATUS "Building for ARC") + message(STATUS "Building for ARC or Flex") add_definitions(-DTARGET_DEVICE=1) else() message(ERROR "Please set a valid device by adding -DTARGET_DEVICE=, where is either \"PVC\" or \"ARC\"") endif() -message(WARNING "cmake build system is still WIP.") - -# Check if either BUILD_PYBIND or BUILD_TORCH_TEST is ON -if(BUILD_PYBIND OR BUILD_TORCH_TEST OR BUILD_TORCH_BENCHMARK) - # Check if libtorch directory exists - if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/libtorch") - # Notify that we are downloading the necessary libtorch files - message(STATUS "libtorch not found in ${PROJECT_SOURCE_DIR}/extern/. Downloading...") - - # Determine the appropriate filenames based on the IPEX_VERSION - if(IPEX_VERSION VERSION_EQUAL "2.1.30") - set(LIBTORCH_FILENAME "libtorch-cxx11-abi-shared-with-deps-2.1.0.post2.zip") - set(LIBINTEL_EXT_FILENAME "libintel-ext-pt-cxx11-abi-2.1.30.post0.run") - elseif(IPEX_VERSION VERSION_EQUAL "2.1.20") - set(LIBTORCH_FILENAME "libtorch-cxx11-abi-shared-with-deps-2.1.0.post0.zip") - set(LIBINTEL_EXT_FILENAME "libintel-ext-pt-cxx11-abi-2.1.20+xpu.run") - elseif(IPEX_VERSION VERSION_EQUAL "2.1.10") - set(LIBTORCH_FILENAME "libtorch-cxx11-abi-shared-with-deps-2.1.0a0.zip") - set(LIBINTEL_EXT_FILENAME "libintel-ext-pt-cxx11-abi-2.1.10+xpu.run") - else() - message(FATAL_ERROR "Unsupported IPEX_VERSION: ${IPEX_VERSION}") - endif() - - # Set the URLs for the files to be downloaded using the determined filenames - set(LIBTORCH_URL "https://intel-extension-for-pytorch.s3.amazonaws.com/libipex/xpu/${LIBTORCH_FILENAME}") - set(LIBINTEL_EXT_URL "https://intel-extension-for-pytorch.s3.amazonaws.com/libipex/xpu/${LIBINTEL_EXT_FILENAME}") - - # Download libtorch - file(DOWNLOAD "${LIBTORCH_URL}" "${CMAKE_CURRENT_BINARY_DIR}/${LIBTORCH_FILENAME}" - STATUS download_status_libtorch) - list(GET download_status_libtorch 0 download_result_libtorch) - if(NOT download_result_libtorch EQUAL 0) - message(FATAL_ERROR "Failed to download libtorch. Please download it manually with:\nwget ${LIBTORCH_URL}\nand follow install instructions for cppsdk: https://intel.github.io/intel-extension-for-pytorch/index.html#installation?platform=gpu&version=v2.1.10%2Bxpu") - endif() - - # Download libintel extension - file(DOWNLOAD "${LIBINTEL_EXT_URL}" "${CMAKE_CURRENT_BINARY_DIR}/${LIBINTEL_EXT_FILENAME}" - STATUS download_status_libintel_ext) - list(GET download_status_libintel_ext 0 download_result_libintel_ext) - if(NOT download_result_libintel_ext EQUAL 0) - message(FATAL_ERROR "Failed to download libintel extension. Please download it manually with:\nwget ${LIBINTEL_EXT_URL}\nand follow install instructions for cppsdk: https://intel.github.io/intel-extension-for-pytorch/index.html#installation?platform=gpu&version=v2.1.10%2Bxpu") - endif() - - # Unzip the downloaded libtorch file - execute_process( - COMMAND ${CMAKE_COMMAND} -E tar xvf "${CMAKE_CURRENT_BINARY_DIR}/${LIBTORCH_FILENAME}" - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/extern/" - ) - - # Execute the installer for the libintel extension - execute_process( - COMMAND bash "${CMAKE_CURRENT_BINARY_DIR}/${LIBINTEL_EXT_FILENAME}" install "${PROJECT_SOURCE_DIR}/extern/libtorch/" - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/extern/" - ) - - # After unpacking and installation, clean up the downloaded files if needed. - file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/${LIBTORCH_FILENAME}") - file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/${LIBINTEL_EXT_FILENAME}") - else() - message(STATUS "libtorch already exists in ${PROJECT_SOURCE_DIR}/extern/.") - endif() - -endif() add_subdirectory(source) diff --git a/README.md b/README.md index 0afdb3f..ab39eee 100644 --- a/README.md +++ b/README.md @@ -108,13 +108,16 @@ conda create -n tiny-dpcpp-nn python=3.10 -y conda activate tiny-dpcpp-nn ``` -Install the latest [ipex](https://intel.github.io/intel-extension-for-pytorch/index.html#installation) via +[Install PyTorch (at the point of writing 2.7)](https://pytorch.org/docs/stable/notes/get_start_xpu.html): -```bash -python -m pip install torch==2.1.0.post2 torchvision==0.16.0.post2 torchaudio==2.1.0.post2 intel-extension-for-pytorch==2.1.30+xpu oneccl_bind_pt==2.1.300+xpu --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/ ``` +pip install -r requirements.txt +``` + +Verify that drivers and PyTorch are installed correctly: -*Note* please ensure that the IPEX version (2.1.30 in this example) is the same as used in `IPEX_VERSION` in `tiny-dpcpp-nn/CMakeLists.txt` +``` +python -c "import torch; print(torch.xpu.is_available())" Install the module (if no `TARGET_DEVICE` is set, the target_device in setup.py is set to `ARC`. Currently `PVC` and `ARC` is supported): ```bash @@ -122,10 +125,6 @@ cd dpcpp_bindings TARGET_DEVICE=ARC pip install -e . ``` -Finally, to test the sample scripts and tests, install the requirements: -```bash -cd python && pip install -r requirements.txt -``` ### Test the install To test that the installation was successful, you can do the following four tests. @@ -152,7 +151,7 @@ To have all tests, run: cmake -DTARGET_DEVICE="PVC" -DBUILD_TORCH_TEST="ON" .. ``` -After all tests are build into `build/`, you can run `cd build/ && make tests` to verfiy that the setup is correct. Please note that we provide tests for both the core `dpcpp` implementation and the `libtorch` wrapper implementation. +After all tests are build into `build/`, you cvan run `cd build/ && make tests` to verfiy that the setup is correct. Please note that we provide tests for both the core `dpcpp` implementation and the `libtorch` wrapper implementation. To test whether the pytorch bindings were installed correctly, please run diff --git a/dpcpp_bindings/CMakeLists.txt b/dpcpp_bindings/CMakeLists.txt index 7e2324a..65379c4 100644 --- a/dpcpp_bindings/CMakeLists.txt +++ b/dpcpp_bindings/CMakeLists.txt @@ -4,15 +4,11 @@ # Include headers find_package(IntelSYCL REQUIRED) -find_package(Torch REQUIRED PATHS ${TORCH_CMAKE_PREFIX_PATH}) +set(CMAKE_PREFIX_PATH "${TORCH_CMAKE_PREFIX_PATH}" CACHE PATH "Path to Torch") +find_package(Torch REQUIRED) # Add include directories -set(LIBTORCH_DIR "${PROJECT_SOURCE_DIR}/extern/libtorch/share/cmake/") -list(APPEND CMAKE_PREFIX_PATH "${LIBTORCH_DIR}") - -find_package(IPEX REQUIRED) - -include_directories(${TORCH_INCLUDE_DIRS}) +# include_directories(${TORCH_INCLUDE_DIRS}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include) # Set source files for the Python bindings set(PYBIND_SOURCES @@ -24,7 +20,7 @@ pybind11_add_module(tiny_dpcpp_nn_pybind_module ${PYBIND_SOURCES}) find_library(TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_CMAKE_PREFIX_PATH}/../../lib" REQUIRED) # Link any required libraries -target_link_libraries(tiny_dpcpp_nn_pybind_module PRIVATE network ${TORCH_LIBRARIES} ${TORCH_PYTHON_LIBRARY} ${TORCH_IPEX_LIBRARIES}) +target_link_libraries(tiny_dpcpp_nn_pybind_module PRIVATE network ${TORCH_LIBRARIES} ${TORCH_PYTHON_LIBRARY}) target_include_directories(tiny_dpcpp_nn_pybind_module PRIVATE "${PROJECT_SOURCE_DIR}/extern/json" "${PROJECT_SOURCE_DIR}/extern/pybind11_json") add_sycl_to_target(TARGET tiny_dpcpp_nn_pybind_module SOURCES ${PYBIND_SOURCES}) diff --git a/dpcpp_bindings/pyproject.toml b/dpcpp_bindings/pyproject.toml index 0ecf3aa..e909578 100644 --- a/dpcpp_bindings/pyproject.toml +++ b/dpcpp_bindings/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools>=62.6.0", "wheel"] -build-backend = "setuptools.build_meta" \ No newline at end of file +requires = ["setuptools>=62.6.0", "wheel", "torch", "ninja"] +build-backend = "setuptools.build_meta" diff --git a/dpcpp_bindings/requirements.txt b/dpcpp_bindings/requirements.txt index 22bd2f9..61c3fc2 100644 --- a/dpcpp_bindings/requirements.txt +++ b/dpcpp_bindings/requirements.txt @@ -1,7 +1,8 @@ --index-url https://download.pytorch.org/whl/xpu --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/ -torch==2.7.0 -torchvision==0.22.0 -torchaudio==2.7.0 -intel-extension-for-pytorch==2.7.10+xpu -oneccl_bind_pt==2.7.0+xpu \ No newline at end of file +torch==2.7.0 +torchvision==0.22.0 +torchaudio==2.7.0 +ninja==1.11.1.1 +# intel-extension-for-pytorch==2.7.10+xpu +# oneccl_bind_pt==2.7.0+xpu \ No newline at end of file diff --git a/dpcpp_bindings/setup.py b/dpcpp_bindings/setup.py index b375ca3..0b7b444 100644 --- a/dpcpp_bindings/setup.py +++ b/dpcpp_bindings/setup.py @@ -1,105 +1,124 @@ import os -from setuptools import setup +import re +import subprocess +import sys +from pathlib import Path +import torch -from intel_extension_for_pytorch.xpu.cpp_extension import ( - DPCPPExtension, - DpcppBuildExtension, - IS_LINUX, -) +from setuptools import Extension, setup +from setuptools.command.build_ext import build_ext -# Here ze_loader is not necessary, just used to check libraries linker -# libraries = ["ze_loader"] if IS_LINUX else [] -libraries = [] +# Convert distutils Windows platform specifiers to CMake -A arguments +PLAT_TO_CMAKE = { + "win32": "Win32", + "win-amd64": "x64", + "win-arm32": "ARM", + "win-arm64": "ARM64", +} -dpcpp_path = os.getenv("CMPLR_ROOT") -dpcpp_sycl_path = os.path.join(dpcpp_path, "include", "sycl") -conda_path = os.getenv("CONDA_PREFIX") -conda_sycl_path = None -if conda_path is not None: - conda_sycl_path = os.path.join(conda_path, "include", "sycl") - if not os.path.exists(conda_sycl_path): - conda_sycl_path = None +# A CMakeExtension needs a sourcedir instead of a file list. +# The name must be the _single_ output extension from the CMake build. +# If you need multiple extensions, see scikit-build. +class CMakeExtension(Extension): + def __init__(self, name: str, sourcedir: str = "") -> None: + super().__init__(name, sources=[]) + self.sourcedir = os.fspath(Path(sourcedir).resolve()) -target_device_map = { - "PVC": "0", - "ARC": "1", -} -target_device = target_device_map.get(os.getenv("TARGET_DEVICE", "ARC")) -if target_device is None: - raise ValueError(f"TARGET_DEVICE must be one of {sorted(target_device_map.keys())}") -if os.getenv("TARGET_DEVICE") is None: - print("Info: TARGET_DEVICE is not set, defaulting to ARC") -else: - print(f"Info: TARGET_DEVICE is set to {os.getenv('TARGET_DEVICE')}") +class CMakeBuild(build_ext): + def build_extension(self, ext: CMakeExtension) -> None: + # Must be in this form due to bug in .resolve() only fixed in Python 3.10+ + ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name) + extdir = ext_fullpath.parent.resolve() + + # Using this requires trailing slash for auto-detection & inclusion of + # auxiliary "native" libs + + debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug + cfg = "Debug" if debug else "Release" + + # CMake lets you override the generator - we need to check this. + # Can be set with Conda-Build, for example. + cmake_generator = os.environ.get("CMAKE_GENERATOR", "") + + # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON + # EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code + # from Python. + target_device = os.environ.get("TARGET_DEVICE", "PVC") + + # Validate TARGET_DEVICE + if target_device not in {"ARC", "PVC"}: + raise ValueError( + "TARGET_DEVICE environment variable must be either 'ARC', 'PVC'." + ) + + cmake_args = [ + f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}", + f"-DPYTHON_EXECUTABLE={sys.executable}", + f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm + f"-DTORCH_CMAKE_PREFIX_PATH={torch.utils.cmake_prefix_path}", + "-DCMAKE_CXX_FLAGS=-fPIC", + f"-DTARGET_DEVICE={target_device}", + "-D BUILD_TEST=OFF", + "-D BUILD_BENCHMARK=OFF", + "-D BUILD_PYBIND=ON", + ] + build_args = [] + # Adding CMake arguments set as environment variable + # (needed e.g. to build for ARM OSx on conda-forge) + if "CMAKE_ARGS" in os.environ: + cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item] + + # In this example, we pass in the version to C++. You might not need to. + cmake_args += [f"-DEXAMPLE_VERSION_INFO={self.distribution.get_version()}"] + + # Using ninja + if not cmake_generator or cmake_generator == "Ninja": + import ninja + ninja_executable_path = Path(ninja.BIN_DIR) / "ninja" + cmake_args += [ + "-GNinja", + f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}", + ] + + # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level + # across all generators. + if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ: + # self.parallel is a Python 3 only way to set parallel jobs by hand + # using -j in the build_ext call, not supported by pip or PyPA-build. + if hasattr(self, "parallel") and self.parallel: + # CMake 3.12+ only. + build_args += [f"-j{self.parallel}"] + + build_temp = Path(self.build_temp) / ext.name + if not build_temp.exists(): + build_temp.mkdir(parents=True) + + subprocess.run( + ["cmake", ext.sourcedir, *cmake_args], + cwd=build_temp, + check=True, + capture_output=False, + ) + + subprocess.run( + ["cmake", "--build", ".", *build_args], + cwd=build_temp, + check=True, + capture_output=False, + ) + + +# The information here can also be placed in setup.cfg - better separation of +# logic and declaration, and simpler if you include description/version in a file. setup( - name="tiny_dpcpp_nn", + name="tiny_dpcpp_nn_pybind_module", version="0.0.1", - description="Python bindings for the tiny-dpcpp-nn library", - packages=["tiny_dpcpp_nn"], - ext_modules=[ - DPCPPExtension( - "tiny_dpcpp_nn.tiny_dpcpp_nn_pybind_module", - [ - "tiny_dpcpp_nn/pybind_module.cpp", - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1664none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLP.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1664sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1616none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1632sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf16128none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp16128relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp16128none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf1664.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1632relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimd.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1616none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp1664.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1616relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp16128sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp1632.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf16128relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1664relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf1632.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp16128.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPfp1616.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1664relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1664sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1632sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf1616.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1664none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1616relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1616sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1616sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1632none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "SwiftNetMLPbf16128.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdfp1632relu.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf1632none.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "network", "kernel_esimdbf16128sigmoid.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "optimizers", "sgd.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "optimizers", "adam.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "common", "SyclGraph.cpp"), - os.path.join(os.path.dirname(__file__), "..", "source", "common", "common.cpp"), - ], - libraries=libraries, - extra_compile_args={'cxx': [f'-DTARGET_DEVICE={target_device}', '-std=c++20', '-fPIC']}, - include_dirs=( - ([dpcpp_sycl_path] - if conda_sycl_path is None - else [conda_sycl_path]) - + [ - os.path.join(os.path.dirname(__file__), "../include"), - os.path.join(os.path.dirname(__file__), "../include/network"), - os.path.join(os.path.dirname(__file__), "../include/common"), - os.path.join(os.path.dirname(__file__), "../include/encodings"), - os.path.join(os.path.dirname(__file__), "../include/optimizers"), - os.path.join(os.path.dirname(__file__), "../extern/json"), - os.path.join(os.path.dirname(__file__), "../extern/pybind11_json"), - ] - ), - ) - ], - cmdclass={"build_ext": DpcppBuildExtension.with_options(use_ninja=True)}, -) \ No newline at end of file + description="A test project using pybind11 and CMake", + long_description="", + ext_modules=[CMakeExtension("tiny_dpcpp_nn_pybind_module", "../")], + cmdclass={"build_ext": CMakeBuild}, + python_requires=">=3.7", +)