Skip to content

Commit bec5c29

Browse files
authored
Initial PR for a linalg example through level_zero (#129)
1 parent 1afc26d commit bec5c29

File tree

23 files changed

+3066
-28
lines changed

23 files changed

+3066
-28
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ endif()
5252
option(DPNP_ENABLE "Use DPNP for some math functions" OFF)
5353
option(GPU_ENABLE "Enable GPU codegen" OFF)
5454
option(NUMBA_ENABLE "Enable numba-based python frontend" ON)
55+
option(TBB_ENABLE "Enable TBB" ON)
5556

5657
message(STATUS "DPNP_ENABLE ${DPNP_ENABLE}")
5758
message(STATUS "GPU_ENABLE ${GPU_ENABLE}")
5859
message(STATUS "BUILD_TESTING ${BUILD_TESTING}")
5960
message(STATUS "NUMBA_ENABLE ${NUMBA_ENABLE}")
61+
message(STATUS "TBB_ENABLE ${TBB_ENABLE}")
6062

6163
include(CTest)
6264

@@ -73,9 +75,9 @@ if(GPU_ENABLE)
7375
endif()
7476

7577
add_subdirectory(mlir)
78+
add_subdirectory(dpcomp_runtime)
7679

7780
if(NUMBA_ENABLE)
78-
add_subdirectory(dpcomp_runtime)
7981
add_subdirectory(tools)
8082
add_subdirectory(numba_dpcomp)
8183
endif()

dpcomp_gpu_runtime/lib/kernel_api_stubs.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <cstdint>
1616
#include <cstdio>
1717
#include <cstdlib>
18+
#include <mutex>
19+
#include <numeric>
1820

1921
#include "dpcomp-gpu-runtime_export.h"
2022

dpcomp_runtime/CMakeLists.txt

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,27 @@ project(dpcomp-runtime LANGUAGES CXX C)
1616

1717
include(GenerateExportHeader)
1818

19-
find_package(TBB REQUIRED)
19+
if(TBB_ENABLE)
20+
find_package(TBB REQUIRED)
21+
endif()
22+
2023
find_package(MLIR REQUIRED CONFIG)
2124

22-
set(SOURCES_LIST
23-
lib/context.cpp
24-
lib/tbb_parallel.cpp
25-
lib/memory.cpp
26-
)
27-
set(HEADERS_LIST
28-
)
25+
if(TBB_ENABLE)
26+
set(SOURCES_LIST
27+
lib/context.cpp
28+
lib/tbb_parallel.cpp
29+
lib/memory.cpp
30+
)
31+
set(HEADERS_LIST
32+
)
33+
else()
34+
set(SOURCES_LIST
35+
lib/memory.cpp
36+
)
37+
set(HEADERS_LIST
38+
)
39+
endif()
2940

3041
add_library(${PROJECT_NAME} SHARED ${SOURCES_LIST} ${HEADERS_LIST})
3142
generate_export_header(${PROJECT_NAME})
@@ -35,5 +46,6 @@ target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE
3546
PRIVATE
3647
${PROJECT_BINARY_DIR}
3748
)
38-
39-
target_link_libraries(${PROJECT_NAME} TBB::tbb)
49+
if(TBB_ENABLE)
50+
target_link_libraries(${PROJECT_NAME} TBB::tbb)
51+
endif()

dpcomp_runtime/lib/memory.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@
2525

2626
#include "dpcomp-runtime_export.h"
2727

