Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM 18 #123

Merged
merged 36 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
bd60141
gh: bump code version
csegarragonz Feb 9, 2024
1158e8b
faasmtools: bump llvm version
csegarragonz Feb 9, 2024
2aa9661
llvm: changes for latest wasi-libc and wasi-sdk
csegarragonz Feb 12, 2024
6afffa4
llvm: install libclang_rt.builitins-wasm32.a
csegarragonz Feb 13, 2024
9969423
cmake: change system name from Wasm to WASI to align with wasi-sdk
csegarragonz Feb 13, 2024
a61d8b0
faasmtools: enable linker feature sign extension as it is the default…
csegarragonz Feb 13, 2024
852fc4a
libs: install in <sysroot>/lib/wasm32-wasi and copy imports appropria…
csegarragonz Feb 13, 2024
53f6567
docker: enable some features
csegarragonz Feb 13, 2024
4c65d67
libs: install libraries and headers in the right location
csegarragonz Feb 13, 2024
29403d4
llvm: fix libclanv_rt.builitins installation
csegarragonz Feb 13, 2024
f7fe16b
mpi: more fixes to the cmake file
csegarragonz Feb 13, 2024
65cc765
wasi: attempt at having two different targets for threads and non-thr…
csegarragonz Feb 13, 2024
0f0125d
func: comment out temporarily disabled functions
csegarragonz Feb 15, 2024
4242785
func: move threaded functions to separate top-level directory
csegarragonz Feb 16, 2024
d69921e
tasks: configurable compilation for different targets
csegarragonz Feb 16, 2024
47be01e
threads: support for pthread apis
csegarragonz Feb 16, 2024
0b67978
cpython: changes to make cpython build work
csegarragonz Feb 19, 2024
022ab93
llvm: add c compiler target flag for compiler-rt build
csegarragonz Feb 19, 2024
eaaf4d5
libs: fix use of (auto)conf with different sysroots
csegarragonz Feb 19, 2024
6cf9946
more fixes
csegarragonz Feb 19, 2024
ca0d78e
faasmtools: change default target when building a threaded application
csegarragonz Feb 20, 2024
2ca4ee6
llvm: bump to version 18 rc2 to fix the frontend bug with openmp
csegarragonz Feb 20, 2024
17e844e
llvm: no harm in using clang-18 to build llvm-18
csegarragonz Feb 20, 2024
676ce38
llvm: use clang-17 for native compilation
csegarragonz Feb 20, 2024
5a2ec10
nits: fix python formatting
csegarragonz Feb 20, 2024
c785471
nits: fix cpp formatting
csegarragonz Feb 20, 2024
1460297
nit: run python formatting
csegarragonz Feb 21, 2024
4b6e62f
func: build all threads func
csegarragonz Feb 21, 2024
27aae15
gha: skip code formatting with clang-format-17
csegarragonz Feb 21, 2024
89c98da
clang-format: fix formatting after llvm bump
csegarragonz Mar 1, 2024
8d5c4a9
nits: clang-format passing with llvm 17
csegarragonz Mar 4, 2024
e42390a
tasks(libs): build threads/non-threads in different directories
csegarragonz Mar 5, 2024
bfad3a8
docker: fix strange libfaasm overwrite
csegarragonz Mar 5, 2024
731744f
funcs: set the threads target when appropriate
csegarragonz Mar 5, 2024
1e23e89
nits: self-review
csegarragonz Mar 12, 2024
16b97f2
libffi: fix build by passing --host flag to configure
csegarragonz Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tasks: configurable compilation for different targets
  • Loading branch information
csegarragonz committed Feb 16, 2024
commit d69921e69fb5ab8930c8cac028b30827ab7cca15
52 changes: 39 additions & 13 deletions faasmtools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
FAASM_NATIVE_DIR = join(FAASM_LOCAL_DIR, "native")
FAASM_CMAKE_ROOT = "/usr/share/cmake-3.24"
WASM_SYSROOT = join(FAASM_LOCAL_DIR, "llvm-sysroot")
WASM_HEADER_INSTALL = "{}/include/wasm32-wasi".format(WASM_SYSROOT)
WASM_LIB_INSTALL = "{}/lib/wasm32-wasi".format(WASM_SYSROOT)
WASM_TOOLCHAIN_ROOT = join(FAASM_LOCAL_DIR, "toolchain")
WASM_TOOLCHAIN_TOOLS = join(WASM_TOOLCHAIN_ROOT, "tools")
WASM_TOOLCHAIN_BIN = join(WASM_TOOLCHAIN_ROOT, "bin")
Expand All @@ -38,6 +36,7 @@
WASM_LDXX = WASM_CXX

