Skip to content

Commit ff2fd3b

Browse files
author
Longsheng Du
committed
Merge branch 'main' into longsheng/add_onednn_graph
2 parents 6a77167 + 0d8210e commit ff2fd3b

File tree

13 files changed

+143
-42
lines changed

13 files changed

+143
-42
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/dnnl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
include(onednn)
22

3-
gc_add_path(GC_LIB_SOURCES GLOB "*.*pp")
3+
gc_add_path(GC_LIB_SOURCES GLOB "*.cpp")
44
gc_add_path(GC_LIB_INCLUDES ${DNNL_INCLUDES})

src/dnnl/dnnl_graph_compiler.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,48 @@
1-
#include "dnnl_graph_compiler.hpp"
1+
/*
2+
* Copyright (C) 2024 Intel Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing,
11+
* software distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions
14+
* and limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
*/
18+
19+
#include "dnnl_graph_compiler.h"
220
#include "gc_version.h"
21+
#include <memory>
322
#include <new>
23+
#include <string_view>
424

525
// dnnl_graph_compiler.h interface implementation.
626
// TODO: Implement.
727

28+
struct dnnl_graph_compiler_executable {
29+
// TODO: Implement
30+
31+
void execute(dnnl_graph_compiler_tensor *inputs,
32+
dnnl_graph_compiler_tensor *outputs) const;
33+
};
34+
35+
struct dnnl_graph_compiler {
36+
const dnnl_graph_compiler_context ctx;
37+
38+
explicit dnnl_graph_compiler(const dnnl_graph_compiler_context *context)
39+
// TODO: Initialize ctx with context or defaults if context is nullptr
40+
: ctx() {}
41+
42+
[[nodiscard]] std::unique_ptr<const dnnl_graph_compiler_executable>
43+
compile(const std::string_view &graph_json) const;
44+
};
45+
846
const dnnl_graph_compiler_version *dnnl_graph_compiler_get_version(void) {
947
static const dnnl_graph_compiler_version ver = {
1048
.api_version = {DNNL_GC_API_V_MAJOR, DNNL_GC_API_V_MINOR,

src/dnnl/dnnl_graph_compiler.hpp

Lines changed: 0 additions & 26 deletions
This file was deleted.

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/dnnl/test_dnnl_c_interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ TEST(dnnl_graph_compiler, c_interface) {
1818
dnnl_graph_compiler_tensor inputs[2];
1919
dnnl_graph_compiler_tensor outputs[1];
2020
uint8_t data_buf[160];
21-
size_t dims[1] = {10};
21+
int64_t dims[1] = {10};
2222
inputs[0] = {.id = 0, .ndims = 1, .dims = dims, .data = data_buf};
2323
inputs[1] = {.id = 1, .ndims = 1, .dims = dims, .data = &data_buf[40]};
2424
outputs[0] = {.id = 2, .ndims = 1, .dims = dims, .data = &data_buf[80]};

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)