TODO: pytorch xpu attempt

This commit is contained in:
TheK0tYaRa 2026-04-16 17:31:09 +03:00
parent 6628aed3e0
commit c2111878df
25 changed files with 1589 additions and 0 deletions

View file

@ -0,0 +1,420 @@
# Copyright 2022-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
PYTHON_COMPAT=( python3_{11..14} )
ROCM_VERSION=6.1
inherit python-single-r1 cmake cuda flag-o-matic prefix rocm toolchain-funcs
MYPN=pytorch
MYP=${MYPN}-${PV}
# caffe2-2.9.0 depends on future version of composable kernel
# TODO: replace it with DEPEND in the future
CK_COMMIT=7fe50dc3da2069d6645d9deb8c017a876472a977
CK_P=composable_kernel-${CK_COMMIT:0:8}
FLASH_PV=2.7.4
FLASH_PN=flash-attention
FLASH_P=${FLASH_PN}-${FLASH_PV}
FLASH_ATT_URI="https://github.com/Dao-AILab/${FLASH_PN}/archive/refs/tags/v${FLASH_PV}.tar.gz -> ${FLASH_P}.gh.tar.gz"
AOTRITON_PV=0.9.2b
AOTRITON_PN=aotriton
AOTRITON_P=${AOTRITON_PN}-${AOTRITON_PV}
AOTRITON_tar=${AOTRITON_P}-manylinux_2_28_x86_64-rocm6.3-shared.tar.gz
DESCRIPTION="A deep learning framework"
HOMEPAGE="https://pytorch.org/"
SRC_URI="
https://github.com/pytorch/${MYPN}/archive/refs/tags/v${PV}.tar.gz -> ${MYP}.tar.gz
rocm? (
https://github.com/ROCm/composable_kernel/archive/${CK_COMMIT}.tar.gz
-> ${CK_P}.tar.gz
)
cuda? (
flash? ( ${FLASH_ATT_URI} )
memefficient? ( ${FLASH_ATT_URI} )
)
"
S="${WORKDIR}"/${MYP}
LICENSE="BSD"
SLOT="0"
KEYWORDS="~amd64 ~arm64"
IUSE="cuda cusparselt distributed fbgemm flash gloo kineto memefficient
mimalloc mkl mpi nccl nnpack +numpy onednn openblas opencl openmp qnnpack
rocm xnnpack"
RESTRICT="test"
REQUIRED_USE="
${PYTHON_REQUIRED_USE}
mpi? ( distributed )
gloo? ( distributed )
?? ( cuda rocm )
rocm? (
|| ( ${ROCM_REQUIRED_USE} )
memefficient? ( flash )
)
cusparselt? ( || ( cuda rocm ) )
flash? ( || ( cuda rocm ) )
memefficient? ( || ( cuda rocm ) )
nccl? ( rocm )
"
RDEPEND="
${PYTHON_DEPS}
dev-cpp/abseil-cpp:=
dev-cpp/gflags:=
>=dev-cpp/glog-0.5.0:=
>=dev-libs/cpuinfo-2025.11.14
dev-libs/libfmt:=
dev-libs/protobuf:=
dev-libs/sleef
sci-ml/onnx
virtual/lapack
cuda? (
dev-libs/cudnn
>=sci-ml/cudnn-frontend-1.12.0:=
>=dev-util/nvidia-cuda-toolkit-12.9:=[profiler]
cusparselt? ( dev-libs/cusparselt )
)
fbgemm? ( >=sci-ml/FBGEMM-1.4 )
gloo? ( >=sci-ml/gloo-2025.06.04[cuda?,rocm?] )
kineto? ( ~sci-ml/kineto-0.4.0_p20260323 )
mimalloc? ( dev-libs/mimalloc )
mpi? ( virtual/mpi )
nnpack? (
sci-ml/NNPACK
dev-libs/pthreadpool
)
numpy? ( $(python_gen_cond_dep '
dev-python/numpy[${PYTHON_USEDEP}]
') )
onednn? ( sci-ml/oneDNN )
opencl? ( virtual/opencl )
qnnpack? (
!sci-libs/QNNPACK
sci-ml/gemmlowp
dev-libs/pthreadpool
)
rocm? (
nccl? ( >=dev-libs/rccl-6.3:= <dev-libs/rccl-7.3:= )
>=dev-util/hip-6.3:= <dev-util/hip-7.3:=
>=dev-util/roctracer-6.3:= <dev-util/roctracer-7.3:=
>=sci-libs/hipBLAS-6.3:= <sci-libs/hipBLAS-7.3:=[rocsolver(+)]
>=sci-libs/hipBLASLt-6.3:= <sci-libs/hipBLASLt-7.3:=
>=sci-libs/hipFFT-6.3:= <sci-libs/hipFFT-7.3:=
>=sci-libs/hipRAND-6.3:= <sci-libs/hipRAND-7.3:=
>=sci-libs/hipSOLVER-6.3:= <sci-libs/hipSOLVER-7.3:=
>=sci-libs/hipSPARSE-6.3:= <sci-libs/hipSPARSE-7.3:=
>=sci-libs/miopen-6.3:= <sci-libs/miopen-7.3:=
>=sci-libs/rocBLAS-6.3:= <sci-libs/rocBLAS-7.3:=
>=sci-libs/rocRAND-6.3:= <sci-libs/rocRAND-7.3:=
>=sci-libs/rocSOLVER-6.3:= <sci-libs/rocSOLVER-7.3:=
memefficient? ( =sci-libs/aotriton-bin-0.11*:= )
distributed? ( >=dev-util/rocm-smi-6.3:= <dev-util/rocm-smi-7.3:= )
cusparselt? ( >=sci-libs/hipsparselt-6.3:= <sci-libs/hipsparselt-7.3:= )
)
distributed? (
!rocm? ( sci-ml/tensorpipe[cuda?] )
dev-cpp/cpp-httplib:=
)
xnnpack? (
>=sci-ml/XNNPACK-2024.11
dev-libs/pthreadpool
)
mkl? ( sci-libs/mkl )
openblas? ( sci-libs/openblas )
"
DEPEND="
${RDEPEND}
dev-cpp/nlohmann_json
dev-libs/flatbuffers
dev-libs/FXdiv
dev-libs/pocketfft
dev-libs/psimd
sci-ml/FP16
$(python_gen_cond_dep '
<dev-python/pybind11-3.0.2[${PYTHON_USEDEP}]
dev-python/pyyaml[${PYTHON_USEDEP}]
dev-python/typing-extensions[${PYTHON_USEDEP}]
')
cuda? ( >=dev-libs/cutlass-3.9.2[tools(+)] )
onednn? ( sci-ml/ideep )
rocm? (
>=sci-libs/hipCUB-6.3:= <sci-libs/hipCUB-7.3:=
>=sci-libs/rocPRIM-6.3:= <sci-libs/rocPRIM-7.3:=
>=sci-libs/rocThrust-6.3:= <sci-libs/rocThrust-7.3:=
)
qnnpack? ( dev-libs/clog )
"
PATCHES=(
"${FILESDIR}"/${PN}-2.5.1-unbundle_fmt.patch
"${FILESDIR}"/${PN}-2.5.1-unbundle_kineto.patch
"${FILESDIR}"/${PN}-2.8.0-unbundle_pocketfft.patch
"${FILESDIR}"/${PN}-2.5.1-cudnn_include_fix.patch
"${FILESDIR}"/${PN}-2.4.0-cpp-httplib.patch
"${FILESDIR}"/${PN}-2.5.1-glog-0.6.0.patch
"${FILESDIR}"/${P}-rocm-fix-std-cpp17.patch
"${FILESDIR}"/${PN}-2.7.0-glog-0.7.1.patch
"${FILESDIR}"/${PN}-2.7.1-aotriton-fixes.patch
"${FILESDIR}"/${PN}-2.8.0-rocm-minus-flash.patch
"${FILESDIR}"/${PN}-2.9.0-cmake.patch
"${FILESDIR}"/${PN}-2.9.0-rocm-distributed-link.patch
"${FILESDIR}"/${PN}-2.9.1-torch_cpu.patch
"${FILESDIR}"/${PN}-2.10.0-gentoo.patch
"${FILESDIR}"/${P}-mimalloc.patch
"${FILESDIR}"/${P}-removekineto-pr178960.patch
)
src_prepare() {
if use cuda && ( use flash || use memefficient ); then
mv "${WORKDIR}"/${FLASH_P}/* third_party/${FLASH_PN}/ || die
fi
filter-lto #bug 862672
# Unbundle fmt
sed -i \
-e 's|::fmt-header-only||' \
c10/CMakeLists.txt \
cmake/Dependencies.cmake \
torch/CMakeLists.txt \
|| die
# tensorpipe is in system, not a build target of caffe2
sed -e '/target_compile_options_if_supported(tensorpipe/d' -i cmake/Dependencies.cmake || die
# Drop third_party from CMake tree
sed -i \
-e '/add_subdirectory.*third_party/d' \
CMakeLists.txt \
cmake/Dependencies.cmake \
cmake/ProtoBuf.cmake \
aten/src/ATen/CMakeLists.txt \
|| die
# Change libc10* path
sed -i \
-e "/EXPORT/s|DESTINATION lib)|DESTINATION $(get_libdir))|" \
c10/cuda/CMakeLists.txt \
c10/CMakeLists.txt \
c10/hip/CMakeLists.txt \
|| die
# Change libaotriton path
sed -i \
-e "s|}/lib|}/\${CMAKE_INSTALL_LIBDIR}|g" \
-e "/set(__AOTRITON_LIB/s|lib/|\${CMAKE_INSTALL_LIBDIR}/|g" \
cmake/External/aotriton.cmake \
|| die
# Noisy warnings from Logging.h
sed -i 's/-Wextra-semi//' cmake/public/utils.cmake || die
cmake_src_prepare
pushd torch/csrc/jit/serialization > /dev/null || die
flatc --cpp --gen-mutable --scoped-enums mobile_bytecode.fbs || die
popd > /dev/null || die
# prefixify the hardcoded paths, after all patches are applied
hprefixify \
aten/CMakeLists.txt \
caffe2/CMakeLists.txt \
cmake/Metal.cmake \
cmake/Modules/*.cmake \
cmake/Modules_CUDA_fix/FindCUDNN.cmake \
cmake/Modules_CUDA_fix/upstream/FindCUDA/make2cmake.cmake \
cmake/Modules_CUDA_fix/upstream/FindPackageHandleStandardArgs.cmake \
cmake/public/LoadHIP.cmake \
cmake/public/cuda.cmake \
cmake/Dependencies.cmake \
torch/CMakeLists.txt \
CMakeLists.txt
if use rocm; then
sed -e "s:/opt/rocm:/usr:" \
-e "s:lib/cmake:$(get_libdir)/cmake:g" \
-i cmake/public/LoadHIP.cmake || die
# TODO: delete, when caffe2 depends on systemwide composable_kernel
sed -e "s:third_party/composable_kernel:../composable_kernel-${CK_COMMIT}:g" \
-i aten/src/ATen/CMakeLists.txt || die
# Bug 959808: fix for gfx101x targets
pushd "${WORKDIR}/composable_kernel-${CK_COMMIT}" > /dev/null || die
eapply "${FILESDIR}"/composable-kernel-7fe50dc-expand-isa.patch
popd > /dev/null || die
if tc-is-clang; then
# Systemwide gcc (for absl and at::TensorBase) + hipcc (llvm>=18) need abi-compat=17.
# But systemwide clang>=18 + hipcc (>=llvm-18) need opposite!
# See also: https://github.com/llvm/llvm-project/issues/102443#issuecomment-2329726287
sed -e '/-fclang-abi-compat=17/d' -i cmake/Dependencies.cmake || die
fi
# Workaround for libc++ issue https://github.com/llvm/llvm-project/issues/100802
sed -e 's/std::memcpy/memcpy/g' -i torch/headeronly/util/Half.h || die
ebegin "HIPifying cuda sources"
FBCODE_BUILD_TOOL="buck" ${EPYTHON} tools/amd_build/build_amd.py || die
eend $?
fi
}
src_configure() {
if use cuda && [[ -z ${TORCH_CUDA_ARCH_LIST} ]]; then
ewarn "WARNING: caffe2 is being built with its default CUDA compute capabilities: 3.5 and 7.0."
ewarn "These may not be optimal for your GPU."
ewarn ""
ewarn "To configure caffe2 with the CUDA compute capability that is optimal for your GPU,"
ewarn "set TORCH_CUDA_ARCH_LIST in your make.conf, and re-emerge caffe2."
ewarn "For example, to use CUDA capability 7.5 & 3.5, add: TORCH_CUDA_ARCH_LIST=7.5 3.5"
ewarn "For a Maxwell model GPU, an example value would be: TORCH_CUDA_ARCH_LIST=Maxwell"
ewarn ""
ewarn "You can look up your GPU's CUDA compute capability at https://developer.nvidia.com/cuda-gpus"
ewarn "or by running /opt/cuda/extras/demo_suite/deviceQuery | grep 'CUDA Capability'"
fi
local mycmakeargs=(
-DBUILD_CUSTOM_PROTOBUF=OFF
-DBUILD_TEST=OFF
-DLIBSHM_INSTALL_LIB_SUBDIR="${EPREFIX}"/usr/$(get_libdir)
-DPython_EXECUTABLE="${PYTHON}"
-DTORCH_INSTALL_LIB_DIR="${EPREFIX}"/usr/$(get_libdir)
-DUSE_CCACHE=OFF
-DUSE_CUDA=$(usex cuda)
-DUSE_DISTRIBUTED=$(usex distributed)
-DUSE_FBGEMM=$(usex fbgemm)
-DUSE_FLASH_ATTENTION=$(usex flash)
-DUSE_GFLAGS=ON
-DUSE_GLOG=ON
-DUSE_GLOO=$(usex gloo)
-DUSE_ITT=OFF
-DUSE_KINETO=$(usex kineto)
-DUSE_KLEIDIAI=OFF # TODO
-DUSE_MAGMA=OFF # TODO: In GURU as sci-libs/magma
-DUSE_MEM_EFF_ATTENTION=$(usex memefficient)
-DUSE_MIMALLOC=$(usex mimalloc)
-DUSE_MKLDNN=$(usex onednn)
-DUSE_MPI=$(usex mpi)
-DUSE_NCCL=OFF
-DUSE_NNPACK=$(usex nnpack)
-DUSE_NUMA=OFF
-DUSE_NUMPY=$(usex numpy)
-DUSE_OPENCL=$(usex opencl)
-DUSE_OPENMP=$(usex openmp)
-DUSE_PYTORCH_QNNPACK=$(usex qnnpack)
-DUSE_PYTORCH_METAL=OFF
-DUSE_ROCM=$(usex rocm)
-DUSE_SYSTEM_CPUINFO=ON
-DUSE_SYSTEM_EIGEN_INSTALL=ON
-DUSE_SYSTEM_FP16=ON
-DUSE_SYSTEM_FXDIV=ON
-DUSE_SYSTEM_GLOO=ON
-DUSE_SYSTEM_NVTX=ON
-DUSE_SYSTEM_ONNX=ON
-DUSE_SYSTEM_PSIMD=ON
-DUSE_SYSTEM_PTHREADPOOL=ON
-DUSE_SYSTEM_PYBIND11=ON
-DUSE_SYSTEM_SLEEF=ON
-DUSE_SYSTEM_XNNPACK=$(usex xnnpack)
-DUSE_TENSORPIPE=$(usex distributed $(usex !rocm))
-DUSE_UCC=OFF
-DUSE_VALGRIND=OFF
-DUSE_XNNPACK=$(usex xnnpack)
-DUSE_XPU=OFF
-Wno-dev
)
if use mkl; then
mycmakeargs+=(-DBLAS=MKL)
elif use openblas; then
mycmakeargs+=(-DBLAS=OpenBLAS)
else
mycmakeargs+=(-DBLAS=Generic -DBLAS_LIBRARIES=)
fi
if use cuda; then
# bug 867706 926116
cuda_add_sandbox
addpredict "/dev/char/"
mycmakeargs+=(
-DUSE_CUDNN=ON
-DTORCH_CUDA_ARCH_LIST="${TORCH_CUDA_ARCH_LIST:-3.5 7.0}"
-DUSE_NCCL=OFF # TODO: NVIDIA Collective Communication Library
-DCMAKE_CUDA_FLAGS="$(cuda_gccdir -f | tr -d \")"
-DUSE_CUSPARSELT=$(usex cusparselt)
)
[[ -v CUDACXX ]] && export PYTORCH_NVCC="${CUDACXX}"
if use flash; then
export FLASH_ATTENTION_FORCE_BUILD="TRUE"
export FLASH_ATTN_CUDA_ARCHS="${CUDAARCHS:-${TORCH_CUDA_ARCH_LIST:-3.5 7.0}}"
fi
elif use rocm; then
export PYTORCH_ROCM_ARCH="$(get_amdgpu_flags)"
if use memefficient; then
export AOTRITON_INSTALLED_PREFIX="${ESYSROOT}/usr"
fi
mycmakeargs+=(
-DUSE_NCCL=$(usex nccl)
-DUSE_SYSTEM_NCCL=ON
-DCMAKE_REQUIRE_FIND_PACKAGE_HIP=ON
-DCMAKE_DISABLE_FIND_PACKAGE_hipsparselt=$(usex !cusparselt) # disable automagic
-DUSE_ROCM_CK_SDPA=OFF # requires flash + aiter, works only on gfx90a/gfx942/gfx950
)
# ROCm libraries produce too much warnings
append-cxxflags -Wno-deprecated-declarations -Wno-unused-result -Wno-unused-value
fi
if use onednn; then
mycmakeargs+=(
-DMKLDNN_FOUND=ON
-DMKLDNN_LIBRARIES=dnnl
-DMKLDNN_INCLUDE_DIR="${ESYSROOT}/usr/include/oneapi/dnnl"
)
fi
cmake_src_configure
}
src_compile() {
PYTORCH_BUILD_VERSION=${PV} \
PYTORCH_BUILD_NUMBER=0 \
cmake_src_compile
}
python_install() {
python_domodule python/torch
mkdir "${D}"$(python_get_sitedir)/torch/bin || die
mkdir "${D}"$(python_get_sitedir)/torch/lib || die
mkdir "${D}"$(python_get_sitedir)/torch/include || die
ln -s ../../../../../include/torch \
"${D}$(python_get_sitedir)"/torch/include/torch || die # bug 923269
ln -s ../../../../../bin/torch_shm_manager \
"${D}"/$(python_get_sitedir)/torch/bin/torch_shm_manager || die
ln -s ../../../../../$(get_libdir)/libtorch_global_deps.so \
"${D}"/$(python_get_sitedir)/torch/lib/libtorch_global_deps.so || die
}
src_install() {
cmake_src_install
# Used by pytorch ebuild
insinto "/var/lib/${PN}"
doins "${BUILD_DIR}"/CMakeCache.txt
rm -rf python
mkdir -p python/torch || die
cp torch/version.py python/torch/ || die
python_install
}

View file

@ -0,0 +1,220 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1084,7 +1084,7 @@
set(CMAKE_COLOR_DIAGNOSTICS ON)
endif()
if(NOT MSVC)
- string(APPEND CMAKE_CXX_FLAGS " -O2 -fPIC")
+ string(APPEND CMAKE_CXX_FLAGS " -O2")
# This prevents use of `c10::optional`, `c10::nullopt` etc within the codebase
string(APPEND CMAKE_CXX_FLAGS " -DC10_NODEPRECATED")
@@ -1095,7 +1095,6 @@
# Details at http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1459
string(APPEND CMAKE_CXX_FLAGS " -Wall")
string(APPEND CMAKE_CXX_FLAGS " -Wextra")
- append_cxx_flag_if_supported("-Werror=return-type" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-Werror=non-virtual-dtor" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-Werror=braced-scalar-init" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-Werror=range-loop-construct" CMAKE_CXX_FLAGS)
@@ -1083,7 +1082,6 @@
endif()
append_cxx_flag_if_supported("-fno-math-errno" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-fno-trapping-math" CMAKE_CXX_FLAGS)
- append_cxx_flag_if_supported("-Werror=format" CMAKE_CXX_FLAGS)
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13)
append_cxx_flag_if_supported("-Wno-dangling-reference" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-Wno-error=dangling-reference" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-Wno-error=redundant-move" CMAKE_CXX_FLAGS)
--- a/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt
+++ b/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt
@@ -323,7 +323,7 @@
set_target_properties(pytorch_qnnpack PROPERTIES PUBLIC_HEADER include/qnnpack_func.h)
# ---[ Configure clog
-if(NOT TARGET clog)
+if(FALSE)
set(CLOG_BUILD_TESTS OFF CACHE BOOL "")
set(CLOG_RUNTIME_TYPE "${CPUINFO_RUNTIME_TYPE}" CACHE STRING "")
add_subdirectory(
@@ -335,7 +335,8 @@
target_compile_options(clog PRIVATE "-Wno-unused-result")
endif()
endif()
-target_link_libraries(pytorch_qnnpack PUBLIC clog)
+find_library(CLOG_LIBRARY NAMES clog REQUIRED)
+target_link_libraries(pytorch_qnnpack PUBLIC ${CLOG_LIBRARY})
# ---[ Configure cpuinfo
if(NOT TARGET cpuinfo AND USE_SYSTEM_CPUINFO)
--- a/caffe2/CMakeLists.txt
+++ b/caffe2/CMakeLists.txt
@@ -87,7 +87,7 @@ endif()
# Note: the folders that are being commented out have not been properly
# addressed yet.
-if(NOT MSVC AND USE_XNNPACK)
+if(FALSE)
if(NOT TARGET fxdiv)
set(FXDIV_BUILD_TESTS OFF CACHE BOOL "")
set(FXDIV_BUILD_BENCHMARKS OFF CACHE BOOL "")
@@ -1212,7 +1212,6 @@ if(USE_XPU)
endif()
if(NOT MSVC AND USE_XNNPACK)
- TARGET_LINK_LIBRARIES(torch_cpu PRIVATE fxdiv)
endif()
# ==========================================================
@@ -1324,17 +1323,6 @@
target_include_directories(torch_cpu PRIVATE
"/usr/include/kineto")
-if(USE_KINETO)
- target_include_directories(torch_cpu PRIVATE
- ${TORCH_ROOT}/third_party/kineto/libkineto/src)
-endif()
-
-target_include_directories(torch_cpu PRIVATE
- ${TORCH_ROOT}/third_party/cpp-httplib)
-
-target_include_directories(torch_cpu PRIVATE
- ${TORCH_ROOT}/third_party/nlohmann/include)
-
install(DIRECTORY
"${TORCH_SRC_DIR}/csrc"
"${TORCH_SRC_DIR}/headeronly"
--- a/cmake/Codegen.cmake
+++ b/cmake/Codegen.cmake
@@ -64,7 +64,7 @@ if(INTERN_BUILD_ATEN_OPS)
if(MSVC)
set(OPT_FLAG "/fp:strict ")
else(MSVC)
- set(OPT_FLAG "-O3 ")
+ set(OPT_FLAG " ")
if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
set(OPT_FLAG " ")
endif()
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -492,7 +492,9 @@
set_property(TARGET pytorch_qnnpack PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET cpuinfo PROPERTY POSITION_INDEPENDENT_CODE ON)
# QNNPACK depends on gemmlowp headers
- target_include_directories(pytorch_qnnpack PRIVATE "${CAFFE2_THIRD_PARTY_ROOT}/gemmlowp")
+ find_package(gemmlowp REQUIRED)
+ get_target_property(GEMMLOWP_INCLUDE_DIRS gemmlowp::gemmlowp INTERFACE_INCLUDE_DIRECTORIES)
+ target_include_directories(pytorch_qnnpack PRIVATE ${GEMMLOWP_INCLUDE_DIRS})
endif()
list(APPEND Caffe2_DEPENDENCY_LIBS pytorch_qnnpack)
@@ -593,7 +591,7 @@
find_library(microkernels-prod_LIBRARY microkernels-prod)
set_property(TARGET XNNPACK PROPERTY IMPORTED_LOCATION "${XNNPACK_LIBRARY}")
set_property(TARGET microkernels-prod PROPERTY IMPORTED_LOCATION "${microkernels-prod_LIBRARY}")
- if(NOT XNNPACK_LIBRARY OR NOT microkernels-prod_LIBRARY)
+ if(FALSE)
message(FATAL_ERROR "Cannot find XNNPACK")
endif()
message("-- Found XNNPACK: ${XNNPACK_LIBRARY}")
@@ -674,7 +672,7 @@ if(BUILD_TEST OR BUILD_MOBILE_BENCHMARK OR BUILD_MOBILE_TEST)
endif()
# ---[ FBGEMM
-if(USE_FBGEMM)
+if(FALSE)
set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
if(NOT DEFINED FBGEMM_SOURCE_DIR)
set(FBGEMM_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/fbgemm" CACHE STRING "FBGEMM source directory")
@@ -698,6 +696,7 @@ if(USE_FBGEMM)
endif()
if(USE_FBGEMM)
+ list(APPEND Caffe2_DEPENDENCY_LIBS fbgemm)
caffe2_update_option(USE_FBGEMM ON)
else()
caffe2_update_option(USE_FBGEMM OFF)
@@ -1156,7 +1155,6 @@
endif()
set(TP_BUILD_LIBUV ON CACHE BOOL "" FORCE)
add_compile_options(-DTORCH_USE_LIBUV)
- include_directories(BEFORE SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../third_party/tensorpipe/third_party/libuv/include)
set(TP_STATIC_OR_SHARED STATIC CACHE STRING "" FORCE)
# Tensorpipe uses cuda_add_library
@@ -1676,11 +1676,9 @@
# Include cpp-httplib
add_library(httplib INTERFACE IMPORTED)
-target_include_directories(httplib SYSTEM INTERFACE ${PROJECT_SOURCE_DIR}/third_party/cpp-httplib)
# Include nlohmann-json
add_library(nlohmann INTERFACE IMPORTED)
-include_directories(nlohmann SYSTEM INTERFACE ${PROJECT_SOURCE_DIR}/third_party/nlohmann/include)
# Include moodycamel
add_library(moodycamel INTERFACE IMPORTED)
--- a/cmake/External/nnpack.cmake
+++ b/cmake/External/nnpack.cmake
@@ -56,7 +56,7 @@
set(PTHREADPOOL_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/pthreadpool" CACHE STRING "pthreadpool source directory")
set(GOOGLETEST_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/googletest" CACHE STRING "Google Test source directory")
- if(NOT TARGET nnpack)
+ if(FALSE)
set(NNPACK_BUILD_TESTS OFF CACHE BOOL "")
set(NNPACK_BUILD_BENCHMARKS OFF CACHE BOOL "")
set(NNPACK_LIBRARY_TYPE "static" CACHE STRING "")
--- a/aten/src/ATen/CMakeLists.txt 2025-02-27 14:23:02.402742165 +0100
+++ b/aten/src/ATen/CMakeLists.txt 2025-02-27 14:23:40.445850718 +0100
@@ -448,8 +448,6 @@
if(USE_CUDA)
list(APPEND ATen_CUDA_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/cuda)
# Next two lines are needed because TunableOp uses third-party/fmt
- list(APPEND ATen_CUDA_INCLUDE $<TARGET_PROPERTY:fmt::fmt-header-only,INTERFACE_INCLUDE_DIRECTORIES>)
- list(APPEND ATen_CUDA_DEPENDENCY_LIBS fmt::fmt-header-only)
list(APPEND ATen_CUDA_CU_SRCS
${cuda_cu}
${native_cuda_cu}
@@ -521,8 +519,6 @@
endif()
# Next two lines are needed because TunableOp uses third-party/fmt
- list(APPEND ATen_HIP_INCLUDE $<TARGET_PROPERTY:fmt::fmt-header-only,INTERFACE_INCLUDE_DIRECTORIES>)
- list(APPEND ATen_HIP_DEPENDENCY_LIBS fmt::fmt-header-only)
if(USE_FLASH_ATTENTION AND USE_ROCM_CK_SDPA)
list(APPEND ATen_HIP_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/native/transformers/hip/flash_attn/ck)
endif()
--- a/torch/CMakeLists.txt
+++ b/torch/CMakeLists.txt
@@ -59,16 +59,10 @@
${CMAKE_BINARY_DIR}/aten/src
${CMAKE_BINARY_DIR}/caffe2/aten/src
${CMAKE_BINARY_DIR}/third_party
- ${CMAKE_BINARY_DIR}/third_party/onnx
${TORCH_ROOT}/third_party/valgrind-headers
- ${TORCH_ROOT}/third_party/gloo
- ${TORCH_ROOT}/third_party/onnx
- ${TORCH_ROOT}/third_party/flatbuffers/include
"/usr/include/kineto"
- ${TORCH_ROOT}/third_party/cpp-httplib
- ${TORCH_ROOT}/third_party/nlohmann/include
${TORCH_SRC_DIR}/csrc
${TORCH_SRC_DIR}/csrc/api/include
--- a/cmake/FlatBuffers.cmake
+++ b/cmake/FlatBuffers.cmake
@@ -1,10 +1 @@
-set(FlatBuffers_Include ${PROJECT_SOURCE_DIR}/third_party/flatbuffers/include)
-file(GLOB FlatBuffers_Library_SRCS
- ${FlatBuffers_Include}/flatbuffers/*.h
-)
add_library(flatbuffers INTERFACE)
-target_sources(
- flatbuffers
- INTERFACE ${FlatBuffers_Library_SRCS}
-)
-target_include_directories(flatbuffers INTERFACE ${FlatBuffers_Include})

View file

@ -0,0 +1,24 @@
--- a/c10/CMakeLists.txt 2026-02-01 09:22:55.398151644 +0100
+++ b/c10/CMakeLists.txt 2026-02-01 09:30:46.720495230 +0100
@@ -120,8 +120,9 @@
endif()
if(USE_MIMALLOC)
- target_link_libraries(c10 PRIVATE "mimalloc-static")
- add_dependencies(c10 mimalloc-static)
+ find_package(mimalloc REQUIRED)
+ target_link_libraries(c10 PRIVATE "mimalloc")
+ add_dependencies(c10 mimalloc)
endif()
if(LINUX)
--- a/CMakeLists.txt 2026-02-03 16:47:46.949580063 +0100
+++ b/CMakeLists.txt 2026-02-03 16:48:57.348716061 +0100
@@ -404,7 +404,6 @@
# on Windows and AArch64.
option(USE_MIMALLOC_ON_MKL "Use mimalloc on MKL" OFF)
if(WIN32 OR (CPU_AARCH64 AND NOT APPLE))
- set(USE_MIMALLOC ON)
# Not enable USE_MIMALLOC_ON_MKL due to it caused issue:
# https://github.com/pytorch/pytorch/issues/138994

View file

@ -0,0 +1,24 @@
--- a/c10/CMakeLists.txt 2026-02-01 09:22:55.398151644 +0100
+++ b/c10/CMakeLists.txt 2026-02-01 09:30:46.720495230 +0100
@@ -120,8 +120,9 @@
endif()
if(USE_MIMALLOC)
- target_link_libraries(c10 PRIVATE "mimalloc-static")
- add_dependencies(c10 mimalloc-static)
+ find_package(mimalloc REQUIRED)
+ target_link_libraries(c10 PRIVATE "mimalloc")
+ add_dependencies(c10 mimalloc)
endif()
if(LINUX)
--- a/CMakeLists.txt 2026-02-03 16:47:46.949580063 +0100
+++ b/CMakeLists.txt 2026-02-03 16:48:57.348716061 +0100
@@ -404,7 +404,6 @@
# on Windows and AArch64.
option(USE_MIMALLOC_ON_MKL "Use mimalloc on MKL" OFF)
if(WIN32 OR (CPU_AARCH64 AND NOT APPLE))
- set(USE_MIMALLOC ON)
# Disable OPT flags for mimalloc on aarch64 as it breaks ARMv8.0
# Not enable USE_MIMALLOC_ON_MKL due to it caused issue:
# See https://github.com/pytorch/pytorch/issues/174344

View file

@ -0,0 +1,170 @@
diff --git a/torch/csrc/autograd/init.cpp b/torch/csrc/autograd/init.cpp
index 28c1a43..70d8f7b 100644
--- a/torch/csrc/autograd/init.cpp
+++ b/torch/csrc/autograd/init.cpp
@@ -301,12 +301,7 @@ PyObject* THPAutograd_initExtension(PyObject* _unused, PyObject* unused) {
.def("privateuse1_elapsed_us", &KinetoEvent::privateuse1ElapsedUs)
.def(
"is_user_annotation",
- [](const KinetoEvent& e) {
- return e.activityType() ==
- (uint8_t)libkineto::ActivityType::USER_ANNOTATION ||
- e.activityType() ==
- (uint8_t)libkineto::ActivityType::GPU_USER_ANNOTATION;
- })
+ [](const KinetoEvent& e) { return e.isUserAnnotation(); })
.def("nbytes", [](const KinetoEvent& e) { return e.nBytes(); })
// whether the event is hidden
.def(
diff --git a/torch/csrc/autograd/profiler_kineto.cpp b/torch/csrc/autograd/profiler_kineto.cpp
index dd4598669827e..85de1c3af923f 100644
--- a/torch/csrc/autograd/profiler_kineto.cpp
+++ b/torch/csrc/autograd/profiler_kineto.cpp
@@ -1081,6 +1081,13 @@ int64_t KinetoEvent::privateuse1ElapsedUs() const {
return -1;
}
+bool KinetoEvent::isUserAnnotation() const {
+ constexpr uint8_t kUserAnnotation = 1;
+ constexpr uint8_t kGpuUserAnnotation = 2;
+ const auto type = activityType();
+ return type == kUserAnnotation || type == kGpuUserAnnotation;
+}
+
void KinetoEvent::getPerfEventCounters(std::vector<uint64_t>& in) const {
return result_->visit(c10::overloaded(
[&in](const ExtraFields<EventType::TorchOp>& e) -> void {
diff --git a/torch/csrc/autograd/profiler_kineto.h b/torch/csrc/autograd/profiler_kineto.h
index 777b8a5851ed5..c3135c61245d4 100644
--- a/torch/csrc/autograd/profiler_kineto.h
+++ b/torch/csrc/autograd/profiler_kineto.h
@@ -67,6 +67,7 @@ struct TORCH_API KinetoEvent {
bool isPythonFunction() const;
int64_t cudaElapsedUs() const;
int64_t privateuse1ElapsedUs() const;
+ bool isUserAnnotation() const;
void getPerfEventCounters(torch::profiler::perf_counters_t& /*in*/) const;
extra_meta_t extraMeta() const;
std::string metadataJson() const;
diff --git a/torch/csrc/profiler/collection.cpp b/torch/csrc/profiler/collection.cpp
index eb29cb7382127..8ee3a9e7707a8 100644
--- a/torch/csrc/profiler/collection.cpp
+++ b/torch/csrc/profiler/collection.cpp
@@ -572,11 +572,13 @@ std::string toString(const ExtraFields<EventType::PyCall>& e) {
e.callsite_.funcname_.str());
}
+#ifdef USE_KINETO
auto scopeToType(at::RecordScope scope) {
return scope == at::RecordScope::USER_SCOPE
? libkineto::ActivityType::USER_ANNOTATION
: libkineto::ActivityType::CPU_OP;
}
+#endif
int64_t torchOpEndNS(
const ExtraFields<EventType::TorchOp>& e,
@@ -625,6 +627,7 @@ std::string Result::overload_name() const {
[](const auto& e) -> std::string { return ""; }));
}
+#ifdef USE_KINETO
libkineto::ActivityType Result::kinetoType() const {
return visit(c10::overloaded(
ATTRIBUTE(TorchOp, scopeToType(e.scope_)),
@@ -637,6 +640,11 @@ libkineto::ActivityType Result::kinetoType() const {
ATTRIBUTE(PythonGC, libkineto::ActivityType::PYTHON_FUNCTION),
ATTRIBUTE(Kineto, e.activity_type_)));
}
+#else
+libkineto::ActivityType Result::kinetoType() const {
+ return libkineto::ActivityType::NONE;
+}
+#endif
uint64_t Result::correlationID() const {
return visit(c10::overloaded(
diff --git a/torch/csrc/profiler/kineto_shim.cpp b/torch/csrc/profiler/kineto_shim.cpp
index fa232e1a01016..0ddf62997a07e 100644
--- a/torch/csrc/profiler/kineto_shim.cpp
+++ b/torch/csrc/profiler/kineto_shim.cpp
@@ -138,6 +138,7 @@ TraceWrapper::TraceWrapper(const int64_t start_time, const std::string& name)
}
#endif // USE_KINETO
+#ifdef USE_KINETO
activity_t* TraceWrapper::addCPUActivity(
const std::string& name,
const libkineto::ActivityType type,
@@ -145,7 +146,6 @@ activity_t* TraceWrapper::addCPUActivity(
const uint64_t correlation_id,
const int64_t start_time,
const int64_t end_time) {
-#ifdef USE_KINETO
TORCH_CHECK((bool)(*this), "Cannot add event to non-existent trace.");
cpu_trace_->emplace_activity(cpu_trace_->span, type, name);
auto& act = libkineto::CpuTraceBuffer::toRef(cpu_trace_->activities.back());
@@ -157,10 +157,18 @@ activity_t* TraceWrapper::addCPUActivity(
act.endTime = end_time;
}
return cpu_trace_->activities.back().get();
+}
#else
+activity_t* TraceWrapper::addCPUActivity(
+ const std::string& name,
+ const libkineto::ActivityType type,
+ const DeviceAndResource device_and_resource,
+ const uint64_t correlation_id,
+ const int64_t start_time,
+ const int64_t end_time) {
return nullptr;
-#endif // USE_KINETO
}
+#endif // USE_KINETO
void TraceWrapper::transferCpuTrace(int64_t end_time) {
#ifdef USE_KINETO
@@ -473,6 +481,7 @@ void logInvariantViolation(
namespace autograd::profiler {
c10::DeviceType deviceTypeFromActivity(libkineto::ActivityType activity_type) {
+#ifdef USE_KINETO
// PrivateUse1 kineto backend reuse some ActivityTypes,
// If PrivateUse1 backend is enabled, this should return
// c10::DeviceType::PrivateUse1.
@@ -524,6 +533,9 @@ c10::DeviceType deviceTypeFromActivity(libkineto::ActivityType activity_type) {
return c10::DeviceType::CPU;
}
}
+#else
+ return c10::DeviceType::CPU;
+#endif // USE_KINETO
}
void addMetadataJson(const std::string& key, const std::string& value) {
diff --git a/torch/csrc/profiler/kineto_shim.h b/torch/csrc/profiler/kineto_shim.h
index 4f9bdc6770507..ddc00c03fa9cc 100644
--- a/torch/csrc/profiler/kineto_shim.h
+++ b/torch/csrc/profiler/kineto_shim.h
@@ -12,7 +12,21 @@
#undef USE_KINETO
#endif
+#ifdef USE_KINETO
#include <ActivityType.h>
+#else
+namespace libkineto {
+enum class ActivityType : uint8_t {
+ CPU_OP = 0,
+ USER_ANNOTATION,
+ GPU_USER_ANNOTATION,
+ NONE = CPU_OP,
+};
+inline const char* toString(ActivityType) {
+ return "CPU_OP";
+}
+} // namespace libkineto
+#endif
#include <torch/csrc/Export.h>
#include <torch/csrc/profiler/api.h>

View file

@ -0,0 +1,50 @@
Fix for CXX=clang USE=rocm error: invalid argument '-std=c++17' not allowed with 'C'
https://github.com/pytorch/pytorch/issues/103222
--- a/c10/hip/CMakeLists.txt
+++ b/c10/hip/CMakeLists.txt
@@ -37,6 +37,7 @@ if(NOT BUILD_LIBTORCHLESS)
# Propagate HIP_CXX_FLAGS that were set from Dependencies.cmake
target_compile_options(c10_hip PRIVATE ${HIP_CXX_FLAGS})
+ set_target_properties(c10_hip PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
# caffe2_hip adds a bunch of dependencies like rocsparse, but c10/hip is supposed to be
# minimal. I'm not sure if we need hip_hcc or not; for now leave it out
--- a/caffe2/CMakeLists.txt
+++ b/caffe2/CMakeLists.txt
@@ -1774,6 +1774,7 @@ if(USE_ROCM)
# Since PyTorch files contain HIP headers, these flags are required for the necessary definitions to be added.
target_compile_options(torch_hip PUBLIC ${HIP_CXX_FLAGS}) # experiment
+ set_target_properties(torch_hip PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
target_link_libraries(torch_hip PUBLIC c10_hip)
@@ -2003,6 +2004,7 @@ if(BUILD_TEST)
target_include_directories(${test_name} PRIVATE $<INSTALL_INTERFACE:include>)
target_include_directories(${test_name} PRIVATE ${Caffe2_CPU_INCLUDE} ${Caffe2_HIP_INCLUDE})
target_compile_options(${test_name} PRIVATE ${HIP_CXX_FLAGS})
+ set_target_properties(${test_name} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
if(INSTALL_TEST)
set_target_properties(${test_name} PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:${_rpath_portable_origin}/../lib")
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -1014,7 +1014,6 @@
list(APPEND HIP_CXX_FLAGS -DUSE_ROCM_CK_GEMM)
endif()
list(APPEND HIP_HIPCC_FLAGS --offload-compress)
- list(APPEND HIP_HIPCC_FLAGS -std=c++17)
# Pass device library path for theRock nightly builds
if(DEFINED ENV{HIP_DEVICE_LIB_PATH})
file(TO_CMAKE_PATH "$ENV{HIP_DEVICE_LIB_PATH}" _hip_device_lib_path)
--- a/cmake/public/utils.cmake
+++ b/cmake/public/utils.cmake
@@ -254,6 +254,7 @@ function(caffe2_hip_binary_target target_name_or_src)
caffe2_binary_target(${target_name_or_src})
target_compile_options(${__target} PRIVATE ${HIP_CXX_FLAGS})
+ set_target_properties(${__target} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
target_include_directories(${__target} PRIVATE ${Caffe2_HIP_INCLUDE})
endfunction()

View file

@ -0,0 +1,13 @@
--- a/torch/lib/libshm/CMakeLists.txt 2024-09-04 06:09:51.943752841 +0200
+++ b/torch/lib/libshm/CMakeLists.txt 2024-09-04 06:10:52.243821438 +0200
@@ -24,6 +24,10 @@
CXX_STANDARD 17)
target_link_libraries(shm PRIVATE ${TORCH_CPU_LIB})
+if (USE_DISTRIBUTED)
+ target_link_libraries(shm PRIVATE cpp-httplib)
+endif()
+
if(UNIX AND NOT APPLE)
include(CheckLibraryExists)
find_package(Threads REQUIRED)

View file

@ -0,0 +1,11 @@
--- a/cmake/Dependencies.cmake 2024-04-29 18:37:34.005639858 +0200
+++ b/cmake/Dependencies.cmake 2024-04-29 18:39:29.126587738 +0200
@@ -1235,7 +1235,7 @@
if(CUDNN_VERSION VERSION_LESS 8.5)
message(FATAL_ERROR "PyTorch needs CuDNN-8.5 or above, but found ${CUDNN_VERSION}. Builds are still possible with `USE_CUDNN=0`")
endif()
- set(CUDNN_FRONTEND_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/../third_party/cudnn_frontend/include)
+ set(CUDNN_FRONTEND_INCLUDE_DIR /opt/cuda/include)
target_include_directories(torch::cudnn INTERFACE ${CUDNN_FRONTEND_INCLUDE_DIR})
endif()

View file

@ -0,0 +1,29 @@
https://github.com/pytorch/pytorch/issues/58054
--- a/c10/util/Logging.cpp
+++ b/c10/util/Logging.cpp
@@ -192,23 +192,13 @@
google::GLOG_WARNING,
"The minimum log level that caffe2 will output.");
-// Google glog's api does not have an external function that allows one to check
-// if glog is initialized or not. It does have an internal function - so we are
-// declaring it here. This is a hack but has been used by a bunch of others too
-// (e.g. Torch).
-namespace google {
-namespace glog_internal_namespace_ {
-bool IsGoogleLoggingInitialized();
-} // namespace glog_internal_namespace_
-} // namespace google
-
namespace c10 {
namespace {
void initGoogleLogging(char const* name) {
#if !defined(_MSC_VER)
// This trick can only be used on UNIX platforms
- if (!::google::glog_internal_namespace_::IsGoogleLoggingInitialized())
+ if (!::google::IsGoogleLoggingInitialized())
#endif
{
::google::InitGoogleLogging(name);

View file

@ -0,0 +1,10 @@
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -1522,7 +1522,6 @@
# CMAKE_CXX_FLAGS in ways that break feature checks. Since we already know
# `fmt` is compatible with a superset of the compilers that PyTorch is, it
# shouldn't be too bad to just disable the checks.
-set_target_properties(fmt-header-only PROPERTIES INTERFACE_COMPILE_FEATURES "")
list(APPEND Caffe2_DEPENDENCY_LIBS fmt)
set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE)

View file

@ -0,0 +1,33 @@
--- a/torch/CMakeLists.txt 2024-11-09 20:50:21.806784527 +0100
+++ b/torch/CMakeLists.txt 2024-11-09 20:52:56.303892418 +0100
@@ -67,7 +67,7 @@
${TORCH_ROOT}/third_party/gloo
${TORCH_ROOT}/third_party/onnx
${TORCH_ROOT}/third_party/flatbuffers/include
- ${TORCH_ROOT}/third_party/kineto/libkineto/include
+ "/usr/include/kineto"
${TORCH_ROOT}/third_party/cpp-httplib
${TORCH_ROOT}/third_party/nlohmann/include
--- a/caffe2/CMakeLists.txt 2024-11-09 20:58:37.698085144 +0100
+++ b/caffe2/CMakeLists.txt 2024-11-09 20:59:15.771391643 +0100
@@ -1185,7 +1185,7 @@
${TORCH_ROOT}/third_party/miniz-2.1.0)
target_include_directories(torch_cpu PRIVATE
- ${TORCH_ROOT}/third_party/kineto/libkineto/include)
+ "/usr/include/kineto")
if(USE_KINETO)
target_include_directories(torch_cpu PRIVATE
--- a/cmake/Dependencies.cmake 2025-05-04 15:30:00.268862558 +0200
+++ b/cmake/Dependencies.cmake 2025-05-04 15:30:13.275934233 +0200
@@ -1711,7 +1711,7 @@
endif()
endif()
- if(NOT TARGET kineto)
+ if(FALSE)
add_subdirectory("${KINETO_SOURCE_DIR}")
set_property(TARGET kineto PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()

View file

@ -0,0 +1,50 @@
Fix for CXX=clang USE=rocm error: invalid argument '-std=c++17' not allowed with 'C'
https://github.com/pytorch/pytorch/issues/103222
--- a/c10/hip/CMakeLists.txt
+++ b/c10/hip/CMakeLists.txt
@@ -36,6 +36,7 @@ if(NOT BUILD_LIBTORCHLESS)
# Propagate HIP_CXX_FLAGS that were set from Dependencies.cmake
target_compile_options(c10_hip PRIVATE ${HIP_CXX_FLAGS})
+ set_target_properties(c10_hip PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
# caffe2_hip adds a bunch of dependencies like rocsparse, but c10/hip is supposed to be
# minimal. I'm not sure if we need hip_hcc or not; for now leave it out
--- a/caffe2/CMakeLists.txt
+++ b/caffe2/CMakeLists.txt
@@ -1684,6 +1684,7 @@ if(USE_ROCM)
# Since PyTorch files contain HIP headers, these flags are required for the necessary definitions to be added.
target_compile_options(torch_hip PUBLIC ${HIP_CXX_FLAGS}) # experiment
+ set_target_properties(torch_hip PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
target_link_libraries(torch_hip PUBLIC c10_hip)
@@ -1886,6 +1887,7 @@ if(BUILD_TEST)
target_include_directories(${test_name} PRIVATE $<INSTALL_INTERFACE:include>)
target_include_directories(${test_name} PRIVATE ${Caffe2_CPU_INCLUDE} ${Caffe2_HIP_INCLUDE})
target_compile_options(${test_name} PRIVATE ${HIP_CXX_FLAGS})
+ set_target_properties(${test_name} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
if(INSTALL_TEST)
set_target_properties(${test_name} PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:${_rpath_portable_origin}/../lib")
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -1043,7 +1043,6 @@ if(USE_ROCM)
list(APPEND HIP_CXX_FLAGS -Wno-duplicate-decl-specifier)
list(APPEND HIP_CXX_FLAGS -DCAFFE2_USE_MIOPEN)
list(APPEND HIP_CXX_FLAGS -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_HIP)
- list(APPEND HIP_CXX_FLAGS -std=c++17)
list(APPEND HIP_CXX_FLAGS -DHIPBLAS_V2)
if(HIP_NEW_TYPE_ENUMS)
list(APPEND HIP_CXX_FLAGS -DHIP_NEW_TYPE_ENUMS)
--- a/cmake/public/utils.cmake
+++ b/cmake/public/utils.cmake
@@ -267,6 +267,7 @@ function(caffe2_hip_binary_target target_name_or_src)
caffe2_binary_target(${target_name_or_src})
target_compile_options(${__target} PRIVATE ${HIP_CXX_FLAGS})
+ set_target_properties(${__target} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
target_include_directories(${__target} PRIVATE ${Caffe2_HIP_INCLUDE})
endfunction()

View file

@ -0,0 +1,11 @@
--- a/c10/util/Logging.cpp 2025-06-26 11:47:58.901240691 +0200
+++ b/c10/util/Logging.cpp 2025-06-26 11:51:56.959290731 +0200
@@ -352,7 +352,7 @@
void ShowLogInfoToStderr() {
FLAGS_logtostderr = 1;
- FLAGS_minloglevel = std::min(FLAGS_minloglevel, google::GLOG_INFO);
+ FLAGS_minloglevel = std::min(FLAGS_minloglevel, int(google::GLOG_INFO));
}
} // namespace c10

View file

@ -0,0 +1,27 @@
Fix installation with aotriton
Upstream bug: https://github.com/pytorch/pytorch/issues/158109
--- a/cmake/External/aotriton.cmake
+++ b/cmake/External/aotriton.cmake
@@ -43,10 +43,6 @@ if(NOT __AOTRITON_INCLUDED)
# Note it is INSTALL"ED"
if(DEFINED ENV{AOTRITON_INSTALLED_PREFIX})
- install(DIRECTORY
- $ENV{AOTRITON_INSTALLED_PREFIX}/${CMAKE_INSTALL_LIBDIR}
- $ENV{AOTRITON_INSTALLED_PREFIX}/include
- DESTINATION ${__AOTRITON_INSTALL_DIR})
set(__AOTRITON_INSTALL_DIR "$ENV{AOTRITON_INSTALLED_PREFIX}")
message(STATUS "Using Preinstalled AOTriton at ${__AOTRITON_INSTALL_DIR}")
elseif(DEFINED ENV{AOTRITON_INSTALL_FROM_SOURCE})
--- a/caffe2/CMakeLists.txt
+++ b/caffe2/CMakeLists.txt
@@ -921,7 +921,7 @@ if(USE_ROCM)
set(CUDA_LINK_LIBRARIES_KEYWORD PRIVATE)
list(APPEND Caffe2_HIP_SRCS ${GENERATED_CXX_TORCH_CUDA})
hip_add_library(torch_hip ${Caffe2_HIP_SRCS})
- if(USE_FLASH_ATTENTION)
+ if(USE_FLASH_ATTENTION OR USE_MEM_EFF_ATTENTION)
target_link_libraries(torch_hip PRIVATE __caffe2_aotriton)
endif()
set(CUDA_LINK_LIBRARIES_KEYWORD)

View file

@ -0,0 +1,86 @@
Fix use of undeclared identifier 'CHECK_NOSPARSE_CONTIGUOUS_CUDA' with USE='-flash'
Bug: https://github.com/pytorch/pytorch/issues/160826
--- a/aten/src/ATen/native/transformers/cuda/attention.cu
+++ b/aten/src/ATen/native/transformers/cuda/attention.cu
@@ -71,6 +71,7 @@
#include <ATen/native/transformers/cuda/sdp_utils.h>
#include <ATen/native/transformers/sdp_utils_cpp.h>
+#include <ATen/native/transformers/flash_api_common.h>
#ifdef USE_FLASH_ATTENTION
// FlashAttention Specific Imports
#include <ATen/native/transformers/cuda/flash_attn/flash_api.h>
--- a/aten/src/ATen/native/transformers/cuda/attention_backward.cu
+++ b/aten/src/ATen/native/transformers/cuda/attention_backward.cu
@@ -33,6 +33,7 @@
#include <ATen/ops/_scaled_dot_product_flash_attention_backward_native.h>
#endif
+#include <ATen/native/transformers/flash_api_common.h>
#ifdef USE_FLASH_ATTENTION
// FlashAttention Specific Imports
#include <ATen/native/transformers/cuda/flash_attn/flash_api.h>
--- /dev/null
+++ b/aten/src/ATen/native/transformers/flash_api_common.h
@@ -0,0 +1,28 @@
+#pragma once
+#include <cstdint>
+#include <limits>
+
+#include <ATen/core/Tensor.h>
+#include <c10/util/Exception.h>
+
+#define CHECK_NOSPARSE_CONTIGUOUS_CUDA(TENSOR) \
+ TORCH_CHECK(TENSOR.is_cuda(), #TENSOR " must be a CUDA tensor"); \
+ TORCH_CHECK(!TENSOR.is_sparse(), #TENSOR " must be a dense tensor"); \
+ TORCH_CHECK(TENSOR.is_contiguous());
+
+#define CHECK_NOSPARSE_LASTCONTIGUOUS_CUDA(TENSOR) \
+ TORCH_CHECK(TENSOR.is_cuda(), #TENSOR " must be a CUDA tensor"); \
+ TORCH_CHECK(!TENSOR.is_sparse(), #TENSOR " must be a dense tensor"); \
+ TORCH_CHECK( \
+ TENSOR.stride(-1) == 1, #TENSOR ": last dimension must be contiguous");
+
+#define CHECK_ALIGNED_PTR(PTR, ALIGNMENT) \
+ TORCH_CHECK( \
+ uint64_t(PTR) % ALIGNMENT == 0, #PTR " is not correctly aligned")
+
+#define ASSIGN_CHECK_OVERFLOW(A, B) \
+ { \
+ A = B; \
+ TORCH_CHECK( \
+ B < std::numeric_limits<decltype(A)>::max(), #B " overflows"); \
+ }
--- a/aten/src/ATen/native/transformers/hip/flash_attn/flash_api.h
+++ b/aten/src/ATen/native/transformers/hip/flash_attn/flash_api.h
@@ -4,28 +4,7 @@
#include <ATen/Context.h>
#include <ATen/core/Tensor.h>
#include <c10/util/Exception.h>
-
-#define CHECK_NOSPARSE_CONTIGUOUS_CUDA(TENSOR) \
- TORCH_CHECK(TENSOR.is_cuda(), #TENSOR " must be a CUDA tensor"); \
- TORCH_CHECK(!TENSOR.is_sparse(), #TENSOR " must be a dense tensor"); \
- TORCH_CHECK(TENSOR.is_contiguous());
-
-#define CHECK_NOSPARSE_LASTCONTIGUOUS_CUDA(TENSOR) \
- TORCH_CHECK(TENSOR.is_cuda(), #TENSOR " must be a CUDA tensor"); \
- TORCH_CHECK(!TENSOR.is_sparse(), #TENSOR " must be a dense tensor"); \
- TORCH_CHECK( \
- TENSOR.stride(-1) == 1, #TENSOR ": last dimension must be contiguous");
-
-#define CHECK_ALIGNED_PTR(PTR, ALIGNMENT) \
- TORCH_CHECK( \
- uint64_t(PTR) % ALIGNMENT == 0, #PTR " is not correctly aligned")
-
-#define ASSIGN_CHECK_OVERFLOW(A, B) \
- { \
- A = B; \
- TORCH_CHECK( \
- B < std::numeric_limits<decltype(A)>::max(), #B " overflows"); \
- }
+#include <ATen/native/transformers/flash_api_common.h>
namespace pytorch_flash {

View file

@ -0,0 +1,18 @@
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -276,15 +276,8 @@
# --- [ PocketFFT
set(AT_POCKETFFT_ENABLED 0)
if(NOT AT_MKL_ENABLED)
- set(POCKETFFT_INCLUDE_DIR "${Torch_SOURCE_DIR}/third_party/pocketfft/")
- if(NOT EXISTS "${POCKETFFT_INCLUDE_DIR}")
- message(FATAL_ERROR "pocketfft directory not found, expected ${POCKETFFT_INCLUDE_DIR}")
- elseif(NOT EXISTS "${POCKETFFT_INCLUDE_DIR}/pocketfft_hdronly.h")
- message(FATAL_ERROR "pocketfft headers not found in ${POCKETFFT_INCLUDE_DIR}")
- endif()
set(AT_POCKETFFT_ENABLED 1)
- message(STATUS "Using pocketfft in directory: ${POCKETFFT_INCLUDE_DIR}")
endif()
# ---[ Dependencies

View file

@ -0,0 +1,53 @@
--- a/.ci/pytorch/test_example_code/CMakeLists.txt 2025-10-24 18:25:10.584717735 +0200
+++ b/.ci/pytorch/test_example_code/CMakeLists.txt 2025-10-24 18:25:17.195639297 +0200
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
+cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(simple-torch-test)
find_package(Torch REQUIRED)
--- a/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt 2025-10-24 18:26:46.165583599 +0200
+++ b/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt 2025-10-24 18:27:00.085418425 +0200
@@ -4,7 +4,7 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
-cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
include(GNUInstallDirs)
--- a/aten/src/ATen/test/test_install/CMakeLists.txt 2025-10-24 18:27:36.180990366 +0200
+++ b/aten/src/ATen/test/test_install/CMakeLists.txt 2025-10-24 18:27:46.812864333 +0200
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.5)
+cmake_minimum_required(VERSION 3.10)
find_package(ATen REQUIRED)
include_directories(${ATEN_INCLUDE_DIR})
--- a/aten/src/ATen/nnapi/CMakeLists.txt 2025-10-24 18:28:58.948009238 +0200
+++ b/aten/src/ATen/nnapi/CMakeLists.txt 2025-10-24 18:29:11.040865888 +0200
@@ -1,6 +1,6 @@
# Define this to build the NNAPI binding out of tree.
if(PYTORCH_NNAPI_STANDALONE)
- cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+ cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(pytorch_nnapi)
set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ standard whose features are requested to build this target.")
--- a/android/pytorch_android_torchvision/CMakeLists.txt 2025-10-24 18:29:31.653621543 +0200
+++ b/android/pytorch_android_torchvision/CMakeLists.txt 2025-10-24 18:29:41.668502824 +0200
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.5)
+cmake_minimum_required(VERSION 3.10)
project(pytorch_vision_jni CXX)
set(CMAKE_CXX_STANDARD 17 CACHE STRING "The C++ standard whose features are requested to build this target.")
#_cmake_modify_IGNORE set(CMAKE_VERBOSE_MAKEFILE ON)
--- a/android/pytorch_android/CMakeLists.txt 2025-10-24 18:29:54.079355700 +0200
+++ b/android/pytorch_android/CMakeLists.txt 2025-10-24 18:30:39.793813797 +0200
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.5)
+cmake_minimum_required(VERSION 3.10)
option(BUILD_LITE_INTERPRETER "Master flag to build pytorch_jni_lite" ON)
message(
STATUS

View file

@ -0,0 +1,28 @@
USE_ROCM=ON USE_DISTRIBUTED=ON: fix *runtime* error: undefined symbol: rsmi_init
Upstream bug: https://github.com/pytorch/pytorch/issues/158725
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -1058,6 +1058,12 @@ if(USE_ROCM)
)
endif()
+ if(USE_DISTRIBUTED)
+ list(APPEND Caffe2_PUBLIC_HIP_DEPENDENCY_LIBS
+ rocm_smi64
+ )
+ endif()
+
# ---[ Kernel asserts
# Kernel asserts is disabled for ROCm by default.
# It can be turned on by turning on the env USE_ROCM_KERNEL_ASSERT to the build system.
--- a/cmake/public/LoadHIP.cmake
+++ b/cmake/public/LoadHIP.cmake
@@ -170,6 +170,7 @@ if(HIP_FOUND)
find_package_and_print_version(rocthrust REQUIRED)
find_package_and_print_version(hipsolver REQUIRED)
find_package_and_print_version(rocsolver REQUIRED)
+ find_package_and_print_version(rocm_smi REQUIRED)
# workaround cmake 4 build issue
if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0")
message(WARNING "Work around hiprtc cmake failure for cmake >= 4")

View file

@ -0,0 +1,15 @@
--- a/caffe2/CMakeLists.txt 2026-01-19 20:28:45.127614622 +0100
+++ b/caffe2/CMakeLists.txt 2026-01-19 20:32:04.509213652 +0100
@@ -1495,6 +1495,12 @@
endif()
endif()
+if(USE_DISTRIBUTED)
+ if(USE_MPI)
+ find_package(httplib REQUIRED)
+ target_link_libraries(torch_cpu PRIVATE httplib::httplib)
+ endif()
+endif()
if(NOT INTERN_BUILD_MOBILE)
if(${CAFFE2_LINK_LOCAL_PROTOBUF})
target_link_libraries(torch_cpu INTERFACE protobuf::libprotobuf)

View file

@ -0,0 +1,141 @@
Fix for "undeclared identifier 'CK_BUFFER_RESOURCE_3RD_DWORD'" for AMDGPU_TARGETS="gfx1012".
Combines of 3 patches from https://github.com/ROCm/composable_kernel/issues/775#issuecomment-2726315348
Bug: https://bugs.gentoo.org/947583
Bug: https://bugs.gentoo.org/show_bug.cgi?id=959808
--- a/include/ck/ck.hpp
+++ b/include/ck/ck.hpp
@@ -78,7 +78,7 @@
#define CK_BUFFER_RESOURCE_3RD_DWORD -1
#elif defined(__gfx803__) || defined(__gfx900__) || defined(__gfx906__) || defined(__gfx9__)
#define CK_BUFFER_RESOURCE_3RD_DWORD 0x00020000
-#elif defined(__gfx103__)
+#elif defined(__gfx101__) || defined(__gfx103__)
#define CK_BUFFER_RESOURCE_3RD_DWORD 0x31014000
#elif defined(__gfx11__) || defined(__gfx12__)
#define CK_BUFFER_RESOURCE_3RD_DWORD 0x31004000
@@ -86,12 +86,12 @@
// FMA instruction
#ifndef __HIP_DEVICE_COMPILE__ // for host code, define nothing
-#elif defined(__gfx803__) || defined(__gfx900__) // for GPU code
-#define CK_USE_AMD_V_MAC_F32
-#elif defined(__gfx906__) || defined(__gfx9__) || defined(__gfx103__) // for GPU code
+#elif defined(__gfx906__) || defined(__gfx9__) || defined(__gfx103__) || defined(__gfx1011__) || defined(__gfx1012__) // for GPU code
#define CK_USE_AMD_V_FMAC_F32
#define CK_USE_AMD_V_DOT2_F32_F16
#define CK_USE_AMD_V_DOT4_I32_I8
+#elif defined(__gfx803__) || defined(__gfx900__) || defined(__gfx101__) // for GPU code
+#define CK_USE_AMD_V_MAC_F32
#elif defined(__gfx11__) || defined(__gfx12__)
#define CK_USE_AMD_V_FMAC_F32
#define CK_USE_AMD_V_DOT2_F32_F16
--- a/include/ck/tensor_operation/gpu/device/impl/device_batched_gemm_multiple_d_dl.hpp
+++ b/include/ck/tensor_operation/gpu/device/impl/device_batched_gemm_multiple_d_dl.hpp
@@ -71,7 +71,7 @@ __launch_bounds__(CK_MAX_THREAD_PER_BLOCK, CK_MIN_BLOCK_PER_CU)
const Block2CTileMap block_2_ctile_map)
{
#if(defined(__gfx906__) || defined(__gfx908__) || defined(__gfx90a__) || defined(__gfx94__) || \
- defined(__gfx103__) || defined(__gfx11__) || defined(__gfx12__))
+ defined(__gfx101__) || defined(__gfx103__) || defined(__gfx11__) || defined(__gfx12__))
const index_t num_blocks_per_batch =
__builtin_amdgcn_readfirstlane(get_grid_size() / batch_count);
--- a/include/ck/tensor_operation/gpu/device/impl/device_gemm_multiple_d_dl.hpp
+++ b/include/ck/tensor_operation/gpu/device/impl/device_gemm_multiple_d_dl.hpp
@@ -50,7 +50,7 @@ __launch_bounds__(CK_MAX_THREAD_PER_BLOCK, CK_MIN_BLOCK_PER_CU)
const CGridDesc_M0_M10_M11_N0_N10_N11 e_grid_desc_m0_m10_m11_n0_n10_n11,
const Block2CTileMap block_2_ctile_map)
{
-#if(defined(__gfx906__) || defined(__gfx9__) || defined(__gfx103__) || defined(__gfx11__) || \
+#if(defined(__gfx906__) || defined(__gfx9__) || defined(__gfx101__) || defined(__gfx103__) || defined(__gfx11__) || \
defined(__gfx12__))
constexpr index_t shared_block_size =
--- a/include/ck/tensor_operation/gpu/device/impl/device_grouped_conv_bwd_weight_dl.hpp
+++ b/include/ck/tensor_operation/gpu/device/impl/device_grouped_conv_bwd_weight_dl.hpp
@@ -48,7 +48,7 @@ __launch_bounds__(CK_MAX_THREAD_PER_BLOCK, CK_MIN_BLOCK_PER_CU)
const Block2CTileMap block_2_ctile_map,
const ComputePtrOffsetOfBatch compute_ptr_offset_of_batch)
{
-#if(defined(__gfx906__) || defined(__gfx103__) || defined(__gfx90a__) || defined(__gfx908__) || \
+#if(defined(__gfx906__) || defined(__gfx101__) || defined(__gfx103__) || defined(__gfx90a__) || defined(__gfx908__) || \
defined(__gfx94__) || defined(__gfx11__) || defined(__gfx12__))
const index_t num_blocks_per_batch =
__builtin_amdgcn_readfirstlane(get_grid_size() / batch_count);
--- a/include/ck/tensor_operation/gpu/device/impl/device_grouped_conv_fwd_dl_multiple_d_nhwc_kyxc_nhwk.hpp
+++ b/include/ck/tensor_operation/gpu/device/impl/device_grouped_conv_fwd_dl_multiple_d_nhwc_kyxc_nhwk.hpp
@@ -90,7 +90,7 @@ __launch_bounds__(CK_MAX_THREAD_PER_BLOCK, CK_MIN_BLOCK_PER_CU)
const Block2CTileMap block_2_ctile_map,
const ComputePtrOffsetOfBatch compute_ptr_offset_of_batch)
{
-#if(defined(__gfx906__) || defined(__gfx103__) || defined(__gfx90a__) || defined(__gfx908__) || \
+#if(defined(__gfx906__) || defined(__gfx101__) || defined(__gfx101__) || defined(__gfx103__) || defined(__gfx90a__) || defined(__gfx908__) || \
defined(__gfx94__) || defined(__gfx11__) || defined(__gfx12__))
// offset base pointer for each work-group
const index_t num_blocks_per_batch =
--- a/include/ck/tensor_operation/gpu/device/impl/device_grouped_conv_fwd_dl_nhwc_kyxc_nhwk.hpp
+++ b/include/ck/tensor_operation/gpu/device/impl/device_grouped_conv_fwd_dl_nhwc_kyxc_nhwk.hpp
@@ -106,7 +106,7 @@ __launch_bounds__(CK_MAX_THREAD_PER_BLOCK, CK_MIN_BLOCK_PER_CU)
const Block2CTileMap block_2_ctile_map,
const ComputePtrOffsetOfBatch compute_ptr_offset_of_batch)
{
-#if(defined(__gfx906__) || defined(__gfx103__) || defined(__gfx11__) || defined(__gfx12__))
+#if(defined(__gfx906__) || defined(__gfx101__) || defined(__gfx103__) || defined(__gfx11__) || defined(__gfx12__))
// offset base pointer for each work-group
const index_t num_blocks_per_batch =
__builtin_amdgcn_readfirstlane(get_grid_size() / batch_count);
--- a/include/ck/tensor_operation/gpu/device/impl/device_grouped_gemm_multiple_d_dl.hpp
+++ b/include/ck/tensor_operation/gpu/device/impl/device_grouped_gemm_multiple_d_dl.hpp
@@ -40,7 +40,7 @@ __launch_bounds__(CK_MAX_THREAD_PER_BLOCK, CK_MIN_BLOCK_PER_CU)
const BElementwiseOperation b_element_op,
const CDEElementwiseOperation cde_element_op)
{
-#if(defined(__gfx906__) || defined(__gfx908__) || defined(__gfx90a__) || defined(__gfx103__) || \
+#if(defined(__gfx906__) || defined(__gfx908__) || defined(__gfx90a__) || defined(__gfx101__) || defined(__gfx101__) || defined(__gfx103__) || \
defined(__gfx11__) || defined(__gfx94__) || defined(__gfx12__))
__shared__ char p_shared[GridwiseGemm::GetSharedMemoryNumberOfByte()];
--- a/include/ck/tensor_operation/gpu/grid/gridwise_gemm_dpp.hpp
+++ b/include/ck/tensor_operation/gpu/grid/gridwise_gemm_dpp.hpp
@@ -28,7 +28,7 @@ __launch_bounds__(CK_MAX_THREAD_PER_BLOCK, CK_MIN_BLOCK_PER_CU)
#endif
kernel_gemm_dpp(const typename GridwiseGemm::Argument karg)
{
-#if(defined(__gfx103__) || defined(__gfx11__))
+#if(defined(__gfx101__) || defined(__gfx103__) || defined(__gfx11__))
__shared__ char p_shared[GridwiseGemm::GetSharedMemoryNumberOfByte()];
const auto a_grid_desc_ak0_m_ak1 = amd_wave_read_first_lane(
--- a/include/ck/tensor_operation/gpu/grid/gridwise_tensor_rearrange.hpp
+++ b/include/ck/tensor_operation/gpu/grid/gridwise_tensor_rearrange.hpp
@@ -36,7 +36,7 @@ __launch_bounds__(CK_MAX_THREAD_PER_BLOCK, CK_MIN_BLOCK_PER_CU)
const ComputePtrOffsetOfStridedBatch compute_ptr_offset_of_batch)
{
#if(defined(__gfx906__) || defined(__gfx908__) || defined(__gfx90a__) || defined(__gfx94__) || \
- defined(__gfx103__) || defined(__gfx11__) || defined(__gfx12__))
+ defined(__gfx101__) || defined(__gfx103__) || defined(__gfx11__) || defined(__gfx12__))
GridwiseTensorRearrangeKernel::Run(in_grid_desc,
p_in_global,
out_grid_desc,
--- a/include/ck_tile/core/config.hpp
+++ b/include/ck_tile/core/config.hpp
@@ -9,6 +9,9 @@
#if defined(__gfx942__) || defined(__gfx950__)
#define __gfx94__
#endif
+#if defined(__gfx1010__) || defined(__gfx1011__) || defined(__gfx1012__)
+#define __gfx101__
+#endif
#if defined(__gfx1030__) || defined(__gfx1031__) || defined(__gfx1032__) || \
defined(__gfx1034__) || defined(__gfx1035__) || defined(__gfx1036__) || \
defined(__gfx10_3_generic__)
@@ -200,7 +203,7 @@
#elif defined(__gfx803__) || defined(__gfx900__) || defined(__gfx906__) || \
defined(__gfx9__) // for GPU code
#define CK_TILE_BUFFER_RESOURCE_3RD_DWORD 0x00020000
-#elif defined(__gfx103__) // for GPU code
+#elif defined(__gfx101__) || defined(__gfx103__) // for GPU code
#define CK_TILE_BUFFER_RESOURCE_3RD_DWORD 0x31014000
#elif defined(__gfx11__) || defined(__gfx12__) // for GPU code
#define CK_TILE_BUFFER_RESOURCE_3RD_DWORD 0x31004000

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
<maintainer type="person">
<email>tupone@gentoo.org</email>
<name>Tupone Alfredo</name>
</maintainer>
<use>
<flag name="cusparselt">Use the CUDA/HIP Sparse Matrix Multiplication</flag>
<flag name="distributed">Support distributed applications</flag>
<flag name="fbgemm">Use <pkg>sci-ml/FBGEMM</pkg></flag>
<flag name="flash">Enable flash attention</flag>
<flag name="gloo">Use <pkg>sci-ml/gloo</pkg></flag>
<flag name="kineto">Use<pkg>sci-ml/kineto</pkg>profiling library</flag>
<flag name="memefficient">Enable mem efficient attention</flag>
<flag name="mimalloc">Use <pkg>dev-libs/mimalloc</pkg> as replacement for system malloc</flag>
<flag name="mkl">Use <pkg>sci-libs/mkl</pkg> for blas, lapack and sparse blas routines</flag>
<flag name="nccl">Use <pkg>dev-libs/rccl</pkg> (NCCL compatible) backend for distributed operations</flag>
<flag name="nnpack">Use <pkg>sci-ml/NNPACK</pkg></flag>
<flag name="numpy">Add support for math operations through numpy</flag>
<flag name="onednn">Use <pkg>sci-ml/oneDNN</pkg></flag>
<flag name="openblas">Use <pkg>sci-libs/openblas</pkg> for blas routines</flag>
<flag name="openmp">Use OpenMP for parallel code</flag>
<flag name="qnnpack">Use QNNPACK</flag>
<flag name="rocm">Enable ROCm gpu computing support</flag>
<flag name="xnnpack">Use <pkg>sci-ml/XNNPACK</pkg></flag>
</use>
<upstream>
<remote-id type="github">pytorch/pytorch</remote-id>
</upstream>
</pkgmetadata>

View file

@ -0,0 +1,16 @@
Fixes multilib (%LIB_DIR% should be replaced in ebuild)
--- a/torch/utils/cpp_extension.py
+++ b/torch/utils/cpp_extension.py
@@ -1478,10 +1477,10 @@ def library_paths(device_type: str = "cpu") -> list[str]:
paths = [TORCH_LIB_PATH]
if device_type == "cuda" and IS_HIP_EXTENSION:
- lib_dir = 'lib'
+ lib_dir = '%LIB_DIR%'
paths.append(_join_rocm_home(lib_dir))
if HIP_HOME is not None:
- paths.append(os.path.join(HIP_HOME, 'lib'))
+ paths.append(os.path.join(HIP_HOME, '%LIB_DIR%'))
elif device_type == "cuda":
if IS_WINDOWS:
lib_dir = os.path.join('lib', 'x64')

View file

@ -0,0 +1,25 @@
--- a/setup.py
+++ b/setup.py
@@ -291,6 +291,7 @@
import setuptools.errors
from setuptools import Command, Extension, find_packages, setup
from setuptools.dist import Distribution
+sys.path[:0] = os.getcwd()
CWD = Path(__file__).absolute().parent
@@ -483,14 +483,6 @@
check_submodules()
check_pydep("yaml", "pyyaml")
- build_pytorch(
- version=TORCH_VERSION,
- cmake_python_library=CMAKE_PYTHON_LIBRARY.as_posix(),
- build_python=not BUILD_LIBTORCH_WHL,
- rerun_cmake=RERUN_CMAKE,
- cmake_only=CMAKE_ONLY,
- cmake=cmake,
- )
if CMAKE_ONLY:
report(

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
<maintainer type="person">
<email>tupone@gentoo.org</email>
<name>Tupone Alfredo</name>
</maintainer>
<upstream>
<bugs-to>https://github.com/pytorch/pytorch/issues</bugs-to>
<changelog>https://github.com/pytorch/pytorch/releases</changelog>
<doc>https://pytorch.org/docs/stable/index.html</doc>
<remote-id type="github">pytorch/pytorch</remote-id>
</upstream>
</pkgmetadata>

View file

@ -0,0 +1,70 @@
# Copyright 2022-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
DISTUTILS_USE_PEP517=setuptools
PYTHON_COMPAT=( python3_{11..14} )
DISTUTILS_SINGLE_IMPL=1
DISTUTILS_EXT=1
inherit distutils-r1 prefix
DESCRIPTION="Tensors and Dynamic neural networks in Python"
HOMEPAGE="https://pytorch.org/"
SRC_URI="https://github.com/pytorch/${PN}/archive/refs/tags/v${PV}.tar.gz
-> ${P}.tar.gz"
LICENSE="BSD"
SLOT="0"
KEYWORDS="~amd64 ~arm64"
RESTRICT="test"
REQUIRED_USE=${PYTHON_REQUIRED_USE}
RDEPEND="
${PYTHON_DEPS}
~sci-ml/caffe2-${PV}[${PYTHON_SINGLE_USEDEP}]
$(python_gen_cond_dep '
dev-python/sympy[${PYTHON_USEDEP}]
dev-python/typing-extensions[${PYTHON_USEDEP}]
')
"
DEPEND="${RDEPEND}
$(python_gen_cond_dep '
dev-python/pyyaml[${PYTHON_USEDEP}]
')
"
PATCHES=(
"${FILESDIR}"/${PN}-2.9.0-dontbuildagain.patch
"${FILESDIR}"/${PN}-2.10.0-cpp-extension-multilib.patch
)
src_prepare() {
# Replace placeholders added by cpp-extension.patch
sed -e "s|%LIB_DIR%|$(get_libdir)|g" \
-i torch/utils/cpp_extension.py || die
# Set build dir for pytorch's setup
sed -e "/BUILD_DIR/s|build|/var/lib/caffe2/|" \
-i tools/setup_helpers/env.py || die
# Drop legacy from pyproject.toml
sed -e "/build-backend/s|:__legacy__||" \
-i pyproject.toml || die
distutils-r1_src_prepare
hprefixify tools/setup_helpers/env.py
}
python_compile() {
PYTORCH_BUILD_VERSION=${PV} \
PYTORCH_BUILD_NUMBER=0 \
USE_SYSTEM_LIBS=ON \
CMAKE_BUILD_DIR="${BUILD_DIR}" \
distutils-r1_python_compile develop sdist
}
python_install() {
USE_SYSTEM_LIBS=ON distutils-r1_python_install
}