Skip to content

add cpu runner #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ 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}")

Expand Down
13 changes: 2 additions & 11 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)

set(gc_opt_libs
${dialect_libs}
${conversion_libs}
MLIROptLib
GCPasses)
add_llvm_executable(gc-opt gc-opt.cpp)

target_link_libraries(gc-opt PRIVATE ${gc_opt_libs})
llvm_update_compile_flags(gc-opt)
mlir_check_all_link_libraries(gc-opt)

add_subdirectory(dnnl)
add_subdirectory(gc-cpu-runner)
add_subdirectory(gc-opt)
33 changes: 33 additions & 0 deletions src/gc-cpu-runner/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# the dependency list copied from mlir/tools/mlir-cpu-runner/CMakeLists.txt of upstream
set(LLVM_LINK_COMPONENTS
Core
Support
nativecodegen
native
)
set(MLIR_LINK_COMPONENTS
MLIRAnalysis
MLIRBuiltinToLLVMIRTranslation
MLIRExecutionEngine
MLIRIR
MLIRJitRunner
MLIRLLVMDialect
MLIRLLVMToLLVMIRTranslation
MLIRToLLVMIRTranslationRegistration
MLIRParser
MLIRTargetLLVMIRExport
MLIRSupport
)

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})
add_llvm_executable(gc-cpu-runner gc-cpu-runner.cpp)

target_link_libraries(gc-cpu-runner PRIVATE ${gc_cpu_runner_libs})
llvm_update_compile_flags(gc-cpu-runner)
mlir_check_all_link_libraries(gc-cpu-runner)
40 changes: 40 additions & 0 deletions src/gc-cpu-runner/gc-cpu-runner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

/*
* Copyright (C) 2024 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/ExecutionEngine/JitRunner.h"
#include "mlir/ExecutionEngine/OptUtils.h"
#include "mlir/IR/Dialect.h"
#include "mlir/Target/LLVMIR/Dialect/All.h"

#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/TargetSelect.h"
#include <stdio.h>

int main(int argc, char **argv) {
llvm::InitLLVM y(argc, argv);
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
llvm::InitializeNativeTargetAsmParser();

mlir::DialectRegistry registry;
mlir::registerAllToLLVMIRTranslations(registry);

return mlir::JitRunnerMain(argc, argv, registry);
}
15 changes: 15 additions & 0 deletions src/gc-opt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(gc_opt_libs
${dialect_libs}
${conversion_libs}
MLIROptLib
GCPasses)
if(GC_MLIR_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GC_MLIR_CXX_FLAGS}")
endif()

add_llvm_executable(gc-opt gc-opt.cpp)

target_link_libraries(gc-opt PRIVATE ${gc_opt_libs})
llvm_update_compile_flags(gc-opt)
mlir_check_all_link_libraries(gc-opt)

File renamed without changes.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(GC_OPT_TEST_DEPENDS
FileCheck count not
# mlir-gen
gc-opt
gc-cpu-runner
GCUnitTests
)

Expand Down
5 changes: 5 additions & 0 deletions test/gc/cpu-runner/run.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: gc-opt %s --convert-func-to-llvm --convert-cf-to-llvm | gc-cpu-runner -e main -entry-point-result=void | FileCheck --allow-empty %s
func.func @main() {
return
}
// CHECK-NOT: any
4 changes: 2 additions & 2 deletions test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@

# test_exec_root: The root path where tests should be run.
config.test_exec_root = os.path.join(config.gc_obj_root, "test")
config.gc_tools_dir = os.path.join(config.gc_obj_root, "src")
config.gc_tools_dir = os.path.join(config.gc_obj_root, "bin")

# Tweak the PATH to include the tools dir.
llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)

tool_dirs = [config.gc_tools_dir, config.llvm_tools_dir]
tools = ["gc-opt"]
tools = ["gc-opt", "gc-cpu-runner"]

llvm_config.add_tool_substitutions(tools, tool_dirs)