commit:     b1ba2684adfb3794f68467c03264d4e67ee3173e
Author:     YiyangWu <xgreenlandforwyy <AT> gmail <DOT> com>
AuthorDate: Thu Aug 26 12:34:56 2021 +0000
Commit:     Benda XU <heroxbd <AT> gentoo <DOT> org>
CommitDate: Wed Nov 10 04:47:29 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b1ba2684

sci-libs/miopen: AMD's Machine Intelligence Library

This is AMD's library for high performance machine learning primitives.
PyTorch-ROCm depends on this package.

Closes: https://bugs.gentoo.org/732954
Package-Manager: Portage-3.0.20, Repoman-3.0.3
Signed-off-by: Yiyang Wu <xgreenlandforwyy <AT> gmail.com>
Signed-off-by: Benda Xu <heroxbd <AT> gentoo.org>

 sci-libs/miopen/Manifest                           |  1 +
 .../miopen-4.2.0-disable-no-inline-boost.patch     | 14 ++++
 .../files/miopen-4.2.0-gcc11-numeric_limits.patch  | 14 ++++
 .../miopen/files/miopen-4.3.0-enable-test.patch    | 31 +++++++++
 ...x-interface-include-in-HIP_COMPILER_FLAGS.patch | 17 +++++
 sci-libs/miopen/files/miopen-4.3.0-no-strip.patch  | 16 +++++
 .../files/miopen-4.3.0-strip-xnack-in-flags.patch  | 18 +++++
 sci-libs/miopen/metadata.xml                       | 15 ++++
 sci-libs/miopen/miopen-4.3.0.ebuild                | 80 ++++++++++++++++++++++
 9 files changed, 206 insertions(+)

diff --git a/sci-libs/miopen/Manifest b/sci-libs/miopen/Manifest
new file mode 100644
index 00000000000..ae3770f95d2
--- /dev/null
+++ b/sci-libs/miopen/Manifest
@@ -0,0 +1 @@
+DIST MIOpen-4.3.0.tar.gz 59405686 BLAKE2B 
fe91bd91a74023866883d6d0a2a8071a8fe40c4cff2fb4ef58fc6e343a05ac2a731f73e657f4d183ade4e5b7c1fbbe41f3f032918f6e50cb713073aee8d97dc5
 SHA512 
a8615b7738acfbc7f68d9417b0746c62630d2b48fb8485fafba4db65a4b277a8230f601d249d7e54f89ba25c14176429ca76ad8365a437b09d836b031b0c4fbb

diff --git a/sci-libs/miopen/files/miopen-4.2.0-disable-no-inline-boost.patch 
b/sci-libs/miopen/files/miopen-4.2.0-disable-no-inline-boost.patch
new file mode 100644
index 00000000000..769217acd9d
--- /dev/null
+++ b/sci-libs/miopen/files/miopen-4.2.0-disable-no-inline-boost.patch
@@ -0,0 +1,14 @@
+This let MIOpen compatible with >boost-1.72, for example 1.76
+
+Suggested by: Michael Boone <[email protected]>
+
+--- a/CMakeLists.txt   2021-07-23 01:26:15.377754243 -0700
++++ b/CMakeLists.txt   2021-07-23 01:29:23.925685190 -0700
+@@ -216,6 +216,7 @@
+ message(STATUS "Hip compiler flags: ${HIP_COMPILER_FLAGS}")
+ 
+ add_definitions("-DHIP_COMPILER_FLAGS=${HIP_COMPILER_FLAGS}")
++add_definitions("-DBOOST_CONTAINER_DISABLE_NOINLINE")
+ 
+ 
+ # HIP

