summaryrefslogtreecommitdiff
path: root/dev-libs/rocm-opencl-runtime/rocm-opencl-runtime-10.1.0-r1.ebuild
blob: 2d253cbb865980cc8bc0593097786e82cca82615 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

ROCM_SKIP_GLOBALS=1
inherit cmake edob flag-o-matic rocm

DESCRIPTION="Radeon Open Compute OpenCL Compatible Runtime"
HOMEPAGE="https://github.com/ROCm/rocm-systems/tree/develop/projects/clr"

SRC_URI="https://github.com/ROCm/rocm-systems/releases/download/therock-${PV%.0}/clr.tar.gz -> rocm-clr-${PV}.tar.gz"
S="${WORKDIR}/clr"

LICENSE="Apache-2.0 MIT"
SLOT="0/$(ver_cut 1-2)"
KEYWORDS="~amd64"
IUSE="debug test"
RESTRICT="!test? ( test )"

RDEPEND="
	dev-libs/rocr-runtime:${SLOT}
	dev-libs/rocm-comgr:${SLOT}
	dev-libs/rocm-device-libs:${SLOT}
	>=virtual/opencl-3
	media-libs/mesa[-opencl]
"
DEPEND="${RDEPEND}"
BDEPEND="
	>=dev-build/rocm-cmake-6.0
	media-libs/glew
	test? ( >=x11-apps/mesa-progs-8.5.0[X] )
"

PATCHES=(
	"${FILESDIR}/${PN}-6.2.4-fix-lib-version.patch"
	"${FILESDIR}/${PN}-10.1.0-aligned-new.patch"
)

src_prepare() {
	# Compatibility with CMake < 3.10 will be removed
	sed -e "/cmake_minimum_required/ s/3\.5/3.10/" \
		-i opencl/khronos/icd/CMakeLists.txt opencl/khronos/headers/opencl2.2/tests/CMakeLists.txt || die

	# Allocate all free memory or a buffer of the maximum allocation size.
	# On APUs this starves other GPU clients (crashing the desktop session) or OOMs.
	cat >> opencl/tests/ocltst/module/runtime/oclruntime.exclude <<-EOF || die
		OCLMemoryInfo
		OCLCreateBuffer
		OCLCreateImage
	EOF

	# rocclr finds glXGetProcAddress via dlsym(RTLD_DEFAULT); expose GL libs of the oclgl module
	sed -e "s/dlopen(m_paths\[i\].c_str(), RTLD_NOW)/dlopen(m_paths[i].c_str(), RTLD_NOW | RTLD_GLOBAL)/" \
		-i opencl/tests/ocltst/env/ocltst.cpp || die

	cmake_src_prepare
}

src_configure() {
	# -Werror=strict-aliasing
	# https://bugs.gentoo.org/856088
	# https://github.com/ROCm/clr/issues/64
	#
	# Do not trust it for LTO either
	append-flags -fno-strict-aliasing
	filter-lto

	use debug && CMAKE_BUILD_TYPE="Debug"
	# upstream release builds have assertions disabled; some are reachable
	# (e.g. Isa::isCompatible on gfx90c), aborting otherwise working programs
	# Bug: https://bugs.gentoo.org/984577
	use debug || append-cppflags -DNDEBUG

	# Fix ld.lld linker error: https://github.com/RadeonOpenCompute/ROCm-OpenCL-Runtime/issues/155
	append-ldflags $(test-flags-CCLD -Wl,--undefined-version)

	# Reported upstream: https://github.com/RadeonOpenCompute/ROCm-OpenCL-Runtime/issues/120
	append-cflags -fcommon

	local mycmakeargs=(
		-Wno-dev
		-DROCM_PATH="${EPREFIX}/usr"
		-DBUILD_TESTS=$(usex test ON OFF)
		-DEMU_ENV=ON
		-DBUILD_ICD=ON
		-DCLR_BUILD_OCL=ON
		-DCMAKE_DISABLE_FIND_PACKAGE_Git=ON
	)
	cmake_src_configure
}

src_install() {
	insinto /etc/OpenCL/vendors
	doins opencl/config/amdocl64.icd

	cd "${BUILD_DIR}"/opencl || die
	insinto /usr/lib64
	doins amdocl/libamdocl64.so*
	doins tools/cltrace/libcltrace.so
}

src_test() {
	check_amdgpu
	cd "${BUILD_DIR}"/tests/ocltst || die
	export OCL_ICD_FILENAMES="${BUILD_DIR}"/opencl/amdocl/libamdocl64.so
	local instruction1="Please start an X server using amdgpu driver (not Xvfb!),"
	local instruction2="and export OCLGL_DISPLAY=\${DISPLAY} OCLGL_XAUTHORITY=\${XAUTHORITY} before reruning the test."
	if [[ -n ${OCLGL_DISPLAY+x} ]]; then
		export DISPLAY=${OCLGL_DISPLAY}
		export XAUTHORITY=${OCLGL_XAUTHORITY}
		ebegin "Running oclgl test under DISPLAY ${OCLGL_DISPLAY}"
		if ! glxinfo | grep "OpenGL vendor string: AMD"; then
			ewarn "${instruction1}"
			ewarn "${instruction2}"
			die "This display does not have AMD OpenGL vendor!"
		fi
		./ocltst -m $(realpath liboclgl.so) -A ogl.exclude
		eend $? || die "oclgl test failed"
	else
		ewarn "${instruction1}"
		ewarn "${instruction2}"
		die "\${OCLGL_DISPLAY} not set."
	fi
	edob ./ocltst -m $(realpath liboclruntime.so) -A oclruntime.exclude
	edob ./ocltst -m $(realpath liboclperf.so) -A oclperf.exclude
}