# Host triple
# TODO: remove this?
WASM_BUILD = "wasm32"
WASM_HOST = "wasm32-unknown-wasi"
WASM_HOST_STATIC = "wasm32-wasi"
Expand Down Expand Up @@ -73,7 +72,7 @@
# https://reviews.llvm.org/D59281
WASM_CFLAGS = [
"-O3",
"-mno-atomics",
# "-mno-atomics",
"-msimd128",
"--sysroot={}".format(WASM_SYSROOT),
"-m32",
Expand Down Expand Up @@ -142,7 +141,6 @@
"-Xlinker --export={}".format(FAASM_WASM_CTORS_FUNC_NAME),
"-Xlinker --export=__stack_pointer",
"-Xlinker --max-memory={}".format(FAASM_WASM_MAX_MEMORY),
"-Xlinker --features=bulk-memory,mutable-globals,sign-ext,simd128",
"-Wl,-z,stack-size={} -Wl".format(FAASM_WASM_STACK_SIZE),
]

Expand Down Expand Up @@ -190,7 +188,7 @@
# depending on the build type variables target
# WARNING: do NOT import this method directly, instead use the getter method:
# get_faasm_build_env_dict
FAASM_BUILD_ENV_DICT = {
_FAASM_BUILD_ENV_DICT = {
"CMAKE_ROOT": FAASM_CMAKE_ROOT,
"FAASM_NATIVE_INSTALL_DIR": FAASM_NATIVE_DIR,
"FAASM_WASM_MAKE_TOOLCHAIN_FILE": MAKE_TOOLCHAIN_FILE,
Expand All @@ -203,8 +201,6 @@
"FAASM_WASM_HOST_STATIC": WASM_HOST_STATIC,
"FAASM_WASM_HOST_UNKNOWN": WASM_HOST_UNKNOWN,
"FAASM_WASM_INSTALL_DIR": WASM_TOOLCHAIN_BIN,
"FAASM_WASM_HEADER_INSTALL_DIR": WASM_HEADER_INSTALL,
"FAASM_WASM_LIB_INSTALL_DIR": WASM_LIB_INSTALL,
"FAASM_WASM_SYSROOT": WASM_SYSROOT,
"FAASM_WASM_CFLAGS": " ".join(WASM_CFLAGS),
"FAASM_WASM_CFLAGS_SHARED": " ".join(WASM_CFLAGS_SHARED),
Expand Down Expand Up @@ -233,16 +229,46 @@ def get_faasm_build_env_dict(is_threads=False):
This method returns the right set of environment variables needed to use
our toolchain file as well as most cross-compilation scripts in Faasm.
"""
build_env_dicts = FAASM_BUILD_ENV_DICT
build_env_dicts = _FAASM_BUILD_ENV_DICT
if is_threads:
build_env_dicts["FAASM_WASM_TRIPLE"] = "wasm32-wasi-threads"
wasm_triple = "wasm32-wasi-threads"
build_env_dicts["FAASM_WASM_TRIPLE"] = wasm_triple
build_env_dicts["FAASM_WASM_CFLAGS"] += " -pthread"
build_env_dicts["FAASM_WASM_CXXFLAGS"] += " -pthread"
build_env_dicts["FAASM_WASM_EXE_LINKER_FLAGS"] += " -Wl,--import-memory"
build_env_dicts["FAASM_WASM_EXE_LINKER_FLAGS"] += " -Wl,--export-memory"
linker_features = [
"atomics",
"bulk-memory",
"mutable-globals",
"sign-ext",
"simd128",
]
build_env_dicts[
"FAASM_WASM_EXE_LINKER_FLAGS"
] += " -Wl,--import-memory"
build_env_dicts[
"FAASM_WASM_EXE_LINKER_FLAGS"
] += " -Wl,--export-memory"
else:
build_env_dicts["FAASM_WASM_TRIPLE"] = "wasm32-wasi"

wasm_triple = "wasm32-wasi"
build_env_dicts["FAASM_WASM_TRIPLE"] = wasm_triple
linker_features = [
"bulk-memory",
"mutable-globals",
"sign-ext",
"simd128",
]

build_env_dicts["FAASM_WASM_HEADER_INSTALL_DIR"] = join(
WASM_SYSROOT, "include", wasm_triple
)
build_env_dicts["FAASM_WASM_LIB_INSTALL_DIR"] = join(
WASM_SYSROOT, "lib", wasm_triple
)
build_env_dicts[
"FAASM_WASM_EXE_LINKER_FLAGS"
] += " -Xlinker --features={}".format(",".join(linker_features))

return build_env_dicts


def get_dict_as_cmake_vars(env_dict):
Expand Down
8 changes: 5 additions & 3 deletions faasmtools/compile_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from faasmtools.build import (
CMAKE_TOOLCHAIN_FILE,
FAASM_BUILD_ENV_DICT,
get_faasm_build_env_dict,
)
from faasmtools.env import WASM_DIR
from os import environ, makedirs
Expand All @@ -9,7 +9,9 @@
from subprocess import run


def wasm_cmake(src_dir, build_dir, target, clean=False, debug=False, is_threads=False):
def wasm_cmake(
src_dir, build_dir, target, clean=False, debug=False, is_threads=False
):
cmake_build_type = "Debug" if debug else "Release"

if exists(build_dir) and clean:
Expand All @@ -28,7 +30,7 @@ def wasm_cmake(src_dir, build_dir, target, clean=False, debug=False, is_threads=
print(build_cmd)

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

res = run(build_cmd, shell=True, cwd=build_dir, env=work_env)
if res.returncode != 0:
Expand Down
17 changes: 11 additions & 6 deletions tasks/clapack.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from copy import copy
from faasmtools.env import THIRD_PARTY_DIR, USABLE_CPUS
from faasmtools.build import (
FAASM_BUILD_ENV_DICT,
WASM_SYSROOT,
WASM_LIB_INSTALL,
get_faasm_build_env_dict,
)
from invoke import task
from os import environ, remove
Expand Down Expand Up @@ -37,7 +36,7 @@ def build(ctx, clean=False, shared=False):
# Set up environment to specify whether we're building static or shared
env = copy(environ)
env.update({"LIBEXT": ".so" if shared else ".a"})
env.update(FAASM_BUILD_ENV_DICT)
env.update(get_faasm_build_env_dict())

# Make libf2c first (needed by others)
run(
Expand Down Expand Up @@ -70,14 +69,20 @@ def uninstall(ctx):
"""
Removes all installed files
"""
for headers_dir in HEADERS_DIRS:
build_env = get_faasm_build_env_dict()

for headers_dir in build_env["FAASM_WASM_HEADER_INSTALL_DIR"]:
if exists(headers_dir):
print("Removing headers {}".format(headers_dir))
rmtree(headers_dir)

for lib_name in INSTALLED_LIBS:
static_path = join(WASM_LIB_INSTALL, "{}.a".format(lib_name))
shared_path = join(WASM_LIB_INSTALL, "{}.so".format(lib_name))
static_path = join(
build_env["FAASM_WASM_LIB_INSTALL_DIR"], "{}.a".format(lib_name)
)
shared_path = join(
build_env["FAASM_WASM_LIB_INSTALL_DIR"], "{}.so".format(lib_name)
)

if exists(static_path):
print("Removing static lib {}".format(static_path))
Expand Down
18 changes: 16 additions & 2 deletions tasks/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ def compile(ctx, user, func, clean=False, debug=False, native=False):
)
else:
# Build the function (gets written to the build dir)
wasm_cmake(FUNC_DIR, FUNC_BUILD_DIR, func, clean, debug, _is_threaded_func(user, func))
wasm_cmake(
FUNC_DIR,
FUNC_BUILD_DIR,
func,
clean,
debug,
_is_threaded_func(user, func),
)

# Copy into place
_copy_built_function(user, func)
Expand Down Expand Up @@ -153,7 +160,14 @@ def user(ctx, user, clean=False, debug=False):
"""
# Build all funcs for this user (will fail if any builds fail)
target = "{}_all_funcs".format(user)
wasm_cmake(FUNC_DIR, FUNC_BUILD_DIR, target, clean, debug, _is_threaded_func(user, ""))
wasm_cmake(
FUNC_DIR,
FUNC_BUILD_DIR,
target,
clean,
debug,
_is_threaded_func(user, ""),
)

funcs = _get_all_user_funcs(user)
for f in funcs:
Expand Down
15 changes: 10 additions & 5 deletions tasks/lib.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from faasmtools.build import (
CMAKE_TOOLCHAIN_FILE,
FAASM_BUILD_ENV_DICT,
FAASM_NATIVE_DIR,
WASM_LIB_INSTALL,
get_faasm_build_env_dict,
)
from faasmtools.env import LLVM_VERSION, PROJ_ROOT
from os.path import exists, join
Expand All @@ -11,12 +10,18 @@
from subprocess import run


def build_faasm_lib(subdir, clean=False, native=False, shared=False):
def build_faasm_lib(
subdir, clean=False, native=False, shared=False, threads=False
):
"""
Builds one of the libraries included in this repo
"""
work_dir = join(PROJ_ROOT, subdir)
install_dir = FAASM_NATIVE_DIR if native else WASM_LIB_INSTALL
install_dir = (
FAASM_NATIVE_DIR
if native
else get_faasm_build_env_dict(threads)["FAASM_WASM_LIB_INSTALL_DIR"]
)

if native and shared:
build_dir = "build-native-shared"
Expand Down Expand Up @@ -62,7 +67,7 @@ def build_faasm_lib(subdir, clean=False, native=False, shared=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=threads))
run(build_cmd_str, shell=True, cwd=build_dir, check=True, env=work_env)

run("ninja", shell=True, cwd=build_dir, check=True)
Expand Down
6 changes: 4 additions & 2 deletions tasks/libfaasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@


@task(default=True)
def build(ctx, clean=False, native=False, shared=False):
def build(ctx, clean=False, native=False, shared=False, threads=False):
"""
Builds faasm C/C++ lib
"""
build_faasm_lib("libfaasm", clean=clean, native=native, shared=shared)
build_faasm_lib(
"libfaasm", clean=clean, native=native, shared=shared, threads=threads
)
4 changes: 2 additions & 2 deletions tasks/libfake.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from faasmtools.build import (
CMAKE_TOOLCHAIN_FILE,
FAASM_BUILD_ENV_DICT,
WASM_SYSROOT,
get_faasm_build_env_dict,
)
from faasmtools.env import PROJ_ROOT, FAASM_RUNTIME_ROOT
from invoke import task
Expand Down Expand Up @@ -35,7 +35,7 @@ def fake(ctx, clean=False):
]