diff --git a/sci-libs/miopen/files/miopen-4.2.0-gcc11-numeric_limits.patch 
b/sci-libs/miopen/files/miopen-4.2.0-gcc11-numeric_limits.patch
new file mode 100644
index 00000000000..73997ce5d4d
--- /dev/null
+++ b/sci-libs/miopen/files/miopen-4.2.0-gcc11-numeric_limits.patch
@@ -0,0 +1,14 @@
+See: 
https://stackoverflow.com/questions/4798936/numeric-limits-was-not-declared-in-this-scope-no-matching-function-for-call-t
+
+https://www.gnu.org/software/gcc/gcc-11/porting_to.html#header-dep-changes
+
+--- MIOpen-rocm-4.2.0/src/include/miopen/float_equal.hpp
++++ MIOpen-rocm-4.2.0/src/include/miopen/float_equal.hpp
+@@ -29,6 +29,7 @@
+ #include <algorithm>
+ #include <cmath>
+ #include <numeric>
++#include <limits>
+ #ifdef _MSC_VER
+ #include <iso646.h>
+ #endif

diff --git a/sci-libs/miopen/files/miopen-4.3.0-enable-test.patch 
b/sci-libs/miopen/files/miopen-4.3.0-enable-test.patch
new file mode 100644
index 00000000000..68d2f143bf4
--- /dev/null
+++ b/sci-libs/miopen/files/miopen-4.3.0-enable-test.patch
@@ -0,0 +1,31 @@
+This create option BUILD_TESTS for miopen, like other rocm math libs, and
+
+testing executables are always built if test enabled. The original behaviour, 
is
+
+always add test/CMakeLists.txt without adding test exes as targets, and 
compile them
+
+during test.
+--- orig/CMakeLists.txt
++++ MIOpen-rocm-4.3.0/CMakeLists.txt
+@@ -590,6 +590,9 @@ add_subdirectory(src)
+ if(MIOPEN_BUILD_DRIVER)
+     add_subdirectory(driver)
+ endif()
+-add_subdirectory(test)
++option(BUILD_TESTS "Build binaries for tests" OFF)
++if(BUILD_TESTS)
++      add_subdirectory(test)
++endif()
+ add_subdirectory(speedtests)
+ add_subdirectory(utils)
+--- orig/test/CMakeLists.txt
++++ MIOpen-rocm-4.3.0/test/CMakeLists.txt
+@@ -142,7 +142,7 @@ function(add_test_command NAME EXE)
+ endfunction()
+ 
+ function(add_test_executable TEST_NAME)
+-    add_executable (${TEST_NAME} EXCLUDE_FROM_ALL ${ARGN})
++    add_executable (${TEST_NAME} ${ARGN})
+     clang_tidy_check(${TEST_NAME})
+     target_link_libraries(${TEST_NAME} ${CMAKE_THREAD_LIBS_INIT})
+     # Cmake does not add flags correctly for gcc

diff --git 
a/sci-libs/miopen/files/miopen-4.3.0-fix-interface-include-in-HIP_COMPILER_FLAGS.patch
 
b/sci-libs/miopen/files/miopen-4.3.0-fix-interface-include-in-HIP_COMPILER_FLAGS.patch
new file mode 100644
index 00000000000..5c2762a3254
--- /dev/null
+++ 
b/sci-libs/miopen/files/miopen-4.3.0-fix-interface-include-in-HIP_COMPILER_FLAGS.patch
@@ -0,0 +1,17 @@
+The interface inlude directories of hip::device should be included using -I, 
not -isystem;
+
+otherwise compilation at MIOpen runtime will fail due to cstdlib cannot find 
<stdlib.h> or similar errors.
+
+Suggested-by: Yuyi Wang <[email protected]>
+Signed-off-by: Yiyang Wu <[email protected]>
+--- orig/cmake/TargetFlags.cmake
++++ MIOpen-rocm-4.3.0/cmake/TargetFlags.cmake
+@@ -41,7 +41,7 @@ function(target_flags FLAGS TARGET)
+     set(_flags)
+     append_flags(_flags ${TARGET} "INTERFACE_COMPILE_OPTIONS" "")
+     append_flags(_flags ${TARGET} "INTERFACE_COMPILE_DEFINITIONS" "-D")
+-    append_flags(_flags ${TARGET} "INTERFACE_INCLUDE_DIRECTORIES" "-isystem ")
++      append_flags(_flags ${TARGET} "INTERFACE_INCLUDE_DIRECTORIES" "-I ")
+     append_flags(_flags ${TARGET} "INTERFACE_LINK_DIRECTORIES" "-L ")
+     append_flags(_flags ${TARGET} "INTERFACE_LINK_OPTIONS" "")
+     append_link_flags(_flags ${TARGET} "INTERFACE_LINK_LIBRARIES" "")

