Skip to content

Commit 74b559a

Browse files
T-Dynamoskuzeyron
andauthored
numpy: enable openblas (#3305)
* numpy: enable openblas * libopenblas: disable dynamic arch * Add doc for numpy --------- Co-authored-by: Mathias Lindström <8863149+kuzeyron@users.noreply.github.com>
1 parent eec8c0a commit 74b559a

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

doc/source/apis.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ https://developer.android.com/reference/android/Manifest.permission
8080
Other common tasks
8181
------------------
8282

83+
Using NumPY
84+
~~~~~~~~~~~
85+
86+
It should work out of the box; just ensure `numpy` is included in your requirements.
87+
If you want better performance, you can also add `libopenblas` to the requirements.
88+
This allows NumPy to use BLAS/LAPACK acceleration, which can significantly improve linear algebra operations.
89+
90+
Keep in mind that `libopenblas` is a fairly large library (~12 MB per architecture),
91+
so it will increase your app size. For example, if you build for 4 architectures,
92+
the APK size may increase by roughly `12 × 4 = 48 MB` (before compression).
93+
8394
Running executables
8495
~~~~~~~~~~~~~~~~~~~
8596

pythonforandroid/recipes/libopenblas/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def build_arch(self, arch):
3333
"-DCMAKE_BUILD_TYPE=Release",
3434
"-DBUILD_SHARED_LIBS=ON",
3535
"-DC_LAPACK=ON",
36+
"-DDYNAMIC_ARCH=0",
3637
"-DTARGET={target}".format(
3738
target={
3839
"arm64-v8a": "ARMV8",

pythonforandroid/recipes/numpy/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class NumpyRecipe(MesonRecipe):
1111
version = "v2.3.0"
1212
url = "git+https://github.com/numpy/numpy"
1313
extra_build_args = ["-Csetup-args=-Dblas=none", "-Csetup-args=-Dlapack=none"]
14+
opt_depends = ["libopenblas"]
1415
need_stl_shared = True
1516
min_ndk_api_support = 24
1617

@@ -41,6 +42,19 @@ def get_recipe_env(self, arch, **kwargs):
4142
"android-build",
4243
"python",
4344
)
45+
blas_dir = join(Recipe.get_recipe("libopenblas", self.ctx
46+
).get_build_dir(arch.arch), "build")
47+
blas_incdir = blas_dir
48+
blas_libdir = join(blas_dir, "lib")
49+
env["CXXFLAGS"] += f" -I{blas_incdir} -L{blas_libdir}"
50+
51+
if 'libopenblas' in self.ctx.recipe_build_order:
52+
self.extra_build_args = [
53+
"-Csetup-args=-Dblas=auto",
54+
"-Csetup-args=-Dlapack=auto",
55+
"-Csetup-args=-Dallow-noblas=False",
56+
]
57+
4458
return env
4559

4660
def get_hostrecipe_env(self, arch=None):

0 commit comments

Comments
 (0)