From 6840826b1266644f91a5cf8056daec3ab2d54583 Mon Sep 17 00:00:00 2001 From: Zhang Lei Date: Wed, 21 Aug 2024 10:12:51 +0800 Subject: [PATCH] feat(interactive): Add the CMake argument `OPTIMIZE_FOR_HOST` to prevent the use of host-specific CPU instructions when building images. (#4159) As titled. Fix #4050 --------- Co-authored-by: Jingbo Xu --- docs/flex/interactive/development/dev_and_test.md | 8 ++++++++ flex/CMakeLists.txt | 6 +++++- k8s/Makefile | 3 +++ k8s/dockerfiles/flex-interactive.Dockerfile | 3 ++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/flex/interactive/development/dev_and_test.md b/docs/flex/interactive/development/dev_and_test.md index f7fa915a444e..9b272a2f403c 100644 --- a/docs/flex/interactive/development/dev_and_test.md +++ b/docs/flex/interactive/development/dev_and_test.md @@ -83,6 +83,14 @@ cd interactive_engine mvn clean package -DskipTests -Pexperimental ``` +### CMake options + +- `BUILD_TEST`: Indicates whether to build tests. +- `BUILD_DOC`: Indicates whether to build Flex documentation. +- `BUILD_ODPS_FRAGMENT_LOADER`: Enables support for loading graphs from ODPS tables. +- `USE_PTHASH`: Indicates whether to use a perfect hash when building the vertex map. +- `OPTIMIZE_FOR_HOST`: Determines if Flex should be optimized for performance on the current machine. Note that enabling this option may result in a binary that does not run on different platforms or CPU architectures. + ## Testing Numerous test cases have been created for Interactive, which can be referenced in the GitHub workflow[interactive.yaml](https://github.com/alibaba/GraphScope/blob/main/.github/workflows/interactive.yml). diff --git a/flex/CMakeLists.txt b/flex/CMakeLists.txt index dd906d667f71..98c96b4cf651 100644 --- a/flex/CMakeLists.txt +++ b/flex/CMakeLists.txt @@ -14,6 +14,7 @@ option(BUILD_TEST "Whether to build test" ON) option(BUILD_DOC "Whether to build doc" OFF) option(BUILD_ODPS_FRAGMENT_LOADER "Whether to build odps fragment loader" OFF) option(USE_PTHASH "Whether to use pthash" OFF) +option(OPTIMIZE_FOR_HOST "Whether to optimize on host" ON) # Whether to build optimized code on host #print options message(STATUS "Build test: ${BUILD_TEST}") @@ -76,7 +77,10 @@ else () endif () endif () -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -Werror -std=c++17 -Wall -fPIC -march=native") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -Werror -std=c++17 -Wall -fPIC") +if (OPTIMIZE_FOR_HOST) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") +endif() set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -g") diff --git a/k8s/Makefile b/k8s/Makefile index 4dfb2e9fdb47..6cd8ac4b3c16 100644 --- a/k8s/Makefile +++ b/k8s/Makefile @@ -21,6 +21,8 @@ PROFILE ?= release CI ?= false # Flex Coordinator ENABLE_COORDINATOR ?= false +# Flex Interactive: controls whether optimize for host, should be enabled when building images +OPTIMIZE_FOR_HOST:= OFF BUILD_PROGRESS ?= auto @@ -167,6 +169,7 @@ flex-interactive: --build-arg BUILDER_VERSION=$(BUILDER_VERSION) \ --build-arg PLATFORM=${PLATFORM} \ --build-arg ARCH=${ARCH} \ + --build-arg OPTIMIZE_FOR_HOST=${OPTIMIZE_FOR_HOST} \ -t graphscope/interactive:${VERSION} \ -f ${DOCKERFILES_DIR}/flex-interactive.Dockerfile . diff --git a/k8s/dockerfiles/flex-interactive.Dockerfile b/k8s/dockerfiles/flex-interactive.Dockerfile index ed852bdc4f5b..556488bc59c3 100644 --- a/k8s/dockerfiles/flex-interactive.Dockerfile +++ b/k8s/dockerfiles/flex-interactive.Dockerfile @@ -6,6 +6,7 @@ ARG REGISTRY=registry.cn-hongkong.aliyuncs.com ARG BUILDER_VERSION=latest FROM $REGISTRY/graphscope/graphscope-dev:$BUILDER_VERSION-$ARCH AS builder ARG ENABLE_COORDINATOR="false" +ARG OPTIMIZE_FOR_HOST=OFF RUN sudo mkdir -p /opt/flex && sudo chown -R graphscope:graphscope /opt/flex/ USER graphscope @@ -39,7 +40,7 @@ COPY --chown=graphscope:graphscope . /home/graphscope/GraphScope # install flex RUN . ${HOME}/.cargo/env && cd ${HOME}/GraphScope/flex && \ - git submodule update --init && mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=/opt/flex -DBUILD_DOC=OFF -DBUILD_TEST=OFF && make -j && make install && \ + git submodule update --init && mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=/opt/flex -DBUILD_DOC=OFF -DBUILD_TEST=OFF -DOPTIMIZE_FOR_HOST=${OPTIMIZE_FOR_HOST} && make -j && make install && \ cd ~/GraphScope/interactive_engine/ && mvn clean package -Pexperimental -DskipTests && \ cd ~/GraphScope/interactive_engine/compiler && cp target/compiler-0.0.1-SNAPSHOT.jar /opt/flex/lib/ && \ cp target/libs/*.jar /opt/flex/lib/ && \