Skip to content

Commit 654253c

Browse files
author
Copybara Bot
committed
Integrate internal changes
GitOrigin-RevId: 630a69d8e14506db43cfefe4be2c790f9352da4f
1 parent 12995a1 commit 654253c

File tree

160 files changed

+5762
-1599
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+5762
-1599
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
cmake_minimum_required(VERSION 3.25)
2+
project(mlir-tensorrt-common LANGUAGES CXX)
3+
4+
# Depdendencies
5+
find_package(LLVM REQUIRED CONFIG)
6+
find_package(MLIR REQUIRED CONFIG)
7+
include(HandleLLVMOptions)
8+
include_directories(${LLVM_INCLUDE_DIRS})
9+
include_directories(${MLIR_INCLUDE_DIRS})
10+
11+
if(MLIR_TRT_TARGET_TENSORRT)
12+
find_package(TensorRT REQUIRED)
13+
endif()
14+
15+
set(MLIR_TENSORRT_COMMON_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
16+
set(MLIR_TENSORRT_COMMON_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
17+
18+
include_directories(include ${CMAKE_CURRENT_BINARY_DIR}/include)
19+
20+
add_library(MLIRTensorRTCommonIncludes INTERFACE)
21+
target_include_directories(MLIRTensorRTCommonIncludes INTERFACE
22+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
23+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
24+
)
25+
26+
add_subdirectory(include/mlir-tensorrt-common)
27+
add_subdirectory(lib)
28+
29+
install(TARGETS MLIRTensorRTCommonIncludes
30+
EXPORT MLIRTensorRTCommonTargets
31+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
32+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
33+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
34+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
35+
)
36+

mlir-tensorrt/common/include/mlir-tensorrt-common/CMakeLists.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//===- LuaRegistration.h ----------------------------------------*- C++ -*-===//
1+
//===- Passes.h -------------------------------------------------*- C++ -*-===//
22
//
3-
// SPDX-FileCopyrightText: Copyright 2024 NVIDIA CORPORATION & AFFILIATES.
3+
// SPDX-FileCopyrightText: Copyright 2025 NVIDIA CORPORATION & AFFILIATES.
44
// All rights reserved.
55
// SPDX-License-Identifier: Apache-2.0
66
//
@@ -18,22 +18,22 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020
///
21-
/// Registration for the Lua runtime methods.
21+
/// This file contains the declarations for the common conversion passes.
2222
///
2323
//===----------------------------------------------------------------------===//
24+
#ifndef MLIR_TENSORRT_COMMON_CONVERSION_PASSES
25+
#define MLIR_TENSORRT_COMMON_CONVERSION_PASSES
2426

25-
#include "mlir-executor/Runtime/API/API.h"
27+
#include "mlir/Pass/Pass.h"
28+
#include <memory>
2629

27-
struct lua_State;
28-
29-
namespace mlirtrt::runtime {
30-
/// Register various external functions with the given Lua state using a
31-
/// directly specified device number, total device count, and a pre-determined
32-
/// NCCL uuid.
33-
void registerLuaRuntimeMethods(lua_State *state,
34-
const RuntimeSessionOptions &options,
35-
PinnedMemoryAllocator *pinnedMemoryAllocator,
36-
AllocTracker *allocTracker,
37-
ResourceTracker *resourceTracker);
30+
//===----------------------------------------------------------------------===//
31+
// Add Tablegen'd pass declarations and registration methods.
32+
//===----------------------------------------------------------------------===//
33+
namespace mlir {
34+
#define GEN_PASS_DECL
35+
#define GEN_PASS_REGISTRATION
36+
#include "mlir-tensorrt-common/Conversion/Passes.h.inc"
37+
} // namespace mlir
3838

39-
} // namespace mlirtrt::runtime
39+
#endif // MLIR_TENSORRT_COMMON_CONVERSION_PASSES
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef MLIR_TENSORRT_COMMON_CONVERSION_PASSES
2+
#define MLIR_TENSORRT_COMMON_CONVERSION_PASSES
3+
4+
include "mlir/Pass/PassBase.td"
5+
6+
def ConvertToLoops : Pass<"convert-to-loops"> {
7+
let summary = "Convert a LoopLikeOpInterface to loops";
8+
let description = [{
9+
This pass converts a LoopLikeOpInterface to loops.
10+
}];
11+
12+
let dependentDialects = [
13+
"::mlir::tensor::TensorDialect",
14+
"::mlir::scf::SCFDialect",
15+
];
16+
}
17+
18+
#endif // MLIR_TENSORRT_COMMON_CONVERSION_PASSES
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===- DataLayoutImpl.h -----------------------------------------*- C++ -*-===//
2+
//
3+
// SPDX-FileCopyrightText: Copyright 2025 NVIDIA CORPORATION & AFFILIATES.
4+
// All rights reserved.
5+
// SPDX-License-Identifier: Apache-2.0
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
//===----------------------------------------------------------------------===//
20+
///
21+
/// This file contains the declarations for the DataLayout extensions to
22+
/// the EmitC dialect.
23+
/// TODO: These interfaces should be upstreamed to the EmitC dialect so that
24+
/// external models are not required.
25+
///
26+
//===----------------------------------------------------------------------===//
27+
#ifndef MLIR_TENSORRT_COMMON_DIALECT_EMITCEXT_IR_DATALAYOUTIMPL_H
28+
#define MLIR_TENSORRT_COMMON_DIALECT_EMITCEXT_IR_DATALAYOUTIMPL_H
29+
30+
#include "mlir/IR/DialectRegistry.h"
31+
32+
namespace mlir::emitc_ext {
33+
void registerDataLayoutInterfaceExternalModels(DialectRegistry &registry);
34+
}
35+
36+
#endif // MLIR_TENSORRT_COMMON_DIALECT_EMITCEXT_IR_DATALAYOUTIMPL_H
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//===- ToLoopsOpInterfaceImpl.h ---------------------------------*- C++ -*-===//
2+
//
3+
// SPDX-FileCopyrightText: Copyright 2025 NVIDIA CORPORATION & AFFILIATES.
4+
// All rights reserved.
5+
// SPDX-License-Identifier: Apache-2.0
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
//===----------------------------------------------------------------------===//
20+
///
21+
/// This file contains the declarations for the ToLoopsOpInterface extensions to
22+
/// the Linalg dialect.
23+
///
24+
//===----------------------------------------------------------------------===//
25+
#ifndef MLIR_TENSORRT_COMMON_DIALECT_LINALGEXT_TRANSFORMS_TOLOOPSOPINTERFACEIMPL
26+
#define MLIR_TENSORRT_COMMON_DIALECT_LINALGEXT_TRANSFORMS_TOLOOPSOPINTERFACEIMPL
27+
28+
#include "mlir-tensorrt-common/Interfaces/ToLoopsOpInterface.h"
29+
#include "mlir/IR/DialectRegistry.h"
30+
31+
namespace mlir::linalg {
32+
class LinalgOp;
33+
}
34+
35+
namespace mlir::scf {
36+
class ForOp;
37+
}
38+
39+
namespace mlir::linalg_ext {
40+
41+
/// Register the ToLoopsOpInterface external models for GenericOp. For other
42+
/// kinds of operations that are LinalgOps, we don't register an external model
43+
/// because there are so many; instead use the below function to perform
44+
/// conversion.
45+
void registerToLoopsOpInterfaceExternalModels(DialectRegistry &registry);
46+
47+
/// Convert a LinalgOp (on tensors) to SCF loops.
48+
FailureOr<SmallVector<Operation *>>
49+
convertLinalgOpToLoops(RewriterBase &rewriter, linalg::LinalgOp op);
50+
51+
} // namespace mlir::linalg_ext
52+
53+
#endif // MLIR_TENSORRT_COMMON_DIALECT_LINALGEXT_TRANSFORMS_TOLOOPSOPINTERFACEIMPL
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===- ToLoopsOpInterface.h -------------------------------*- C++ -*-===//
2+
//
3+
// SPDX-FileCopyrightText: Copyright 2025 NVIDIA CORPORATION & AFFILIATES.
4+
// All rights reserved.
5+
// SPDX-License-Identifier: Apache-2.0
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
//===----------------------------------------------------------------------===//
20+
///
21+
/// This file contains the declarations for the `ToLoopsOpInterface` interface.
22+
///
23+
//===----------------------------------------------------------------------===//
24+
#ifndef MLIR_TENSORRT_COMMON_INTERFACES_TOLOOPSOPINTERFACE
25+
#define MLIR_TENSORRT_COMMON_INTERFACES_TOLOOPSOPINTERFACE
26+
27+
#include "mlir/IR/OpDefinition.h"
28+
29+
namespace mlir {
30+
class RewriterBase;
31+
namespace scf {
32+
class ForOp;
33+
} // namespace scf
34+
} // namespace mlir
35+
36+
#include "mlir-tensorrt-common/Interfaces/ToLoopsOpInterface.h.inc"
37+
38+
#endif // MLIR_TENSORRT_COMMON_INTERFACES_TOLOOPSOPINTERFACE
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef MLIR_TENSORRT_COMMON_INTERFACES_TOLOOPSOPINTERFACE
2+
#define MLIR_TENSORRT_COMMON_INTERFACES_TOLOOPSOPINTERFACE
3+
4+
include "mlir/IR/OpBase.td"
5+
6+
def ToLoopsOpInterface : OpInterface<"ToLoopsOpInterface"> {
7+
let description = "Interface for lowering to loops";
8+
9+
let cppNamespace = "::mlir";
10+
11+
let methods = [
12+
InterfaceMethod<[{
13+
Lower the operation to a loop nest. Returns
14+
the outermost loop that should replace the original
15+
op, but does not actually perform the replacement.
16+
}],
17+
"::mlir::FailureOr<::mlir::Operation*>",
18+
"lowerToLoops",
19+
(ins "::mlir::RewriterBase&":$rewriter),
20+
"",
21+
[{
22+
llvm_unreachable("Not implemented");
23+
}]
24+
>
25+
];
26+
}
27+
28+
#endif // MLIR_TENSORRT_COMMON_INTERFACES_TOLOOPSOPINTERFACE
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_subdirectory(Conversion)
2+
add_subdirectory(Dialect)
3+
add_subdirectory(Interfaces)
4+
add_subdirectory(Utils)
5+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
set(LLVM_TARGET_DEFINITIONS
2+
"${MLIR_TENSORRT_COMMON_SOURCE_DIR}/include/mlir-tensorrt-common/Conversion/Passes.td")
3+
set(OUTPUT_DIR
4+
"${MLIR_TENSORRT_COMMON_BINARY_DIR}/include/mlir-tensorrt-common/Conversion")
5+
6+
cmake_path(SET OUTPUT_DIR NORMALIZE "${OUTPUT_DIR}")
7+
cmake_path(RELATIVE_PATH OUTPUT_DIR BASE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
8+
mlir_tablegen("${OUTPUT_DIR}/Passes.h.inc" -gen-pass-decls -name MLIRTensorRTCommonConversion)
9+
add_public_tablegen_target(MLIRTensorRTCommonConversionPassesIncGen)
10+
11+
add_subdirectory(ToLoops)

0 commit comments

Comments
 (0)