diff --git a/sci-libs/miopen/files/miopen-4.3.0-no-strip.patch 
b/sci-libs/miopen/files/miopen-4.3.0-no-strip.patch
new file mode 100644
index 00000000000..2d056582106
--- /dev/null
+++ b/sci-libs/miopen/files/miopen-4.3.0-no-strip.patch
@@ -0,0 +1,16 @@
+Don't strip for release. Let portage handle stripping.
+--- orig/CMakeLists.txt
++++ MIOpen-rocm-4.3.0/CMakeLists.txt
+@@ -69,12 +69,6 @@ set(MIOPEN_ENABLE_SQLITE_BACKOFF On CACH
+ option( BUILD_DEV "Build for development only" OFF)
+ 
+ 
+-# Strip symbols for release
+-if(NOT WIN32 AND NOT APPLE)
+-    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s")
+-    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
+-endif()
+-
+ rocm_setup_version(VERSION 2.12.0)
+ 
+ list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake )

diff --git a/sci-libs/miopen/files/miopen-4.3.0-strip-xnack-in-flags.patch 
b/sci-libs/miopen/files/miopen-4.3.0-strip-xnack-in-flags.patch
new file mode 100644
index 00000000000..dc6db68c2af
--- /dev/null
+++ b/sci-libs/miopen/files/miopen-4.3.0-strip-xnack-in-flags.patch
@@ -0,0 +1,18 @@
+if options like :xnack- exists in ${AMDGPU_TARGETS}, CMakeLists cannot handle 
HIP_COMPILER_FLAGS well
+
+the original regex replace should include :+- so xnack- is stripped as well. 
Otherwise clang complation at MIOpen runtime will fail.
+
+Signed-off-by: Yiyang Wu <[email protected]>
+--- orig/CMakeLists.txt
++++ MIOpen-rocm-4.3.0/CMakeLists.txt
+@@ -191,8 +191,8 @@ find_package(hip REQUIRED PATHS /opt/roc
+ message(STATUS "Build with HIP ${hip_VERSION}")
+ target_flags(HIP_COMPILER_FLAGS hip::device)
+ # Remove cuda arch flags
+-string(REGEX REPLACE --cuda-gpu-arch=[a-z0-9]+ "" HIP_COMPILER_FLAGS 
"${HIP_COMPILER_FLAGS}")
+-string(REGEX REPLACE --offload-arch=[a-z0-9]+ "" HIP_COMPILER_FLAGS 
"${HIP_COMPILER_FLAGS}")
++string(REGEX REPLACE --cuda-gpu-arch=[a-z0-9:+-]+ "" HIP_COMPILER_FLAGS 
"${HIP_COMPILER_FLAGS}")
++string(REGEX REPLACE --offload-arch=[a-z0-9:+-]+ "" HIP_COMPILER_FLAGS 
"${HIP_COMPILER_FLAGS}")
+ 
+ # Override HIP version in config.h, if necessary.
+ # The variables set by find_package() can't be overwritten,

diff --git a/sci-libs/miopen/metadata.xml b/sci-libs/miopen/metadata.xml
new file mode 100644
index 00000000000..da47ad0ef39
--- /dev/null
+++ b/sci-libs/miopen/metadata.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM 'http://www.gentoo.org/dtd/metadata.dtd'>
+<pkgmetadata>
+  <maintainer type="project">
+    <email>[email protected]</email>
+  </maintainer>
+  <maintainer type="person">
+    <email>[email protected]</email>
+    <name>Wilfried Holzke</name>
+  </maintainer>
+  <maintainer type="person">
+    <email>[email protected]</email>
+    <name>Yiyang Wu</name>
+  </maintainer>
+</pkgmetadata>

diff --git a/sci-libs/miopen/miopen-4.3.0.ebuild 
b/sci-libs/miopen/miopen-4.3.0.ebuild
new file mode 100644
index 00000000000..3e754480664
--- /dev/null
+++ b/sci-libs/miopen/miopen-4.3.0.ebuild
@@ -0,0 +1,80 @@
+# Copyright 1999-2021 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+inherit cmake
+
+DESCRIPTION="AMD's Machine Intelligence Library"
+HOMEPAGE="https://github.com/ROCmSoftwarePlatform/MIOpen";
+SRC_URI="https://github.com/ROCmSoftwarePlatform/MIOpen/archive/rocm-${PV}.tar.gz
 -> MIOpen-${PV}.tar.gz"
+
+LICENSE="MIT"
+KEYWORDS="~amd64"
+SLOT="0/$(ver_cut 1-2)"
+
+IUSE="debug test"
+RESTRICT="!test? ( test )"
+
+RDEPEND="
+       dev-util/hip:${SLOT}
+       >=dev-db/sqlite-3.17
+       dev-libs/ocl-icd
+       dev-util/rocm-clang-ocl:${SLOT}
+       sci-libs/rocBLAS:${SLOT}
+       >=dev-libs/boost-1.72
+"
+
+DEPEND="${RDEPEND}"
+
+BDEPEND="dev-libs/half:0/1"
+
+S="${WORKDIR}/MIOpen-rocm-${PV}"
+
+PATCHES=(
+       "${FILESDIR}/${PN}-4.2.0-disable-no-inline-boost.patch"
+       "${FILESDIR}/${PN}-4.2.0-gcc11-numeric_limits.patch"
+       "${FILESDIR}/${PN}-4.3.0-strip-xnack-in-flags.patch"
+       
"${FILESDIR}/${PN}-4.3.0-fix-interface-include-in-HIP_COMPILER_FLAGS.patch"
+       "${FILESDIR}/${PN}-4.3.0-enable-test.patch"
+       "${FILESDIR}/${PN}-4.3.0-no-strip.patch"
+)
+
+src_prepare() {
+       sed -e "s:/opt/rocm/llvm:""${EPREFIX}""/usr/lib/llvm/roc/ 
NO_DEFAULT_PATH:" \
+               -e "s:/opt/rocm/hip:""${EPREFIX}""/usr/lib/hip/ 
NO_DEFAULT_PATH:" \
+               -e '/set( MIOPEN_INSTALL_DIR/s:miopen:${CMAKE_INSTALL_PREFIX}:' 
\
+               -e '/set(MIOPEN_SYSTEM_DB_PATH/s:${CMAKE_INSTALL_PREFIX}/::' \
+               -e '/MIOPEN_TIDY_ERRORS ALL/d' \
+               -i CMakeLists.txt || die
+
+       sed -e "/rocm_install_symlink_subdir(\${MIOPEN_INSTALL_DIR})/d" -i 
src/CMakeLists.txt || die
+       sed -e "/add_test/s:--build \${CMAKE_CURRENT_BINARY_DIR}:--build 
${BUILD_DIR}:" -i test/CMakeLists.txt || die
+
+       sed -e 
"s:\${AMD_DEVICE_LIBS_PREFIX}/lib:${EPREFIX}/usr/lib/amdgcn/bitcode:" -i 
cmake/hip-config.cmake || die
+
+       cmake_src_prepare
+}
+
+src_configure() {
+       if ! use debug; then
+               append-cflags "-DNDEBUG"
+               append-cxxflags "-DNDEBUG"
+               CMAKE_BUILD_TYPE="Release"
+       else
+               CMAKE_BUILD_TYPE="Debug"
+       fi
+
+       export CXX="${EPREFIX}/usr/lib/llvm/roc/bin/clang++"
+
+       local mycmakeargs=(
+               -DCMAKE_SKIP_RPATH=ON
+               -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr"
+               -DMIOPEN_BACKEND=HIP
+               -DBoost_USE_STATIC_LIBS=OFF
+               -DBUILD_TESTS=$(usex test ON OFF)
+               ${AMDGPU_TARGETS+-DAMDGPU_TARGETS="${AMDGPU_TARGETS}"}
+       )
+
+       cmake_src_configure
+}

Reply via email to