28+
template <typename T, int N> struct MemRefDescriptor {
29+
T *allocated;
30+
T *aligned;
31+
int64_t offset;
32+
int64_t sizes[N];
33+
int64_t strides[N];
34+
};
35+
36+
/// Fills the given 1D float memref with the given float value.
37+
extern "C" DPCOMP_RUNTIME_EXPORT void
38+
_mlir_ciface_fillResource1DFloat(MemRefDescriptor<float, 1> *ptr, // NOLINT
39+
float value) {
40+
std::fill_n(ptr->allocated, ptr->sizes[0], value);
41+
}
42+
2843
extern "C" DPCOMP_RUNTIME_EXPORT void
2944
memrefCopy(int64_t elemSize, UnrankedMemRefType<char> *srcArg,
3045
UnrankedMemRefType<char> *dstArg) {

mlir/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,21 @@ endif()
3939

4040
add_subdirectory(include/mlir-extensions/dialect/plier)
4141
add_subdirectory(include/mlir-extensions/dialect/plier_util)
42+
add_subdirectory(include/mlir-extensions/dialect/gpu_runtime/IR)
43+
44+
if (GPU_ENABLE)
45+
add_subdirectory(tools)
46+
endif()
4247

4348
set(SOURCES_LIST
4449
lib/Conversion/SCFToAffine/SCFToAffine.cpp
50+
lib/Conversion/gpu_to_gpu_runtime.cpp
51+
lib/Conversion/gpu_runtime_to_llvm.cpp
4552
lib/analysis/memory_ssa.cpp
4653
lib/analysis/memory_ssa_analysis.cpp
4754
lib/compiler/compiler.cpp
4855
lib/compiler/pipeline_registry.cpp
56+
lib/dialect/gpu_runtime/IR/gpu_runtime_ops.cpp
4957
lib/dialect/plier/dialect.cpp
5058
lib/dialect/plier_util/dialect.cpp
5159
lib/transforms/arg_lowering.cpp
@@ -72,10 +80,13 @@ set(SOURCES_LIST
7280
)
7381
set(HEADERS_LIST
7482
include/mlir-extensions/Conversion/SCFToAffine/SCFToAffine.h
83+
include/mlir-extensions/Conversion/gpu_to_gpu_runtime.hpp
84+
include/mlir-extensions/Conversion/gpu_runtime_to_llvm.hpp
7585
include/mlir-extensions/analysis/memory_ssa.hpp
7686
include/mlir-extensions/analysis/memory_ssa_analysis.hpp
7787
include/mlir-extensions/compiler/compiler.hpp
7888
include/mlir-extensions/compiler/pipeline_registry.hpp
89+
include/mlir-extensions/dialect/gpu_runtime/IR/gpu_runtime_ops.hpp
7990
include/mlir-extensions/dialect/plier/dialect.hpp
8091
include/mlir-extensions/dialect/plier_util/dialect.hpp
8192
include/mlir-extensions/transforms/arg_lowering.hpp
@@ -140,4 +151,4 @@ target_include_directories(${MLIR_EXTENSIONS_LIB} PUBLIC
140151
${PROJECT_BINARY_DIR}/mlir-extensions/include
141152
)
142153

143-
add_dependencies(${MLIR_EXTENSIONS_LIB} MLIRPlierOpsIncGen MLIRPlierUtilOpsIncGen)
154+
add_dependencies(${MLIR_EXTENSIONS_LIB} MLIRPlierOpsIncGen MLIRPlierUtilOpsIncGen MLIRGpuRuntimeOpsIncGen)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2022 Intel Corporation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include "mlir-extensions/dialect/gpu_runtime/IR/gpu_runtime_ops.hpp"
18+
#include "mlir-extensions/transforms/func_utils.hpp"
19+
20+
#include <mlir/Conversion/AsyncToLLVM/AsyncToLLVM.h>
21+
#include <mlir/Conversion/GPUCommon/GPUCommonPass.h>
22+
#include <mlir/Conversion/LLVMCommon/ConversionTarget.h>
23+
#include <mlir/Conversion/LLVMCommon/Pattern.h>
24+
#include <mlir/Conversion/LLVMCommon/TypeConverter.h>
25+
#include <mlir/Dialect/GPU/Passes.h>
26+
#include <mlir/Dialect/LLVMIR/LLVMDialect.h>
27+
#include <mlir/Pass/PassManager.h>
28+
#include <mlir/Transforms/DialectConversion.h>
29+
#include <mlir/Transforms/Passes.h>
30+
31+
namespace gpu_runtime {
32+
33+
std::unique_ptr<mlir::Pass> createEnumerateEventsPass();
34+
std::unique_ptr<mlir::Pass> createGPUToLLVMPass();
35+
36+
} // namespace gpu_runtime
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2022 Intel Corporation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include "mlir-extensions/dialect/gpu_runtime/IR/gpu_runtime_ops.hpp"
18+
19+
#include "mlir/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRV.h"
20+
#include <mlir/Analysis/BufferViewFlowAnalysis.h>
21+
#include <mlir/Conversion/AffineToStandard/AffineToStandard.h>
22+
#include <mlir/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.h>
23+
#include <mlir/Conversion/GPUCommon/GPUCommonPass.h>
24+
#include <mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h>
25+
#include <mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h>
26+
#include <mlir/Conversion/MathToSPIRV/MathToSPIRV.h>
27+
#include <mlir/Conversion/SCFToSPIRV/SCFToSPIRV.h>
28+
#include <mlir/Conversion/StandardToSPIRV/StandardToSPIRV.h>
29+
#include <mlir/Dialect/Affine/IR/AffineOps.h>
30+
#include <mlir/Dialect/Arithmetic/Transforms/Passes.h>
31+
#include <mlir/Dialect/GPU/ParallelLoopMapper.h>
32+
#include <mlir/Dialect/GPU/Passes.h>
33+
#include <mlir/Dialect/GPU/Utils.h>
34+
#include <mlir/Dialect/LLVMIR/LLVMDialect.h>
35+
#include <mlir/Dialect/Math/IR/Math.h>
36+
#include <mlir/Dialect/MemRef/IR/MemRef.h>
37+
#include <mlir/Dialect/SCF/SCF.h>
38+
#include <mlir/Dialect/SPIRV/IR/SPIRVDialect.h>
39+
#include <mlir/Dialect/SPIRV/IR/SPIRVOps.h>
40+
#include <mlir/Dialect/SPIRV/IR/TargetAndABI.h>
41+
#include <mlir/Dialect/SPIRV/Transforms/Passes.h>
42+
#include <mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h>
43+
#include <mlir/Dialect/StandardOps/IR/Ops.h>
44+
#include <mlir/Pass/PassManager.h>
45+
#include <mlir/Target/SPIRV/Serialization.h>
46+
#include <mlir/Transforms/DialectConversion.h>
47+
#include <mlir/Transforms/GreedyPatternRewriteDriver.h>
48+
#include <mlir/Transforms/Passes.h>
49+
#include <llvm/ADT/SmallBitVector.h>
50+
51+
52+
namespace gpu_runtime {
53+
54+
std::unique_ptr<mlir::Pass> createAbiAttrsPass();
55+
std::unique_ptr<mlir::Pass> createSetSPIRVCapabilitiesPass();
56+
std::unique_ptr<mlir::Pass> createGPUToSpirvPass();
57+
std::unique_ptr<mlir::Pass> createInsertGPUAllocsPass();
58+
std::unique_ptr<mlir::Pass> createUnstrideMemrefsPass();
59+
std::unique_ptr<mlir::Pass> createSerializeSPIRVPass();
60+
std::unique_ptr<mlir::Pass> createGPUExPass();
61+
std::unique_ptr<mlir::Pass> createParallelLoopGPUMappingPass();
62+
63+
} // namespace gpu_runtime
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
include_directories(${MLIR_INCLUDE_DIRS})
2+
set(dialect GpuRuntimeOps)
3+
set(dialect_namespace gpu_runtime)
4+
set(LLVM_TARGET_DEFINITIONS ${dialect}.td)
5+
mlir_tablegen(${dialect}Enums.h.inc -gen-enum-decls)
6+
mlir_tablegen(${dialect}Enums.cpp.inc -gen-enum-defs)
7+
mlir_tablegen(${dialect}.h.inc -gen-op-decls)
8+
mlir_tablegen(${dialect}.cpp.inc -gen-op-defs)
9+
mlir_tablegen(${dialect}Dialect.h.inc -gen-dialect-decls -dialect=${dialect_namespace})
10+
mlir_tablegen(${dialect}Dialect.cpp.inc -gen-dialect-defs -dialect=${dialect_namespace})
11+
add_public_tablegen_target(MLIR${dialect}IncGen)
12+
add_dependencies(mlir-headers MLIR${dialect}IncGen)
13+

0 commit comments

Comments
 (0)