-
Notifications
You must be signed in to change notification settings - Fork 13
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
WIP: Adding TRT options/task #435
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//===- PassManagerUtils.h ---------------------------------------*- C++ -*-===// | ||
// | ||
// SPDX-FileCopyrightText: Copyright 2024 NVIDIA CORPORATION & AFFILIATES. | ||
// All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "mlir-tensorrt/Compiler/OptionsProviders.h" | ||
#include "mlir/Pass/PassManager.h" | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Common helpers | ||
//===----------------------------------------------------------------------===// | ||
|
||
mlir::LogicalResult | ||
setupPassManager(mlir::PassManager &pm, | ||
const mlirtrt::compiler::DebugOptions &options); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//===- TensorRTToExecutable.h -----------------------------------*- C++ -*-===// | ||
// | ||
// SPDX-FileCopyrightText: Copyright 2024 NVIDIA CORPORATION & AFFILIATES. | ||
// All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef MLIR_TENSORRT_COMPILER_TENSORRTTOEXECUTABLE | ||
#define MLIR_TENSORRT_COMPILER_TENSORRTTOEXECUTABLE | ||
|
||
// TODO (pranavm): MLIR_TRT_TARGET_TENSORRT is only needed because we pull in | ||
// the TranslateToTensorRT.h header. If we move the translation options, we | ||
// won't need it. | ||
#ifdef MLIR_TRT_TARGET_TENSORRT | ||
#include "mlir-tensorrt-dialect/Target/TranslateToTensorRT.h" | ||
#include "mlir-tensorrt-dialect/Utils/Options.h" | ||
#include "mlir-tensorrt-dialect/Utils/OptionsBundle.h" | ||
#include "mlir-tensorrt/Compiler/Client.h" | ||
#include "mlir-tensorrt/Compiler/Extension.h" | ||
#include "mlir-tensorrt/Compiler/OptionsProviders.h" | ||
#include "mlir/Support/TypeID.h" | ||
|
||
namespace mlirtrt::compiler { | ||
|
||
//===----------------------------------------------------------------------===// | ||
// TensorRTToExecutableOptions | ||
//===----------------------------------------------------------------------===// | ||
|
||
// TODO (pranavm): Figure out a better way to reuse TRT translation options - | ||
// maybe move to options providers? | ||
struct TensorRTOptions | ||
: public mlirtrt::compiler::OptionsProvider<TensorRTOptions> { | ||
mlir::tensorrt::TensorRTTranslationOptions options; | ||
|
||
void addToOptions(mlir::OptionsContext &context) { | ||
options.addToOptions(context); | ||
} | ||
}; | ||
|
||
struct TensorRTToExecutableOptions | ||
: public mlir::OptionsBundle<DeviceOptions, DebugOptions, ExecutorOptions, | ||
CommonCompilationOptions, TensorRTOptions> { | ||
|
||
TensorRTToExecutableOptions(TaskExtensionRegistry extensions); | ||
}; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// TensorRTToExecutableTask | ||
//===----------------------------------------------------------------------===// | ||
|
||
class TensorRTToExecutableTask | ||
: public CompilationTask<TensorRTToExecutableTask, | ||
TensorRTToExecutableOptions> { | ||
public: | ||
using Base::Base; | ||
|
||
static void populatePassManager(mlir::PassManager &pm, | ||
const TensorRTToExecutableOptions &options); | ||
}; | ||
|
||
/// Register the task/options with the client's registry. | ||
void registerTensorRTToExecutableTask(); | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Pipeline Registrations | ||
//===----------------------------------------------------------------------===// | ||
|
||
// TODO (pranavm): How to do pipeline registration? | ||
// void registerTensorRTPipelines(); | ||
|
||
} // namespace mlirtrt::compiler | ||
|
||
MLIR_DECLARE_EXPLICIT_TYPE_ID(mlirtrt::compiler::TensorRTToExecutableTask) | ||
|
||
#endif | ||
#endif // MLIR_TENSORRT_COMPILER_TENSORRTTOEXECUTABLE |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
#define REGISTRATION_REGISTERMLIRTENSORRTPASSES_H | ||
|
||
#include "mlir-tensorrt-dialect/TensorRT/Transforms/Passes.h" | ||
#include "mlir-tensorrt/Compiler/TensorRTToExecutable.h" | ||
#include "mlir-tensorrt/Conversion/Passes.h" | ||
#include "mlir-tensorrt/Transforms/Passes.h" | ||
#include "mlir/Conversion/Passes.h" | ||
|
@@ -52,6 +53,12 @@ inline void registerAllMlirTensorRtPasses() { | |
mlir::registerTransformsPasses(); | ||
mlir::registerConvertPDLToPDLInterp(); | ||
|
||
// TODO (pranavm): Check if this needs to be conditional - the TRT passes | ||
// above are not. | ||
#ifdef MLIR_TRT_TARGET_TENSORRT | ||
mlirtrt::compiler::registerTensorRTToExecutableTask(); | ||
#endif | ||
Comment on lines
+56
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what exactly needs to be guarded. In a lot of places we guard TRT things with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The TensorRT dialect and MLIR passes are always built. It doesn't depend on actually having TensorRT binaries or headers to build against (or at least, that was the idea, we haven't been enforcing it). The |
||
|
||
#ifdef MLIR_TRT_ENABLE_HLO | ||
mlirtrt::compiler::registerStablehloClusteringPipelines(); | ||
registerStableHloInputPipelines(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ add_mlir_tensorrt_library(MLIRTensorRTCompilerClient | |
Extension.cpp | ||
OptionsRegistry.cpp | ||
OptionsProviders.cpp | ||
PassManagerUtils.cpp | ||
PARTIAL_SOURCES_INTENDED | ||
|
||
LINK_LIBS PUBLIC | ||
|
@@ -19,6 +20,8 @@ add_mlir_tensorrt_library(MLIRTensorRTCompilerStableHloToExecutable | |
StableHloToExecutable.cpp | ||
# TODO: TensorRTExtension should be an independent library. | ||
TensorRTExtension/TensorRTExtension.cpp | ||
# TODO (pranavm): TensorRTToExecutable should probably be a separate library | ||
TensorRTToExecutable.cpp | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that there's an open TODO for |
||
|
||
PARTIAL_SOURCES_INTENDED | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//===- PassManagerUtils.cpp -------------------------------------*- C++ -*-===// | ||
// | ||
// SPDX-FileCopyrightText: Copyright 2024 NVIDIA CORPORATION & AFFILIATES. | ||
// All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "mlir-tensorrt/Compiler/PassManagerUtils.h" | ||
|
||
using namespace mlirtrt::compiler; | ||
using namespace mlir; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Common helpers | ||
//===----------------------------------------------------------------------===// | ||
|
||
mlir::LogicalResult setupPassManager(mlir::PassManager &pm, | ||
const DebugOptions &options) { | ||
pm.enableVerifier(true); | ||
mlir::applyDefaultTimingPassManagerCLOptions(pm); | ||
if (failed(mlir::applyPassManagerCLOptions(pm))) | ||
return mlir::failure(); | ||
if (!options.dumpIRPath.empty()) { | ||
pm.enableIRPrintingToFileTree( | ||
[](Pass *, Operation *) { return false; }, | ||
[](Pass *, Operation *) { return true; }, true, false, false, | ||
options.dumpIRPath, OpPrintingFlags().elideLargeElementsAttrs(32)); | ||
} | ||
return mlir::success(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can move
TensorRTTranslationOptions
to make them an options provider if that makes sense to do.