Skip to content

[SYCL][ESIMD][EMU] URL for pre-built CM_EMU library package #6027

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

Merged
Merged
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
2 changes: 1 addition & 1 deletion sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ if ("hip" IN_LIST SYCL_ENABLE_PLUGINS)
set(SYCL_BUILD_PI_HIP ON)
endif()
if ("esimd_emulator" IN_LIST SYCL_ENABLE_PLUGINS)
set(SYCL_BUILD_PI_HIP ON)
set(SYCL_BUILD_PI_ESIMD_EMULATOR ON)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it documented anywhere? Is it set from anywhere, e.g. buildbot/congigure.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to look up, but @pvchupin confirmed that this is typo. #5799 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding it's initialized at this specific point. Everything configure.py is doing is adding esimd_emulator to SYCL_ENABLE_PLUGINS under the switch.
I'm not sure if we are using SYCL_BUILD_PI_ESIMD_EMULATOR anywhere, but it seems there are a few occurrences in in LIT infra.

endif()

# Configure SYCL version macro
Expand Down
89 changes: 44 additions & 45 deletions sycl/plugins/esimd_emulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,45 @@ include_directories(${OpenCL_INCLUDE_DIR})
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_build)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install)

if (MSVC)
if (WIN32)
set(LIBCM ${LLVM_BINARY_DIR}/pi_esimd_emulator_deps/lib/libcm${CMAKE_STATIC_LIBRARY_SUFFIX})
set(LIBIGFXCMRT_EMU ${LLVM_BINARY_DIR}/pi_esimd_emulator_deps/lib/igfxcmrt64_emu${CMAKE_STATIC_LIBRARY_SUFFIX})
else()
set(LIBCM ${LLVM_BINARY_DIR}/pi_esimd_emulator_deps/lib/libcm${CMAKE_SHARED_LIBRARY_SUFFIX})
set(LIBIGFXCMRT_EMU ${LLVM_BINARY_DIR}/pi_esimd_emulator_deps/lib/libigfxcmrt_emu${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()

if (DEFINED CM_LOCAL_SOURCE_DIR)
# Using local CM directory for online building without downloading
if (MSVC)
set (DEFAULT_CM_EMU_PREBUILT_PACKAGE "https://github.com/intel/cm-cpu-emulation/releases/download/v2022-05-06/intel-cmemu-1.0.22.u20.04-release.x86_64.tar.xz")
set (DEFAULT_CM_EMU_SOURCE_URL "https://github.com/intel/cm-cpu-emulation.git")

if ((DEFINED USE_DEFAULT_CM_EMU_SOURCE) OR (DEFINED USE_LOCAL_CM_EMU_SOURCE))
if (DEFINED USE_CM_EMU_PREBUILT_PACKAGE)
message(FATAL_ERROR "Configuration failure : Pre-built package and On-line building of CM_EMU library package cannot be applied together")
endif()
if ((DEFINED USE_DEFAULT_CM_EMU_SOURCE) AND (DEFINED USE_LOCAL_CM_EMU_SOURCE))
message(FATAL_ERROR "Configuration failure : Either default CM_EMU source or local source can be used for on-line CM building - not together")
endif()
if (WIN32)
message(FATAL_ERROR "Configuration failure : Online-building of CM_EMU library is not supported under Windows environment")
endif()

if (DEFINED USE_DEFAULT_CM_EMU_SOURCE)
message(STATUS "CM_EMU library package will be built online with source codes downloaded from ${DEFAULT_CM_EMU_SOURCE_URL}")
ExternalProject_Add(cm-emu
DOWNLOAD_COMMAND ""
SOURCE_DIR ${CM_LOCAL_SOURCE_DIR}
GIT_REPOSITORY ${DEFAULT_CM_EMU_SOURCE_URL}
GIT_TAG f9d167edbcb995e713d5a8
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_build
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
CMAKE_ARGS -DLIBVA_INSTALL_PATH=/usr
-D__SYCL_EXPLICIT_SIMD_PLUGIN__=true
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
BUILD_BYPRODUCTS ${LIBCM} ${LIBIGFXCMRT_EMU}
)
else()
elseif (DEFINED USE_LOCAL_CM_EMU_SOURCE)
message(STATUS "CM_EMU library package will be built online with source codes from ${USE_LOCAL_CM_EMU_SOURCE}")
ExternalProject_Add(cm-emu
DOWNLOAD_COMMAND ""
SOURCE_DIR ${CM_LOCAL_SOURCE_DIR}
SOURCE_DIR ${USE_LOCAL_CM_EMU_SOURCE}
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_build
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install
CMAKE_ARGS -DLIBVA_INSTALL_PATH=/usr
Expand All @@ -45,42 +61,25 @@ if (DEFINED CM_LOCAL_SOURCE_DIR)
BUILD_BYPRODUCTS ${LIBCM} ${LIBIGFXCMRT_EMU}
)
endif()
else ()
if (DEFINED CM_PACKAGE_URL)
# Downloading pre-built CM Package
file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install)
ExternalProject_Add(cm-emu
URL ${CM_PACKAGE_URL}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
UPDATE_COMMAND ""
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/cm-emu-prefix/src/cm-emu/ <INSTALL_DIR>
BUILD_BYPRODUCTS ${LIBCM} ${LIBIGFXCMRT_EMU}
)
else()
set(ACTUAL_CM_EMU_PREBUILT_PACKAGE ${DEFAULT_CM_EMU_PREBUILT_PACKAGE})
Copy link
Contributor

@kbobrovs kbobrovs Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to add a message here so that users can see what USE_* variables are available to adjust the emulator build, something like
"Neither of USE_DEFAULT_CM_EMU_SOURCE, USE_LOCAL_CM_EMU_SOURCE, USE_CM_EMU_PREBUILT_PACKAGE is set, using prebuilt libCM from ${ACTUAL_CM_EMU_PREBUILT_PACKAGE}"

if (DEFINED USE_CM_EMU_PREBUILT_PACKAGE)
set(ACTUAL_CM_EMU_PREBUILT_PACKAGE ${USE_CM_EMU_PREBUILT_PACKAGE})
else()
# Build from CM source tree fetched from github
if (MSVC)
message(FATAL_ERROR "Online-building of CM_EMU library is not supported under Windows environment")
else()
# Arguments for online patching to suppress log message from CM_EMU
# Replacing CM_EMU's log print-out macro controlled by 'GFX_EMU_WITH_FLAGS_'
# with blank space from $CM_EMU_SRC/common/emu_log.h
set (replacing_pattern s/{\ ?GFX_EMU_WITH_FLAGS_.*//g)
ExternalProject_Add(cm-emu
GIT_REPOSITORY https://github.com/intel/cm-cpu-emulation.git
GIT_TAG f9d167edbcb995e713d5a8
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_build
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install
PATCH_COMMAND perl -pi.back -e ${replacing_pattern} ${CMAKE_CURRENT_BINARY_DIR}/cm-emu-prefix/src/cm-emu/common/emu_log.h
CMAKE_ARGS -DLIBVA_INSTALL_PATH=/usr
-D__SYCL_EXPLICIT_SIMD_PLUGIN__=true
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
BUILD_BYPRODUCTS ${LIBCM} ${LIBIGFXCMRT_EMU}
)
endif()
message(STATUS "Neither of USE_DEFAULT_CM_EMU_SOURCE, USE_LOCAL_CM_EMU_SOURCE, USE_CM_EMU_PREBUILT_PACKAGE is set, using prebuilt libCM from ${DEFAULT_CM_EMU_PREBUILT_PACKAGE}")
endif()
endif ()
file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install)
ExternalProject_Add(cm-emu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExternalProject_Add seems not the right tool for downloading pre-built packages, AFAIU, it is for adding external CMakeProjects and build them from source. Please check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FetchContent_* functions can be used for downloading archives. However, it seems that using the functions requires extra steps for CM_EMU as the downloaded library package is used for both toolchain build and kernel compilation. I would like to keep this part as it is with TODO comments due to urgency of this change set. CMake for LevelZero PI also uses ExternalProject_Add for LevelZero module and already has TODO comment for FetchContent -

#TODO: Replace ExternalProject with FetchContent for better maintainance and
.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, please add a TODO then too

URL ${ACTUAL_CM_EMU_PREBUILT_PACKAGE}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
UPDATE_COMMAND ""
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/cm-emu-prefix/src/cm-emu/ <INSTALL_DIR>
BUILD_BYPRODUCTS ${LIBCM} ${LIBIGFXCMRT_EMU}
)
endif()

ExternalProject_Add_Step(cm-emu llvminstall
COMMAND ${CMAKE_COMMAND} -E make_directory ${LLVM_BINARY_DIR}/pi_esimd_emulator_deps && ${CMAKE_COMMAND} -E copy_directory <INSTALL_DIR>/ ${LLVM_BINARY_DIR}/pi_esimd_emulator_deps
COMMENT "Installing cm-emu into the LLVM binary directory"
Expand All @@ -97,7 +96,7 @@ set(CMAKE_CXX_STANDARD 17)

# Compilation option modification to prevent build termination caused by
# warnings from CM-imported files
if (MSVC)
if (WIN32)
string(REPLACE "/W4" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
string(REPLACE "-pedantic" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
Expand Down Expand Up @@ -127,7 +126,7 @@ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install/include/libcm/cm
)

# Copy '.so' files to '$(INSTALL)/lib'
if (MSVC)
if (WIN32)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install/lib/
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
COMPONENT libcmrt-libs
Expand Down