Skip to content

Commit

Permalink
feat(interactive): Add the CMake argument OPTIMIZE_FOR_HOST to prev…
Browse files Browse the repository at this point in the history
…ent the use of host-specific CPU instructions when building images. (#4159)

As titled.

Fix #4050

---------

Co-authored-by: Jingbo Xu <[email protected]>
  • Loading branch information
zhanglei1949 and yecol authored Aug 21, 2024
1 parent 54ad17f commit 6840826
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/flex/interactive/development/dev_and_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
6 changes: 5 additions & 1 deletion flex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions k8s/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 .

Expand Down
3 changes: 2 additions & 1 deletion k8s/dockerfiles/flex-interactive.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/ && \
Expand Down

0 comments on commit 6840826

Please sign in to comment.