-
Notifications
You must be signed in to change notification settings - Fork 45
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
[Do not merge] Initial support for auto updating and building dependent third party projects #211
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,11 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
cmake_minimum_required(VERSION 3.5) | ||
# Match requirement from LLVM/MLIR | ||
cmake_minimum_required(VERSION 3.13.4) | ||
|
||
project(mlir-extensions) | ||
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules/") | ||
|
||
set(CMAKE_CXX_STANDARD 14) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
@@ -70,6 +72,43 @@ macro(apply_llvm_compile_flags target) | |
target_compile_definitions(${target} PRIVATE ${LLVM_DEFINITIONS}) | ||
endmacro() | ||
|
||
# Check if using external LLVM/MLIR install tree | ||
if (DEFINED MLIR_DIR) | ||
if (DEFINED MLIR_DIR) | ||
set(MLIR_EXT_USE_LLVM_INSTALL_TREE ON) | ||
else() | ||
message(FATAL_ERROR "Need to define both LLVM_DIR and MLIR_DIR or none.") | ||
endif() | ||
elseif (DEFINED LLVM_DIR) | ||
message(FATAL_ERROR "Need to define both LLVM_DIR and MLIR_DIR or none.") | ||
else() | ||
set(MLIR_EXT_USE_LLVM_INSTALL_TREE OFF) | ||
endif() | ||
|
||
if(GPU_ENABLE) | ||
# Check if using external level-zero | ||
if(DEFINED LEVEL_ZERO_DIR) | ||
set(MLIR_EXT_USE_EXT_LEVEL_ZERO ON) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let us move to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
else() | ||
set(MLIR_EXT_USE_EXT_LEVEL_ZERO OFF) | ||
endif() | ||
message(STATUS "MLIR_EXT_USE_EXT_LEVEL_ZERO: ${MLIR_EXT_USE_EXT_LEVEL_ZERO}") | ||
endif() | ||
|
||
add_subdirectory(third-party) | ||
|
||
if(NOT MLIR_EXT_USE_LLVM_INSTALL_TREE) | ||
set(LLVM_DIR ${PROJECT_BINARY_DIR}/third-party/mlir/llvm-project/llvm/lib/cmake/llvm) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not like checking out third party repos in IMEX repo. The problem is if you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR does not remove the option of providing -DCMAKE_THIRD_PARTY_LIB_PATH. It only checks out third party repo if -DCMAKE_THIRD_PARTY_LIB_PATH is not provided. |
||
set(MLIR_DIR ${PROJECT_BINARY_DIR}/lib/cmake/mlir) | ||
endif() | ||
|
||
if(GPU_ENABLE) | ||
if(NOT MLIR_EXT_USE_EXT_LEVEL_ZERO) | ||
set(LEVEL_ZERO_DIR ${PROJECT_BINARY_DIR}) | ||
message(STATUS "LEVEL_ZERO_DIR set to: ${PROJECT_BINARY_DIR}") | ||
endif() | ||
endif() | ||
|
||
if(GPU_ENABLE) | ||
add_subdirectory(dpcomp_gpu_runtime) | ||
endif() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#=============================================================================== | ||
# Copyright 2022 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
#=============================================================================== | ||
|
||
set(LEVEL_ZERO_VERSION_FILE "${PROJECT_SOURCE_DIR}/level-zero-sha.txt") | ||
file(READ "${LEVEL_ZERO_VERSION_FILE}" REVISION_FILE) | ||
string(REGEX MATCH "([A-Za-z0-9]+)" _ ${REVISION_FILE}) | ||
set(MLIR_EXT_LEVEL_ZERO_COMMIT_ID ${CMAKE_MATCH_1}) | ||
message(STATUS "LEVEL_ZERO COMMIT ID: ${MLIR_EXT_LEVEL_ZERO_COMMIT_ID}") | ||
set(MLIR_EXT_LEVEL_ZERO_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/level-zero") | ||
|
||
if (NOT EXISTS "${MLIR_EXT_LEVEL_ZERO_SOURCE_DIR}") | ||
message(STATUS "Cloning LEVEL_ZERO git repo") | ||
execute_process(COMMAND git clone https://github.com/oneapi-src/level-zero.git | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
COMMAND_ECHO STDOUT | ||
OUTPUT_VARIABLE LEVEL_ZERO_CLONE_OUTPUT | ||
ERROR_VARIABLE LEVEL_ZERO_CLONE_ERROR | ||
) | ||
else() | ||
message(STATUS "LEVEL_ZERO git repo already cloned.") | ||
endif() | ||
execute_process(COMMAND git fetch --prune | ||
WORKING_DIRECTORY ${MLIR_EXT_LEVEL_ZERO_SOURCE_DIR} | ||
COMMAND_ECHO STDOUT | ||
OUTPUT_VARIABLE LEVEL_ZERO_PULL_OUTPUT | ||
ERROR_VARIABLE LEVEL_ZERO_PULL_ERROR | ||
) | ||
|
||
message(STATUS "LEVEL_ZERO: checkout ${MLIR_EXT_LEVEL_ZERO_COMMIT_ID}") | ||
|
||
execute_process(COMMAND git checkout ${MLIR_EXT_LEVEL_ZERO_COMMIT_ID} | ||
WORKING_DIRECTORY ${MLIR_EXT_LEVEL_ZERO_SOURCE_DIR} | ||
COMMAND_ECHO STDOUT | ||
OUTPUT_VARIABLE LEVEL_ZERO_CHECKOUT_OUTPUT | ||
ERROR_VARIABLE LEVEL_ZERO_CHECKOUT_ERROR | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#=============================================================================== | ||
# Copyright 2022 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
#=============================================================================== | ||
|
||
set(LLVM_VERSION_FILE "${PROJECT_SOURCE_DIR}/llvm-sha.txt") | ||
file(READ "${LLVM_VERSION_FILE}" REVISION_FILE) | ||
string(REGEX MATCH "([A-Za-z0-9]+)" _ ${REVISION_FILE}) | ||
set(MLIR_EXT_LLVM_COMMIT_ID ${CMAKE_MATCH_1}) | ||
message(STATUS "LLVM COMMIT ID: ${MLIR_EXT_LLVM_COMMIT_ID}") | ||
set(MLIR_EXT_LLVM_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/llvm-project") | ||
|
||
if (NOT EXISTS "${MLIR_EXT_LLVM_SOURCE_DIR}") | ||
message(STATUS "Cloning LLVM git repo") | ||
execute_process(COMMAND git clone https://github.com/llvm/llvm-project.git | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
COMMAND_ECHO STDOUT | ||
OUTPUT_VARIABLE LLVM_CLONE_OUTPUT | ||
ERROR_VARIABLE LLVM_CLONE_ERROR | ||
) | ||
else() | ||
message(STATUS "LLVM git repo already cloned.") | ||
endif() | ||
execute_process(COMMAND git fetch --prune | ||
WORKING_DIRECTORY ${MLIR_EXT_LLVM_SOURCE_DIR} | ||
COMMAND_ECHO STDOUT | ||
OUTPUT_VARIABLE LLVM_PULL_OUTPUT | ||
ERROR_VARIABLE LLVM_PULL_ERROR | ||
) | ||
|
||
message(STATUS "LLVM: checkout ${MLIR_EXT_LLVM_COMMIT_ID}") | ||
|
||
execute_process(COMMAND git checkout ${MLIR_EXT_LLVM_COMMIT_ID} | ||
WORKING_DIRECTORY ${MLIR_EXT_LLVM_SOURCE_DIR} | ||
COMMAND_ECHO STDOUT | ||
OUTPUT_VARIABLE LLVM_CHECKOUT_OUTPUT | ||
ERROR_VARIABLE LLVM_CHECKOUT_ERROR | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bb7fff05b801e26c3d7858e03e509d1089914d59 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps bind to a released tag for L0. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. That was the intention but did not have time to update tag parsing routine. I already had a SHA parse code so just used a SHA instead of tag for now. The SHA points to tag v1.5.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#=============================================================================== | ||
# Copyright 2022 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
#=============================================================================== | ||
|
||
# third party projects | ||
message(STATUS "Configure third-party projects.") | ||
add_subdirectory(mlir) | ||
add_subdirectory(level-zero) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# third party repo sources. | ||
|
||
Source files for third party projects will be placed in this directory. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#=============================================================================== | ||
# Copyright 2022 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
#=============================================================================== | ||
|
||
if ((NOT GPU_ENABLE) OR MLIR_EXT_USE_EXT_LEVEL_ZERO) | ||
return() | ||
endif() | ||
|
||
# Update MLIR source | ||
include(update_level_zero) | ||
include(ExternalProject) | ||
ExternalProject_Add(level-zero | ||
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/level-zero | ||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR} | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#=============================================================================== | ||
# Copyright 2022 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
#=============================================================================== | ||
|
||
if (MLIR_EXT_USE_LLVM_INSTALL_TREE) | ||
message(STATUS "Using LLVM install tree.") | ||
return() | ||
endif() | ||
|
||
# Update MLIR source | ||
include(update_mlir) | ||
|
||
# Add MLIR/LLVM | ||
if (LINUX) | ||
set(LLVM_ENABLE_LLD ON CACHE INTERNAL "") | ||
endif() | ||
set(LLVM_INSTALL_UTILS ON CACHE INTERNAL "") | ||
set(LLVM_ENABLE_PROJECTS mlir CACHE INTERNAL "") | ||
set(LLVM_TARGETS_TO_BUILD "host" CACHE INTERNAL "") | ||
set(LLVM_INCLUDE_TOOLS ON CACHE INTERNAL "") | ||
set(LLVM_BUILD_EXAMPLES ON CACHE INTERNAL "") | ||
set(LLVM_ENABLE_ASSERTIONS ON CACHE INTERNAL "") | ||
set(LLVM_ENABLE_RTTI ON CACHE INTERNAL "") | ||
# ON by default | ||
#set(LLVM_INCLUDE_TESTS ON CACHE INTERNAL "") | ||
set(MLIR_INCLUDE_INTEGRATION_TESTS ON CACHE INTERNAL "") | ||
add_subdirectory(llvm-project/llvm) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should really not need two flags. If someone is using an LLVM build without building MLIR project, CMake will throw an error and we should at that point inform user what to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I am not understanding it right. What does
MLIR_DIR
point to?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MLIR_DIR is defined to guide "find_package(MLIR)" work correctly in CMake.
LLVM_DIR is for "find_package(LLVM)"
Both were already used in the code base. Not introduced by this PR.
Actually find_package(MLIR) will call find_package(LLVM) internally. So we can clean it up but that requires more changes.