Skip to content

Commit

Permalink
tasks: change usage of dict for getter method
Browse files Browse the repository at this point in the history
  • Loading branch information
csegarragonz committed Feb 20, 2024
1 parent e8b1e62 commit 68d999f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 68 deletions.
40 changes: 17 additions & 23 deletions tasks/ffmpeg.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
from faasmtools.build import (
WASM_SYSROOT,
WASM_LIB_INSTALL,
WASM_CC,
WASM_CXX,
WASM_AR,
WASM_NM,
WASM_RANLIB,
WASM_CFLAGS,
WASM_LDFLAGS,
)
from faasmtools.build import get_faasm_build_env_dict
from invoke import task
from os.path import join
from subprocess import run
Expand All @@ -25,12 +15,14 @@ def ffmpeg(ctx, clean=False):
if clean:
run("make clean", shell=True, cwd=ffmpeg_dir, check=True)

build_env = get_faasm_build_env_dict()

# List of flags inspired from the github project:
# https://github.com/ffmpegwasm/ffmpeg.wasm-core
configure_cmd = [
"./configure",
"--prefix={}".format(WASM_SYSROOT),
"--libdir={}".format(WASM_LIB_INSTALL),
"--prefix={}".format(build_env["FAASM_WASM_SYSROOT"]),
"--libdir={}".format(build_env["FAASM_WASM_HEADER_INSTALL_DIR"]),
"--target-os=none",
"--arch=x86_32",
"--enable-cross-compile",
Expand All @@ -41,16 +33,18 @@ def ffmpeg(ctx, clean=False):
"--disable-programs",
"--disable-doc",
"--disable-zlib",
"--extra-cflags='{}'".format(" ".join(WASM_CFLAGS)),
"--extra-cxxflags='{}'".format(" ".join(WASM_CFLAGS)),
"--extra-ldflags='{}'".format(" ".join(WASM_LDFLAGS)),
"--nm={}".format(WASM_NM),
"--ar={}".format(WASM_AR),
"--ranlib={}".format(WASM_RANLIB),
"--cc={}".format(WASM_CC),
"--cxx={}".format(WASM_CXX),
"--objcc={}".format(WASM_CC),
"--dep-cc={}".format(WASM_CC),
"--extra-cflags='{}'".format(build_env["FAASM_WASM_CFLAGS"]),
"--extra-cxxflags='{}'".format(build_env["FAASM_WASM_CXXFLAGS"]),
"--extra-ldflags='{}'".format(
build_env["FAASM_WASM_STATIC_LINKER_FLAGS"]
),
"--nm={}".format(build_env["FAASM_WASM_NM"]),
"--ar={}".format(build_env["FAASM_WASM_AR"]),
"--ranlib={}".format(build_env["FAASM_WASM_RANLIB"]),
"--cc={}".format(build_env["FAASM_WASM_CC"]),
"--cxx={}".format(build_env["FAASM_WASM_CXX"]),
"--objcc={}".format(build_env["FAASM_WASM_CC"]),
"--dep-cc={}".format(build_env["FAASM_WASM_CC"]),
]

configure_cmd = " ".join(configure_cmd)
Expand Down
17 changes: 15 additions & 2 deletions tasks/kernels.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from faasmtools.build import FAASM_BUILD_ENV_DICT
from faasmtools.build import get_faasm_build_env_dict
from faasmtools.compile_util import wasm_copy_upload
from invoke import task
from os import environ, makedirs
Expand Down Expand Up @@ -33,7 +33,7 @@ def build(ctx, clean=False, native=False):

