blob: ea1baf5d6e12535b4af8e35c3760bcb00677ac7a (
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
|
# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
DISTUTILS_USE_PEP517=setuptools
PYTHON_COMPAT=( python3_{13..14} )
LLVM_COMPAT=( 22 23 )
inherit distutils-r1 llvm-r2
DESCRIPTION="Tensor library and neural network framework with automatic differentiation"
HOMEPAGE="https://tinygrad.org/ https://github.com/tinygrad/tinygrad"
SRC_URI="https://github.com/tinygrad/tinygrad/archive/refs/tags/v${PV}.tar.gz -> ${P}.gh.tar.gz"
# The visualization assets also bundle highlight.js (BSD) and d3 (ISC).
LICENSE="BSD ISC MIT"
SLOT="0"
KEYWORDS="~amd64"
IUSE="cuda numpy opencl"
# The CPU backend invokes Clang at runtime, including for its worker kernels.
RDEPEND="
$(llvm_gen_dep 'llvm-core/clang:${LLVM_SLOT}')
cuda? ( dev-util/nvidia-cuda-toolkit )
numpy? ( dev-python/numpy[${PYTHON_USEDEP}] )
opencl? ( virtual/opencl )
"
BDEPEND="
>=dev-python/setuptools-77[${PYTHON_USEDEP}]
"
EPYTEST_PLUGINS=()
EPYTEST_XDIST=1
distutils_enable_tests pytest
python_prepare_all() {
distutils-r1_python_prepare_all
# Slotted Clang is not necessarily available as /usr/bin/clang.
# Keep the upstream CC environment override for callers that need it.
sed -i \
-e "s@getenv(\"CC\", 'clang')@getenv(\"CC\", '${EPREFIX}/usr/lib/llvm/${LLVM_SLOT}/bin/clang')@" \
tinygrad/runtime/support/compiler_cpu.py || die
}
python_test() {
local -x DEV=CPU
local -x CC="$(get_llvm_prefix -b)/bin/clang"
local -x XDG_CACHE_HOME="${T}/cache-${EPYTHON}"
# Self-contained tensor, autograd, JIT, and dtype tests. The full suite
# additionally needs GPUs, model downloads, and other ML frameworks.
epytest test/test_tiny.py test/null/test_dtype.py
}
pkg_postinst() {
elog "Use DEV=CPU to select the CPU backend explicitly."
elog "GPU backends need compatible hardware and runtime libraries."
elog "See https://docs.tinygrad.org/runtime/ for backend configuration."
}
|