Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 0 additions & 17 deletions pp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -243,23 +243,6 @@ cc_static_library(
],
)

cc_library(
name = "entrypoint_init",
srcs = glob(["entrypoint/init/*.cpp"]),
hdrs = glob([
"entrypoint/init/**/*.h",
"entrypoint/init/**/*.hpp",
]),
linkstatic = True,
)

cc_static_library(
name = "entrypoint_init_aio",
deps = [
":entrypoint_init",
],
)

cc_library(
name = "performance_tests_headers",
hdrs = glob(["performance_tests/**/*.h"]),
Expand Down
27 changes: 7 additions & 20 deletions pp/entrypoint/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,14 @@ ifeq ($(platform),aarch64)
platform := arm64
endif

# Here we specifie supported flavors per platform
# Baseline march per platform used for the single built variant.
#
# All flavors should be valid march option.
# First flavor in list is used as minimal fallback, so it will be system requirement.
# Runtime detection flavor is placed in entrypoint.cpp.template/mk.
# It should be a valid march option and acts as the system requirement for the binary.
amd64_flavors := k8 nehalem haswell
arm64_flavors := armv8-a armv8-a+crc
flavors := $($(platform)_flavors)
generic_flavor := $(firstword $(flavors))

# Since arm64 flavors uses special characters such as + and - in the name,
# in some cases we have to escape them.
escape = echo $(1) | sed 's/[^a-zA-Z0-9]/_/g'
make_escape = $(shell $(call escape,$(1)))
amd64_escaped_flavors := $(foreach flavor,$(amd64_flavors),$(call make_escape,$(flavor)))
arm64_escaped_flavors := $(foreach flavor,$(arm64_flavors),$(call make_escape,$(flavor)))
escaped_flavors := $($(platform)_escaped_flavors)

include entrypoint.cpp.mk
include build.mk

.PHONY: help
Expand All @@ -61,23 +50,21 @@ help: ## Show this message
@grep -hE '^[a-zA-Z_-]+\?=.*## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = " *(?=|##) *"}; {printf "\033[33m%-20s\033[0m %s \033[30m(default %s)\033[0m\n", $$1, $$3, $$2}'

.PHONY: all
all: $(result_dir)/entrypoint.h ## Generate archive with flavored code and runtime init
all: $(result_dir)/$(platform)_entrypoint_init_aio_$(result_suffix).a
all: $(prefixed_archives)
all: $(result_dir)/entrypoint.h ## Generate archive with entrypoint code
all: $(result_dir)/$(platform)_entrypoint_aio_$(result_suffix).a

.PHONY: clean
clean: ## Remove all generated content
@-rm -rf init $(build_dir) $(result_dir)
@-rm -rf $(build_dir) $(result_dir)

.PHONY: install
install: $(result_dir)/entrypoint.h ## Copy resulting generated files to destination $(install_dir)
install: $(result_dir)/$(platform)_entrypoint_init_aio_$(result_suffix).a
install: $(prefixed_archives)
install: $(result_dir)/$(platform)_entrypoint_aio_$(result_suffix).a
@install $^ $(install_dir)

# Shared type/layout contracts that the Go side reads via cgo (e.g. Sizeof_* macros).
type_headers := types/go_constants.h

$(result_dir)/entrypoint.h: $(type_headers) $(headers) entrypoint.h.template ## Concat all headers in one
$(result_dir)/entrypoint.h: $(type_headers) $(headers) ## Concat all headers in one
@mkdir -p ${@D}
@cat $^ > $@
25 changes: 20 additions & 5 deletions pp/entrypoint/bridge/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <malloc.h>
#endif

#include <cstring>

#include "primitives/go_slice.h"

extern "C" void prompp_free_bytes(void* args) {
Expand All @@ -13,12 +15,25 @@ extern "C" void prompp_free_bytes(void* args) {
static_cast<Slice*>(args)->~Slice();
}

extern "C" void je_jemalloc_constructor(void);

extern "C" void prompp_jemalloc_init() {
#if JEMALLOC_AVAILABLE
je_jemalloc_constructor();
namespace {
#if defined(__x86_64__) || defined(_M_AMD64)
constexpr const char* kPromppFlavor = "k8";
#elif defined(__aarch64__) || defined(_M_ARM64)
constexpr const char* kPromppFlavor = "armv8-a";
#else
constexpr const char* kPromppFlavor = "unknown";
#endif
} // namespace

extern "C" void prompp_get_flavor(void* res) {
struct Result {
const char* data;
size_t len;
};

auto* out = static_cast<Result*>(res);
out->data = kPromppFlavor;
out->len = std::strlen(kPromppFlavor);
}

extern "C" void prompp_mem_info(void* res) {
Expand Down
9 changes: 9 additions & 0 deletions pp/entrypoint/bridge/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ void prompp_mem_info(void* res);
*/
void prompp_dump_memory_profile(void* args, void* res);

/**
* @brief return build architecture flavor
*
* @param res {
* flavor string
* }
*/
void prompp_get_flavor(void* res);

#ifdef __cplusplus
}
#endif
39 changes: 7 additions & 32 deletions pp/entrypoint/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,12 @@ ifeq ($(asan),true)
result_suffix := $(result_suffix)_asan
endif

archives := $(patsubst %, $(build_dir)/$(platform)_%_entrypoint_aio.a, $(escaped_flavors))
prefixed_archives := $(patsubst $(build_dir)/%.a, $(result_dir)/%_prefixed_$(result_suffix).a, $(archives))

$(result_dir)/$(platform)_entrypoint_init_aio_$(result_suffix).a: init/entrypoint.cpp
@mkdir -p ${@D}
@$(bazel_in_root);\
$(call bazel_build_march,$(generic_flavor)) -- //:entrypoint_init_aio
@cp -f ../bazel-bin/entrypoint_init_aio.a $@

# Build flavoured prefixed_archives with prefixed symbols
.PRECIOUS: $(prefixed_archives)
$(prefixed_archives): $(result_dir)/%_entrypoint_aio_prefixed_$(result_suffix).a: $(build_dir)/%.pairs | $(build_dir)/%_entrypoint_aio.a
# Single non-flavored archive.
#
# We build one variant with the baseline march for the platform ($(generic_flavor))
# and link its symbols directly, without per-flavor prefixing or runtime dispatch.
$(result_dir)/$(platform)_entrypoint_aio_$(result_suffix).a:
@mkdir -p ${@D}
@objcopy --redefine-syms=$< $| $@

.INTERMEDIATE: $(build_dir)/%.pairs
$(build_dir)/%.pairs: $(build_dir)/%.symbols
@cat $< | cut -d' ' -f3 | sort -u | awk '{ print $$0 " $(call make_escape,$*)_" $$0 }' > $@

.INTERMEDIATE: $(build_dir)/%.symbols
$(build_dir)/%.symbols: $(build_dir)/%_entrypoint_aio.a
@nm --defined-only $< > $@


# We build all archives in bash loop because files contains escaped flavor in name but --march flag shouldn't be escaped
.PRECIOUS: $(archives)
$(archives):
@mkdir -p $(build_dir)
@$(bazel_in_root);\
for i in $(flavors); do\
$(call bazel_build_march,$$i) -- //:entrypoint_aio &&\
cp -f bazel-bin/entrypoint_aio.a $(build_dir_absolute_path)/$(platform)_$$($(call escape,$$i))_entrypoint_aio.a ||\
exit 1;\
done
$(call bazel_build_march,$(generic_flavor)) -- //:entrypoint_aio
@cp -f ../bazel-bin/entrypoint_aio.a $@
66 changes: 0 additions & 66 deletions pp/entrypoint/entrypoint.cpp.mk

This file was deleted.

Loading
Loading