summaryrefslogtreecommitdiff
path: root/llvm-runtimes/offload/offload-19.1.6.ebuild
blob: 7c7f2f70cb2cca41e8a9ce10d2d7082a5232bed2 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

PYTHON_COMPAT=( python3_{10..13} )
inherit cmake flag-o-matic llvm.org python-any-r1 toolchain-funcs

DESCRIPTION="OpenMP offloading support"
HOMEPAGE="https://openmp.llvm.org"

LICENSE="Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )"
SLOT="0/${LLVM_SOABI}"
KEYWORDS="~amd64 ~arm64"
IUSE="+debug ompt test llvm_targets_AMDGPU llvm_targets_NVPTX"
RESTRICT="!test? ( test )"

RDEPEND="
	dev-libs/libffi:=
	~llvm-core/llvm-${PV}
	~llvm-runtimes/openmp-${PV}[ompt?]
	llvm_targets_AMDGPU? ( dev-libs/rocr-runtime:= )
"
DEPEND="
	${RDEPEND}
"
# tests:
# - dev-python/lit provides the test runner
# - llvm-core/llvm provide test utils (e.g. FileCheck)
# - llvm-core/clang provides the compiler to run tests
BDEPEND="
	dev-lang/perl
	virtual/pkgconfig
	llvm_targets_AMDGPU? ( llvm-core/clang )
	llvm_targets_NVPTX? ( llvm-core/clang )
	test? (
		${PYTHON_DEPS}
		$(python_gen_any_dep '
			dev-python/lit[${PYTHON_USEDEP}]
		')
		llvm-core/clang
	)
"
# TODO: can it be fixed to compile with gcc?
BDEPEND+="
	llvm-core/clang
"

LLVM_COMPONENTS=( offload cmake runtimes/cmake )
LLVM_TEST_COMPONENTS=( openmp/cmake )
llvm.org_set_globals

pkg_pretend() {
	if [[ ${LLVM_ALLOW_GPU_TESTING} ]]; then
		ewarn "LLVM_ALLOW_GPU_TESTING set.  This package will run tests against your"
		ewarn "GPU if it is supported.  Note that these tests may be flaky, fail or"
		ewarn "hang, or even cause your GPU to crash (requiring a reboot)."
	fi
}

python_check_deps() {
	python_has_version "dev-python/lit[${PYTHON_USEDEP}]"
}

pkg_setup() {
	if use test; then
		python-any-r1_pkg_setup
	fi
}

src_configure() {
	# TODO
	local -x CC=${CHOST}-clang
	local -x CXX=${CHOST}-clang++
	strip-unsupported-flags

	# LLVM_ENABLE_ASSERTIONS=NO does not guarantee this for us, #614844
	use debug || local -x CPPFLAGS="${CPPFLAGS} -DNDEBUG"

	local libdir="$(get_libdir)"
	local ffi_cflags=$($(tc-getPKG_CONFIG) --cflags-only-I libffi)
	local ffi_ldflags=$($(tc-getPKG_CONFIG) --libs-only-L libffi)
	local plugins="host"
	local gpus=
	local build_devicertl=FALSE

	if has "${CHOST%%-*}" aarch64 powerpc64le x86_64; then
		if use llvm_targets_AMDGPU; then
			plugins+=";amdgpu"
			build_devicertl=TRUE
			gpus+=";gfx700;gfx701;gfx801;gfx803;gfx900;gfx902;gfx906"
			gpus+=";gfx908;gfx90a;gfx90c;gfx940;gfx941;gfx942"
			gpus+=";gfx1010;gfx1030;gfx1031;gfx1032;gfx1033"
			gpus+=";gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102"
			gpus+=";gfx1103;gfx1150;gfx1151;gfx1152"
		fi
		if use llvm_targets_NVPTX; then
			plugins+=";cuda"
			build_devicertl=TRUE
			gpus+=";sm_35;sm_37;sm_50;sm_52;sm_53;sm_60;sm_61;sm_62"
			gpus+=";sm_70;sm_72;sm_75;sm_80;sm_86;sm_87;sm_89;sm_90"
		fi
	fi

	local mycmakeargs=(
		-DLLVM_ROOT="${ESYSROOT}/usr/lib/llvm/${LLVM_MAJOR}"

		-DOFFLOAD_LIBDIR_SUFFIX="${libdir#lib}"
		-DLIBOMPTARGET_PLUGINS_TO_BUILD="${plugins}"
		-DLIBOMPTARGET_OMPT_SUPPORT="$(usex ompt)"
		-DLIBOMPTARGET_BUILD_DEVICERTL_BCLIB="${build_devicertl}"

		# this breaks building static target libs
		-DBUILD_SHARED_LIBS=OFF

		-DFFI_INCLUDE_DIR="${ffi_cflags#-I}"
		-DFFI_LIBRARY_DIR="${ffi_ldflags#-L}"
	)

	[[ ! ${LLVM_ALLOW_GPU_TESTING} ]] && mycmakeargs+=(
		# prevent trying to access the GPU
		-DLIBOMPTARGET_AMDGPU_ARCH=LIBOMPTARGET_AMDGPU_ARCH-NOTFOUND
		-DLIBOMPTARGET_NVPTX_ARCH=LIBOMPTARGET_NVPTX_ARCH-NOTFOUND
	)
	[[ -n ${gpus} ]] && mycmakeargs+=(
		-DLIBOMPTARGET_DEVICE_ARCHITECTURES="${gpus}"
	)
	use test && mycmakeargs+=(
		# this project does not use standard LLVM cmake macros
		-DOPENMP_LLVM_LIT_EXECUTABLE="${EPREFIX}/usr/bin/lit"
		-DOPENMP_LIT_ARGS="$(get_lit_flags)"

		-DOPENMP_TEST_C_COMPILER="$(type -P "${CHOST}-clang")"
		-DOPENMP_TEST_CXX_COMPILER="$(type -P "${CHOST}-clang++")"
	)

	cmake_src_configure

	if [[ -z ${gpus} ]]; then
		# clang requires libomptarget.devicertl.a, but it can be empty
		> "${BUILD_DIR}"/libomptarget.devicertl.a || die
	fi
}

src_test() {
	# respect TMPDIR!
	local -x LIT_PRESERVES_TMP=1

	cmake_build check-offload
}

src_install() {
	cmake_src_install

	if [[ ! -f ${ED}/usr/$(get_libdir)/libomptarget.devicertl.a ]]
	then
		dolib.a "${BUILD_DIR}"/libomptarget.devicertl.a
	fi
}