Skip to content

Commit 0d8210e

Browse files
author
Menooker
authored
add cpu runner (#65)
1 parent 5791f6a commit 0d8210e

File tree

9 files changed

+102
-13
lines changed

9 files changed

+102
-13
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ find_package(MLIR REQUIRED CONFIG)
2020
message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
2121
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
2222

23+
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
24+
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
25+
set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR})
26+
2327
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
2428
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
2529

src/CMakeLists.txt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
22
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
33

4-
set(gc_opt_libs
5-
${dialect_libs}
6-
${conversion_libs}
7-
MLIROptLib
8-
GCPasses)
9-
add_llvm_executable(gc-opt gc-opt.cpp)
10-
11-
target_link_libraries(gc-opt PRIVATE ${gc_opt_libs})
12-
llvm_update_compile_flags(gc-opt)
13-
mlir_check_all_link_libraries(gc-opt)
14-
154
add_subdirectory(dnnl)
5+
add_subdirectory(gc-cpu-runner)
6+
add_subdirectory(gc-opt)

src/gc-cpu-runner/CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# the dependency list copied from mlir/tools/mlir-cpu-runner/CMakeLists.txt of upstream
2+
set(LLVM_LINK_COMPONENTS
3+
Core
4+
Support
5+
nativecodegen
6+
native
7+
)
8+
set(MLIR_LINK_COMPONENTS
9+
MLIRAnalysis
10+
MLIRBuiltinToLLVMIRTranslation
11+
MLIRExecutionEngine
12+
MLIRIR
13+
MLIRJitRunner
14+
MLIRLLVMDialect
15+
MLIRLLVMToLLVMIRTranslation
16+
MLIRToLLVMIRTranslationRegistration
17+
MLIRParser
18+
MLIRTargetLLVMIRExport
19+
MLIRSupport
20+
)
21+
22+
if(GC_MLIR_CXX_FLAGS)
23+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GC_MLIR_CXX_FLAGS}")
24+
endif()
25+
26+
#LLVM_LINK_COMPONENTS is processed by LLVM cmake in add_llvm_executable
27+
set(gc_cpu_runner_libs
28+
${MLIR_LINK_COMPONENTS})
29+
add_llvm_executable(gc-cpu-runner gc-cpu-runner.cpp)
30+
31+
target_link_libraries(gc-cpu-runner PRIVATE ${gc_cpu_runner_libs})
32+
llvm_update_compile_flags(gc-cpu-runner)
33+
mlir_check_all_link_libraries(gc-cpu-runner)

src/gc-cpu-runner/gc-cpu-runner.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
/*
3+
* Copyright (C) 2024 Intel Corporation
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions
15+
* and limitations under the License.
16+
*
17+
* SPDX-License-Identifier: Apache-2.0
18+
*/
19+
20+
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
21+
#include "mlir/ExecutionEngine/JitRunner.h"
22+
#include "mlir/ExecutionEngine/OptUtils.h"
23+
#include "mlir/IR/Dialect.h"
24+
#include "mlir/Target/LLVMIR/Dialect/All.h"
25+
26+
#include "llvm/Support/InitLLVM.h"
27+
#include "llvm/Support/TargetSelect.h"
28+
#include <stdio.h>
29+
30+
int main(int argc, char **argv) {
31+
llvm::InitLLVM y(argc, argv);
32+
llvm::InitializeNativeTarget();
33+
llvm::InitializeNativeTargetAsmPrinter();
34+
llvm::InitializeNativeTargetAsmParser();
35+
36+
mlir::DialectRegistry registry;
37+
mlir::registerAllToLLVMIRTranslations(registry);
38+
39+
return mlir::JitRunnerMain(argc, argv, registry);
40+
}

src/gc-opt/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
set(gc_opt_libs
2+
${dialect_libs}
3+
${conversion_libs}
4+
MLIROptLib
5+
GCPasses)
6+
if(GC_MLIR_CXX_FLAGS)
7+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GC_MLIR_CXX_FLAGS}")
8+
endif()
9+
10+
add_llvm_executable(gc-opt gc-opt.cpp)
11+
12+
target_link_libraries(gc-opt PRIVATE ${gc_opt_libs})
13+
llvm_update_compile_flags(gc-opt)
14+
mlir_check_all_link_libraries(gc-opt)
15+
File renamed without changes.

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(GC_OPT_TEST_DEPENDS
2929
FileCheck count not
3030
# mlir-gen
3131
gc-opt
32+
gc-cpu-runner
3233
GCUnitTests
3334
)
3435

test/gc/cpu-runner/run.mlir

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// 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
2+
func.func @main() {
3+
return
4+
}
5+
// CHECK-NOT: any

test/lit.cfg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
4141

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

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

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

5252
llvm_config.add_tool_substitutions(tools, tool_dirs)

0 commit comments

Comments
 (0)