work_env = environ.copy()
work_env.update(FAASM_BUILD_ENV_DICT)
work_env.update(get_faasm_build_env_dict())
run(
" ".join(build_cmd),
shell=True,
Expand Down
23 changes: 11 additions & 12 deletions tasks/libffi.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
from faasmtools.build import (
build_config_cmd,
get_faasm_build_env_dict,
run_autotools,
WASM_SYSROOT,
WASM_LIB_INSTALL,
)
from faasmtools.env import THIRD_PARTY_DIR, USABLE_CPUS, PROJ_ROOT
from faasmtools.env import THIRD_PARTY_DIR, USABLE_CPUS
from invoke import task
from os.path import join, exists
from subprocess import run

LIBFFI_DIR = join(THIRD_PARTY_DIR, "libffi")
LIBFFI_LIBS_DIR = join(LIBFFI_DIR, "wasm32-unknown-wasi")


@task(default=True)
def build(ctx, clean=False):
def build(ctx, clean=False, threads=False):
"""
Builds libffi
"""
Expand All @@ -25,10 +23,14 @@ def build(ctx, clean=False):
run_autotools(LIBFFI_DIR)

# Configure
build_env = get_faasm_build_env_dict(threads)
configure_cmd = build_config_cmd(
[
"./configure",
"--prefix={}".format(WASM_SYSROOT),
"--includedir={}".format(
build_env["FAASM_WASM_HEADER_INSTALL_DIR"]
),
"--libdir={}".format(build_env["FAASM_WASM_LIB_INSTALL_DIR"]),
"--disable-multi-os-directory",
"--disable-docs",
],
Expand All @@ -44,14 +46,11 @@ def build(ctx, clean=False):
run("make install", shell=True, check=True, cwd=LIBFFI_DIR)

# Move lib into correct install dir
for lib_name in ["libffi.a", "libffi.la"]:
src_lib = join(WASM_SYSROOT, "lib", lib_name)
dest_lib = join(WASM_LIB_INSTALL, lib_name)
print("Moving {} to {}".format(src_lib, dest_lib))
run("mv {} {}".format(src_lib, dest_lib), shell=True, check=True)

# Copy imports into place
# TODO: do we need these?
"""
src_imports = join(PROJ_ROOT, "sysroot_extras", "libffi.imports")
dest_imports = join(WASM_LIB_INSTALL, "libffi.imports")
print("Copying {} to {}".format(src_imports, dest_imports))
run("cp {} {}".format(src_imports, dest_imports), check=True, shell=True)
"""
Loading
Loading