diff --git a/CMakeLists.txt b/CMakeLists.txt index 636b33ad2..f1adaadc1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,99 +18,111 @@ cmake_minimum_required(VERSION 3.20) project(GraphCompiler VERSION "0.1.0" LANGUAGES C CXX) -set(CMAKE_CXX_STANDARD 17) +############################# Cmake options #################################### +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +# Silence a false positive GCC -Wunused-but-set-parameter warning in constexpr +# cases, by marking SelectedCase as used. See +# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85827 for details. The issue is +# fixed in GCC 10. +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0") + check_cxx_compiler_flag("-Wno-unused-but-set-parameter" CXX_SUPPORTS_WNO_UNUSED_BUT_SET_PARAMETER) + append_if(CXX_SUPPORTS_WNO_UNUSED_BUT_SET_PARAMETER "-Wno-unused-but-set-parameter" CMAKE_CXX_FLAGS) +endif() +################################################################################ -option(GC_LEGACY_ENABLE ON) -option(GC_TEST_ENABLE "Build the tests" ON) -option(GC_USE_GPU "Enable GPU backend" OFF) +############################ Build options ##################################### +option(GC_ENABLE_LEGACY ON) +option(GC_ENABLE_DNNL "Enable the oneDNN library integration" ON) +option(GC_ENABLE_TEST "Build the tests" ON) +option(GC_ENABLE_TEST_DNNL "Build the dnnl tests" ${GC_ENABLE_DNNL}) +option(GC_ENABLE_TEST_MLIR "Build the mlir tests" ON) +option(GC_ENABLE_TOOLS "Build the tools" ON) +option(GC_ENABLE_OPT "Build gc-opt" ${GC_ENABLE_TOOLS}) +option(GC_ENABLE_IMEX "Enable IntelĀ® Extension for MLIR" OFF) option(GC_ENABLE_BINDINGS_PYTHON "Enable Graph Complier Python Binding" ON) option(GC_DEV_LINK_LLVM_DYLIB "Link dynamic libraries of LLVM and MLIR. For developers only. Do not use it in packing the library." OFF) -if(GC_LEGACY_ENABLE) - add_subdirectory(legacy/core) -endif() - -find_package(MLIR REQUIRED CONFIG) - -message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") -message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") - -set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin) -set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib) -set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR}) - -list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") -list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") - -include(TableGen) -include(AddLLVM) -include(AddMLIR) -include(HandleLLVMOptions) - -if(GC_USE_GPU) - include(imex) - if(GC_DEV_LINK_LLVM_DYLIB) - message(WARN "GPU backend may not be compatible with dynamic linking to LLVM") - endif() -endif() - -if(GC_ENABLE_BINDINGS_PYTHON AND NOT MLIR_ENABLE_BINDINGS_PYTHON) - message(STATUS "Failed to enable Python API due to the 'MLIR_ENABLE_BINDINGS_PYTHON' for LLVM is not ON.") - set(GC_ENABLE_BINDINGS_PYTHON OFF CACHE BOOL "" FORCE) +if(GC_ENABLE_LEGACY) + add_subdirectory(legacy/core) endif() -if(GC_ENABLE_BINDINGS_PYTHON) - include(MLIRDetectPythonEnv) - mlir_configure_python_dev_packages() +if(GC_ENABLE_DNNL) + set(GC_ONEDNN_DIALECT_LIB_NAME MLIROneDNNGraph) endif() +################################################################################ -include_directories( - ${LLVM_INCLUDE_DIRS} - ${MLIR_INCLUDE_DIRS} - ${PROJECT_BINARY_DIR}/include - ${PROJECT_SOURCE_DIR}/include +############################## Targets ######################################### +# All common options, includes etc. are added to this interface target. +add_library(GcInterface INTERFACE) +target_compile_features(GcInterface INTERFACE cxx_std_17) +target_include_directories(GcInterface INTERFACE + $ + $ + $ ) -# The paths are added in the subfolders using the gc_add_path() function. -# These lists are also used by tests. -set(GC_LIB_SOURCES CACHE INTERNAL "The graph_compiler library source paths") -set(GC_LIB_INCLUDES CACHE INTERNAL "The graph_compiler library include paths") - -add_definitions(${LLVM_DEFINITIONS}) - -set(GC_MLIR_CXX_FLAGS "") -# Silence a false positive GCC -Wunused-but-set-parameter warning in constexpr -# cases, by marking SelectedCase as used. See -# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85827 for details. The issue is -# fixed in GCC 10. -if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0") - check_cxx_compiler_flag("-Wno-unused-but-set-parameter" CXX_SUPPORTS_WNO_UNUSED_BUT_SET_PARAMETER) - append_if(CXX_SUPPORTS_WNO_UNUSED_BUT_SET_PARAMETER "-Wno-unused-but-set-parameter" GC_MLIR_CXX_FLAGS) -endif() -include("cmake/version.cmake") +include(functions) +include(version) +include(mlir) add_subdirectory(include) add_subdirectory(lib) add_subdirectory(src) -if(GC_ENABLE_BINDINGS_PYTHON) - message(STATUS "Enabling Python API") - add_subdirectory(python) -endif() +add_subdirectory(python) +add_subdirectory(test) +################################################################################ -set(GC_LIB_LINKED_LIBS - GCJitWrapper - GCCpuRuntime +############################### Install ######################################## +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ TYPE INCLUDE) +install(DIRECTORY ${PROJECT_BINARY_DIR}/include/ TYPE INCLUDE + REGEX "CMake.*|.*cmake" EXCLUDE) + +# Export the targets +get_property(GC_TOOLS GLOBAL PROPERTY GC_TOOLS) +get_property(GC_MLIR_LIBS GLOBAL PROPERTY GC_MLIR_LIBS) +get_property(GC_PASS_LIBS GLOBAL PROPERTY GC_PASS_LIBS) +get_property(GC_DIALECT_LIBS GLOBAL PROPERTY GC_DIALECT_LIBS) +install(TARGETS + GcInterface + ${GC_TOOLS} + ${GC_MLIR_LIBS} + ${GC_PASS_LIBS} + ${GC_DIALECT_LIBS} + EXPORT ${PROJECT_NAME}Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) +export(EXPORT ${PROJECT_NAME}Targets + FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake" +) +install(EXPORT ${PROJECT_NAME}Targets + FILE ${PROJECT_NAME}Targets.cmake + DESTINATION lib/cmake/${PROJECT_NAME} ) -add_mlir_library(graph_compiler SHARED ${GC_LIB_SOURCES}) -target_include_directories(graph_compiler PUBLIC ${GC_LIB_INCLUDES}) -target_compile_options(graph_compiler PRIVATE -fvisibility=hidden -fexceptions) -target_link_options(graph_compiler PRIVATE -Wl,--gc-sections) -target_link_libraries(graph_compiler PRIVATE ${GC_LIB_LINKED_LIBS}) -add_subdirectory(test) +# Generate the config files +include(CMakePackageConfigHelpers) +configure_package_config_file( + ${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION "lib/cmake/${PROJECT_NAME}" + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) +write_basic_package_version_file( + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + COMPATIBILITY AnyNewerVersion +) +install(FILES + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION "lib/cmake/${PROJECT_NAME}" +) +################################################################################ diff --git a/README.md b/README.md index 958878fae..4c04cc460 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ cmake --build build --target install Notes * It is recommended to add optional options `-DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON` to the command `cmake -G Ninja llvm ...` above **if you are building for CPU only**. These will enable the build of LLVM/MLIR dynamic libraries and let MLIR/LLVM tools link to them, to reduce the installed binary size of LLVM/MLIR. These options also enable the `GC_DEV_LINK_LLVM_DYLIB` option of graph-compiler repo (see below). - * The option `-DLLVM_INSTALL_GTEST=ON` is optional, if the tests of graph-compiler are disabled (see `GC_TEST_ENABLE` below). + * The option `-DLLVM_INSTALL_GTEST=ON` is optional, if the tests of graph-compiler are disabled (see `GC_ENABLE_TEST` below). * If you would like to enable GPU components of Graph Compiler, please make sure to statically link Graph Compiler and LLVM(MLIR). It is a known issue that LLVM shared library cannot be linked together with IGC (Intel's low level GPU compiler). Make sure `LLVM_BUILD_LLVM_DYLIB` and `LLVM_LINK_LLVM_DYLIB` are `OFF` (they are off by default). Also make sure Graph Compiler's cmake option `GC_DEV_LINK_LLVM_DYLIB` is `OFF` when configuring Graph Compiler (see below). We have now installed LLVM at `llvm-project/llvm-install`. @@ -59,7 +59,7 @@ Notes: * `/PATH/TO/llvm-project/llvm-install` should be the install path of LLVM. If you installed LLVM elsewhere by `-DCMAKE_INSTALL_PREFIX` option when building LLVM, you need to change the path in `-DMLIR_DIR` accordingly. * The cmake option `-DLLVM_EXTERNAL_LIT` is for the tests of this project. It requires the `lit` tool to be installed in the system. You can install it via `pip install lit`. If you don't need to run the tests of this repo, you can omit this option in the command line. -More notes if GPU components are on (`-DGC_USE_GPU=ON`): +More notes if IntelĀ® Extension for MLIR is on (`-DGC_ENABLE_IMEX=ON`): * make sure the OpenCL runtime is installed in your system. You can either install using OS-provided package (Ubuntu 22.04) ```sh @@ -70,11 +70,11 @@ sudo apt install -y intel-opencl-icd opencl-c-headers Graph Compiler supports the following build-time options. -| CMake Option | Supported values (defaults in bold) | Description | -|:--------------------------------|:---------------------------------------|:---------------------------------------------------------------------------------------| -| GC_LEGACY_ENABLE | **ON**, OFF | Controls building the legacy graph-compiler component | -| GC_TEST_ENABLE | **ON**, OFF | Controls building the tests | -| GC_DEV_LINK_LLVM_DYLIB | ON, **OFF** | Controls dynamic link LLVM/MLIR libraries, mainly for developer | -| GC_ENABLE_BINDINGS_PYTHON | **ON**, OFF | Controls building the Python API | -| GC_USE_GPU | ON, **OFF** | Whether to enable the GPU components | +| CMake Option | Supported values (defaults in bold) | Description | +|:--------------------------|:---------------------------------------|:----------------------------------------------------------------| +| GC_ENABLE_LEGACY | **ON**, OFF | Controls building the legacy graph-compiler component | +| GC_ENABLE_TEST | **ON**, OFF | Controls building the tests | +| GC_DEV_LINK_LLVM_DYLIB | ON, **OFF** | Controls dynamic link LLVM/MLIR libraries, mainly for developer | +| GC_ENABLE_BINDINGS_PYTHON | **ON**, OFF | Controls building the Python API | +| GC_ENABLE_IMEX | ON, **OFF** | Whether to enable the GPU components | diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 000000000..90c5b52a0 --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1,10 @@ +@PACKAGE_INIT@ + +include ("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") + +find_package(MLIR REQUIRED CONFIG) + +include_directories( + ${LLVM_INCLUDE_DIRS} + ${MLIR_INCLUDE_DIRS} +) diff --git a/cmake/functions.cmake b/cmake/functions.cmake index 57885301d..cbd173e75 100644 --- a/cmake/functions.cmake +++ b/cmake/functions.cmake @@ -18,20 +18,25 @@ function(gc_fetch_content # Optional arguments: # SKIP_ADD: Populate but do not add the content to the project. # SKIP_FIND: Do not use find_package(). - # CMAKE_ARGS: Passed to FetchContent_Declare. + # SET: key=value variables to be set before the content population. ) string(TOUPPER ${name} uname) - cmake_parse_arguments(GC_${uname} "SKIP_ADD;SKIP_FIND" "" "CMAKE_ARGS" ${ARGN}) + cmake_parse_arguments(GC_${uname} "SKIP_ADD;SKIP_FIND" "" "SET" ${ARGN}) - if (DEFINED GC_${uname}_CMAKE_ARGS) - message(STATUS "${name}_CMAKE_ARGS: ${GC_${uname}_CMAKE_ARGS}") + if (DEFINED GC_${uname}_SET) + foreach (var ${GC_${uname}_SET}) + string(REGEX REPLACE "([^=]+)=(.*)" "\\1;\\2" var ${var}) + list(GET var 0 key) + list(GET var 1 value) + message(STATUS "Setting ${key}=${value}") + set(${key} ${value}) + endforeach () endif () if (DEFINED GC_${uname}_SRC_DIR) FetchContent_Declare( ${name} SOURCE_DIR ${GC_${uname}_SRC_DIR} - CMAKE_ARGS ${GC_${uname}_CMAKE_ARGS} ) else () if (DEFINED GC_${uname}_VERSION) @@ -53,7 +58,6 @@ function(gc_fetch_content GIT_REPOSITORY ${git_repository} GIT_TAG ${git_tag_or_version} GIT_PROGRESS TRUE - CMAKE_ARGS ${GC_${uname}_CMAKE_ARGS} FIND_PACKAGE_ARGS ${FIND_PACKAGE_ARGS} ) endif () @@ -75,28 +79,6 @@ function(gc_fetch_content endif () endfunction() -# Add one or multiple paths to the specified list. -# The paths could be specified as a list of files or a GLOB pattern: -# gc_add_path(SOURCES GLOB "src/*.cpp") -# gc_add_path(INCLUDES include1 include2 include3) -function(gc_add_path list_name paths) - if (paths STREQUAL "GLOB") - file(GLOB paths ${ARGN}) - list(APPEND ${list_name} ${paths}) - else () - get_filename_component(path ${paths} ABSOLUTE) - list(APPEND ${list_name} ${path}) - foreach (path ${ARGN}) - get_filename_component(path ${path} ABSOLUTE) - list(APPEND ${list_name} ${path}) - endforeach () - endif () - set(${list_name} ${${list_name}} - CACHE INTERNAL "${list_name} paths" - ) -endfunction() - - macro(gc_set_mlir_link_components VAR) if(GC_DEV_LINK_LLVM_DYLIB) set(${VAR} @@ -108,3 +90,31 @@ macro(gc_set_mlir_link_components VAR) ) endif() endmacro() + +function(gc_add_mlir_library name) + add_mlir_library(${ARGV}) + + if(name MATCHES ".+Passes") + set_property(GLOBAL APPEND PROPERTY GC_PASS_LIBS ${name}) + else() + set_property(GLOBAL APPEND PROPERTY GC_MLIR_LIBS ${name}) + endif() + + if(GcInterface IN_LIST ARGN) + if(SHARED IN_LIST ARGN) + target_link_libraries(${name} PUBLIC GcInterface) + else() + target_link_libraries(obj.${name} PUBLIC GcInterface) + endif() + endif() +endfunction() + +function(gc_add_mlir_dialect_library name) + add_mlir_dialect_library(${ARGV}) + target_link_libraries(obj.${name} PUBLIC GcInterface) + set_property(GLOBAL APPEND PROPERTY GC_DIALECT_LIBS ${name}) + + if(GcInterface IN_LIST ARGN) + target_link_libraries(obj.${name} PUBLIC GcInterface) + endif() +endfunction() \ No newline at end of file diff --git a/cmake/gtest.cmake b/cmake/gtest.cmake index bbc1d0198..54924ec99 100644 --- a/cmake/gtest.cmake +++ b/cmake/gtest.cmake @@ -1,8 +1,8 @@ include_guard() -include(functions) gc_fetch_content( - GTest - v1.14.0 - https://github.com/google/googletest.git + GTest + v1.14.0 + https://github.com/google/googletest.git + SET INSTALL_GTEST=OFF ) diff --git a/cmake/imex.cmake b/cmake/imex.cmake index 8ed61e3b3..1c9339282 100644 --- a/cmake/imex.cmake +++ b/cmake/imex.cmake @@ -2,13 +2,14 @@ include_guard() get_property(IMEX_INCLUDES GLOBAL PROPERTY IMEX_INCLUDES) if (NOT DEFINED IMEX_INCLUDES) - include(functions) - set(IMEX_CHECK_LLVM_VERSION ON) - set(IMEX_ENABLE_L0_RUNTIME 0) - # TODO: Change to main https://github.com/oneapi-src/oneDNN.git when all the + if(GC_DEV_LINK_LLVM_DYLIB) + message(WARN "GPU backend may not be compatible with dynamic linking to LLVM") + endif() + + # TODO: Change to main https://github.com/intel/mlir-extensions when all the # required functionality is merged. gc_fetch_content(imex 496b240093b5e132b60c5ee69878300fe69be300 https://github.com/Menooker/mlir-extensions - CMAKE_ARGS "-DMLIR_DIR=${MLIR_DIR};-DIMEX_CHECK_LLVM_VERSION=ON;-DIMEX_ENABLE_L0_RUNTIME=0" + SET IMEX_CHECK_LLVM_VERSION=ON IMEX_ENABLE_L0_RUNTIME=0 ) set(IMEX_INCLUDES diff --git a/cmake/mlir.cmake b/cmake/mlir.cmake new file mode 100644 index 000000000..4e5c9b66d --- /dev/null +++ b/cmake/mlir.cmake @@ -0,0 +1,31 @@ +include_guard() + +find_package(MLIR REQUIRED CONFIG) + +message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") +message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") + +set(LLVM_RUNTIME_OUTPUT_INTDIR ${PROJECT_BINARY_DIR}/bin) +set(LLVM_LIBRARY_OUTPUT_INTDIR ${PROJECT_BINARY_DIR}/lib) +set(MLIR_BINARY_DIR ${PROJECT_BINARY_DIR}) + +list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") +list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") + +include(TableGen) +include(AddLLVM) +include(AddMLIR) +include(HandleLLVMOptions) + +include_directories( + ${LLVM_INCLUDE_DIRS} + ${MLIR_INCLUDE_DIRS} +) + +set(LLVM_TABLEGEN_FLAGS + -I${PROJECT_BINARY_DIR}/include + -I${PROJECT_SOURCE_DIR}/include +) + +string(REPLACE " " ";" GC_LLVM_DEFINITIONS ${LLVM_DEFINITIONS}) +target_compile_options(GcInterface INTERFACE ${GC_LLVM_DEFINITIONS}) diff --git a/cmake/onednn.cmake b/cmake/onednn.cmake index 673c4b97e..4c84085aa 100644 --- a/cmake/onednn.cmake +++ b/cmake/onednn.cmake @@ -1,22 +1,19 @@ include_guard() -get_property(DNNL_INCLUDES GLOBAL PROPERTY DNNL_INCLUDES) -if (NOT DEFINED DNNL_INCLUDES) - include(functions) - +get_property(GC_DNNL_INCLUDES GLOBAL PROPERTY GC_DNNL_INCLUDES) +if (NOT DEFINED GC_DNNL_INCLUDES) # TODO: Change to main https://github.com/oneapi-src/oneDNN.git when all the # required functionality is merged. gc_fetch_content(dnnl dev https://github.com/kurapov-peter/oneDNN.git SKIP_ADD - CMAKE_ARGS -DDNNL_IS_MAIN_PROJECT=FALSE -DDNNL_BUILD_TESTS=FALSE -DDNNL_BUILD_EXAMPLES=FALSE ) - set(DNNL_INCLUDES - ${dnnl_BINARY_DIR}/include - ${dnnl_SOURCE_DIR}/include - ${dnnl_SOURCE_DIR}/src + set(GC_DNNL_INCLUDES + $ + $ + $ ) - set_property(GLOBAL PROPERTY DNNL_INCLUDES ${DNNL_INCLUDES}) + set_property(GLOBAL PROPERTY GC_DNNL_INCLUDES ${GC_DNNL_INCLUDES}) # This allows to generate headers from *.in without adding the library to the build. # If the build is required, remove this and the SKIP_ADD option above. @@ -27,6 +24,7 @@ if (NOT DEFINED DNNL_INCLUDES) -Wno-dev -S ${dnnl_SOURCE_DIR} -B ${dnnl_BINARY_DIR} - ${GC_DNNL_CMAKE_ARGS} + -DDNNL_IS_MAIN_PROJECT=FALSE -DDNNL_BUILD_TESTS=FALSE -DDNNL_BUILD_EXAMPLES=FALSE + COMMAND_ERROR_IS_FATAL ANY ) endif () diff --git a/cmake/version.cmake b/cmake/version.cmake index db2d17da2..a6b1cb9aa 100644 --- a/cmake/version.cmake +++ b/cmake/version.cmake @@ -18,8 +18,8 @@ if(NOT GIT_FOUND OR RESULT) set(GC_VERSION_HASH "N/A") endif() -add_compile_definitions( - GC_VERSION_MAJOR=${GC_VERSION_MAJOR} - GC_VERSION_MINOR=${GC_VERSION_MINOR} - GC_VERSION_PATCH=${GC_VERSION_PATCH} - GC_VERSION_HASH="${GC_VERSION_HASH}") +target_compile_options(GcInterface INTERFACE + -DGC_VERSION_MAJOR=${GC_VERSION_MAJOR} + -DGC_VERSION_MINOR=${GC_VERSION_MINOR} + -DGC_VERSION_PATCH=${GC_VERSION_PATCH} + -DGC_VERSION_HASH="${GC_VERSION_HASH}") diff --git a/include/gc-c/Dialects.h b/include/gc-c/Dialects.h index 40b20e8d0..2a8670c43 100644 --- a/include/gc-c/Dialects.h +++ b/include/gc-c/Dialects.h @@ -26,7 +26,9 @@ extern "C" { #endif +#ifdef GC_HAS_ONEDNN_DIALECT MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(OneDNNGraph, onednn_graph); +#endif MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(CPURuntime, cpuruntime); #ifdef __cplusplus diff --git a/include/gc/Dialect/OneDNNGraph/CMakeLists.txt b/include/gc/Dialect/OneDNNGraph/CMakeLists.txt index 63dfde793..1b1f00222 100644 --- a/include/gc/Dialect/OneDNNGraph/CMakeLists.txt +++ b/include/gc/Dialect/OneDNNGraph/CMakeLists.txt @@ -1,3 +1,8 @@ +if (NOT GC_ENABLE_DNNL) + message(STATUS "OneDNNGraphDialect is not enabled.") + return() +endif () + add_mlir_dialect(OneDNNGraphOps onednn_graph) add_mlir_doc(OneDNNGraphOps OneDNNGraphOps gc/Dialect/OneDNNGraph/ -gen-op-doc) add_mlir_doc(OneDNNGraphDialect OneDNNGraphDialect gc/Dialect/OneDNNGraph/ -gen-dialect-doc) diff --git a/include/gc/Transforms/CMakeLists.txt b/include/gc/Transforms/CMakeLists.txt index fdc68e6a7..299e5c344 100644 --- a/include/gc/Transforms/CMakeLists.txt +++ b/include/gc/Transforms/CMakeLists.txt @@ -1,5 +1,12 @@ +if(GC_ENABLE_DNNL) + list(APPEND TABLEGEN_MACROS -DGC_HAS_ONEDNN_DIALECT) +endif() +if(GC_ENABLE_IMEX) + list(APPEND TABLEGEN_MACROS -DGC_USE_IMEX) +endif() + set(LLVM_TARGET_DEFINITIONS Passes.td) -mlir_tablegen(Passes.h.inc -gen-pass-decls -name GraphCompiler) +mlir_tablegen(Passes.h.inc -gen-pass-decls -name GraphCompiler ${TABLEGEN_MACROS}) mlir_tablegen(Passes.capi.h.inc -gen-pass-capi-header --prefix GraphCompiler) mlir_tablegen(Passes.capi.cpp.inc -gen-pass-capi-impl --prefix GraphCompiler) add_public_tablegen_target(GraphCompilerPassIncGen) diff --git a/include/gc/Transforms/Passes.td b/include/gc/Transforms/Passes.td index 79a62f028..0d5274eb9 100644 --- a/include/gc/Transforms/Passes.td +++ b/include/gc/Transforms/Passes.td @@ -17,6 +17,7 @@ def TileLinalgNamed : Pass<"tile-named-linalg", "func::FuncOp"> { ["linalg::LinalgDialect", "scf::SCFDialect", "tensor::TensorDialect"]; } +#ifdef GC_HAS_ONEDNN_DIALECT def ConvertOneDNNGraphToLinalg : Pass<"convert-onednn-graph-to-linalg"> { let summary = "Lower the operations from the oneDNN Graph dialect into Linalg"; let description = [{ @@ -31,8 +32,9 @@ def ConvertOneDNNGraphToLinalg : Pass<"convert-onednn-graph-to-linalg"> { "linalgx::LinalgxDialect" ]; } +#endif -#ifdef GC_USE_GPU +#ifdef GC_USE_IMEX def LinalgToXeGPU : Pass<"linalg-to-xegpu", "func::FuncOp"> { let summary = "Convert linalg dialect to XeGPU dialect."; let description = [{ diff --git a/lib/gc/CAPI/CMakeLists.txt b/lib/gc/CAPI/CMakeLists.txt index f7738c064..30b684b3c 100644 --- a/lib/gc/CAPI/CMakeLists.txt +++ b/lib/gc/CAPI/CMakeLists.txt @@ -1,11 +1,10 @@ -set(GC_ALL_LIBS - MLIROneDNNGraph - MLIRCPURuntimeDialect - GCPasses +set(GC_ALL_LIBS + ${GC_ONEDNN_DIALECT_LIB_NAME} + GcPasses MLIRCPURuntimeTransforms) -if(GC_USE_GPU) - list(APPEND GC_ALL_LIBS GCGPUPasses) +if(GC_ENABLE_IMEX) + list(APPEND GC_ALL_LIBS GcGpuPasses) endif() add_mlir_public_c_api_library(GcCAPI @@ -13,4 +12,6 @@ add_mlir_public_c_api_library(GcCAPI Passes.cpp LINK_LIBS PUBLIC ${GC_ALL_LIBS} -) \ No newline at end of file +) +target_link_libraries(obj.GcCAPI PUBLIC GcInterface) +set_property(GLOBAL APPEND PROPERTY GC_MLIR_LIBS GcCAPI) diff --git a/lib/gc/CAPI/Dialects.cpp b/lib/gc/CAPI/Dialects.cpp index 27bca9e8b..77003c5a0 100644 --- a/lib/gc/CAPI/Dialects.cpp +++ b/lib/gc/CAPI/Dialects.cpp @@ -8,11 +8,13 @@ #include "gc-c/Dialects.h" #include "gc/Dialect/CPURuntime/IR/CPURuntimeDialect.h" -#include "gc/Dialect/OneDNNGraph/OneDNNGraphDialect.h" #include "mlir/CAPI/Registration.h" +#ifdef GC_HAS_ONEDNN_DIALECT +#include "gc/Dialect/OneDNNGraph/OneDNNGraphDialect.h" MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(OneDNNGraph, onednn_graph, mlir::onednn_graph::OneDNNGraphDialect) +#endif MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(CPURuntime, cpuruntime, mlir::cpuruntime::CPURuntimeDialect) \ No newline at end of file diff --git a/lib/gc/CMakeLists.txt b/lib/gc/CMakeLists.txt index 781e46a63..7e955ffe9 100644 --- a/lib/gc/CMakeLists.txt +++ b/lib/gc/CMakeLists.txt @@ -1,9 +1,3 @@ -if(GC_MLIR_CXX_FLAGS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GC_MLIR_CXX_FLAGS}") -endif() - -include(functions) - add_subdirectory(CAPI) add_subdirectory(Dialect) add_subdirectory(Transforms) diff --git a/lib/gc/Dialect/CPURuntime/IR/CMakeLists.txt b/lib/gc/Dialect/CPURuntime/IR/CMakeLists.txt index 8d92804d6..c79ea0855 100644 --- a/lib/gc/Dialect/CPURuntime/IR/CMakeLists.txt +++ b/lib/gc/Dialect/CPURuntime/IR/CMakeLists.txt @@ -1,16 +1,14 @@ gc_set_mlir_link_components(MLIR_LINK_COMPONENTS MLIRFuncDialect) -add_mlir_dialect_library(MLIRCPURuntimeDialect +gc_add_mlir_dialect_library(MLIRCPURuntimeDialect CPURuntimeDialect.cpp CPURuntimeOps.cpp - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/ - DEPENDS MLIRCPURuntimeOpsIncGen MLIRCPURuntimePassesIncGen LINK_LIBS PUBLIC ${MLIR_LINK_COMPONENTS} + GcInterface ) diff --git a/lib/gc/Dialect/CPURuntime/Transforms/CMakeLists.txt b/lib/gc/Dialect/CPURuntime/Transforms/CMakeLists.txt index 52c0d7441..7243bbebd 100644 --- a/lib/gc/Dialect/CPURuntime/Transforms/CMakeLists.txt +++ b/lib/gc/Dialect/CPURuntime/Transforms/CMakeLists.txt @@ -3,15 +3,13 @@ gc_set_mlir_link_components(MLIR_LINK_COMPONENTS MLIRFuncDialect) add_mlir_dialect_library(MLIRCPURuntimeTransforms CPURuntimeToLLVM.cpp - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/ - DEPENDS MLIRCPURuntimePassesIncGen LINK_LIBS PUBLIC ${MLIR_LINK_COMPONENTS} MLIRCPURuntimeDialect + GcInterface ) - +target_link_libraries(obj.MLIRCPURuntimeTransforms PUBLIC GcInterface) set_property(GLOBAL APPEND PROPERTY GC_PASS_LIBS MLIRCPURuntimeTransforms) \ No newline at end of file diff --git a/lib/gc/Dialect/Linalgx/CMakeLists.txt b/lib/gc/Dialect/Linalgx/CMakeLists.txt index 636760331..e225efe97 100644 --- a/lib/gc/Dialect/Linalgx/CMakeLists.txt +++ b/lib/gc/Dialect/Linalgx/CMakeLists.txt @@ -1,17 +1,17 @@ gc_set_mlir_link_components(MLIR_LINK_COMPONENTS MLIRIR) -add_mlir_dialect_library(MLIRLinalgx +gc_add_mlir_dialect_library(MLIRLinalgx LinalgxDialect.cpp LinalgxOps.cpp - + ADDITIONAL_HEADER_DIRS ${PROJECT_SOURCE_DIR}/include/gc/Dialect/Linalgx - + DEPENDS MLIRLinalgxOpsIncGen MLIRLinalgxStructuredOpsIncGen LINK_LIBS PUBLIC ${MLIR_LINK_COMPONENTS} -) -set_property(GLOBAL APPEND PROPERTY GC_DIALECT_LIBS MLIRLinalgx) \ No newline at end of file + GcInterface +) \ No newline at end of file diff --git a/lib/gc/Dialect/Microkernel/CMakeLists.txt b/lib/gc/Dialect/Microkernel/CMakeLists.txt index 029f00cce..33e420f2e 100644 --- a/lib/gc/Dialect/Microkernel/CMakeLists.txt +++ b/lib/gc/Dialect/Microkernel/CMakeLists.txt @@ -1,18 +1,18 @@ gc_set_mlir_link_components(MLIR_LINK_COMPONENTS MLIRIR) -add_mlir_dialect_library(MLIRMicrokernel +gc_add_mlir_dialect_library(MLIRMicrokernel MicrokernelEnum.cpp MicrokernelDialect.cpp MicrokernelOps.cpp - + ADDITIONAL_HEADER_DIRS ${PROJECT_SOURCE_DIR}/include/gc/Dialect/Microkernel - + DEPENDS MLIRMicrokernelOpsIncGen LINK_LIBS PUBLIC ${MLIR_LINK_COMPONENTS} - GCUtilsIR + GcInterface + GcUtilsIR ) -set_property(GLOBAL APPEND PROPERTY GC_DIALECT_LIBS MLIRMicrokernel) diff --git a/lib/gc/Dialect/OneDNNGraph/CMakeLists.txt b/lib/gc/Dialect/OneDNNGraph/CMakeLists.txt index a030820ee..56bb58f95 100644 --- a/lib/gc/Dialect/OneDNNGraph/CMakeLists.txt +++ b/lib/gc/Dialect/OneDNNGraph/CMakeLists.txt @@ -1,5 +1,11 @@ +if (NOT GC_ENABLE_DNNL) + return() +endif () + +target_compile_options(GcInterface INTERFACE -DGC_HAS_ONEDNN_DIALECT) + gc_set_mlir_link_components(MLIR_LINK_COMPONENTS MLIRIR) -add_mlir_dialect_library(MLIROneDNNGraph +gc_add_mlir_dialect_library(${GC_ONEDNN_DIALECT_LIB_NAME} OneDNNGraphDialect.cpp OneDNNGraphOps.cpp @@ -7,9 +13,9 @@ add_mlir_dialect_library(MLIROneDNNGraph ${PROJECT_SOURCE_DIR}/include/gc/Dialect/OneDNNGraph DEPENDS - MLIROneDNNGraphOpsIncGen + ${GC_ONEDNN_DIALECT_LIB_NAME}OpsIncGen LINK_LIBS PUBLIC ${MLIR_LINK_COMPONENTS} + GcInterface ) -set_property(GLOBAL APPEND PROPERTY GC_DIALECT_LIBS MLIROneDNNGraph) \ No newline at end of file diff --git a/lib/gc/ExecutionEngine/CMakeLists.txt b/lib/gc/ExecutionEngine/CMakeLists.txt index d5279b044..f13a27b1a 100644 --- a/lib/gc/ExecutionEngine/CMakeLists.txt +++ b/lib/gc/ExecutionEngine/CMakeLists.txt @@ -1,5 +1,5 @@ add_subdirectory(CPURuntime) add_subdirectory(Driver) -if(GC_USE_GPU) +if(GC_ENABLE_IMEX) add_subdirectory(OpenCLRuntime) endif() \ No newline at end of file diff --git a/lib/gc/ExecutionEngine/CPURuntime/CMakeLists.txt b/lib/gc/ExecutionEngine/CPURuntime/CMakeLists.txt index 6be58e28f..faeb0ff60 100644 --- a/lib/gc/ExecutionEngine/CPURuntime/CMakeLists.txt +++ b/lib/gc/ExecutionEngine/CPURuntime/CMakeLists.txt @@ -1,15 +1,20 @@ find_package(OpenMP REQUIRED) -if ("iomp" IN_LIST OpenMP_C_LIB_NAMES OR "omp" IN_LIST OpenMP_C_LIB_NAMES OR "omp5" IN_LIST OpenMP_C_LIB_NAMES) -else() - add_definitions("-DGC_NEEDS_OMP_WRAPPER=1") -endif() - -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") -add_mlir_library(GCCpuRuntime +gc_add_mlir_library(GcCpuRuntime SHARED Parallel.cpp + LINK_LIBS PUBLIC + GcInterface + EXCLUDE_FROM_LIBMLIR - ) \ No newline at end of file +) + +if ("iomp" IN_LIST OpenMP_C_LIB_NAMES OR "omp" IN_LIST OpenMP_C_LIB_NAMES OR "omp5" IN_LIST OpenMP_C_LIB_NAMES) +else() + target_compile_options(GcCpuRuntime PRIVATE "-DGC_NEEDS_OMP_WRAPPER") +endif() + +string(REPLACE " " ";" flags "${OpenMP_C_FLAGS} ${OpenMP_CXX_FLAGS}") +target_compile_options(GcCpuRuntime PUBLIC ${flags}) +target_link_options(GcCpuRuntime PUBLIC ${flags}) diff --git a/lib/gc/ExecutionEngine/CPURuntime/Parallel.cpp b/lib/gc/ExecutionEngine/CPURuntime/Parallel.cpp index 3a5b4c2c1..4b658b320 100644 --- a/lib/gc/ExecutionEngine/CPURuntime/Parallel.cpp +++ b/lib/gc/ExecutionEngine/CPURuntime/Parallel.cpp @@ -10,9 +10,12 @@ #include #include #include -#include #include +#ifdef GC_NEEDS_OMP_WRAPPER +#include +#endif + #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) @@ -65,7 +68,7 @@ void gc_init_barrier(barrier_t *b, int num_barriers, uint64_t thread_count) { } } -#if GC_NEEDS_OMP_WRAPPER +#ifdef GC_NEEDS_OMP_WRAPPER void WEAK_SYMBOL __kmpc_barrier(void *loc, int32_t global_tid) { #pragma omp barrier } diff --git a/lib/gc/ExecutionEngine/Driver/CMakeLists.txt b/lib/gc/ExecutionEngine/Driver/CMakeLists.txt index 8742ef6e9..a0309dea8 100644 --- a/lib/gc/ExecutionEngine/Driver/CMakeLists.txt +++ b/lib/gc/ExecutionEngine/Driver/CMakeLists.txt @@ -26,21 +26,17 @@ else() ) endif() -set(GC_PASSES GCPasses) -if(GC_USE_GPU) - list(APPEND GC_PASSES GCGPUPasses) +set(GC_PASSES GcInterface GcPasses) +if(GC_UNABLE_GPU) + list(APPEND GC_PASSES GcGpuPasses) endif() -add_mlir_library(GCJitWrapper +gc_add_mlir_library(GcJitWrapper Driver.cpp - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include - LINK_LIBS PUBLIC ${MLIR_LINK_COMPONENTS} ${dialect_libs} ${conversion_libs} ${GC_PASSES} ) - diff --git a/lib/gc/ExecutionEngine/Driver/Driver.cpp b/lib/gc/ExecutionEngine/Driver/Driver.cpp index 0f2361924..16da521d0 100644 --- a/lib/gc/ExecutionEngine/Driver/Driver.cpp +++ b/lib/gc/ExecutionEngine/Driver/Driver.cpp @@ -8,7 +8,9 @@ #include "gc/ExecutionEngine/Driver/Driver.h" #include "gc/Dialect/CPURuntime/Transforms/CPURuntimePasses.h" +#ifdef GC_HAS_ONEDNN_DIALECT #include "gc/Dialect/OneDNNGraph/OneDNNGraphDialect.h" +#endif #include "gc/Transforms/Passes.h" #include "mlir/InitAllDialects.h" #include "mlir/InitAllPasses.h" @@ -29,7 +31,9 @@ static DialectRegistry initDialects() { registry.insert(); mlir::registerAllDialects(registry); mlir::cpuruntime::registerConvertCPURuntimeToLLVMInterface(registry); +#ifdef GC_HAS_ONEDNN_DIALECT registry.insert(); +#endif llvm::InitializeNativeTarget(); llvm::InitializeNativeTargetAsmPrinter(); llvm::InitializeNativeTargetAsmParser(); diff --git a/lib/gc/ExecutionEngine/OpenCLRuntime/CMakeLists.txt b/lib/gc/ExecutionEngine/OpenCLRuntime/CMakeLists.txt index 62163496f..466c67158 100644 --- a/lib/gc/ExecutionEngine/OpenCLRuntime/CMakeLists.txt +++ b/lib/gc/ExecutionEngine/OpenCLRuntime/CMakeLists.txt @@ -1,6 +1,6 @@ find_package(OpenCL REQUIRED) -add_mlir_library(mlir_opencl_runtime +gc_add_mlir_library(GcOpenclRuntime SHARED OpenCLRuntimeWrappers.cpp @@ -11,12 +11,12 @@ check_cxx_compiler_flag("-frtti" CXX_HAS_FRTTI_FLAG) if(NOT CXX_HAS_FRTTI_FLAG) message(FATAL_ERROR "CXX compiler does not accept flag -frtti") endif() -target_compile_options (mlir_opencl_runtime PUBLIC -fexceptions -frtti) +target_compile_options (GcOpenclRuntime PUBLIC -fexceptions -frtti) -target_include_directories(mlir_opencl_runtime PRIVATE +target_include_directories(GcOpenclRuntime PRIVATE ${MLIR_INCLUDE_DIRS} ${OpenCL_INCLUDE_DIRS} ) message(STATUS "OpenCL Libraries: ${OpenCL_LIBRARIES}") -target_link_libraries(mlir_opencl_runtime PUBLIC ${OpenCL_LIBRARIES}) +target_link_libraries(GcOpenclRuntime PUBLIC ${OpenCL_LIBRARIES}) diff --git a/lib/gc/ExecutionEngine/OpenCLRuntime/OpenCLRuntimeWrappers.cpp b/lib/gc/ExecutionEngine/OpenCLRuntime/OpenCLRuntimeWrappers.cpp index b78ca2233..b7675b9f7 100644 --- a/lib/gc/ExecutionEngine/OpenCLRuntime/OpenCLRuntimeWrappers.cpp +++ b/lib/gc/ExecutionEngine/OpenCLRuntime/OpenCLRuntimeWrappers.cpp @@ -13,7 +13,9 @@ #include #include #include +#include #include +#include #include #ifdef _WIN32 diff --git a/lib/gc/Transforms/CMakeLists.txt b/lib/gc/Transforms/CMakeLists.txt index f60c8cec2..08ae24143 100644 --- a/lib/gc/Transforms/CMakeLists.txt +++ b/lib/gc/Transforms/CMakeLists.txt @@ -9,14 +9,11 @@ gc_set_mlir_link_components(MLIR_LINK_COMPONENTS get_property(mlir_dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) get_property(mlir_conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) -add_mlir_library(GCPasses +gc_add_mlir_library(GcPasses OneDNNGraphToLinalg.cpp Pipeline.cpp TileNamed.cpp - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include - DEPENDS GraphCompilerPassIncGen @@ -24,10 +21,10 @@ add_mlir_library(GCPasses ${mlir_dialect_libs} ${mlir_conversion_libs} ${MLIR_LINK_COMPONENTS} - MLIROneDNNGraph + ${GC_ONEDNN_DIALECT_LIB_NAME} + GcInterface ) -set_property(GLOBAL APPEND PROPERTY GC_PASS_LIBS GCPasses) -if(GC_USE_GPU) +if(GC_ENABLE_IMEX) add_subdirectory(GPU) endif() diff --git a/lib/gc/Transforms/GPU/CMakeLists.txt b/lib/gc/Transforms/GPU/CMakeLists.txt index d730db5a3..18a7434e2 100644 --- a/lib/gc/Transforms/GPU/CMakeLists.txt +++ b/lib/gc/Transforms/GPU/CMakeLists.txt @@ -1,9 +1,6 @@ -add_mlir_library(GCGPUPasses +gc_add_mlir_library(GcGpuPasses LinalgToXeGPU.cpp - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include - DEPENDS GraphCompilerPassIncGen @@ -17,7 +14,7 @@ add_mlir_library(GCGPUPasses MLIRMathToSPIRV MLIRControlFlowToSPIRV MLIRMemRefTransforms - GCUtilsIR + GcInterface + GcUtilsIR ) -set_property(GLOBAL APPEND PROPERTY GC_PASS_LIBS GCGPUPasses) diff --git a/lib/gc/Transforms/OneDNNGraphToLinalg.cpp b/lib/gc/Transforms/OneDNNGraphToLinalg.cpp index c472dbe87..5a75c37cd 100644 --- a/lib/gc/Transforms/OneDNNGraphToLinalg.cpp +++ b/lib/gc/Transforms/OneDNNGraphToLinalg.cpp @@ -5,6 +5,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// +#ifdef GC_HAS_ONEDNN_DIALECT #include #include @@ -560,3 +561,5 @@ struct ConvertOneDNNGraphToLinalg } // namespace } // namespace gc } // namespace mlir + +#endif // GC_HAS_ONEDNN_DIALECT diff --git a/lib/gc/Transforms/Pipeline.cpp b/lib/gc/Transforms/Pipeline.cpp index 29a143835..7d487f149 100644 --- a/lib/gc/Transforms/Pipeline.cpp +++ b/lib/gc/Transforms/Pipeline.cpp @@ -27,14 +27,18 @@ #include "gc/Dialect/CPURuntime/Transforms/CPURuntimePasses.h" #include "gc/Dialect/Linalgx/LinalgxDialect.h" +#ifdef GC_HAS_ONEDNN_DIALECT #include "gc/Dialect/OneDNNGraph/OneDNNGraphDialect.h" +#endif #include "gc/Transforms/Passes.h" namespace mlir::gc { // linalg + linalgX + tensor void populateFrontendPasses(mlir::OpPassManager &pm) { +#ifdef GC_HAS_ONEDNN_DIALECT pm.addPass(createConvertOneDNNGraphToLinalg()); +#endif } // scf + arith + math + vector + tensor + linalg.brgemm + tensor.pack/unpack diff --git a/lib/gc/Transforms/Utils/CMakeLists.txt b/lib/gc/Transforms/Utils/CMakeLists.txt index ce4d7f0b0..94b700435 100644 --- a/lib/gc/Transforms/Utils/CMakeLists.txt +++ b/lib/gc/Transforms/Utils/CMakeLists.txt @@ -1,11 +1,11 @@ -add_mlir_library(GCUtilsIR +gc_add_mlir_library(GcUtilsIR MatcherUtils.cpp StructuredOpMatcher.cpp ValueUtils.cpp - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include - DEPENDS MLIRLinalgDialect + + LINK_LIBS PUBLIC + GcInterface ) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 2aef3f17a..54a3f7a04 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -15,6 +15,19 @@ # SPDX-License-Identifier: Apache-2.0 ################################################################################ +if(GC_ENABLE_BINDINGS_PYTHON) + if(NOT MLIR_ENABLE_BINDINGS_PYTHON) + message(STATUS "Failed to enable Python API due to the 'MLIR_ENABLE_BINDINGS_PYTHON' for LLVM is not ON.") + set(GC_ENABLE_BINDINGS_PYTHON OFF CACHE BOOL "" FORCE) + return() + endif() + message(STATUS "Enabling Python API") +else() + return() +endif() + +include(MLIRDetectPythonEnv) +mlir_configure_python_dev_packages() include(AddMLIRPython) # Specifies that all MLIR packages are co-located under the `gc_mlir` @@ -84,6 +97,7 @@ add_mlir_python_common_capi_library(GcPythonCAPI MLIRPythonExtension.RegisterEverything MLIRPythonSources.Core ) +target_link_libraries(GcPythonCAPI PUBLIC GcInterface) ################################################################################ # Instantiation of all Python modules diff --git a/scripts/compile.sh b/scripts/compile.sh index 1e5234061..45b64383e 100755 --- a/scripts/compile.sh +++ b/scripts/compile.sh @@ -11,23 +11,27 @@ print_usage() { cat < #include #endif @@ -36,7 +38,7 @@ void registerCPUPipeline(); } // namespace mlir::gc int main(int argc, char *argv[]) { -#ifdef GC_USE_GPU +#ifdef GC_USE_IMEX imex::registerTransformsPasses(); // Conversion passes imex::registerConvertGPUToGPUX(); @@ -50,12 +52,14 @@ int main(int argc, char *argv[]) { mlir::gc::registerGraphCompilerPasses(); mlir::cpuruntime::registerCPURuntimePasses(); mlir::DialectRegistry registry; +#ifdef GC_HAS_ONEDNN_DIALECT registry.insert(); +#endif registry.insert(); registry.insert(); registry.insert(); mlir::registerAllDialects(registry); -#ifdef GC_USE_GPU +#ifdef GC_USE_IMEX registry.insert<::imex::xetile::XeTileDialect, ::imex::gpux::GPUXDialect>(); #endif mlir::cpuruntime::registerConvertCPURuntimeToLLVMInterface(registry); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c210b46c6..4e4036b19 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,15 +1,8 @@ -if (NOT GC_TEST_ENABLE) +if (NOT GC_ENABLE_TEST) message(STATUS "The tests are not enabled.") return() endif () include(gtest) - -# Static graph compiler library to be used in tests -add_mlir_library(graph_compiler_static STATIC ${GC_LIB_SOURCES}) -target_compile_options(obj.graph_compiler_static PUBLIC -fexceptions) -target_include_directories(graph_compiler_static PUBLIC ${GC_LIB_INCLUDES}) -target_link_libraries(graph_compiler_static PUBLIC ${GC_LIB_LINKED_LIBS}) - add_subdirectory(dnnl) add_subdirectory(mlir) diff --git a/test/dnnl/CMakeLists.txt b/test/dnnl/CMakeLists.txt index 65c62f8ce..18d7d421a 100644 --- a/test/dnnl/CMakeLists.txt +++ b/test/dnnl/CMakeLists.txt @@ -1,3 +1,7 @@ +if (NOT GC_ENABLE_TEST OR NOT GC_ENABLE_TEST_DNNL OR NOT GC_ENABLE_DNNL) + message(STATUS "The dnnl tests are not enabled.") + return() +endif () # Copy resources to the build directory file(GLOB_RECURSE TEST_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*) @@ -9,14 +13,13 @@ file(GLOB TEST_SOURCES Test*.cpp) foreach (TEST_SOURCE ${TEST_SOURCES}) get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE) add_executable(${TEST_NAME} ${TEST_SOURCE}) - target_include_directories(${TEST_NAME} PRIVATE ${GC_LIB_INCLUDES}) if (${TEST_NAME} MATCHES "^TestApi.*") # The API tests are linked with the shared lib - target_link_libraries(${TEST_NAME} PRIVATE LLVMSupport graph_compiler) + target_link_libraries(${TEST_NAME} PRIVATE LLVMSupport GcDnnl) else () # The other tests are linked with the static lib and have non-public includes - target_link_libraries(${TEST_NAME} PRIVATE graph_compiler_static) - target_include_directories(${TEST_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src/dnnl) + target_link_libraries(${TEST_NAME} PRIVATE GcDnnlStatic) + target_include_directories(${TEST_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/src/dnnl) endif () target_link_libraries(${TEST_NAME} PRIVATE gtest gtest_main) add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME}) diff --git a/test/mlir/CMakeLists.txt b/test/mlir/CMakeLists.txt index 4dbde976d..a15ffe0e5 100644 --- a/test/mlir/CMakeLists.txt +++ b/test/mlir/CMakeLists.txt @@ -1,2 +1,7 @@ +if (NOT GC_ENABLE_TEST_MLIR) + message(STATUS "The mlir tests are not enabled.") + return() +endif () + add_subdirectory(test) add_subdirectory(unittests) diff --git a/test/mlir/test/CMakeLists.txt b/test/mlir/test/CMakeLists.txt index 7ac5a89c6..a8776a957 100644 --- a/test/mlir/test/CMakeLists.txt +++ b/test/mlir/test/CMakeLists.txt @@ -23,9 +23,9 @@ set(GC_OPT_TEST_DEPENDS GCUnitTests ) -if(GC_USE_GPU) +if(GC_ENABLE_IMEX) include(imex) - list(APPEND GC_OPT_TEST_DEPENDS mlir_opencl_runtime) + list(APPEND GC_OPT_TEST_DEPENDS GcOpenclRuntime) endif() if(GC_ENABLE_BINDINGS_PYTHON) diff --git a/test/mlir/test/gc/Transforms/GPU/lit.local.cfg b/test/mlir/test/gc/Transforms/GPU/lit.local.cfg index f086e9be8..f180dd41b 100644 --- a/test/mlir/test/gc/Transforms/GPU/lit.local.cfg +++ b/test/mlir/test/gc/Transforms/GPU/lit.local.cfg @@ -1,2 +1,2 @@ -if not config.gc_use_gpu: +if not config.gc_use_imex: config.unsupported = True \ No newline at end of file diff --git a/test/mlir/test/gc/gpu-runner/lit.local.cfg b/test/mlir/test/gc/gpu-runner/lit.local.cfg index f086e9be8..f180dd41b 100644 --- a/test/mlir/test/gc/gpu-runner/lit.local.cfg +++ b/test/mlir/test/gc/gpu-runner/lit.local.cfg @@ -1,2 +1,2 @@ -if not config.gc_use_gpu: +if not config.gc_use_imex: config.unsupported = True \ No newline at end of file diff --git a/test/mlir/test/lit.cfg.py b/test/mlir/test/lit.cfg.py index d53e105e1..b618568e7 100644 --- a/test/mlir/test/lit.cfg.py +++ b/test/mlir/test/lit.cfg.py @@ -33,7 +33,7 @@ config.substitutions.append(('%mlir_runner_utils', config.mlir_runner_utils)) config.substitutions.append(('%mlir_c_runner_utils', config.mlir_c_runner_utils)) -if config.gc_use_gpu: +if config.gc_use_imex: config.substitutions.append(('%opencl_runtime', config.opencl_runtime)) llvm_config.with_system_environment(["HOME", "INCLUDE", "LIB", "TMP", "TEMP"]) diff --git a/test/mlir/test/lit.site.cfg.py.in b/test/mlir/test/lit.site.cfg.py.in index 6bea6d13e..82d7ddcbc 100644 --- a/test/mlir/test/lit.site.cfg.py.in +++ b/test/mlir/test/lit.site.cfg.py.in @@ -30,11 +30,11 @@ config.host_ldflags = '@HOST_LDFLAGS@' config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@" config.llvm_host_triple = '@LLVM_HOST_TRIPLE@' config.host_arch = "@HOST_ARCH@" -config.gc_src_root = "@CMAKE_SOURCE_DIR@" -config.gc_obj_root = "@CMAKE_BINARY_DIR@" +config.gc_src_root = "@PROJECT_SOURCE_DIR@" +config.gc_obj_root = "@PROJECT_BINARY_DIR@" config.gc_lib_dir = os.path.join(config.gc_obj_root, "lib") config.mlir_obj_dir = "@MLIR_BINARY_DIR@" -config.gc_use_gpu = "@GC_USE_GPU@" in ["ON", "1"] +config.gc_use_imex = "@GC_ENABLE_IMEX@" in ["ON", "1"] config.enable_bindings_python = @GC_ENABLE_BINDINGS_PYTHON@ config.llvm_shlib_dir = "@SHLIBDIR@" config.llvm_shlib_ext = "@SHLIBEXT@" @@ -42,10 +42,10 @@ config.mlir_runner_utils_dir = "@MLIR_RUNNER_UTILS_DIR@" config.mlir_runner_utils = os.path.normpath(os.path.join(config.mlir_runner_utils_dir, config.shlib_prefix + "mlir_runner_utils" + config.llvm_shlib_ext)) config.mlir_c_runner_utils = os.path.normpath(os.path.join(config.mlir_runner_utils_dir, config.shlib_prefix + "mlir_c_runner_utils" + config.llvm_shlib_ext)) -config.opencl_runtime = os.path.normpath(os.path.join(config.gc_lib_dir, config.shlib_prefix + "mlir_opencl_runtime" + config.llvm_shlib_ext)) +config.opencl_runtime = os.path.normpath(os.path.join(config.gc_lib_dir, config.shlib_prefix + "GcOpenclRuntime" + config.llvm_shlib_ext)) import lit.llvm lit.llvm.initialize(lit_config, config) # Let the main config do the real work. -lit_config.load_config(config, "@CMAKE_SOURCE_DIR@/test/mlir/test/lit.cfg.py") +lit_config.load_config(config, "@PROJECT_SOURCE_DIR@/test/mlir/test/lit.cfg.py") diff --git a/test/mlir/unittests/CMakeLists.txt b/test/mlir/unittests/CMakeLists.txt index 8bdb63b68..0ad5b02d0 100644 --- a/test/mlir/unittests/CMakeLists.txt +++ b/test/mlir/unittests/CMakeLists.txt @@ -1,6 +1,3 @@ -if(GC_MLIR_CXX_FLAGS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GC_MLIR_CXX_FLAGS}") -endif() add_definitions(-DMLIR_INCLUDE_TESTS) add_custom_target(GCUnitTests) set_target_properties(GCUnitTests PROPERTIES FOLDER "MLIR GC Tests") diff --git a/test/mlir/unittests/ExecutionEngine/CMakeLists.txt b/test/mlir/unittests/ExecutionEngine/CMakeLists.txt index 0e7315a0f..2cfe3f77e 100644 --- a/test/mlir/unittests/ExecutionEngine/CMakeLists.txt +++ b/test/mlir/unittests/ExecutionEngine/CMakeLists.txt @@ -3,5 +3,5 @@ add_mlir_unittest(GCExecutionEngineTests ) target_link_libraries(GCExecutionEngineTests PRIVATE - GCJitWrapper - GCCpuRuntime) + GcJitWrapper + GcCpuRuntime)