work_env = environ.copy()
if not native:
work_env.update(FAASM_BUILD_ENV_DICT)
work_env.update(get_faasm_build_env_dict())
work_env["FAASM_WASM"] = "on"
else:
work_env.update(
Expand Down Expand Up @@ -78,6 +78,19 @@ def build(ctx, clean=False, native=False):
# Clean MPI wasm files
run("make clean", shell=True, check=True, cwd=kernels_dir)

# Re-start the work environment to use the wasm32-wasi-threads target
work_env = environ.copy()
if not native:
work_env.update(get_faasm_build_env_dict(is_threads=True))
work_env["FAASM_WASM"] = "on"
else:
work_env.update(
{
"LD_LIBRARY_PATH": "/usr/local/lib",
"FAASM_WASM": "off",
}
)

# Build the OMP kernels
work_env["FAASM_KERNEL_TYPE"] = "omp"
omp_kernel_targets = [
Expand Down
6 changes: 3 additions & 3 deletions tasks/lammps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from faasmtools.build import CMAKE_TOOLCHAIN_FILE, FAASM_BUILD_ENV_DICT
from faasmtools.build import CMAKE_TOOLCHAIN_FILE, get_faasm_build_env_dict
from faasmtools.compile_util import wasm_copy_upload
from faasmtools.env import LLVM_VERSION
from tasks.env import DEV_FAASM_LOCAL, EXAMPLES_DIR, in_docker
Expand Down Expand Up @@ -61,7 +61,7 @@ def build(
cmake_cmd = " ".join(cmake_cmd)

work_env = environ.copy()
work_env.update(FAASM_BUILD_ENV_DICT)
work_env.update(get_faasm_build_env_dict())

run(cmake_cmd, shell=True, check=True, cwd=build_dir, env=work_env)
run("ninja", shell=True, check=True, cwd=build_dir)
Expand All @@ -80,7 +80,7 @@ def build(
run_docker_build_cmd(
[cmake_cmd, "ninja"],
cwd=in_docker_build_dir,
env=FAASM_BUILD_ENV_DICT,
env=get_faasm_build_env_dict(),
)

if not native:
Expand Down
34 changes: 16 additions & 18 deletions tasks/libpng.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
from faasmtools.build import (
WASM_AR,
WASM_CC,
WASM_CFLAGS,
WASM_LDFLAGS,
WASM_LIB_INSTALL,
WASM_RANLIB,
WASM_SYSROOT,
)
from faasmtools.build import get_faasm_build_env_dict
from invoke import task
from os import listdir, makedirs
from os.path import exists, join
Expand All @@ -24,34 +16,40 @@ def libpng(ctx, clean=False):
if clean:
run("make clean", shell=True, cwd=libpng_dir, check=True)

build_env = get_faasm_build_env_dict()

# 30/01/2022 - SIMD not working with ImageMagick, so we must also not use
# SIMD when building libpng
wasm_cflags_nosimd = WASM_CFLAGS
wasm_cflags_nosimd.remove("-msimd128")
wasm_cflags_nosimd = build_env["FAASM_WASM_CFLAGS"]
wasm_cflags_nosimd = wasm_cflags_nosimd.replace("-msimd128", "")

# Instead of running a complicated configure, we use a simplified makefile
# under `faasm/libpng/scripts/makefile.wasm` to build _only_ libpng
make_cmd = [
"WASM_CC={}".format(WASM_CC),
"WASM_AR={}".format(WASM_AR),
"WASM_RANLIB={}".format(WASM_RANLIB),
"WASM_CC={}".format(build_env["FAASM_WASM_CC"]),
"WASM_AR={}".format(build_env["FAASM_WASM_AR"]),
"WASM_RANLIB={}".format(build_env["FAASM_WASM_RANLIB"]),
"WASM_CFLAGS='{}'".format(" ".join(wasm_cflags_nosimd)),
"WASM_LDFLAGS='{}'".format(" ".join(WASM_LDFLAGS)),
"WASM_SYSROOT={}".format(WASM_SYSROOT),
"WASM_LDFLAGS='{}'".format(
build_env["FAASM_WASM_STATIC_LINKER_FLAGS"]
),
"WASM_SYSROOT={}".format(build_env["FAASM_WASM_SYSROOT"]),
"make -j",
]
make_cmd = " ".join(make_cmd)
run(make_cmd, shell=True, cwd=libpng_dir, check=True)

# Install static library
cp_cmd = "cp {}/libpng.a {}/libpng16.a".format(
libpng_dir, WASM_LIB_INSTALL
libpng_dir, build_env["FAASM_WASM_LIB_INSTALL_DIR"]
)
run(cp_cmd, shell=True, check=True)
print(cp_cmd)

# Install headers
libpng_header_install_dir = join(WASM_SYSROOT, "include", "libpng16")
libpng_header_install_dir = join(
build_env["FAASM_WASM_HEADER_INSTALL_DIR"], "libpng16"
)
if not exists(libpng_header_install_dir):
makedirs(libpng_header_install_dir)
header_files = [
Expand Down
4 changes: 2 additions & 2 deletions tasks/lulesh.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from faasmtools.build import CMAKE_TOOLCHAIN_FILE, FAASM_BUILD_ENV_DICT
from faasmtools.build import CMAKE_TOOLCHAIN_FILE, get_faasm_build_env_dict
from faasmtools.compile_util import wasm_copy_upload
from invoke import task
from os import environ, makedirs
Expand Down Expand Up @@ -47,7 +47,7 @@ def build(ctx, clean=False, native=False):

work_env = environ.copy()
if not native:
work_env.update(FAASM_BUILD_ENV_DICT)
work_env.update(get_faasm_build_env_dict(is_threads=True))

run(cmake_cmd, shell=True, check=True, cwd=build_dir, env=work_env)
run("cmake --build . --target all", shell=True, check=True, cwd=build_dir)
Expand Down
4 changes: 2 additions & 2 deletions tasks/polybench.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from faasmtools.build import CMAKE_TOOLCHAIN_FILE, FAASM_BUILD_ENV_DICT
from faasmtools.build import CMAKE_TOOLCHAIN_FILE, get_faasm_build_env_dict
from faasmtools.compile_util import wasm_copy_upload
from faasmtools.env import LLVM_VERSION
from tasks.env import EXAMPLES_DIR
Expand Down Expand Up @@ -47,7 +47,7 @@ def build(ctx, clean=False, native=False):
cmake_cmd = " ".join(cmake_cmd)

work_env = environ.copy()
work_env.update(FAASM_BUILD_ENV_DICT)
work_env.update(get_faasm_build_env_dict())

run(cmake_cmd, shell=True, check=True, cwd=build_dir, env=work_env)
run(
Expand Down
34 changes: 16 additions & 18 deletions tasks/tensorflow.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
from faasmtools.build import (
BASE_CONFIG_CMD,
WASM_CFLAGS,
WASM_CXXFLAGS,
WASM_HOST,
WASM_LDFLAGS,
WASM_HEADER_INSTALL,
WASM_LIB_INSTALL,
build_config_cmd,
get_faasm_build_env_dict,
)
from invoke import task
from os import cpu_count
Expand All @@ -32,18 +27,17 @@ def lite(ctx, clean=False):
cores = cpu_count()
make_cores = int(cores) - 1

build_env = get_faasm_build_env_dict()
make_target = "lib"
make_cmd = ["make -j {}".format(make_cores)]
make_cmd.extend(BASE_CONFIG_CMD)
make_cmd = build_config_cmd(
build_env,
"make -j {}".format(make_cores),
conf_args=False,
)
make_cmd.extend(
[
'CFLAGS="{} -ftls-model=local-exec"'.format(" ".join(WASM_CFLAGS)),
'CXXFLAGS="{}"'.format(" ".join(WASM_CXXFLAGS)),
'LDFLAGS="{} -Xlinker --max-memory=4294967296"'.format(
" ".join(WASM_LDFLAGS)
),
"MINIMAL_SRCS=",
"TARGET={}".format(WASM_HOST),
"TARGET={}".format(build_env["FAASM_WASM_TRIPLE"]),
"BUILD_WITH_MMAP=false",
'LIBS="-lstdc++"',
'-C "{}"'.format(tf_dir),
Expand All @@ -53,7 +47,9 @@ def lite(ctx, clean=False):

make_cmd.append(make_target)

clean_dir = join(tf_make_dir, "gen", "wasm32-unknown-wasi_x86_64")
clean_dir = join(
tf_make_dir, "gen", "{}_x86_64".format(build_env["FAASM_WASM_TRIPLE"])
)
if clean and exists(clean_dir):
rmtree(clean_dir)

Expand All @@ -63,13 +59,15 @@ def lite(ctx, clean=False):
# Install static library
tf_lib_dir = join(clean_dir, "lib")
cp_cmd = "cp {}/libtensorflow-lite.a {}/libtensorflow-lite.a".format(
tf_lib_dir, WASM_LIB_INSTALL
tf_lib_dir, build_env["FAASM_WASM_LIB_INSTALL_DIR"]
)
print(cp_cmd)
run(cp_cmd, shell=True, check=True)

# Install header files
header_install_dir = join(WASM_HEADER_INSTALL, "tensorflow")
header_install_dir = join(
build_env["FAASM_WASM_HEADER_INSTALL_DIR"], "tensorflow"
)
if exists(header_install_dir):
rmtree(header_install_dir)

Expand Down

0 comments on commit 68d999f

Please sign in to comment.