From edd619d8aa5a2e169436955a769fdb6dc2b86136 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Wed, 24 Jul 2024 04:03:35 +0200 Subject: [PATCH 1/4] Make the project compatible with FetchContent and find_package to simplify integration with thirdparty projects. - Use the Gc prefix in the target names. - Added a separate shared library for oneDNN integration - GcDnnl. - The GcDnnl library and the OneDNNGraphDialect are not built if GC_ENABLE_DNNL=OFF. - Added new build options: GC_ENABLE_TEST(renamed), GC_ENABLE_TEST_DNNL, GC_ENABLE_TEST_MLIR, GC_ENABLE_OPT. - Renamed the GC_USE_GPU option to GC_ENABLE_GPU to be consistent with other options. - Export the OpenMP flags to resolve the "JIT session error: Symbols not found: __kmpc_...". - Minor compile.sh script enhancements. --- CMakeLists.txt | 103 ++++++++++++++---- README.md | 18 +-- cmake/Config.cmake.in | 5 + cmake/functions.cmake | 38 ++----- cmake/imex.cmake | 11 +- cmake/onednn.cmake | 4 +- include/gc-c/Dialects.h | 2 + include/gc/Dialect/OneDNNGraph/CMakeLists.txt | 5 + include/gc/Transforms/CMakeLists.txt | 9 +- include/gc/Transforms/Passes.td | 2 + lib/gc/CAPI/CMakeLists.txt | 8 +- lib/gc/CAPI/Dialects.cpp | 4 +- lib/gc/Dialect/Microkernel/CMakeLists.txt | 2 +- lib/gc/Dialect/OneDNNGraph/CMakeLists.txt | 10 +- .../ExecutionEngine/CPURuntime/CMakeLists.txt | 20 ++-- .../ExecutionEngine/CPURuntime/Parallel.cpp | 7 +- lib/gc/ExecutionEngine/Driver/CMakeLists.txt | 8 +- lib/gc/ExecutionEngine/Driver/Driver.cpp | 4 + lib/gc/Transforms/CMakeLists.txt | 4 +- lib/gc/Transforms/GPU/CMakeLists.txt | 6 +- lib/gc/Transforms/OneDNNGraphToLinalg.cpp | 3 + lib/gc/Transforms/Pipeline.cpp | 4 + lib/gc/Transforms/Utils/CMakeLists.txt | 2 +- scripts/compile.sh | 93 +++++++++------- src/dnnl/CMakeLists.txt | 30 ++++- src/gc-cpu-runner/CMakeLists.txt | 2 +- src/gc-opt/CMakeLists.txt | 22 ++-- src/gc-opt/gc-opt.cpp | 4 + test/CMakeLists.txt | 9 +- test/dnnl/CMakeLists.txt | 11 +- test/mlir/CMakeLists.txt | 5 + test/mlir/test/CMakeLists.txt | 2 +- test/mlir/test/lit.site.cfg.py.in | 8 +- .../unittests/ExecutionEngine/CMakeLists.txt | 4 +- 34 files changed, 301 insertions(+), 168 deletions(-) create mode 100644 cmake/Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 636b33ad2..9659e5f7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,15 +24,19 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") - -option(GC_LEGACY_ENABLE ON) -option(GC_TEST_ENABLE "Build the tests" ON) -option(GC_USE_GPU "Enable GPU backend" OFF) +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") + +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_OPT "Build gc-opt" ON) +option(GC_ENABLE_GPU "Enable GPU backend" 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) +if(GC_ENABLE_LEGACY) add_subdirectory(legacy/core) endif() @@ -41,9 +45,9 @@ 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}) +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}") @@ -53,13 +57,22 @@ include(AddLLVM) include(AddMLIR) include(HandleLLVMOptions) -if(GC_USE_GPU) +if(GC_ENABLE_DNNL) + add_definitions(-DGC_HAS_ONEDNN_DIALECT) + set(GC_ONEDNN_DIALECT_LIB_NAME MLIROneDNNGraph) +endif () + +if(GC_ENABLE_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_OPT) + set(GC_OPT_EXE_NAME gc-opt) +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) @@ -77,11 +90,6 @@ include_directories( ${PROJECT_SOURCE_DIR}/include ) -# 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 "") @@ -102,15 +110,62 @@ if(GC_ENABLE_BINDINGS_PYTHON) message(STATUS "Enabling Python API") add_subdirectory(python) endif() +add_subdirectory(test) -set(GC_LIB_LINKED_LIBS - GCJitWrapper - GCCpuRuntime +# Export the targets +add_library(GcInterface INTERFACE) +target_include_directories(GcInterface INTERFACE + $ + $ + $ +) +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ TYPE INCLUDE) +install(DIRECTORY ${PROJECT_BINARY_DIR}/include/ TYPE INCLUDE + PATTERN "CMake*" EXCLUDE PATTERN "*.cmake" EXCLUDE) +install(TARGETS + GcCpuRuntime + GcGpuPasses + GcInterface + GcJitWrapper + GcPasses + GcUtilsIR + MLIRCPURuntimeDialect + MLIRCPURuntimeTransforms + MLIRLinalgx + MLIRMicrokernel + ${GC_OPT_EXE_NAME} + ${GC_ONEDNN_DIALECT_LIB_NAME} + + 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..adcc31e7c 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 GPU components are on (`-DGC_ENABLE_GPU=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_GPU | 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..de4884b60 --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include ( "${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake" ) + +find_package(MLIR REQUIRED CONFIG) diff --git a/cmake/functions.cmake b/cmake/functions.cmake index 57885301d..8f70e89bf 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} 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/onednn.cmake b/cmake/onednn.cmake index 673c4b97e..b9f1d3036 100644 --- a/cmake/onednn.cmake +++ b/cmake/onednn.cmake @@ -8,7 +8,6 @@ if (NOT DEFINED DNNL_INCLUDES) # 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 @@ -27,6 +26,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/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..6203d3e7b 100644 --- a/include/gc/Dialect/OneDNNGraph/CMakeLists.txt +++ b/include/gc/Dialect/OneDNNGraph/CMakeLists.txt @@ -1,3 +1,8 @@ +if (NOT GC_ENABLE_TEST_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..d51c185bb 100644 --- a/include/gc/Transforms/CMakeLists.txt +++ b/include/gc/Transforms/CMakeLists.txt @@ -1,5 +1,12 @@ +if(GC_ENABLE_DNNL) + set(TABLEGEN_MACROS "${TABLEGEN_MACROS} -DGC_HAS_ONEDNN_DIALECT") +endif() +if(GC_ENABLE_GPU) + set(TABLEGEN_MACROS "${TABLEGEN_MACROS} -DGC_USE_GPU") +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..d087cd0ba 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,6 +32,7 @@ def ConvertOneDNNGraphToLinalg : Pass<"convert-onednn-graph-to-linalg"> { "linalgx::LinalgxDialect" ]; } +#endif #ifdef GC_USE_GPU def LinalgToXeGPU : Pass<"linalg-to-xegpu", "func::FuncOp"> { diff --git a/lib/gc/CAPI/CMakeLists.txt b/lib/gc/CAPI/CMakeLists.txt index f7738c064..a5133505d 100644 --- a/lib/gc/CAPI/CMakeLists.txt +++ b/lib/gc/CAPI/CMakeLists.txt @@ -1,11 +1,11 @@ set(GC_ALL_LIBS MLIROneDNNGraph - MLIRCPURuntimeDialect - GCPasses + ${GC_ONEDNN_DIALECT_LIB_NAME} + GcPasses MLIRCPURuntimeTransforms) if(GC_USE_GPU) - list(APPEND GC_ALL_LIBS GCGPUPasses) + list(APPEND GC_ALL_LIBS GcGPUPasses) endif() add_mlir_public_c_api_library(GcCAPI @@ -13,4 +13,4 @@ add_mlir_public_c_api_library(GcCAPI Passes.cpp LINK_LIBS PUBLIC ${GC_ALL_LIBS} -) \ No newline at end of file +) 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/Dialect/Microkernel/CMakeLists.txt b/lib/gc/Dialect/Microkernel/CMakeLists.txt index 029f00cce..b68701abf 100644 --- a/lib/gc/Dialect/Microkernel/CMakeLists.txt +++ b/lib/gc/Dialect/Microkernel/CMakeLists.txt @@ -13,6 +13,6 @@ add_mlir_dialect_library(MLIRMicrokernel LINK_LIBS PUBLIC ${MLIR_LINK_COMPONENTS} - GCUtilsIR + 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..4058efec5 100644 --- a/lib/gc/Dialect/OneDNNGraph/CMakeLists.txt +++ b/lib/gc/Dialect/OneDNNGraph/CMakeLists.txt @@ -1,5 +1,9 @@ +if (NOT GC_ENABLE_TEST_DNNL) + return() +endif () + gc_set_mlir_link_components(MLIR_LINK_COMPONENTS MLIRIR) -add_mlir_dialect_library(MLIROneDNNGraph +add_mlir_dialect_library(${GC_ONEDNN_DIALECT_LIB_NAME} OneDNNGraphDialect.cpp OneDNNGraphOps.cpp @@ -7,9 +11,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} ) -set_property(GLOBAL APPEND PROPERTY GC_DIALECT_LIBS MLIROneDNNGraph) \ No newline at end of file +set_property(GLOBAL APPEND PROPERTY GC_DIALECT_LIBS ${GC_ONEDNN_DIALECT_LIB_NAME}) diff --git a/lib/gc/ExecutionEngine/CPURuntime/CMakeLists.txt b/lib/gc/ExecutionEngine/CPURuntime/CMakeLists.txt index 6be58e28f..eafb2a166 100644 --- a/lib/gc/ExecutionEngine/CPURuntime/CMakeLists.txt +++ b/lib/gc/ExecutionEngine/CPURuntime/CMakeLists.txt @@ -1,15 +1,17 @@ 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 +add_mlir_library(GcCpuRuntime SHARED Parallel.cpp 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_definitions(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..9961d84d7 100644 --- a/lib/gc/ExecutionEngine/Driver/CMakeLists.txt +++ b/lib/gc/ExecutionEngine/Driver/CMakeLists.txt @@ -26,12 +26,12 @@ else() ) endif() -set(GC_PASSES GCPasses) -if(GC_USE_GPU) - list(APPEND GC_PASSES GCGPUPasses) +set(GC_PASSES GcPasses) +if(GC_UNABLE_GPU) + list(APPEND GC_PASSES GcGPUPasses) endif() -add_mlir_library(GCJitWrapper +add_mlir_library(GcJitWrapper Driver.cpp ADDITIONAL_HEADER_DIRS 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/Transforms/CMakeLists.txt b/lib/gc/Transforms/CMakeLists.txt index f60c8cec2..76e6310dc 100644 --- a/lib/gc/Transforms/CMakeLists.txt +++ b/lib/gc/Transforms/CMakeLists.txt @@ -9,7 +9,7 @@ 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 +add_mlir_library(GcPasses OneDNNGraphToLinalg.cpp Pipeline.cpp TileNamed.cpp @@ -24,7 +24,7 @@ add_mlir_library(GCPasses ${mlir_dialect_libs} ${mlir_conversion_libs} ${MLIR_LINK_COMPONENTS} - MLIROneDNNGraph + ${GC_ONEDNN_DIALECT_LIB_NAME} ) set_property(GLOBAL APPEND PROPERTY GC_PASS_LIBS GCPasses) diff --git a/lib/gc/Transforms/GPU/CMakeLists.txt b/lib/gc/Transforms/GPU/CMakeLists.txt index d730db5a3..2294c0b17 100644 --- a/lib/gc/Transforms/GPU/CMakeLists.txt +++ b/lib/gc/Transforms/GPU/CMakeLists.txt @@ -1,4 +1,4 @@ -add_mlir_library(GCGPUPasses +add_mlir_library(GcGpuPasses LinalgToXeGPU.cpp ADDITIONAL_HEADER_DIRS @@ -17,7 +17,7 @@ add_mlir_library(GCGPUPasses MLIRMathToSPIRV MLIRControlFlowToSPIRV MLIRMemRefTransforms - GCUtilsIR + GcUtilsIR ) -set_property(GLOBAL APPEND PROPERTY GC_PASS_LIBS GCGPUPasses) +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..d20de5e0a 100644 --- a/lib/gc/Transforms/Utils/CMakeLists.txt +++ b/lib/gc/Transforms/Utils/CMakeLists.txt @@ -1,4 +1,4 @@ -add_mlir_library(GCUtilsIR +add_mlir_library(GcUtilsIR MatcherUtils.cpp StructuredOpMatcher.cpp ValueUtils.cpp diff --git a/scripts/compile.sh b/scripts/compile.sh index 1e5234061..05bad8bb1 100755 --- a/scripts/compile.sh +++ b/scripts/compile.sh @@ -11,23 +11,27 @@ print_usage() { cat <(); +#endif registry.insert(); registry.insert(); registry.insert(); 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..b55241d7e 100644 --- a/test/dnnl/CMakeLists.txt +++ b/test/dnnl/CMakeLists.txt @@ -1,3 +1,7 @@ +if (NOT GC_ENABLE_TEST_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..efc16c7f8 100644 --- a/test/mlir/test/CMakeLists.txt +++ b/test/mlir/test/CMakeLists.txt @@ -23,7 +23,7 @@ set(GC_OPT_TEST_DEPENDS GCUnitTests ) -if(GC_USE_GPU) +if(GC_ENABLE_GPU) include(imex) list(APPEND GC_OPT_TEST_DEPENDS mlir_opencl_runtime) endif() diff --git a/test/mlir/test/lit.site.cfg.py.in b/test/mlir/test/lit.site.cfg.py.in index 6bea6d13e..8fe3ca786 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_gpu = "@GC_ENABLE_GPU@" in ["ON", "1"] config.enable_bindings_python = @GC_ENABLE_BINDINGS_PYTHON@ config.llvm_shlib_dir = "@SHLIBDIR@" config.llvm_shlib_ext = "@SHLIBEXT@" @@ -48,4 +48,4 @@ 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/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) From 50d0ddbb317348091ac1742083dc835d456995b2 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Wed, 31 Jul 2024 14:39:28 +0200 Subject: [PATCH 2/4] Added GC_ENABLE_IMEX option --- CMakeLists.txt | 5 +++++ src/gc-opt/CMakeLists.txt | 4 ++-- src/gc-opt/gc-opt.cpp | 6 +++--- test/mlir/test/CMakeLists.txt | 2 +- test/mlir/test/gc/gpu-runner/lit.local.cfg | 2 +- test/mlir/test/lit.site.cfg.py.in | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9659e5f7c..f22c3f143 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ 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_OPT "Build gc-opt" ON) option(GC_ENABLE_GPU "Enable GPU backend" OFF) +option(GC_ENABLE_IMEX "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) @@ -63,6 +64,10 @@ if(GC_ENABLE_DNNL) endif () if(GC_ENABLE_GPU) + add_definitions(-DGC_USE_GPU) +endif () + +if(GC_ENABLE_IMEX) include(imex) if(GC_DEV_LINK_LLVM_DYLIB) message(WARN "GPU backend may not be compatible with dynamic linking to LLVM") diff --git a/src/gc-opt/CMakeLists.txt b/src/gc-opt/CMakeLists.txt index 45eb22d40..21a20fd15 100644 --- a/src/gc-opt/CMakeLists.txt +++ b/src/gc-opt/CMakeLists.txt @@ -40,8 +40,8 @@ set(gc_opt_libs ${MLIR_LINK_COMPONENTS} GCPasses) -if(GC_ENABLE_GPU) - add_definitions(-DGC_USE_GPU=1) +if(GC_ENABLE_IMEX) + add_definitions(-DGC_USE_IMEX) get_property(IMEX_INCLUDES GLOBAL PROPERTY IMEX_INCLUDES) include_directories(${IMEX_INCLUDES}) list(APPEND gc_opt_libs IMEXGPUXDialect IMEXXeTileDialect IMEXRegionDialect IMEXRegionTransforms diff --git a/src/gc-opt/gc-opt.cpp b/src/gc-opt/gc-opt.cpp index 5543dcbe7..7526106e4 100644 --- a/src/gc-opt/gc-opt.cpp +++ b/src/gc-opt/gc-opt.cpp @@ -28,7 +28,7 @@ #include "mlir/InitAllPasses.h" #include "mlir/Tools/mlir-opt/MlirOptMain.h" -#ifdef GC_USE_GPU +#ifdef GC_USE_IMEX #include #include #endif @@ -38,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(); @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) { 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/mlir/test/CMakeLists.txt b/test/mlir/test/CMakeLists.txt index efc16c7f8..9ea39691c 100644 --- a/test/mlir/test/CMakeLists.txt +++ b/test/mlir/test/CMakeLists.txt @@ -23,7 +23,7 @@ set(GC_OPT_TEST_DEPENDS GCUnitTests ) -if(GC_ENABLE_GPU) +if(GC_ENABLE_IMEX) include(imex) list(APPEND GC_OPT_TEST_DEPENDS mlir_opencl_runtime) endif() 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.site.cfg.py.in b/test/mlir/test/lit.site.cfg.py.in index 8fe3ca786..f83acd363 100644 --- a/test/mlir/test/lit.site.cfg.py.in +++ b/test/mlir/test/lit.site.cfg.py.in @@ -34,7 +34,7 @@ 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_ENABLE_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@" From 1633679c94c7e0201dcd6f6610d0b19ee2de5575 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Thu, 1 Aug 2024 00:41:52 +0200 Subject: [PATCH 3/4] Apply suggestions from code review --- CMakeLists.txt | 173 +++++++----------- cmake/Config.cmake.in | 7 +- cmake/functions.cmake | 28 +++ cmake/gtest.cmake | 8 +- cmake/mlir.cmake | 31 ++++ cmake/onednn.cmake | 16 +- cmake/version.cmake | 10 +- include/gc/Dialect/OneDNNGraph/CMakeLists.txt | 2 +- include/gc/Transforms/CMakeLists.txt | 4 +- lib/gc/CAPI/CMakeLists.txt | 7 +- lib/gc/CMakeLists.txt | 6 - lib/gc/Dialect/CPURuntime/IR/CMakeLists.txt | 6 +- .../CPURuntime/Transforms/CMakeLists.txt | 6 +- lib/gc/Dialect/Linalgx/CMakeLists.txt | 10 +- lib/gc/Dialect/Microkernel/CMakeLists.txt | 8 +- lib/gc/Dialect/OneDNNGraph/CMakeLists.txt | 8 +- lib/gc/ExecutionEngine/CMakeLists.txt | 2 +- .../ExecutionEngine/CPURuntime/CMakeLists.txt | 7 +- lib/gc/ExecutionEngine/Driver/CMakeLists.txt | 10 +- .../OpenCLRuntime/CMakeLists.txt | 8 +- .../OpenCLRuntime/OpenCLRuntimeWrappers.cpp | 2 + lib/gc/Transforms/CMakeLists.txt | 9 +- lib/gc/Transforms/GPU/CMakeLists.txt | 7 +- lib/gc/Transforms/Utils/CMakeLists.txt | 8 +- python/CMakeLists.txt | 14 ++ scripts/compile.sh | 4 +- src/dnnl/CMakeLists.txt | 46 ++--- src/gc-cpu-runner/CMakeLists.txt | 12 +- src/gc-opt/CMakeLists.txt | 58 +++--- test/dnnl/CMakeLists.txt | 2 +- test/mlir/test/CMakeLists.txt | 2 +- test/mlir/test/lit.site.cfg.py.in | 3 +- test/mlir/unittests/CMakeLists.txt | 3 - 33 files changed, 281 insertions(+), 246 deletions(-) create mode 100644 cmake/mlir.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f22c3f143..6c7a676b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,159 +18,112 @@ 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") - -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - list(APPEND CMAKE_MODULE_PATH "${PROJECT_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() +################################################################################ + +############################ 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_OPT "Build gc-opt" ON) +option(GC_ENABLE_TOOLS "Build the tools" ON) +option(GC_ENABLE_OPT "Build gc-opt" ${GC_ENABLE_TOOLS}) option(GC_ENABLE_GPU "Enable GPU backend" OFF) option(GC_ENABLE_IMEX "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_ENABLE_LEGACY) - add_subdirectory(legacy/core) + 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 ${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) - if(GC_ENABLE_DNNL) - add_definitions(-DGC_HAS_ONEDNN_DIALECT) set(GC_ONEDNN_DIALECT_LIB_NAME MLIROneDNNGraph) -endif () - -if(GC_ENABLE_GPU) - add_definitions(-DGC_USE_GPU) -endif () - -if(GC_ENABLE_IMEX) - 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_OPT) - set(GC_OPT_EXE_NAME gc-opt) -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) -endif() - -if(GC_ENABLE_BINDINGS_PYTHON) - include(MLIRDetectPythonEnv) - mlir_configure_python_dev_packages() 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 + $ + $ + $ ) -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) +################################################################################ -# Export the targets -add_library(GcInterface INTERFACE) -target_include_directories(GcInterface INTERFACE - $ - $ - $ -) +############################### Install ######################################## install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ TYPE INCLUDE) install(DIRECTORY ${PROJECT_BINARY_DIR}/include/ TYPE INCLUDE - PATTERN "CMake*" EXCLUDE PATTERN "*.cmake" EXCLUDE) -install(TARGETS - GcCpuRuntime - GcGpuPasses - GcInterface - GcJitWrapper - GcPasses - GcUtilsIR - MLIRCPURuntimeDialect - MLIRCPURuntimeTransforms - MLIRLinalgx - MLIRMicrokernel - ${GC_OPT_EXE_NAME} - ${GC_ONEDNN_DIALECT_LIB_NAME} + REGEX "CMake.*|.*cmake" EXCLUDE) - 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 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" + FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake" ) install(EXPORT ${PROJECT_NAME}Targets - FILE ${PROJECT_NAME}Targets.cmake - DESTINATION lib/cmake/${PROJECT_NAME} + FILE ${PROJECT_NAME}Targets.cmake + DESTINATION lib/cmake/${PROJECT_NAME} ) # 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 + ${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 + "${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}" + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION "lib/cmake/${PROJECT_NAME}" ) +################################################################################ diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in index de4884b60..90c5b52a0 100644 --- a/cmake/Config.cmake.in +++ b/cmake/Config.cmake.in @@ -1,5 +1,10 @@ @PACKAGE_INIT@ -include ( "${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake" ) +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 8f70e89bf..cbd173e75 100644 --- a/cmake/functions.cmake +++ b/cmake/functions.cmake @@ -90,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/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 b9f1d3036..4c84085aa 100644 --- a/cmake/onednn.cmake +++ b/cmake/onednn.cmake @@ -1,21 +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 ) - 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. 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/Dialect/OneDNNGraph/CMakeLists.txt b/include/gc/Dialect/OneDNNGraph/CMakeLists.txt index 6203d3e7b..1b1f00222 100644 --- a/include/gc/Dialect/OneDNNGraph/CMakeLists.txt +++ b/include/gc/Dialect/OneDNNGraph/CMakeLists.txt @@ -1,4 +1,4 @@ -if (NOT GC_ENABLE_TEST_DNNL) +if (NOT GC_ENABLE_DNNL) message(STATUS "OneDNNGraphDialect is not enabled.") return() endif () diff --git a/include/gc/Transforms/CMakeLists.txt b/include/gc/Transforms/CMakeLists.txt index d51c185bb..6474c2b9b 100644 --- a/include/gc/Transforms/CMakeLists.txt +++ b/include/gc/Transforms/CMakeLists.txt @@ -1,8 +1,8 @@ if(GC_ENABLE_DNNL) - set(TABLEGEN_MACROS "${TABLEGEN_MACROS} -DGC_HAS_ONEDNN_DIALECT") + list(APPEND TABLEGEN_MACROS -DGC_HAS_ONEDNN_DIALECT) endif() if(GC_ENABLE_GPU) - set(TABLEGEN_MACROS "${TABLEGEN_MACROS} -DGC_USE_GPU") + list(APPEND TABLEGEN_MACROS -DGC_USE_GPU) endif() set(LLVM_TARGET_DEFINITIONS Passes.td) diff --git a/lib/gc/CAPI/CMakeLists.txt b/lib/gc/CAPI/CMakeLists.txt index a5133505d..3871fd4ab 100644 --- a/lib/gc/CAPI/CMakeLists.txt +++ b/lib/gc/CAPI/CMakeLists.txt @@ -1,11 +1,10 @@ set(GC_ALL_LIBS - MLIROneDNNGraph ${GC_ONEDNN_DIALECT_LIB_NAME} GcPasses MLIRCPURuntimeTransforms) -if(GC_USE_GPU) - list(APPEND GC_ALL_LIBS GcGPUPasses) +if(GC_ENABLE_GPU) + list(APPEND GC_ALL_LIBS GcGpuPasses) endif() add_mlir_public_c_api_library(GcCAPI @@ -14,3 +13,5 @@ add_mlir_public_c_api_library(GcCAPI LINK_LIBS PUBLIC ${GC_ALL_LIBS} ) +target_link_libraries(obj.GcCAPI PUBLIC GcInterface) +set_property(GLOBAL APPEND PROPERTY GC_MLIR_LIBS GcCAPI) 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 b68701abf..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} + 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 4058efec5..56bb58f95 100644 --- a/lib/gc/Dialect/OneDNNGraph/CMakeLists.txt +++ b/lib/gc/Dialect/OneDNNGraph/CMakeLists.txt @@ -1,9 +1,11 @@ -if (NOT GC_ENABLE_TEST_DNNL) +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(${GC_ONEDNN_DIALECT_LIB_NAME} +gc_add_mlir_dialect_library(${GC_ONEDNN_DIALECT_LIB_NAME} OneDNNGraphDialect.cpp OneDNNGraphOps.cpp @@ -15,5 +17,5 @@ add_mlir_dialect_library(${GC_ONEDNN_DIALECT_LIB_NAME} LINK_LIBS PUBLIC ${MLIR_LINK_COMPONENTS} + GcInterface ) -set_property(GLOBAL APPEND PROPERTY GC_DIALECT_LIBS ${GC_ONEDNN_DIALECT_LIB_NAME}) diff --git a/lib/gc/ExecutionEngine/CMakeLists.txt b/lib/gc/ExecutionEngine/CMakeLists.txt index d5279b044..0cabbdd43 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_GPU) 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 eafb2a166..faeb0ff60 100644 --- a/lib/gc/ExecutionEngine/CPURuntime/CMakeLists.txt +++ b/lib/gc/ExecutionEngine/CPURuntime/CMakeLists.txt @@ -1,15 +1,18 @@ find_package(OpenMP REQUIRED) -add_mlir_library(GcCpuRuntime +gc_add_mlir_library(GcCpuRuntime SHARED Parallel.cpp + LINK_LIBS PUBLIC + GcInterface + EXCLUDE_FROM_LIBMLIR ) 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_definitions(GcCpuRuntime PRIVATE "-DGC_NEEDS_OMP_WRAPPER") + target_compile_options(GcCpuRuntime PRIVATE "-DGC_NEEDS_OMP_WRAPPER") endif() string(REPLACE " " ";" flags "${OpenMP_C_FLAGS} ${OpenMP_CXX_FLAGS}") diff --git a/lib/gc/ExecutionEngine/Driver/CMakeLists.txt b/lib/gc/ExecutionEngine/Driver/CMakeLists.txt index 9961d84d7..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) +set(GC_PASSES GcInterface GcPasses) if(GC_UNABLE_GPU) - list(APPEND GC_PASSES GcGPUPasses) + 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/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 76e6310dc..384990112 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 @@ -25,9 +22,9 @@ add_mlir_library(GcPasses ${mlir_conversion_libs} ${MLIR_LINK_COMPONENTS} ${GC_ONEDNN_DIALECT_LIB_NAME} + GcInterface ) -set_property(GLOBAL APPEND PROPERTY GC_PASS_LIBS GCPasses) -if(GC_USE_GPU) +if(GC_ENABLE_GPU) add_subdirectory(GPU) endif() diff --git a/lib/gc/Transforms/GPU/CMakeLists.txt b/lib/gc/Transforms/GPU/CMakeLists.txt index 2294c0b17..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 + GcInterface GcUtilsIR ) -set_property(GLOBAL APPEND PROPERTY GC_PASS_LIBS GcGpuPasses) diff --git a/lib/gc/Transforms/Utils/CMakeLists.txt b/lib/gc/Transforms/Utils/CMakeLists.txt index d20de5e0a..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 05bad8bb1..45b64383e 100755 --- a/scripts/compile.sh +++ b/scripts/compile.sh @@ -110,9 +110,9 @@ build_llvm() { -DLLVM_INCLUDE_TESTS=OFF \ -DLLVM_INCLUDE_BENCHMARKS=OFF \ -DLLVM_INCLUDE_DOCS=OFF \ - -DLLVM_BUILD_TOOLS=OFF \ -DLLVM_INSTALL_UTILS=ON \ - -DLLVM_INSTALL_GTEST=ON + -DLLVM_INSTALL_GTEST=ON \ + -DMLIR_ENABLE_BINDINGS_PYTHON=ON cmake --build build --parallel $MAX_JOBS MLIR_DIR="$PWD/build/lib/cmake/mlir" diff --git a/src/dnnl/CMakeLists.txt b/src/dnnl/CMakeLists.txt index 7d7eccecc..69e8cb29f 100644 --- a/src/dnnl/CMakeLists.txt +++ b/src/dnnl/CMakeLists.txt @@ -13,32 +13,36 @@ # and limitations under the License. # SPDX-License-Identifier: Apache-2.0 -if (NOT GC_ENABLE_DNNL AND NOT GC_ENABLE_TEST_DNNL) - message(STATUS "oneDNN library integration is not enabled.") - return() -endif () +if(NOT GC_ENABLE_DNNL) + message(STATUS "oneDNN library integration is not enabled.") + return() +endif() include(onednn) -set(GC_LIB_INCLUDES ${DNNL_INCLUDES}) -set(GC_LIB_SOURCES - JsonParser.cpp - dnnl_graph_compiler.cpp +set(GC_DNNL_SOURCES + JsonParser.cpp + dnnl_graph_compiler.cpp ) -set(GC_LIB_LINKED_LIBS - GcJitWrapper - GcCpuRuntime +set(GC_DNNL_LINKED_LIBS + GcJitWrapper + GcCpuRuntime ) -add_mlir_library(GcDnnl SHARED ${GC_LIB_SOURCES}) -target_include_directories(GcDnnl PUBLIC ${DNNL_INCLUDES}) +gc_add_mlir_library(GcDnnl SHARED + ${GC_DNNL_SOURCES} + LINK_LIBS PRIVATE ${GC_DNNL_LINKED_LIBS} +) +target_link_libraries(GcDnnl PUBLIC GcInterface) +target_include_directories(GcDnnl PUBLIC ${GC_DNNL_INCLUDES}) target_compile_options(GcDnnl PRIVATE -fvisibility=hidden -fexceptions) target_link_options(GcDnnl PRIVATE -Wl,--gc-sections) -target_link_libraries(GcDnnl PRIVATE ${GC_LIB_LINKED_LIBS}) -if (GC_ENABLE_TEST_DNNL) - # Static graph compiler library to be used in tests - add_mlir_library(GcDnnlStatic STATIC ${GC_LIB_SOURCES}) - target_compile_options(obj.GcDnnlStatic PUBLIC -fexceptions) - target_include_directories(GcDnnlStatic PUBLIC ${GC_LIB_INCLUDES}) - target_link_libraries(GcDnnlStatic PUBLIC ${GC_LIB_LINKED_LIBS}) -endif () \ No newline at end of file +if(GC_ENABLE_TEST_DNNL) + # Static graph compiler library to be used in tests + gc_add_mlir_library(GcDnnlStatic STATIC + ${GC_DNNL_SOURCES} + LINK_LIBS PUBLIC GcInterface ${GC_DNNL_LINKED_LIBS} + ) + target_compile_options(obj.GcDnnlStatic PUBLIC -fexceptions) + target_include_directories(GcDnnlStatic PUBLIC ${GC_DNNL_INCLUDES}) +endif() diff --git a/src/gc-cpu-runner/CMakeLists.txt b/src/gc-cpu-runner/CMakeLists.txt index 9f7fceb0f..eaab1242d 100644 --- a/src/gc-cpu-runner/CMakeLists.txt +++ b/src/gc-cpu-runner/CMakeLists.txt @@ -15,6 +15,11 @@ # SPDX-License-Identifier: Apache-2.0 ################################################################################ +if(NOT GC_ENABLE_TOOLS) + message(STATUS "Cpu runner is not enabled.") + return() +endif() + if(GC_DEV_LINK_LLVM_DYLIB) set(LLVM_LINK_COMPONENTS LLVM @@ -47,18 +52,15 @@ else() ) endif() -if(GC_MLIR_CXX_FLAGS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GC_MLIR_CXX_FLAGS}") -endif() - #LLVM_LINK_COMPONENTS is processed by LLVM cmake in add_llvm_executable set(gc_cpu_runner_libs ${MLIR_LINK_COMPONENTS} GcCpuRuntime) add_mlir_tool(gc-cpu-runner gc-cpu-runner.cpp + ) llvm_update_compile_flags(gc-cpu-runner) -target_link_libraries(gc-cpu-runner PRIVATE ${gc_cpu_runner_libs}) +target_link_libraries(gc-cpu-runner PRIVATE GcInterface ${gc_cpu_runner_libs}) mlir_check_all_link_libraries(gc-cpu-runner) diff --git a/src/gc-opt/CMakeLists.txt b/src/gc-opt/CMakeLists.txt index 21a20fd15..301413083 100644 --- a/src/gc-opt/CMakeLists.txt +++ b/src/gc-opt/CMakeLists.txt @@ -15,10 +15,10 @@ # SPDX-License-Identifier: Apache-2.0 ################################################################################ -if (NOT GC_ENABLE_OPT) - message(STATUS "gc-opt is not enabled.") - return() -endif () +if(NOT GC_ENABLE_OPT) + message(STATUS "gc-opt is not enabled.") + return() +endif() if(GC_DEV_LINK_LLVM_DYLIB) set(MLIR_LINK_COMPONENTS @@ -34,26 +34,40 @@ else() get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) endif() -set(gc_opt_libs - ${dialect_libs} - ${conversion_libs} - ${MLIR_LINK_COMPONENTS} - GCPasses) +add_llvm_executable(gc-opt gc-opt.cpp) +llvm_update_compile_flags(gc-opt) +mlir_check_all_link_libraries(gc-opt) + +target_link_libraries(gc-opt PUBLIC GcInterface) +target_link_libraries(gc-opt PRIVATE + ${dialect_libs} + ${conversion_libs} + ${MLIR_LINK_COMPONENTS} + GcPasses +) + +if(GC_ENABLE_GPU) + target_link_libraries(gc-opt PRIVATE GcGpuPasses) +endif() if(GC_ENABLE_IMEX) - add_definitions(-DGC_USE_IMEX) + include(imex) + target_compile_options(gc-opt PRIVATE -DGC_USE_IMEX) get_property(IMEX_INCLUDES GLOBAL PROPERTY IMEX_INCLUDES) - include_directories(${IMEX_INCLUDES}) - list(APPEND gc_opt_libs IMEXGPUXDialect IMEXXeTileDialect IMEXRegionDialect IMEXRegionTransforms - IMEXTransforms IMEXGPUToGPUX IMEXGPUToSPIRV IMEXGPUXToLLVM IMEXXeGPUToVC IMEXXeTileToXeGPU IMEXUtil - GcGPUPasses) -endif() -if(GC_MLIR_CXX_FLAGS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GC_MLIR_CXX_FLAGS}") + target_include_directories(gc-opt PRIVATE ${IMEX_INCLUDES}) + target_link_libraries(gc-opt PRIVATE + IMEXGPUXDialect + IMEXXeTileDialect + IMEXRegionDialect + IMEXRegionTransforms + IMEXTransforms + IMEXGPUToGPUX + IMEXGPUToSPIRV + IMEXGPUXToLLVM + IMEXXeGPUToVC + IMEXXeTileToXeGPU + IMEXUtil + ) endif() -add_llvm_executable(${GC_OPT_EXE_NAME} gc-opt.cpp) - -target_link_libraries(${GC_OPT_EXE_NAME} PRIVATE ${gc_opt_libs}) -llvm_update_compile_flags(${GC_OPT_EXE_NAME}) -mlir_check_all_link_libraries(${GC_OPT_EXE_NAME}) +set_property(GLOBAL APPEND PROPERTY GC_TOOLS gc-opt) diff --git a/test/dnnl/CMakeLists.txt b/test/dnnl/CMakeLists.txt index b55241d7e..18d7d421a 100644 --- a/test/dnnl/CMakeLists.txt +++ b/test/dnnl/CMakeLists.txt @@ -1,4 +1,4 @@ -if (NOT GC_ENABLE_TEST_DNNL) +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 () diff --git a/test/mlir/test/CMakeLists.txt b/test/mlir/test/CMakeLists.txt index 9ea39691c..a8776a957 100644 --- a/test/mlir/test/CMakeLists.txt +++ b/test/mlir/test/CMakeLists.txt @@ -25,7 +25,7 @@ set(GC_OPT_TEST_DEPENDS 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/lit.site.cfg.py.in b/test/mlir/test/lit.site.cfg.py.in index f83acd363..2972c53ee 100644 --- a/test/mlir/test/lit.site.cfg.py.in +++ b/test/mlir/test/lit.site.cfg.py.in @@ -34,6 +34,7 @@ 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_ENABLE_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@" @@ -42,7 +43,7 @@ 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) 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") From 683a3467bb8a2e557d4a967d1118d1ba6c572917 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Thu, 1 Aug 2024 13:35:44 +0200 Subject: [PATCH 4/4] Renamed USE_GPU to USE_IMEX --- CMakeLists.txt | 3 +-- README.md | 16 ++++++++-------- include/gc/Transforms/CMakeLists.txt | 4 ++-- include/gc/Transforms/Passes.td | 2 +- lib/gc/CAPI/CMakeLists.txt | 4 ++-- lib/gc/ExecutionEngine/CMakeLists.txt | 2 +- lib/gc/Transforms/CMakeLists.txt | 2 +- src/gc-opt/CMakeLists.txt | 5 +---- test/mlir/test/gc/Transforms/GPU/lit.local.cfg | 2 +- test/mlir/test/lit.cfg.py | 2 +- test/mlir/test/lit.site.cfg.py.in | 1 - 11 files changed, 19 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c7a676b0..f1adaadc1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,8 +42,7 @@ 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_GPU "Enable GPU backend" OFF) -option(GC_ENABLE_IMEX "Intel® Extension for MLIR" OFF) +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) diff --git a/README.md b/README.md index adcc31e7c..4c04cc460 100644 --- a/README.md +++ b/README.md @@ -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_ENABLE_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_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_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/include/gc/Transforms/CMakeLists.txt b/include/gc/Transforms/CMakeLists.txt index 6474c2b9b..299e5c344 100644 --- a/include/gc/Transforms/CMakeLists.txt +++ b/include/gc/Transforms/CMakeLists.txt @@ -1,8 +1,8 @@ if(GC_ENABLE_DNNL) list(APPEND TABLEGEN_MACROS -DGC_HAS_ONEDNN_DIALECT) endif() -if(GC_ENABLE_GPU) - list(APPEND TABLEGEN_MACROS -DGC_USE_GPU) +if(GC_ENABLE_IMEX) + list(APPEND TABLEGEN_MACROS -DGC_USE_IMEX) endif() set(LLVM_TARGET_DEFINITIONS Passes.td) diff --git a/include/gc/Transforms/Passes.td b/include/gc/Transforms/Passes.td index d087cd0ba..0d5274eb9 100644 --- a/include/gc/Transforms/Passes.td +++ b/include/gc/Transforms/Passes.td @@ -34,7 +34,7 @@ def ConvertOneDNNGraphToLinalg : Pass<"convert-onednn-graph-to-linalg"> { } #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 3871fd4ab..30b684b3c 100644 --- a/lib/gc/CAPI/CMakeLists.txt +++ b/lib/gc/CAPI/CMakeLists.txt @@ -1,9 +1,9 @@ -set(GC_ALL_LIBS +set(GC_ALL_LIBS ${GC_ONEDNN_DIALECT_LIB_NAME} GcPasses MLIRCPURuntimeTransforms) -if(GC_ENABLE_GPU) +if(GC_ENABLE_IMEX) list(APPEND GC_ALL_LIBS GcGpuPasses) endif() diff --git a/lib/gc/ExecutionEngine/CMakeLists.txt b/lib/gc/ExecutionEngine/CMakeLists.txt index 0cabbdd43..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_ENABLE_GPU) +if(GC_ENABLE_IMEX) add_subdirectory(OpenCLRuntime) endif() \ No newline at end of file diff --git a/lib/gc/Transforms/CMakeLists.txt b/lib/gc/Transforms/CMakeLists.txt index 384990112..08ae24143 100644 --- a/lib/gc/Transforms/CMakeLists.txt +++ b/lib/gc/Transforms/CMakeLists.txt @@ -25,6 +25,6 @@ gc_add_mlir_library(GcPasses GcInterface ) -if(GC_ENABLE_GPU) +if(GC_ENABLE_IMEX) add_subdirectory(GPU) endif() diff --git a/src/gc-opt/CMakeLists.txt b/src/gc-opt/CMakeLists.txt index 301413083..96d5ae860 100644 --- a/src/gc-opt/CMakeLists.txt +++ b/src/gc-opt/CMakeLists.txt @@ -46,16 +46,13 @@ target_link_libraries(gc-opt PRIVATE GcPasses ) -if(GC_ENABLE_GPU) - target_link_libraries(gc-opt PRIVATE GcGpuPasses) -endif() - if(GC_ENABLE_IMEX) include(imex) target_compile_options(gc-opt PRIVATE -DGC_USE_IMEX) get_property(IMEX_INCLUDES GLOBAL PROPERTY IMEX_INCLUDES) target_include_directories(gc-opt PRIVATE ${IMEX_INCLUDES}) target_link_libraries(gc-opt PRIVATE + GcGpuPasses IMEXGPUXDialect IMEXXeTileDialect IMEXRegionDialect 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/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 2972c53ee..82d7ddcbc 100644 --- a/test/mlir/test/lit.site.cfg.py.in +++ b/test/mlir/test/lit.site.cfg.py.in @@ -34,7 +34,6 @@ 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_ENABLE_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@"